Index: gc_core/js/lang_core/gc_engine.js ================================================================== --- gc_core/js/lang_core/gc_engine.js +++ gc_core/js/lang_core/gc_engine.js @@ -33,15 +33,16 @@ const _zBeginOfParagraph = new RegExp ("^[-  –—.,;?!…]*", "ig"); const _zEndOfParagraph = new RegExp ("[-  .,;?!…–—]*$", "ig"); // grammar rules and dictionary //const _rules = require("./gc_rules.js"); +let _sContext = ""; // what software is running const _rules = require("resource://grammalecte/${lang}/gc_rules.js"); -let _dOptions = gc_options.dOpt._shallowCopy(); // duplication necessary, to be able to reset to default +let _dOptions = null; let _aIgnoredRules = new Set(); let _oDict = null; -let _dAnalyses = new Map(); // cache for data from dictionary +let _dAnalyses = new Map(); // cache for data from dictionary ///// Parsing function parse (sText, sCountry="${country_default}", bDebug=false, bContext=false) { @@ -293,13 +294,15 @@ } //////// init -function load () { +function load (sContext="JavaScript") { try { _oDict = new ibdawg.IBDAWG("${dic_name}.json"); + _sContext = sContext; + _dOptions = gc_options.getOptions(sContext)._shallowCopy(); // duplication necessary, to be able to reset to default } catch (e) { helpers.logerror(e); } } @@ -317,15 +320,15 @@ function getOptions () { return _dOptions; } function getDefaultOptions () { - return gc_options.dOpt._shallowCopy(); + return gc_options.getOptions(_sContext)._shallowCopy(); } function resetOptions () { - _dOptions = gc_options.dOpt._shallowCopy(); + _dOptions = gc_options.getOptions(_sContext)._shallowCopy(); } function getDictionary () { return _oDict; } Index: gc_core/js/lang_core/gc_options.js ================================================================== --- gc_core/js/lang_core/gc_options.js +++ gc_core/js/lang_core/gc_options.js @@ -1,13 +1,24 @@ // Options for Grammalecte ${map} + +function getOptions (sContext="JavaScript") { + if (dOpt.hasOwnProperty(sContext)) { + return dOpt[sContext]; + } + return dOpt["JavaScript"]; +} const lStructOpt = ${lStructOpt}; -const dOpt = new Map (${dOptJavaScript}); +const dOpt = { + "JavaScript": new Map (${dOptJavaScript}), + "Firefox": new Map (${dOptFirefox}), + "Thunderbird": new Map (${dOptThunderbird}), +} const dOptLabel = ${dOptLabel}; +exports.getOptions = getOptions; exports.lStructOpt = lStructOpt; -exports.dOpt = dOpt; exports.dOptLabel = dOptLabel; Index: gc_core/py/lang_core/gc_engine.py ================================================================== --- gc_core/py/lang_core/gc_engine.py +++ gc_core/py/lang_core/gc_engine.py @@ -27,12 +27,13 @@ name = "${name}" version = "${version}" author = "${author}" # grammar rules and dictionary -_rules = None -_dOptions = dict(gc_options.dOpt) # duplication necessary, to be able to reset to default +_sContext = "" # what software is running +_rules = None # module gc_rules +_dOptions = None _aIgnoredRules = set() _oDict = None _dAnalyses = {} # cache for data from dictionary @@ -283,14 +284,18 @@ _createError = _createWriterError except ImportError: _createError = _createDictError -def load (): +def load (sContext="Python"): global _oDict + global _sContext + global _dOptions try: _oDict = IBDAWG("${dic_name}.bdic") + _sContext = sContext + _dOptions = dict(gc_options.getOptions(sContext)) # duplication necessary, to be able to reset to default except: traceback.print_exc() def setOption (sOpt, bVal): @@ -307,11 +312,11 @@ def getOptions (): return _dOptions def getDefaultOptions (): - return dict(gc_options.dOpt) + return dict(gc_options.getOptions(_sContext)) def getOptionsLabels (sLang): return gc_options.getUI(sLang) @@ -322,11 +327,11 @@ echo("") def resetOptions (): global _dOptions - _dOptions = dict(gc_options.dOpt) + _dOptions = dict(gc_options.getOptions(_sContext)) def getDictionary (): return _oDict Index: gc_core/py/lang_core/gc_options.py ================================================================== --- gc_core/py/lang_core/gc_options.py +++ gc_core/py/lang_core/gc_options.py @@ -2,11 +2,24 @@ def getUI (sLang): if sLang in _dOptLabel: return _dOptLabel[sLang] return _dOptLabel["fr"] + + +def getOptions (sContext="Python"): + if sContext in dOpt: + return dOpt[sContext] + return dOpt["Python"] + lStructOpt = ${lStructOpt} -dOpt = ${dOptPython} + +dOpt = { + "Python": ${dOptPython}, + "Server": ${dOptServer}, + "Writer": ${dOptWriter} +} + _dOptLabel = ${dOptLabel} Index: gc_core/py/oxt/Grammalecte.py ================================================================== --- gc_core/py/oxt/Grammalecte.py +++ gc_core/py/oxt/Grammalecte.py @@ -31,11 +31,11 @@ l = gce.locales[i] self.locales.append(Locale(l[0], l[1], l[2])) self.locales = tuple(self.locales) xCurCtx = uno.getComponentContext() # init - gce.load() + gce.load("Writer") # GC options # opt_handler.load(xCurCtx) dOpt = Options.load(xCurCtx) gce.setOptions(dOpt) # store for results of big paragraphs Index: gc_core/py/oxt/Options.py ================================================================== --- gc_core/py/oxt/Options.py +++ gc_core/py/oxt/Options.py @@ -139,20 +139,22 @@ print("Wrong command: " + xActionEvent.ActionCommand) except: traceback.print_exc() def _setDefault (self): + dOpt = gce.gc_options.getOptions("Writer") for w in self.lxOptions: - w.State = gce.gc_options.dOpt.get(w.Name, False) + w.State = dOpt.get(w.Name, False) def load (self, sLang): try: xChild = self.xNode.getByName(sLang) - for sKey in gce.gc_options.dOpt: + dOpt = gce.gc_options.getOptions("Writer") + for sKey in dOpt: sValue = xChild.getPropertyValue(sKey) if sValue == '': - if gce.gc_options.dOpt[sKey]: + if dOpt[sKey]: sValue = 1 else: sValue = 0 options[sKey] = bool(int(sValue)) except: Index: gc_lang/fr/rules.grx ================================================================== --- gc_lang/fr/rules.grx +++ gc_lang/fr/rules.grx @@ -58,45 +58,45 @@ OPTGROUP/misc: date mc OPTGROUP/debug: idrule # pour l’instant, seuls les colonnes Python et JavaScript sont utiles -OPTSOFTWARE: Python JavaScript Writer Firefox Thunderbird -OPT/typo: True True True True True -OPT/apos: True True True True True -OPT/esp: True False True False False -OPT/tab: False False True False False -OPT/nbsp: True False True False False -OPT/tu: True True True True True -OPT/maj: True True True True True -OPT/num: True True True True True -OPT/virg: True True True True True -OPT/unit: True False True False False -OPT/nf: True True True True True -OPT/liga: False False False False False -OPT/mapos: False False False False False -OPT/chim: False False False False False -OPT/ocr: False False False False False -OPT/conf: True True True True True -OPT/sgpl: True True True True True -OPT/gn: True True True True True -OPT/infi: True True True True True -OPT/conj: True True True True True -OPT/ppas: True True True True True -OPT/imp: True True True True True -OPT/inte: True True True True True -OPT/vmode: True True True True True -OPT/bs: True True True True True -OPT/pleo: True True True True True -OPT/redon1: False False False False False -OPT/redon2: False False False False False -OPT/neg: False False False False False -OPT/date: True True True True True -OPT/mc: False False False False False -OPT/idrule: False False False False False -OPT/html: False True False True True -OPT/latex: False False False False False +OPTSOFTWARE: Python Server Writer JavaScript Firefox Thunderbird +OPT/typo: True True True True True True +OPT/apos: True True True True True True +OPT/esp: True True True False False False +OPT/tab: False True False False False False +OPT/nbsp: True True True False False False +OPT/tu: True True True True True True +OPT/maj: True True True True True True +OPT/num: True True True True True True +OPT/virg: True True True True True True +OPT/unit: True True True False False False +OPT/nf: True True True True True True +OPT/liga: False False False False False False +OPT/mapos: False False False False False False +OPT/chim: False False False False False False +OPT/ocr: False False False False False False +OPT/conf: True True True True True True +OPT/sgpl: True True True True True True +OPT/gn: True True True True True True +OPT/infi: True True True True True True +OPT/conj: True True False True True True +OPT/ppas: True True True True True True +OPT/imp: True True True True True True +OPT/inte: True True True True True True +OPT/vmode: True True True True True True +OPT/bs: True True True True True True +OPT/pleo: True True True True True True +OPT/redon1: False False False False False False +OPT/redon2: False False False False False False +OPT/neg: False False False False False False +OPT/date: True True True True True True +OPT/mc: False False False False False False +OPT/idrule: False False False False False False +OPT/html: False False False True True True +OPT/latex: False False False False False False # Priority: from 0 to 9. Default priority is 4. OPTPRIORITY/tu: 6 OPTPRIORITY/conf: 5 OPTPRIORITY/ocr: 3 Index: gc_lang/fr/tb/content/overlay.js ================================================================== --- gc_lang/fr/tb/content/overlay.js +++ gc_lang/fr/tb/content/overlay.js @@ -47,11 +47,11 @@ loadGC: function () { if (this.xGCEWorker === null) { // Grammar checker echo('Loading Grammalecte'); this.xGCEWorker = new BasePromiseWorker('chrome://promiseworker/content/gce_worker.js'); - let xPromise = this.xGCEWorker.post('loadGrammarChecker', [prefs.getCharPref("sGCOptions")]); + let xPromise = this.xGCEWorker.post('loadGrammarChecker', [prefs.getCharPref("sGCOptions"), "Thunderbird"]); xPromise.then( function (aVal) { echo(aVal); prefs.setCharPref("sGCOptions", aVal); }, Index: gc_lang/fr/xpi/gce_worker.js ================================================================== --- gc_lang/fr/xpi/gce_worker.js +++ gc_lang/fr/xpi/gce_worker.js @@ -52,27 +52,32 @@ let oTokenizer = null; let oDict = null; let oLxg = null; -function loadGrammarChecker (sGCOptions="") { +function loadGrammarChecker (sGCOptions="", sContext="JavaScript") { if (gce === null) { - gce = require("resource://grammalecte/fr/gc_engine.js"); - helpers = require("resource://grammalecte/helpers.js"); - text = require("resource://grammalecte/text.js"); - tkz = require("resource://grammalecte/tokenizer.js"); - lxg = require("resource://grammalecte/fr/lexicographe.js"); - oTokenizer = new tkz.Tokenizer("fr"); - helpers.setLogOutput(worker.log); - gce.load(); - oDict = gce.getDictionary(); - oLxg = new lxg.Lexicographe(oDict); - if (sGCOptions !== "") { - gce.setOptions(helpers.objectToMap(JSON.parse(sGCOptions))); - } - // we always retrieve options from the gce, for setOptions filters obsolete options - return gce.getOptions()._toString(); + try { + gce = require("resource://grammalecte/fr/gc_engine.js"); + helpers = require("resource://grammalecte/helpers.js"); + text = require("resource://grammalecte/text.js"); + tkz = require("resource://grammalecte/tokenizer.js"); + lxg = require("resource://grammalecte/fr/lexicographe.js"); + oTokenizer = new tkz.Tokenizer("fr"); + helpers.setLogOutput(worker.log); + gce.load(sContext); + oDict = gce.getDictionary(); + oLxg = new lxg.Lexicographe(oDict); + if (sGCOptions !== "") { + gce.setOptions(helpers.objectToMap(JSON.parse(sGCOptions))); + } + // we always retrieve options from the gce, for setOptions filters obsolete options + return gce.getOptions()._toString(); + } + catch (e) { + worker.log("# Error: " + e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message); + } } } function parse (sText, sLang, bDebug, bContext) { let aGrammErr = gce.parse(sText, sLang, bDebug, bContext); Index: gc_lang/fr/xpi/ui.js ================================================================== --- gc_lang/fr/xpi/ui.js +++ gc_lang/fr/xpi/ui.js @@ -79,11 +79,11 @@ function loadGrammarChecker (bSetPanelOptions=false) { if (xGCEWorker === null) { // Grammar checker xGCEWorker = new BasePromiseWorker('chrome://promiseworker/content/gce_worker.js'); - let xPromise = xGCEWorker.post('loadGrammarChecker', [sp.prefs["sGCOptions"]]); + let xPromise = xGCEWorker.post('loadGrammarChecker', [sp.prefs["sGCOptions"], "Firefox"]); xPromise.then( function (aVal) { sp.prefs["sGCOptions"] = aVal; if (bSetPanelOptions) { xAboutPanel.port.emit("sendGrammarOptionsToPanel", aVal); Index: make.py ================================================================== --- make.py +++ make.py @@ -144,11 +144,11 @@ for sSection, lOpt in dOptData["lStructOpt"]: hDst.write("\n########## " + dOptData["dOptLabel"][sLang].get(sSection, sSection + "[no label found]")[0] + " ##########\n") for lLineOpt in lOpt: for sOpt in lLineOpt: hDst.write("# " + dOptData["dOptLabel"][sLang].get(sOpt, "[no label found]")[0] + "\n") - hDst.write(sOpt + " = " + ("1" if dOptData["dOptPython"].get(sOpt, None) else "0") + "\n") + hDst.write(sOpt + " = " + ("1" if dOptData["dOptServer"].get(sOpt, None) else "0") + "\n") hDst.write("html = 1\n") def createServerZip (sLang, dVars, spLangPack): "create server zip" @@ -238,10 +238,12 @@ print() dVars["pluginsJS"] = sCodePlugins # options data struct dVars["dOptJavaScript"] = json.dumps(list(dVars["dOptJavaScript"].items())) + dVars["dOptFirefox"] = json.dumps(list(dVars["dOptFirefox"].items())) + dVars["dOptThunderbird"] = json.dumps(list(dVars["dOptThunderbird"].items())) # create folder spLangPack = "grammalecte-js/"+sLang helpers.createCleanFolder(spLangPack) Index: server.py ================================================================== --- server.py +++ server.py @@ -141,11 +141,11 @@ return " " + json.dumps({ "iParagraph": iParagraph, "lGrammarErrors": aGrammErrs, "lSpellingErrors": aSpellErrs }, ensure_ascii=False) if __name__ == '__main__': - gce.load() + gce.load("Server") echo("Grammalecte v{}".format(gce.version)) dServerOptions = getServerOptions() dGCOptions = getConfigOptions("fr") if dGCOptions: gce.setOptions(dGCOptions) Index: server_options.fr.ini ================================================================== --- server_options.fr.ini +++ server_options.fr.ini @@ -8,11 +8,11 @@ # Apostrophe typographique apos = 1 # Espaces surnuméraires esp = 1 # Tabulations surnuméraires -tab = 0 +tab = 1 # Espaces insécables nbsp = 1 # Espaces insécables avant unités de mesure unit = 1 # Traits d’union