Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -302,14 +302,14 @@ // confusing: no way to get the node where we click?! switch (xInfo.menuItemId) { // analyze case "grammar_checker_editable": case "grammar_checker_page": - sendCommandToTab(xInfo.menuItemId, xTab.id); + sendCommandToTab(xTab.id, xInfo.menuItemId); break; case "grammar_checker_selection": - sendCommandToTab("grammar_checker_selection", xTab.id); + sendCommandToTab(xTab.id, xInfo.menuItemId, xInfo.selectionText); xGCEWorker.postMessage({ sCommand: "parseAndSpellcheck", dParam: {sText: xInfo.selectionText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {iReturnPort: xTab.id} }); @@ -386,13 +386,13 @@ dOptions = helpers.mapToObject(dOptions); } browser.storage.local.set({"gc_options": dOptions}); } -function sendCommandToTab (sCommand, iTab) { +function sendCommandToTab (iTab, sCommand, result=null) { let xTabPort = dConnx.get(iTab); - xTabPort.postMessage({sActionDone: sCommand, result: null, dInfo: null, bEnd: false, bError: false}); + xTabPort.postMessage({sActionDone: sCommand, result: result, dInfo: null, bEnd: false, bError: false}); } function sendCommandToCurrentTab (sCommand) { if (bChrome) { browser.tabs.query({ currentWindow: true, active: true }, (lTabs) => { Index: gc_lang/fr/webext/content_scripts/init.js ================================================================== --- gc_lang/fr/webext/content_scripts/init.js +++ gc_lang/fr/webext/content_scripts/init.js @@ -1,10 +1,10 @@ // Modify page /* jshint esversion:6, -W097 */ /* jslint esversion:6 */ -/* global GrammalectePanel, GrammalecteButton, GrammalecteTextFormatter, GrammalecteLexicographer, GrammalecteGrammarChecker, GrammalecteMessageBox, showError, MutationObserver, chrome, document, console */ +/* global GrammalectePanel, GrammalecteButton, GrammalecteTextFormatter, GrammalecteGrammarChecker, GrammalecteMessageBox, showError, MutationObserver, chrome, document, console */ /* JS sucks (again, and again, and again, and again…) Not possible to load content from within the extension: https://bugzilla.mozilla.org/show_bug.cgi?id=1267027 @@ -139,11 +139,10 @@ createTFPanel: function () { if (this.oTFPanel === null) { this.oTFPanel = new GrammalecteTextFormatter("grammalecte_tf_panel", "Formateur de texte", 760, 595, false); this.oTFPanel.insertIntoPage(); - window.setTimeout( () => { this.oTFPanel.adjustHeight(); }, 50); } }, createGCPanel: function () { if (this.oGCPanel === null) { @@ -157,40 +156,33 @@ this.oMessageBox = new GrammalecteMessageBox("grammalecte_message_box", "Grammalecte"); this.oMessageBox.insertIntoPage(); } }, - startGCPanel: function (xNode=null) { + startGCPanel: function (what, bCheckText=true) { this.createGCPanel(); this.oGCPanel.clear(); this.oGCPanel.show(); this.oGCPanel.showEditor(); - this.oGCPanel.start(xNode); + this.oGCPanel.start(what); this.oGCPanel.startWaitIcon(); + if (what && bCheckText) { + let sText = this.oGCPanel.oTextControl.getText(); + xGrammalectePort.postMessage({ + sCommand: "parseAndSpellcheck", + dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false}, + dInfo: (what.nodeType && what.nodeType === 1) ? {sTextAreaId: what.id} : {} + }); + } }, showMessage: function (sMessage) { this.createMessageBox(); this.oMessageBox.show(); this.oMessageBox.setMessage(sMessage); }, - parseAndSpellcheck (xNode=null) { - this.startGCPanel(xNode); - let sText = ""; - if (xNode) { - sText = (xNode.tagName == "TEXTAREA" || xNode.tagName == "INPUT") ? xNode.value.normalize("NFC") : xNode.innerText.normalize("NFC"); - } else { - sText = this.getPageText(); - } - xGrammalectePort.postMessage({ - sCommand: "parseAndSpellcheck", - dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false}, - dInfo: (xNode) ? {sTextAreaId: xNode.id} : {} - }); - }, - getPageText: function () { let sPageText = document.body.innerText; let nPos = sPageText.indexOf("__grammalecte_panel__"); if (nPos >= 0) { sPageText = sPageText.slice(0, nPos).normalize("NFC"); @@ -338,20 +330,20 @@ (Context menu are initialized in background) */ // Grammar checker commands case "grammar_checker_editable": if (oGrammalecte.xRightClickedNode !== null) { - oGrammalecte.parseAndSpellcheck(oGrammalecte.xRightClickedNode); + oGrammalecte.startGCPanel(oGrammalecte.xRightClickedNode); } else { oGrammalecte.showMessage("Erreur. Le node sur lequel vous avez cliqué n’a pas pu être identifié. Sélectionnez le texte à corriger et relancez le correcteur via le menu contextuel."); } break; case "grammar_checker_page": - oGrammalecte.parseAndSpellcheck(); + oGrammalecte.startGCPanel(oGrammalecte.getPageText()); break; case "grammar_checker_selection": - oGrammalecte.startGCPanel(); + oGrammalecte.startGCPanel(result, false); // result is the selected text // selected text is sent to the GC worker in the background script. break; // rescan page command case "rescanPage": oGrammalecte.rescanPage(); @@ -370,14 +362,14 @@ /* Commands received from the keyboard (shortcuts) */ case "shortcutGrammarChecker": if (xActiveNode && (xActiveNode.tagName == "TEXTAREA" || xActiveNode.tagName == "INPUT" || xActiveNode.isContentEditable)) { - oGrammalecte.parseAndSpellcheck(xActiveNode); + oGrammalecte.startGCPanel(xActiveNode); } else { - oGrammalecte.parseAndSpellcheck(); + oGrammalecte.startGCPanel(oGrammalecte.getPageText()); } break; default: console.log("[Content script] Unknown command: " + sActionDone); } }); Index: gc_lang/fr/webext/content_scripts/menu.js ================================================================== --- gc_lang/fr/webext/content_scripts/menu.js +++ gc_lang/fr/webext/content_scripts/menu.js @@ -11,11 +11,11 @@ constructor (nMenu, xNode) { this.xNode = xNode; this.xButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_main_button", textContent: " "}); this.xButton.onclick = () => { - oGrammalecte.parseAndSpellcheck(this.xNode); + oGrammalecte.startGCPanel(this.xNode); }; this.xButton.style.zIndex = (xNode.style.zIndex.search(/^[0-9]+$/) !== -1) ? (parseInt(xNode.style.zIndex) + 1).toString() : xNode.style.zIndex; this.bShadow = document.body.createShadowRoot || document.body.attachShadow; if (this.bShadow) { Index: gc_lang/fr/webext/content_scripts/panel.css ================================================================== --- gc_lang/fr/webext/content_scripts/panel.css +++ gc_lang/fr/webext/content_scripts/panel.css @@ -6,10 +6,16 @@ div.grammalecte_panel { all: initial; padding: 0; margin: 0; position: fixed; + /* flexbox */ + display: flex; + justify-content: flex-start; + flex-direction: column; + align-items: stretch; + /* end flexbox */ box-sizing: content-box; z-index: 2147483641; /* maximum is 2147483647: https://stackoverflow.com/questions/491052/minimum-and-maximum-value-of-z-index */ border: 2px solid hsl(210, 50%, 50%); border-radius: 10px 10px 10px 10px; background-color: hsl(210, 0%, 100%); @@ -28,11 +34,11 @@ padding: 0; } div.grammalecte_panel_bar { position: sticky; - width: 100%; + /*width: 100%;*/ background-color: hsl(210, 50%, 50%); border-radius: 10px 10px 0 0; border-bottom: 1px solid hsl(210, 20%, 86%); } @@ -110,13 +116,11 @@ background-color: hsl(210, 80%, 40%); } div.grammalecte_panel_content { - position: absolute; - width: 100%; - height: calc(100% - 65px); /* panel height - title_bar */ + flex-grow: 1; overflow: auto; } div#grammalecte_panel_message_block { display: none; Index: gc_lang/fr/webext/content_scripts/panel.js ================================================================== --- gc_lang/fr/webext/content_scripts/panel.js +++ gc_lang/fr/webext/content_scripts/panel.js @@ -128,16 +128,15 @@ document.body.appendChild(this.xPanel); } } show () { - this.xPanel.style.display = "block"; + this.xPanel.style.display = "flex"; } hide () { this.xPanel.style.display = "none"; - oGrammalecte.clearRightClickedNode(); } center () { let nHeight = (this.bFlexible) ? window.innerHeight-100 : this.nHeight; this.setSizeAndPosition(`${this.nWidth}px`, `${nHeight}px`, "50%", "", "", "50%", `-${nHeight/2}px`, `-${this.nWidth/2}px`); @@ -178,15 +177,10 @@ reduce () { // todo } - adjustHeight () { - this.xPanelContent.style.height = this.xPanelContent.firstChild.offsetHeight + "px"; // xPanelContent has only one child - this.xPanel.style.height = this.xPanelBar.offsetHeight + this.xPanelContent.offsetHeight + 10 + "px"; - } - getWidth () { return this.xPanelContent.offsetWidth; } logInnerHTML () { Index: gc_lang/fr/webext/content_scripts/panel_gc.js ================================================================== --- gc_lang/fr/webext/content_scripts/panel_gc.js +++ gc_lang/fr/webext/content_scripts/panel_gc.js @@ -51,17 +51,18 @@ super(...args); this.aIgnoredErrors = new Set(); this.createMenu() // Editor this.xGCPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_gc_panel_content"}); + this.xGCPanelContent.style.marginBottom = "10px"; this.xParagraphList = oGrammalecte.createNode("div", {id: "grammalecte_paragraph_list"}); this.xGCPanelContent.appendChild(this.xParagraphList); this.xPanelContent.addEventListener("click", onGrammalecteGCPanelClick, false); this.oTooltip = new GrammalecteTooltip(this.xParent, this.xGCPanelContent); this.xPanelContent.appendChild(this.xGCPanelContent); this.xNode = null; - this.oNodeControl = new GrammalecteNodeControl(); + this.oTextControl = new GrammalecteTextControl(); // Lexicographer this.nLxgCount = 0; this.xLxgPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_lxg_panel_content"}); this.xPanelContent.appendChild(this.xLxgPanelContent); // Conjugueur @@ -79,17 +80,13 @@ this.xLxgButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Lexicographe"}); this.xConjButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Conjugueur"}); this.xLEButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "•Éditeur lexical•"}); this.xTFButton.onclick = () => { if (!this.bWorking) { - if (this.xNode && (this.xNode.tagName == "TEXTAREA" || this.xNode.tagName == "INPUT" || this.xNode.isContentEditable)) { - oGrammalecte.createTFPanel(); - oGrammalecte.oTFPanel.start(this); - oGrammalecte.oTFPanel.show(); - } else { - oGrammalecte.showMessage("Aucune zone de texte éditable sur laquelle appliquer le formatage de texte.") - } + oGrammalecte.createTFPanel(); + oGrammalecte.oTFPanel.start(); + oGrammalecte.oTFPanel.show(); } }; this.xEditorButton.onclick = () => { if (!this.bWorking) { this.showEditor(); @@ -100,11 +97,11 @@ this.showLexicographer(); this.clearLexicographer(); this.startWaitIcon(); xGrammalectePort.postMessage({ sCommand: "getListOfTokens", - dParam: {sText: this.getParsedText()}, + dParam: {sText: this.oTextControl.getText()}, dInfo: ((this.xNode) ? {sTextAreaId: this.xNode.id} : {}) }); } }; this.xConjButton.onclick = () => { @@ -121,44 +118,42 @@ this.xMenu.appendChild(this.xConjButton) this.xMenu.appendChild(this.xLEButton) this.xPanelBar.appendChild(this.xMenu); } - start (xNode=null) { - this.xNode = xNode; + start (what) { this.oTooltip.hide(); this.bWorking = false; this.clear(); - if (xNode) { - this.oNodeControl.setNode(xNode); - if (!(xNode.tagName == "TEXTAREA" || xNode.tagName == "INPUT")) { - this.showMessage("La zone de texte analysée est un champ textuel enrichi susceptible de contenir des éléments non textuels qui seront effacés lors de la correction."); - } + this.hideMessage(); + if (typeof(what) === "string") { + // text + this.xNode = null; + this.oTextControl.setText(what); + } else if (what.nodeType && what.nodeType === 1) { + // node + this.xNode = what; + this.oTextControl.setNode(this.xNode); } else { - this.oNodeControl.clear(); + // error + oGrammalecte.oMessageBox.showMessage("[BUG] Analyse d’un élément inconnu…"); + console.log("Grammalecte [bug]:", what); } } recheckAll () { this.oTooltip.hide(); + this.showEditor(); this.clear(); this.startWaitIcon(); xGrammalectePort.postMessage({ sCommand: "parseAndSpellcheck", - dParam: {sText: this.getParsedText(), sCountry: "FR", bDebug: false, bContext: false}, + dParam: {sText: this.oTextControl.getText(), sCountry: "FR", bDebug: false, bContext: false}, dInfo: ((this.xNode) ? {sTextAreaId: this.xNode.id} : {}) }); } - getParsedText () { - if (this.xNode) { - return (this.xNode.tagName == "TEXTAREA" || this.xNode.tagName == "INPUT") ? this.xNode.value.normalize("NFC") : this.xNode.innerText.normalize("NFC"); - } else { - return oGrammalecte.getPageText(); - } - } - showEditor () { this.switchContentOn(this.xGCPanelContent, this.xEditorButton); this.switchContentOff(this.xLxgPanelContent, this.xLxgButton); this.switchContentOff(this.xConjPanelContent, this.xConjButton); } @@ -197,12 +192,15 @@ } this.aIgnoredErrors.clear(); } hide () { + if (oGrammalecte.oTFPanel) { oGrammalecte.oTFPanel.hide(); } + if (oGrammalecte.oMessageBox) { oGrammalecte.oMessageBox.hide(); } + oGrammalecte.clearRightClickedNode(); this.xPanel.style.display = "none"; - this.oNodeControl.clear(); + this.oTextControl.clear(); } addParagraphResult (oResult) { try { if (oResult && (oResult.sParagraph.trim() !== "" || oResult.aGrammErr.length > 0 || oResult.aSpellErr.length > 0)) { @@ -219,12 +217,12 @@ window.clearTimeout(parseInt(xParagraph.dataset.timer_id)); xParagraph.dataset.timer_id = window.setTimeout(this.recheckParagraph.bind(this), 3000, oResult.iParaNum); let [nStart, nEnd] = oGrammalecte.getCaretPosition(xParagraph); xParagraph.dataset.caret_position_start = nStart; xParagraph.dataset.caret_position_end = nEnd; - this.oNodeControl.setParagraph(parseInt(xEvent.target.dataset.para_num), this.purgeText(xEvent.target.textContent)); - this.oNodeControl.write(); + this.oTextControl.setParagraph(parseInt(xEvent.target.dataset.para_num), this.purgeText(xEvent.target.textContent)); + this.oTextControl.write(); }.bind(this) , true); this._tagParagraph(xParagraph, oResult.sParagraph, oResult.iParaNum, oResult.aGrammErr, oResult.aSpellErr); // creation xNodeDiv.appendChild(xActionsBar); @@ -245,12 +243,12 @@ xGrammalectePort.postMessage({ sCommand: "parseAndSpellcheck1", dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {sParagraphId: sParagraphId} }); - this.oNodeControl.setParagraph(iParaNum, sText); - this.oNodeControl.write(); + this.oTextControl.setParagraph(iParaNum, sText); + this.oTextControl.write(); } refreshParagraph (sParagraphId, oResult) { try { let xParagraph = this.xParent.getElementById(sParagraphId); @@ -712,11 +710,11 @@ this.sErrorId = null; this.bDebug = false; this.xTooltip = oGrammalecte.createNode("div", {id: "grammalecte_tooltip"}); this.xTooltipArrow = oGrammalecte.createNode("img", { id: "grammalecte_tooltip_arrow", - src: " data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwAAADsABataJCQAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xNzNun2MAAAAnSURBVChTY/j//z8cq/kW/wdhZDEMSXRFWCVhGKwAmwQyHngFxf8B5fOGYfeFpYoAAAAASUVORK5CYII=", + src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwAAADsABataJCQAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xNzNun2MAAAAnSURBVChTY/j//z8cq/kW/wdhZDEMSXRFWCVhGKwAmwQyHngFxf8B5fOGYfeFpYoAAAAASUVORK5CYII=", alt: "^", }); // message let xMessageBlock = oGrammalecte.createNode("div", {id: "grammalecte_tooltip_message_block"}); xMessageBlock.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_tooltip_rule_id"})); @@ -868,11 +866,11 @@ } } } -class GrammalecteNodeControl { +class GrammalecteTextControl { constructor () { this.xNode = null; this.dParagraph = new Map(); this.bTextArea = null; @@ -880,12 +878,21 @@ setNode (xNode) { this.clear(); this.xNode = xNode; this.bTextArea = (xNode.tagName == "TEXTAREA" || xNode.tagName == "INPUT"); + if (!this.bTextArea) { + oGrammalecte.oGCPanel.showMessage("La zone de texte analysée est un champ textuel enrichi susceptible de contenir des éléments non textuels qui seront effacés lors de la correction."); + } this.xNode.disabled = true; - this._loadText(); + this.loadText((this.bTextArea) ? this.xNode.value : this.xNode.innerText); + } + + setText (sText) { + this.clear(); + oGrammalecte.oGCPanel.showMessage("Le texte analysé n’appartient pas à un champ textuel défini. Les modifications ne seront pas répercutées sur la zone d’où le texte a été extrait. Vous pouvez néanmoins récupérer l’ensemble du texte corrigé avec le bouton 📋."); + this.loadText(sText); } clear () { if (this.xNode !== null) { this.xNode.disabled = false; @@ -893,50 +900,54 @@ this.xNode = null; } this.dParagraph.clear(); } - setParagraph (iParagraph, sText) { - if (this.xNode !== null) { - this.dParagraph.set(iParagraph, sText); - } - } - - _loadText () { - let sText = (this.bTextArea) ? this.xNode.value : this.xNode.innerText; - let i = 0; - let iStart = 0; - let iEnd = 0; - sText = sText.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/­/g, "").normalize("NFC"); - while ((iEnd = sText.indexOf("\n", iStart)) !== -1) { - this.dParagraph.set(i, sText.slice(iStart, iEnd)); - i++; - iStart = iEnd+1; - } - this.dParagraph.set(i, sText.slice(iStart)); - //console.log("Paragraphs number: " + (i+1)); - } - - eraseContent () { + getText () { + let sText = ""; + this.dParagraph.forEach(function (val, key) { + sText += val + "\n"; + }); + return sText.slice(0,-1).normalize("NFC"); + } + + setParagraph (iParagraph, sText) { + this.dParagraph.set(iParagraph, sText); + } + + loadText (sText) { + if (typeof(sText) === "string") { + let i = 0; + let iStart = 0; + let iEnd = 0; + sText = sText.replace(/\r\n/g, "\n").replace(/\r/g, "\n").normalize("NFC"); + while ((iEnd = sText.indexOf("\n", iStart)) !== -1) { + this.dParagraph.set(i, sText.slice(iStart, iEnd)); + i++; + iStart = iEnd+1; + } + this.dParagraph.set(i, sText.slice(iStart)); + //console.log("Paragraphs number: " + (i+1)); + } + } + + eraseNodeContent () { while (this.xNode.firstChild) { this.xNode.removeChild(this.xNode.firstChild); } } write () { if (this.xNode !== null) { let sText = ""; if (this.bTextArea) { - this.dParagraph.forEach(function (val, key) { - sText += val + "\n"; - }); - this.xNode.value = sText.slice(0,-1).normalize("NFC"); + this.xNode.value = this.getText(); } else { - this.eraseContent(); + this.eraseNodeContent(); this.dParagraph.forEach((val, key) => { this.xNode.appendChild(document.createTextNode(val.normalize("NFC"))); this.xNode.appendChild(document.createElement("br")); }); } } } } Index: gc_lang/fr/webext/content_scripts/panel_tf.js ================================================================== --- gc_lang/fr/webext/content_scripts/panel_tf.js +++ gc_lang/fr/webext/content_scripts/panel_tf.js @@ -12,24 +12,23 @@ constructor (...args) { super(...args); this.xTFNode = this._createTextFormatter(); this.xPanelContent.appendChild(this.xTFNode); - this.xTextNode = null; this.xPanel.style.zIndex = 2147483647; /* maximum is 2147483647: https://stackoverflow.com/questions/491052/minimum-and-maximum-value-of-z-index */ this.bTextChanged = false; - this.TextFormatter = new TextFormatter(); - this.formatText = this.TextFormatter.formatTextRuleCount; - this.removeHyphenAtEndOfParagraphs = this.TextFormatter.removeHyphenAtEndOfParagraphsCount; - this.mergeContiguousParagraphs = this.TextFormatter.mergeContiguousParagraphsCount; - this.getParagraph = this.TextFormatter.getParagraph; + this.oTextFormatter = new TextFormatter(); + this.formatText = this.oTextFormatter.formatTextRuleCount; + this.removeHyphenAtEndOfParagraphs = this.oTextFormatter.removeHyphenAtEndOfParagraphsCount; + this.mergeContiguousParagraphs = this.oTextFormatter.mergeContiguousParagraphsCount; + this.getParagraph = this.oTextFormatter.getParagraph; this.xCloseButton.onclick = () => { this.hide(); if (this.bTextChanged) { - this.xGCPanel.recheckAll(); + oGrammalecte.oGCPanel.recheckAll(); this.bTextChanged = false; } }; } @@ -177,38 +176,40 @@ xLine.appendChild(this._createOption("o_ordinals_no_exponant", true, "Ordinaux (15e, XXIe…)")); xLine.appendChild(this._createOption("o_ordinals_exponant", true, "e → ᵉ")); xLine.appendChild(oGrammalecte.createNode("div", {id: "res_"+"o_ordinals_no_exponant", className: "grammalecte_tf_result", textContent: "·"})); return xLine; } + /* Actions */ - start (xGCPanel) { - if (xGCPanel.xNode !== null && (xGCPanel.xNode.tagName == "TEXTAREA" || xGCPanel.xNode.tagName == "INPUT" || xGCPanel.xNode.isContentEditable)) { - this.xTextNode = xGCPanel.xNode; - this.xGCPanel = xGCPanel; - if (bChrome) { - browser.storage.local.get("tf_options", this.setOptions.bind(this)); - } else { - let xPromise = browser.storage.local.get("tf_options"); - xPromise.then(this.setOptions.bind(this), this.reset.bind(this)); - } - } - } - - getNodeText () { - return (this.xTextNode.tagName == "TEXTAREA" || this.xTextNode.tagName == "INPUT") ? this.xTextNode.value.normalize("NFC") : this.xTextNode.innerText.normalize("NFC"); - } - - setNodeText (sText) { - if (this.xTextNode.tagName == "TEXTAREA" || this.xTextNode.tagName == "INPUT") { - this.xTextNode.value = sText; - } else { - this.xTextNode.textContent = sText; - } - this.bTextChanged = true; + start () { + if (bChrome) { + browser.storage.local.get("tf_options", this.setOptions.bind(this)); + } else { + let xPromise = browser.storage.local.get("tf_options"); + xPromise.then(this.setOptions.bind(this), this.reset.bind(this)); + } + } + + setOptions (oOptions) { + if (oOptions.hasOwnProperty("tf_options")) { + oOptions = oOptions.tf_options; + } + let elmOpt = this.xParent.getElementById('grammalecte_tf_options'); + for (let xOption of elmOpt.getElementsByClassName("grammalecte_tf_option")) { + //console.log(xOption.id + " > " + oOptions.hasOwnProperty(xOption.id) + ": " + oOptions[xOption.id] + " [" + xOption.dataset.default + "]"); + xOption.dataset.selected = (oOptions.hasOwnProperty(xOption.id)) ? oOptions[xOption.id] : xOption.dataset.default; + xOption.className = (xOption.dataset.selected == "true") ? xOption.className.replace("_off", "_on") : xOption.className.replace("_on", "_off"); + if (this.xParent.getElementById("res_"+xOption.id) !== null) { + this.xParent.getElementById("res_"+xOption.id).textContent = ""; + } + if (xOption.id.startsWith("o_group_")) { + this.switchGroup(xOption.id); + } + } } switchGroup (sOptName) { if (this.xParent.getElementById(sOptName).dataset.selected == "true") { this.xParent.getElementById(sOptName.slice(2)).style.opacity = 1; @@ -253,28 +254,10 @@ resetProgressBar () { this.xParent.getElementById('grammalecte_tf_progressbar').value = 0; this.xParent.getElementById('grammalecte_tf_time_res').textContent = ""; } - setOptions (oOptions) { - if (oOptions.hasOwnProperty("tf_options")) { - oOptions = oOptions.tf_options; - } - let elmOpt = this.xParent.getElementById('grammalecte_tf_options'); - for (let xOption of elmOpt.getElementsByClassName("grammalecte_tf_option")) { - //console.log(xOption.id + " > " + oOptions.hasOwnProperty(xOption.id) + ": " + oOptions[xOption.id] + " [" + xOption.dataset.default + "]"); - xOption.dataset.selected = (oOptions.hasOwnProperty(xOption.id)) ? oOptions[xOption.id] : xOption.dataset.default; - xOption.className = (xOption.dataset.selected == "true") ? xOption.className.replace("_off", "_on") : xOption.className.replace("_on", "_off"); - if (this.xParent.getElementById("res_"+xOption.id) !== null) { - this.xParent.getElementById("res_"+xOption.id).textContent = ""; - } - if (xOption.id.startsWith("o_group_")) { - this.switchGroup(xOption.id); - } - } - } - saveOptions () { let oOptions = {}; let elmOpt = this.xParent.getElementById('grammalecte_tf_options'); for (let xOption of elmOpt.getElementsByClassName("grammalecte_tf_option")) { oOptions[xOption.id] = (xOption.dataset.selected == "true"); @@ -293,11 +276,11 @@ apply () { try { const t0 = Date.now(); //window.setCursor("wait"); // change pointer this.resetProgressBar(); - let sText = this.getNodeText(); + let sText = oGrammalecte.oGCPanel.oTextControl.getText(); this.xParent.getElementById('grammalecte_tf_progressbar').max = 7; let n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0, n6 = 0, n7 = 0; // Restructuration if (this.isSelected("o_group_struct")) { @@ -539,11 +522,13 @@ //window.setCursor("auto"); // restore pointer const t1 = Date.now(); this.xParent.getElementById('grammalecte_tf_time_res').textContent = this.getTimeRes((t1-t0)/1000); - this.setNodeText(sText); + oGrammalecte.oGCPanel.oTextControl.loadText(sText); + oGrammalecte.oGCPanel.oTextControl.write(); + this.bTextChanged = true; } catch (e) { showError(e); } }