Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -103,40 +103,73 @@ catch (e) { console.log("initGrammarChecker failed"); showError(e); } } + +function setDictionaryOnOff (sDictionary, bActivate) { + xGCEWorker.postMessage({ + sCommand: "setDictionary", + dParam: { sDictionary: sDictionary, bActivate: bActivate }, + dInfo: {} + }); +} + +function initSCOptions (dSavedOptions) { + if (!dSavedOptions.hasOwnProperty("sc_options")) { + browser.storage.local.set({"sc_options": { + extended: true, + community: true, + personal: true + }}); + setDictionaryOnOff("extended", true); + setDictionaryOnOff("community", true); + setDictionaryOnOff("personal", true); + } else { + let dOptions = dSavedOptions.sc_options; + setDictionaryOnOff("extended", dOptions["extended"]); + setDictionaryOnOff("community", dOptions["community"]); + setDictionaryOnOff("personal", dOptions["personal"]); + } +} + +function setDictionary (sDictionary, oDictionary) { + xGCEWorker.postMessage({ + sCommand: "setDictionary", + dParam: { sDictionary: sDictionary, oDict: oDictionary }, + dInfo: {} + }); +} function setSpellingDictionary (dSavedDictionary) { if (dSavedDictionary.hasOwnProperty("oExtendedDictionary")) { - xGCEWorker.postMessage({ - sCommand: "setDictionary", - dParam: { sType: "extended", oDict: dSavedDictionary["oExtendedDictionary"] }, - dInfo: {} - }); + setDictionary("extended", dSavedDictionary["oExtendedDictionary"]); + } + if (dSavedDictionary.hasOwnProperty("oCommunityDictionary")) { + setDictionary("community", dSavedDictionary["oCommunityDictionary"]); } if (dSavedDictionary.hasOwnProperty("oPersonalDictionary")) { - xGCEWorker.postMessage({ - sCommand: "setDictionary", - dParam: { sType: "personal", oDict: dSavedDictionary["oPersonalDictionary"] }, - dInfo: {} - }); + setDictionary("personal", dSavedDictionary["oPersonalDictionary"]); } } 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("oCommunityDictionary", setSpellingDictionary); browser.storage.local.get("oPersonalDictionary", setSpellingDictionary); + browser.storage.local.get("sc_options", initSCOptions); 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("oCommunityDictionary").then(setSpellingDictionary, showError); browser.storage.local.get("oPersonalDictionary").then(setSpellingDictionary, showError); + browser.storage.local.get("sc_options").then(initSCOptions, showError); } init(); @@ -171,10 +204,11 @@ case "setOption": case "resetOptions": case "textToTest": case "fullTests": case "setDictionary": + case "setDictionaryOnOff": 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 @@ -120,11 +120,14 @@ break; case "fullTests": fullTests(dInfo); break; case "setDictionary": - setDictionary(dParam.sType, dParam.oDict, dInfo); + setDictionary(dParam.sDictionary, dParam.oDict, dInfo); + break; + case "setDictionaryOnOff": + setDictionaryOnOff(dParam.sDictionary, dParam.bActivate, dInfo); break; case "getSpellSuggestions": getSpellSuggestions(dParam.sWord, dInfo); break; case "getListOfTokens": @@ -304,35 +307,66 @@ } // SpellChecker -function setDictionary (sType, oDict, dInfo) { +function setDictionary (sDictionary, oDict, dInfo) { + if (!oSpellChecker) { + postMessage(createResponse("setDictionary", "# Error. SpellChecker not loaded.", dInfo, true)); + return; + } + switch (sDictionary) { + case "main": + oSpellChecker.setMainDictionary(oDict); + break; + case "extended": + oSpellChecker.setExtendedDictionary(oDict); + break; + case "community": + oSpellChecker.setCommunityDictionary(oDict); + break; + case "personal": + oSpellChecker.setPersonalDictionary(oDict); + break; + default: + console.log("[worker] setDictionary: Unknown dictionary"); + } + postMessage(createResponse("setDictionary", true, dInfo, true)); +} + +function setDictionaryOnOff (sDictionary, bActivate, 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; + console.log(sDictionary, bActivate); + switch (sDictionary) { case "extended": - oSpellChecker.setExtendedDictionary(oDict); - postMessage(createResponse("setDictionary", true, dInfo, true)); + if (bActivate) { + oSpellChecker.activateExtendedDictionary(); + } else { + oSpellChecker.deactivateExtendedDictionary(); + } break; case "community": - oSpellChecker.setCommunityDictionary(oDict); - postMessage(createResponse("setDictionary", true, dInfo, true)); + if (bActivate) { + oSpellChecker.activateCommunityDictionary(); + } else { + oSpellChecker.deactivateCommunityDictionary(); + } break; case "personal": - oSpellChecker.setPersonalDictionary(oDict); - postMessage(createResponse("setDictionary", true, dInfo, true)); + if (bActivate) { + oSpellChecker.activatePersonalDictionary(); + } else { + oSpellChecker.deactivatePersonalDictionary(); + } break; default: - console.log("[worker] setDictionary: Unknown command"); + console.log("[worker] setDictionaryOnOff: Unknown dictionary"); } + postMessage(createResponse("setDictionary", true, dInfo, true)); } function getSpellSuggestions (sWord, dInfo) { if (!oSpellChecker) { postMessage(createResponse("getSpellSuggestions", "# Error. SpellChecker not loaded.", dInfo, true)); Index: gc_lang/fr/webext/panel/main.js ================================================================== --- gc_lang/fr/webext/panel/main.js +++ gc_lang/fr/webext/panel/main.js @@ -52,10 +52,20 @@ sCommand: "setOption", dParam: {sOptName: xElem.dataset.option, bValue: xElem.checked}, dInfo: {} }); } + } + else if (xElem.id.endsWith("_dic")) { + if (xElem.dataset.dictionary) { + storeSCOptions(); + browser.runtime.sendMessage({ + sCommand: "setDictionaryOnOff", + dParam: {sDictionary: xElem.dataset.dictionary, bActivate: xElem.checked}, + dInfo: {} + }); + } } else if (xElem.id.startsWith("ui_option_")) { storeUIOptions(); } else if (xElem.id.startsWith("link_")) { @@ -132,10 +142,13 @@ displayGCOptionsLoadedFromStorage(); } else if (sPageName == "ui_options_page") { displayUIOptionsLoadedFromStorage(); } + else if (sPageName == "sc_options_page") { + displaySCOptionsLoadedFromStorage(); + } } catch (e) { showError(e); } } @@ -173,11 +186,10 @@ /* UI options */ - function displayUIOptionsLoadedFromStorage () { if (bChrome) { browser.storage.local.get("ui_options", displayUIOptions); return; } @@ -198,12 +210,44 @@ } } function storeUIOptions () { browser.storage.local.set({"ui_options": { - textarea: ui_option_textarea.checked, - editablenode: ui_option_editablenode.checked + textarea: document.getElementById("ui_option_textarea").checked, + editablenode: document.getElementById("ui_option_editablenode").checked + }}); +} + + +/* + SC Options +*/ +function displaySCOptionsLoadedFromStorage () { + if (bChrome) { + browser.storage.local.get("sc_options", displaySCOptions); + return; + } + let xPromise = browser.storage.local.get("sc_options"); + xPromise.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_dic; + //document.getElementById("community_dic").checked = dOptions.community_dic; + document.getElementById("personal_dic").checked = dOptions.personal; +} + +function storeSCOptions () { + browser.storage.local.set({"sc_options": { + extended: false, + community: false, + personal: document.getElementById("personal_dic").checked }}); } /*