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
@@ -309,13 +309,10 @@
display: block;
margin-left: 5px;
background-color: hsl(210, 50%, 50%);
color: hsl(210, 0%, 100%);
}
-#import_button {
- display: none;
-}
#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
@@ -15,12 +15,17 @@
Dictionnaire personnel
Enregistré le : —
0 entrées
+
+
+
+
+
Exporter
-
Importer
+
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
@@ -494,11 +494,11 @@
oIBDAWG: null,
load: function () {
if (bChrome) {
- browser.storage.local.get("oPersonalDictionary", this._load);
+ browser.storage.local.get("oPersonalDictionary", this._load.bind(this));
return;
}
let xPromise = browser.storage.local.get("oPersonalDictionary");
xPromise.then(this._load.bind(this), showError);
},
@@ -507,29 +507,71 @@
if (!oResult.hasOwnProperty("oPersonalDictionary")) {
hideElement("export_button");
return;
}
let oJSON = oResult.oPersonalDictionary;
- this.oIBDAWG = new IBDAWG(oJSON);
+ if (oJSON) {
+ this.__load(oJSON);
+ } else {
+ oLexiconTable.clear();
+ this.setDictData(0, "[néant]");
+ }
+ },
+
+ __load: function (oJSON) {
+ try {
+ this.oIBDAWG = new IBDAWG(oJSON);
+ }
+ catch (e) {
+ console.error(e);
+ this.setDictData(0, "#Erreur. Voir la console.");
+ return;
+ }
let lEntry = [];
for (let aRes of this.oIBDAWG.select()) {
lEntry.push(aRes);
}
oLexiconTable.fill(lEntry);
this.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate);
- showElement("export_button");
+ },
+
+ import: function () {
+ 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);
+ browser.storage.local.set({ "oPersonalDictionary": oJSON });
+ this.__load(oJSON);
+ }
+ catch (e) {
+ console.error(e);
+ this.setDictData(0, "#Erreur. Voir la console.");
+ return;
+ }
+ } else {
+ this.setDictData(0, "[néant]");
+ browser.storage.local.set({ "oPersonalDictionary": "" });
+ }
},
setDictData: function (nEntries, sDate) {
document.getElementById("dic_num_entries").textContent = nEntries;
document.getElementById("dic_save_date").textContent = sDate;
+ if (nEntries == 0) {
+ hideElement("export_button");
+ } else {
+ showElement("export_button");
+ }
},
listen: function () {
document.getElementById("save_button").addEventListener("click", () => { this.build(); }, false);
document.getElementById("export_button").addEventListener("click", () => { this.export(); }, false);
- document.getElementById("import_button").addEventListener("click", () => { this.import(); }, false);
+ document.getElementById("import_input").addEventListener("change", () => { this.import(); }, false);
},
build: function () {
let xProgressNode = document.getElementById("wait_progress");
let lEntry = oLexiconTable.getEntries();
@@ -538,22 +580,17 @@
let oJSON = oDAWG.createBinaryJSON(1);
browser.storage.local.set({ "oPersonalDictionary": oJSON });
this.oIBDAWG = new IBDAWG(oJSON);
this.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate);
browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sType: "personal", oDict: oJSON}, dInfo: {} });
- showElement("export_button");
} else {
this.setDictData(0, "[néant]");
browser.storage.local.set({ "oPersonalDictionary": "" });
browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sType: "personal", oDict: null}, dInfo: {} });
}
},
- import: function () {
- console.log("import");
- },
-
export: function () {
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 });
}