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 @@ -300,10 +300,23 @@ /* Dictionary */ +#new_dictionary_button, #delete_dictionary_button { + margin-left: 5px; + padding: 1px 5px; + background-color: hsl(150, 50%, 50%); + color: hsl(150, 0%, 100%); + border-radius: 3px; + cursor: pointer; +} +#delete_dictionary_button { + background-color: hsl(0, 50%, 50%); + color: hsl(0, 0%, 100%); +} + #save_button { display: none; margin-left: 5px; padding: 1px 5px; background-color: hsl(150, 50%, 50%); @@ -319,10 +332,23 @@ background-color: hsl(210, 50%, 50%); color: hsl(210, 0%, 100%); border-radius: 3px; cursor: pointer; } + +#new_dictionary_section { + margin: 5px 0; + padding: 5px 10px; + background-color: hsl(210, 10%, 90%); + border-radius: 3px; +} +#create_dictionary_button { + padding: 1px 5px; + background-color: hsl(120, 50%, 30%); + color: hsl(120, 10%, 100%); + border-radius: 3px; +} #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 @@ -13,25 +13,32 @@

Éditeur lexical

Dictionnaire

-
+
+
+
+
+
[]
0 entrées
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 @@ -47,10 +47,20 @@ } else { console.log("HTML node named <" + sElemId + "> not found.") } } +function switchDisplay (sElemId, sDisplay="block") { + if (document.getElementById(sElemId)) { + if (document.getElementById(sElemId).style.display != "none") { + document.getElementById(sElemId).style.display = "none"; + } else { + document.getElementById(sElemId).style.display = sDisplay; + } + } +} + const oTabulations = { lPage: ["lexicon_page", "add_page", "search_page", "info_page"], @@ -531,17 +541,19 @@ } return null; }, saveDictionary: function (sName, oJSON) { - console.log(sName); if (sName == "__personal__") { browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "personal", oDict: oJSON}, dInfo: {} }); browser.storage.local.set({ "personal_dictionary": oJSON }); } else { this.oDictionaries[sName] = oJSON; + if (oJSON === null) { + delete this.oDictionaries[sName]; + } browser.storage.local.set({ "shared_dictionaries": this.oDictionaries }); } } } @@ -617,10 +629,12 @@ listen: function () { 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); }, build: function () { let xProgressNode = document.getElementById("wait_progress"); let lEntry = oLexiconTable.getEntries(); @@ -634,10 +648,21 @@ oDictHandler.saveDictionary(this.sName, null); this.setDictData(0, "[néant]"); } hideElement("save_button"); }, + + 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__"); + } + } + }, export: function () { let xBlob = new Blob([ JSON.stringify(this.oIBDAWG.getJSON()) ], {type: 'application/json'}); let sURL = URL.createObjectURL(xBlob); browser.downloads.download({ filename: "fr."+this.sName+".json", url: sURL, saveAs: true });