Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -142,38 +142,38 @@ }); } 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.dictionaries.hasOwnProperty("__personal__")) { - setDictionary("personal", oData.dictionaries["__personal__"]); - } - if (oData.dictionaries.hasOwnProperty("__community__")) { - setDictionary("community", oData.dictionaries["__community__"]); - } + if (oData.hasOwnProperty("personal_dictionary")) { + 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(); Index: gc_lang/fr/webext/panel/dictionaries.css ================================================================== --- gc_lang/fr/webext/panel/dictionaries.css +++ gc_lang/fr/webext/panel/dictionaries.css @@ -100,16 +100,26 @@ 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 */ @@ -137,10 +147,10 @@ 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; } Index: gc_lang/fr/webext/panel/dictionaries.html ================================================================== --- gc_lang/fr/webext/panel/dictionaries.html +++ gc_lang/fr/webext/panel/dictionaries.html @@ -10,12 +10,14 @@

Dictionnaires communautaires

+
Appliquer les modifications

Dictionnaires sélectionnés

[Aucun]

+

0 dictionnaires disponibles

@@ -24,11 +26,13 @@ + + Index: gc_lang/fr/webext/panel/dictionaries.js ================================================================== --- gc_lang/fr/webext/panel/dictionaries.js +++ gc_lang/fr/webext/panel/dictionaries.js @@ -32,18 +32,34 @@ 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; @@ -176,10 +192,11 @@ 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; @@ -207,22 +224,24 @@ 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"); @@ -248,16 +267,27 @@ 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(); 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 @@ -15,12 +15,11 @@

Dictionnaire

[]
0 entrées
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 @@ -495,52 +495,55 @@ } } 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; } - this.oDictionaries = oResult.dictionaries; - oBinaryDict.load("__personal__"); + if (oResult.hasOwnProperty("personal_dictionary")) { + this.oPersonalDictionary = oResult.personal_dictionary; + oBinaryDict.load("__personal__"); + } }, getDictionary: function (sName) { - if (this.oDictionaries && this.oDictionaries.hasOwnProperty(sName)) { + if (sName == "__personal__") { + return this.oPersonalDictionary; + } + 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; + browser.storage.local.set({ "shared_dictionaries": this.oDictionaries }); } - this.storeDictionaries(); - }, - - storeDictionaries: function () { - browser.storage.local.set({ "dictionaries": this.oDictionaries }); } } const oBinaryDict = {