Index: gc_lang/fr/webext/panel/dictionaries.js ================================================================== --- gc_lang/fr/webext/panel/dictionaries.js +++ gc_lang/fr/webext/panel/dictionaries.js @@ -178,11 +178,10 @@ xRowNode.appendChild(createNode("td", { textContent: "×", className: "delete_entry", title: "Effacer cette entrée" }, { id_entry: this.iEntryIndex })); } let [nDicId, sName, sOwner, nEntry, sDescription, ...data] = lData; xRowNode.appendChild(createNode("td", { textContent: nDicId })); xRowNode.appendChild(createNode("td", { textContent: sName })); - xRowNode.appendChild(createNode("td", { textContent: sOwner })); xRowNode.appendChild(createNode("td", { textContent: nEntry })); xRowNode.appendChild(createNode("td", { textContent: sDescription })); if (this.bActionButtons) { xRowNode.appendChild(createNode("td", { textContent: "+", className: "select_entry", title: "Sélectionner/Désélectionner cette entrée" }, { id_entry: this.iEntryIndex, dict_name: sName })); } @@ -283,11 +282,12 @@ 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 }); + browser.storage.local.set({ "selected_dictionaries_list": this.dSelectedDict.keys() }); } } 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.css ================================================================== --- gc_lang/fr/webext/panel/lex_editor.css +++ gc_lang/fr/webext/panel/lex_editor.css @@ -344,10 +344,11 @@ #create_dictionary_button { padding: 1px 5px; background-color: hsl(120, 50%, 30%); color: hsl(120, 10%, 100%); border-radius: 3px; + cursor: pointer; } #wait_progress { width: 100%; height: 4px; 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 @@ -32,11 +32,11 @@
Exporter
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 @@ -17,11 +17,11 @@ function showError (e) { console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message); } -function createNode (sType, oAttr, oDataset=null) { +function createNode (sType, oAttr, oDataset=null) { try { let xNode = document.createElement(sType); Object.assign(xNode, oAttr); if (oDataset) { Object.assign(xNode.dataset, oDataset); @@ -504,32 +504,72 @@ } } } const oDictHandler = { - oDictionaries: null, + oDictionaries: {}, oPersonalDictionary: null, + lCreatedDictionaries: [], + xDicSelector: document.getElementById("dic_selector"), loadDictionaries: function () { if (bChrome) { browser.storage.local.get("shared_dictionaries", this._loadDictionaries.bind(this)); browser.storage.local.get("personal_dictionary", this._loadDictionaries.bind(this)); + browser.storage.local.get("created_dictionaries_list", this._loadDictionaries.bind(this)); return; } 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); + let xPromise3 = browser.storage.local.get("created_dictionaries_list"); + xPromise3.then(this._loadDictionaries.bind(this), showError); }, _loadDictionaries: function (oResult) { if (oResult.hasOwnProperty("shared_dictionaries")) { this.oDictionaries = oResult.shared_dictionaries; } if (oResult.hasOwnProperty("personal_dictionary")) { this.oPersonalDictionary = oResult.personal_dictionary; oBinaryDict.load("__personal__"); + } + if (oResult.hasOwnProperty("created_dictionaries_list")) { + this.lCreatedDictionaries = oResult.created_dictionaries_list; + for (let sDicName of this.lCreatedDictionaries) { + let xOption = createNode("option", {value: sDicName, textContent: sDicName}); + this.xDicSelector.appendChild(xOption); + } + } + }, + + addDictionary: function (sDicName) { + if (!this.oDictionaries.hasOwnProperty(sDicName)) { + let xOption = createNode("option", {value: sDicName, textContent: sDicName}); + this.xDicSelector.appendChild(xOption); + this.xDicSelector.selectedIndex = this.xDicSelector.options.length-1; + this.lCreatedDictionaries.push(sDicName); + browser.storage.local.set({ "created_dictionaries_list": this.lCreatedDictionaries }); + } + }, + + deleteDictionary: function (sDicName) { + this.saveDictionary(sDicName, null); + if (sDicName != "__personal__") { + let iDict = this.lCreatedDictionaries.indexOf(sDicName); + if (iDict > -1) { + this.lCreatedDictionaries.splice(iDict, 1); + } + browser.storage.local.set({ "created_dictionaries_list": this.lCreatedDictionaries }); + for (let xNode of this.xDicSelector.childNodes) { + if (xNode.value == sDicName) { + this.xDicSelector.removeChild(xNode); + } + } + this.xDicSelector.selectedIndex = 0; + oBinaryDict.load("__personal__"); } }, getDictionary: function (sName) { if (sName == "__personal__") { @@ -573,10 +613,23 @@ oLexiconTable.clear(); this.setDictData(0, "[néant]"); hideElement("save_button"); } }, + + newDictionary: function () { + this.oIBDAWG = null; + this.sName = document.getElementById("new_dictionary_name").value; + this.sDescription = document.getElementById("new_dictionary_description").value; + oDictHandler.addDictionary(this.sName); + oLexiconTable.clear(); + this.setDictData(0, "[néant]"); + hideElement("save_button"); + document.getElementById("new_dictionary_name").value = ""; + document.getElementById("new_dictionary_description").value = ""; + hideElement("new_dictionary_section") + }, parseDict: function (oJSON) { try { this.oIBDAWG = new IBDAWG(oJSON); } @@ -630,11 +683,12 @@ document.getElementById("dic_selector").addEventListener("change", () => {this.load(document.getElementById("dic_selector").value)}, false); document.getElementById("save_button").addEventListener("click", () => { this.build(); }, false); document.getElementById("export_button").addEventListener("click", () => { this.export(); }, false); document.getElementById("import_input").addEventListener("change", () => { this.import(); }, false); document.getElementById("new_dictionary_button").addEventListener("click", () => { switchDisplay("new_dictionary_section"); }, false); - document.getElementById("delete_dictionary_button").addEventListener("click", () => { this.delete() }, false); + document.getElementById("delete_dictionary_button").addEventListener("click", () => { this.delete(); }, false); + document.getElementById("create_dictionary_button").addEventListener("click", () => { this.newDictionary(); }, false); }, build: function () { let xProgressNode = document.getElementById("wait_progress"); let lEntry = oLexiconTable.getEntries(); @@ -652,15 +706,12 @@ }, delete: function () { if (confirm("Voulez-vous effacer le dictionnaire “"+this.sName+"” ?")) { oLexiconTable.clear(); - oDictHandler.saveDictionary(this.sName, null); this.setDictData(0, "[néant]"); - if (this.sName != "__personal__") { - this.load("__personal__"); - } + oDictHandler.deleteDictionary(this.sName); } }, export: function () { let xBlob = new Blob([ JSON.stringify(this.oIBDAWG.getJSON()) ], {type: 'application/json'});