Grammalecte  Diff

Differences From Artifact [8760b8d3dd]:

To Artifact [502b8838ad]:


344
345
346
347
348
349
350
351

352
353
354
355
356
357
358
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();
                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
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");
        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
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);
                sendCommandToTabViaPort(xTab.id, xInfo.menuItemId);
                break;
            case "grammar_checker_iframe":
                sendCommandToTab(xTab.id, xInfo.menuItemId, xInfo.frameId);
                sendCommandToTabViaPort(xTab.id, xInfo.menuItemId, xInfo.frameId);
                break;
            case "grammar_checker_selection":
                sendCommandToTab(xTab.id, xInfo.menuItemId, xInfo.selectionText);
                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
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 sendCommandToTab (iTab, sCommand, result=null) {
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
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__") {
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")