Commit a0cdc9b0 authored by Rodrigo Nascimento's avatar Rodrigo Nascimento

Try to load dictionaries on linux

parent 7abbc9fd
......@@ -74,6 +74,8 @@ var webContents = remote.getCurrentWebContents();
var Menu = remote.require('menu');
var menu = new Menu();
var path = remote.require('path');
// set the initial context menu so that a context menu exists even before spellcheck is called
var getTemplate = function() {
return [
......@@ -111,6 +113,7 @@ let languagesMenu;
let checker;
const enabledDictionaries = [];
let availableDictionaries = [];
let dictionariesPath;
if (localStorage.getItem('spellcheckerDictionaries')) {
let spellcheckerDictionaries = JSON.parse(localStorage.getItem('spellcheckerDictionaries'));
......@@ -138,7 +141,7 @@ const isCorrect = function(text) {
return;
}
checker.setDictionary(enabledDictionary);
checker.setDictionary(enabledDictionary, dictionariesPath);
if (!checker.isMisspelled(text)) {
isCorrect = true;
}
......@@ -156,7 +159,7 @@ const getCorrections = function(text) {
return;
}
checker.setDictionary(enabledDictionary);
checker.setDictionary(enabledDictionary, dictionariesPath);
const languageCorrections = checker.getCorrectionsForMisspelling(text);
if (languageCorrections.length > 0) {
allCorrections.push(languageCorrections);
......@@ -196,30 +199,38 @@ try {
availableDictionaries = checker.getAvailableDictionaries();
if (availableDictionaries.length > 0) {
languagesMenu = {
label: 'Spelling languages',
submenu: []
};
if (availableDictionaries.length === 0) {
dictionariesPath = path.join(remote.app.getAppPath(), '../dictionaries');
console.log('dictionariesPath', dictionariesPath);
availableDictionaries = [
'en_US',
'es_ES',
'pt_BR'
];
}
availableDictionaries.forEach((dictionary) => {
const menu = {
label: dictionary,
type: 'checkbox',
checked: enabledDictionaries.indexOf(dictionary) > -1,
click: function(menuItem) {
menu.checked = menuItem.checked;
if (menuItem.checked) {
enabledDictionaries.push(dictionary);
} else {
enabledDictionaries.splice(enabledDictionaries.indexOf(dictionary), 1);
}
saveEnabledDictionaries();
languagesMenu = {
label: 'Spelling languages',
submenu: []
};
availableDictionaries.forEach((dictionary) => {
const menu = {
label: dictionary,
type: 'checkbox',
checked: enabledDictionaries.indexOf(dictionary) > -1,
click: function(menuItem) {
menu.checked = menuItem.checked;
if (menuItem.checked) {
enabledDictionaries.push(dictionary);
} else {
enabledDictionaries.splice(enabledDictionaries.indexOf(dictionary), 1);
}
};
languagesMenu.submenu.push(menu);
});
}
saveEnabledDictionaries();
}
};
languagesMenu.submenu.push(menu);
});
webFrame.setSpellCheckProvider('', false, {
spellCheck: function(text) {
......
......@@ -21,7 +21,6 @@ var paths = {
'./lib/**',
'./spec.js',
'./quit.js',
'./dictionaries/**',
'./node_modules/**',
'./vendor/**',
'./images/**',
......
......@@ -56,6 +56,9 @@ var finalize = function () {
// Copy icon
projectDir.copy('app/images/linux/icon.png', readyAppDir.path('icon.png'));
// Copy dictionaries
projectDir.copy('dictionaries', readyAppDir.path('resources/dictionaries'));
return new Q();
};
......
......@@ -69,6 +69,9 @@ var finalize = function () {
// Copy icon
projectDir.copy('app/images/osx/icon.icns', finalAppDir.path('Contents/Resources/icon.icns'));
// Copy dictionaries
projectDir.copy('dictionaries', finalAppDir.path('Contents/Resources/dictionaries'));
return new Q();
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment