Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -346,11 +346,11 @@ break; case "openConjugueurWindow": openConjugueurWindow(); break; case "openLexiconEditor": - openLexiconEditor(); + openLexiconEditor("__personal__", oParam["sWord"]); break; default: console.log("[background] Unknown command: " + sCommand); console.log(oRequest); } @@ -368,11 +368,11 @@ 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"); }); } /* @@ -398,17 +398,17 @@ // 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; @@ -477,14 +477,19 @@ 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) { @@ -506,12 +511,16 @@ for (let [iTab, xTabPort] of dConnx.entries()) { xTabPort.postMessage({sActionDone: sCommand, result: null, oInfo: null, bEnd: false, bError: false}); } } -function openLexiconEditor (sName="__personal__") { + +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; @@ -521,15 +530,19 @@ }); 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) { 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 @@ -362,12 +362,12 @@ openURL: function (sURL) { this.send("openURL", { "sURL": sURL }); }, - openLexiconEditor: function () { - this.send("openLexiconEditor"); + openLexiconEditor: function (sWord="") { + this.send("openLexiconEditor", { sWord: sWord }); }, restartWorker: function (nTimeDelay=10) { this.send("restartWorker", { "nTimeDelay": nTimeDelay }); }, Index: gc_lang/fr/webext/content_scripts/panel_gc.css ================================================================== --- gc_lang/fr/webext/content_scripts/panel_gc.css +++ gc_lang/fr/webext/content_scripts/panel_gc.css @@ -149,11 +149,12 @@ 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_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); @@ -161,11 +162,12 @@ 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_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 { 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 @@ -943,13 +943,19 @@ 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); } @@ -1000,15 +1006,17 @@ 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); Index: gc_lang/fr/webext/panel/lex_editor.js ================================================================== --- gc_lang/fr/webext/panel/lex_editor.js +++ gc_lang/fr/webext/panel/lex_editor.js @@ -323,10 +323,19 @@ } 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(); @@ -844,5 +853,23 @@ 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);