Grammalecte  Check-in [5539a3d29b]

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

Overview
Comment:[fx] autorefresh option
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256:5539a3d29bb9aee62bc4cd4d92b64b4fa495d707cdab6584ca8619e72cd3fd75
User & Date: olr 2019-08-10 16:55:03
Context
2019-08-10
17:41
[fx] test page layout check-in: 61a0800d1b user: olr tags: fx, trunk
16:55
[fx] autorefresh option check-in: 5539a3d29b user: olr tags: fx, trunk
15:33
[fx] fix caret position saving check-in: 72fe2a6c07 user: olr tags: fx, trunk
Changes

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

   119    119   
   120    120   
   121    121   const oInitHandler = {
   122    122   
   123    123       initUIOptions: function () {
   124    124           if (bChrome) {
   125    125               browser.storage.local.get("ui_options", this._initUIOptions);
          126  +            browser.storage.local.get("autorefresh_option", this._initUIOptions);
   126    127               return;
   127    128           }
   128    129           browser.storage.local.get("ui_options").then(this._initUIOptions, showError);
          130  +        browser.storage.local.get("autorefresh_option").then(this._initUIOptions, showError);
   129    131       },
   130    132   
   131    133       initGrammarChecker: function () {
   132    134           if (bChrome) {
   133    135               browser.storage.local.get("gc_options", this._initGrammarChecker);
   134    136               browser.storage.local.get("personal_dictionary", this._setSpellingDictionaries);
   135    137               browser.storage.local.get("community_dictionary", this._setSpellingDictionaries);
................................................................................
   147    149       _initUIOptions: function (oSavedOptions) {
   148    150           if (!oSavedOptions.hasOwnProperty("ui_options")) {
   149    151               browser.storage.local.set({"ui_options": {
   150    152                   textarea: true,
   151    153                   editablenode: true
   152    154               }});
   153    155           }
          156  +        if (!oSavedOptions.hasOwnProperty("autorefresh_option")) {
          157  +            browser.storage.local.set({"autorefresh_option": true});
          158  +        }
   154    159       },
   155    160   
   156    161       _initGrammarChecker: function (oSavedOptions) {
   157    162           try {
   158    163               let dOptions = (oSavedOptions.hasOwnProperty("gc_options")) ? oSavedOptions.gc_options : null;
   159    164               if (dOptions !== null && Object.getOwnPropertyNames(dOptions).length == 0) {
   160    165                   console.log("# Error: the saved options was an empty object.");
................................................................................
   187    192               oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionary", dParam: { sDictionary: "personal", oDict: oData["personal_dictionary"] }, dInfo: {} });
   188    193           }
   189    194       },
   190    195   
   191    196       _initSCOptions: function (oData) {
   192    197           if (!oData.hasOwnProperty("sc_options")) {
   193    198               browser.storage.local.set({"sc_options": {
   194         -                extended: true,
   195    199                   community: true,
   196    200                   personal: true
   197    201               }});
   198    202               oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", dParam: { sDictionary: "community", bActivate: true }, dInfo: {} });
   199    203               oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", dParam: { sDictionary: "personal", bActivate: true }, dInfo: {} });
   200    204           } else {
   201    205               oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", dParam: { sDictionary: "community", bActivate: oData.sc_options["community"] }, dInfo: {} });

Changes to gc_lang/fr/webext/content_scripts/init.js.

    56     56       xRightClickedNode: null,
    57     57   
    58     58       xObserver: null,
    59     59   
    60     60       sExtensionUrl: null,
    61     61   
    62     62       oOptions: null,
           63  +
           64  +    bAutoRefresh: true,
    63     65   
    64     66       listenRightClick: function () {
    65     67           // Node where a right click is done
    66     68           // Bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=1325814
    67     69           document.addEventListener('contextmenu', (xEvent) => {
    68     70               this.xRightClickedNode = xEvent.target;
    69     71           }, true);
................................................................................
   278    280           }
   279    281           let xSelection = window.getSelection();
   280    282           xSelection.removeAllRanges();
   281    283           xSelection.addRange(xRange);
   282    284       }
   283    285   };
   284    286   
          287  +
          288  +function autoRefreshOption (oSavedOptions=null) {
          289  +    // auto recallable function
          290  +    if (oSavedOptions === null) {
          291  +        if (bChrome) {
          292  +            browser.storage.local.get("autorefresh_option", autoRefreshOption);
          293  +            return;
          294  +        }
          295  +        browser.storage.local.get("autorefresh_option").then(autoRefreshOption, showError);
          296  +    }
          297  +    else if (oSavedOptions.hasOwnProperty("autorefresh_option")) {
          298  +        console.log("autorefresh_option", oSavedOptions["autorefresh_option"]);
          299  +        oGrammalecte.bAutoRefresh = oSavedOptions["autorefresh_option"];
          300  +    }
          301  +}
          302  +
          303  +autoRefreshOption();
          304  +
   285    305   
   286    306   /*
   287    307       Connexion to the background
   288    308   */
   289    309   let xGrammalectePort = browser.runtime.connect({name: "content-script port"});
   290    310   
   291    311   xGrammalectePort.onMessage.addListener(function (oMessage) {
   292    312       let {sActionDone, result, dInfo, bEnd, bError} = oMessage;
   293    313       switch (sActionDone) {
   294    314           case "init":
   295    315               oGrammalecte.sExtensionUrl = oMessage.sUrl;
   296         -            // Start
   297    316               oGrammalecte.listenRightClick();
   298    317               oGrammalecte.createButtons();
   299    318               oGrammalecte.observePage();
   300    319               break;
   301    320           case "parseAndSpellcheck":
   302    321               if (!bEnd) {
   303    322                   oGrammalecte.oGCPanel.addParagraphResult(result);

Changes to gc_lang/fr/webext/content_scripts/panel_gc.js.

    57     57           this.xParagraphList = oGrammalecte.createNode("div", {id: "grammalecte_paragraph_list"});
    58     58           this.xGCPanelContent.appendChild(this.xParagraphList);
    59     59           this.xPanelContent.addEventListener("click", onGrammalecteGCPanelClick, false);
    60     60           this.oTooltip = new GrammalecteTooltip(this.xParent, this.xGCPanelContent);
    61     61           this.xPanelContent.appendChild(this.xGCPanelContent);
    62     62           this.xNode = null;
    63     63           this.oTextControl = new GrammalecteTextControl();
    64         -        this.bAutoRefresh = false;
    65     64           this.nLastResult = 0
    66     65           // Lexicographer
    67     66           this.nLxgCount = 0;
    68     67           this.xLxgPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_lxg_panel_content"});
    69     68           this.xPanelContent.appendChild(this.xLxgPanelContent);
    70     69           // Conjugueur
    71     70           this.xConjPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_conj_panel_content"});
................................................................................
    80     79           this.xTFButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Formateur de texte"});
    81     80           this.xEditorButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Éditeur"});
    82     81           this.xLxgButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Lexicographe"});
    83     82           this.xConjButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Conjugueur"});
    84     83           this.xLEButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "•Éditeur lexical•"});
    85     84           this.xAutoRefresh = oGrammalecte.createNode("div", {className: "grammalecte_autorefresh_button", textContent: "AR", title: "Auto-rafraîchissement de la correction grammaticale (3 s après la dernière frappe)"})
    86     85           this.xEditorButton.appendChild(this.xAutoRefresh);
           86  +        this.bAutoRefresh = oGrammalecte.bAutoRefresh;
           87  +        this.setAutoRefreshButton();
    87     88           this.xTFButton.onclick = () => {
    88     89               if (!this.bWorking) {
    89     90                   oGrammalecte.createTFPanel();
    90     91                   oGrammalecte.oTFPanel.start();
    91     92                   oGrammalecte.oTFPanel.show();
    92     93               }
    93     94           };
................................................................................
    94     95           this.xEditorButton.onclick = () => {
    95     96               if (!this.bWorking) {
    96     97                   this.showEditor();
    97     98               }
    98     99           };
    99    100           this.xAutoRefresh.onclick = () => {
   100    101               this.bAutoRefresh = !this.bAutoRefresh;
   101         -            this.xAutoRefresh.style.backgroundColor = (this.bAutoRefresh) ? "hsl(150, 50%, 50%)" : "";
   102         -            this.xAutoRefresh.style.color = (this.bAutoRefresh) ? "hsl(150, 50%, 96%)" : "";
   103         -            this.xAutoRefresh.style.opacity = (this.bAutoRefresh) ? "1" : "";
          102  +            oGrammalecte.bAutoRefresh = this.bAutoRefresh;
          103  +            browser.storage.local.set({"autorefresh_option": this.bAutoRefresh});
          104  +            this.setAutoRefreshButton();
   104    105           }
   105    106           this.xLxgButton.onclick = () => {
   106    107               if (!this.bWorking) {
   107    108                   this.showLexicographer();
   108    109                   this.clearLexicographer();
   109    110                   this.startWaitIcon();
   110    111                   xGrammalectePort.postMessage({
................................................................................
   123    124               if (!this.bWorking) {
   124    125                   this.showConjugueur();
   125    126               }
   126    127           };
   127    128           this.xLEButton.onclick = () => {
   128    129               xGrammalectePort.postMessage({sCommand: "openLexiconEditor", dParam: null, dInfo: null});
   129    130           };
          131  +        // Menu, tabs
   130    132           this.xMenu.appendChild(this.xTFButton)
   131    133           this.xMenu.appendChild(this.xEditorButton)
   132    134           this.xMenu.appendChild(this.xLxgButton)
   133    135           this.xMenu.appendChild(this.xConjButton)
   134    136           this.xMenu.appendChild(this.xLEButton)
   135    137           this.xPanelBar.appendChild(this.xMenu);
   136    138       }
................................................................................
   151    153               this.oTextControl.setNode(this.xNode);
   152    154           } else {
   153    155               // error
   154    156               oGrammalecte.oMessageBox.showMessage("[BUG] Analyse d’un élément inconnu…");
   155    157               console.log("Grammalecte [bug]:", what);
   156    158           }
   157    159       }
          160  +
          161  +    setAutoRefreshButton () {
          162  +        this.xAutoRefresh.style.backgroundColor = (this.bAutoRefresh) ? "hsl(150, 50%, 50%)" : "";
          163  +        this.xAutoRefresh.style.color = (this.bAutoRefresh) ? "hsl(150, 50%, 96%)" : "";
          164  +        this.xAutoRefresh.style.opacity = (this.bAutoRefresh) ? "1" : "";
          165  +    }
   158    166   
   159    167       recheckAll () {
   160    168           this.oTooltip.hide();
   161    169           this.showEditor();
   162    170           this.clear();
   163    171           this.startWaitIcon();
   164    172           this.resetTimer();