Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -277,27 +277,18 @@ /* Context Menu */ - -// Selected text -browser.contextMenus.create({ id: "rightClickLxgSelectedText", title: "Lexicographe (sélection)", contexts: ["selection"] }); -browser.contextMenus.create({ id: "rightClickGCSelectedText", title: "Correction grammaticale (sélection)", contexts: ["selection"] }); -browser.contextMenus.create({ id: "separator_selection", type: "separator", contexts: ["selection"] }); -// Editable content -browser.contextMenus.create({ id: "rightClickTFEditableNode", title: "Formateur de texte (zone de texte)", contexts: ["editable"] }); -browser.contextMenus.create({ id: "rightClickLxgEditableNode", title: "Lexicographe (zone de texte)", contexts: ["editable"] }); -browser.contextMenus.create({ id: "rightClickGCEditableNode", title: "Correction grammaticale (zone de texte)", contexts: ["editable"] }); -browser.contextMenus.create({ id: "separator_editable", type: "separator", contexts: ["editable"] }); -// Page -browser.contextMenus.create({ id: "rightClickLxgPage", title: "Lexicographe (page)", contexts: ["all"] }); // on all parts, due to unwanted selection -browser.contextMenus.create({ id: "rightClickGCPage", title: "Correction grammaticale (page)", contexts: ["all"] }); -browser.contextMenus.create({ id: "separator_page", type: "separator", contexts: ["all"] }); +// Analyze +browser.contextMenus.create({ id: "grammar_checker_editable", title: "Analyser cette zone de texte", contexts: ["editable"] }); +browser.contextMenus.create({ id: "grammar_checker_selection", title: "Analyser la sélection", contexts: ["selection"] }); +browser.contextMenus.create({ id: "grammar_checker_page", title: "Analyser la page", contexts: ["all"] }); +browser.contextMenus.create({ id: "separator_tools", type: "separator", contexts: ["all"] }); // Tools -browser.contextMenus.create({ id: "conjugueur_window", title: "Conjugueur [fenêtre]", contexts: ["all"] }); browser.contextMenus.create({ id: "conjugueur_tab", title: "Conjugueur [onglet]", contexts: ["all"] }); +browser.contextMenus.create({ id: "conjugueur_window", title: "Conjugueur [fenêtre]", contexts: ["all"] }); //browser.contextMenus.create({ id: "dictionaries", title: "Dictionnaires", contexts: ["all"] }); browser.contextMenus.create({ id: "lexicon_editor", title: "Éditeur lexical", contexts: ["all"] }); // Rescan page browser.contextMenus.create({ id: "separator_rescan", type: "separator", contexts: ["editable"] }); browser.contextMenus.create({ id: "rescanPage", title: "Rechercher à nouveau les zones de texte", contexts: ["editable"] }); @@ -306,37 +297,24 @@ browser.contextMenus.onClicked.addListener(function (xInfo, xTab) { // 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) { - // editable node - // page - case "rightClickTFEditableNode": - case "rightClickLxgEditableNode": - case "rightClickGCEditableNode": - case "rightClickLxgPage": - case "rightClickGCPage": + // analyze + case "grammar_checker_editable": + case "grammar_checker_page": sendCommandToTab(xInfo.menuItemId, xTab.id); break; - // selected text - case "rightClickGCSelectedText": - sendCommandToTab("rightClickGCSelectedText", xTab.id); + case "grammar_checker_selection": + sendCommandToTab("grammar_checker_selection", xTab.id); xGCEWorker.postMessage({ sCommand: "parseAndSpellcheck", dParam: {sText: xInfo.selectionText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {iReturnPort: xTab.id} }); break; - case "rightClickLxgSelectedText": - sendCommandToTab("rightClickLxgSelectedText", xTab.id); - xGCEWorker.postMessage({ - sCommand: "getListOfTokens", - dParam: {sText: xInfo.selectionText}, - dInfo: {iReturnPort: xTab.id} - }); - break; - // conjugueur + // tools case "conjugueur_window": openConjugueurWindow(); break; case "conjugueur_tab": openConjugueurTab(); @@ -363,25 +341,16 @@ /* Keyboard shortcuts */ browser.commands.onCommand.addListener(function (sCommand) { switch (sCommand) { - case "lexicographer": - sendCommandToCurrentTab("shortcutLexicographer"); - break; - case "text_formatter": - sendCommandToCurrentTab("shortcutTextFormatter"); - break; case "grammar_checker": sendCommandToCurrentTab("shortcutGrammarChecker"); break; case "conjugueur_tab": openConjugueurTab(); break; - case "conjugueur_window": - openConjugueurWindow(); - break; case "lexicon_editor": openLexiconEditor(); break; case "dictionaries": openDictionaries(); @@ -421,11 +390,10 @@ let xTabPort = dConnx.get(iTab); xTabPort.postMessage({sActionDone: sCommand, result: null, dInfo: null, bEnd: false, bError: false}); } function sendCommandToCurrentTab (sCommand) { - console.log(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}); @@ -484,11 +452,11 @@ function onDictionariesOpened (xTab) { nTabDictionaries = xTab.id; } function openConjugueurTab () { - if (nTabDictionaries === null) { + if (nTabConjugueur === null) { if (bChrome) { browser.tabs.create({ url: browser.extension.getURL("panel/conjugueur.html") }, onConjugueurOpened); return; 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 @@ -47,11 +47,11 @@ nMenu: 0, lMenu: [], oTFPanel: null, - oLxgPanel: null, + //oLxgPanel: null, oGCPanel: null, oMessageBox: null, xRightClickedNode: null, @@ -130,11 +130,11 @@ }); }, rescanPage: function () { if (this.oTFPanel !== null) { this.oTFPanel.hide(); } - if (this.oLxgPanel !== null) { this.oLxgPanel.hide(); } + //if (this.oLxgPanel !== null) { this.oLxgPanel.hide(); } if (this.oGCPanel !== null) { this.oGCPanel.hide(); } for (let oMenu of this.lMenu) { oMenu.deleteNodes(); } this.lMenu.length = 0; // to clear an array @@ -151,17 +151,10 @@ self.oTFPanel.adjustHeight(); }, 50, this); } }, - createLxgPanel: function () { - if (this.oLxgPanel === null) { - this.oLxgPanel = new GrammalecteLexicographer("grammalecte_lxg_panel", "Lexicographe", 500, 700); - this.oLxgPanel.insertIntoPage(); - } - }, - createGCPanel: function () { if (this.oGCPanel === null) { this.oGCPanel = new GrammalecteGrammarChecker("grammalecte_gc_panel", "Grammalecte", 500, 700); this.oGCPanel.insertIntoPage(); } @@ -176,19 +169,20 @@ startGCPanel: function (xNode=null) { this.createGCPanel(); this.oGCPanel.clear(); this.oGCPanel.show(); + this.oGCPanel.showEditor(); this.oGCPanel.start(xNode); this.oGCPanel.startWaitIcon(); }, startLxgPanel: function () { - this.createLxgPanel(); - this.oLxgPanel.clear(); - this.oLxgPanel.show(); - this.oLxgPanel.startWaitIcon(); + this.createGCPanel(); + this.oGCPanel.clearLexicographer(); + this.oGCPanel.showLexicographer(); + this.oGCPanel.startWaitIcon(); }, startFTPanel: function (xNode=null) { this.createTFPanel(); this.oTFPanel.start(xNode); @@ -203,11 +197,11 @@ getPageText: function () { let sPageText = document.body.innerText; let nPos = sPageText.indexOf("__grammalecte_panel__"); if (nPos >= 0) { - sPageText = sPageText.slice(0, nPos); + sPageText = sPageText.slice(0, nPos).normalize("NFC"); } return sPageText; }, createNode: function (sType, oAttr, oDataset=null) { @@ -328,13 +322,13 @@ case "parseAndSpellcheck1": oGrammalecte.oGCPanel.refreshParagraph(dInfo.sParagraphId, result); break; case "getListOfTokens": if (!bEnd) { - oGrammalecte.oLxgPanel.addListOfTokens(result); + oGrammalecte.oGCPanel.addListOfTokens(result); } else { - oGrammalecte.oLxgPanel.stopWaitIcon(); + oGrammalecte.oGCPanel.stopWaitIcon(); } break; case "getSpellSuggestions": oGrammalecte.oGCPanel.oTooltip.setSpellSuggestionsFor(result.sWord, result.aSugg, result.iSuggBlock, dInfo.sErrorId); break; @@ -341,50 +335,23 @@ /* Commands received from the context menu (Context menu are initialized in background) */ // Grammar checker commands - case "rightClickGCEditableNode": + case "grammar_checker_editable": if (oGrammalecte.xRightClickedNode !== null) { parseAndSpellcheckEditableNode(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 "rightClickGCPage": + case "grammar_checker_page": parseAndSpellcheckPage(); break; - case "rightClickGCSelectedText": + case "grammar_checker_selection": oGrammalecte.startGCPanel(); // selected text is sent to the GC worker in the background script. - break; - // Lexicographer commands - case "rightClickLxgEditableNode": - if (oGrammalecte.xRightClickedNode !== null) { - lexicographerEditableNode(oGrammalecte.xRightClickedNode); - } else { - oGrammalecte.showMessage("Erreur. Le node sur lequel vous avez cliqué n’a pas pu être identifié. Sélectionnez le texte à analyser et relancez le lexicographe via le menu contextuel."); - } - break; - case "rightClickLxgPage": - lexicographerPage(); - break; - case "rightClickLxgSelectedText": - oGrammalecte.startLxgPanel(); - // selected text is sent to the GC worker in the background script. - break; - // Text formatter command - case "rightClickTFEditableNode": - if (oGrammalecte.xRightClickedNode !== null) { - if (oGrammalecte.xRightClickedNode.tagName == "TEXTAREA" || oGrammalecte.xRightClickedNode.tagName == "INPUT") { - oGrammalecte.startFTPanel(oGrammalecte.xRightClickedNode); - } else { - oGrammalecte.showMessage("Cette zone de texte n’est pas réellement un champ de formulaire, mais un node HTML éditable. Le formateur de texte n’est pas disponible pour ce type de champ de saisie."); - } - } else { - oGrammalecte.showMessage("Erreur. Le node sur lequel vous avez cliqué n’a pas pu être identifié."); - } break; // rescan page command case "rescanPage": oGrammalecte.rescanPage(); break; @@ -401,22 +368,10 @@ let xActiveNode = document.activeElement; switch (sActionRequest) { /* Commands received from the keyboard (shortcuts) */ - case "shortcutLexicographer": - if (xActiveNode && (xActiveNode.tagName == "TEXTAREA" || xActiveNode.tagName == "INPUT" || xActiveNode.isContentEditable)) { - lexicographerEditableNode(xActiveNode); - } else { - lexicographerPage(); - } - break; - case "shortcutTextFormatter": - if (xActiveNode && (xActiveNode.tagName == "TEXTAREA" || xActiveNode.tagName == "INPUT")) { - oGrammalecte.startFTPanel(xActiveNode); - } - break; case "shortcutGrammarChecker": if (xActiveNode && (xActiveNode.tagName == "TEXTAREA" || xActiveNode.tagName == "INPUT" || xActiveNode.isContentEditable)) { parseAndSpellcheckEditableNode(xActiveNode); } else { parseAndSpellcheckPage(); @@ -445,27 +400,8 @@ oGrammalecte.startGCPanel(xNode); let sText = (xNode.tagName == "TEXTAREA" || xNode.tagName == "INPUT") ? xNode.value : xNode.innerText; xGrammalectePort.postMessage({ sCommand: "parseAndSpellcheck", dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false}, - dInfo: {sTextAreaId: xNode.id} - }); -} - -function lexicographerPage () { - oGrammalecte.startLxgPanel(); - xGrammalectePort.postMessage({ - sCommand: "getListOfTokens", - dParam: {sText: oGrammalecte.getPageText()}, - dInfo: {} - }); -} - -function lexicographerEditableNode (xNode) { - oGrammalecte.startLxgPanel(); - let sText = (xNode.tagName == "TEXTAREA" || xNode.tagName == "INPUT") ? xNode.value : xNode.innerText; - xGrammalectePort.postMessage({ - sCommand: "getListOfTokens", - dParam: {sText: sText}, dInfo: {sTextAreaId: xNode.id} }); } 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 @@ -9,15 +9,20 @@ class GrammalecteMenu { constructor (nMenu, xNode) { this.xNode = xNode; - this.sMenuId = "grammalecte_menu" + nMenu; this.xButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_main_button", textContent: " "}); - this.xButton.onclick = () => { this.switchMenu(); }; + this.xButton.onclick = () => { + oGrammalecte.startGCPanel(this.xNode); + xGrammalectePort.postMessage({ + sCommand: "parseAndSpellcheck", + dParam: {sText: this._getText(), sCountry: "FR", bDebug: false, bContext: false}, + dInfo: {sTextAreaId: this.xNode.id} + }); + }; this.xButton.style.zIndex = (xNode.style.zIndex.search(/^[0-9]+$/) !== -1) ? (parseInt(xNode.style.zIndex) + 1).toString() : xNode.style.zIndex; - this.xMenu = this._createMenu(); let xStyle = window.getComputedStyle(this.xNode); let xNodeInsertAfter = this.xNode; if (document.location.host == "twitter.com" && this.xNode.classList.contains('rich-editor')) { @@ -30,23 +35,16 @@ this.xShadowBtn = oGrammalecte.createNode("div", {style: "display:none;position:absolute;width:0;height:0;"}); this.xShadowBtnNode = this.xShadowBtn.attachShadow({mode: "open"}); oGrammalecte.createStyle("content_scripts/menu.css", null, this.xShadowBtnNode); this.xShadowBtnNode.appendChild(this.xButton); this._insertAfter(this.xShadowBtn, xNodeInsertAfter, nMarginTop); - - this.xShadowMenu = oGrammalecte.createNode("div", {id: this.sMenuId+"_shadow", style: "display:none;position:absolute;width:0;height:0;"}); - this.xShadowMenuNode = this.xShadowMenu.attachShadow({mode: "open"}); - oGrammalecte.createStyle("content_scripts/menu.css", null, this.xShadowMenuNode); - this.xShadowMenuNode.appendChild(this.xMenu); - this._insertAfter(this.xShadowMenu, xNodeInsertAfter, nMarginTop + 8); } else { let nMarginTop = -1 * (8 + parseInt(xStyle.marginBottom.replace('px', ''), 10)); if (!document.getElementById("grammalecte_cssmenu")) { oGrammalecte.createStyle("content_scripts/menu.css", "grammalecte_cssmenu", document.head); } this._insertAfter(this.xButton, xNodeInsertAfter, nMarginTop); - this._insertAfter(this.xMenu, xNodeInsertAfter, nMarginTop + 8); } this._createListeners(); } _insertAfter (xNewNode, xReferenceNode, nMarginTop) { @@ -68,102 +66,13 @@ _getText () { return (this.xNode.tagName == "TEXTAREA") ? this.xNode.value.normalize("NFC") : this.xNode.innerText.normalize("NFC"); } - _createMenu () { - try { - let xMenu = oGrammalecte.createNode("div", {id: this.sMenuId, className: "grammalecte_menu"}); - let xCloseButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_close_button", textContent: "×"} ); - xCloseButton.onclick = () => { - if (this.bShadow){ - this.xShadowBtn.style.display = "none"; - } - this.xButton.style.display = "none"; - this.switchMenu(); - } - xMenu.appendChild(xCloseButton); - xMenu.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_menu_header", textContent: "GRAMMALECTE"})); - // Text formatter - if (this.xNode.tagName == "TEXTAREA") { - let xTFButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item", textContent: "Formateur de texte"}); - xTFButton.onclick = () => { - this.switchMenu(); - oGrammalecte.createTFPanel(); - oGrammalecte.oTFPanel.start(this.xNode); - oGrammalecte.oTFPanel.show(); - }; - xMenu.appendChild(xTFButton); - } - // lexicographe - let xLxgButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item", textContent: "Lexicographe"}); - xLxgButton.onclick = () => { - this.switchMenu(); - oGrammalecte.startLxgPanel(); - xGrammalectePort.postMessage({ - sCommand: "getListOfTokens", - dParam: {sText: this._getText()}, - dInfo: {sTextAreaId: this.xNode.id} - }); - }; - xMenu.appendChild(xLxgButton); - // Grammar checker - let xGCButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item", textContent: "Correction grammaticale"}); - xGCButton.onclick = () => { - this.switchMenu(); - oGrammalecte.startGCPanel(this.xNode); - xGrammalectePort.postMessage({ - sCommand: "parseAndSpellcheck", - dParam: {sText: this._getText(), sCountry: "FR", bDebug: false, bContext: false}, - dInfo: {sTextAreaId: this.xNode.id} - }); - }; - xMenu.appendChild(xGCButton); - // Lexicon editor - let xLEButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item", textContent: "Éditeur lexical"}); - xLEButton.onclick = () => { - this.switchMenu(); - xGrammalectePort.postMessage({sCommand: "openLexiconEditor", dParam: null, dInfo: null}); - }; - xMenu.appendChild(xLEButton); - // Conjugation tool - let xConjButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item_block", textContent: "Conjugueur"}); - let xConjButtonTab = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Onglet"}); - xConjButtonTab.onclick = () => { - this.switchMenu(); - xGrammalectePort.postMessage({sCommand: "openConjugueurTab", dParam: null, dInfo: null}); - }; - let xConjButtonWin = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Fenêtre"}); - xConjButtonWin.onclick = () => { - this.switchMenu(); - xGrammalectePort.postMessage({sCommand: "openConjugueurWindow", dParam: null, dInfo: null}); - }; - xConjButton.appendChild(xConjButtonTab); - xConjButton.appendChild(xConjButtonWin); - xMenu.appendChild(xConjButton); - //xMenu.appendChild(oGrammalecte.createNode("img", {scr: browser.extension.getURL("img/logo-16.png")})); - // can’t work, due to content-script policy: https://bugzilla.mozilla.org/show_bug.cgi?id=1267027 - xMenu.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_menu_footer"})); - return xMenu; - } - catch (e) { - showError(e); - } - } - deleteNodes () { if (this.bShadow) { - this.xShadowMenu.parentNode.removeChild(this.xShadowMenu); this.xShadowBtn.parentNode.removeChild(this.xShadowBtn); } else { - this.xMenu.parentNode.removeChild(this.xMenu); this.xButton.parentNode.removeChild(this.xButton); } } - - switchMenu () { - if (this.bShadow) { - this.xShadowMenu.style.display = (this.xShadowMenu.style.display == "block") ? "none" : "block"; - } - this.xMenu.style.display = (this.xMenu.style.display == "block") ? "none" : "block"; - } } 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 @@ -101,11 +101,11 @@ } div.grammalecte_panel_content { position: absolute; width: 100%; - height: calc(100% - 55px); /* panel height - title_bar */ + height: calc(100% - 75px); /* panel height - title_bar */ overflow: auto; } div.grammalecte_panel_message { margin: 10px; @@ -115,10 +115,29 @@ color: hsl(0, 50%, 96%); font-family: "Trebuchet MS", "Fira Sans", "Liberation Sans", sans-serif; font-size: 16px; } + +div.grammalecte_panel_menu { + display: flex; + flex-direction: row; + justify-content: space-around; + background-color: hsl(210, 50%, 50%); +} +div.grammalecte_menu_button { + color: hsl(210, 50%, 96%); + padding: 5px 10px; + font-size: 12px; + font-variant: small-caps; + cursor: pointer; + border-radius: 3px; +} +div.grammalecte_menu_button:hover { + background-color: hsl(210, 80%, 40%); +} + /* Spinner */ div.grammalecte_spinner { 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 @@ -48,29 +48,103 @@ */ constructor (...args) { super(...args); this.aIgnoredErrors = new Set(); - this.xContentNode = oGrammalecte.createNode("div", {id: "grammalecte_gc_panel_content"}); + this.createMenu() + // Editor + this.xGCPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_gc_panel_content"}); this.xParagraphList = oGrammalecte.createNode("div", {id: "grammalecte_paragraph_list"}); - this.xContentNode.appendChild(this.xParagraphList); + this.xGCPanelContent.appendChild(this.xParagraphList); this.xPanelContent.addEventListener("click", onGrammalecteGCPanelClick, false); - this.oTooltip = new GrammalecteTooltip(this.xParent, this.xContentNode); - this.xPanelContent.appendChild(this.xContentNode); + this.oTooltip = new GrammalecteTooltip(this.xParent, this.xGCPanelContent); + this.xPanelContent.appendChild(this.xGCPanelContent); + this.xNode = null; this.oNodeControl = new GrammalecteNodeControl(); + // Lexicographer + this.nLxgCount = 0; + this.xLxgPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_lxg_panel_content"}); + this.xPanelContent.appendChild(this.xLxgPanelContent); + } + + createMenu () { + this.xMenu = oGrammalecte.createNode("div", {className: "grammalecte_panel_menu"}); + this.xTFButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Formateur de texte"}); + this.xEditorButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Texte"}); + 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 = () => { + oGrammalecte.createTFPanel(); + if (this.xNode) { + oGrammalecte.oTFPanel.start(this.xNode); + oGrammalecte.oTFPanel.show(); + this.start(this.xNode); + this.startWaitIcon(); + xGrammalectePort.postMessage({ + sCommand: "parseAndSpellcheck", + dParam: {sText: this.getParsedText(), sCountry: "FR", bDebug: false, bContext: false}, + dInfo: ((this.xNode) ? {sTextAreaId: this.xNode.id} : {}) + }); + } else { + oGrammalecte.showMessage("Aucun node sur lequel appliquer le formatage de texte.") + } + }; + this.xEditorButton.onclick = () => { + this.showEditor(); + }; + this.xLxgButton.onclick = () => { + this.showLexicographer(); + if (true) { + this.clearLexicographer(); + this.startWaitIcon(); + xGrammalectePort.postMessage({ + sCommand: "getListOfTokens", + dParam: {sText: this.getParsedText()}, + dInfo: ((this.xNode) ? {sTextAreaId: this.xNode.id} : {}) + }); + } + }; + this.xConjButton.onclick = () => { xGrammalectePort.postMessage({sCommand: "openConjugueurTab", dParam: null, dInfo: null}); }; + this.xLEButton.onclick = () => { xGrammalectePort.postMessage({sCommand: "openLexiconEditor", dParam: null, dInfo: null}); }; + this.xMenu.appendChild(this.xTFButton) + this.xMenu.appendChild(this.xEditorButton) + this.xMenu.appendChild(this.xLxgButton) + this.xMenu.appendChild(this.xConjButton) + this.xMenu.appendChild(this.xLEButton) + this.xPanelBar.appendChild(this.xMenu); } start (xNode=null) { this.oTooltip.hide(); this.clear(); + this.xNode = xNode; if (xNode) { this.oNodeControl.setNode(xNode); if (!(xNode.tagName == "TEXTAREA" || xNode.tagName == "INPUT")) { this.addMessage("Note : cette zone de texte n’est pas un champ de formulaire “textarea” mais un node HTML éditable. Une telle zone de texte est susceptible de contenir des éléments non textuels qui seront effacés lors de la correction."); } } } + + getParsedText () { + if (this.xNode) { + return (this.xNode.tagName == "TEXTAREA") ? this.xNode.value.normalize("NFC") : this.xNode.innerText.normalize("NFC"); + } else { + return oGrammalecte.getPageText(); + } + } + + showEditor () { + this.xGCPanelContent.style.display = "block"; + this.xLxgPanelContent.style.display = "none"; + } + + showLexicographer () { + this.xGCPanelContent.style.display = "none"; + this.xLxgPanelContent.style.display = "block"; + } clear () { while (this.xParagraphList.firstChild) { this.xParagraphList.removeChild(this.xParagraphList.firstChild); } @@ -86,11 +160,11 @@ try { if (oResult && (oResult.sParagraph.trim() !== "" || oResult.aGrammErr.length > 0 || oResult.aSpellErr.length > 0)) { let xNodeDiv = oGrammalecte.createNode("div", {className: "grammalecte_paragraph_block"}); // actions let xActionsBar = oGrammalecte.createNode("div", {className: "grammalecte_paragraph_actions"}); - xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_check" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_green", textContent: "A", title: "Réanalyser…"}, {para_num: oResult.iParaNum})); + xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_check" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_green", textContent: "↻", title: "Réanalyser…"}, {para_num: oResult.iParaNum})); xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_hide" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_red", textContent: "×", title: "Cacher", style: "font-weight: bold;"})); // paragraph let xParagraph = oGrammalecte.createNode("p", {id: "grammalecte_paragraph"+oResult.iParaNum, className: "grammalecte_paragraph", lang: "fr", contentEditable: "true"}, {para_num: oResult.iParaNum}); xParagraph.setAttribute("spellcheck", "false"); // doesn’t seem possible to use “spellcheck” as a common attribute. xParagraph.dataset.timer_id = "0"; @@ -215,11 +289,11 @@ freeParagraph (xParagraph) { xParagraph.contentEditable = "true"; let nStart = parseInt(xParagraph.dataset.caret_position_start); let nEnd = parseInt(xParagraph.dataset.caret_position_end); oGrammalecte.setCaretPosition(xParagraph, nStart, nEnd); - this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).textContent = "A"; + this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).textContent = "↻"; this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.backgroundColor = ""; this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.animation = ""; setTimeout(() => { this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.boxShadow = ""; }, 500); } @@ -295,16 +369,98 @@ catch (e) { showError(e); } this.stopWaitIcon(); } + + + // Lexicographer + + clearLexicographer () { + this.nLxgCount = 0; + while (this.xLxgPanelContent.firstChild) { + this.xLxgPanelContent.removeChild(this.xLxgPanelContent.firstChild); + } + } + + addLxgSeparator (sText) { + if (this.xLxgPanelContent.textContent !== "") { + this.xLxgPanelContent.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_separator", textContent: sText})); + } + } + + addMessage (sMessage) { + let xNode = oGrammalecte.createNode("div", {className: "grammalecte_panel_message", textContent: sMessage}); + this.xLxgPanelContent.appendChild(xNode); + } + + addListOfTokens (lToken) { + try { + if (lToken) { + this.nLxgCount += 1; + let xTokenList = oGrammalecte.createNode("div", {className: "grammalecte_lxg_list_of_tokens"}); + xTokenList.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_list_num", textContent: this.nLxgCount})); + for (let oToken of lToken) { + xTokenList.appendChild(this._createTokenBlock(oToken)); + } + this.xLxgPanelContent.appendChild(xTokenList); + } + } + catch (e) { + showError(e); + } + } + + _createTokenBlock (oToken) { + let xTokenBlock = oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_block"}); + xTokenBlock.appendChild(this._createTokenDescr(oToken)); + if (oToken.aSubElem) { + let xSubBlock = oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_subblock"}); + for (let oSubElem of oToken.aSubElem) { + xSubBlock.appendChild(this._createTokenDescr(oSubElem)); + } + xTokenBlock.appendChild(xSubBlock); + } + return xTokenBlock; + } + + _createTokenDescr (oToken) { + try { + let xTokenDescr = oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_descr"}); + if (oToken.sType == "LOCP") { + xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_also", textContent: "possiblement › "})); + } + xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_token grammalecte_lxg_token_" + oToken.sType, textContent: oToken.sValue})); + xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_colon", textContent: ":"})); + if (oToken.aLabel.length === 1) { + xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_morph_elem_inline", textContent: oToken.aLabel[0]})); + } else { + let xMorphList = oGrammalecte.createNode("div", {className: "grammalecte_lxg_morph_list"}); + for (let sLabel of oToken.aLabel) { + xMorphList.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_morph_elem", textContent: "• " + sLabel})); + } + xTokenDescr.appendChild(xMorphList); + } + return xTokenDescr; + } + catch (e) { + showError(e); + } + } + + setHidden (sClass, bHidden) { + let xPanelContent = this.xParent.getElementById('grammalecte_panel_content'); + for (let xNode of xPanelContent.getElementsByClassName(sClass)) { + xNode.hidden = bHidden; + } + } } class GrammalecteTooltip { - constructor (xParent, xContentNode) { + constructor (xParent, xGCPanelContent) { this.xParent = xParent; this.sErrorId = null; this.bDebug = false; this.xTooltip = oGrammalecte.createNode("div", {id: "grammalecte_tooltip"}); this.xTooltipArrow = oGrammalecte.createNode("img", { @@ -326,12 +482,12 @@ 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: " ››› base de données"}, {url: ""})); this.xTooltip.appendChild(xActions); // add tooltip to the page - xContentNode.appendChild(this.xTooltip); - xContentNode.appendChild(this.xTooltipArrow); + xGCPanelContent.appendChild(this.xTooltip); + xGCPanelContent.appendChild(this.xTooltipArrow); } show (sNodeErrorId) { // err try { let xNodeErr = this.xParent.getElementById(sNodeErrorId); Index: gc_lang/fr/webext/content_scripts/panel_lxg.css ================================================================== --- gc_lang/fr/webext/content_scripts/panel_lxg.css +++ gc_lang/fr/webext/content_scripts/panel_lxg.css @@ -1,9 +1,10 @@ /* Lexicographer */ div#grammalecte_lxg_panel_content { + display: none; padding: 5px; font-size: 13px; } div.grammalecte_lxg_list_of_tokens { DELETED gc_lang/fr/webext/content_scripts/panel_lxg.js Index: gc_lang/fr/webext/content_scripts/panel_lxg.js ================================================================== --- gc_lang/fr/webext/content_scripts/panel_lxg.js +++ /dev/null @@ -1,97 +0,0 @@ -// JavaScript - -/* jshint esversion:6, -W097 */ -/* jslint esversion:6 */ -/* global GrammalectePanel, oGrammalecte, showError, console */ - -"use strict"; - - -class GrammalecteLexicographer extends GrammalectePanel { - - constructor (...args) { - super(...args); - this._nCount = 0; - this._xContentNode = oGrammalecte.createNode("div", {id: "grammalecte_lxg_panel_content"}); - this.xPanelContent.appendChild(this._xContentNode); - } - - clear () { - this._nCount = 0; - while (this._xContentNode.firstChild) { - this._xContentNode.removeChild(this._xContentNode.firstChild); - } - } - - addSeparator (sText) { - if (this._xContentNode.textContent !== "") { - this._xContentNode.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_separator", textContent: sText})); - } - } - - addMessage (sMessage) { - let xNode = oGrammalecte.createNode("div", {className: "grammalecte_panel_message", textContent: sMessage}); - this._xContentNode.appendChild(xNode); - } - - addListOfTokens (lToken) { - try { - if (lToken) { - this._nCount += 1; - let xTokenList = oGrammalecte.createNode("div", {className: "grammalecte_lxg_list_of_tokens"}); - xTokenList.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_list_num", textContent: this._nCount})); - for (let oToken of lToken) { - xTokenList.appendChild(this._createTokenBlock(oToken)); - } - this._xContentNode.appendChild(xTokenList); - } - } - catch (e) { - showError(e); - } - } - - _createTokenBlock (oToken) { - let xTokenBlock = oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_block"}); - xTokenBlock.appendChild(this._createTokenDescr(oToken)); - if (oToken.aSubElem) { - let xSubBlock = oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_subblock"}); - for (let oSubElem of oToken.aSubElem) { - xSubBlock.appendChild(this._createTokenDescr(oSubElem)); - } - xTokenBlock.appendChild(xSubBlock); - } - return xTokenBlock; - } - - _createTokenDescr (oToken) { - try { - let xTokenDescr = oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_descr"}); - if (oToken.sType == "LOCP") { - xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_also", textContent: "possiblement › "})); - } - xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_token grammalecte_lxg_token_" + oToken.sType, textContent: oToken.sValue})); - xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_colon", textContent: ":"})); - if (oToken.aLabel.length === 1) { - xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_morph_elem_inline", textContent: oToken.aLabel[0]})); - } else { - let xMorphList = oGrammalecte.createNode("div", {className: "grammalecte_lxg_morph_list"}); - for (let sLabel of oToken.aLabel) { - xMorphList.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_morph_elem", textContent: "• " + sLabel})); - } - xTokenDescr.appendChild(xMorphList); - } - return xTokenDescr; - } - catch (e) { - showError(e); - } - } - - setHidden (sClass, bHidden) { - let xPanelContent = this.xParent.getElementById('grammalecte_panel_content'); - for (let xNode of xPanelContent.getElementsByClassName(sClass)) { - xNode.hidden = bHidden; - } - } -} Index: gc_lang/fr/webext/manifest.json ================================================================== --- gc_lang/fr/webext/manifest.json +++ gc_lang/fr/webext/manifest.json @@ -51,11 +51,10 @@ "js": [ "content_scripts/panel.js", "grammalecte/fr/textformatter.js", "content_scripts/panel_tf.js", "content_scripts/panel_gc.js", - "content_scripts/panel_lxg.js", "content_scripts/message_box.js", "content_scripts/menu.js", "content_scripts/init.js" ], "run_at": "document_end" @@ -78,29 +77,17 @@ "run_at": "document_idle" } ], "commands": { - "lexicographer": { - "suggested_key": { "default": "Ctrl+Shift+L" }, - "description": "Ouvre le lexicographe" - }, - "text_formatter": { - "suggested_key": { "default": "Ctrl+Shift+F" }, - "description": "Ouvre le formateur de texte" - }, "grammar_checker": { - "suggested_key": { "default": "Ctrl+Shift+V" }, + "suggested_key": { "default": "Ctrl+Shift+6" }, "description": "Ouvre le correcteur grammatical" }, "conjugueur_tab": { - "suggested_key": { "default": "Ctrl+Shift+6" }, - "description": "Ouvre le conjugueur dans un onglet" - }, - "conjugueur_window": { "suggested_key": { "default": "Ctrl+Shift+7" }, - "description": "Ouvre le conjugueur dans une fenêtre" + "description": "Ouvre le conjugueur" }, "lexicon_editor": { "suggested_key": { "default": "Ctrl+Shift+8" }, "description": "Ouvre l’éditeur lexical" }