diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 299b873f9..dcf19017d 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -93,7 +93,8 @@ define([ initialize: function() { this.addListeners({ 'FileMenu': { - 'settings:apply': _.bind(this.applySettings, this) + 'settings:apply': _.bind(this.applySettings, this), + 'spellcheck:apply': _.bind(this.applySpellcheckSettings, this) }, 'Common.Views.ReviewChanges': { 'settings:apply': _.bind(this.applySettings, this) @@ -685,6 +686,15 @@ define([ Common.Utils.InternalSettings.set("sse-settings-coauthmode", me._state.fastCoauth); /** coauthoring end **/ + /** spellcheck settings begin **/ + var ignoreUppercase = Common.localStorage.getBool("sse-spellcheck-ignore-uppercase-words", true); + Common.Utils.InternalSettings.set("sse-spellcheck-ignore-uppercase-words", ignoreUppercase); + this.api.asc_ignoreUppercase(ignoreUppercase); + var ignoreNumbers = Common.localStorage.getBool("sse-spellcheck-ignore-numbers-words", true); + Common.Utils.InternalSettings.set("sse-spellcheck-ignore-numbers-words", ignoreNumbers); + this.api.asc_ignoreUppercase(ignoreNumbers); + /** spellcheck settings end **/ + me.api.asc_registerCallback('asc_onStartAction', _.bind(me.onLongActionBegin, me)); me.api.asc_registerCallback('asc_onConfirmAction', _.bind(me.onConfirmAction, me)); me.api.asc_registerCallback('asc_onActiveSheetChanged', _.bind(me.onActiveSheetChanged, me)); @@ -2040,6 +2050,17 @@ define([ } }, + applySpellcheckSettings: function() { + if (this.appOptions.isEdit && !this.appOptions.isOffline && this.appOptions.canCoAuthoring && this.api) { + var value = Common.localStorage.getBool("sse-spellcheck-ignore-uppercase-words"); + this.api.asc_ignoreUppercase(value); + value = Common.localStorage.getBool("sse-spellcheck-ignore-numbers-words"); + this.api.asc_ignoreNumbers(value); + value = parseInt(Common.localStorage.getItem("sse-spellcheck-locale")); + this.api.asc_setDefaultLanguage(value); + } + }, + onDocumentName: function(name) { this.headerView.setDocumentCaption(name); this.updateWindowTitle(this.api.asc_isDocumentModified(), true); diff --git a/apps/spreadsheeteditor/main/app/controller/Spellcheck.js b/apps/spreadsheeteditor/main/app/controller/Spellcheck.js index 0a58ef1b3..f6e61d6ec 100644 --- a/apps/spreadsheeteditor/main/app/controller/Spellcheck.js +++ b/apps/spreadsheeteditor/main/app/controller/Spellcheck.js @@ -55,6 +55,7 @@ define([ 'Spellcheck': { 'show': function() { me._initSettings && me.loadLanguages(); + me.updateLanguages(); me.onClickNext(); }, 'hide': function() { @@ -124,20 +125,16 @@ define([ }, loadLanguages: function () { - var value = Common.localStorage.getItem("sse-spellcheck-locale"); - if (value) - value = parseInt(value); - else - value = this.mode.lang ? parseInt(Common.util.LanguageInfo.getLocalLanguageCode(this.mode.lang)) : 0x0409; + var me = this; + Common.Utils.InternalSettings.set("sse-spellcheck-locale", Common.localStorage.getItem("sse-spellcheck-locale")); - var combo = this.panelSpellcheck.cmbDictionaryLanguage; if (this.languages && this.languages.length>0) { - var langs = [], info, - allLangs = Common.util.LanguageInfo.getLanguages(); + var langs = [], info; + this.allLangs = Common.util.LanguageInfo.getLanguages(); this.languages.forEach(function (code) { code = parseInt(code); - if (allLangs.hasOwnProperty(code)) { - info = allLangs[code]; + if (me.allLangs.hasOwnProperty(code)) { + info = me.allLangs[code]; langs.push({ displayValue: info[1], shortName: info[0], @@ -151,13 +148,30 @@ define([ return 0; }); this.langs = langs; - combo.setData(langs); + } else { + this.langs = undefined; + } + this._initSettings = false; + + return [this.allLangs, this.langs]; + }, + + updateLanguages: function() { + var sessionValue = Common.Utils.InternalSettings.get("sse-spellcheck-locale"), + value; + if (sessionValue) + value = parseInt(sessionValue); + else + value = this.mode.lang ? parseInt(Common.util.LanguageInfo.getLocalLanguageCode(this.mode.lang)) : 0x0409; + var combo = this.panelSpellcheck.cmbDictionaryLanguage; + if (this.langs && this.langs.length>0) { + combo.setData(this.langs); var item = combo.store.findWhere({value: value}); - if (!item && allLangs[value]) { - value = allLangs[value][0].split(/[\-\_]/)[0]; + if (!item && this.allLangs[value]) { + value = this.allLangs[value][0].split(/[\-\_]/)[0]; item = combo.store.find(function(model){ - return model.get('shortName').indexOf(value)==0; - }); + return model.get('shortName').indexOf(value)==0; + }); } combo.setValue(item ? item.get('value') : langs[0].value); value = combo.getValue(); @@ -165,18 +179,21 @@ define([ combo.setValue(Common.util.LanguageInfo.getLocalLanguageName(value)[1]); combo.setDisabled(true); } - this.langValue = value; - this.api.asc_setDefaultLanguage(value); - this._initSettings = false; - - return [this.langs, this.langValue]; + if (this.api) { + this.api.asc_setDefaultLanguage(value); + if (value !== sessionValue) { + Common.Utils.InternalSettings.set("sse-spellcheck-locale", value); + } + } }, onSelectLanguage: function (combo, record) { var lang = record.value; if (this.api && lang) { this.api.asc_setDefaultLanguage(lang); - Common.localStorage.setItem("sse-spellcheck-locale", this.panelSpellcheck.cmbDictionaryLanguage.getValue()); + var value = this.panelSpellcheck.cmbDictionaryLanguage.getValue(); + Common.localStorage.setItem("sse-spellcheck-locale", value); + Common.Utils.InternalSettings.set("sse-spellcheck-locale", value); } Common.NotificationCenter.trigger('edit:complete', this, {restorefocus:true}); }, @@ -250,7 +267,7 @@ define([ onApiEditCell: function(state) { if (state == Asc.c_oAscCellEditorState.editEnd) { this.panelSpellcheck.buttonNext.setDisabled(!this.panelSpellcheck.lblComplete.hasClass('hidden')); - this.panelSpellcheck.cmbDictionaryLanguage.setDisabled(false); + this.panelSpellcheck.cmbDictionaryLanguage.setDisabled((this.languages && this.languages.length > 0) ? false : true); } else { this.panelSpellcheck.buttonNext.setDisabled(true); this.panelSpellcheck.currentWord.setDisabled(true); diff --git a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js index 3810c812f..3fd6c8cfe 100644 --- a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js +++ b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js @@ -232,6 +232,7 @@ define([ if (!this.mode.canPrint) this.viewSettingsPicker.store.pop(); this.generalSettings && this.generalSettings.setMode(this.mode); + this.spellcheckSettings && this.spellcheckSettings.setMode(this.mode); }, setApi: function(api) { @@ -970,6 +971,11 @@ define([ '', '
', '', + '', + '', + '', + '', + '', '' ].join('')), @@ -986,13 +992,11 @@ define([ this.chIgnoreUppercase = new Common.UI.CheckBox({ el: $markup.findById('#fms-chb-ignore-uppercase-words'), labelText: this.strIgnoreWordsInUPPERCASE - }).on('change', function(field, newValue, oldValue, eOpts){ }); this.chIgnoreNumbers = new Common.UI.CheckBox({ el: $markup.findById('#fms-chb-ignore-numbers-words'), labelText: this.strIgnoreWordsWithNumbers - }).on('change', function(field, newValue, oldValue, eOpts){ }); this.cmbDictionaryLanguage = new Common.UI.ComboBox({ @@ -1003,7 +1007,7 @@ define([ }); this.btnApply = new Common.UI.Button({ - el: $markup.findById('#fms-btn-apply') + el: $markup.findById('#fms-spellcheck-btn-apply') }); this.btnApply.on('click', _.bind(this.applySettings, this)); @@ -1035,25 +1039,60 @@ define([ }, updateSettings: function() { - var array = SSE.getController('Spellcheck').loadLanguages(), - lang = array[0], - value = array[1]; - if (lang) { + var lang = SSE.getController('Spellcheck').loadLanguages(), + allLangs = lang[0], + lang = lang[1]; + var sessionValue = Common.Utils.InternalSettings.get("sse-spellcheck-locale"), + value; + if (sessionValue) + value = parseInt(sessionValue); + else + value = this.mode.lang ? parseInt(Common.util.LanguageInfo.getLocalLanguageCode(this.mode.lang)) : 0x0409; + if (lang && lang.length > 0) { this.cmbDictionaryLanguage.setData(lang); - this.cmbDictionaryLanguage.setValue(value); + var item = this.cmbDictionaryLanguage.store.findWhere({value: value}); + if (!item && allLangs[value]) { + value = allLangs[value][0].split(/[\-\_]/)[0]; + item = combo.store.find(function(model){ + return model.get('shortName').indexOf(value)==0; + }); + } + this.cmbDictionaryLanguage.setValue(item ? item.get('value') : langs[0].value); + value = this.cmbDictionaryLanguage.getValue(); + if (value !== sessionValue) { + Common.Utils.InternalSettings.set("sse-spellcheck-locale", value); + } } else { this.cmbDictionaryLanguage.setValue(Common.util.LanguageInfo.getLocalLanguageName(value)[1]); this.cmbDictionaryLanguage.setDisabled(true); } + + this.chIgnoreUppercase.setValue(Common.Utils.InternalSettings.get("sse-spellcheck-ignore-uppercase-words")); + this.chIgnoreNumbers.setValue(Common.Utils.InternalSettings.get("sse-spellcheck-ignore-numbers-words")); }, applySettings: function() { + var value = this.chIgnoreUppercase.isChecked(); + Common.localStorage.setBool("sse-spellcheck-ignore-uppercase-words", value); + Common.Utils.InternalSettings.set("sse-spellcheck-ignore-uppercase-words", value); + value = this.chIgnoreNumbers.isChecked(); + Common.localStorage.setBool("sse-spellcheck-ignore-numbers-words", value); + Common.Utils.InternalSettings.set("sse-spellcheck-ignore-numbers-words", value); + value = this.cmbDictionaryLanguage.getValue(); + Common.localStorage.setItem("sse-spellcheck-locale", value); + Common.Utils.InternalSettings.set("sse-spellcheck-locale", value); + + Common.localStorage.save(); + if (this.menu) { + this.menu.fireEvent('spellcheck:apply', [this.menu]); + } }, strIgnoreWordsInUPPERCASE: 'Ignore words in UPPERCASE', strIgnoreWordsWithNumbers: 'Ignore words with numbers', - strDictionaryLanguage: 'Dictionary language' + strDictionaryLanguage: 'Dictionary language', + okButtonText: 'Apply' }, SSE.Views.FileMenuPanels.MainSpellCheckSettings || {})); diff --git a/apps/spreadsheeteditor/main/locale/en.json b/apps/spreadsheeteditor/main/locale/en.json index ff5e1a54f..d944c87c9 100644 --- a/apps/spreadsheeteditor/main/locale/en.json +++ b/apps/spreadsheeteditor/main/locale/en.json @@ -1591,6 +1591,10 @@ "SSE.Views.FileMenuPanels.MainSettingsGeneral.txtPt": "Point", "SSE.Views.FileMenuPanels.MainSettingsGeneral.txtRu": "Russian", "SSE.Views.FileMenuPanels.MainSettingsGeneral.txtWin": "as Windows", + "SSE.Views.FileMenuPanels.MainSpellCheckSettings.strIgnoreWordsInUPPERCASE": "Ignore words in UPPERCASE", + "SSE.Views.FileMenuPanels.MainSpellCheckSettings.strIgnoreWordsWithNumbers": "Ignore words with numbers", + "SSE.Views.FileMenuPanels.MainSpellCheckSettings.strDictionaryLanguage": "Dictionary language", + "SSE.Views.FileMenuPanels.MainSpellCheckSettings.okButtonText": "Apply", "SSE.Views.FileMenuPanels.ProtectDoc.notcriticalErrorTitle": "Warning", "SSE.Views.FileMenuPanels.ProtectDoc.strEncrypt": "With password", "SSE.Views.FileMenuPanels.ProtectDoc.strProtect": "Protect Spreadsheet",