Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -131,17 +131,19 @@ }, initGrammarChecker: function () { if (bChrome) { browser.storage.local.get("gc_options", this._initGrammarChecker); + browser.storage.local.get("main_dic_name", this._setSpellingDictionaries); browser.storage.local.get("personal_dictionary", this._setSpellingDictionaries); browser.storage.local.get("community_dictionary", this._setSpellingDictionaries); browser.storage.local.get("oPersonalDictionary", this._setSpellingDictionaries); // deprecated browser.storage.local.get("sc_options", this._initSCOptions); return; } browser.storage.local.get("gc_options").then(this._initGrammarChecker, showError); + browser.storage.local.get("main_dic_name", this._setSpellingDictionaries); browser.storage.local.get("personal_dictionary").then(this._setSpellingDictionaries, showError); browser.storage.local.get("community_dictionary").then(this._setSpellingDictionaries, showError); browser.storage.local.get("oPersonalDictionary").then(this._setSpellingDictionaries, showError); // deprecated browser.storage.local.get("sc_options").then(this._initSCOptions, showError); }, @@ -183,10 +185,13 @@ console.log("personal dictionary migration"); browser.storage.local.set({ "personal_dictionary": oData["oPersonalDictionary"] }); oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sDictionary: "personal", oDict: oData["oPersonalDictionary"] }, dInfo: {} }); browser.storage.local.remove("oPersonalDictionary"); } + if (oData.hasOwnProperty("main_dic_name")) { + oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sDictionary: "main", oDict: oData["main_dic_name"] }, dInfo: {sExtPath: browser.extension.getURL("")} }); + } if (oData.hasOwnProperty("community_dictionary")) { oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sDictionary: "community", oDict: oData["community_dictionary"] }, dInfo: {} }); } if (oData.hasOwnProperty("personal_dictionary")) { oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sDictionary: "personal", oDict: oData["personal_dictionary"] }, dInfo: {} }); Index: gc_lang/fr/webext/gce_worker.js ================================================================== --- gc_lang/fr/webext/gce_worker.js +++ gc_lang/fr/webext/gce_worker.js @@ -353,11 +353,11 @@ return; } //console.log("setDictionary", sDictionary); switch (sDictionary) { case "main": - oSpellChecker.setMainDictionary(oDict); + oSpellChecker.setMainDictionary(oDict, dInfo["sExtPath"]+"/grammalecte/graphspell/_dictionaries"); break; case "community": oSpellChecker.setCommunityDictionary(oDict); break; case "personal": Index: gc_lang/fr/webext/panel/main.css ================================================================== --- gc_lang/fr/webext/panel/main.css +++ gc_lang/fr/webext/panel/main.css @@ -245,11 +245,10 @@ font-size: 16px; text-align: center; cursor: pointer; } - .option_section { padding: 10px; margin-top: 10px; border-radius: 5px; background-color: hsl(210, 20%, 96%); @@ -263,10 +262,39 @@ .option_description { padding: 0 0 0 20px; color: hsl(0, 0%, 0%); font-size: 12px; } + + +#spelling_section { + padding: 5px 0 0 20px; +} +#spelling_section .subheader { + font-size: 14px; + font-weight: bold; + color: hsl(210, 20%, 50%); +} +#spelling_section .radiolike { + display: inline-block; + padding: 3px 5px; + font-size: 11px; + color: hsl(210, 10%, 96%); + background-color: hsl(210, 10%, 80%); + border-radius: 3px; + cursor: pointer; +} +#spelling_section .radiolike:hover { + color: hsl(210, 10%, 100%); + background-color: hsl(210, 10%, 50%); + box-shadow: 0 0 3px 3px hsl(210, 30%, 85%); +} +#spelling_section .selected { + color: hsl(210, 10%, 100%); + background-color: hsl(210, 50%, 50%); +} + /* Spell checking options */ Index: gc_lang/fr/webext/panel/main.html ================================================================== --- gc_lang/fr/webext/panel/main.html +++ gc_lang/fr/webext/panel/main.html @@ -110,10 +110,18 @@

DICTIONNAIRES DE GRAMMALECTE

Environ 83 000 entrées, 500 000 flexions.
Ni éditable, ni désactivable.
Ce dictionnaire est créé à partir du dictionnaire orthographique pour Firefox et LibreOffice, conçu sur le site de Grammalecte.

+
+

Orthographe

+

+

Classique
+
Réforme 1990
+
Toutes variantes
+

+

Ce dictionnaire est composé à partir de dictionnaires communautaires disponibles en ligne aux membres.

Non disponible. Fonctionnalité à venir.

Index: gc_lang/fr/webext/panel/main.js ================================================================== --- gc_lang/fr/webext/panel/main.js +++ gc_lang/fr/webext/panel/main.js @@ -22,10 +22,11 @@ window.addEventListener( "click", function (xEvent) { let xElem = xEvent.target; if (xElem.id) { + // tests if (xElem.id === "text_to_test_button") { browser.runtime.sendMessage({ sCommand: "textToTest", dParam: {sText: document.getElementById("text_to_test").value, sCountry: "FR", bDebug: true, bContext: false}, dInfo: {} @@ -37,10 +38,18 @@ sCommand: "fullTests", dParam: {}, dInfo: {} }); } + else if (xElem.id == "restart_worker") { + browser.runtime.sendMessage({ + sCommand: "restartWorker", + dParam: { "nDelayLimit": 3 }, + dInfo: {} + }); + } + // grammar options else if (xElem.id === "default_options_button") { browser.runtime.sendMessage({ sCommand: "resetOptions", dParam: {}, dInfo: {} @@ -53,10 +62,11 @@ dParam: {sOptName: xElem.dataset.option, bValue: xElem.checked}, dInfo: {} }); } } + // dictionaries options else if (xElem.id.endsWith("_dic")) { if (xElem.dataset.dictionary) { storeSCOptions(); browser.runtime.sendMessage({ sCommand: "setDictionaryOnOff", @@ -63,13 +73,25 @@ dParam: {sDictionary: xElem.dataset.dictionary, bActivate: xElem.checked}, dInfo: {} }); } } + else if (xElem.id.startsWith("spelling_")) { + updateSpellingChoiceUI(xElem.id); + let sMainDicName = document.getElementById(xElem.id).dataset.dicname; + browser.storage.local.set({"main_dic_name": sMainDicName}); + browser.runtime.sendMessage({ + sCommand: "setDictionary", + dParam: { sDictionary: "main", oDict: sMainDicName }, + dInfo: { sExtPath: browser.extension.getURL("") } + }); + } + // UI options else if (xElem.id.startsWith("ui_option_")) { storeUIOptions(); } + // else if (xElem.id.startsWith("link_")) { browser.tabs.create({url: xElem.dataset.url}); } else if (xElem.id == "conj_button") { browser.runtime.sendMessage({ @@ -97,17 +119,11 @@ sCommand: "openLexiconEditor", dParam: { "dictionary": "__personal__"}, dInfo: {} }); } - else if (xElem.id == "restart_worker") { - browser.runtime.sendMessage({ - sCommand: "restartWorker", - dParam: { "nDelayLimit": 3 }, - dInfo: {} - }); - } + // change UI page } else if (xElem.className.startsWith("select")) { showPage(xElem.dataset.page); }/* else if (xElem.tagName === "A") { openURL(xElem.getAttribute("href")); }*/ @@ -228,34 +244,46 @@ SC Options */ function displaySCOptionsLoadedFromStorage () { if (bChrome) { browser.storage.local.get("sc_options", displaySCOptions); + browser.storage.local.get("main_dic_name", displaySCOptions); return; } - let xPromise = browser.storage.local.get("sc_options"); - xPromise.then(displaySCOptions, showError); + browser.storage.local.get("sc_options").then(displaySCOptions, showError); + browser.storage.local.get("main_dic_name").then(displaySCOptions, showError); } function displaySCOptions (dOptions) { - if (!dOptions.hasOwnProperty("sc_options")) { - console.log("no sc options found"); - return; - } - dOptions = dOptions.sc_options; - //document.getElementById("extended_dic").checked = dOptions.extended; - document.getElementById("community_dic").checked = dOptions.community; - document.getElementById("personal_dic").checked = dOptions.personal; + if (dOptions.hasOwnProperty("sc_options")) { + document.getElementById("community_dic").checked = dOptions.sc_options.community; + document.getElementById("personal_dic").checked = dOptions.sc_options.personal; + } + if (dOptions.hasOwnProperty("main_dic_name")) { + switch (dOptions.main_dic_name) { + case "fr-classic.json": updateSpellingChoiceUI("spelling_classic"); break; + case "fr-reform.json": updateSpellingChoiceUI("spelling_reform"); break; + case "fr-allvars.json": updateSpellingChoiceUI("spelling_allvars"); break; + default: + console.log("Unknown dictionary name:", dOptions.main_dic_name); + } + } } function storeSCOptions () { browser.storage.local.set({"sc_options": { extended: false, community: document.getElementById("community_dic").checked, personal: document.getElementById("personal_dic").checked }}); } + +function updateSpellingChoiceUI (sSpellingChoice) { + document.getElementById("spelling_classic").className = (sSpellingChoice == "spelling_classic") ? "radiolike selected" : "radiolike"; + document.getElementById("spelling_reform").className = (sSpellingChoice == "spelling_reform") ? "radiolike selected" : "radiolike"; + document.getElementById("spelling_allvars").className = (sSpellingChoice == "spelling_allvars") ? "radiolike selected" : "radiolike"; +} /* GC options */ Index: graphspell-js/ibdawg.js ================================================================== --- graphspell-js/ibdawg.js +++ graphspell-js/ibdawg.js @@ -96,31 +96,31 @@ class IBDAWG { // INDEXABLE BINARY DIRECT ACYCLIC WORD GRAPH - constructor (param1, sPath="") { - // param1 can be a filename or a object with all the necessary data. + constructor (source, sPath="") { + // can be a filename or a object with all the necessary data. try { let oData = null; - if (typeof(param1) == "string") { + if (typeof(source) == "string") { let sURL; - if(typeof(process) !== 'undefined') { - sURL = (sPath !== "") ? sPath + "/" + param1 : __dirname + "/_dictionaries/"+param1; + if (typeof(process) !== 'undefined') { + sURL = (sPath !== "") ? sPath + "/" + source : __dirname + "/_dictionaries/"+source; } else { - sURL = (sPath !== "") ? sPath + "/" + param1 : "resource://grammalecte/graphspell/_dictionaries/"+param1; + sURL = (sPath !== "") ? sPath + "/" + source : "resource://grammalecte/graphspell/_dictionaries/"+source; } oData = JSON.parse(helpers.loadFile(sURL)); } else { - oData = param1; + oData = source; } Object.assign(this, oData); } catch (e) { console.error(e); console.log("path: " + sPath); - console.log("dic:" + param1.slice(0, 1000)); + console.log("dic:" + source.slice(0, 1000)); throw Error("# Error. File not found or not loadable.\n" + e.message + "\n"); } /* Properties: sName, nCompressionMethod, sHeader, lArcVal, nArcVal, sByDic, sLang, nChar, nBytesArc, nBytesNodeAddress, Index: graphspell-js/spellchecker.js ================================================================== --- graphspell-js/spellchecker.js +++ graphspell-js/spellchecker.js @@ -54,19 +54,19 @@ this._dMorphologies = new Map(); // key: flexion, value: list of morphologies this._dLemmas = new Map(); // key: flexion, value: list of lemmas } _loadDictionary (dictionary, sPath="", bNecessary=false) { - // returns an IBDAWG object + // can be a filename or a JSON object, returns an IBDAWG object if (!dictionary) { return null; } try { if (typeof(ibdawg) !== 'undefined') { - return new ibdawg.IBDAWG(dictionary, sPath); // dictionary can be a filename or a JSON object + return new ibdawg.IBDAWG(dictionary, sPath); } else { - return new IBDAWG(dictionary, sPath); // dictionary can be a filename or a JSON object + return new IBDAWG(dictionary, sPath); } } catch (e) { let sfDictionary = (typeof(dictionary) == "string") ? dictionary : dictionary.sLangName + "/" + dictionary.sFileName; let sErrorMessage = "Error [" + this.sLangCode + "]: <" + sfDictionary + "> not loaded.";