Index: gc_lang/fr/tb/content/spellchecker.js ================================================================== --- gc_lang/fr/tb/content/spellchecker.js +++ gc_lang/fr/tb/content/spellchecker.js @@ -15,10 +15,11 @@ */ "use strict"; /* +// Loaded in another file const Cc = Components.classes; const Ci = Components.interfaces; const Cu = Components.utils; const { require } = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {}); */ @@ -25,34 +26,27 @@ const FileUtils = Cu.import("resource://gre/modules/FileUtils.jsm").FileUtils; const AddonManager = Cu.import("resource://gre/modules/AddonManager.jsm").AddonManager; -/* -const parser = Cc["@mozilla.org/parserutils;1"].getService(Ci.nsIParserUtils); -const persodict = Cc["@mozilla.org/spellchecker/personaldictionary;1"].getService(Ci.mozIPersonalDictionary); -*/ - -//const system = require("sdk/system"); - var oSpellControl = { xSCEngine: null, init: function () { if (this.xSCEngine === null) { try { let sSpellchecker = "@mozilla.org/spellchecker/myspell;1"; if ("@mozilla.org/spellchecker/hunspell;1" in Cc) { - sSpellchecker = "@mozilla.org/spellchecker/hunspell;1"; + sSpellchecker = "@mozilla.org/spellchecker/hunspell;1"; } if ("@mozilla.org/spellchecker/engine;1" in Cc) { - sSpellchecker = "@mozilla.org/spellchecker/engine;1"; + sSpellchecker = "@mozilla.org/spellchecker/engine;1"; } this.xSCEngine = Cc[sSpellchecker].getService(Ci.mozISpellCheckingEngine); } catch (e) { - echo("Can’t initiate the spellchecker."); + console.log("Can’t initiate the spellchecker."); Cu.reportError(e); } } }, getDictionariesList: function () { @@ -77,12 +71,12 @@ catch (e) { Cu.reportError(e); return false; } } else { - echo("Warning. No dictionary for locale: " + sLocale); - echo("Existing dictionaries: " + this.getDictionariesList().join(" | ")); + console.log("Warning. No dictionary for locale: " + sLocale); + console.log("Existing dictionaries: " + this.getDictionariesList().join(" | ")); } return false; }, check: function (sWord) { // todo: check in personal dict? @@ -97,11 +91,11 @@ suggest: function (sWord) { try { let lSugg = {}; this.xSCEngine.suggest(sWord, lSugg, {}); return lSugg.value; - // lSugg.value is a JavaScript Array of strings + // lSugg.value is a JavaScript Array of strings } catch (e) { Cu.reportError(e); return ['#Erreur.']; } @@ -110,11 +104,11 @@ try { let xNsiFolder = new FileUtils.File(sFolder); this.xSCEngine.addDirectory(xNsiFolder); } catch (e) { - echo("Unable to add directory: " + sFolder); + console.log("Unable to add directory: " + sFolder); Cu.reportError(e); } }, removeDirectory: function (sFolder) { // does not work but no exception raised (bug?) @@ -121,35 +115,37 @@ try { let xNsiFolder = new FileUtils.File(sFolder); this.xSCEngine.removeDirectory(xNsiFolder); } catch (e) { - echo("Unable to remove directory: " + sFolder); + console.log("Unable to remove directory: " + sFolder); Cu.reportError(e); } }, setExtensionDictFolder: function (sDictName, bActivate) { try { let that = this; let sPath = "/content/dictionaries/" + sDictName; AddonManager.getAddonByID("French-GC-TB@grammalecte.net", function (addon) { let xURI = addon.getResourceURI(sPath); - console.log("> " + xURI.path); - let sFolder = xURI.path; - //if (system.platform === "winnt") { - if (sFolder) { - sFolder = sFolder.slice(1).replace(/\//g, "\\\\"); - } - console.log("> " + sFolder); - if (bActivate) { - that.addDirectory(sFolder); - } else { - that.removeDirectory(sFolder); + //console.log(xURI); + let sFolder = xURI.filePath; + if (sFolder !== undefined) { + if (/^\/[A-Z]:\//.test(sFolder)) { + // Windows path + sFolder = sFolder.slice(1).replace(/\//g, "\\\\"); + } + console.log("folder: " + sFolder); + if (bActivate) { + that.addDirectory(sFolder); + } else { + that.removeDirectory(sFolder); + } } }); } catch (e) { - echo("Unable to add extension folder"); + console.log("Unable to add extension folder"); Cu.reportError(e); } } };