Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -117,23 +117,22 @@ dParam: { sDictionary: sDictionary, bActivate: bActivate }, dInfo: {} }); } -function initSCOptions (dSavedOptions) { - if (!dSavedOptions.hasOwnProperty("sc_options")) { +function initSCOptions (oData) { + if (!oData.hasOwnProperty("sc_options")) { browser.storage.local.set({"sc_options": { extended: true, community: true, personal: true }}); setDictionaryOnOff("community", true); setDictionaryOnOff("personal", true); } else { - let dOptions = dSavedOptions.sc_options; - setDictionaryOnOff("community", dOptions["community"]); - setDictionaryOnOff("personal", dOptions["personal"]); + setDictionaryOnOff("community", oData.sc_options["community"]); + setDictionaryOnOff("personal", oData.sc_options["personal"]); } } function setDictionary (sDictionary, oDictionary) { xGCEWorker.postMessage({ @@ -141,32 +140,41 @@ dParam: { sDictionary: sDictionary, oDict: oDictionary }, dInfo: {} }); } -function setSpellingDictionary (dSavedDictionary) { - if (dSavedDictionary.hasOwnProperty("oCommunityDictionary")) { - setDictionary("community", dSavedDictionary["oCommunityDictionary"]); +function setSpellingDictionaries (oData) { + if (oData.hasOwnProperty("oPersonalDictionary")) { + // deprecated + console.log("personal dictionary migration"); + browser.storage.local.set({ "oDictionaries": { "__personal__": oData["oPersonalDictionary"] } }); + setDictionary("personal", oData["oPersonalDictionary"]); + browser.storage.local.remove("oPersonalDictionary"); } - if (dSavedDictionary.hasOwnProperty("oPersonalDictionary")) { - setDictionary("personal", dSavedDictionary["oPersonalDictionary"]); + if (oData.hasOwnProperty("oDictionaries")) { + if (oData.oDictionaries.hasOwnProperty("__personal__")) { + setDictionary("personal", oData.oDictionaries["__personal__"]); + } + if (oData.oDictionaries.hasOwnProperty("__community__")) { + setDictionary("personal", oData.oDictionaries["__community__"]); + } } } function init () { if (bChrome) { browser.storage.local.get("gc_options", initGrammarChecker); browser.storage.local.get("ui_options", initUIOptions); - browser.storage.local.get("oCommunityDictionary", setSpellingDictionary); - browser.storage.local.get("oPersonalDictionary", setSpellingDictionary); + browser.storage.local.get("oDictionaries", 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("oCommunityDictionary").then(setSpellingDictionary, showError); - browser.storage.local.get("oPersonalDictionary").then(setSpellingDictionary, showError); + browser.storage.local.get("oDictionaries").then(setSpellingDictionaries, showError); + browser.storage.local.get("oPersonalDictionary").then(setSpellingDictionaries, showError); // deprecated browser.storage.local.get("sc_options").then(initSCOptions, showError); } init(); Index: gc_lang/fr/webext/panel/lex_editor.html ================================================================== --- gc_lang/fr/webext/panel/lex_editor.html +++ gc_lang/fr/webext/panel/lex_editor.html @@ -3,28 +3,29 @@ Grammalecte · Éditeur lexical - +

Éditeur lexical

Dictionnaire personnel

-
Enregistré le :
+
Date :
0 entrées
- -
+
-
Exporter
+
Exporter
+
+
@@ -154,11 +155,11 @@
Je suis venu.
Je suis parti.
J’ai venu.
J’ai parti.
- +
@@ -229,15 +230,15 @@

- +

Mots générés

- +
Ajouter au lexique
@@ -253,11 +254,11 @@

Nombre d’entrées : 0.

- +
@@ -281,11 +282,11 @@

Résultats

- +
@@ -311,11 +312,11 @@

Il est déconseillé d’utiliser la catégorie ‹Autre› pour générer autre chose que des noms, des adjectifs, des noms propres, des verbes et des adverbes. Il n’y a aucune garantie que les étiquettes pour les autres catégories, notamment les mots grammaticaux, ne changeront pas.

- +
@@ -331,7 +332,7 @@ - + Index: gc_lang/fr/webext/panel/lex_editor.js ================================================================== --- gc_lang/fr/webext/panel/lex_editor.js +++ gc_lang/fr/webext/panel/lex_editor.js @@ -490,39 +490,73 @@ showError(e); } } } - -const oBinaryDict = { - - oIBDAWG: null, - - load: function () { - if (bChrome) { - browser.storage.local.get("oPersonalDictionary", this._load.bind(this)); - return; - } - let xPromise = browser.storage.local.get("oPersonalDictionary"); - xPromise.then(this._load.bind(this), showError); - }, - - _load: function (oResult) { - if (!oResult.hasOwnProperty("oPersonalDictionary")) { - hideElement("export_button"); - return; - } - let oJSON = oResult.oPersonalDictionary; - if (oJSON) { - this.__load(oJSON); +const oDictHandler = { + oDictionaries: null, + + loadDictionaries: function () { + if (bChrome) { + browser.storage.local.get("oDictionaries", this._loadDictionaries.bind(this)); + return; + } + let xPromise = browser.storage.local.get("oDictionaries"); + xPromise.then(this._loadDictionaries.bind(this), showError); + }, + + _loadDictionaries: function (oResult) { + if (!oResult.hasOwnProperty("oDictionaries")) { + return; + } + this.oDictionaries = oResult.oDictionaries; + oBinaryDict.load("__personal__"); + }, + + getDictionary: function (sName) { + console.log("load "+sName); + 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; + if (sName == "__personal__") { + browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "personal", oDict: oJSON}, dInfo: {} }); + } else { + // rebuild now? + //browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "community", oDict: oJSON}, dInfo: {} }); + } + this.storeDictionaries(); + }, + + storeDictionaries: function () { + browser.storage.local.set({ "oDictionaries": this.oDictionaries }); + } +} + +const oBinaryDict = { + + oIBDAWG: null, + sName: null, + + load: function (sName="__personal__") { + this.sName = sName; + let oJSON = oDictHandler.getDictionary(sName); + if (oJSON) { + console.log("parse"); + this.parseDict(oJSON); } else { oLexiconTable.clear(); this.setDictData(0, "[néant]"); } }, - __load: function (oJSON) { + parseDict: function (oJSON) { try { this.oIBDAWG = new IBDAWG(oJSON); } catch (e) { console.error(e); @@ -530,39 +564,34 @@ return; } let lEntry = []; for (let aRes of this.oIBDAWG.select()) { lEntry.push(aRes); - } + } oLexiconTable.fill(lEntry); this.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate); }, - save: function (oJSON) { - browser.storage.local.set({ "oPersonalDictionary": oJSON }); - browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "personal", oDict: oJSON}, dInfo: {} }); - }, - import: function () { - let xInput = document.getElementById("import_input"); + let xInput = document.getElementById("import_input"); let xFile = xInput.files[0]; let xURL = URL.createObjectURL(xFile); let sJSON = helpers.loadFile(xURL); if (sJSON) { try { let oJSON = JSON.parse(sJSON); - this.__load(oJSON); - this.save(oJSON); + this.parseDict(oJSON); + oDictHandler.saveDictionary(this.sName, oJSON); } catch (e) { console.error(e); this.setDictData(0, "#Erreur. Voir la console."); return; } } else { this.setDictData(0, "[néant]"); - this.save(null); + oDictHandler.saveDictionary(this.sName, null); } }, setDictData: function (nEntries, sDate) { document.getElementById("dic_num_entries").textContent = nEntries; @@ -584,24 +613,24 @@ let xProgressNode = document.getElementById("wait_progress"); let lEntry = oLexiconTable.getEntries(); if (lEntry.length > 0) { let oDAWG = new DAWG(lEntry, "S", "fr", "Français", "Dictionnaire personnel", xProgressNode); let oJSON = oDAWG.createBinaryJSON(1); - this.save(oJSON); + oDictHandler.saveDictionary(this.sName, oJSON); this.oIBDAWG = new IBDAWG(oJSON); this.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate); } else { + oDictHandler.saveDictionary(this.sName, null); this.setDictData(0, "[néant]"); - this.save(null); } hideElement("save_button"); }, export: function () { - let xBlob = new Blob([ JSON.stringify(this.oIBDAWG.getJSON()) ], {type: 'application/json'}); + let xBlob = new Blob([ JSON.stringify(this.oIBDAWG.getJSON()) ], {type: 'application/json'}); let sURL = URL.createObjectURL(xBlob); - browser.downloads.download({ filename: "fr.personal.json", url: sURL, saveAs: true }); + browser.downloads.download({ filename: "fr."+this.sName+".json", url: sURL, saveAs: true }); } } const oSearch = { @@ -664,10 +693,10 @@ const oTagsTable = new Table("tags_table", ["Étiquette", "Signification"], "wait_progress", "", false); oTagsInfo.load(); oSearch.load(); -oBinaryDict.load(); +oDictHandler.loadDictionaries(); oBinaryDict.listen(); oGenerator.listen(); oTabulations.listen(); oSearch.listen();