Grammalecte  Check-in [833a8d3dce]

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

Overview
Comment:[fx] lexicon editor: dictionary selector
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | comdic
Files: files | file ages | folders
SHA3-256:833a8d3dce41f1dc8c422913f857c2983cf99c1aff9aebd53cf3f20ab1aef6bf
User & Date: olr 2018-12-10 11:32:37
Context
2018-12-10
14:27
merge trunk check-in: ad98751778 user: olr tags: comdic
11:32
[fx] lexicon editor: dictionary selector check-in: 833a8d3dce user: olr tags: comdic, fx
2018-12-08
18:09
[fx] storing custom dictionaries rework check-in: ac510fca99 user: olr tags: comdic, fx
Changes

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

   142    142       });
   143    143   }
   144    144   
   145    145   function setSpellingDictionaries (oData) {
   146    146       if (oData.hasOwnProperty("oPersonalDictionary")) {
   147    147           // deprecated
   148    148           console.log("personal dictionary migration");
   149         -        browser.storage.local.set({ "oDictionaries": { "__personal__": oData["oPersonalDictionary"] } });
          149  +        browser.storage.local.set({ "dictionaries": { "__personal__": oData["oPersonalDictionary"] } });
   150    150           setDictionary("personal", oData["oPersonalDictionary"]);
   151    151           browser.storage.local.remove("oPersonalDictionary");
   152    152       }
   153         -    if (oData.hasOwnProperty("oDictionaries")) {
   154         -        if (oData.oDictionaries.hasOwnProperty("__personal__")) {
   155         -            setDictionary("personal", oData.oDictionaries["__personal__"]);
          153  +    if (oData.hasOwnProperty("dictionaries")) {
          154  +        if (oData.dictionaries.hasOwnProperty("__personal__")) {
          155  +            setDictionary("personal", oData.dictionaries["__personal__"]);
   156    156           }
   157         -        if (oData.oDictionaries.hasOwnProperty("__community__")) {
   158         -            setDictionary("personal", oData.oDictionaries["__community__"]);
          157  +        if (oData.dictionaries.hasOwnProperty("__community__")) {
          158  +            setDictionary("personal", oData.dictionaries["__community__"]);
   159    159           }
   160    160       }
   161    161   }
   162    162   
   163    163   function init () {
   164    164       if (bChrome) {
   165    165           browser.storage.local.get("gc_options", initGrammarChecker);
   166    166           browser.storage.local.get("ui_options", initUIOptions);
   167         -        browser.storage.local.get("oDictionaries", setSpellingDictionaries);
          167  +        browser.storage.local.get("dictionaries", setSpellingDictionaries);
   168    168           browser.storage.local.get("oPersonalDictionary", setSpellingDictionaries); // deprecated
   169    169           browser.storage.local.get("sc_options", initSCOptions);
   170    170           return;
   171    171       }
   172    172       browser.storage.local.get("gc_options").then(initGrammarChecker, showError);
   173    173       browser.storage.local.get("ui_options").then(initUIOptions, showError);
   174         -    browser.storage.local.get("oDictionaries").then(setSpellingDictionaries, showError);
          174  +    browser.storage.local.get("dictionaries").then(setSpellingDictionaries, showError);
   175    175       browser.storage.local.get("oPersonalDictionary").then(setSpellingDictionaries, showError); // deprecated
   176    176       browser.storage.local.get("sc_options").then(initSCOptions, showError);
   177    177   }
   178    178   
   179    179   init();
   180    180   
   181    181   

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

    46     46       font: bold 20px "Trebuchet MS", "Fira Sans", "Liberation Sans", sans-serif;
    47     47   }
    48     48   h3 {
    49     49       margin: 3px 0 2px 0;
    50     50       color: hsl(210, 50%, 50%);
    51     51       font: bold 16px "Trebuchet MS", "Fira Sans", "Liberation Sans", sans-serif;
    52     52   }
           53  +
           54  +#dic_selector {
           55  +    color: hsl(210, 50%, 50%);
           56  +    font: bold 16px "Trebuchet MS", "Fira Sans", "Liberation Sans", sans-serif;
           57  +}
    53     58   
    54     59   details {
    55     60       font-size: 11px;
    56     61       font-variant: small-caps;
    57     62       color: hsl(210, 50%, 50%);
    58     63       cursor: pointer;
    59     64   }
................................................................................
    63     68       color: hsl(210, 0%, 0%);
    64     69       cursor: auto;
    65     70   }
    66     71   details.inline {
    67     72       padding: 3px;
    68     73       width: 260px;
    69     74   }
           75  +
    70     76   
    71     77   
    72     78   /*
    73     79       Main buttons
    74     80   */
    75     81   #buttons {
    76     82       padding: 10px 0;
................................................................................
   245    251       background-color: hsl(150, 60%, 40%);
   246    252       color: hsl(150, 60%, 90%);
   247    253       box-shadow: 0 0 2px hsl(150, 60%, 50%);
   248    254   }
   249    255   
   250    256   
   251    257   #lexicon_page {
   252         -    
          258  +
   253    259   }
   254    260   
   255    261   
   256    262   /*
   257    263       Search page
   258    264   */
   259    265   #search_page {

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

    10     10   
    11     11       <div class="inbox">
    12     12   
    13     13         <h1>Éditeur lexical</h1>
    14     14   
    15     15         <div class="big_block">
    16     16           <div class="dic_container">
    17         -          <div><h3>Dictionnaire personnel</h3></div>
    18         -          <div>Date : <span id="dic_save_date">—</span></div>
           17  +          <div><h3>Dictionnaire</h3></div>
           18  +          <div>
           19  +            <select id="dic_selector">
           20  +              <option value="__personal__">personnel</option>
           21  +              <option value="__community__">communautaire</option>
           22  +            </select>
           23  +          </div>
           24  +          <div>[<span id="dic_save_date">—</span>]</div>
    19     25             <div><span id="dic_num_entries">0</span> entrées</div>
    20     26             <div>
    21     27               <input type="file" id="import_input" accept=".json" style="display: none;">
    22     28               <label id="import_button" for="import_input">Importer</label>
    23     29             </div>
    24     30             <div id="export_button">Exporter</div>
    25     31           </div>

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

   123    123           this.xTable.appendChild(xRowNode);
   124    124       }
   125    125   
   126    126       clear () {
   127    127           while (this.xTable.firstChild) {
   128    128               this.xTable.removeChild(this.xTable.firstChild);
   129    129           }
          130  +        this.lEntry = [];
          131  +        this.nEntry = 0;
   130    132           this.iEntryIndex = 0;
   131    133           this._createHeader();
          134  +        this.showEntryNumber();
   132    135       }
   133    136   
   134    137       fill (lFlex) {
   135    138           this.clear();
   136    139           if (lFlex.length > 0) {
   137    140               this.xProgressBar.max = lFlex.length;
   138    141               this.xProgressBar.value = 1;
................................................................................
   493    496   }
   494    497   
   495    498   const oDictHandler = {
   496    499       oDictionaries: null,
   497    500   
   498    501       loadDictionaries: function () {
   499    502           if (bChrome) {
   500         -            browser.storage.local.get("oDictionaries", this._loadDictionaries.bind(this));
          503  +            browser.storage.local.get("dictionaries", this._loadDictionaries.bind(this));
   501    504               return;
   502    505           }
   503         -        let xPromise = browser.storage.local.get("oDictionaries");
          506  +        let xPromise = browser.storage.local.get("dictionaries");
   504    507           xPromise.then(this._loadDictionaries.bind(this), showError);
   505    508       },
   506    509   
   507    510       _loadDictionaries: function (oResult) {
   508         -        if (!oResult.hasOwnProperty("oDictionaries")) {
          511  +        if (!oResult.hasOwnProperty("dictionaries")) {
   509    512               return;
   510    513           }
   511         -        this.oDictionaries = oResult.oDictionaries;
          514  +        this.oDictionaries = oResult.dictionaries;
   512    515           oBinaryDict.load("__personal__");
   513    516       },
   514    517   
   515    518       getDictionary: function (sName) {
   516         -        console.log("load "+sName);
   517    519           if (this.oDictionaries  &&  this.oDictionaries.hasOwnProperty(sName)) {
   518         -            console.log(this.oDictionaries[sName]);
          520  +            //console.log(this.oDictionaries[sName]);
   519    521               return this.oDictionaries[sName];
   520    522           }
   521    523           return null;
   522    524       },
   523    525   
   524    526       saveDictionary: function (sName, oJSON) {
   525    527           this.oDictionaries[sName] = oJSON;
   526    528           if (sName == "__personal__") {
   527    529               browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "personal", oDict: oJSON}, dInfo: {} });
   528         -        } else {
   529         -            // rebuild now?
   530         -            //browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "community", oDict: oJSON}, dInfo: {} });
          530  +        }
          531  +        else if (sName == "__community__") {
          532  +            browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "community", oDict: oJSON}, dInfo: {} });
          533  +        }
          534  +        else {
          535  +            // TODO: merge sub-dictionaries
   531    536           }
   532    537           this.storeDictionaries();
   533    538       },
   534    539   
   535    540       storeDictionaries: function () {
   536         -        browser.storage.local.set({ "oDictionaries": this.oDictionaries });
          541  +        browser.storage.local.set({ "dictionaries": this.oDictionaries });
   537    542       }
   538    543   }
   539    544   
   540    545   const oBinaryDict = {
   541    546   
   542    547       oIBDAWG: null,
   543    548       sName: null,
   544    549   
   545         -    load: function (sName="__personal__") {
          550  +    load: function (sName) {
          551  +        console.log("lexicon editor, load: " + sName);
   546    552           this.sName = sName;
   547    553           let oJSON = oDictHandler.getDictionary(sName);
   548    554           if (oJSON) {
   549         -            console.log("parse");
   550    555               this.parseDict(oJSON);
   551    556           } else {
   552    557               oLexiconTable.clear();
   553    558               this.setDictData(0, "[néant]");
   554    559           }
   555    560       },
   556    561   
................................................................................
   600    605               hideElement("export_button");
   601    606           } else {
   602    607               showElement("export_button");
   603    608           }
   604    609       },
   605    610   
   606    611       listen: function () {
          612  +        document.getElementById("dic_selector").addEventListener("change", () => {this.load(document.getElementById("dic_selector").value)}, false);
   607    613           document.getElementById("save_button").addEventListener("click", () => { this.build(); }, false);
   608    614           document.getElementById("export_button").addEventListener("click", () => { this.export(); }, false);
   609    615           document.getElementById("import_input").addEventListener("change", () => { this.import(); }, false);
   610    616       },
   611    617   
   612    618       build: function () {
   613    619           let xProgressNode = document.getElementById("wait_progress");
   614    620           let lEntry = oLexiconTable.getEntries();
   615    621           if (lEntry.length > 0) {
   616         -            let oDAWG = new DAWG(lEntry, "S", "fr", "Français", "Dictionnaire personnel", xProgressNode);
          622  +            let oDAWG = new DAWG(lEntry, "S", "fr", "Français", this.sName, xProgressNode);
   617    623               let oJSON = oDAWG.createBinaryJSON(1);
   618    624               oDictHandler.saveDictionary(this.sName, oJSON);
   619    625               this.oIBDAWG = new IBDAWG(oJSON);
   620    626               this.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate);
   621    627           } else {
   622    628               oDictHandler.saveDictionary(this.sName, null);
   623    629               this.setDictData(0, "[néant]");