Grammalecte  Check-in [1c3f0579cf]

Overview
Comment:[fx] open lexicon editor from an unknown word error
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256: 1c3f0579cf89bba177d767f075a11bcd550d4b14dd9451df1584532001ef728c
User & Date: olr on 2020-10-31 17:43:55
Other Links: manifest | tags
Context
2020-11-02
14:49
[fr] ajustements check-in: e83a01147e user: olr tags: trunk, fr
2020-10-31
17:43
[fx] open lexicon editor from an unknown word error check-in: 1c3f0579cf user: olr tags: trunk, fx
17:43
[fr] ajustements check-in: ea86352a28 user: olr tags: trunk, fr
Changes

Modified gc_lang/fr/webext/background.js from [8760b8d3dd] to [502b8838ad].

344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
            case "openConjugueurTab":
                openConjugueurTab();
                break;
            case "openConjugueurWindow":
                openConjugueurWindow();
                break;
            case "openLexiconEditor":
                openLexiconEditor();
                break;
            default:
                console.log("[background] Unknown command: " + sCommand);
                console.log(oRequest);
        }
    });
    //xPort.postMessage({sActionDone: "newId", result: iPortId});







|







344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
            case "openConjugueurTab":
                openConjugueurTab();
                break;
            case "openConjugueurWindow":
                openConjugueurWindow();
                break;
            case "openLexiconEditor":
                openLexiconEditor("__personal__", oParam["sWord"]);
                break;
            default:
                console.log("[background] Unknown command: " + sCommand);
                console.log(oRequest);
        }
    });
    //xPort.postMessage({sActionDone: "newId", result: iPortId});
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380

/*
    ComposeAction
    (Thunderbird only)
*/
if (bThunderbird) {
    messenger.composeAction.onClicked.addListener(function (xTab, xData) {
        sendCommandToTab(xTab.id, "grammar_checker_compose_window");
    });
}


/*
    Context Menu
    (not for MailExtension)







|







366
367
368
369
370
371
372
373
374
375
376
377
378
379
380

/*
    ComposeAction
    (Thunderbird only)
*/
if (bThunderbird) {
    messenger.composeAction.onClicked.addListener(function (xTab, xData) {
        sendCommandToTabViaPort(xTab.id, "grammar_checker_compose_window");
    });
}


/*
    Context Menu
    (not for MailExtension)
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
        // xInfo = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/OnClickData
        // xTab = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/Tab
        // confusing: no way to get the node where we click?!
        switch (xInfo.menuItemId) {
            // analyze
            case "grammar_checker_editable":
            case "grammar_checker_page":
                sendCommandToTab(xTab.id, xInfo.menuItemId);
                break;
            case "grammar_checker_iframe":
                sendCommandToTab(xTab.id, xInfo.menuItemId, xInfo.frameId);
                break;
            case "grammar_checker_selection":
                sendCommandToTab(xTab.id, xInfo.menuItemId, xInfo.selectionText);
                break;
            // tools
            case "conjugueur_window":
                openConjugueurWindow();
                break;
            case "conjugueur_tab":
                openConjugueurTab();







|


|


|







396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
        // xInfo = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/OnClickData
        // xTab = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/Tab
        // confusing: no way to get the node where we click?!
        switch (xInfo.menuItemId) {
            // analyze
            case "grammar_checker_editable":
            case "grammar_checker_page":
                sendCommandToTabViaPort(xTab.id, xInfo.menuItemId);
                break;
            case "grammar_checker_iframe":
                sendCommandToTabViaPort(xTab.id, xInfo.menuItemId, xInfo.frameId);
                break;
            case "grammar_checker_selection":
                sendCommandToTabViaPort(xTab.id, xInfo.menuItemId, xInfo.selectionText);
                break;
            // tools
            case "conjugueur_window":
                openConjugueurWindow();
                break;
            case "conjugueur_tab":
                openConjugueurTab();
475
476
477
478
479
480
481
482
483
484
485





486
487
488
489
490
491
492
function storeGCOptions (dOptions) {
    if (dOptions instanceof Map) {
        dOptions = helpers.mapToObject(dOptions);
    }
    browser.storage.local.set({"gc_options": dOptions});
}

function sendCommandToTab (iTab, sCommand, result=null) {
    let xTabPort = dConnx.get(iTab);
    xTabPort.postMessage({sActionDone: sCommand, result: result, oInfo: null, bEnd: false, bError: false});
}






function sendCommandToCurrentTab (sCommand) {
    if (bChrome) {
        browser.tabs.query({ currentWindow: true, active: true }, (lTabs) => {
            for (let xTab of lTabs) {
                //console.log(xTab);
                browser.tabs.sendMessage(xTab.id, {sActionRequest: sCommand});







|



>
>
>
>
>







475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
function storeGCOptions (dOptions) {
    if (dOptions instanceof Map) {
        dOptions = helpers.mapToObject(dOptions);
    }
    browser.storage.local.set({"gc_options": dOptions});
}

function sendCommandToTabViaPort (iTab, sCommand, result=null) {
    let xTabPort = dConnx.get(iTab);
    xTabPort.postMessage({sActionDone: sCommand, result: result, oInfo: null, bEnd: false, bError: false});
}

function sendCommandToTab (iTab, sCommand, oParam=null) {
    //console.log("send to:", iTab, "command:", sCommand, "params:", oParam);
    browser.tabs.sendMessage(iTab, {sActionRequest: sCommand, oParam: oParam});
}

function sendCommandToCurrentTab (sCommand) {
    if (bChrome) {
        browser.tabs.query({ currentWindow: true, active: true }, (lTabs) => {
            for (let xTab of lTabs) {
                //console.log(xTab);
                browser.tabs.sendMessage(xTab.id, {sActionRequest: sCommand});
504
505
506
507
508
509
510



511
512

513
514
515
516
517
518
519
520
521
522
523
524
525

526
527
528
529
530



531
532
533
534
535
536
537

function sendCommandToAllTabs (sCommand) {
    for (let [iTab, xTabPort] of dConnx.entries()) {
        xTabPort.postMessage({sActionDone: sCommand, result: null, oInfo: null, bEnd: false, bError: false});
    }
}




function openLexiconEditor (sName="__personal__") {
    if (nTabLexiconEditor === null) {

        if (bChrome) {
            browser.tabs.create({
                url: browser.runtime.getURL("panel/lex_editor.html")
            }, onLexiconEditorOpened);
            return;
        }
        let xLexEditor = browser.tabs.create({
            url: browser.runtime.getURL("panel/lex_editor.html")
        });
        xLexEditor.then(onLexiconEditorOpened, showError);
    }
    else {
        browser.tabs.update(nTabLexiconEditor, {active: true});

    }
}

function onLexiconEditorOpened (xTab) {
    nTabLexiconEditor = xTab.id;



}

function openDictionaries () {
    if (nTabDictionaries === null) {
        if (bChrome) {
            browser.tabs.create({
                url: browser.runtime.getURL("panel/dictionaries.html")







>
>
>
|

>













>





>
>
>







509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
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

function sendCommandToAllTabs (sCommand) {
    for (let [iTab, xTabPort] of dConnx.entries()) {
        xTabPort.postMessage({sActionDone: sCommand, result: null, oInfo: null, bEnd: false, bError: false});
    }
}


let sWordForLexiconEditor = "";

function openLexiconEditor (sName="__personal__", sWord="") {
    if (nTabLexiconEditor === null) {
        sWordForLexiconEditor = sWord;
        if (bChrome) {
            browser.tabs.create({
                url: browser.runtime.getURL("panel/lex_editor.html")
            }, onLexiconEditorOpened);
            return;
        }
        let xLexEditor = browser.tabs.create({
            url: browser.runtime.getURL("panel/lex_editor.html")
        });
        xLexEditor.then(onLexiconEditorOpened, showError);
    }
    else {
        browser.tabs.update(nTabLexiconEditor, {active: true});
        sendCommandToTab(nTabLexiconEditor, "new_entry", { sWord: sWord });
    }
}

function onLexiconEditorOpened (xTab) {
    nTabLexiconEditor = xTab.id;
    if (sWordForLexiconEditor !== "") {
        setTimeout(sendCommandToTab, 1000, nTabLexiconEditor, "new_entry", { sWord: sWordForLexiconEditor });
    }
}

function openDictionaries () {
    if (nTabDictionaries === null) {
        if (bChrome) {
            browser.tabs.create({
                url: browser.runtime.getURL("panel/dictionaries.html")

Modified gc_lang/fr/webext/content_scripts/init.js from [b54947b0d1] to [e22c4ced0c].

360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
        this.send("getSpellSuggestions", { sWord: sWord }, { sDestination: sDestination, sErrorId: sErrorId });
    },

    openURL: function (sURL) {
        this.send("openURL", { "sURL": sURL });
    },

    openLexiconEditor: function () {
        this.send("openLexiconEditor");
    },

    restartWorker: function (nTimeDelay=10) {
        this.send("restartWorker", { "nTimeDelay": nTimeDelay });
    },

    /*







|
|







360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
        this.send("getSpellSuggestions", { sWord: sWord }, { sDestination: sDestination, sErrorId: sErrorId });
    },

    openURL: function (sURL) {
        this.send("openURL", { "sURL": sURL });
    },

    openLexiconEditor: function (sWord="") {
        this.send("openLexiconEditor", { sWord: sWord });
    },

    restartWorker: function (nTimeDelay=10) {
        this.send("restartWorker", { "nTimeDelay": nTimeDelay });
    },

    /*

Modified gc_lang/fr/webext/content_scripts/panel_gc.css from [89a25fc756] to [d65d10b5ae].

147
148
149
150
151
152
153
154

155
156
157
158
159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
    text-decoration: none;
}
div#grammalecte_tooltip_ignore:hover {
    background-color: hsl(30, 30%, 50%);
    color: hsla(0, 0%, 100%, 1);
    text-shadow: 0 0 3px hsl(30, 30%, 60%);
}
div#grammalecte_tooltip_url {

    display: inline-block;
    margin-left: 10px;
    padding: 1px 5px;
    background-color: hsl(210, 50%, 50%);
    color: hsla(210, 0%, 96%, 1);
    border-radius: 2px;
    cursor: pointer;
    font-family: Tahoma, "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", sans-serif;
    font-size: 12px;
    text-decoration: none;
}
div#grammalecte_tooltip_url:hover {

    background-color: hsl(210, 50%, 60%);
    color: hsla(0, 0%, 100%, 1);
    text-shadow: 0 0 3px hsl(210, 30%, 60%);
}
div#grammalecte_tooltip_db_search {
    display: inline-block;
    margin-left: 10px;







|
>











|
>







147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
    text-decoration: none;
}
div#grammalecte_tooltip_ignore:hover {
    background-color: hsl(30, 30%, 50%);
    color: hsla(0, 0%, 100%, 1);
    text-shadow: 0 0 3px hsl(30, 30%, 60%);
}
div#grammalecte_tooltip_url,
div#grammalecte_tooltip_open_lexed {
    display: inline-block;
    margin-left: 10px;
    padding: 1px 5px;
    background-color: hsl(210, 50%, 50%);
    color: hsla(210, 0%, 96%, 1);
    border-radius: 2px;
    cursor: pointer;
    font-family: Tahoma, "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", sans-serif;
    font-size: 12px;
    text-decoration: none;
}
div#grammalecte_tooltip_url:hover,
div#grammalecte_tooltip_open_lexed:hover {
    background-color: hsl(210, 50%, 60%);
    color: hsla(0, 0%, 100%, 1);
    text-shadow: 0 0 3px hsl(210, 30%, 60%);
}
div#grammalecte_tooltip_db_search {
    display: inline-block;
    margin-left: 10px;

Modified gc_lang/fr/webext/content_scripts/panel_gc.js from [9de466bad8] to [901571cea6].

941
942
943
944
945
946
947


948
949
950




951
952
953
954
955
956
957
        // suggestions
        this.xTooltip.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_tooltip_sugg_title", textContent: "SUGGESTIONS :"}));
        this.xTooltipSuggBlock = oGrammalecte.createNode("div", {id: "grammalecte_tooltip_sugg_block"});
        this.xTooltip.appendChild(this.xTooltipSuggBlock);
        // actions
        let xActions = oGrammalecte.createNode("div", {id: "grammalecte_tooltip_actions"});
        xActions.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_tooltip_ignore", textContent: "Ignorer"}));


        xActions.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_tooltip_url", textContent: "Voulez-vous en savoir plus ?…"}, {url: ""}));
        xActions.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_tooltip_db_search", textContent: "››"}, {url: ""}));
        this.xTooltip.appendChild(xActions);




        // add tooltip to the page
        xGCPanelContent.appendChild(this.xTooltip);
        xGCPanelContent.appendChild(this.xTooltipArrow);
    }

    show (xParagraph, sNodeErrorId) {  // err
        try {







>
>



>
>
>
>







941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
        // suggestions
        this.xTooltip.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_tooltip_sugg_title", textContent: "SUGGESTIONS :"}));
        this.xTooltipSuggBlock = oGrammalecte.createNode("div", {id: "grammalecte_tooltip_sugg_block"});
        this.xTooltip.appendChild(this.xTooltipSuggBlock);
        // actions
        let xActions = oGrammalecte.createNode("div", {id: "grammalecte_tooltip_actions"});
        xActions.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_tooltip_ignore", textContent: "Ignorer"}));
        this.xLexEditNode = oGrammalecte.createNode("div", {id: "grammalecte_tooltip_open_lexed", textContent: "›› Éditeur lexical…"})
        xActions.appendChild(this.xLexEditNode);
        xActions.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_tooltip_url", textContent: "Voulez-vous en savoir plus ?…"}, {url: ""}));
        xActions.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_tooltip_db_search", textContent: "››"}, {url: ""}));
        this.xTooltip.appendChild(xActions);
        this.sUnknownWord = "";
        this.xLexEditNode.onclick = () => {
            oGrammalecteBackgroundPort.openLexiconEditor(this.sUnknownWord);
        };
        // add tooltip to the page
        xGCPanelContent.appendChild(this.xTooltip);
        xGCPanelContent.appendChild(this.xTooltipArrow);
    }

    show (xParagraph, sNodeErrorId) {  // err
        try {
998
999
1000
1001
1002
1003
1004

1005
1006
1007
1008
1009

1010
1011
1012
1013
1014
1015
1016
                    }
                } else {
                    this.xTooltipSuggBlock.textContent = "Aucune.";
                }
            }
            if (xNodeErr.dataset.error_type === "spelling") {
                // spelling mistake

                this.xParent.getElementById("grammalecte_tooltip_message").textContent = "Mot inconnu du dictionnaire.";
                this.xParent.getElementById("grammalecte_tooltip_ignore").dataset.error_id = xNodeErr.dataset.error_id;
                this.xParent.getElementById("grammalecte_tooltip_rule_id").style.display = "none";
                this.xParent.getElementById("grammalecte_tooltip_url").dataset.url = "";
                this.xParent.getElementById("grammalecte_tooltip_url").style.display = "none";

                this.xParent.getElementById("grammalecte_tooltip_db_search").style.display = "inline-block";
                this.xParent.getElementById("grammalecte_tooltip_db_search").dataset.url = "https://grammalecte.net/dictionary.php?prj=fr&lemma="+xNodeErr.textContent;
                this.clearSuggestionBlock();
                this.xTooltipSuggBlock.textContent = "Recherche de graphies possibles…";
                oGrammalecteBackgroundPort.getSpellSuggestions(xNodeErr.textContent, "__GrammalectePanel__", xNodeErr.dataset.error_id);
            }
            this.xTooltipArrow.style.display = "block";







>





>







1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
                    }
                } else {
                    this.xTooltipSuggBlock.textContent = "Aucune.";
                }
            }
            if (xNodeErr.dataset.error_type === "spelling") {
                // spelling mistake
                this.sUnknownWord = xNodeErr.textContent;
                this.xParent.getElementById("grammalecte_tooltip_message").textContent = "Mot inconnu du dictionnaire.";
                this.xParent.getElementById("grammalecte_tooltip_ignore").dataset.error_id = xNodeErr.dataset.error_id;
                this.xParent.getElementById("grammalecte_tooltip_rule_id").style.display = "none";
                this.xParent.getElementById("grammalecte_tooltip_url").dataset.url = "";
                this.xParent.getElementById("grammalecte_tooltip_url").style.display = "none";
                this.xParent.getElementById("grammalecte_tooltip_open_lexed").style.display = "inline";
                this.xParent.getElementById("grammalecte_tooltip_db_search").style.display = "inline-block";
                this.xParent.getElementById("grammalecte_tooltip_db_search").dataset.url = "https://grammalecte.net/dictionary.php?prj=fr&lemma="+xNodeErr.textContent;
                this.clearSuggestionBlock();
                this.xTooltipSuggBlock.textContent = "Recherche de graphies possibles…";
                oGrammalecteBackgroundPort.getSpellSuggestions(xNodeErr.textContent, "__GrammalectePanel__", xNodeErr.dataset.error_id);
            }
            this.xTooltipArrow.style.display = "block";

Modified gc_lang/fr/webext/panel/lex_editor.js from [e29ea9ca06] to [a95656b530].

321
322
323
324
325
326
327









328
329
330
331
332
333
334
                }
            }
        }
        catch (e) {
            showError(e);
        }
    },










    onWrite: function () {
        if (document.getElementById("lemma").value.trim() !== "") {
            showElement("editor");
            this.update();
        } else {
            hideElement("editor");







>
>
>
>
>
>
>
>
>







321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
                }
            }
        }
        catch (e) {
            showError(e);
        }
    },

    newEntry: function (sWord) {
        if (typeof(sWord) !== "string" || !sWord) {
            return;
        }
        oTabulations.showPage("add_page");
        document.getElementById("lemma").value = sWord;
        this.onWrite();
    },

    onWrite: function () {
        if (document.getElementById("lemma").value.trim() !== "") {
            showElement("editor");
            this.update();
        } else {
            hideElement("editor");
842
843
844
845
846
847
848


















oTagsInfo.load();
oSearch.load();
oDictHandler.loadDictionaries();
oBinaryDict.listen();
oGenerator.listen();
oTabulations.listen();
oSearch.listen();

























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
oTagsInfo.load();
oSearch.load();
oDictHandler.loadDictionaries();
oBinaryDict.listen();
oGenerator.listen();
oTabulations.listen();
oSearch.listen();


/*
    Messages received
*/
function handleMessage (oMessage, xSender, sendResponse) {
    let {sActionRequest, oParam} = oMessage;
    switch(sActionRequest) {
        case "new_entry":
            oGenerator.newEntry(oParam.sWord);
            break;
        default:
            console.log("[Grammalecte] Lexicon editor. Unknown command: " + sActionRequest);
    }
    //sendResponse({sCommand: "none", result: "done"});
}

browser.runtime.onMessage.addListener(handleMessage);