Grammalecte  Check-in [550fb30fe3]

Overview
Comment:[tb] lexicon editor: update
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tb | multid
Files: files | file ages | folders
SHA3-256: 550fb30fe322ebaa44b4206048aaf2eaab711844f2f02f7094da0bc625b66a8b
User & Date: olr on 2018-03-17 15:32:55
Other Links: branch diff | manifest | tags
Context
2018-03-17
16:36
[tb] lexicon editor: export (attempt with FilePicker) check-in: 7260392d1d user: olr tags: tb, multid
15:32
[tb] lexicon editor: update check-in: 550fb30fe3 user: olr tags: tb, multid
11:02
[tb] lexicon editor: update check-in: 8f2d9b2f72 user: olr tags: tb, multid
Changes

Modified gc_lang/fr/tb/content/lex_editor.js from [96f662f9f6] to [f08cbf555e].

1
2
3
4
5
6
7
8
9





10
11
12
13
14
15
16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21









+
+
+
+
+







// JavaScript

"use strict";

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("extensions.grammarchecker.");

var FileUtils = Cu.import("resource://gre/modules/FileUtils.jsm").FileUtils





/*
    Common functions
*/

function showError (e) {
    Cu.reportError(e);
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
47
48
49
50
51
52
53




54
55
56
57
58
59
60







-
-
-
-







    if (document.getElementById(sElemId)) {
        document.getElementById(sElemId).disabled = true;
    } else {
        console.log("HTML node named <" + sElemId + "> not found.")
    }
}



document.getElementById("save_button").addEventListener("click", () => { oBinaryDict.build(); }, false);



class Table {

    constructor (sNodeId, lColumn, lColumnWidth, sProgressBarId, sResultId="") {
        this.sNodeId = sNodeId;
        this.xTable = document.getElementById(sNodeId);
339
340
341
342
343
344
345

346

347
348
349
350
351
352
353
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356







+

+







                                // utilisation du générateur de conjugaison
                                let bVarPpas = document.getElementById("v_ppas").checked;
                                for (let [sFlexion, sFlexTags] of conj_generator.conjugate(this.sLemma, sVerbTag, bVarPpas)) {
                                    this.lFlexion.push([sFlexion, sFlexTags]);
                                }
                            } else {
                                // copie du motif d’un autre verbe : utilisation du conjugueur
                                console.log("pattern: " + sVerbPattern);
                                if (conj.isVerb(sVerbPattern)) {
                                    console.log("yes");
                                    let oVerb = new Verb(this.sLemma, sVerbPattern);
                                    for (let [sTag1, dFlex] of oVerb.dConj.entries()) {
                                        if (sTag1 !== ":Q") {
                                            for (let [sTag2, sConj] of dFlex.entries()) {
                                                if (sTag2.startsWith(":") && sConj !== "") {
                                                    this.lFlexion.push([sConj, ":V" + oVerb.cGroup + "_" + sVerbTag + sTag1 + sTag2]);
                                                }
453
454
455
456
457
458
459
460
461


462
463
464

465
466
467
468
469
470
471
472
473
474
475
476
477
478

479
480
481
482
483
484
485
486
487
488
489






490

491
492
493
494
495
496
497
498
499
500
456
457
458
459
460
461
462


463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481

482
483
484
485
486
487
488
489
490
491


492
493
494
495
496
497

498
499
500
501
502
503
504
505
506
507
508







-
-
+
+



+













-
+









-
-
+
+
+
+
+
+
-
+










            oLexiconTable.fill(lEntry);
            this.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate);
            enableElement("export_button");
        }
    },

    setDictData: function (nEntries, sDate) {
        document.getElementById("dic_num_entries").textContent = nEntries;
        document.getElementById("dic_save_date").textContent = sDate;
        document.getElementById("dic_num_entries").value = nEntries;
        document.getElementById("dic_save_date").value = sDate;
    },

    listen: function () {
        document.getElementById("save_button").addEventListener("click", () => { this.build(); }, false);
        document.getElementById("export_button").addEventListener("click", () => { this.export(); }, false);
        //document.getElementById("import_button").addEventListener("click", () => { this.import(); }, false);
    },

    build: function () {
        let xProgressNode = document.getElementById("wait_progress");
        let lEntry = oLexiconTable.getEntries();
        if (lEntry.length > 0) {
            let oDAWG = new DAWG(lEntry, "S", "fr", "Français", "Dictionnaire personnel", xProgressNode);
            let oJSON = oDAWG.createBinaryJSON(1);
            prefs.setCharPref("oPersonalDictionary", JSON.stringify(oJSON));
            this.oIBDAWG = new IBDAWG(oJSON);
            this.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate);
            browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sType: "personal", oDict: oJSON}, dInfo: {} });
            //browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sType: "personal", oDict: oJSON}, dInfo: {} });
        }
        enableElement("export_button");
    },

    import: function () {
        console.log("import");
    },

    export: function () {
        let xBlob = new Blob([ JSON.stringify(this.oIBDAWG.getJSON()) ], {type: 'application/json'}); 
        let sURL = URL.createObjectURL(xBlob);
        let sJSON = JSON.stringify(this.oIBDAWG.getJSON());
        let xFile = new FileUtils.File("D:\\fr.personal.json");
        xFile.createUnique(FileUtils.NORMAL_FILE_TYPE, 555);
        console.log(xFile);
        let xFile2 = new File([ sJSON ], "D:\\fr.test.personal.json", {type: 'text/plain'}); 
        let sURL = URL.createObjectURL(xFile2);
        browser.downloads.download({ filename: "fr.personal.json", url: sURL, saveAs: true });
        console.log(xFile2);
    }
}


const oLexiconTable = new Table("lexicon_table", ["Flexions", "Lemmes", "Étiquettes"], [10, 7, 10],"progress_lexicon", "num_entries");
const oGenWordsTable = new Table("generated_words_table", ["Flexions", "Étiquettes"], [10, 10], "progress_new_words");

oBinaryDict.load();
oBinaryDict.listen();
oGenerator.listen();

Modified gc_lang/fr/tb/content/lex_editor.xul from [f370f1df19] to [9a4f4b9ece].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24


25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21


22
23
24
25
26
27
28
29
30













-








-
-
+
+







<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://grammarchecker/content/lex_editor.css" type="text/css"?>

<!DOCTYPE dialog SYSTEM "chrome://grammarchecker/locale/lex_editor.dtd">

<dialog
  id="grammalecte-lexicon-editor-window"
  title="&window.title;"
  orient="vertical"
  buttons="cancel"
  buttonlabelcancel="&button.cancel.label;"
  ondialogcancel="return;"
  defaultButton="cancel"
  width="500"
  onload="document.getElementById('grammalecte-lexicon-editor-window').centerWindowOnScreen();"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <!-- Other elements go here -->
  <hbox>
    <label class="dictionary" value="Dictionnaire personnel" />
    <label class="dic_text dic_saved_date_label" value="Enregistré le :" />
    <label class="dic_text dic_saved_date" value="·" />
    <label class="dic_text dic_num_entries" value="0" />
    <label id="dic_save_date" class="dic_text dic_saved_date" value="·" />
    <label id="dic_num_entries" class="dic_text dic_num_entries" value="0" />
    <label class="dic_text dic_num_entries_label" value="entrées" />
    <button id="export_button" label="Exporter" />
  </hbox>

  <tabbox id="tabs" selectedIndex="0">
    <tabs>
      <tab label="&tab.editor.label;"/>
166
167
168
169
170
171
172
173

174
175
176
177
178
179
180
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179







-
+







      <!-- LEXICON -->
      <tabpanel orient="vertical">
        <dialogheader title="&dialogheader.lexicon.label;" description="" />
        <hbox>
          <vbox>
            <hbox>
              <label class="info_label" value="Nombre d’entrées : " />
              <label class="data" value="0" />
              <label id="num_entries" class="data" value="0" />
            </hbox>
            <progressmeter id="progress_lexicon" value="0"/>
            <button id="save_button" label="Enregistrer" />        
          </vbox>

          <vbox>
            <listbox id="lexicon_table">
202
203
204
205
206
207
208
209
210






211
212
213
201
202
203
204
205
206
207


208
209
210
211
212
213
214
215
216







-
-
+
+
+
+
+
+



        </hbox>
      </tabpanel>

    </tabpanels>

  </tabbox>

  <script type="application/x-javascript" src="resource://grammalecte/content/fr/conj.js" />
  <script type="application/x-javascript" src="resource://grammalecte/content/fr/conj_generator.js" />
  <script type="application/x-javascript" src="resource://grammalecte/graphspell/helpers.js" />
  <script type="application/x-javascript" src="resource://grammalecte/graphspell/str_transform.js" />
  <script type="application/x-javascript" src="resource://grammalecte/graphspell/dawg.js" />
  <script type="application/x-javascript" src="resource://grammalecte/graphspell/ibdawg.js" />
  <script type="application/x-javascript" src="resource://grammalecte/fr/conj.js" />
  <script type="application/x-javascript" src="resource://grammalecte/fr/conj_generator.js" />
  <script type="application/x-javascript" src="lex_editor.js" />

</dialog>