Overview
| Comment: | [tb] load personal dictionary at startup |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | tb | multid |
| Files: | files | file ages | folders |
| SHA3-256: |
0ab0682f550100e8bb4adb9106ededcc |
| User & Date: | olr on 2018-03-20 11:13:07 |
| Other Links: | branch diff | manifest | tags |
Context
|
2018-03-20
| ||
| 12:04 | [tb] comment: spelling mistake check-in: 0726b05211 user: olr tags: tb, multid | |
| 11:13 | [tb] load personal dictionary at startup check-in: 0ab0682f55 user: olr tags: tb, multid | |
| 09:21 | [tb] timeout: progress bar to 0 after 2 s check-in: 5eb79332a3 user: olr tags: tb, multid | |
Changes
Added gc_lang/fr/tb/content/file_handler.js version [39a972038f].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
// JavaScript
"use strict";
// Assuming that Cc, Ci and Cu are already loaded
const {TextDecoder, TextEncoder, OS} = Components.utils.import("resource://gre/modules/osfile.jsm", {});
const oFileHandler = {
// https://developer.mozilla.org/fr/docs/Mozilla/JavaScript_code_modules/OSFile.jsm/OS.File_for_the_main_thread
xDataFolder: null,
prepareDataFolder: function () {
let xDirectoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
// this is a reference to the profile dir (ProfD) now.
let xExtFolder = xDirectoryService.get("ProfD", Ci.nsIFile);
xExtFolder.append("grammalecte-data");
if (!xExtFolder.exists() || !xExtFolder.isDirectory()) {
// read and write permissions to owner and group, read-only for others.
xExtFolder.create(Ci.nsIFile.DIRECTORY_TYPE, 774);
}
this.xDataFolder = xExtFolder;
},
createPathFileName: function (sFilename) {
let spfDest = this.xDataFolder.path;
spfDest += (/^[A-Z]:/.test(this.xDataFolder.path)) ? "\\" + sFilename : "/" + sFilename;
return spfDest;
},
loadFile: async function (sFilename) {
if (!this.xDataFolder) {
this.prepareDataFolder();
}
try {
let xDecoder = new TextDecoder();
let array = await OS.File.read(this.createPathFileName(sFilename));
return xDecoder.decode(array);
}
catch (e) {
console.error(e);
return null;
}
},
saveFile: function (sFilename, sData) {
if (!this.xDataFolder) {
this.prepareDataFolder();
}
let xEncoder = new TextEncoder();
let xEncodedRes = xEncoder.encode(sData);
console.log("save dictionary: " + this.createPathFileName(sFilename));
OS.File.writeAtomic(this.createPathFileName(sFilename), xEncodedRes);
//OS.File.writeAtomic(this.createPathFileName(sFilename), xEncodedRes, {tmpPath: "file.txt.tmp"}); // error with a temporary file (can’t move it)
},
deleteFile: function (sFilename) {
if (!this.xDataFolder) {
this.prepareDataFolder();
}
OS.File.remove(this.createPathFileName(sFilename), {ignoreAbsent: true});
},
saveAs: function (sData) {
// save anywhere with file picker
let xFilePicker = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
xFilePicker.init(window, "Enregistrer sous", Ci.nsIFilePicker.modeSave);
xFilePicker.appendFilters(Ci.nsIFilePicker.filterAll | Ci.nsIFilePicker.filterText);
xFilePicker.open(function (nReturnValue) {
if (nReturnValue == Ci.nsIFilePicker.returnOK || nReturnValue == Ci.nsIFilePicker.returnReplace) {
let xEncoder = new TextEncoder();
let xEncodedRes = xEncoder.encode(sData);
OS.File.writeAtomic(xFilePicker.file.path, xEncodedRes, {tmpPath: "file.txt.tmp"});
}
});
}
}
|
Modified gc_lang/fr/tb/content/lex_editor.js from [7abca98323] to [e1b304940a].
1 2 3 4 5 6 7 8 9 |
// JavaScript
"use strict";
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("extensions.grammarchecker.");
| < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// JavaScript
"use strict";
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("extensions.grammarchecker.");
/*
Common functions
*/
function showError (e) {
Cu.reportError(e);
|
| ︙ | ︙ | |||
472 473 474 475 476 477 478 479 |
export: function () {
let sJSON = JSON.stringify(this.oIBDAWG.getJSON());
oFileHandler.saveAs(sJSON);
}
}
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
export: function () {
let sJSON = JSON.stringify(this.oIBDAWG.getJSON());
oFileHandler.saveAs(sJSON);
}
}
const oGenWordsTable = new Table("generated_words_table", ["Flexions", "Étiquettes"], [1, 1], "progress_new_words");
const oLexiconTable = new Table("lexicon_table", ["Flexions", "Lemmes", "Étiquettes"], [10, 7, 10], "progress_lexicon", "num_entries");
conj.init(helpers.loadFile("resource://grammalecte/fr/conj_data.json"));
oBinaryDict.load();
oBinaryDict.listen();
oGenerator.listen();
|
Modified gc_lang/fr/tb/content/lex_editor.xul from [509f3f99a7] to [d3f3183550].
| ︙ | ︙ | |||
215 216 217 218 219 220 221 222 223 224 | <script type="application/x-javascript" src="resource://grammalecte/graphspell/helpers.js" /> <script type="application/x-javascript" src="resource://grammalecte/graphspell/str_transform.js" /> <script type="application/x-javascript" src="resource://grammalecte/graphspell/dawg.js" /> <script type="application/x-javascript" src="resource://grammalecte/graphspell/ibdawg.js" /> <script type="application/x-javascript" src="resource://grammalecte/fr/conj.js" /> <script type="application/x-javascript" src="resource://grammalecte/fr/conj_generator.js" /> <script type="application/x-javascript" src="lex_editor.js" /> </dialog> | > | 215 216 217 218 219 220 221 222 223 224 225 | <script type="application/x-javascript" src="resource://grammalecte/graphspell/helpers.js" /> <script type="application/x-javascript" src="resource://grammalecte/graphspell/str_transform.js" /> <script type="application/x-javascript" src="resource://grammalecte/graphspell/dawg.js" /> <script type="application/x-javascript" src="resource://grammalecte/graphspell/ibdawg.js" /> <script type="application/x-javascript" src="resource://grammalecte/fr/conj.js" /> <script type="application/x-javascript" src="resource://grammalecte/fr/conj_generator.js" /> <script type="application/x-javascript" src="file_handler.js" /> <script type="application/x-javascript" src="lex_editor.js" /> </dialog> |
Modified gc_lang/fr/tb/content/overlay.js from [94ffc58fa0] to [a85c2d244d].
| ︙ | ︙ | |||
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
xGCEWorker: null,
bDictActive: null,
loadGC: function () {
if (this.xGCEWorker === null) {
// Grammar checker
echo('Loading Grammalecte');
this.xGCEWorker = new BasePromiseWorker('chrome://promiseworker/content/gce_worker.js');
let xPromise = this.xGCEWorker.post('loadGrammarChecker', [prefs.getCharPref("sGCOptions"), "Thunderbird"]);
xPromise.then(
function (aVal) {
echo(aVal);
prefs.setCharPref("sGCOptions", aVal);
},
function (aReason) { echo('Promise rejected - ', aReason); }
).catch(
function (aCaught) { echo('Promise Error - ', aCaught); }
);
}
},
fullTests: function () {
echo('Performing tests... Wait...');
let xPromise = this.xGCEWorker.post('fullTests', ['{"nbsp":true, "esp":true, "unit":true, "num":true}']);
xPromise.then(
function (aVal) {
| > > > > > > > > | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
xGCEWorker: null,
bDictActive: null,
loadGC: function () {
if (this.xGCEWorker === null) {
// Grammar checker
echo('Loading Grammalecte');
this.xGCEWorker = new BasePromiseWorker('chrome://promiseworker/content/gce_worker.js');
let that = this;
let xPromise = this.xGCEWorker.post('loadGrammarChecker', [prefs.getCharPref("sGCOptions"), "Thunderbird"]);
xPromise.then(
function (aVal) {
echo(aVal);
prefs.setCharPref("sGCOptions", aVal);
if (prefs.getBoolPref("bPersonalDictionary")) {
let sDicJSON = oFileHandler.loadFile("fr.personal.json");
if (sDicJSON) {
that.xGCEWorker.post('setDictionary', ["personal", sDicJSON]);
}
}
},
function (aReason) { echo('Promise rejected - ', aReason); }
).catch(
function (aCaught) { echo('Promise Error - ', aCaught); }
);
}
},
fullTests: function () {
echo('Performing tests... Wait...');
let xPromise = this.xGCEWorker.post('fullTests', ['{"nbsp":true, "esp":true, "unit":true, "num":true}']);
xPromise.then(
function (aVal) {
|
| ︙ | ︙ |
Modified gc_lang/fr/tb/content/overlay.xul from [991053c2ea] to [74df4d6d6c].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="chrome://grammarchecker/content/overlay.css" type="text/css"?>
<!DOCTYPE overlay SYSTEM "chrome://grammarchecker/locale/overlay.dtd">
<overlay id="grammarchecker-overlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
<script type="application/x-javascript" src="overlay.js"/>
<script type="application/x-javascript" src="spellchecker.js"/>
<script type="application/x-javascript" src="editor.js"/>
<stringbundleset id="stringbundleset">
<stringbundle id="grammarchecker-strings" src="chrome://grammarchecker/locale/grammarchecker.properties"/>
</stringbundleset>
| > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="chrome://grammarchecker/content/overlay.css" type="text/css"?>
<!DOCTYPE overlay SYSTEM "chrome://grammarchecker/locale/overlay.dtd">
<overlay id="grammarchecker-overlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
<script type="application/x-javascript" src="overlay.js"/>
<script type="application/x-javascript" src="file_handler.js"/>
<script type="application/x-javascript" src="spellchecker.js"/>
<script type="application/x-javascript" src="editor.js"/>
<stringbundleset id="stringbundleset">
<stringbundle id="grammarchecker-strings" src="chrome://grammarchecker/locale/grammarchecker.properties"/>
</stringbundleset>
|
| ︙ | ︙ |
Modified gc_lang/fr/tb/defaults/preferences/grammarchecker.js from [768dd584ea] to [1b1284d83a].
1 2 3 4 5 6 7 |
pref("extensions.grammarchecker.sGCOptions", "");
pref("extensions.grammarchecker.sTFOptions", "");
pref("extensions.grammarchecker.bDictModern", false);
pref("extensions.grammarchecker.bDictClassic", true);
pref("extensions.grammarchecker.bDictReform", false);
pref("extensions.grammarchecker.bDictClassicReform", false);
pref("extensions.grammarchecker.bCheckSignature", true);
| | | | | 1 2 3 4 5 6 7 8 9 10 |
pref("extensions.grammarchecker.sGCOptions", "");
pref("extensions.grammarchecker.sTFOptions", "");
pref("extensions.grammarchecker.bDictModern", false);
pref("extensions.grammarchecker.bDictClassic", true);
pref("extensions.grammarchecker.bDictReform", false);
pref("extensions.grammarchecker.bDictClassicReform", false);
pref("extensions.grammarchecker.bCheckSignature", true);
pref("extensions.grammarchecker.bExtendedDictionary", false);
pref("extensions.grammarchecker.bCommunityDictionary", false);
pref("extensions.grammarchecker.bPersonalDictionary", true);
|
Modified gc_lang/fr/tb/worker/gce_worker.js from [4fc9e7a3c2] to [43b4c7c8b0].
| ︙ | ︙ | |||
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
return gce.getOptions().gl_toString();
}
catch (e) {
console.log("# Error: " + e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}
}
}
function parse (sText, sCountry, bDebug, bContext) {
let aGrammErr = gce.parse(sText, sCountry, bDebug, bContext);
return JSON.stringify(aGrammErr);
}
function parseAndSpellcheck (sText, sCountry, bDebug, bContext) {
| > > > > > > > > > > > > > > > > > > > > > | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
return gce.getOptions().gl_toString();
}
catch (e) {
console.log("# Error: " + e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}
}
}
function setDictionary (sTypeDic, sDicJSON) {
try {
console.log("set dictionary: " + sTypeDic);
let oJSON = JSON.parse(sDicJSON);
switch (sTypeDic) {
case "extended":
break;
case "community":
break;
case "personal":
oSpellChecker.setPersonalDictionary(oJSON);
break;
default:
console.log("[GCE worker] unknow dictionary type");
}
}
catch (e) {
console.error(e);
}
}
function parse (sText, sCountry, bDebug, bContext) {
let aGrammErr = gce.parse(sText, sCountry, bDebug, bContext);
return JSON.stringify(aGrammErr);
}
function parseAndSpellcheck (sText, sCountry, bDebug, bContext) {
|
| ︙ | ︙ |