Grammalecte  Check-in [6a95ec929e]

Overview
Comment:[tb] code cleaning
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tb | tbme
Files: files | file ages | folders
SHA3-256: 6a95ec929ec86f91d53f836f8614b58bf2d747d8dcd73da265f75c7b1eaac8c6
User & Date: olr on 2019-09-05 06:00:31
Other Links: branch diff | manifest | tags
Context
2019-09-05
06:56
[tb] gc options: ui update check-in: 66ee6776cc user: olr tags: tb, tbme
06:00
[tb] code cleaning check-in: 6a95ec929e user: olr tags: tb, tbme
2019-09-04
19:51
[tb] useless console.log() check-in: 4cc1a6db6e user: olr tags: tb, tbme
Changes

Modified gc_lang/fr/mailext/content/spellchecker.js from [f4fc6376bf] to [ca575ac13b].

    12     12       https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Using_spell_checking_in_XUL
    13     13       https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFile
    14     14       https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/FileUtils.jsm
    15     15   */
    16     16   
    17     17   "use strict";
    18     18   
    19         -/*
    20         -// Loaded in another file
    21         -const Cc = Components.classes;
    22         -const Ci = Components.interfaces;
    23         -const Cu = Components.utils;
    24         -const { require } = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {});
    25         -*/
    26     19   
    27         -const FileUtils = ChromeUtils.import("resource://gre/modules/FileUtils.jsm").FileUtils;
    28         -const AddonManager = ChromeUtils.import("resource://gre/modules/AddonManager.jsm").AddonManager;
           20  +const { FileUtils } = ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
           21  +const { AddonManager } = ChromeUtils.import("resource://gre/modules/AddonManager.jsm");
    29     22   
    30     23   
    31     24   var oSpellControl = {
    32     25       xSCEngine: null,
    33     26       init: function () {
    34     27           if (this.xSCEngine === null) {
    35     28               try {
................................................................................
    41     34                       sSpellchecker = "@mozilla.org/spellchecker/engine;1";
    42     35                   }
    43     36                   this.xSCEngine = Cc[sSpellchecker].getService(Ci.mozISpellCheckingEngine);
    44     37               }
    45     38               catch (e) {
    46     39                   console.log("Can’t initiate the spellchecker.");
    47     40                   console.error(e);
    48         -                // Cu.reportError(e);
    49     41               }
    50     42           }
    51     43       },
    52     44       getDictionariesList: function () {
    53     45           this.init();
    54     46           try {
    55     47               let l = {};
    56     48               let c = {};
    57     49               this.xSCEngine.getDictionaryList(l, c);
    58     50               return l.value;
    59     51           }
    60     52           catch (e) {
    61     53               console.error(e);
    62         -            // Cu.reportError(e);
    63     54               return [];
    64     55           }
    65     56       },
    66     57       setDictionary: function (sLocale) {
    67     58           if (this.getDictionariesList().includes(sLocale)) {
    68     59               try {
    69     60                   this.xSCEngine.dictionary = sLocale; // en-US, fr, etc.
    70     61                   return true;
    71     62               }
    72     63               catch (e) {
    73     64                   console.error(e);
    74         -                // Cu.reportError(e);
    75     65                   return false;
    76     66               }
    77     67           } else {
    78     68               console.log("Warning. No dictionary for locale: " + sLocale);
    79     69               console.log("Existing dictionaries: " + this.getDictionariesList().join(" | "));
    80     70           }
    81     71           return false;
................................................................................
    83     73       check: function (sWord) {
    84     74           // todo: check in personal dict?
    85     75           try {
    86     76               return this.xSCEngine.check(sWord);
    87     77           }
    88     78           catch (e) {
    89     79               console.error(e);
    90         -            // Cu.reportError(e);
    91     80               return false;
    92     81           }
    93     82       },
    94     83       suggest: function (sWord) {
    95     84           try {
    96     85               let lSugg = {};
    97     86               this.xSCEngine.suggest(sWord, lSugg, {});
    98     87               return lSugg.value;
    99     88               // lSugg.value is a JavaScript Array of strings
   100     89           }
   101     90           catch (e) {
   102     91               console.error(e);
   103         -            // Cu.reportError(e);
   104     92               return ['#Erreur.'];
   105     93           }
   106     94       },
   107     95       addDirectory: function (sFolder) {
   108     96           try {
   109     97               let xNsiFolder = new FileUtils.File(sFolder);
   110     98               this.xSCEngine.addDirectory(xNsiFolder);
   111     99           }
   112    100           catch (e) {
   113    101               console.log("Unable to add directory: " + sFolder);
   114    102               console.error(e);
   115         -            // Cu.reportError(e);
   116    103           }
   117    104       },
   118    105       removeDirectory: function (sFolder) {
   119    106           // does not work but no exception raised (bug?)
   120    107           try {
   121    108               let xNsiFolder = new FileUtils.File(sFolder);
   122    109               this.xSCEngine.removeDirectory(xNsiFolder);
   123    110           }
   124    111           catch (e) {
   125    112               console.log("Unable to remove directory: " + sFolder);
   126    113               console.error(e);
   127         -            // Cu.reportError(e);
   128    114           }
   129    115       },
   130    116       setExtensionDictFolder: function (sDictName, bActivate) {
   131    117           try {
   132    118               let that = this;
   133    119               let sPath = "/content/dictionaries/" + sDictName;
   134         -            AddonManager.getAddonByID("French-GC-TB@grammalecte.net", function (addon) {
   135         -                let xURI = addon.getResourceURI(sPath);
          120  +            AddonManager.getAddonByID("French-GC-TB@grammalecte.net")
          121  +            .then(function (xAddon) {
          122  +                let xURI = xAddon.getResourceURI(sPath);
   136    123                   //console.log(xURI);
   137    124                   let sFolder = xURI.filePath;
   138    125                   if (sFolder !== undefined) {
   139    126                       if (/^\/[A-Z]:\//.test(sFolder)) {
   140    127                           // Windows path
   141    128                           sFolder = sFolder.slice(1).replace(/\//g, "\\\\");
   142    129                       }
................................................................................
   148    135                       }
   149    136                   }
   150    137               });
   151    138           }
   152    139           catch (e) {
   153    140               console.log("Unable to add extension folder");
   154    141               console.error(e);
   155         -            // Cu.reportError(e);
   156    142           }
   157    143       }
   158    144   };