Grammalecte  Check-in [52dc932e38]

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

Overview
Comment:[fx] lexicon editor: launch from main panel and prevent multi-tabs
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | comdic
Files: files | file ages | folders
SHA3-256:52dc932e3849a275763eec53efc00acf2625ec9371dd726ab94ec2c6d1169bc1
User & Date: olr 2018-12-10 17:56:03
Context
2018-12-11
18:50
[fx] page for dictionaries (draft) check-in: 09a2b4f200 user: olr tags: comdic, fx
2018-12-10
17:56
[fx] lexicon editor: launch from main panel and prevent multi-tabs check-in: 52dc932e38 user: olr tags: comdic, fx
14:27
merge trunk check-in: ad98751778 user: olr tags: comdic
Changes

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

   214    214           case "setDictionary":
   215    215           case "setDictionaryOnOff":
   216    216               xGCEWorker.postMessage(oRequest);
   217    217               break;
   218    218           case "openURL":
   219    219               browser.tabs.create({url: dParam.sURL});
   220    220               break;
          221  +        case "openConjugueurTab":
          222  +            openConjugueurTab();
          223  +            break;
          224  +        case "openLexiconEditor":
          225  +            openLexiconEditor(dParam["dictionary"]);
          226  +            break;
   221    227           default:
   222    228               console.log("[background] Unknown command: " + sCommand);
   223    229               console.log(oRequest);
   224    230       }
   225    231       //sendResponse({response: "response from background script"});
   226    232   }
   227    233   
   228    234   browser.runtime.onMessage.addListener(handleMessage);
   229    235   
   230    236   
   231    237   function handleConnexion (xPort) {
          238  +    // Messages from tabs
   232    239       let iPortId = xPort.sender.tab.id; // identifier for the port: each port can be found at dConnx[iPortId]
   233    240       dConnx.set(iPortId, xPort);
   234    241       xPort.onMessage.addListener(function (oRequest) {
   235    242           let {sCommand, dParam, dInfo} = oRequest;
   236    243           switch (sCommand) {
   237    244               case "parse":
   238    245               case "parseAndSpellcheck":
................................................................................
   347    354           case "conjugueur_tab":
   348    355               openConjugueurTab();
   349    356               break;
   350    357           case "conjugueur_window":
   351    358               openConjugueurWindow();
   352    359               break;
   353    360           case "lex_editor":
   354         -            openLexEditor();
          361  +            openLexiconEditor();
   355    362               break;
   356    363       }
   357    364   });
   358    365   
          366  +
          367  +/*
          368  +    Lexicon editor tab
          369  +*/
          370  +let nTabLexiconEditor = null;
          371  +
          372  +browser.tabs.onRemoved.addListener(function (nTabId, xRemoveInfo) {
          373  +    if (nTabId === nTabLexiconEditor) {
          374  +        nTabLexiconEditor = null;
          375  +    }
          376  +});
          377  +
   359    378   
   360    379   /*
   361    380       Actions
   362    381   */
   363    382   
   364    383   function storeGCOptions (dOptions) {
   365    384       if (dOptions instanceof Map) {
................................................................................
   369    388   }
   370    389   
   371    390   function sendCommandToTab (sCommand, iTab) {
   372    391       let xTabPort = dConnx.get(iTab);
   373    392       xTabPort.postMessage({sActionDone: sCommand, result: null, dInfo: null, bEnd: false, bError: false});
   374    393   }
   375    394   
   376         -function openLexEditor () {
   377         -    if (bChrome) {
   378         -        browser.tabs.create({
          395  +function openLexiconEditor (sName="__personal__") {
          396  +    if (nTabLexiconEditor === null) {
          397  +        if (bChrome) {
          398  +            browser.tabs.create({
          399  +                url: browser.extension.getURL("panel/lex_editor.html")
          400  +            }, onLexiconEditorOpened);
          401  +            return;
          402  +        }
          403  +        let xLexEditor = browser.tabs.create({
   379    404               url: browser.extension.getURL("panel/lex_editor.html")
   380    405           });
   381         -        return;
          406  +        xLexEditor.then(onLexiconEditorOpened, onError);
   382    407       }
   383         -    let xLexEditor = browser.tabs.create({
   384         -        url: browser.extension.getURL("panel/lex_editor.html")
   385         -    });
   386         -    xLexEditor.then(onCreated, onError);
          408  +}
          409  +
          410  +function onLexiconEditorOpened (xTab) {
          411  +    //console.log(xTab);
          412  +    nTabLexiconEditor = xTab.id;
   387    413   }
   388    414   
   389    415   function openConjugueurTab () {
   390    416       if (bChrome) {
   391    417           browser.tabs.create({
   392    418               url: browser.extension.getURL("panel/conjugueur.html")
   393    419           });
................................................................................
   420    446   
   421    447   
   422    448   function onCreated (xWindowInfo) {
   423    449       //console.log(`Created window: ${xWindowInfo.id}`);
   424    450   }
   425    451   
   426    452   function onError (error) {
   427         -    console.log(`Error: ${error}`);
          453  +    console.log(error);
   428    454   }

Changes to gc_lang/fr/webext/panel/main.css.

    82     82       height: 500px;
    83     83       font-family: "Trebuchet MS", "Fira Sans", "Liberation Sans", sans-serif;
    84     84   }
    85     85   body {
    86     86       width: 450px;
    87     87       height: 500px;
    88     88   }
    89         -/* 
           89  +/*
    90     90       Maximal height of a panel in WebExtention seems to be 500px.
    91     91       When going over this limit, a scrollbar appears which destructs the
    92     92       horizontal balance of elements.
    93     93       --> vertical scrolling is done with overflow in #page.
    94     94           #page must have the same height than body.
    95     95   */
    96     96   
................................................................................
   243    243       padding: 5px 10px;
   244    244       border-radius: 3px;
   245    245       font-size: 16px;
   246    246       text-align: center;
   247    247       cursor: pointer;
   248    248   }
   249    249   
          250  +
          251  +.option_section {
          252  +    padding: 10px;
          253  +    margin-top: 10px;
          254  +    border-radius: 5px;
          255  +    background-color: hsl(210, 20%, 96%);
          256  +}
          257  +.option_section label {
          258  +    font-size: 16px;
          259  +    line-height: 20px;
          260  +    color: hsl(210, 20%, 50%);
          261  +    font-weight: bold;
          262  +}
          263  +.option_description {
          264  +    padding: 0 0 0 20px;
          265  +    color: hsl(0, 0%, 0%);
          266  +    font-size: 12px;
          267  +}
          268  +
   250    269   
   251    270   /*
   252    271       Spell checking options
   253    272   */
   254    273   #sc_options_page {
   255    274       display: none;
   256    275       padding: 20px;
................................................................................
   263    282       color: hsl(0, 10%, 96%);
   264    283   }
   265    284   #sc_options_page h2 {
   266    285       margin-top: 20px;
   267    286       font: normal 22px 'Yanone Kaffeesatz', "Oswald", "Liberation Sans Narrow", sans-serif;
   268    287       color: hsl(210, 50%, 50%);
   269    288   }
   270         -
   271         -/*
   272         -    Options
   273         -*/
   274         -.option_section {
   275         -    padding: 10px;
   276         -    margin-top: 10px;
   277         -    border-radius: 5px;
   278         -    background-color: hsl(210, 20%, 96%);
   279         -}
   280         -.option_section label {
   281         -    font-size: 16px;
   282         -    line-height: 20px;
   283         -    color: hsl(210, 20%, 50%);
   284         -    font-weight: bold;
   285         -}
   286         -.option_description {
   287         -    padding: 0 0 0 20px;
   288         -    color: hsl(0, 0%, 0%);
   289         -    font-size: 12px;
          289  +.dic_button {
          290  +    float: right;
          291  +    padding: 2px 10px;
          292  +    background-color: hsl(210, 50%, 50%);
          293  +    color: hsl(210, 10%, 96%);
          294  +    cursor: pointer;
          295  +    font-size: 14px;
          296  +    font-variant-caps: small-caps;
          297  +    border-radius: 3px;
   290    298   }
   291    299   
   292    300   
   293    301   /*
   294    302     Test page
   295    303   */
   296    304   #test_page {
................................................................................
   370    378       animation: sk-bounce 2.0s infinite ease-in-out;
   371    379   }
   372    380   .double-bounce2 {
   373    381       animation-delay: -1.0s;
   374    382   }
   375    383   
   376    384   @keyframes sk-bounce {
   377         -    0%, 100% { 
          385  +    0%, 100% {
   378    386           transform: scale(0.0);
   379         -    } 50% { 
          387  +    } 50% {
   380    388           transform: scale(1.0);
   381    389       }
   382    390   }

Changes to gc_lang/fr/webext/panel/main.html.

   104    104             <div id="default_options_button" class="button blue center">Options par défaut</div>
   105    105           </section> <!-- #gc_options_page -->
   106    106   
   107    107           <section id="sc_options_page" class="page">
   108    108             <h1>OPTIONS ORTHOGRAPHIQUES</h1>
   109    109             <div id="hunspell_options">
   110    110               <h2>DICTIONNAIRES DE GRAMMALECTE</h2>
   111         -            <p class="dictionaries_info">Ces dictionnaires ne sont utilisés que lors de l’analyse grammaticale.</p>
   112    111               <div class="option_section" id="main_dic_box">
   113         -                <p><input type="checkbox" id="main_dic" data-dictionary="personal" checked disabled="disabled" /> <label for="main_dic">Dictionnaire principal</label></p>
   114         -                <p class="option_description">Environ 83 000 entrées, 500 000 flexions.<br/>Ni éditable, ni désactivable.</p>
          112  +                <p><input type="checkbox" id="main_dic" data-dictionary="main" checked disabled="disabled" /> <label for="main_dic">Dictionnaire principal</label></p>
          113  +                <p class="option_description">Environ 83 000 entrées, 500 000 flexions.<br/>Ni éditable, ni désactivable.<br/>Ce dictionnaire est créé à partir du dictionnaire orthographique pour Firefox et LibreOffice, conçu sur le <a id="link_grammalecte" class="link" data-url="http://grammalecte.net/home.php?prj=fr">site de Grammalecte</a>.</p>
   115    114               </div>
   116         -            <div class="option_section" id="community_dic_box" style="opacity: .33;">
   117         -                <p><input type="checkbox" id="community_dic" data-dictionary="personal" disabled="disabled" /> <label for="community_dic">Dictionnaire communautaire</label></p>
   118         -                <p class="option_description">Fonctionnalité à venir.</p>
          115  +            <div class="option_section" id="community_dic_box">
          116  +                <p><input type="checkbox" id="community_dic" data-dictionary="community" /> <label for="community_dic">Dictionnaire communautaire</label></p>
          117  +                <div class="dic_button" id="dic_community_button">Éditer</div>
          118  +                <p class="option_description">Ce dictionnaire est créé et édité via l’éditeur lexical et est sauvegardé sur un serveur en ligne accessible à tous les membres.</p>
   119    119               </div>
   120    120               <div class="option_section" id="personal_dic_box">
   121    121                   <p><input type="checkbox" id="personal_dic" data-dictionary="personal" /> <label for="personal_dic">Dictionnaire personnel</label></p>
   122         -                <p class="option_description">Ce dictionnaire est créé et édité via l’éditeur lexical.</p>
          122  +                <div class="dic_button" id="dic_personal_button">Éditer</div>
          123  +                <p class="option_description">Ce dictionnaire est créé et édité via l’éditeur lexical et n’est pas partagé.</p>
   123    124               </div>
   124    125             </div>
   125    126   
   126    127             <div id="hunspell_options" style="display: none; opacity: .25">
   127    128               <h2>DICTIONNAIRES HUNSPELL</h2>
   128    129               <p class="dictionaries_info">Les dictionnaires Hunspell ne sont utilisées que pour la correction orthographique proposée par Firefox (soulignement rouge).<br/><br/>Section inactive.<br/>Le système d’extension <i>WebExtension</i> ne propose pas encore d’interface de programmation pour le correcteur orthographique.</p>
   129    130               <div class="option_section" id="fr-FR-modern_box">

Changes to gc_lang/fr/webext/panel/main.js.

    68     68               else if (xElem.id.startsWith("ui_option_")) {
    69     69                   storeUIOptions();
    70     70               }
    71     71               else if (xElem.id.startsWith("link_")) {
    72     72                   browser.tabs.create({url: xElem.dataset.url});
    73     73               }
    74     74               else if (xElem.id == "conj_button") {
    75         -                openConjugueurTab();
           75  +                browser.runtime.sendMessage({
           76  +                    sCommand: "openConjugueurTab",
           77  +                    dParam: {},
           78  +                    dInfo: {}
           79  +                });
           80  +            }
           81  +            else if (xElem.id == "dic_community_button") {
           82  +                browser.runtime.sendMessage({
           83  +                    sCommand: "openLexiconEditor",
           84  +                    dParam: { "dictionary": "__community__"},
           85  +                    dInfo: {}
           86  +                });
           87  +            }
           88  +            else if (xElem.id == "dic_personal_button") {
           89  +                browser.runtime.sendMessage({
           90  +                    sCommand: "openLexiconEditor",
           91  +                    dParam: { "dictionary": "__personal__"},
           92  +                    dInfo: {}
           93  +                });
    76     94               }
    77     95           } else if (xElem.className.startsWith("select")) {
    78     96               showPage(xElem.dataset.page);
    79     97           }/* else if (xElem.tagName === "A") {
    80     98               openURL(xElem.getAttribute("href"));
    81     99           }*/
    82    100       },
    83    101       false
    84    102   );
    85    103   
    86    104   
    87         -/* 
          105  +/*
    88    106       Message sender
    89    107       and response handling
    90    108   */
    91    109   function handleResponse (oResponse) {
    92    110       console.log(`[Panel] received:`);
    93    111       console.log(oResponse);
    94    112   }
................................................................................
    96    114   function handleError (error) {
    97    115       console.log(`[Panel] Error:`);
    98    116       console.log(error);
    99    117   }
   100    118   
   101    119   function sendMessageAndWaitResponse (oData) {
   102    120       let xPromise = browser.runtime.sendMessage(oData);
   103         -    xPromise.then(handleResponse, handleError);  
          121  +    xPromise.then(handleResponse, handleError);
   104    122   }
   105    123   
   106    124   
   107    125   /*
   108    126       Messages received
   109    127   */
   110    128   function handleMessage (oMessage, xSender, sendResponse) {
................................................................................
   154    172   }
   155    173   
   156    174   
   157    175   function showTestResult (sText) {
   158    176       document.getElementById("tests_result").textContent = sText;
   159    177   }
   160    178   
   161         -function openConjugueurTab () {
   162         -    if (bChrome) {
   163         -        browser.tabs.create({
   164         -            url: browser.extension.getURL("panel/conjugueur.html")
   165         -        });
   166         -        return;
   167         -    }
   168         -    let xConjTab = browser.tabs.create({
   169         -        url: browser.extension.getURL("panel/conjugueur.html")
   170         -    });
   171         -    xConjTab.then(onCreated, onError);
   172         -}
   173         -
   174         -function openConjugueurTab () {
   175         -    if (bChrome) {
   176         -        browser.tabs.create({
   177         -            url: browser.extension.getURL("panel/conjugueur.html")
   178         -        });
   179         -        return;
   180         -    }
   181         -    let xConjTab = browser.tabs.create({
   182         -        url: browser.extension.getURL("panel/conjugueur.html")
   183         -    });
   184         -    xConjTab.then(onCreated, onError);
   185         -}
   186         -
   187    179   
   188    180   /*
   189    181       UI options
   190    182   */
   191    183   function displayUIOptionsLoadedFromStorage () {
   192    184       if (bChrome) {
   193    185           browser.storage.local.get("ui_options", displayUIOptions);
................................................................................
   233    225   function displaySCOptions (dOptions) {
   234    226       if (!dOptions.hasOwnProperty("sc_options")) {
   235    227           console.log("no sc options found");
   236    228           return;
   237    229       }
   238    230       dOptions = dOptions.sc_options;
   239    231       //document.getElementById("extended_dic").checked = dOptions.extended_dic;
   240         -    //document.getElementById("community_dic").checked = dOptions.community_dic;
          232  +    document.getElementById("community_dic").checked = dOptions.community_dic;
   241    233       document.getElementById("personal_dic").checked = dOptions.personal;
   242    234   }
   243    235   
   244    236   function storeSCOptions () {
   245    237       browser.storage.local.set({"sc_options": {
   246    238           extended: false,
   247         -        community: false,
          239  +        community: document.getElementById("community_dic").checked,
   248    240           personal: document.getElementById("personal_dic").checked
   249    241       }});
   250    242   }
   251    243   
   252    244   
   253    245   /*
   254    246       GC options