From d06d9fd653565ba4df4ca9feedde023fd0b95e1c Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Sat, 23 Jul 2022 00:10:05 +0300 Subject: [PATCH] [DE] Refactoring equation settings, add eq.settings to equation toolbar --- .../main/app/controller/DocumentHolder.js | 47 ++++- .../main/app/view/DocumentHolder.js | 180 ++++++------------ .../main/resources/less/toolbar.less | 5 +- 3 files changed, 109 insertions(+), 123 deletions(-) diff --git a/apps/documenteditor/main/app/controller/DocumentHolder.js b/apps/documenteditor/main/app/controller/DocumentHolder.js index e2d3d01c3..e11fed559 100644 --- a/apps/documenteditor/main/app/controller/DocumentHolder.js +++ b/apps/documenteditor/main/app/controller/DocumentHolder.js @@ -620,13 +620,18 @@ define([ } } var i = -1, - in_equation = false; + in_equation = false, + locked = false; while (++i < selectedElements.length) { - if (selectedElements[i].get_ObjectType() === Asc.c_oAscTypeSelectElement.Math) { + var type = selectedElements[i].get_ObjectType(); + if (type === Asc.c_oAscTypeSelectElement.Math) { in_equation = true; + } else if (type === Asc.c_oAscTypeSelectElement.Paragraph || type === Asc.c_oAscTypeSelectElement.Table || type === Asc.c_oAscTypeSelectElement.Header) { + var value = selectedElements[i].get_ObjectValue(); + value && (locked = locked || value.get_Locked()); } } - in_equation ? this.onEquationPanelShow() : this.onEquationPanelHide(); + in_equation ? this.onEquationPanelShow(locked) : this.onEquationPanelHide(); }, handleDocumentWheel: function(event) { @@ -2307,7 +2312,7 @@ define([ return false; }, - onEquationPanelShow: function() { + onEquationPanelShow: function(disabled) { var me = this, documentHolder = me.documentHolder, eqContainer = documentHolder.cmpEl.find('#equation-container'); @@ -2324,6 +2329,8 @@ define([ var style = 'margin-right: 8px;' + (i==0 ? 'margin-left: 5px;' : ''); eqStr += ''; } + eqStr += '
'; + eqStr += ''; eqStr += ''; eqContainer = $(eqStr); documentHolder.cmpEl.find('#id_main_view').append(eqContainer); @@ -2371,11 +2378,41 @@ define([ btn.menu.on('show:before', onShowBefore); me.equationBtns.push(btn); } + + me.equationSettingsBtn = new Common.UI.Button({ + parentEl: $('#id-document-holder-btn-equation-settings', documentHolder.cmpEl), + cls : 'btn-toolbar no-caret', + iconCls : 'toolbar__icon more-vertical', + hint : me.documentHolder.advancedEquationText, + menu : me.documentHolder.createEquationMenu('popuptbeqinput', 'tl-bl') + }); + me.equationSettingsBtn.menu.options.initMenu = function() { + var eq = me.api.asc_GetMathInputType(); + var menu = me.equationSettingsBtn.menu; + menu.items[0].setChecked(eq===Asc.c_oAscMathInputType.Unicode); + menu.items[1].setChecked(eq===Asc.c_oAscMathInputType.LaTeX); + menu.items[8].setChecked(me.api.asc_IsInlineMath()); + }; + me.equationSettingsBtn.menu.on('item:click', _.bind(me.convertEquation, me)); + me.equationSettingsBtn.menu.on('show:before', function(menu) { + menu.options.initMenu(); + }); } var showPoint = [(me._Width - eqContainer.outerWidth())/2, 0]; eqContainer.css({left: showPoint[0], top : showPoint[1]}); - eqContainer.show(); + if (eqContainer.is(':visible')) { + if (me.equationSettingsBtn.menu.isVisible()) { + me.equationSettingsBtn.menu.options.initMenu(); + me.equationSettingsBtn.menu.alignPosition(); + } + } else { + eqContainer.show(); + } + me.equationBtns.forEach(function(item){ + item && item.setDisabled(!!disabled); + }); + me.equationSettingsBtn.setDisabled(!!disabled); }, onEquationPanelHide: function() { diff --git a/apps/documenteditor/main/app/view/DocumentHolder.js b/apps/documenteditor/main/app/view/DocumentHolder.js index a3b0d2959..cf261f989 100644 --- a/apps/documenteditor/main/app/view/DocumentHolder.js +++ b/apps/documenteditor/main/app/view/DocumentHolder.js @@ -1145,64 +1145,7 @@ define([ me.menuTableEquation = new Common.UI.MenuItem({ caption : me.advancedEquationText, - menu : new Common.UI.Menu({ - cls: 'ppm-toolbar shifted-right', - menuAlign: 'tl-tr', - items : [ - new Common.UI.MenuItem({ - caption : me.unicodeText, - iconCls : 'menu__icon unicode', - checkable : true, - checkmark : false, - checked : false, - toggleGroup : 'popupparaeqinput', - type : 'input', - value : Asc.c_oAscMathInputType.Unicode - }), - new Common.UI.MenuItem({ - caption : me.latexText, - iconCls : 'menu__icon latex', - checkable : true, - checkmark : false, - checked : false, - toggleGroup : 'popupparaeqinput', - type : 'input', - value : Asc.c_oAscMathInputType.LaTeX - }), - { caption : '--' }, - new Common.UI.MenuItem({ - caption : me.currProfText, - iconCls : 'menu__icon professional-equation', - type : 'view', - value : {all: false, linear: false} - }), - new Common.UI.MenuItem({ - caption : me.currLinearText, - iconCls : 'menu__icon linear-equation', - type : 'view', - value : {all: false, linear: true} - }), - new Common.UI.MenuItem({ - caption : me.allProfText, - iconCls : 'menu__icon professional-equation', - type : 'view', - value : {all: true, linear: false} - }), - new Common.UI.MenuItem({ - caption : me.allLinearText, - iconCls : 'menu__icon linear-equation', - type : 'view', - value : {all: true, linear: true} - }), - { caption : '--' }, - new Common.UI.MenuItem({ - caption : me.eqToInlineText, - checkable : true, - checked : false, - type : 'mode' - }) - ] - }) + menu : me.createEquationMenu('popuptableeqinput', 'tl-tr') }); me.menuTableSelectText = new Common.UI.MenuItem({ @@ -1658,66 +1601,8 @@ define([ me.menuParagraphEquation = new Common.UI.MenuItem({ caption : me.advancedEquationText, - menu : new Common.UI.Menu({ - cls: 'ppm-toolbar shifted-right', - menuAlign: 'tl-tr', - items : [ - new Common.UI.MenuItem({ - caption : me.unicodeText, - iconCls : 'menu__icon unicode', - checkable : true, - checkmark : false, - checked : false, - toggleGroup : 'popupparaeqinput', - type : 'input', - value : Asc.c_oAscMathInputType.Unicode - }), - new Common.UI.MenuItem({ - caption : me.latexText, - iconCls : 'menu__icon latex', - checkable : true, - checkmark : false, - checked : false, - toggleGroup : 'popupparaeqinput', - type : 'input', - value : Asc.c_oAscMathInputType.LaTeX - }), - { caption : '--' }, - new Common.UI.MenuItem({ - caption : me.currProfText, - iconCls : 'menu__icon professional-equation', - type : 'view', - value : {all: false, linear: false} - }), - new Common.UI.MenuItem({ - caption : me.currLinearText, - iconCls : 'menu__icon linear-equation', - type : 'view', - value : {all: false, linear: true} - }), - new Common.UI.MenuItem({ - caption : me.allProfText, - iconCls : 'menu__icon professional-equation', - type : 'view', - value : {all: true, linear: false} - }), - new Common.UI.MenuItem({ - caption : me.allLinearText, - iconCls : 'menu__icon linear-equation', - type : 'view', - value : {all: true, linear: true} - }), - { caption : '--' }, - new Common.UI.MenuItem({ - caption : me.eqToInlineText, - checkable : true, - checked : false, - type : 'mode' - }) - ] - }) + menu : me.createEquationMenu('popupparaeqinput', 'tl-tr') }); - /** coauthoring begin **/ var menuCommentSeparatorPara = new Common.UI.MenuItem({ caption : '--' @@ -2978,6 +2863,67 @@ define([ } }, + createEquationMenu: function(toggleGroup, menuAlign) { + return new Common.UI.Menu({ + cls: 'ppm-toolbar shifted-right', + menuAlign: menuAlign, + items : [ + new Common.UI.MenuItem({ + caption : this.unicodeText, + iconCls : 'menu__icon unicode', + checkable : true, + checkmark : false, + checked : false, + toggleGroup : toggleGroup, + type : 'input', + value : Asc.c_oAscMathInputType.Unicode + }), + new Common.UI.MenuItem({ + caption : this.latexText, + iconCls : 'menu__icon latex', + checkable : true, + checkmark : false, + checked : false, + toggleGroup : toggleGroup, + type : 'input', + value : Asc.c_oAscMathInputType.LaTeX + }), + { caption : '--' }, + new Common.UI.MenuItem({ + caption : this.currProfText, + iconCls : 'menu__icon professional-equation', + type : 'view', + value : {all: false, linear: false} + }), + new Common.UI.MenuItem({ + caption : this.currLinearText, + iconCls : 'menu__icon linear-equation', + type : 'view', + value : {all: false, linear: true} + }), + new Common.UI.MenuItem({ + caption : this.allProfText, + iconCls : 'menu__icon professional-equation', + type : 'view', + value : {all: true, linear: false} + }), + new Common.UI.MenuItem({ + caption : this.allLinearText, + iconCls : 'menu__icon linear-equation', + type : 'view', + value : {all: true, linear: true} + }), + { caption : '--' }, + new Common.UI.MenuItem({ + caption : this.eqToInlineText, + checkable : true, + checked : false, + type : 'mode' + }) + ] + }); + }, + focus: function() { var me = this; _.defer(function(){ me.cmpEl.focus(); }, 50); diff --git a/apps/documenteditor/main/resources/less/toolbar.less b/apps/documenteditor/main/resources/less/toolbar.less index 8036006a2..4cd966832 100644 --- a/apps/documenteditor/main/resources/less/toolbar.less +++ b/apps/documenteditor/main/resources/less/toolbar.less @@ -174,7 +174,10 @@ } #equation-container { - padding: 2px; + padding: 4px; + .separator { + height: 20px; + } } .dropdown-menu.list-settings-level {