Grammalecte  Changes On Branch tbnext

Changes In Branch tbnext Excluding Merge-Ins

This is equivalent to a diff from f2ef884d79 to 7ed7293d91

2018-08-06
16:43
[tb] merge tbnext: update Thunderbird extension for Thunderbird 60 (API update) check-in: b5dece919f user: olr tags: trunk, tb
16:39
[tb] center spell options dialog window Closed-Leaf check-in: 7ed7293d91 user: olr tags: tb, tbnext
2018-07-05
12:43
[graphspell][py] trim useless spaces check-in: 016c0dd46a user: olr tags: trunk, graphspell
2018-07-01
20:42
merge trunk check-in: 6333b39383 user: olr tags: tbnext
20:13
[fx] update webext number (necessary for Mozilla website) check-in: f2ef884d79 user: olr tags: trunk, fx
18:49
[fr] data rebuilt check-in: 0924fbec11 user: olr tags: trunk, fr

Modified gc_lang/fr/build.py from [9ca6336e46] to [039403a815].

87
88
89
90
91
92
93
94
95



96
97
98
99
100
101
102
    helpers.addFolderToZipAndFileFile(hZip, "gc_lang/"+sLang+"/tb", "", dVars, True)
    spDict = "gc_lang/"+sLang+"/xpi/data/dictionaries"
    for sp in os.listdir(spDict):
        if os.path.isdir(spDict+"/"+sp):
            hZip.write(spDict+"/"+sp+"/"+sp+".dic", "content/dictionaries/"+sp+"/"+sp+".dic")
            hZip.write(spDict+"/"+sp+"/"+sp+".aff", "content/dictionaries/"+sp+"/"+sp+".aff")
    hZip.close()
    spfDebugProfile = dVars['win_tb_debug_extension_path']  if platform.system() == "Windows"  else dVars['linux_tb_debug_extension_path']
    helpers.unzip(spfZip, spfDebugProfile)





def _createOptionsForThunderbird (dVars):
    dVars['sXULTabs'] = ""
    dVars['sXULTabPanels'] = ""
    # dialog options
    for sSection, lOpt in dVars['lStructOpt']:







|
|
>
>
>







87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
    helpers.addFolderToZipAndFileFile(hZip, "gc_lang/"+sLang+"/tb", "", dVars, True)
    spDict = "gc_lang/"+sLang+"/xpi/data/dictionaries"
    for sp in os.listdir(spDict):
        if os.path.isdir(spDict+"/"+sp):
            hZip.write(spDict+"/"+sp+"/"+sp+".dic", "content/dictionaries/"+sp+"/"+sp+".dic")
            hZip.write(spDict+"/"+sp+"/"+sp+".aff", "content/dictionaries/"+sp+"/"+sp+".aff")
    hZip.close()
    spDebugProfile = dVars['win_tb_debug_extension_path']  if platform.system() == "Windows"  else dVars['linux_tb_debug_extension_path']
    helpers.unzip(spfZip, spDebugProfile)
    spfBetaExtension = dVars['win_tb_beta_extension_filepath']  if platform.system() == "Windows"  else dVars['linux_tb_beta_extension_filepath']
    #helpers.unzip(spfZip, spBetaProfile)
    file_util.copy_file(spfZip, spfBetaExtension)


def _createOptionsForThunderbird (dVars):
    dVars['sXULTabs'] = ""
    dVars['sXULTabPanels'] = ""
    # dialog options
    for sSection, lOpt in dVars['lStructOpt']:

Modified gc_lang/fr/config.ini from [f07a04e149] to [2149787618].

51
52
53
54
55
56
57





58
59


60
61
62
63
64
65
66
win_fx_nightly_path = C:\Program Files\Nightly\firefox.exe
linux_fx_dev_path = /usr/bin/firefox
linux_fx_nightly_path = /usr/bin/firefox

# Thunderbird
tb_identifier = French-GC-TB@grammalecte.net
tb_name = Grammalecte [fr]





win_tb_debug_extension_path = D:\_temp\tb-debug.profile\extensions\French-GC-TB@grammalecte.net
linux_tb_debug_extension_path = ~/tb-debug.profile/extensions/French-GC-TB@grammalecte.net


# Set Thunderbird folder in your PATH variable
# Create a local profile:
#     	thunderbird -CreateProfile "debug _build\tb-debug.profile"
# Or you can use the GUI with:
#	 	thunderbird -P
# To launch Thunderbird with the profile debug, type:
#     	thunderbird -P debug







>
>
>
>
>


>
>







51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
win_fx_nightly_path = C:\Program Files\Nightly\firefox.exe
linux_fx_dev_path = /usr/bin/firefox
linux_fx_nightly_path = /usr/bin/firefox

# Thunderbird
tb_identifier = French-GC-TB@grammalecte.net
tb_name = Grammalecte [fr]
win_tb_path = C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe
#win_tb_beta_path = C:\Program Files (x86)\Mozilla Thunderbird (Beta)\thunderbird.exe
win_tb_beta_path = C:\Program Files (x86)\Mozilla Thunderbird (Beta)\thunderbird.exe
linux_tb_path = /usr/bin/thunderbird
linux_tb_beta_path = /usr/bin/thunderbird
win_tb_debug_extension_path = D:\_temp\tb-debug.profile\extensions\French-GC-TB@grammalecte.net
linux_tb_debug_extension_path = ~/tb-debug.profile/extensions/French-GC-TB@grammalecte.net
win_tb_beta_extension_filepath = D:\_temp\tb-beta.profile\extensions\French-GC-TB@grammalecte.net.xpi
linux_tb_beta_extension_filepath = ~/tb-beta.profile/extensions/French-GC-TB@grammalecte.net.xpi
# Set Thunderbird folder in your PATH variable
# Create a local profile:
#     	thunderbird -CreateProfile "debug _build\tb-debug.profile"
# Or you can use the GUI with:
#	 	thunderbird -P
# To launch Thunderbird with the profile debug, type:
#     	thunderbird -P debug

Modified gc_lang/fr/dictionnaire/_templates/moz/install.rdf from [349100bbce] to [42635d34a5].

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
        </Description>
    </em:targetApplication>

    <em:targetApplication>
        <Description>
            <em:id>{3550f703-e582-4d05-9a08-453d09bdfdc6}</em:id> <!-- Thunderbird -->
            <em:minVersion>14.0</em:minVersion>
            <em:maxVersion>53.*</em:maxVersion>
        </Description>
    </em:targetApplication>

    <em:targetApplication>
        <Description>
            <em:id>{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}</em:id> <!-- SeaMonkey -->
            <em:minVersion>2.12</em:minVersion>
            <em:maxVersion>*</em:maxVersion>
        </Description>
    </em:targetApplication>

  </Description>
</RDF>







|













31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
        </Description>
    </em:targetApplication>

    <em:targetApplication>
        <Description>
            <em:id>{3550f703-e582-4d05-9a08-453d09bdfdc6}</em:id> <!-- Thunderbird -->
            <em:minVersion>14.0</em:minVersion>
            <em:maxVersion>61.*</em:maxVersion>
        </Description>
    </em:targetApplication>

    <em:targetApplication>
        <Description>
            <em:id>{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}</em:id> <!-- SeaMonkey -->
            <em:minVersion>2.12</em:minVersion>
            <em:maxVersion>*</em:maxVersion>
        </Description>
    </em:targetApplication>

  </Description>
</RDF>

Modified gc_lang/fr/tb/chrome.manifest from [39608040f5] to [a8f859a2c4].

1
2
3
4
5
6
7
8
9
# https://developer.mozilla.org/en-US/docs/Chrome_Registration
content	grammarchecker	content/
content promiseworker ./worker/
resource grammalecte ./grammalecte-js/
locale	grammarchecker	fr	locale/fr/
locale	grammarchecker	en	locale/en/
skin	grammarchecker	classic/1.0	skin/
overlay	chrome://messenger/content/messengercompose/messengercompose.xul	chrome://grammarchecker/content/overlay.xul
style	chrome://global/content/customizeToolbar.xul	chrome://grammarchecker/content/overlay.css








|
1
2
3
4
5
6
7
8
9
# https://developer.mozilla.org/en-US/docs/Chrome_Registration
content	grammarchecker	content/
content promiseworker ./worker/
resource grammalecte ./grammalecte-js/
locale	grammarchecker	fr	locale/fr/
locale	grammarchecker	en	locale/en/
skin	grammarchecker	classic/1.0	skin/
overlay	chrome://messenger/content/messengercompose/messengercompose.xul	chrome://grammarchecker/content/overlay.xul
style	chrome://messenger/content/customizeToolbar.xul	chrome://grammarchecker/content/overlay.css

Modified gc_lang/fr/tb/content/about.css from [d621de3251] to [0c03b7bf9e].

21
22
23
24
25
26
27




















#contrib {
	font-size: 16px;
	text-align: center;
	color: hsl(210, 50%, 50%);
	cursor: pointer;
}


























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

#contrib {
	font-size: 16px;
	text-align: center;
	color: hsl(210, 50%, 50%);
	cursor: pointer;
}


/*
    TB Next: fix dialogheaders
*/
dialogheader {
  -moz-binding: url("chrome://messenger/content/generalBindings.xml#dialogheader");
  margin: 0 5px 5px;
  border: 1px solid ThreeDDarkShadow;
  padding: 5px 8px;
  background-color: Highlight;
  color: HighlightText;
}

.dialogheader-title {
  margin: 0 !important;
  font-size: larger;
  font-weight: bold;
}

Modified gc_lang/fr/tb/content/about.js from [2bc9ad5ee7] to [94f44e1159].

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
32
33
34
35

36
37
38
// JavaScript

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
//const { require } = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {});

function echo (...args) {
    Services.console.logStringMessage(args.join(" -- ") + "\n");
}


function openInBrowserURL (sURL) {
    // method found in S3.Google.Translator
    try {
        openURL(sURL);
        // Works in overlay.js, but not here… Seems there is no documentation available about this feature on Mozilla.org
    }
    catch (e) {

        Cu.reportError(e);
    }
}

function openInTabURL (sURL) {
    // method found in S3.Google.Translator
    try {
        let xWM = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
        let xWin = xWM.getMostRecentWindow("mail:3pane");
        let xTabmail = xWin.document.getElementById('tabmail');
        xWin.focus();
        if (xTabmail) {
            xTabmail.openTab('contentTab', { contentPage: sURL });
        }
    }
    catch (e) {

        Cu.reportError(e);
    }
}




|
<
<
<
<
<









>
|















>
|


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
32
33
34
35
// JavaScript

const Cc = Components.classes;
const Ci = Components.interfaces;
//const Cu = Components.utils;







function openInBrowserURL (sURL) {
    // method found in S3.Google.Translator
    try {
        openURL(sURL);
        // Works in overlay.js, but not here… Seems there is no documentation available about this feature on Mozilla.org
    }
    catch (e) {
        console.error(e);
        //Cu.reportError(e);
    }
}

function openInTabURL (sURL) {
    // method found in S3.Google.Translator
    try {
        let xWM = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
        let xWin = xWM.getMostRecentWindow("mail:3pane");
        let xTabmail = xWin.document.getElementById('tabmail');
        xWin.focus();
        if (xTabmail) {
            xTabmail.openTab('contentTab', { contentPage: sURL });
        }
    }
    catch (e) {
        console.error(e);
        //Cu.reportError(e);
    }
}

Modified gc_lang/fr/tb/content/about.xul from [fc21852913] to [9407ba6c78].

30
31
32
33
34
35
36
37
38
    onclick="openInTabURL('http://lamouette.org/?from=grammalecte-tb');" />
  <label class="stdlabel" value="&amp;" />
  <image src="chrome://grammarchecker/skin/Algoo_logo.png" style="cursor: pointer;"
    onclick="openInTabURL('https://www.algoo.fr/?from=grammalecte-tb');" />
  <label id="contrib" value="&contrib;"
    onclick="openInTabURL('https://www.dicollecte.org/#thanks');" />

  <script type="application/x-javascript" src="about.js"/>
</dialog>







|

30
31
32
33
34
35
36
37
38
    onclick="openInTabURL('http://lamouette.org/?from=grammalecte-tb');" />
  <label class="stdlabel" value="&amp;" />
  <image src="chrome://grammarchecker/skin/Algoo_logo.png" style="cursor: pointer;"
    onclick="openInTabURL('https://www.algoo.fr/?from=grammalecte-tb');" />
  <label id="contrib" value="&contrib;"
    onclick="openInTabURL('https://www.dicollecte.org/#thanks');" />

  <script type="application/javascript" src="about.js"/>
</dialog>

Modified gc_lang/fr/tb/content/conjugueur.css from [0ecfe596a1] to [f9d44fa63b].

37
38
39
40
41
42
43



















	color: hsl(210, 50%, 50%);
	font-size: 13px;
	font-weight: bold;
}
label.cj {
	font-size: 11px;
}


























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
	color: hsl(210, 50%, 50%);
	font-size: 13px;
	font-weight: bold;
}
label.cj {
	font-size: 11px;
}


/*
    TB Next: fix dialogheaders
*/
dialogheader {
  -moz-binding: url("chrome://messenger/content/generalBindings.xml#dialogheader");
  margin: 0 5px 5px;
  border: 1px solid ThreeDDarkShadow;
  padding: 5px 8px;
  background-color: Highlight;
  color: HighlightText;
}

.dialogheader-title {
  margin: 0 !important;
  font-size: larger;
  font-weight: bold;
}

Modified gc_lang/fr/tb/content/conjugueur.js from [52fcb1616a] to [7858c1ae9f].

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
32
33
34
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50
// JavaScript

const Cu = Components.utils;
const { require } = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {});
const conj = require("resource://grammalecte/fr/conj.js");


function echo (...args) {
    Services.console.logStringMessage(args.join(" -- ") + "\n");
}


let oConj = {
    init: function () {
        let that = this;
        try {
            // button
            document.getElementById('conjugate').addEventListener("click", function (event) {
                that.getVerbAndConjugate();
            });
            // text field
            document.getElementById('verb').addEventListener("change", function (event) {
                that.getVerbAndConjugate();
            });
            // options
            document.getElementById('oneg').addEventListener("click", function (event) {
                that._displayResults();
            });
            document.getElementById('opro').addEventListener("click", function (event) {
                that._displayResults();
            });
            document.getElementById('oint').addEventListener("click", function (event) {
                that._displayResults();
            });
            document.getElementById('ofem').addEventListener("click", function (event) {
                that._displayResults();
            });
            document.getElementById('otco').addEventListener("click", function (event) {
                that._displayResults();
            });
        }
        catch (e) {

            Cu.reportError(e);
        }
        this.conjugate("être");
    },

    oVerb: null,

    getVerbAndConjugate: function () {


|
|
|
<
<
<
<
<




|


|
|


|
|


|
|

|
|

|
|

|
|

|
|



>
|







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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// JavaScript

//const Cu = Components.utils;
//const { require } = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {});
//const conj = require("resource://grammalecte/fr/conj.js");







let oConj = {
    init: function () {
        console.log("Init conjugueur");
        try {
            // button
            document.getElementById('conjugate').addEventListener("click", (xEvent) => {
                this.getVerbAndConjugate();
            });
            // text field
            document.getElementById('verb').addEventListener("change", (xEvent) => {
                this.getVerbAndConjugate();
            });
            // options
            document.getElementById('oneg').addEventListener("click", (xEvent) => {
                this._displayResults();
            });
            document.getElementById('opro').addEventListener("click", (xEvent) => {
                this._displayResults();
            });
            document.getElementById('oint').addEventListener("click", (xEvent) => {
                this._displayResults();
            });
            document.getElementById('ofem').addEventListener("click", (xEvent) => {
                this._displayResults();
            });
            document.getElementById('otco').addEventListener("click", (xEvent) => {
                this._displayResults();
            });
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
        this.conjugate("être");
    },

    oVerb: null,

    getVerbAndConjugate: function () {
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

                if (!conj.isVerb(sVerb)) {
                    document.getElementById('verb').style = "color: #BB4411;";
                } else {
                    document.getElementById('verb_title').textContent = sVerb;
                    document.getElementById('verb').style = "color: #999999;";
                    document.getElementById('verb').value = "";
                    this.oVerb = new conj.Verb(sVerb);
                    let sRawInfo = this.oVerb._sRawInfo;
                    document.getElementById('info').textContent = this.oVerb.sInfo;
                    document.getElementById('opro').textContent = "pronominal";
                    if (sRawInfo.endsWith("zz")) {
                        document.getElementById('opro').checked = false;
                        document.getElementById('opro').disabled = true;
                        document.getElementById('opro').style = "color: #CCC;";







|







77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

                if (!conj.isVerb(sVerb)) {
                    document.getElementById('verb').style = "color: #BB4411;";
                } else {
                    document.getElementById('verb_title').textContent = sVerb;
                    document.getElementById('verb').style = "color: #999999;";
                    document.getElementById('verb').value = "";
                    this.oVerb = new Verb(sVerb);
                    let sRawInfo = this.oVerb._sRawInfo;
                    document.getElementById('info').textContent = this.oVerb.sInfo;
                    document.getElementById('opro').textContent = "pronominal";
                    if (sRawInfo.endsWith("zz")) {
                        document.getElementById('opro').checked = false;
                        document.getElementById('opro').disabled = true;
                        document.getElementById('opro').style = "color: #CCC;";
125
126
127
128
129
130
131

132
133
134
135
136
137
138
139
                        document.getElementById('otco').style = "color: #000;";
                    }
                    this._displayResults();
                }
            }
        }
        catch (e) {

            Cu.reportError(e);
        }
    },

    _displayResults: function () {
        if (this.oVerb === null) {
            return;
        }







>
|







121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
                        document.getElementById('otco').style = "color: #000;";
                    }
                    this._displayResults();
                }
            }
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    },

    _displayResults: function () {
        if (this.oVerb === null) {
            return;
        }
235
236
237
238
239
240
241

242
243
244
245
246
247
248
249
                document.getElementById('condb4').textContent = " ";
                document.getElementById('condb5').textContent = " ";
                document.getElementById('condb6').textContent = " ";
            }
            document.getElementById('verb').Text = "";
        }
        catch (e) {

            Cu.reportError(e);
        }
    },

    _setTitles: function () {
        try {
            if (!document.getElementById('otco').checked) {
                document.getElementById('ipre_temps').textContent = "Présent";







>
|







232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
                document.getElementById('condb4').textContent = " ";
                document.getElementById('condb5').textContent = " ";
                document.getElementById('condb6').textContent = " ";
            }
            document.getElementById('verb').Text = "";
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    },

    _setTitles: function () {
        try {
            if (!document.getElementById('otco').checked) {
                document.getElementById('ipre_temps').textContent = "Présent";
264
265
266
267
268
269
270

271
272
273
274
275

276
277
                document.getElementById('simp_temps').textContent = "Plus-que-parfait";
                document.getElementById('conda_temps').textContent = "Passé (1ʳᵉ forme)";
                document.getElementById('condb_temps').textContent = "Passé (2ᵉ forme)";
                document.getElementById('impe_temps').textContent = "Passé";
            }
        }
        catch (e) {

            Cu.reportError(e);
        }
    }
};


oConj.init();








>
|




>

<
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

                document.getElementById('simp_temps').textContent = "Plus-que-parfait";
                document.getElementById('conda_temps').textContent = "Passé (1ʳᵉ forme)";
                document.getElementById('condb_temps').textContent = "Passé (2ᵉ forme)";
                document.getElementById('impe_temps').textContent = "Passé";
            }
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    }
};

conj.init(helpers.loadFile("resource://grammalecte/fr/conj_data.json"));
oConj.init();

Modified gc_lang/fr/tb/content/conjugueur.xul from [ee8b63b554] to [70a4bfd479].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://grammarchecker/content/conjugueur.css" type="text/css"?>

<dialog
  id="grammalecte-conjugueur-window"
  title="Grammalecte · Conjugueur…"
  orient="vertical"
  width="550"
  buttons="extra1"
  buttonlabelextra1="Conjuguer"
  ondialogextra1="oConj.getVerbAndConjugate();"
  defaultButton="extra1"
  onload=""
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">









|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://grammarchecker/content/conjugueur.css" type="text/css"?>

<dialog
  id="grammalecte-conjugueur-window"
  title="Grammalecte · Conjugueur…"
  orient="vertical"
  width="580"
  buttons="extra1"
  buttonlabelextra1="Conjuguer"
  ondialogextra1="oConj.getVerbAndConjugate();"
  defaultButton="extra1"
  onload=""
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

150
151
152
153
154
155
156


157
158
        <label id="condb4" class="cj">.</label>
        <label id="condb5" class="cj">.</label>
        <label id="condb6" class="cj">.</label>
      </groupbox>
    </column>
  </columns>



  <script type="application/x-javascript" src="conjugueur.js"/>
</dialog>







>
>
|

150
151
152
153
154
155
156
157
158
159
160
        <label id="condb4" class="cj">.</label>
        <label id="condb5" class="cj">.</label>
        <label id="condb6" class="cj">.</label>
      </groupbox>
    </column>
  </columns>

  <script type="application/javascript" src="resource://grammalecte/graphspell/helpers.js"/>
  <script type="application/javascript" src="resource://grammalecte/fr/conj.js"/>
  <script type="application/javascript" src="conjugueur.js"/>
</dialog>

Modified gc_lang/fr/tb/content/editor.js from [71421bf6bc] to [80f443c01c].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

106
107
108
109
        }
    };

    * _getParsableNodes (xRootNode=this.xEditor.rootElement) {
        // recursive function
        try {
            for (let xNode of xRootNode.childNodes) {
                //echo("tag: " + xNode.tagName);
                if (xNode.className !== "moz-cite-prefix" && xNode.tagName !== "BLOCKQUOTE"
                    && (xNode.nodeType == Node.TEXT_NODE || (xNode.nodeType == Node.ELEMENT_NODE && !xNode.textContent.startsWith(">")))
                    && xNode.textContent !== "") {
                    //echo("<"+xNode.tagName+">["+xNode.textContent+"]");
                    if (xNode.tagName === undefined) {
                        if (!prefs.getBoolPref("bCheckSignature") && xNode.textContent.startsWith("-- ")) {
                            break;
                        }
                        yield xNode;
                    } else if (this.lParsableNodes.includes(xNode.tagName)) {
                        yield xNode;
                    } else if (this.lRootNodes.includes(xNode.tagName)) {
                        yield* this._getParsableNodes(xNode);
                    }
                }
            }
        } catch (e) {

            Cu.reportError(e);
        }
    };

    * getParagraphs () {
        try {
            let i = 0;
            for (let xNode of this._getParsableNodes()) {
                this.lNode.push(xNode);
                yield [i, this._getTextFromNode(xNode)];
                i += 1;
            }
        } catch (e) {

            Cu.reportError(e);
        }
    };

    getContent () {
        try {
            let sContent = "";
            for (let [i, sHTML] of this.getParagraphs()) {
                if (sContent.length > 0) {
                    sContent += "\n";
                }
                sContent += sHTML;
            }
            return sContent;
        } catch (e) {

            Cu.reportError(e);
        }
    };

    getParagraph (iPara) {
        try {
            return this._getTextFromNode(this.lNode[iPara]);
        } catch (e) {

            Cu.reportError(e);
        }
    };

    writeParagraph (iPara, sText) {
        try {
            let xNode = this.lNode[iPara];
            if ("innerHTML" in xNode) {
                xNode.innerHTML = sText;
            } else {
                xNode.textContent = sText;
            }
        } catch (e) {

            Cu.reportError(e);
        }
    };

    changeParagraph (iPara, sModif, iStart, iEnd) {
        let sText = this.getParagraph(iPara);
        this.writeParagraph(iPara, sText.slice(0, iStart) + sModif + sText.slice(iEnd));
    };

    getLangFromSpellChecker () {
        try {
            let gSpellChecker = this.xEditor.getInlineSpellChecker(true);
            let sLang = gSpellChecker.spellChecker.GetCurrentDictionary();
            return sLang.slice(0, 2);
        } catch (e) {

            Cu.reportError(e);
        }
    };
}







<



<













>
|












>
|














>
|







>
|












>
|














>
|



17
18
19
20
21
22
23

24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
        }
    };

    * _getParsableNodes (xRootNode=this.xEditor.rootElement) {
        // recursive function
        try {
            for (let xNode of xRootNode.childNodes) {

                if (xNode.className !== "moz-cite-prefix" && xNode.tagName !== "BLOCKQUOTE"
                    && (xNode.nodeType == Node.TEXT_NODE || (xNode.nodeType == Node.ELEMENT_NODE && !xNode.textContent.startsWith(">")))
                    && xNode.textContent !== "") {

                    if (xNode.tagName === undefined) {
                        if (!prefs.getBoolPref("bCheckSignature") && xNode.textContent.startsWith("-- ")) {
                            break;
                        }
                        yield xNode;
                    } else if (this.lParsableNodes.includes(xNode.tagName)) {
                        yield xNode;
                    } else if (this.lRootNodes.includes(xNode.tagName)) {
                        yield* this._getParsableNodes(xNode);
                    }
                }
            }
        } catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    };

    * getParagraphs () {
        try {
            let i = 0;
            for (let xNode of this._getParsableNodes()) {
                this.lNode.push(xNode);
                yield [i, this._getTextFromNode(xNode)];
                i += 1;
            }
        } catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    };

    getContent () {
        try {
            let sContent = "";
            for (let [i, sHTML] of this.getParagraphs()) {
                if (sContent.length > 0) {
                    sContent += "\n";
                }
                sContent += sHTML;
            }
            return sContent;
        } catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    };

    getParagraph (iPara) {
        try {
            return this._getTextFromNode(this.lNode[iPara]);
        } catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    };

    writeParagraph (iPara, sText) {
        try {
            let xNode = this.lNode[iPara];
            if ("innerHTML" in xNode) {
                xNode.innerHTML = sText;
            } else {
                xNode.textContent = sText;
            }
        } catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    };

    changeParagraph (iPara, sModif, iStart, iEnd) {
        let sText = this.getParagraph(iPara);
        this.writeParagraph(iPara, sText.slice(0, iStart) + sModif + sText.slice(iEnd));
    };

    getLangFromSpellChecker () {
        try {
            let gSpellChecker = this.xEditor.getInlineSpellChecker(true);
            let sLang = gSpellChecker.spellChecker.GetCurrentDictionary();
            return sLang.slice(0, 2);
        } catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    };
}

Modified gc_lang/fr/tb/content/gc_options.css from [6199209734] to [df2e253402].

1
2
3
4
5
6
7



















/* CSS */

.section {
	font-size: 16px;
	font-weight: bold;
	color: hsl(210, 50%, 50%);
}


























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/* CSS */

.section {
	font-size: 16px;
	font-weight: bold;
	color: hsl(210, 50%, 50%);
}

/*
    TB Next: fix dialogheaders
*/
dialogheader {
  -moz-binding: url("chrome://messenger/content/generalBindings.xml#dialogheader");
  margin: 0 5px 5px;
  border: 1px solid ThreeDDarkShadow;
  padding: 5px 8px;
  background-color: Highlight;
  color: HighlightText;
}

.dialogheader-title {
  margin: 0 !important;
  font-size: larger;
  font-weight: bold;
}

Modified gc_lang/fr/tb/content/gc_options.js from [f85fde1089] to [ed480efba2].

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
32
33
34
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50
51
// JavaScript

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.");
//const { require } = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {});

function echo (...args) {
    Services.console.logStringMessage(args.join(" -- ") + "\n");
}

var oOptControl = {
    oOptions: null,
    load: function () {
        this._setDialogOptions(false);
    },
    _setDialogOptions: function (bDefaultOptions=false) {
        try {
            sOptions = bDefaultOptions ? prefs.getCharPref("sGCDefaultOptions") : prefs.getCharPref("sGCOptions");
            //echo(">> " + sOptions);
            this.oOptions = JSON.parse(sOptions);
            for (let sParam in this.oOptions) {
                //echo(sParam + ":" + oOptions[sParam]);
                if (document.getElementById("option_"+sParam) !== null) {
                    document.getElementById("option_"+sParam).checked = this.oOptions[sParam];
                }
            }
        }
        catch (e) {

            Cu.reportError(e);
        }
    },
    save: function () {
        try {
            for (let xNode of document.getElementsByClassName("option")) {
                this.oOptions[xNode.id.slice(7)] = xNode.checked;
            }
            prefs.setCharPref("sGCOptions", JSON.stringify(this.oOptions));
            //echo("<< " + JSON.stringify(this.oOptions));
        }
        catch (e) {

            Cu.reportError(e);
        }
    },
    reset: function () {
        this._setDialogOptions(true);
    }
}

oOptControl.load();




|

<

<
<
<









<


<






>
|








<


>
|








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
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
// JavaScript

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 oOptControl = {
    oOptions: null,
    load: function () {
        this._setDialogOptions(false);
    },
    _setDialogOptions: function (bDefaultOptions=false) {
        try {
            sOptions = bDefaultOptions ? prefs.getCharPref("sGCDefaultOptions") : prefs.getCharPref("sGCOptions");

            this.oOptions = JSON.parse(sOptions);
            for (let sParam in this.oOptions) {

                if (document.getElementById("option_"+sParam) !== null) {
                    document.getElementById("option_"+sParam).checked = this.oOptions[sParam];
                }
            }
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    },
    save: function () {
        try {
            for (let xNode of document.getElementsByClassName("option")) {
                this.oOptions[xNode.id.slice(7)] = xNode.checked;
            }
            prefs.setCharPref("sGCOptions", JSON.stringify(this.oOptions));

        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    },
    reset: function () {
        this._setDialogOptions(true);
    }
}

oOptControl.load();

Modified gc_lang/fr/tb/content/gc_options.xul from [8e6b4a963d] to [65926a1200].

27
28
29
30
31
32
33
34
35
36
${sXULTabs}
    </tabs>
    <tabpanels>
${sXULTabPanels}
    </tabpanels>
  </tabbox>

  <script type="application/x-javascript" src="gc_options.js" />

</dialog>







|


27
28
29
30
31
32
33
34
35
36
${sXULTabs}
    </tabs>
    <tabpanels>
${sXULTabPanels}
    </tabpanels>
  </tabbox>

  <script type="application/javascript" src="gc_options.js" />

</dialog>

Added gc_lang/fr/tb/content/options.css version [20756f5a2f].







































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* CSS */

/*
    TB Next: fix dialogheaders
*/
dialogheader {
  -moz-binding: url("chrome://messenger/content/generalBindings.xml#dialogheader");
  margin: 0 5px 5px;
  border: 1px solid ThreeDDarkShadow;
  padding: 5px 8px;
  background-color: Highlight;
  color: HighlightText;
}

.dialogheader-title {
  margin: 0 !important;
  font-size: larger;
  font-weight: bold;
}

Added gc_lang/fr/tb/content/options.js version [7635023546].









































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
32
33
34
35
36
// 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 oOptControl = {

    load: function () {
        try {
            document.getElementById('check_signature').checked = prefs.getBoolPref('bCheckSignature');
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    },

    save: function () {
        try {
            prefs.setBoolPref('bCheckSignature', document.getElementById('check_signature').checked);
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    }
}


oOptControl.load();

Modified gc_lang/fr/tb/content/options.xul from [4546c76788] to [b4b7f2b7c3].

1
2

3
4
5

6
7







8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>


<!DOCTYPE prefwindow SYSTEM "chrome://grammarchecker/locale/options.dtd">


<prefwindow id="grammarcheckerPreferences"
  title="&prefwindow.title;"







  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">


  <prefpane id="pane1" label="&pane1.title;">
    <dialogheader id="grammalecte-title" title="&pane1.title;" description="" />
    <preferences>
      <preference id="check_signature" name="extensions.grammarchecker.bCheckSignature" type="bool" />
      <!--<preference id="gc_options" name="extensions.grammarchecker.sGCOptions" type="string" />
      <preference id="tf_options" name="extensions.grammarchecker.sTFOptions" type="string" />
      <preference id="mothertongue" name="extensions.grammarchecker.mothertongue" type="string"/>-->
    </preferences>
    <checkbox label="&check_signature.label;" accesskey="&check_signature.accesskey;"  preference="check_signature"/>
    <!--<label accesskey="&gc_options.accesskey;" control="texturlpref1">&gc_options.label;</label><textbox id="texturlpref1" preference="gc_options"/>
    <label accesskey="&tf_options.accesskey;" control="texturlpref2">&tf_options.label;</label><textbox id="texturlpref2" preference="tf_options"/>
    <label accesskey="&mothertongue.accesskey;" control="textmothertongue">&mothertongue.label;</label><textbox id="textmothertongue" preference="mothertongue"/>-->
    <!--<description>&panel.description;</description>-->
  </prefpane>
</prefwindow>
|

>

|

>
|
|
>
>
>
>
>
>
>


>
|
|
|
<
<
<
<
<
|
|
<
<
|
|
|
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
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://grammarchecker/content/options.css" type="text/css"?>

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

<dialog
  id="grammalecte-options-window"
  title="&window.title;"
  orient="vertical"
  buttons="accept, cancel"
  ondialogaccept="oOptControl.save();"
  ondialogcancel="return;"
  defaultButton="accept"
  width="400"
  onload="document.getElementById('grammalecte-options-window').centerWindowOnScreen();"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <!-- Other elements go here -->
  
  <dialogheader id="grammalecte-title" title="&dialogheader.label;" description="" />






  <checkbox id="check_signature" label="&check_signature.label;" accesskey="&check_signature.accesskey;" />



  <script type="application/javascript" src="options.js" />

</dialog>

Modified gc_lang/fr/tb/content/overlay.css from [778a1d344a] to [8c73a24356].

183
184
185
186
187
188
189




















/* elems */
.bs, .pleo, .neg, .redon1, .redon2, .mc, .date, .notype {
    background-color: hsl(180, 50%, 40%);
    color: hsl(180, 10%, 96%);
    border-radius: 3px;
}


























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208

/* elems */
.bs, .pleo, .neg, .redon1, .redon2, .mc, .date, .notype {
    background-color: hsl(180, 50%, 40%);
    color: hsl(180, 10%, 96%);
    border-radius: 3px;
}


/*
    TB Next: fix dialogheaders
*/
dialogheader {
  -moz-binding: url("chrome://messenger/content/generalBindings.xml#dialogheader");
  margin: 0 5px 5px;
  border: 1px solid ThreeDDarkShadow;
  padding: 5px 8px;
  background-color: Highlight;
  color: HighlightText;
}

.dialogheader-title {
  margin: 0 !important;
  font-size: larger;
  font-weight: bold;
}

Modified gc_lang/fr/tb/content/overlay.js from [86779b773f] to [99ae888938].

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
32
// JavaScript

"use strict";


const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const { require } = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {});

const { BasePromiseWorker } = Cu.import('resource://gre/modules/PromiseWorker.jsm', {});
const Task = Cu.import("resource://gre/modules/Task.jsm").Task;
const prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("extensions.grammarchecker.");
//Cu.import("resource://gre/modules/Console.jsm"); // doesn’t work
//const xConsole = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
//xConsole.logStringMessage("Grammalecte: " + args.join(" · ")); // useless now. Use: Services.console.logStringMessage("***");

const text = require("resource://grammalecte/text.js");
const tf = require("resource://grammalecte/fr/textformatter.js");


function echo (...args) {
    dump(args.join(" -- ") + "\n");  // obsolete since TB 52?
    Services.console.logStringMessage("Grammalecte: " + args.join(" · "));
}


const oConverterToExponent = {
    dNumbers: new Map ([
        ["1", "¹"], ["2", "²"], ["3", "³"], ["4", "⁴"], ["5", "⁵"],
        ["6", "⁶"], ["7", "⁷"], ["8", "⁸"], ["9", "⁹"], ["0", "⁰"]
    ]),








|

|
|

<
<
<

|
|
<
<
<
<
<
<







1
2
3
4
5
6
7
8
9
10
11
12
13



14
15
16






17
18
19
20
21
22
23
// JavaScript

"use strict";


const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
//const { require } = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {});

const { BasePromiseWorker } = ChromeUtils.import('resource://gre/modules/PromiseWorker.jsm', {});
const Task = ChromeUtils.import("resource://gre/modules/Task.jsm").Task;
const prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("extensions.grammarchecker.");




//const text = require("resource://grammalecte/text.js");
//const tf = require("resource://grammalecte/fr/textformatter.js");








const oConverterToExponent = {
    dNumbers: new Map ([
        ["1", "¹"], ["2", "²"], ["3", "³"], ["4", "⁴"], ["5", "⁵"],
        ["6", "⁶"], ["7", "⁷"], ["8", "⁸"], ["9", "⁹"], ["0", "⁰"]
    ]),
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

var oGrammarChecker = {
    // you must use var to be able to call this object from elsewhere
    xGCEWorker: null,
    loadGC: function () {
        if (this.xGCEWorker === null) {
            // Grammar checker
            echo('Loading Grammalecte');
            this.xGCEWorker = new BasePromiseWorker('chrome://promiseworker/content/gce_worker.js');
            let that = this;
            let xPromise = this.xGCEWorker.post('loadGrammarChecker', [prefs.getCharPref("sGCOptions"), "Thunderbird"]);
            xPromise.then(
                function (aVal) {
                    echo(aVal);
                    prefs.setCharPref("sGCOptions", aVal);
                    if (prefs.getBoolPref("bPersonalDictionary")) {
                        let sDicJSON = oFileHandler.loadFile("fr.personal.json");
                        if (sDicJSON) {
                            that.xGCEWorker.post('setDictionary', ["personal", sDicJSON]);
                        }
                    }
                },
                function (aReason) { echo('Promise rejected - ', aReason); }
            ).catch(
                function (aCaught) { echo('Promise Error - ', aCaught); }
            );

        }
    },
    fullTests: function () {
        echo('Performing tests... Wait...');
        let xPromise = this.xGCEWorker.post('fullTests', ['{"nbsp":true, "esp":true, "unit":true, "num":true}']);
        xPromise.then(
            function (aVal) {
                echo('Done.');
                echo(aVal);
            },
            function (aReason) { echo('Promise rejected', aReason); }
        ).catch(
            function (aCaught) { echo('Promise Error', aCaught); }
        );
    },
    test: function (sText) {
        echo("Test...");
        let xPromise = this.xGCEWorker.post('parse', [sText, "FR", true]);
        xPromise.then(
            function (aVal) {
                let lErr = JSON.parse(aVal);
                if (lErr.length > 0) {
                    for (let dErr of lErr) {
                        echo(text.getReadableError(dErr));
                    }
                } else {
                    echo("no error found");
                }
            },
            function (aReason) { echo('Promise rejected', aReason); }
        ).catch(
            function (aCaught) { echo('Promise Error', aCaught); }
        );
    },
    setOptions: function () {
        echo('Set options');
        let xPromise = this.xGCEWorker.post('setOptions', [prefs.getCharPref("sGCOptions")]);
        xPromise.then(
            function (aVal) {
                echo(aVal);
                prefs.setCharPref("sGCOptions", aVal);
            },
            function (aReason) { echo('Promise rejected', aReason); }
        ).catch(
            function (aCaught) { echo('Promise Error', aCaught); }
        );
    },
    resetOptions: function () {
        let xPromise = this.xGCEWorker.post('resetOptions');
        xPromise.then(
            function (aVal) {
                echo(aVal);
                prefs.setCharPref("sGCOptions", aVal);
            },
            function (aReason) { echo('Promise rejected', aReason); }
        ).catch(
            function (aCaught) { echo('Promise Error', aCaught); }
        );
    },
    _getGCResultPromise: function (sParagraph, sLang, bDebug, bContext) {
        // For some reason, you can’t use result of PromiseWorker within a Task,
        // you have to wrap it in a common Promise. Task and yield can be replaced with async / await when it is available.
        let that = this;
        return new Promise(function (resolve, reject) {







|





|








|

|





|



|
|

|

|



|






|


|


|

|



|



|


|

|






|


|

|







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

var oGrammarChecker = {
    // you must use var to be able to call this object from elsewhere
    xGCEWorker: null,
    loadGC: function () {
        if (this.xGCEWorker === null) {
            // Grammar checker
            console.log('Loading Grammalecte');
            this.xGCEWorker = new BasePromiseWorker('chrome://promiseworker/content/gce_worker.js');
            let that = this;
            let xPromise = this.xGCEWorker.post('loadGrammarChecker', [prefs.getCharPref("sGCOptions"), "Thunderbird"]);
            xPromise.then(
                function (aVal) {
                    console.log(aVal);
                    prefs.setCharPref("sGCOptions", aVal);
                    if (prefs.getBoolPref("bPersonalDictionary")) {
                        let sDicJSON = oFileHandler.loadFile("fr.personal.json");
                        if (sDicJSON) {
                            that.xGCEWorker.post('setDictionary', ["personal", sDicJSON]);
                        }
                    }
                },
                function (aReason) { console.log('Promise rejected - ', aReason); }
            ).catch(
                function (aCaught) { console.log('Promise Error - ', aCaught); }
            );

        }
    },
    fullTests: function () {
        console.log('Performing tests... Wait...');
        let xPromise = this.xGCEWorker.post('fullTests', ['{"nbsp":true, "esp":true, "unit":true, "num":true}']);
        xPromise.then(
            function (aVal) {
                console.log('Done.');
                console.log(aVal);
            },
            function (aReason) { console.log('Promise rejected', aReason); }
        ).catch(
            function (aCaught) { console.log('Promise Error', aCaught); }
        );
    },
    test: function (sText) {
        console.log("Test...");
        let xPromise = this.xGCEWorker.post('parse', [sText, "FR", true]);
        xPromise.then(
            function (aVal) {
                let lErr = JSON.parse(aVal);
                if (lErr.length > 0) {
                    for (let dErr of lErr) {
                        console.log(text.getReadableError(dErr));
                    }
                } else {
                    console.log("no error found");
                }
            },
            function (aReason) { console.log('Promise rejected', aReason); }
        ).catch(
            function (aCaught) { console.log('Promise Error', aCaught); }
        );
    },
    setOptions: function () {
        console.log('Set options');
        let xPromise = this.xGCEWorker.post('setOptions', [prefs.getCharPref("sGCOptions")]);
        xPromise.then(
            function (aVal) {
                console.log(aVal);
                prefs.setCharPref("sGCOptions", aVal);
            },
            function (aReason) { console.log('Promise rejected', aReason); }
        ).catch(
            function (aCaught) { console.log('Promise Error', aCaught); }
        );
    },
    resetOptions: function () {
        let xPromise = this.xGCEWorker.post('resetOptions');
        xPromise.then(
            function (aVal) {
                console.log(aVal);
                prefs.setCharPref("sGCOptions", aVal);
            },
            function (aReason) { console.log('Promise rejected', aReason); }
        ).catch(
            function (aCaught) { console.log('Promise Error', aCaught); }
        );
    },
    _getGCResultPromise: function (sParagraph, sLang, bDebug, bContext) {
        // For some reason, you can’t use result of PromiseWorker within a Task,
        // you have to wrap it in a common Promise. Task and yield can be replaced with async / await when it is available.
        let that = this;
        return new Promise(function (resolve, reject) {
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
                document.getElementById("grammalecte-errors").appendChild(xNodeP);
            }
            return nParagraph;
        }).then(function (res) {
            that.setInfo("Nombre de paragraphes analysés : " + res);
        }, function (e) {
            that.setInfo("Erreur : " + e.message);

            Cu.reportError(e);
        });
    },
    createResultNode: function (xEditor, sParagraph, iParagraph, aGrammErr, aSpellErr) {
        let xResultNode = document.createElement("div");
        xResultNode.setAttribute("id", "resnode" + iParagraph);
        this.fillResultNode(xResultNode, xEditor, sParagraph, iParagraph, aGrammErr, aSpellErr);
        return xResultNode;
    },
    reparseParagraph: function (xEditor, iParagraph) {
        try {
            let that = this;
            let xResultNode = document.getElementById("resnode"+iParagraph);
            xResultNode.textContent = "…………… réanalyse en cours ……………";
            let sParagraph = xEditor.getParagraph(iParagraph);
            let xPromise = this._getGCResultPromise(sParagraph, "FR", false, false);
            xPromise.then(function (res) {
                //echo("res: " + res);
                xResultNode.textContent = "";
                let oRes = JSON.parse(res);
                if (oRes.aGrammErr.length > 0 || oRes.aSpellErr.length > 0) {
                    that.fillResultNode(xResultNode, xEditor, sParagraph, iParagraph, oRes.aGrammErr, oRes.aSpellErr);
                }
            }, function (res) {
                xResultNode.textContent = "Erreur: " + res;
            });
        }
        catch (e) {

            Cu.reportError(e);
        }
    },
    fillResultNode: function (xResultNode, xEditor, sParagraph, iParagraph, aGrammErr, aSpellErr) {
        try {
            if (aGrammErr.length === 0  &&  aSpellErr.length === 0) {
                return null;
            }







>
|
















|










>
|







165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
                document.getElementById("grammalecte-errors").appendChild(xNodeP);
            }
            return nParagraph;
        }).then(function (res) {
            that.setInfo("Nombre de paragraphes analysés : " + res);
        }, function (e) {
            that.setInfo("Erreur : " + e.message);
            console.error(e);
            // Cu.reportError(e);
        });
    },
    createResultNode: function (xEditor, sParagraph, iParagraph, aGrammErr, aSpellErr) {
        let xResultNode = document.createElement("div");
        xResultNode.setAttribute("id", "resnode" + iParagraph);
        this.fillResultNode(xResultNode, xEditor, sParagraph, iParagraph, aGrammErr, aSpellErr);
        return xResultNode;
    },
    reparseParagraph: function (xEditor, iParagraph) {
        try {
            let that = this;
            let xResultNode = document.getElementById("resnode"+iParagraph);
            xResultNode.textContent = "…………… réanalyse en cours ……………";
            let sParagraph = xEditor.getParagraph(iParagraph);
            let xPromise = this._getGCResultPromise(sParagraph, "FR", false, false);
            xPromise.then(function (res) {
                //console.log("res: " + res);
                xResultNode.textContent = "";
                let oRes = JSON.parse(res);
                if (oRes.aGrammErr.length > 0 || oRes.aSpellErr.length > 0) {
                    that.fillResultNode(xResultNode, xEditor, sParagraph, iParagraph, oRes.aGrammErr, oRes.aSpellErr);
                }
            }, function (res) {
                xResultNode.textContent = "Erreur: " + res;
            });
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    },
    fillResultNode: function (xResultNode, xEditor, sParagraph, iParagraph, aGrammErr, aSpellErr) {
        try {
            if (aGrammErr.length === 0  &&  aSpellErr.length === 0) {
                return null;
            }
252
253
254
255
256
257
258

259
260
261
262
263
264
265
266
            xParagraphNode.appendChild(document.createTextNode(this._purgeTags(sParagraph.slice(nEndLastErr))));
            xResultNode.appendChild(xParagraphNode);
            for (let xNode of lNodeError) {
                xResultNode.appendChild(xNode);
            }
        }
        catch (e) {

            Cu.reportError(e);
            xResultNode.textContent = "# Error: " + e.message;
        }
    },
    _createNodeGCErrorDescription: function (xEditor, nError, dErr, iParagraph) {
        let xNodeDiv = document.createElement("div");
        let that = this;
        // message







>
|







245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
            xParagraphNode.appendChild(document.createTextNode(this._purgeTags(sParagraph.slice(nEndLastErr))));
            xResultNode.appendChild(xParagraphNode);
            for (let xNode of lNodeError) {
                xResultNode.appendChild(xNode);
            }
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
            xResultNode.textContent = "# Error: " + e.message;
        }
    },
    _createNodeGCErrorDescription: function (xEditor, nError, dErr, iParagraph) {
        let xNodeDiv = document.createElement("div");
        let that = this;
        // message
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
                            });
                            xNodeSuggLine.appendChild(xNodeSugg);
                            n += 1;
                        }
                    } else {
                        xNodeSuggLine.appendChild(document.createTextNode("Aucune suggestion."));
                    }
                    
                },
                function (aReason) { console.error('Promise rejected - ', aReason); }
            ).catch(
                function (aCaught) { console.error('Promise Error - ', aCaught); }
            );
        });
        xNodeSuggLine.appendChild(xNodeSuggButton);
        xNodeDiv.appendChild(xNodeSuggLine);
        return xNodeDiv;
    },
    loadUI: function() {
        echo("loadUI");
        this._strings = document.getElementById("grammarchecker-strings");
        let that = this;
        let nsGrammarCommand = {
            isCommandEnabled: function (aCommand, dummy) {
                return (IsDocumentEditable() && !IsInHTMLSourceMode());
            },
            getCommandStateParams: function (aCommand, aParams, aRefCon) {},







<











|







354
355
356
357
358
359
360

361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
                            });
                            xNodeSuggLine.appendChild(xNodeSugg);
                            n += 1;
                        }
                    } else {
                        xNodeSuggLine.appendChild(document.createTextNode("Aucune suggestion."));
                    }

                },
                function (aReason) { console.error('Promise rejected - ', aReason); }
            ).catch(
                function (aCaught) { console.error('Promise Error - ', aCaught); }
            );
        });
        xNodeSuggLine.appendChild(xNodeSuggButton);
        xNodeDiv.appendChild(xNodeSuggLine);
        return xNodeDiv;
    },
    loadUI: function() {
        console.log("loadUI");
        this._strings = document.getElementById("grammarchecker-strings");
        let that = this;
        let nsGrammarCommand = {
            isCommandEnabled: function (aCommand, dummy) {
                return (IsDocumentEditable() && !IsInHTMLSourceMode());
            },
            getCommandStateParams: function (aCommand, aParams, aRefCon) {},
401
402
403
404
405
406
407

408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423

424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443

444
445
446
447
448
449
450
451
452
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
501
502
            xNavBar.setAttribute("currentset", aSet.join(","));
            xNavBar.currentSet = aSet.join(",");
            document.persist(xNavBar.id, "currentset");
            try {
                BrowserToolboxCustomizeDone(true);
            }
            catch (e) {

                Cu.reportError(e);
            }
        }
    },
    clearPreview: function() {
        let xPreview = document.getElementById("grammalecte-errors");
        while (xPreview.firstChild) {
            xPreview.removeChild(xPreview.firstChild);
        };
        let xEditor = GetCurrentEditor();
        if (xEditor != null) {
            try {
                xEditor.QueryInterface(Ci.nsIEditorStyleSheets);
                xEditor.addOverrideStyleSheet("chrome://grammarchecker/content/overlay.css");
            }
            catch (e) {

                Cu.reportError(e);
            }
        }
        this.setInfo("[vide]");
    },
    setInfo: function (sText) {
        document.getElementById("grammalecte-info").textContent = sText;
    },
    openPanel: function () {
        document.getElementById("textformatter-splitter").setAttribute("state", "collapsed");
        document.getElementById("grammarchecker-splitter").setAttribute("state", "open");
    },
    closePanel: function () {
        document.getElementById("grammarchecker-splitter").setAttribute("state", "collapsed");
    },
    openDialog: function (sWhat, sName="", sOptions="") {
        try {
            window.openDialog(sWhat, sName, sOptions);
        }
        catch (e) {

            Cu.reportError(e);
        }
    },
    openInTabURL: function (sURL) {
        // method found in S3.Google.Translator
        try {
            let xWM = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
            let xWin = xWM.getMostRecentWindow("mail:3pane");
            let xTabmail = xWin.document.getElementById('tabmail');
            xWin.focus();
            if (xTabmail) {
                xTabmail.openTab('contentTab', { contentPage: sURL });
            }
        }
        catch (e) {

            Cu.reportError(e);
        }
    },
    openInBrowserURL: function (sURL) {
        // method found in S3.Google.Translator
        try {
            openURL(sURL);
        }
        catch (e) {

            Cu.reportError(e);
        }
    },
    onParseText: function (e) {
        this.parse();
    },
    onClosePanel: function (e) {
        this.closePanel();
    },
    onOpenGCOptions: function (e) {
        let that = this;
        let xPromise = this.xGCEWorker.post('getDefaultOptions');
        xPromise.then(
            function (aVal) {
                echo(aVal);
                prefs.setCharPref("sGCDefaultOptions", aVal);
            },
            function (aReason) { echo('Promise rejected', aReason); }
        ).catch(
            function (aCaught) { echo('Promise Error', aCaught); }
        ).then(
            function () {
                that.openDialog("chrome://grammarchecker/content/gc_options.xul", "", "chrome, dialog, modal, resizable=no");
                that.setOptions();
            },
            function (aReason) { echo('Error options dialog', aReason); }
        ).catch(
            function (aCaught) { echo('Error', aCaught); }
        );
    },
    onOpenSpellOptions: function (e) {
        this.openDialog("chrome://grammarchecker/content/spell_options.xul", "", "chrome, dialog, modal, resizable=no");
    },
    onOpenOptions: function (e) {
        this.openDialog("chrome://grammarchecker/content/options.xul", "", "chrome, dialog, modal, resizable=no");







>
|















>
|



















>
|














>
|








>
|













|


|

|





|

|







394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
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
            xNavBar.setAttribute("currentset", aSet.join(","));
            xNavBar.currentSet = aSet.join(",");
            document.persist(xNavBar.id, "currentset");
            try {
                BrowserToolboxCustomizeDone(true);
            }
            catch (e) {
                console.error(e);
                // Cu.reportError(e);
            }
        }
    },
    clearPreview: function() {
        let xPreview = document.getElementById("grammalecte-errors");
        while (xPreview.firstChild) {
            xPreview.removeChild(xPreview.firstChild);
        };
        let xEditor = GetCurrentEditor();
        if (xEditor != null) {
            try {
                xEditor.QueryInterface(Ci.nsIEditorStyleSheets);
                xEditor.addOverrideStyleSheet("chrome://grammarchecker/content/overlay.css");
            }
            catch (e) {
                console.error(e);
                // Cu.reportError(e);
            }
        }
        this.setInfo("[vide]");
    },
    setInfo: function (sText) {
        document.getElementById("grammalecte-info").textContent = sText;
    },
    openPanel: function () {
        document.getElementById("textformatter-splitter").setAttribute("state", "collapsed");
        document.getElementById("grammarchecker-splitter").setAttribute("state", "open");
    },
    closePanel: function () {
        document.getElementById("grammarchecker-splitter").setAttribute("state", "collapsed");
    },
    openDialog: function (sWhat, sName="", sOptions="") {
        try {
            window.openDialog(sWhat, sName, sOptions);
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    },
    openInTabURL: function (sURL) {
        // method found in S3.Google.Translator
        try {
            let xWM = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
            let xWin = xWM.getMostRecentWindow("mail:3pane");
            let xTabmail = xWin.document.getElementById('tabmail');
            xWin.focus();
            if (xTabmail) {
                xTabmail.openTab('contentTab', { contentPage: sURL });
            }
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    },
    openInBrowserURL: function (sURL) {
        // method found in S3.Google.Translator
        try {
            openURL(sURL);
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    },
    onParseText: function (e) {
        this.parse();
    },
    onClosePanel: function (e) {
        this.closePanel();
    },
    onOpenGCOptions: function (e) {
        let that = this;
        let xPromise = this.xGCEWorker.post('getDefaultOptions');
        xPromise.then(
            function (aVal) {
                console.log(aVal);
                prefs.setCharPref("sGCDefaultOptions", aVal);
            },
            function (aReason) { console.log('Promise rejected', aReason); }
        ).catch(
            function (aCaught) { console.log('Promise Error', aCaught); }
        ).then(
            function () {
                that.openDialog("chrome://grammarchecker/content/gc_options.xul", "", "chrome, dialog, modal, resizable=no");
                that.setOptions();
            },
            function (aReason) { console.log('Error options dialog', aReason); }
        ).catch(
            function (aCaught) { console.log('Error', aCaught); }
        );
    },
    onOpenSpellOptions: function (e) {
        this.openDialog("chrome://grammarchecker/content/spell_options.xul", "", "chrome, dialog, modal, resizable=no");
    },
    onOpenOptions: function (e) {
        this.openDialog("chrome://grammarchecker/content/options.xul", "", "chrome, dialog, modal, resizable=no");
528
529
530
531
532
533
534

535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553

554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570

571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
        }
    },
    _setDictionary: function (sDicName, sOptName) {
        try {
            oSpellControl.setExtensionDictFolder(sDicName, prefs.getBoolPref(sOptName));
        }
        catch (e) {

            Cu.reportError(e);
        }
    }
}


var oTextFormatter = {
    init: function () {
        try {
            this.closePanel();
            let sTFOptions = prefs.getCharPref("sTFOptions");
            if (sTFOptions !== "") {
                this.setOptionsInPanel(JSON.parse(sTFOptions));
                this.resetProgressBar();
            } else {
                this.reset();
            }
        }
        catch (e) {

            Cu.reportError(e);
        }
    },
    apply: function () {
        try {
            this.saveOptions();
            this.resetProgressBar();
            let xEditor = new Editor();
            let sText = xEditor.getContent();
            let iParagraph = 0;
            sText = this.applyOptions(sText);
            for (let sParagraph of text.getParagraph(sText)) {
                xEditor.writeParagraph(iParagraph, sParagraph);
                iParagraph += 1;
            }
        }
        catch (e) {

            Cu.reportError(e);
        }
    },
    saveOptions: function () {
        let oOptions = {};
        for (let xNode of document.getElementsByClassName("option")) {
            oOptions[xNode.id] = xNode.checked;
        }
        //echo("save options: " + JSON.stringify(oOptions));
        prefs.setCharPref("sTFOptions", JSON.stringify(oOptions));
    },
    setOptionsInPanel: function (oOptions) {
        for (let sOptName in oOptions) {
            //console.log(sOptName + ":" + oOptions[sOptName]);
            if (document.getElementById(sOptName) !== null) {
                document.getElementById(sOptName).checked = oOptions[sOptName];







>
|


















>
|
















>
|







|







526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
        }
    },
    _setDictionary: function (sDicName, sOptName) {
        try {
            oSpellControl.setExtensionDictFolder(sDicName, prefs.getBoolPref(sOptName));
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    }
}


var oTextFormatter = {
    init: function () {
        try {
            this.closePanel();
            let sTFOptions = prefs.getCharPref("sTFOptions");
            if (sTFOptions !== "") {
                this.setOptionsInPanel(JSON.parse(sTFOptions));
                this.resetProgressBar();
            } else {
                this.reset();
            }
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    },
    apply: function () {
        try {
            this.saveOptions();
            this.resetProgressBar();
            let xEditor = new Editor();
            let sText = xEditor.getContent();
            let iParagraph = 0;
            sText = this.applyOptions(sText);
            for (let sParagraph of text.getParagraph(sText)) {
                xEditor.writeParagraph(iParagraph, sParagraph);
                iParagraph += 1;
            }
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    },
    saveOptions: function () {
        let oOptions = {};
        for (let xNode of document.getElementsByClassName("option")) {
            oOptions[xNode.id] = xNode.checked;
        }
        //console.log("save options: " + JSON.stringify(oOptions));
        prefs.setCharPref("sTFOptions", JSON.stringify(oOptions));
    },
    setOptionsInPanel: function (oOptions) {
        for (let sOptName in oOptions) {
            //console.log(sOptName + ":" + oOptions[sOptName]);
            if (document.getElementById(sOptName) !== null) {
                document.getElementById(sOptName).checked = oOptions[sOptName];
607
608
609
610
611
612
613

614
615
616
617
618
619
620
621
                xNode.checked = (xNode.getAttribute('data-default') === "true");
                if (xNode.id.startsWith("o_group_")) {
                    this.switchGroup(xNode.id);
                }
            }
        }
        catch (e) {

            Cu.reportError(e);
        }
    },
    resetProgressBar: function () {
        document.getElementById('progressbar').value = 0;
        document.getElementById('time_res').textContent = "";
    },
    getTimeRes: function (n) {







>
|







608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
                xNode.checked = (xNode.getAttribute('data-default') === "true");
                if (xNode.id.startsWith("o_group_")) {
                    this.switchGroup(xNode.id);
                }
            }
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
    },
    resetProgressBar: function () {
        document.getElementById('progressbar').value = 0;
        document.getElementById('time_res').textContent = "";
    },
    getTimeRes: function (n) {
883
884
885
886
887
888
889

890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906

907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
            // end of processing

            //window.setCursor("auto"); // restore pointer
            const t1 = Date.now();
            document.getElementById('time_res').textContent = this.getTimeRes((t1-t0)/1000);
        }
        catch (e) {

            Cu.reportError(e);
        }
        return sText;
    },
    formatText: function (sText, sOptName) {
        let nCount = 0;
        try {
            if (!tf.oReplTable.hasOwnProperty(sOptName)) {
                echo("# Error. TF: there is no option “" + sOptName+ "”.");
                return [sText, nCount];
            }
            for (let [zRgx, sRep] of tf.oReplTable[sOptName]) {
                nCount += (sText.match(zRgx) || []).length;
                sText = sText.replace(zRgx, sRep);
            }
        }
        catch (e) {

            Cu.reportError(e);
        }
        return [sText, nCount];
    }
}


/* EVENTS */

window.addEventListener("click", function (xEvent) {
    let xElem = xEvent.target;
    if (xElem.id && xElem.id.startsWith("o_group_")) {
        oTextFormatter.switchGroup(xElem.id);
        oTextFormatter.resetProgressBar();
    }
}, false);

window.addEventListener("load", function (xEvent) {
    oDictIgniter.init();
    oGrammarChecker.loadGC();
    //oGrammarChecker.fullTests();
}, false);

window.addEventListener("compose-window-init", function (xEvent) {
    oGrammarChecker.loadUI();
    oGrammarChecker.closePanel();
    oGrammarChecker.clearPreview();
    oTextFormatter.init();
}, true);







>
|






|
|


|





>
|

















|










885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
            // end of processing

            //window.setCursor("auto"); // restore pointer
            const t1 = Date.now();
            document.getElementById('time_res').textContent = this.getTimeRes((t1-t0)/1000);
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
        return sText;
    },
    formatText: function (sText, sOptName) {
        let nCount = 0;
        try {
            if (!oReplTable.hasOwnProperty(sOptName)) {
                console.log("# Error. TF: there is no option “" + sOptName+ "”.");
                return [sText, nCount];
            }
            for (let [zRgx, sRep] of oReplTable[sOptName]) {
                nCount += (sText.match(zRgx) || []).length;
                sText = sText.replace(zRgx, sRep);
            }
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
        }
        return [sText, nCount];
    }
}


/* EVENTS */

window.addEventListener("click", function (xEvent) {
    let xElem = xEvent.target;
    if (xElem.id && xElem.id.startsWith("o_group_")) {
        oTextFormatter.switchGroup(xElem.id);
        oTextFormatter.resetProgressBar();
    }
}, false);

window.addEventListener("load", function (xEvent) {
    // oDictIgniter.init();
    oGrammarChecker.loadGC();
    //oGrammarChecker.fullTests();
}, false);

window.addEventListener("compose-window-init", function (xEvent) {
    oGrammarChecker.loadUI();
    oGrammarChecker.closePanel();
    oGrammarChecker.clearPreview();
    oTextFormatter.init();
}, true);

Modified gc_lang/fr/tb/content/overlay.xul from [1a5af170ba] to [0101f0b174].

1
2
3
4
5
6
7
8
9


10
11
12
13

14
15
16
17
18
19
20
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="chrome://grammarchecker/content/overlay.css" type="text/css"?>

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

<overlay id="grammarchecker-overlay"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>


  <script type="application/x-javascript" src="overlay.js"/>
  <script type="application/x-javascript" src="file_handler.js"/>
  <script type="application/x-javascript" src="spellchecker.js"/>
  <script type="application/x-javascript" src="editor.js"/>


  <stringbundleset id="stringbundleset">
    <stringbundle id="grammarchecker-strings" src="chrome://grammarchecker/locale/grammarchecker.properties"/>
  </stringbundleset>

  <commandset id="composerEditMenuItems" commandupdater="true" 
              events="focus" 








|
>
>
|
|
|
|
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="chrome://grammarchecker/content/overlay.css" type="text/css"?>

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

<overlay id="grammarchecker-overlay"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="application/javascript" src="chrome://global/content/globalOverlay.js"/>
  <script type="application/javascript" src="resource://grammalecte/text.js"/>
  <script type="application/javascript" src="resource://grammalecte/fr/textformatter.js"/>
  <script type="application/javascript" src="overlay.js"/>
  <script type="application/javascript" src="file_handler.js"/>
  <script type="application/javascript" src="spellchecker.js"/>
  <script type="application/javascript" src="editor.js"/>


  <stringbundleset id="stringbundleset">
    <stringbundle id="grammarchecker-strings" src="chrome://grammarchecker/locale/grammarchecker.properties"/>
  </stringbundleset>

  <commandset id="composerEditMenuItems" commandupdater="true" 
              events="focus" 

Modified gc_lang/fr/tb/content/spell_options.css from [11e9c94ca2] to [c906b183f7].

17
18
19
20
21
22
23
24
25



















}

.dicdescr {
	margin-left: 27px;
}

.disabled {
	opacity: .25;
}


























|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
}

.dicdescr {
	margin-left: 27px;
}

.disabled {
  opacity: .25;
}


/*
    TB Next: fix dialogheaders
*/
dialogheader {
  -moz-binding: url("chrome://messenger/content/generalBindings.xml#dialogheader");
  margin: 0 5px 5px;
  border: 1px solid ThreeDDarkShadow;
  padding: 5px 8px;
  background-color: Highlight;
  color: HighlightText;
}

.dialogheader-title {
  margin: 0 !important;
  font-size: larger;
  font-weight: bold;
}

Modified gc_lang/fr/tb/content/spell_options.js from [f3284c0323] to [4e9d9b0e95].

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

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57
// 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.");
const { require } = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {});


function echo (...args) {
	Services.console.logStringMessage(args.join(" -- ") + "\n");
}


var oDialogControl = {
	load: function () {
		try {

			// Graphspell dictionaries
			document.getElementById('personal_dic').checked = prefs.getBoolPref('bPersonalDictionary');
			// Hunspell dictionaries
			document.getElementById('fr-FR-modern').checked = prefs.getBoolPref('bDictModern');
			document.getElementById('fr-FR-classic').checked = prefs.getBoolPref('bDictClassic');
			document.getElementById('fr-FR-reform').checked = prefs.getBoolPref('bDictReform');
			document.getElementById('fr-FR-classic-reform').checked = prefs.getBoolPref('bDictClassicReform');
			// center window
			document.getElementById('grammalecte-spelloptions-window').centerWindowOnScreen();
		}
		catch (e) {

			Cu.reportError(e);
		}
	},
	setDictionaries: function () {
		oSpellControl.init();
		this._setGraphspellDictionaries();
		this._setHunspellDictionary('fr-FR-modern', 'bDictModern');
		this._setHunspellDictionary('fr-FR-classic', 'bDictClassic');
		this._setHunspellDictionary('fr-FR-reform', 'bDictReform');
		this._setHunspellDictionary('fr-FR-classic-reform', 'bDictClassicReform');
	},
	_setHunspellDictionary: function (sDicName, sOptName) {
		try {
			let bActivate = document.getElementById(sDicName).checked;
			oSpellControl.setExtensionDictFolder(sDicName, bActivate);
			prefs.setBoolPref(sOptName, bActivate);
		}
		catch (e) {

			Cu.reportError(e);
		}
	},
	_setGraphspellDictionaries: function () {
		let bActivate = document.getElementById('personal_dic').checked;
		prefs.setBoolPref("bPersonalDictionary", bActivate);
	}
};







|

<
<
<
<
<
<





>











>
|

















>
|







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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// 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 oDialogControl = {
	load: function () {
		try {
			document.getElementById('grammalecte-spelloptions-window').centerWindowOnScreen();
			// Graphspell dictionaries
			document.getElementById('personal_dic').checked = prefs.getBoolPref('bPersonalDictionary');
			// Hunspell dictionaries
			document.getElementById('fr-FR-modern').checked = prefs.getBoolPref('bDictModern');
			document.getElementById('fr-FR-classic').checked = prefs.getBoolPref('bDictClassic');
			document.getElementById('fr-FR-reform').checked = prefs.getBoolPref('bDictReform');
			document.getElementById('fr-FR-classic-reform').checked = prefs.getBoolPref('bDictClassicReform');
			// center window
			document.getElementById('grammalecte-spelloptions-window').centerWindowOnScreen();
		}
		catch (e) {
			console.error(e);
			// Cu.reportError(e);
		}
	},
	setDictionaries: function () {
		oSpellControl.init();
		this._setGraphspellDictionaries();
		this._setHunspellDictionary('fr-FR-modern', 'bDictModern');
		this._setHunspellDictionary('fr-FR-classic', 'bDictClassic');
		this._setHunspellDictionary('fr-FR-reform', 'bDictReform');
		this._setHunspellDictionary('fr-FR-classic-reform', 'bDictClassicReform');
	},
	_setHunspellDictionary: function (sDicName, sOptName) {
		try {
			let bActivate = document.getElementById(sDicName).checked;
			oSpellControl.setExtensionDictFolder(sDicName, bActivate);
			prefs.setBoolPref(sOptName, bActivate);
		}
		catch (e) {
			console.error(e);
			// Cu.reportError(e);
		}
	},
	_setGraphspellDictionaries: function () {
		let bActivate = document.getElementById('personal_dic').checked;
		prefs.setBoolPref("bPersonalDictionary", bActivate);
	}
};

Modified gc_lang/fr/tb/content/spell_options.xul from [390fda8e41] to [996cd1abbc].

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
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://grammarchecker/content/spell_options.css" type="text/css"?>

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

<dialog
  id="grammalecte-spelloptions-window"
  title="&window.title;"
  orient="vertical"
  buttons="accept,cancel"
  ondialogaccept="oDialogControl.setDictionaries();"
  ondialogcancel="return;"
  width="800"
  height="680"
  onload="oDialogControl.load();"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <!-- Other elements go here -->
  
  <dialogheader id="grammalecte-title" title="&dialogheader.label;" description=""/>

  <hbox>

    <groupbox with="380">
      <caption id="grouptitle" label="&grouptitle_hunspell;" />
      <description id="warning">&warning_hunspell;</description>
      
      <checkbox id="fr-FR-modern" class="option" label="&option.modern.label;" />
      <description class="dicdescr">&option.modern.descr;</description>
      <checkbox id="fr-FR-classic" class="option" label="&option.classic.label;" />
      <description class="dicdescr">&option.classic.descr;</description>
      <checkbox id="fr-FR-reform" class="option" label="&option.reform.label;" />
      <description class="dicdescr">&option.reform.descr;</description>
      <checkbox id="fr-FR-classic-reform" class="option" label="&option.allvar.label;" />
      <description class="dicdescr">&option.allvar.descr;</description>
    </groupbox>


    <groupbox with="380">
      <caption id="grouptitle" label="&grouptitle_graphspell;" />
      <description id="warning">&warning_graphspell;</description>

      <checkbox id="main_dic" class="option" label="&option.main_dic.label;" disabled="true" checked="true" />
      <description class="dicdescr">&option.main_dic.descr;</description>

      <checkbox id="extended_dic" class="option disabled" label="&option.extended_dic.label;" disabled="true" />
      <description class="dicdescr disabled">&option.extended_dic.descr;</description>

      <checkbox id="community_dic" class="option disabled" label="&option.community_dic.label;" disabled="true" />
      <description class="dicdescr disabled">&option.community_dic.descr;</description>

      <checkbox id="personal_dic" class="option" label="&option.personal_dic.label;" />
      <description class="dicdescr">&option.personal_dic.descr;</description>
    </groupbox>
  </hbox>

  <script type="application/x-javascript" src="spell_options.js"/>
  <script type="application/x-javascript" src="spellchecker.js"/>

</dialog>













|
|




|



>



|









>



















|
|


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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://grammarchecker/content/spell_options.css" type="text/css"?>

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

<dialog
  id="grammalecte-spelloptions-window"
  title="&window.title;"
  orient="vertical"
  buttons="accept,cancel"
  ondialogaccept="oDialogControl.setDictionaries();"
  ondialogcancel="return;"
  width="400"
  height="480"
  onload="oDialogControl.load();"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <!-- Other elements go here -->

  <dialogheader id="grammalecte-title" title="&dialogheader.label;" description=""/>

  <hbox>
    <!--
    <groupbox with="380">
      <caption id="grouptitle" label="&grouptitle_hunspell;" />
      <description id="warning">&warning_hunspell;</description>

      <checkbox id="fr-FR-modern" class="option" label="&option.modern.label;" />
      <description class="dicdescr">&option.modern.descr;</description>
      <checkbox id="fr-FR-classic" class="option" label="&option.classic.label;" />
      <description class="dicdescr">&option.classic.descr;</description>
      <checkbox id="fr-FR-reform" class="option" label="&option.reform.label;" />
      <description class="dicdescr">&option.reform.descr;</description>
      <checkbox id="fr-FR-classic-reform" class="option" label="&option.allvar.label;" />
      <description class="dicdescr">&option.allvar.descr;</description>
    </groupbox>
    -->

    <groupbox with="380">
      <caption id="grouptitle" label="&grouptitle_graphspell;" />
      <description id="warning">&warning_graphspell;</description>

      <checkbox id="main_dic" class="option" label="&option.main_dic.label;" disabled="true" checked="true" />
      <description class="dicdescr">&option.main_dic.descr;</description>

      <checkbox id="extended_dic" class="option disabled" label="&option.extended_dic.label;" disabled="true" />
      <description class="dicdescr disabled">&option.extended_dic.descr;</description>

      <checkbox id="community_dic" class="option disabled" label="&option.community_dic.label;" disabled="true" />
      <description class="dicdescr disabled">&option.community_dic.descr;</description>

      <checkbox id="personal_dic" class="option" label="&option.personal_dic.label;" />
      <description class="dicdescr">&option.personal_dic.descr;</description>
    </groupbox>
  </hbox>

  <script type="application/javascript" src="spell_options.js"/>
  <script type="application/javascript" src="spellchecker.js"/>

</dialog>

Modified gc_lang/fr/tb/content/spellchecker.js from [3be1484aff] to [f4fc6376bf].

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112
113
114
115

116
117
118
119
120
121
122
123
124
125
126

127
128
129
130
131
132
133
134
135
136
137
138


139
140
141
142
143
144
145
146

147
148
149
150

151
152
153
154
// JavaScript

/*
	Hunspell wrapper

	XPCOM obsolete (?), but there is nothing else...
	Overly complicated and weird. To throw away ASAP if possible.

	And you can’t access to this from a PromiseWorker (it sucks).

	https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/mozISpellCheckingEngine
	https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Using_spell_checking_in_XUL
	https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFile
	https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/FileUtils.jsm
*/

"use strict";

/*

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const { require } = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {});
*/


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";
				}
				if ("@mozilla.org/spellchecker/engine;1" in Cc) {
				    sSpellchecker = "@mozilla.org/spellchecker/engine;1";
				}
				this.xSCEngine = Cc[sSpellchecker].getService(Ci.mozISpellCheckingEngine);
			}
			catch (e) {
				echo("Can’t initiate the spellchecker.");

				Cu.reportError(e);
			}
		}
	},
	getDictionariesList: function () {
		this.init();
		try {
			let l = {};
			let c = {};
			this.xSCEngine.getDictionaryList(l, c);
			return l.value;
		}
		catch (e) {

			Cu.reportError(e);
			return [];
		}
	},
	setDictionary: function (sLocale) {
		if (this.getDictionariesList().includes(sLocale)) {
			try {
				this.xSCEngine.dictionary = sLocale; // en-US, fr, etc.
				return true;
			}
			catch (e) {

				Cu.reportError(e);
				return false;
			}
		} else {
			echo("Warning. No dictionary for locale: " + sLocale);
			echo("Existing dictionaries: " + this.getDictionariesList().join(" | "));
		}
		return false;
	},
	check: function (sWord) {
		// todo: check in personal dict?
		try {
			return this.xSCEngine.check(sWord);
		}
		catch (e) {

			Cu.reportError(e);
			return false;
		}
	},
	suggest: function (sWord) {
		try {
			let lSugg = {};
			this.xSCEngine.suggest(sWord, lSugg, {});
			return lSugg.value;
		   	// lSugg.value is a JavaScript Array of strings
		}
		catch (e) {

			Cu.reportError(e);
			return ['#Erreur.'];
		}
	},
	addDirectory: function (sFolder) {
		try {
			let xNsiFolder = new FileUtils.File(sFolder);
			this.xSCEngine.addDirectory(xNsiFolder);
		}
		catch (e) {
			echo("Unable to add directory: " + sFolder);

			Cu.reportError(e);
		}
	},
	removeDirectory: function (sFolder) {
		// does not work but no exception raised (bug?)
		try {
			let xNsiFolder = new FileUtils.File(sFolder);
			this.xSCEngine.removeDirectory(xNsiFolder);
		}
		catch (e) {
			echo("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") {


					sFolder = sFolder.slice(1).replace(/\//g, "\\\\");
				}
				//console.log("> " + sFolder);
				if (bActivate) {
					that.addDirectory(sFolder);
				} else {
					that.removeDirectory(sFolder);
				}

			});
		}
		catch (e) {
			echo("Unable to add extension folder");

			Cu.reportError(e);
		}
	}
};



|

|
|

|

|
|
|
|





>






<
|
|
<
<
<
<
<
<
<



|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
>
>
|
|
|
|
|
|
|
|
>
|
|
|
|
>
|
|
|

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// JavaScript

/*
    Hunspell wrapper

    XPCOM obsolete (?), but there is nothing else...
    Overly complicated and weird. To throw away ASAP if possible.

    And you can’t access to this from a PromiseWorker (it sucks).

    https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/mozISpellCheckingEngine
    https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Using_spell_checking_in_XUL
    https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFile
    https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/FileUtils.jsm
*/

"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", {});
*/


const FileUtils = ChromeUtils.import("resource://gre/modules/FileUtils.jsm").FileUtils;
const AddonManager = ChromeUtils.import("resource://gre/modules/AddonManager.jsm").AddonManager;









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";
                }
                if ("@mozilla.org/spellchecker/engine;1" in Cc) {
                    sSpellchecker = "@mozilla.org/spellchecker/engine;1";
                }
                this.xSCEngine = Cc[sSpellchecker].getService(Ci.mozISpellCheckingEngine);
            }
            catch (e) {
                console.log("Can’t initiate the spellchecker.");
                console.error(e);
                // Cu.reportError(e);
            }
        }
    },
    getDictionariesList: function () {
        this.init();
        try {
            let l = {};
            let c = {};
            this.xSCEngine.getDictionaryList(l, c);
            return l.value;
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
            return [];
        }
    },
    setDictionary: function (sLocale) {
        if (this.getDictionariesList().includes(sLocale)) {
            try {
                this.xSCEngine.dictionary = sLocale; // en-US, fr, etc.
                return true;
            }
            catch (e) {
                console.error(e);
                // Cu.reportError(e);
                return false;
            }
        } else {
            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?
        try {
            return this.xSCEngine.check(sWord);
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
            return false;
        }
    },
    suggest: function (sWord) {
        try {
            let lSugg = {};
            this.xSCEngine.suggest(sWord, lSugg, {});
            return lSugg.value;
            // lSugg.value is a JavaScript Array of strings
        }
        catch (e) {
            console.error(e);
            // Cu.reportError(e);
            return ['#Erreur.'];
        }
    },
    addDirectory: function (sFolder) {
        try {
            let xNsiFolder = new FileUtils.File(sFolder);
            this.xSCEngine.addDirectory(xNsiFolder);
        }
        catch (e) {
            console.log("Unable to add directory: " + sFolder);
            console.error(e);
            // Cu.reportError(e);
        }
    },
    removeDirectory: function (sFolder) {
        // does not work but no exception raised (bug?)
        try {
            let xNsiFolder = new FileUtils.File(sFolder);
            this.xSCEngine.removeDirectory(xNsiFolder);
        }
        catch (e) {
            console.log("Unable to remove directory: " + sFolder);
            console.error(e);
            // 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);
                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) {
            console.log("Unable to add extension folder");
            console.error(e);
            // Cu.reportError(e);
        }
    }
};

Modified gc_lang/fr/tb/install.rdf from [96b9474d12] to [0993527248].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xml version="1.0" encoding="UTF-8"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
 xmlns:em="http://www.mozilla.org/2004/em-rdf#">
  <Description about="urn:mozilla:install-manifest">
    <em:id>${tb_identifier}</em:id>
    <em:name>${tb_name}</em:name>
    <em:type>2</em:type>
    <em:version>${version}</em:version>
    <em:creator>${author}</em:creator>
    <em:description>${description}</em:description>
    <em:homepageURL>${link}</em:homepageURL>
    <em:optionsURL>chrome://grammarchecker/content/options.xul</em:optionsURL>
    <em:unpack>true</em:unpack>

    <em:targetApplication>
      <Description>
        <em:id>{3550f703-e582-4d05-9a08-453d09bdfdc6}</em:id> <!-- thunderbird -->
        <em:minVersion>45.8.0</em:minVersion>
        <em:maxVersion>56.*</em:maxVersion>
      </Description>
    </em:targetApplication>
  </Description>
</RDF>











|





|
|




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xml version="1.0" encoding="UTF-8"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
 xmlns:em="http://www.mozilla.org/2004/em-rdf#">
  <Description about="urn:mozilla:install-manifest">
    <em:id>${tb_identifier}</em:id>
    <em:name>${tb_name}</em:name>
    <em:type>2</em:type>
    <em:version>${version}</em:version>
    <em:creator>${author}</em:creator>
    <em:description>${description}</em:description>
    <em:homepageURL>${link}</em:homepageURL>
    <!--<em:optionsURL>chrome://grammarchecker/content/options.xul</em:optionsURL>-->
    <em:unpack>true</em:unpack>

    <em:targetApplication>
      <Description>
        <em:id>{3550f703-e582-4d05-9a08-453d09bdfdc6}</em:id> <!-- thunderbird -->
        <em:minVersion>59.0</em:minVersion>
        <em:maxVersion>61.*</em:maxVersion>
      </Description>
    </em:targetApplication>
  </Description>
</RDF>

Modified gc_lang/fr/tb/locale/en/options.dtd from [071253db94] to [5fe56718ba].

1
2
3
4
5
6
7


<!ENTITY prefwindow.title "Grammalecte · Options">
<!ENTITY pane1.title "Other options">
<!ENTITY pane1.description "Options are available in the menu Grammalecte in composing windows.">
<!ENTITY mothertongue.label "Mother tongue:">
<!ENTITY mothertongue.accesskey "M">
<!ENTITY check_signature.label "Check signature text (in text mode)">
<!ENTITY check_signature.accesskey "C">


|
|
<
<
<


>
>
1
2



3
4
5
6
<!ENTITY window.title "Grammalecte · Options">
<!ENTITY dialogheader.label "Other options">



<!ENTITY check_signature.label "Check signature text (in text mode)">
<!ENTITY check_signature.accesskey "C">


Modified gc_lang/fr/tb/locale/fr/options.dtd from [a50c0f39f8] to [37a043f079].

1
2
3
4
5
6
7
<!ENTITY prefwindow.title "Grammalecte · Options">
<!ENTITY pane1.title "Autres options">
<!ENTITY pane1.description "Les options sont disponibles dans le menu Grammalecte des fenêtres de rédaction.">
<!ENTITY mothertongue.label "Langue maternelle:">
<!ENTITY mothertongue.accesskey "M">
<!ENTITY check_signature.label "Vérifier le texte de la signature (en mode texte)">
<!ENTITY check_signature.accesskey "V">
|
|
<
<
<


1
2



3
4
<!ENTITY window.title "Grammalecte · Options">
<!ENTITY dialogheader.label "Autres options">



<!ENTITY check_signature.label "Vérifier le texte de la signature (en mode texte)">
<!ENTITY check_signature.accesskey "V">

Modified graphspell-js/helpers.js from [b70dea39e2] to [d93f7e0941].

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

    loadFile: function (spf) {
        // load ressources in workers (suggested by Mozilla extensions reviewers)
        // for more options have a look here: https://gist.github.com/Noitidart/ec1e6b9a593ec7e3efed
        // if not in workers, use sdk/data.load() instead
        try {
            let xRequest;
            if (typeof XMLHttpRequest !== "undefined") {
                xRequest = new XMLHttpRequest();
            } else {
                // JS sucks again… necessary for Thunderbird
                let { Cc, Ci } = require("chrome");
                xRequest = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
                xRequest.QueryInterface(Ci.nsIXMLHttpRequest);
            }
            xRequest.open('GET', spf, false); // 3rd arg is false for synchronous, sync is acceptable in workers
            xRequest.overrideMimeType('text/json');
            xRequest.send();
            return xRequest.responseText;
        }
        catch (e) {
            this.logerror(e);







<
|
<
<
<
<
<
<







49
50
51
52
53
54
55

56






57
58
59
60
61
62
63

    loadFile: function (spf) {
        // load ressources in workers (suggested by Mozilla extensions reviewers)
        // for more options have a look here: https://gist.github.com/Noitidart/ec1e6b9a593ec7e3efed
        // if not in workers, use sdk/data.load() instead
        try {
            let xRequest;

            xRequest = new XMLHttpRequest();






            xRequest.open('GET', spf, false); // 3rd arg is false for synchronous, sync is acceptable in workers
            xRequest.overrideMimeType('text/json');
            xRequest.send();
            return xRequest.responseText;
        }
        catch (e) {
            this.logerror(e);

Modified make.py from [14e0172bf2] to [3fef4d51d6].

374
375
376
377
378
379
380

381
382
383
384
385
386
387
    xParser.add_argument("-aed", "--add_extended_dictionary", help="add extended dictionary to the build", action="store_true")
    xParser.add_argument("-acd", "--add_community_dictionary", help="add community dictionary to the build", action="store_true")
    xParser.add_argument("-apd", "--add_personal_dictionary", help="add personal dictionary to the build", action="store_true")
    xParser.add_argument("-fx", "--firefox", help="Launch Firefox Developper for WebExtension testing", action="store_true")
    xParser.add_argument("-we", "--web_ext", help="Launch Firefox Nightly for WebExtension testing", action="store_true")
    xParser.add_argument("-l", "--lint_web_ext", help="web-ext lint on the WebExtension", action="store_true")
    xParser.add_argument("-tb", "--thunderbird", help="Launch Thunderbird", action="store_true")

    xParser.add_argument("-i", "--install", help="install the extension in Writer (path of unopkg must be set in config.ini)", action="store_true")
    xArgs = xParser.parse_args()

    if xArgs.build_data:
        xArgs.build_data_before = True
        xArgs.build_data_after = True








>







374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
    xParser.add_argument("-aed", "--add_extended_dictionary", help="add extended dictionary to the build", action="store_true")
    xParser.add_argument("-acd", "--add_community_dictionary", help="add community dictionary to the build", action="store_true")
    xParser.add_argument("-apd", "--add_personal_dictionary", help="add personal dictionary to the build", action="store_true")
    xParser.add_argument("-fx", "--firefox", help="Launch Firefox Developper for WebExtension testing", action="store_true")
    xParser.add_argument("-we", "--web_ext", help="Launch Firefox Nightly for WebExtension testing", action="store_true")
    xParser.add_argument("-l", "--lint_web_ext", help="web-ext lint on the WebExtension", action="store_true")
    xParser.add_argument("-tb", "--thunderbird", help="Launch Thunderbird", action="store_true")
    xParser.add_argument("-tbb", "--thunderbird_beta", help="Launch Thunderbird Beta", action="store_true")
    xParser.add_argument("-i", "--install", help="install the extension in Writer (path of unopkg must be set in config.ini)", action="store_true")
    xArgs = xParser.parse_args()

    if xArgs.build_data:
        xArgs.build_data_before = True
        xArgs.build_data_after = True

467
468
469
470
471
472
473


474




475
476
477
478
479
480
481
482
483
                        spfFirefox = dVars['win_fx_nightly_path']  if platform.system() == "Windows"  else dVars['linux_fx_nightly_path']
                    os.system(r'web-ext run --firefox="' + spfFirefox + '" --browser-console --firefox-profile=debug')
                    # https://github.com/mozilla/web-ext/issues/932
                    # os.system(r'web-ext run --firefox="' + spfFirefox + r'" --browser-console --firefox-profile=C:\Users\EAK\AppData\Roaming\Mozilla\Firefox\Profiles\e26559tw.debug --keep-profile-changes')

            # Thunderbird
            if xArgs.thunderbird:


                os.system("thunderbird -jsconsole -P debug")




        else:
            print("Folder not found: gc_lang/"+sLang)

    oNow = datetime.datetime.now()
    print("============== MAKE GRAMMALECTE [finished] at {0.hour:>2} h {0.minute:>2} min {0.second:>2} s ==============".format(oNow))


if __name__ == '__main__':
    main()







>
>
|
>
>
>
>









468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
                        spfFirefox = dVars['win_fx_nightly_path']  if platform.system() == "Windows"  else dVars['linux_fx_nightly_path']
                    os.system(r'web-ext run --firefox="' + spfFirefox + '" --browser-console --firefox-profile=debug')
                    # https://github.com/mozilla/web-ext/issues/932
                    # os.system(r'web-ext run --firefox="' + spfFirefox + r'" --browser-console --firefox-profile=C:\Users\EAK\AppData\Roaming\Mozilla\Firefox\Profiles\e26559tw.debug --keep-profile-changes')

            # Thunderbird
            if xArgs.thunderbird:
                spfThunderbird = '"'+dVars['win_tb_path']+'"'  if platform.system() == "Windows"  else dVars['linux_tb_path']
                print(spfThunderbird)
                os.system(spfThunderbird + ' -jsconsole -P debug')
            if xArgs.thunderbird_beta:
                spfThunderbird = '"'+dVars['win_tb_beta_path']+'"'  if platform.system() == "Windows"  else dVars['linux_tb_beta_path']
                print(spfThunderbird)
                os.system(spfThunderbird + ' -jsconsole -P beta')
        else:
            print("Folder not found: gc_lang/"+sLang)

    oNow = datetime.datetime.now()
    print("============== MAKE GRAMMALECTE [finished] at {0.hour:>2} h {0.minute:>2} min {0.second:>2} s ==============".format(oNow))


if __name__ == '__main__':
    main()