From 98684a0c8b18b4cf1a699eff49a66e5f42035a5a Mon Sep 17 00:00:00 2001
From: Julia Radzhabova <julia.radzhabova@onlyoffice.com>
Date: Tue, 1 Nov 2022 22:48:39 +0300
Subject: [PATCH] [SSE] Add equation settings

---
 .../main/app/controller/DocumentHolder.js     | 37 +++++++---
 .../main/app/view/DocumentHolder.js           | 71 ++++++++++++++++++-
 2 files changed, 95 insertions(+), 13 deletions(-)

diff --git a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js
index 1519d4903..30fb0c34d 100644
--- a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js
+++ b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js
@@ -268,6 +268,7 @@ define([
                 view.menuImgMacro.on('click',                       _.bind(me.onImgMacro, me));
                 view.menuImgEditPoints.on('click',                  _.bind(me.onImgEditPoints, me));
                 view.pmiGetRangeList.on('click',                    _.bind(me.onGetLink, me));
+                view.menuParagraphEquation.menu.on('item:click', _.bind(me.convertEquation, me));
 
                 if (!me.permissions.isEditMailMerge && !me.permissions.isEditDiagram && !me.permissions.isEditOle) {
                     var oleEditor = me.getApplication().getController('Common.Controllers.ExternalOleEditor').getView('Common.Views.ExternalOleEditor');
@@ -2284,6 +2285,14 @@ define([
                 } else
                     this.clearEquationMenu(4);
 
+                documentHolder.menuParagraphEquation.setVisible(isEquation);
+                documentHolder.menuParagraphEquation.setDisabled(isObjLocked);
+                if (isEquation) {
+                    var eq = this.api.asc_GetMathInputType();
+                    documentHolder.menuParagraphEquation.menu.items[0].setChecked(eq===Asc.c_oAscMathInputType.Unicode);
+                    documentHolder.menuParagraphEquation.menu.items[1].setChecked(eq===Asc.c_oAscMathInputType.LaTeX);
+                }
+
                 if (showMenu) this.showPopupMenu(documentHolder.textInShapeMenu, {}, event);
 
                 documentHolder.menuParagraphBullets.setDisabled(isSmartArt || isSmartArtInternal);
@@ -4311,8 +4320,8 @@ define([
                     var style = 'margin-right: 8px;' + (i==0 ? 'margin-left: 5px;' : '');
                     eqStr += '<span id="id-document-holder-btn-equation-' + i + '" style="' + style +'"></span>';
                 }
-                // eqStr += '<div class="separator"></div>';
-                // eqStr += '<span id="id-document-holder-btn-equation-settings" style="margin-right: 5px; margin-left: 8px;"></span>';
+                eqStr += '<div class="separator"></div>';
+                eqStr += '<span id="id-document-holder-btn-equation-settings" style="margin-right: 5px; margin-left: 8px;"></span>';
                 eqStr += '</div>';
                 eqContainer = $(eqStr);
                 documentHolder.cmpEl.append(eqContainer);
@@ -4349,7 +4358,7 @@ define([
                         menu        : new Common.UI.Menu({
                             cls: 'menu-shapes',
                             value: i,
-                            // restoreHeight: equationGroup.get('groupHeight') ? parseInt(equationGroup.get('groupHeight')) : true,
+                            restoreHeight: equationGroup.get('groupHeight') ? parseInt(equationGroup.get('groupHeight')) : true,
                             items: [
                                 { template: _.template('<div id="id-document-holder-btn-equation-menu-' + i +
                                         '" class="menu-shape" style="width:' + (equationGroup.get('groupWidth') + 8) + 'px; ' +
@@ -4361,7 +4370,6 @@ define([
                     me.equationBtns.push(btn);
                 }
 
-                /*
                 me.equationSettingsBtn = new Common.UI.Button({
                     parentEl: $('#id-document-holder-btn-equation-settings', documentHolder.cmpEl),
                     cls         : 'btn-toolbar no-caret',
@@ -4374,13 +4382,11 @@ define([
                     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();
                 });
-                */
             }
 
             if (!me.tooltips.coauth.XY)
@@ -4389,17 +4395,17 @@ define([
             var showPoint = [(me.tooltips.coauth.apiWidth - eqContainer.outerWidth())/2, 0];
             eqContainer.css({left: showPoint[0], top : showPoint[1]});
             if (eqContainer.is(':visible')) {
-                // if (me.equationSettingsBtn.menu.isVisible()) {
-                //     me.equationSettingsBtn.menu.options.initMenu();
-                //     me.equationSettingsBtn.menu.alignPosition();
-                // }
+                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);
+            me.equationSettingsBtn.setDisabled(!!disabled);
         },
 
         onEquationPanelHide: function() {
@@ -4409,6 +4415,15 @@ define([
             }
         },
 
+        convertEquation: function(menu, item, e) {
+            if (this.api) {
+                if (item.options.type=='input')
+                    this.api.asc_SetMathInputType(item.value);
+                else if (item.options.type=='view')
+                    this.api.asc_ConvertMathView(item.value.linear, item.value.all);
+            }
+        },
+
         getUserName: function(id){
             var usersStore = SSE.getCollection('Common.Collections.Users');
             if (usersStore){
diff --git a/apps/spreadsheeteditor/main/app/view/DocumentHolder.js b/apps/spreadsheeteditor/main/app/view/DocumentHolder.js
index a1474e39e..90d3f9e3f 100644
--- a/apps/spreadsheeteditor/main/app/view/DocumentHolder.js
+++ b/apps/spreadsheeteditor/main/app/view/DocumentHolder.js
@@ -1074,6 +1074,11 @@ define([
                 value       : 'paste'
             });
 
+            me.menuParagraphEquation = new Common.UI.MenuItem({
+                caption     : me.advancedEquationText,
+                menu        : me.createEquationMenu('popupparaeqinput', 'tl-tr')
+            });
+
             this.textInShapeMenu = new Common.UI.Menu({
                 cls: 'shifted-right',
                 items: [
@@ -1087,7 +1092,8 @@ define([
                     me.menuAddHyperlinkShape,
                     me.menuHyperlinkShape,
                     {caption: '--'},
-                    me.pmiTextAdvanced
+                    me.pmiTextAdvanced,
+                    me.menuParagraphEquation
                 ]
             });
 
@@ -1167,6 +1173,60 @@ define([
             item.setCaption(add ? this.txtAddComment : (editable ? this.txtEditComment : this.txtShowComment), true);
         },
 
+        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}
+                    })
+                ]
+            });
+        },
+
         txtSort:                'Sort',
         txtAscending:           'Ascending',
         txtDescending:          'Descending',
@@ -1325,7 +1385,14 @@ define([
         chartDataText: 'Select Chart Data',
         chartTypeText: 'Change Chart Type',
         txtGetLink: 'Get link to this range',
-        txtRefresh: 'Refresh'
+        txtRefresh: 'Refresh',
+        advancedEquationText: 'Equation Settings',
+        unicodeText: 'Unicode',
+        latexText: 'LaTeX',
+        currProfText: 'Current - Professional',
+        currLinearText: 'Current - Linear',
+        allProfText: 'All - Professional',
+        allLinearText: 'All - Linear'
 
     }, SSE.Views.DocumentHolder || {}));
 });
\ No newline at end of file