Grammalecte  Check-in [c3e4095da4]

Overview
Comment:[fx] dictionaries reorganization
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | comdic
Files: files | file ages | folders
SHA3-256: c3e4095da4af239848a64392fc667c636a6c885f50cb15f5fd8d515c08a382b6
User & Date: olr on 2019-01-30 16:33:10
Other Links: branch diff | manifest | tags
Context
2019-01-30
16:35
[graphspell][js] dictionaries merger check-in: a3a2352766 user: olr tags: graphspell, comdic
16:33
[fx] dictionaries reorganization check-in: c3e4095da4 user: olr tags: fx, comdic
2019-01-28
22:17
[fx] get dictionaries list, download dictionaries check-in: a0890eba14 user: olr tags: fx, comdic
Changes

Modified gc_lang/fr/webext/background.js from [dfd47dd30f] to [338285a5c1].

140
141
142
143
144
145
146
147

148
149

150
151
152
153

154
155
156
157
158




159
160
161
162
163
164
165
166
167


168
169
170
171
172
173
174


175
176
177
178
179
180
181
140
141
142
143
144
145
146

147
148

149
150
151
152

153





154
155
156
157

158
159
160
161
162
163
164

165
166
167
168
169
170
171
172

173
174
175
176
177
178
179
180
181







-
+

-
+



-
+
-
-
-
-
-
+
+
+
+
-







-
+
+






-
+
+







        dParam: { sDictionary: sDictionary, oDict: oDictionary },
        dInfo: {}
    });
}

function setSpellingDictionaries (oData) {
    if (oData.hasOwnProperty("oPersonalDictionary")) {
        // deprecated
        // deprecated (to be removed in 2020)
        console.log("personal dictionary migration");
        browser.storage.local.set({ "dictionaries": { "__personal__": oData["oPersonalDictionary"] } });
        browser.storage.local.set({ "personal_dictionary": oData["oPersonalDictionary"] });
        setDictionary("personal", oData["oPersonalDictionary"]);
        browser.storage.local.remove("oPersonalDictionary");
    }
    if (oData.hasOwnProperty("dictionaries")) {
    if (oData.hasOwnProperty("personal_dictionary")) {
        if (oData.dictionaries.hasOwnProperty("__personal__")) {
            setDictionary("personal", oData.dictionaries["__personal__"]);
        }
        if (oData.dictionaries.hasOwnProperty("__community__")) {
            setDictionary("community", oData.dictionaries["__community__"]);
        setDictionary("personal", oData["personal_dictionary"]);
    }
    if (oData.hasOwnProperty("community_dictionary")) {
        setDictionary("community", oData["community_dictionary"]);
        }
    }
}

function init () {
    if (bChrome) {
        browser.storage.local.get("gc_options", initGrammarChecker);
        browser.storage.local.get("ui_options", initUIOptions);
        browser.storage.local.get("dictionaries", setSpellingDictionaries);
        browser.storage.local.get("personal_dictionary", setSpellingDictionaries);
        browser.storage.local.get("community_dictionary", setSpellingDictionaries);
        browser.storage.local.get("oPersonalDictionary", setSpellingDictionaries); // deprecated
        browser.storage.local.get("sc_options", initSCOptions);
        return;
    }
    browser.storage.local.get("gc_options").then(initGrammarChecker, showError);
    browser.storage.local.get("ui_options").then(initUIOptions, showError);
    browser.storage.local.get("dictionaries").then(setSpellingDictionaries, showError);
    browser.storage.local.get("personal_dictionary").then(setSpellingDictionaries, showError);
    browser.storage.local.get("community_dictionary").then(setSpellingDictionaries, showError);
    browser.storage.local.get("oPersonalDictionary").then(setSpellingDictionaries, showError); // deprecated
    browser.storage.local.get("sc_options").then(initSCOptions, showError);
}

init();


Modified gc_lang/fr/webext/panel/dictionaries.css from [bafc0510cd] to [f2b5daf12c].

98
99
100
101
102
103
104
105

106
107
108

109
110










111
112
113
114
115
116
117
98
99
100
101
102
103
104

105
106
107

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127







-
+


-
+


+
+
+
+
+
+
+
+
+
+







    border-color: hsl(0, 50%, 45%);
    border-radius: 3px 0 0 3px;
    cursor: pointer;
}
.dic_button_label {
    display: inline-block;
    padding: 1px 10px;
    background-color: hsl(120, 50%, 94%);
    background-color: hsl(210, 50%, 94%);
    border-style: solid;
    border-width: 1px 1px 1px 0;
    border-color: hsl(120, 50%, 70%);
    border-color: hsl(210, 50%, 70%);
    border-radius: 0 3px 3px 0;
}

.apply {
    display: none;
    float: right;
    padding: 2px 10px;
    background: hsl(120, 50%, 30%);
    color: hsl(120, 50%, 96%);
    cursor: pointer;
    border-radius: 3px;
}


/*
    Table
*/
#wait_progress {
    width: 100%;
135
136
137
138
139
140
141
142
143


144
145
146
145
146
147
148
149
150
151


152
153
154
155
156







-
-
+
+



.delete_entry {
    cursor: pointer;
    font-weight: bold;
    color: hsl(0, 100%, 50%);
}
.select_entry {
    cursor: pointer;
    background-color: hsl(120, 50%, 30%);
    color: hsl(120, 50%, 100%);
    background-color: hsl(210, 50%, 30%);
    color: hsl(210, 50%, 100%);
    border-radius: 3px;
    text-align: center;
}

Modified gc_lang/fr/webext/panel/dictionaries.html from [30e1db6643] to [8ce0f3ed0b].

8
9
10
11
12
13
14

15
16

17
18
19
20
21
22
23
24
25
26
27
28

29

30
31
32
33
34
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38







+


+












+

+






  <body>

    <div class="inbox">

      <h1>Dictionnaires communautaires</h1>

        <div id="apply" class="apply">Appliquer les modifications</div>
        <h2>Dictionnaires sélectionnés</h2>
        <p id="dictionaries_list">[Aucun]<p>


        <h2><span id="num_dic">0</span> dictionnaires disponibles</h2>
        <progress id="wait_progress" value="0"></progress>
        <table id="dictionaries_table">
        </table>

    </div>


    <script src="../grammalecte/graphspell/helpers.js"></script>
    <script src="../grammalecte/graphspell/char_player.js"></script>
    <script src="../grammalecte/graphspell/str_transform.js"></script>
    <script src="../grammalecte/graphspell/dawg.js"></script>
    <script src="../grammalecte/graphspell/ibdawg.js"></script>
    <script src="../grammalecte/graphspell/dic_merger.js"></script>
    <script src="../grammalecte/graphspell/spellchecker.js"></script>
    <script src="dictionaries.js"></script>
  </body>

</html>

Modified gc_lang/fr/webext/panel/dictionaries.js from [35271f2dab] to [cb7ebf796e].

30
31
32
33
34
35
36















37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








+







        return xNode;
    }
    catch (e) {
        showError(e);
    }
}

function showElement (sElemId, sDisplay="block") {
    if (document.getElementById(sElemId)) {
        document.getElementById(sElemId).style.display = sDisplay;
    } else {
        console.log("HTML node named <" + sElemId + "> not found.")
    }
}

function hideElement (sElemId) {
    if (document.getElementById(sElemId)) {
        document.getElementById(sElemId).style.display = "none";
    } else {
        console.log("HTML node named <" + sElemId + "> not found.")
    }
}



class Table {

    constructor (sNodeId, lColumn, sProgressBarId, sResultId="", bDeleteButtons=true, bActionButtons) {
        this.sNodeId = sNodeId;
        this.xTable = document.getElementById(sNodeId);
        this.xApply = document.getElementById("apply");
        this.nColumn = lColumn.length;
        this.lColumn = lColumn;
        this.xProgressBar = document.getElementById(sProgressBarId);
        this.xNumEntry = document.getElementById(sResultId);
        this.iEntryIndex = 0;
        this.lEntry = [];
        this.nEntry = 0;
174
175
176
177
178
179
180

181
182
183
184
185
186
187
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204







+







        this.iEntryIndex += 1;
    }

    listen () {
        if (this.bDeleteButtons || this.bActionButtons) {
            this.xTable.addEventListener("click", (xEvent) => { this.onTableClick(xEvent); }, false);
        }
        this.xApply.addEventListener("click", (xEvent) => { this.generateCommunityDictionary(xEvent); }, false);
    }

    onTableClick (xEvent) {
        try {
            let xElem = xEvent.target;
            if (xElem.className) {
                switch (xElem.className) {
205
206
207
208
209
210
211

212
213
214
215
216
217
218

219
220
221
222
223

224
225
226
227
228
229
230
222
223
224
225
226
227
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244
245
246
247
248
249







+






-
+





+







            document.getElementById(this.sNodeId + "_row_" + iEntry).style.display = "none";
        }
        this.nEntry -= 1;
        this.showEntryNumber();
        if (this.sNodeId == "lexicon_table") {
            showElement("save_button", "inline-block");
        }
        showElement("apply");
    }

    selectEntry (nEntryId, sDicName) {
        let sRowId = this.sNodeId + "_row_" + nEntryId;
        if (!this.dSelectedDict.has(sDicName)) {
            this.dSelectedDict.set(sDicName, nEntryId);
            document.getElementById(sRowId).style.backgroundColor = "hsl(120, 50%, 90%)";
            document.getElementById(sRowId).style.backgroundColor = "hsl(210, 50%, 90%)";
        }
        else {
            this.dSelectedDict.delete(sDicName);
            document.getElementById(sRowId).style.backgroundColor = "";
        }
        showElement("apply");
        this.showSelectedDict();
    }

    clearSelectedDict () {
        let xDicList = document.getElementById("dictionaries_list");
        while (xDicList.firstChild) {
            xDicList.removeChild(xDicList.firstChild);
246
247
248
249
250
251
252

253
254
255
256
257
258
259












260
261
262
263
265
266
267
268
269
270
271
272
273
274
275
276
277


278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293







+





-
-
+
+
+
+
+
+
+
+
+
+
+
+




    createDictLabel (nDicId, sLabel) {
        let xLabel = createNode("div", {className: "dic_button"});
        let xCloseButton = createNode("div", {className: "dic_button_close", textContent: "×"}, {id_entry: nDicId});
        xCloseButton.addEventListener("click", () => {
            this.dSelectedDict.delete(sLabel);
            document.getElementById(this.sNodeId+"_row_"+nDicId).style.backgroundColor = "";
            xLabel.style.display = "none";
            showElement("apply");
        });
        xLabel.appendChild(xCloseButton);
        xLabel.appendChild(createNode("div", {className: "dic_button_label", textContent: sLabel}));
        return xLabel;
    }
}


    generateCommunityDictionary (xEvent) {
        hideElement("apply");
        let lDict = [];
        for (let sName of this.dSelectedDict.keys()) {
            lDict.push(this.dDict.get(sName));
        }
        let oDict = dic_merger.merge(lDict, "S", "fr", "Français", "fr.community", "Dictionnaire communautaire (personnalisé)", this.xProgressBar);
        console.log(oDict);
        browser.storage.local.set({ "community_dictionary": oDict });
    }
}

const oDicTable = new Table("dictionaries_table", ["Id", "Nom", "par", "Entrées", "Description"], "wait_progress", "num_dic", false, true);

oDicTable.getDictionarieslist();

Modified gc_lang/fr/webext/panel/lex_editor.html from [18a9eff11b] to [41cead673f].

13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
13
14
15
16
17
18
19

20

21
22
23
24
25
26
27







-
+
-







      <h1>Éditeur lexical</h1>

      <div class="big_block">
        <div class="dic_container">
          <div><h3>Dictionnaire</h3></div>
          <div>
            <select id="dic_selector">
              <option value="__personal__">personnel</option>
              <option value="__personal__">__personnel__</option>
              <option value="__community__">communautaire</option>
            </select>
          </div>
          <div>[<span id="dic_save_date">—</span>]</div>
          <div><span id="dic_num_entries">0</span> entrées</div>
          <div>
            <input type="file" id="import_input" accept=".json" style="display: none;">
            <label id="import_button" for="import_input">Importer</label>

Modified gc_lang/fr/webext/panel/lex_editor.js from [380093a31f] to [9505b2fbc4].

493
494
495
496
497
498
499

500
501
502
503


504
505
506

507


508
509
510
511
512


513

514
515



516
517
518



519

520
521
522
523
524
525
526
527

528
529
530
531
532

533
534
535

536
537

538
539

540
541
542
543
544
545
546
547
548
493
494
495
496
497
498
499
500
501
502
503

504
505
506
507

508
509
510
511
512
513
514


515
516
517
518


519
520
521
522
523
524
525
526
527

528
529
530
531
532
533
534
535

536
537
538



539
540
541

542


543


544


545
546
547
548
549
550
551







+



-
+
+


-
+

+
+



-
-
+
+

+
-
-
+
+
+



+
+
+
-
+







-
+


-
-
-
+


-
+
-
-
+
-
-
+
-
-







            showError(e);
        }
    }
}

const oDictHandler = {
    oDictionaries: null,
    oPersonalDictionary: null,

    loadDictionaries: function () {
        if (bChrome) {
            browser.storage.local.get("dictionaries", this._loadDictionaries.bind(this));
            browser.storage.local.get("shared_dictionaries", this._loadDictionaries.bind(this));
            browser.storage.local.get("personal_dictionary", this._loadDictionaries.bind(this));
            return;
        }
        let xPromise = browser.storage.local.get("dictionaries");
        let xPromise = browser.storage.local.get("shared_dictionaries");
        xPromise.then(this._loadDictionaries.bind(this), showError);
        let xPromise2 = browser.storage.local.get("personal_dictionary");
        xPromise2.then(this._loadDictionaries.bind(this), showError);
    },

    _loadDictionaries: function (oResult) {
        if (!oResult.hasOwnProperty("dictionaries")) {
            return;
        if (oResult.hasOwnProperty("shared_dictionaries")) {
            this.oDictionaries = oResult.shared_dictionaries;
        }
        if (oResult.hasOwnProperty("personal_dictionary")) {
        this.oDictionaries = oResult.dictionaries;
        oBinaryDict.load("__personal__");
            this.oPersonalDictionary = oResult.personal_dictionary;
            oBinaryDict.load("__personal__");
        }
    },

    getDictionary: function (sName) {
        if (sName == "__personal__") {
            return this.oPersonalDictionary;
        }
        if (this.oDictionaries  &&  this.oDictionaries.hasOwnProperty(sName)) {
        else if (this.oDictionaries  &&  this.oDictionaries.hasOwnProperty(sName)) {
            //console.log(this.oDictionaries[sName]);
            return this.oDictionaries[sName];
        }
        return null;
    },

    saveDictionary: function (sName, oJSON) {
        this.oDictionaries[sName] = oJSON;
        console.log(sName);
        if (sName == "__personal__") {
            browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "personal", oDict: oJSON}, dInfo: {} });
        }
        else if (sName == "__community__") {
            browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "community", oDict: oJSON}, dInfo: {} });
            browser.storage.local.set({ "personal_dictionary": oJSON });
        }
        else {
            // TODO: merge sub-dictionaries
            this.oDictionaries[sName] = oJSON;
        }
        this.storeDictionaries();
            browser.storage.local.set({ "shared_dictionaries": this.oDictionaries });
    },

        }
    storeDictionaries: function () {
        browser.storage.local.set({ "dictionaries": this.oDictionaries });
    }
}

const oBinaryDict = {

    oIBDAWG: null,
    sName: "",