Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -60,10 +60,13 @@ break; case "setOptions": case "setOption": storeGCOptions(result); break; + case "setDictionary": + console.log("[background] " + sActionDone + ": " + result); + break; default: console.log("[background] Unknown command: " + sActionDone); console.log(e.data); } } @@ -87,19 +90,40 @@ sCommand: "init", dParam: {sExtensionPath: browser.extension.getURL(""), dOptions: dOptions, sContext: "Firefox"}, dInfo: {} }); } + +function setSpellingDictionary (dSavedDictionary) { + if (dSavedDictionary.hasOwnProperty("oExtendedDictionary")) { + xGCEWorker.postMessage({ + sCommand: "setDictionary", + dParam: { sType: "extended", oDict: dSavedDictionary["oExtendedDictionary"] }, + dInfo: {} + }); + } + else if (dSavedDictionary.hasOwnProperty("oPersonalDictionary")) { + xGCEWorker.postMessage({ + sCommand: "setDictionary", + dParam: { sType: "personal", oDict: dSavedDictionary["oPersonalDictionary"] }, + dInfo: {} + }); + } +} function init () { if (bChrome) { browser.storage.local.get("gc_options", initGrammarChecker); browser.storage.local.get("ui_options", initUIOptions); + browser.storage.local.get("oExtendedDictionary", setSpellingDictionary); + browser.storage.local.get("oPersonalDictionary", setSpellingDictionary); return; } browser.storage.local.get("gc_options").then(initGrammarChecker, showError); browser.storage.local.get("ui_options").then(initUIOptions, showError); + browser.storage.local.get("oExtendedDictionary").then(setSpellingDictionary, showError); + browser.storage.local.get("oPersonalDictionary").then(setSpellingDictionary, showError); } init(); @@ -133,10 +157,11 @@ case "setOptions": case "setOption": case "resetOptions": case "textToTest": case "fullTests": + case "setDictionary": xGCEWorker.postMessage(oRequest); break; case "openURL": browser.tabs.create({url: dParam.sURL}); break; Index: gc_lang/fr/webext/gce_worker.js ================================================================== --- gc_lang/fr/webext/gce_worker.js +++ gc_lang/fr/webext/gce_worker.js @@ -119,10 +119,13 @@ textToTest(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo); break; case "fullTests": fullTests(dInfo); break; + case "setDictionary": + setDictionary(dParam.sType, dParam.oDict, dInfo); + break; case "getSpellSuggestions": getSpellSuggestions(dParam.sWord, dInfo); break; case "getListOfTokens": getListOfTokens(dParam.sText, dInfo); @@ -287,15 +290,38 @@ gc_engine.setOptions(dMemoOptions); postMessage(createResponse("fullTests", sMsg, dInfo, true)); } -// Spellchecker +// SpellChecker + +function setDictionary (sType, oDict, dInfo) { + if (!oSpellChecker) { + postMessage(createResponse("setDictionary", "# Error. SpellChecker not loaded.", dInfo, true)); + return; + } + switch (sType) { + case "main": + oSpellChecker.setMainDictionary(oDict); + postMessage(createResponse("setDictionary", true, dInfo, true)); + break; + case "extended": + oSpellChecker.setExtendedDictionary(oDict); + postMessage(createResponse("setDictionary", true, dInfo, true)); + break; + case "personal": + oSpellChecker.setPersonalDictionary(oDict); + postMessage(createResponse("setDictionary", true, dInfo, true)); + break; + default: + console.log("[worker] setDictionary: Unknown command"); + } +} function getSpellSuggestions (sWord, dInfo) { if (!oSpellChecker) { - postMessage(createResponse("getSpellSuggestions", "# Error. Dictionary not loaded.", dInfo, true)); + postMessage(createResponse("getSpellSuggestions", "# Error. SpellChecker not loaded.", dInfo, true)); return; } let i = 1; for (let aSugg of oSpellChecker.suggest(sWord)) { postMessage(createResponse("getSpellSuggestions", {sWord: sWord, aSugg: aSugg, iSugg: i}, dInfo, true)); 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 @@ -570,23 +570,23 @@ oIBDAWG: null, load: function () { if (bChrome) { - browser.storage.local.get("oDictionary", this._load); + browser.storage.local.get("oPersonalDictionary", this._load); return; } - let xPromise = browser.storage.local.get("oDictionary"); + let xPromise = browser.storage.local.get("oPersonalDictionary"); xPromise.then(this._load.bind(this), showError); }, _load: function (oResult) { - if (!oResult.hasOwnProperty("oDictionary")) { + if (!oResult.hasOwnProperty("oPersonalDictionary")) { oWidgets.hideElement("export_button"); return; } - let oJSON = oResult.oDictionary; + let oJSON = oResult.oPersonalDictionary; this.oIBDAWG = new IBDAWG(oJSON); let lEntry = []; for (let s of this.oIBDAWG.select()) { lEntry.push(s.split("\t")); } @@ -603,14 +603,15 @@ this.save(oJSON); this.oIBDAWG = new IBDAWG(oJSON); oWidgets.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate); oWidgets.hideElement("build_progress"); oWidgets.showElement("export_button"); + browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sType: "personal", oDict: oJSON}, dInfo: {} }); }, save: function (oJSON) { - browser.storage.local.set({ "oDictionary": oJSON }); + browser.storage.local.set({ "oPersonalDictionary": oJSON }); }, import: function () { // TO DO }, Index: graphspell-js/spellchecker.js ================================================================== --- graphspell-js/spellchecker.js +++ graphspell-js/spellchecker.js @@ -60,23 +60,23 @@ } setMainDictionary (dictionary) { // returns true if the dictionary is loaded this.oMainDic = this._loadDictionary(dictionary); - return bool(this.oMainDic); + return Boolean(this.oMainDic); } setExtendedDictionary (dictionary) { // returns true if the dictionary is loaded this.oExtendedDic = this._loadDictionary(dictionary); - return bool(this.oExtendedDic); + return Boolean(this.oExtendedDic); } setPersonalDictionary (dictionary) { // returns true if the dictionary is loaded this.oPersonalDic = this._loadDictionary(dictionary); - return bool(this.oPersonalDic); + return Boolean(this.oPersonalDic); } // IBDAWG functions isValidToken (sToken) { @@ -123,14 +123,14 @@ getMorph (sWord) { // retrieves morphologies list, different casing allowed let lResult = this.oMainDic.getMorph(sWord); if (this.oExtendedDic) { - lResult.extends(this.oExtendedDic.getMorph(sWord)); + lResult.push(...this.oExtendedDic.getMorph(sWord)); } if (this.oPersonalDic) { - lResult.extends(this.oPersonalDic.getMorph(sWord)); + lResult.push(...this.oPersonalDic.getMorph(sWord)); } return lResult; } * suggest (sWord, nSuggLimit=10) {