Grammalecte  Check-in [395558764c]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[fx][graphspell][js] spelling selector
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx | graphspell
Files: files | file ages | folders
SHA3-256:395558764c271e723c458a99de2cd4c4e33c21f35dfa9fa38f4bbe98271efdc9
User & Date: olr 2019-10-09 16:58:07
Context
2019-10-10
11:21
[fr] ajustements et faux positif check-in: e1d086f4bb user: olr tags: fr, trunk
2019-10-09
16:58
[fx][graphspell][js] spelling selector check-in: 395558764c user: olr tags: fx, graphspell, trunk
11:35
[fr] ajustements check-in: 97aba9fb36 user: olr tags: fr, trunk
Changes

Changes to gc_lang/fr/webext/background.js.

   129    129           browser.storage.local.get("ui_options").then(this._initUIOptions, showError);
   130    130           browser.storage.local.get("autorefresh_option").then(this._initUIOptions, showError);
   131    131       },
   132    132   
   133    133       initGrammarChecker: function () {
   134    134           if (bChrome) {
   135    135               browser.storage.local.get("gc_options", this._initGrammarChecker);
          136  +            browser.storage.local.get("main_dic_name", this._setSpellingDictionaries);
   136    137               browser.storage.local.get("personal_dictionary", this._setSpellingDictionaries);
   137    138               browser.storage.local.get("community_dictionary", this._setSpellingDictionaries);
   138    139               browser.storage.local.get("oPersonalDictionary", this._setSpellingDictionaries); // deprecated
   139    140               browser.storage.local.get("sc_options", this._initSCOptions);
   140    141               return;
   141    142           }
   142    143           browser.storage.local.get("gc_options").then(this._initGrammarChecker, showError);
          144  +        browser.storage.local.get("main_dic_name", this._setSpellingDictionaries);
   143    145           browser.storage.local.get("personal_dictionary").then(this._setSpellingDictionaries, showError);
   144    146           browser.storage.local.get("community_dictionary").then(this._setSpellingDictionaries, showError);
   145    147           browser.storage.local.get("oPersonalDictionary").then(this._setSpellingDictionaries, showError); // deprecated
   146    148           browser.storage.local.get("sc_options").then(this._initSCOptions, showError);
   147    149       },
   148    150   
   149    151       _initUIOptions: function (oSavedOptions) {
................................................................................
   181    183           if (oData.hasOwnProperty("oPersonalDictionary")) {
   182    184               // deprecated (to be removed in 2020)
   183    185               console.log("personal dictionary migration");
   184    186               browser.storage.local.set({ "personal_dictionary": oData["oPersonalDictionary"] });
   185    187               oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sDictionary: "personal", oDict: oData["oPersonalDictionary"] }, dInfo: {} });
   186    188               browser.storage.local.remove("oPersonalDictionary");
   187    189           }
          190  +        if (oData.hasOwnProperty("main_dic_name")) {
          191  +            oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sDictionary: "main", oDict: oData["main_dic_name"] }, dInfo: {sExtPath: browser.extension.getURL("")} });
          192  +        }
   188    193           if (oData.hasOwnProperty("community_dictionary")) {
   189    194               oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sDictionary: "community", oDict: oData["community_dictionary"] }, dInfo: {} });
   190    195           }
   191    196           if (oData.hasOwnProperty("personal_dictionary")) {
   192    197               oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sDictionary: "personal", oDict: oData["personal_dictionary"] }, dInfo: {} });
   193    198           }
   194    199       },

Changes to gc_lang/fr/webext/gce_worker.js.

   351    351       if (!oSpellChecker) {
   352    352           postMessage(createResponse("setDictionary", "# Error. SpellChecker not loaded.", dInfo, true));
   353    353           return;
   354    354       }
   355    355       //console.log("setDictionary", sDictionary);
   356    356       switch (sDictionary) {
   357    357           case "main":
   358         -            oSpellChecker.setMainDictionary(oDict);
          358  +            oSpellChecker.setMainDictionary(oDict, dInfo["sExtPath"]+"/grammalecte/graphspell/_dictionaries");
   359    359               break;
   360    360           case "community":
   361    361               oSpellChecker.setCommunityDictionary(oDict);
   362    362               break;
   363    363           case "personal":
   364    364               oSpellChecker.setPersonalDictionary(oDict);
   365    365               break;

Changes to gc_lang/fr/webext/panel/main.css.

   243    243       padding: 5px 10px;
   244    244       border-radius: 3px;
   245    245       font-size: 16px;
   246    246       text-align: center;
   247    247       cursor: pointer;
   248    248   }
   249    249   
   250         -
   251    250   .option_section {
   252    251       padding: 10px;
   253    252       margin-top: 10px;
   254    253       border-radius: 5px;
   255    254       background-color: hsl(210, 20%, 96%);
   256    255   }
   257    256   .option_section label {
................................................................................
   261    260       font-weight: bold;
   262    261   }
   263    262   .option_description {
   264    263       padding: 0 0 0 20px;
   265    264       color: hsl(0, 0%, 0%);
   266    265       font-size: 12px;
   267    266   }
          267  +
          268  +
          269  +#spelling_section {
          270  +    padding: 5px 0 0 20px;
          271  +}
          272  +#spelling_section .subheader {
          273  +    font-size: 14px;
          274  +    font-weight: bold;
          275  +    color: hsl(210, 20%, 50%);
          276  +}
          277  +#spelling_section .radiolike {
          278  +    display: inline-block;
          279  +    padding: 3px 5px;
          280  +    font-size: 11px;
          281  +    color: hsl(210, 10%, 96%);
          282  +    background-color: hsl(210, 10%, 80%);
          283  +    border-radius: 3px;
          284  +    cursor: pointer;
          285  +}
          286  +#spelling_section .radiolike:hover {
          287  +    color: hsl(210, 10%, 100%);
          288  +    background-color: hsl(210, 10%, 50%);
          289  +    box-shadow: 0 0 3px 3px hsl(210, 30%, 85%);
          290  +}
          291  +#spelling_section .selected {
          292  +    color: hsl(210, 10%, 100%);
          293  +    background-color: hsl(210, 50%, 50%);
          294  +}
          295  +
   268    296   
   269    297   
   270    298   /*
   271    299       Spell checking options
   272    300   */
   273    301   #sc_options_page {
   274    302       display: none;

Changes to gc_lang/fr/webext/panel/main.html.

   108    108           <section id="sc_options_page" class="page">
   109    109             <h1>OPTIONS ORTHOGRAPHIQUES</h1>
   110    110             <div id="hunspell_options">
   111    111               <h2>DICTIONNAIRES DE GRAMMALECTE</h2>
   112    112               <div class="option_section" id="main_dic_box">
   113    113                   <p><input type="checkbox" id="main_dic" data-dictionary="main" checked disabled="disabled" /> <label for="main_dic">Dictionnaire principal</label></p>
   114    114                   <p class="option_description">Environ 83 000 entrées, 500 000 flexions.<br/>Ni éditable, ni désactivable.<br/>Ce dictionnaire est créé à partir du dictionnaire orthographique pour Firefox et LibreOffice, conçu sur le <a id="link_grammalecte" class="link" data-url="http://grammalecte.net/home.php?prj=fr">site de Grammalecte</a>.</p>
          115  +                <div id="spelling_section">
          116  +                  <p class="subheader">Orthographe</p>
          117  +                  <p>
          118  +                    <div class="radiolike" id="spelling_classic" data-dicname="fr-classic.json" />Classique</div>
          119  +                    <div class="radiolike" id="spelling_reform" data-dicname="fr-reform.json" />Réforme 1990</div>
          120  +                    <div class="radiolike selected" id="spelling_allvars" data-dicname="fr-allvars.json" />Toutes variantes</div>
          121  +                  </p>
          122  +                </div>
   115    123               </div>
   116    124               <div class="option_section" id="community_dic_box">
   117    125                   <p><input type="checkbox" id="community_dic" data-dictionary="community" disabled/> <label for="community_dic" style="color: hsl(0, 0%, 70%);">Dictionnaire communautaire</label></p>
   118    126                   <p class="option_description" style="color: hsl(0, 0%, 70%);">Ce dictionnaire est composé à partir de dictionnaires communautaires disponibles en ligne aux membres.</p>
   119    127                   <p class="option_description">Non disponible. Fonctionnalité à venir.</p>
   120    128                   <div class="button_row">
   121    129                     <!--<div class="dic_button" id="dic_community_button">Éditer</div>

Changes to gc_lang/fr/webext/panel/main.js.

    20     20       Events
    21     21   */
    22     22   window.addEventListener(
    23     23       "click",
    24     24       function (xEvent) {
    25     25           let xElem = xEvent.target;
    26     26           if (xElem.id) {
           27  +            // tests
    27     28               if (xElem.id === "text_to_test_button") {
    28     29                   browser.runtime.sendMessage({
    29     30                       sCommand: "textToTest",
    30     31                       dParam: {sText: document.getElementById("text_to_test").value, sCountry: "FR", bDebug: true, bContext: false},
    31     32                       dInfo: {}
    32     33                   });
    33     34               }
................................................................................
    35     36                   document.getElementById("tests_result").textContent = "Veuillez patienter…";
    36     37                   browser.runtime.sendMessage({
    37     38                       sCommand: "fullTests",
    38     39                       dParam: {},
    39     40                       dInfo: {}
    40     41                   });
    41     42               }
           43  +            else if (xElem.id == "restart_worker") {
           44  +                browser.runtime.sendMessage({
           45  +                    sCommand: "restartWorker",
           46  +                    dParam: { "nDelayLimit": 3 },
           47  +                    dInfo: {}
           48  +                });
           49  +            }
           50  +            // grammar options
    42     51               else if (xElem.id === "default_options_button") {
    43     52                   browser.runtime.sendMessage({
    44     53                      sCommand: "resetOptions",
    45     54                      dParam: {},
    46     55                      dInfo: {}
    47     56                   });
    48     57               }
................................................................................
    51     60                       browser.runtime.sendMessage({
    52     61                           sCommand: "setOption",
    53     62                           dParam: {sOptName: xElem.dataset.option, bValue: xElem.checked},
    54     63                           dInfo: {}
    55     64                       });
    56     65                   }
    57     66               }
           67  +            // dictionaries options
    58     68               else if (xElem.id.endsWith("_dic")) {
    59     69                   if (xElem.dataset.dictionary) {
    60     70                       storeSCOptions();
    61     71                       browser.runtime.sendMessage({
    62     72                           sCommand: "setDictionaryOnOff",
    63     73                           dParam: {sDictionary: xElem.dataset.dictionary, bActivate: xElem.checked},
    64     74                           dInfo: {}
    65     75                       });
    66     76                   }
    67     77               }
           78  +            else if (xElem.id.startsWith("spelling_")) {
           79  +                updateSpellingChoiceUI(xElem.id);
           80  +                let sMainDicName = document.getElementById(xElem.id).dataset.dicname;
           81  +                browser.storage.local.set({"main_dic_name": sMainDicName});
           82  +                browser.runtime.sendMessage({
           83  +                    sCommand: "setDictionary",
           84  +                    dParam: { sDictionary: "main", oDict: sMainDicName },
           85  +                    dInfo: { sExtPath: browser.extension.getURL("") }
           86  +                });
           87  +            }
           88  +            // UI options
    68     89               else if (xElem.id.startsWith("ui_option_")) {
    69     90                   storeUIOptions();
    70     91               }
           92  +            //
    71     93               else if (xElem.id.startsWith("link_")) {
    72     94                   browser.tabs.create({url: xElem.dataset.url});
    73     95               }
    74     96               else if (xElem.id == "conj_button") {
    75     97                   browser.runtime.sendMessage({
    76     98                       sCommand: "openConjugueurTab",
    77     99                       dParam: {},
................................................................................
    95    117               else if (xElem.id == "dic_personal_button") {
    96    118                   browser.runtime.sendMessage({
    97    119                       sCommand: "openLexiconEditor",
    98    120                       dParam: { "dictionary": "__personal__"},
    99    121                       dInfo: {}
   100    122                   });
   101    123               }
   102         -            else if (xElem.id == "restart_worker") {
   103         -                browser.runtime.sendMessage({
   104         -                    sCommand: "restartWorker",
   105         -                    dParam: { "nDelayLimit": 3 },
   106         -                    dInfo: {}
   107         -                });
   108         -            }
          124  +        // change UI page
   109    125           } else if (xElem.className.startsWith("select")) {
   110    126               showPage(xElem.dataset.page);
   111    127           }/* else if (xElem.tagName === "A") {
   112    128               openURL(xElem.getAttribute("href"));
   113    129           }*/
   114    130       },
   115    131       false
................................................................................
   226    242   
   227    243   /*
   228    244       SC Options
   229    245   */
   230    246   function displaySCOptionsLoadedFromStorage () {
   231    247       if (bChrome) {
   232    248           browser.storage.local.get("sc_options", displaySCOptions);
          249  +        browser.storage.local.get("main_dic_name", displaySCOptions);
   233    250           return;
   234    251       }
   235         -    let xPromise = browser.storage.local.get("sc_options");
   236         -    xPromise.then(displaySCOptions, showError);
          252  +    browser.storage.local.get("sc_options").then(displaySCOptions, showError);
          253  +    browser.storage.local.get("main_dic_name").then(displaySCOptions, showError);
   237    254   }
   238    255   
   239    256   function displaySCOptions (dOptions) {
   240         -    if (!dOptions.hasOwnProperty("sc_options")) {
   241         -        console.log("no sc options found");
   242         -        return;
          257  +    if (dOptions.hasOwnProperty("sc_options")) {
          258  +        document.getElementById("community_dic").checked = dOptions.sc_options.community;
          259  +        document.getElementById("personal_dic").checked = dOptions.sc_options.personal;
   243    260       }
   244         -    dOptions = dOptions.sc_options;
   245         -    //document.getElementById("extended_dic").checked = dOptions.extended;
   246         -    document.getElementById("community_dic").checked = dOptions.community;
   247         -    document.getElementById("personal_dic").checked = dOptions.personal;
          261  +    if (dOptions.hasOwnProperty("main_dic_name")) {
          262  +        switch (dOptions.main_dic_name) {
          263  +            case "fr-classic.json":  updateSpellingChoiceUI("spelling_classic"); break;
          264  +            case "fr-reform.json":  updateSpellingChoiceUI("spelling_reform"); break;
          265  +            case "fr-allvars.json":  updateSpellingChoiceUI("spelling_allvars"); break;
          266  +            default:
          267  +                console.log("Unknown dictionary name:", dOptions.main_dic_name);
          268  +        }
          269  +    }
   248    270   }
   249    271   
   250    272   function storeSCOptions () {
   251    273       browser.storage.local.set({"sc_options": {
   252    274           extended: false,
   253    275           community: document.getElementById("community_dic").checked,
   254    276           personal: document.getElementById("personal_dic").checked
   255    277       }});
   256    278   }
          279  +
          280  +function updateSpellingChoiceUI (sSpellingChoice) {
          281  +    document.getElementById("spelling_classic").className = (sSpellingChoice == "spelling_classic") ? "radiolike selected" : "radiolike";
          282  +    document.getElementById("spelling_reform").className = (sSpellingChoice == "spelling_reform") ? "radiolike selected" : "radiolike";
          283  +    document.getElementById("spelling_allvars").className = (sSpellingChoice == "spelling_allvars") ? "radiolike selected" : "radiolike";
          284  +}
   257    285   
   258    286   
   259    287   /*
   260    288       GC options
   261    289   */
   262    290   function displayGCOptionsLoadedFromStorage () {
   263    291       if (bChrome) {

Changes to graphspell-js/ibdawg.js.

    94     94       }
    95     95   }
    96     96   
    97     97   
    98     98   class IBDAWG {
    99     99       // INDEXABLE BINARY DIRECT ACYCLIC WORD GRAPH
   100    100   
   101         -    constructor (param1, sPath="") {
   102         -        // param1 can be a filename or a object with all the necessary data.
          101  +    constructor (source, sPath="") {
          102  +        // <source> can be a filename or a object with all the necessary data.
   103    103           try {
   104    104               let oData = null;
   105         -            if (typeof(param1) == "string") {
          105  +            if (typeof(source) == "string") {
   106    106                   let sURL;
   107         -                if(typeof(process) !== 'undefined') {
   108         -                    sURL = (sPath !== "") ? sPath + "/" + param1 : __dirname + "/_dictionaries/"+param1;
          107  +                if (typeof(process) !== 'undefined') {
          108  +                    sURL = (sPath !== "") ? sPath + "/" + source : __dirname + "/_dictionaries/"+source;
   109    109                   } else {
   110         -                    sURL = (sPath !== "") ? sPath + "/" + param1 : "resource://grammalecte/graphspell/_dictionaries/"+param1;
          110  +                    sURL = (sPath !== "") ? sPath + "/" + source : "resource://grammalecte/graphspell/_dictionaries/"+source;
   111    111                   }
   112    112                   oData = JSON.parse(helpers.loadFile(sURL));
   113    113               } else {
   114         -                oData = param1;
          114  +                oData = source;
   115    115               }
   116    116               Object.assign(this, oData);
   117    117           }
   118    118           catch (e) {
   119    119               console.error(e);
   120    120               console.log("path: " + sPath);
   121         -            console.log("dic:" + param1.slice(0, 1000));
          121  +            console.log("dic:" + source.slice(0, 1000));
   122    122               throw Error("# Error. File not found or not loadable.\n" + e.message + "\n");
   123    123           }
   124    124           /*
   125    125               Properties:
   126    126               sName, nCompressionMethod, sHeader, lArcVal, nArcVal, sByDic, sLang, nChar, nBytesArc, nBytesNodeAddress,
   127    127               nEntry, nNode, nArc, nAff, cStemming, nTag, dChar, nBytesOffset,
   128    128           */

Changes to graphspell-js/spellchecker.js.

    52     52           // storage
    53     53           this.bStorage = false;
    54     54           this._dMorphologies = new Map();            // key: flexion, value: list of morphologies
    55     55           this._dLemmas = new Map();                  // key: flexion, value: list of lemmas
    56     56       }
    57     57   
    58     58       _loadDictionary (dictionary, sPath="", bNecessary=false) {
    59         -        // returns an IBDAWG object
           59  +        // <dictionary> can be a filename or a JSON object, returns an IBDAWG object
    60     60           if (!dictionary) {
    61     61               return null;
    62     62           }
    63     63           try {
    64     64               if (typeof(ibdawg) !== 'undefined') {
    65         -                return new ibdawg.IBDAWG(dictionary, sPath);  // dictionary can be a filename or a JSON object
           65  +                return new ibdawg.IBDAWG(dictionary, sPath);
    66     66               } else {
    67         -                return new IBDAWG(dictionary, sPath);  // dictionary can be a filename or a JSON object
           67  +                return new IBDAWG(dictionary, sPath);
    68     68               }
    69     69           }
    70     70           catch (e) {
    71     71               let sfDictionary = (typeof(dictionary) == "string") ? dictionary : dictionary.sLangName + "/" + dictionary.sFileName;
    72     72               let sErrorMessage = "Error [" + this.sLangCode + "]: <" + sfDictionary + "> not loaded.";
    73     73               if (bNecessary) {
    74     74                   throw sErrorMessage + " | " + e.message;