From d9cbca0b5dd52943b49402365506f3a3f0119aaf Mon Sep 17 00:00:00 2001 From: "Julia.Svinareva" Date: Wed, 27 Mar 2024 20:57:17 +0300 Subject: [PATCH] [common] Add asc_pluginStop, getUsedBackgroundPlugins methods, fix srart/close in button menu for inside mode plugins --- apps/common/main/lib/controller/Plugins.js | 27 +++++++++++---------- apps/common/main/lib/view/Plugins.js | 28 +++++++++++++++------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/apps/common/main/lib/controller/Plugins.js b/apps/common/main/lib/controller/Plugins.js index 0d53512e70..e0702a7311 100644 --- a/apps/common/main/lib/controller/Plugins.js +++ b/apps/common/main/lib/controller/Plugins.js @@ -73,11 +73,11 @@ define([ } }, 'Common.Views.Plugins': { - 'plugin:select': function(guid, type) { - if (!this.viewPlugins.pluginPanels[guid]) { - me.api.asc_pluginRun(guid, type, ''); + 'plugin:select': function(guid, type, isRun, closePanel) { + if (!this.viewPlugins.pluginPanels[guid] || (this.viewPlugins.pluginPanels[guid] && type > 0)) { + !isRun || type > 0 ? me.api.asc_pluginRun(guid, type, '') : me.api.asc_pluginStop(guid); } else { - me.openUIPlugin(guid); + closePanel ? me.onToolClose(this.viewPlugins.pluginPanels[guid]) : me.openUIPlugin(guid); } } }, @@ -306,12 +306,14 @@ define([ } }; this.backgroundPluginsSwitchers = []; + var usedPlugins = this.api.getUsedBackgroundPlugins(); this.backgroundPlugins.forEach(function (model) { var modes = model.get('variations'), icons = modes[model.get('currentVariation')].get('icons'), parsedIcons = me.viewPlugins.parseIcons(icons), icon_url = model.get('baseUrl') + parsedIcons['normal'], - guid = model.get('guid'); + guid = model.get('guid'), + isRun = _.indexOf(usedPlugins, guid) !== -1; model.set('parsedIcons', parsedIcons); var menuItem = new Common.UI.MenuItem({ value: guid, @@ -333,14 +335,14 @@ define([ model.set('backgroundPlugin', menuItem); var switcher = new Common.UI.Switcher({ el: menuItem.$el.find('.plugin-toggle')[0], - value: !!model.isSystem, + value: !!model.isSystem || isRun, disabled: !!model.isSystem, pluginGuid: guid, - hint: me.viewPlugins.textStart + hint: isRun ? me.viewPlugins.textStop : me.viewPlugins.textStart }); switcher.on('change', function (element, value) { switcher.updateHint(value ? me.viewPlugins.textStop : me.viewPlugins.textStart); - me.viewPlugins.fireEvent('plugin:select', [switcher.options.pluginGuid, 0]); + me.viewPlugins.fireEvent('plugin:select', [switcher.options.pluginGuid, 0, !value]); }); me.backgroundPluginsSwitchers.push(switcher); var menuItems = []; @@ -367,7 +369,7 @@ define([ }); btn.menu.on('item:click', function (menu, item, e) { Common.UI.Menu.Manager.hideAll(); - me.viewPlugins.fireEvent('plugin:select', [menu.options.pluginGuid, item.value]); + me.viewPlugins.fireEvent('plugin:select', [menu.options.pluginGuid, item.value, false]); me.clickInsideMenu = false; }); btn.menu.on('keydown:before', function (menu, e) { @@ -694,7 +696,7 @@ define([ } } - !variation.get_InsideMode() && this.viewPlugins.openedPluginMode(plugin.get_Guid()); + this.viewPlugins.openedPluginMode(plugin.get_Guid(), variation.get_InsideMode()); }, onPluginClose: function(plugin) { @@ -713,9 +715,8 @@ define([ this.viewPlugins.fireEvent(model.get('menu') === 'right' ? 'pluginsright:close' : 'pluginsleft:close', [guid]); } } - if (!isIframePlugin) { - !this.turnOffBackgroundPlugin(guid) && this.viewPlugins.closedPluginMode(guid); - } + !this.turnOffBackgroundPlugin(guid) && this.viewPlugins.closedPluginMode(guid, isIframePlugin); + this.runAutoStartPlugins(); }, diff --git a/apps/common/main/lib/view/Plugins.js b/apps/common/main/lib/view/Plugins.js index b18483b259..66b1ea954f 100644 --- a/apps/common/main/lib/view/Plugins.js +++ b/apps/common/main/lib/view/Plugins.js @@ -190,7 +190,7 @@ define([ } }, - openedPluginMode: function(pluginGuid) { + openedPluginMode: function(pluginGuid, insideMode) { // var rec = this.viewPluginsList.store.findWhere({guid: pluginGuid}); // if ( rec ) { // this.viewPluginsList.cmpEl.find('#' + rec.get('id')).parent().addClass('selected'); @@ -200,27 +200,35 @@ define([ if ( model ) { var _btn = model.get('button'); if (_btn) { - _btn.toggle(true); - this.updatePluginButton(model); + if (!insideMode) { + _btn.toggle(true); + this.updatePluginButton(model); + } if (_btn.menu && _btn.menu.items.length>0) { _btn.menu.items[0].setCaption(this.textStop); + _btn.menu.items[0].isRun = true; } + _btn.options.isRun = true; } } }, - closedPluginMode: function(guid) { + closedPluginMode: function(guid, insideMode) { // this.viewPluginsList.cmpEl.find('.selected').removeClass('selected'); var model = this.storePlugins.findWhere({guid: guid}); if ( model ) { var _btn = model.get('button'); if (_btn) { - _btn.toggle(false); - this.updatePluginButton(model); + if (!insideMode) { + _btn.toggle(false); + this.updatePluginButton(model); + } if (_btn.menu && _btn.menu.items.length>0) { _btn.menu.items[0].setCaption(this.textStart); + _btn.menu.items[0].isRun = false; } + _btn.options.isRun = false; } } }, @@ -449,7 +457,8 @@ define([ if (variation.get('visible')) _menu_items.push({ caption : index > 0 ? variation.get('description') : me.textStart, - value : parseInt(variation.get('index')) + value : parseInt(variation.get('index')), + isRun : false }); }); @@ -461,6 +470,7 @@ define([ menu: _menu_items.length > 1, split: _menu_items.length > 1, value: guid, + isRun: false, hint: model.get('name'), lock: model.get('isDisplayedInViewer') ? [_set.viewMode, _set.previewReviewMode, _set.viewFormMode, _set.selRangeEdit, _set.editFormula] : [_set.viewMode, _set.previewReviewMode, _set.viewFormMode, _set.docLockView, _set.docLockForms, _set.docLockComments, _set.selRangeEdit, _set.editFormula ], dataHint: '1', @@ -477,12 +487,12 @@ define([ ); btn.menu.on('item:click', function(menu, item, e) { - me.fireEvent('plugin:select', [menu.options.pluginGuid, item.value]); + me.fireEvent('plugin:select', [menu.options.pluginGuid, item.value, item.isRun, item.value === 0 && item.isRun]); }); } btn.on('click', function(b, e) { - me.fireEvent('plugin:select', [b.options.value, 0]); + me.fireEvent('plugin:select', [b.options.value, 0, btn.options.isRun]); }); model.set('button', btn);