From e47e9b38c8c9e48cf931ae6cbdae48622a178c20 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 11 Aug 2020 14:35:15 +0300 Subject: [PATCH] Proofing: add list with recognized functions --- .../lib/template/AutoCorrectDialog.template | 24 ++ .../common/main/lib/view/AutoCorrectDialog.js | 257 +++++++++++++++++- .../main/app/controller/Main.js | 9 +- .../main/app/view/FileMenuPanels.js | 3 + .../main/app/controller/Main.js | 9 +- .../main/app/view/FileMenuPanels.js | 3 + .../main/app/controller/Main.js | 9 +- .../main/app/view/FileMenuPanels.js | 3 + 8 files changed, 310 insertions(+), 7 deletions(-) diff --git a/apps/common/main/lib/template/AutoCorrectDialog.template b/apps/common/main/lib/template/AutoCorrectDialog.template index f2bb6aa9a..e7ec47cf3 100644 --- a/apps/common/main/lib/template/AutoCorrectDialog.template +++ b/apps/common/main/lib/template/AutoCorrectDialog.template @@ -35,5 +35,29 @@
+ + + + + + + + + + + + + +
+ +
+
+
+
+
+ + + +
diff --git a/apps/common/main/lib/view/AutoCorrectDialog.js b/apps/common/main/lib/view/AutoCorrectDialog.js index 0aed09e80..c46fa49e6 100644 --- a/apps/common/main/lib/view/AutoCorrectDialog.js +++ b/apps/common/main/lib/view/AutoCorrectDialog.js @@ -61,8 +61,8 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template', title: this.textTitle, storageName: this.appPrefix + 'autocorrect-dialog-category', items: [ - {panelId: 'id-autocorrect-dialog-settings-math', panelCaption: this.textMathCorrect}, - {panelId: 'id-autocorrect-dialog-settings-recognized', panelCaption: this.textLock} + {panelId: 'id-autocorrect-dialog-settings-math', panelCaption: this.textMathCorrect}, + {panelId: 'id-autocorrect-dialog-settings-recognized', panelCaption: this.textRecognized} ], template: [ '
', @@ -82,6 +82,7 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template', }, options || {}); this.mathStore = this.options.mathStore || new Common.UI.DataViewStore(); + this.functionsStore = this.options.functionsStore || new Common.UI.DataViewStore(); this.api = this.options.api; this.handler = this.options.handler; @@ -91,6 +92,12 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template', value = Common.Utils.InternalSettings.get(path + "-rem"); this.arrRem = value ? JSON.parse(value) : []; + path = this.appPrefix + "settings-rec-functions"; + value = Common.Utils.InternalSettings.get(path + "-add"); + this.arrAddRec = value ? JSON.parse(value) : []; + value = Common.Utils.InternalSettings.get(path + "-rem"); + this.arrRemRec = value ? JSON.parse(value) : []; + Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options); }, @@ -100,6 +107,7 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template', var $window = this.getChild(); var me = this; + // Math correct this.chReplaceType = new Common.UI.CheckBox({ el: $window.findById('#auto-correct-chb-replace-type'), labelText: this.textReplaceType, @@ -113,7 +121,6 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template', this.onInitList(); - // special this.mathList = new Common.UI.ListView({ el: $window.find('#auto-correct-math-list'), store: new Common.UI.DataViewStore(this.mathStore.slice(0, 9)), @@ -194,7 +201,78 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template', }); this.btnDelete.on('click', _.bind(this.onDelete, this, false)); + // Recognized functions + this.onInitRecList(); + + this.mathRecList = new Common.UI.ListView({ + el: $window.find('#auto-correct-recognized-list'), + store: new Common.UI.DataViewStore(this.functionsStore.slice(0, 9)), + simpleAddMode: false, + template: _.template(['
'].join('')), + itemTemplate: _.template([ + '
<%= value %>
' + ].join('')), + scrollAlwaysVisible: true + }); + this.mathRecList.on('item:select', _.bind(this.onSelectRecItem, this)); + + this.inputRecFind = new Common.UI.InputField({ + el : $window.find('#auto-correct-rec-find'), + allowBlank : true, + validateOnChange : true, + validation : function () { return true; } + }).on ('changing', function (input, value) { + var _selectedItem; + if (value.length) { + var store = me.mathRecList.store; + _selectedItem = store.find(function(item) { + if ( item.get('value').indexOf(value) == 0) { + return true; + } + }); + if (_selectedItem) { + me.mathRecList.scrollToRecord(_selectedItem, true); + if (_selectedItem.get('value') == value) + me.mathRecList.selectRecord(_selectedItem, true); + else + _selectedItem = null; + } + } + (!_selectedItem) && me.mathRecList.deselectAll(); + me.updateRecControls(_selectedItem); + }); + + this.inputRecFind.cmpEl.find('input').on('keydown', function(event){ + if (event.key == 'ArrowDown') { + var _selectedItem = me.mathRecList.getSelectedRec() || me.mathRecList.store.at(0); + if (_selectedItem) { + me.mathRecList.selectRecord(_selectedItem); + me.mathRecList.scrollToRecord(_selectedItem); + } + _.delay(function(){ + me.mathRecList.cmpEl.find('.listview').focus(); + },10); + + } + }); + + this.btnResetRec = new Common.UI.Button({ + el: $('#auto-correct-btn-rec-reset') + }); + this.btnResetRec.on('click', _.bind(this.onResetRecToDefault, this)); + + this.btnAddRec = new Common.UI.Button({ + el: $('#auto-correct-btn-rec-edit') + }); + this.btnAddRec.on('click', _.bind(this.onAddRec, this, false)); + + this.btnDeleteRec = new Common.UI.Button({ + el: $('#auto-correct-btn-rec-delete') + }); + this.btnDeleteRec.on('click', _.bind(this.onDeleteRec, this, false)); + this.btnsCategory[0].on('click', _.bind(this.onMathCategoryClick, this, false)); + this.btnsCategory[1].on('click', _.bind(this.onRecCategoryClick, this, false)); this.afterRender(); }, @@ -244,11 +322,13 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template', var value = this.getActiveCategory(); if (value==0) this.onMathCategoryClick(true); + else if (value==1) this.onRecCategoryClick(true); }, close: function() { Common.Views.AdvancedSettingsWindow.prototype.close.apply(this, arguments); this.mathList && this.mathList.deselectAll(); + this.mathRecList && this.mathRecList.deselectAll(); }, onMathCategoryClick: function(delay) { @@ -433,6 +513,171 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template', this.updateControls(); }, + onInitRecList: function() { + if (this.functionsStore.length>0) return; + + this.functionsStore.comparator = function(item1, item2) { + var n1 = item1.get('value').toLowerCase(), + n2 = item2.get('value').toLowerCase(); + if (n1==n2) return 0; + return (n1-1 + }); + }); + + var dataAdd = []; + _.each(arrAdd, function(item, index){ + if (_.findIndex(data, {value: item})<0) { + dataAdd.push({ + value: item, + defaultValue: false, + defaultDisabled: false + }); + } + }); + this.functionsStore.reset(data.concat(dataAdd)); + this.updateRecControls(); + }, + + onResetRecToDefault: function() { + Common.UI.warning({ + maxwidth: 500, + msg: this.textWarnResetRec, + buttons: ['yes', 'no'], + primary: 'yes', + callback: _.bind(function(btn, dontshow){ + if (btn == 'yes') { + this.api.asc_resetToDefaultAutoCorrectMathSymbols(); + this.onResetRecList(); + } + }, this) + }); + }, + + onResetRecList: function() { + // remove storage data + var path = this.appPrefix + "settings-rec-functions"; + var val = JSON.stringify([]); + Common.Utils.InternalSettings.set(path + "-add", val); + Common.localStorage.setItem(path + "-add", val); + Common.Utils.InternalSettings.set(path + "-rem", val); + Common.localStorage.setItem(path + "-rem", val); + this.arrAddRec = []; + this.arrRemRec = []; + + this.functionsStore.remove(this.functionsStore.findWhere({defaultValue: false})); + this.functionsStore.each(function(item, index){ + item.set('defaultDisabled', false); + }); + this.mathRecList.deselectAll(); + if (this.mathRecList.scroller) { + this.mathRecList.scroller.update(); + this.mathRecList.scroller.scrollTop(0); + } + this.updateRecControls(); + }, + + onRecCategoryClick: function(delay) { + var me = this; + _.delay(function(){ + $('input', me.inputRecFind.cmpEl).select().focus(); + },delay ? 50 : 0); + + if (me.mathRecList.store.length < me.functionsStore.length) { + _.delay(function(){ + me.mathRecList.setStore(me.functionsStore); + me.mathRecList.onResetItems(); + },delay ? 100 : 10); + } + }, + + onDeleteRec: function() { + var rec = this.mathRecList.getSelectedRec(); + if (rec) { + if (rec.get('defaultValue')) { + var path = this.appPrefix + "settings-rec-functions-rem"; + var disabled = !rec.get('defaultDisabled'); + rec.set('defaultDisabled', disabled); + if (disabled) + this.arrRemRec.push(rec.get('value')); + else + this.arrRemRec.splice(this.arrRemRec.indexOf(rec.get('value')), 1); + var val = JSON.stringify(this.arrRemRec); + Common.Utils.InternalSettings.set(path, val); + Common.localStorage.setItem(path, val); + this.btnDeleteRec.setCaption(disabled ? this.textRestore : this.textDelete); + } else { + this.functionsStore.remove(rec); + } + this.updateRecControls(); + this.api.asc_deleteFromAutoCorrectMathFunctions(rec.get('value')); + } + }, + + onAddRec: function() { + var rec = this.mathRecList.getSelectedRec(), + me = this, + applySettings = function(record) { + var path = me.appPrefix + "settings-rec-functions-add"; + var val = JSON.stringify(me.arrAddRec); + Common.Utils.InternalSettings.set(path, val); + Common.localStorage.setItem(path, val); + me.api.asc_AddFromAutoCorrectMathFunctions(record.get('value')); + me.mathRecList.selectRecord(record); + me.mathRecList.scrollToRecord(record); + }; + if (!rec) { + rec = this.functionsStore.findWhere({value: this.inputRecFind.getValue()}) + } + if (!rec) { + if (/^[A-Z]+$/i.test(this.inputRecFind.getValue())) { + rec = this.functionsStore.add({ + value: this.inputRecFind.getValue(), + defaultValue: false, + defaultDisabled: false + }); + this.arrAddRec.push(rec.get('value')); + applySettings(rec); + } else + Common.UI.warning({ + maxwidth: 500, + msg: this.textWarnAddRec + }); + } else { + me.mathRecList.selectRecord(rec); + me.mathRecList.scrollToRecord(rec); + } + }, + + onSelectRecItem: function(lisvView, itemView, record) { + if (record) { + this.inputRecFind.setValue(record.get('value')); + } + this.updateRecControls(record); + }, + + updateRecControls: function(rec) { + if (!this.mathRecList) return; + + rec = rec || this.mathRecList.getSelectedRec(); + var value = this.inputRecFind.getValue(); + + this.btnDeleteRec.setCaption(rec && rec.get('defaultDisabled') ? this.textRestore : this.textDelete); + this.btnDeleteRec.setDisabled(!rec); + this.btnAddRec.setDisabled(!!rec || !value); + }, + textTitle: 'AutoCorrect', textMathCorrect: 'Math AutoCorrect', textReplace: 'Replace', @@ -445,7 +690,11 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template', textReplaceType: 'Replace text as you type', warnReset: 'Any autocorrect you added will be removed and the changed ones will be restored to their original values. Do you want to continue?', warnReplace: 'The autocorrect entry for %1 already exists. Do you want to replace it?', - warnRestore: 'The autocorrect entry for %1 will be reset to its original value. Do you want to continue?' + warnRestore: 'The autocorrect entry for %1 will be reset to its original value. Do you want to continue?', + textRecognized: 'Recognized Functions', + textRecognizedDesc: 'The following expressions are recognized math expressions. They will not be automatically italicized.', + textWarnAddRec: 'Recognized functions must contain only the letters A through Z, uppercase or lowercase.', + textWarnResetRec: 'Any expression you added will be removed and the removed ones will be restored. Do you want to continue?' }, Common.Views.AutoCorrectDialog || {})) }); diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 7a258277c..b917ed4fc 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -1065,9 +1065,16 @@ define([ var arrRem = value ? JSON.parse(value) : []; value = Common.localStorage.getBool("de-settings-math-correct-replace-type", true); // replace on type Common.Utils.InternalSettings.set("de-settings-math-correct-replace-type", value); - me.api.asc_refreshOnStartAutoCorrectMathSymbols(arrRem, arrAdd, value); + value = Common.localStorage.getItem("de-settings-rec-functions-add"); + Common.Utils.InternalSettings.set("de-settings-rec-functions-add", value); + arrAdd = value ? JSON.parse(value) : []; + value = Common.localStorage.getItem("de-settings-rec-functions-rem"); + Common.Utils.InternalSettings.set("de-settings-rec-functions-rem", value); + arrRem = value ? JSON.parse(value) : []; + me.api.asc_refreshOnStartAutoCorrectMathFunctions(arrRem, arrAdd); + if (me.needToUpdateVersion) Common.NotificationCenter.trigger('api:disconnect'); var timer_sl = setInterval(function(){ diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index 7df74a918..172dc2174 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -633,8 +633,11 @@ define([ autoCorrect: function() { if (!this._mathCorrect) this._mathCorrect = new Common.UI.DataViewStore(); + if (!this._funcCorrect) + this._funcCorrect = new Common.UI.DataViewStore(); (new Common.Views.AutoCorrectDialog({ mathStore: this._mathCorrect, + functionsStore: this._funcCorrect, api: this.api })).show(); }, diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index cac7e7d86..49ed377b8 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -791,9 +791,16 @@ define([ var arrRem = value ? JSON.parse(value) : []; value = Common.localStorage.getBool("pe-settings-math-correct-replace-type", true); // replace on type Common.Utils.InternalSettings.set("pe-settings-math-correct-replace-type", value); - me.api.asc_refreshOnStartAutoCorrectMathSymbols(arrRem, arrAdd, value); + value = Common.localStorage.getItem("pe-settings-rec-functions-add"); + Common.Utils.InternalSettings.set("pe-settings-rec-functions-add", value); + arrAdd = value ? JSON.parse(value) : []; + value = Common.localStorage.getItem("pe-settings-rec-functions-rem"); + Common.Utils.InternalSettings.set("pe-settings-rec-functions-rem", value); + arrRem = value ? JSON.parse(value) : []; + me.api.asc_refreshOnStartAutoCorrectMathFunctions(arrRem, arrAdd); + if (me.needToUpdateVersion) Common.NotificationCenter.trigger('api:disconnect'); var timer_sl = setInterval(function(){ diff --git a/apps/presentationeditor/main/app/view/FileMenuPanels.js b/apps/presentationeditor/main/app/view/FileMenuPanels.js index 4f96554f3..f014e711d 100644 --- a/apps/presentationeditor/main/app/view/FileMenuPanels.js +++ b/apps/presentationeditor/main/app/view/FileMenuPanels.js @@ -545,8 +545,11 @@ define([ autoCorrect: function() { if (!this._mathCorrect) this._mathCorrect = new Common.UI.DataViewStore(); + if (!this._funcCorrect) + this._funcCorrect = new Common.UI.DataViewStore(); (new Common.Views.AutoCorrectDialog({ mathStore: this._mathCorrect, + functionsStore: this._funcCorrect, api: this.api })).show(); }, diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 60801c928..a4a50d41c 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -829,9 +829,16 @@ define([ var arrRem = value ? JSON.parse(value) : []; value = Common.localStorage.getBool("sse-settings-math-correct-replace-type", true); // replace on type Common.Utils.InternalSettings.set("sse-settings-math-correct-replace-type", value); - me.api.asc_refreshOnStartAutoCorrectMathSymbols(arrRem, arrAdd, value); + value = Common.localStorage.getItem("sse-settings-rec-functions-add"); + Common.Utils.InternalSettings.set("sse-settings-rec-functions-add", value); + arrAdd = value ? JSON.parse(value) : []; + value = Common.localStorage.getItem("sse-settings-rec-functions-rem"); + Common.Utils.InternalSettings.set("sse-settings-rec-functions-rem", value); + arrRem = value ? JSON.parse(value) : []; + me.api.asc_refreshOnStartAutoCorrectMathFunctions(arrRem, arrAdd); + if (me.needToUpdateVersion) { Common.NotificationCenter.trigger('api:disconnect'); toolbarController.onApiCoAuthoringDisconnect(); diff --git a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js index 3d5845828..a636d0171 100644 --- a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js +++ b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js @@ -1431,8 +1431,11 @@ define([ autoCorrect: function() { if (!this._mathCorrect) this._mathCorrect = new Common.UI.DataViewStore(); + if (!this._funcCorrect) + this._funcCorrect = new Common.UI.DataViewStore(); (new Common.Views.AutoCorrectDialog({ mathStore: this._mathCorrect, + functionsStore: this._funcCorrect, api: this.api })).show(); },