diff --git a/apps/common/main/lib/controller/LayoutManager.js b/apps/common/main/lib/controller/LayoutManager.js index 368df43608..a0cd041f4d 100644 --- a/apps/common/main/lib/controller/LayoutManager.js +++ b/apps/common/main/lib/controller/LayoutManager.js @@ -48,7 +48,9 @@ Common.UI.LayoutManager = new(function() { var _config, _licensed, _api, - _lastInternalTabIdx = 10; + _lastInternalTabIdx = 10, + _toolbar, + _arrPlugins = []; // all plugins that add controls to toolbar or menu items to toolbar buttons var _init = function(config, licensed, api) { _config = config; _licensed = licensed; @@ -172,6 +174,8 @@ Common.UI.LayoutManager = new(function() { var _addCustomItems = function (toolbar, data) { if (!data) return; + _toolbar = toolbar; + var lang = Common.Locale.getCurrentLanguage(), btns = []; data.forEach(function(plugin) { @@ -217,6 +221,13 @@ Common.UI.LayoutManager = new(function() { if (tab) { var added = [], removed = _findRemovedButtons(toolbar, tab.id, plugin.guid, tab.items); + + if (!_arrPlugins[plugin.guid]) + _arrPlugins[plugin.guid] = {actions: [], tabs: []}; + + if (_.indexOf(_arrPlugins[plugin.guid].tabs, tab)<0) + _arrPlugins[plugin.guid].tabs.push(tab.id); + tab.items && tab.items.forEach(function(item, index) { var btn = _findCustomButton(toolbar, tab.id, plugin.guid, item.id), _set = Common.enumLock; @@ -292,13 +303,24 @@ Common.UI.LayoutManager = new(function() { return btns; }; + var _clearCustomItems = function(guid) { + if (!_toolbar) return; + if (_arrPlugins[guid] && _arrPlugins[guid].tabs) { + _arrPlugins[guid].tabs.forEach(function(tab) { + _toolbar.addCustomItems({action: tab}, undefined, _findRemovedButtons(_toolbar, tab, guid)); + }); + _arrPlugins[guid].tabs = []; + } + }; + return { init: _init, applyCustomization: _applyCustomization, isElementVisible: _isElementVisible, getInitValue: _getInitValue, lastTabIdx: _lastInternalTabIdx, - addCustomItems: _addCustomItems + addCustomItems: _addCustomItems, + clearCustomItems: _clearCustomItems, // remove controls added by plugin from toolbar } })(); diff --git a/apps/common/main/lib/controller/Plugins.js b/apps/common/main/lib/controller/Plugins.js index d530350263..d07bd2a9c6 100644 --- a/apps/common/main/lib/controller/Plugins.js +++ b/apps/common/main/lib/controller/Plugins.js @@ -114,6 +114,7 @@ define([ this.customPluginsDlg = []; this.newInstalledBackgroundPlugins = []; + this.customButtonsArr = []; Common.Gateway.on('init', this.loadConfig.bind(this)); Common.NotificationCenter.on('app:face', this.onAppShowed.bind(this)); @@ -409,6 +410,11 @@ define([ onResetPlugins: function (collection) { var me = this; + me.customButtonsArr.forEach(function(item) { + me.toolbar && me.toolbar.addCustomItems({action: item.tab}, undefined, [item.btn]) + }); + me.customButtonsArr = []; + me.appOptions.canPlugins = !collection.isEmpty(); if ( me.$toolbarPanelPlugins ) { me.backgroundPlugins = []; @@ -427,7 +433,13 @@ define([ return; } if (model.get('tab')) { - me.toolbar && me.toolbar.addCustomItems(model.get('tab'), [me.viewPlugins.createPluginButton(model)]); + let tab = model.get('tab'), + btn = me.viewPlugins.createPluginButton(model); + if (btn) { + btn.options.separator = tab.separator; + me.toolbar && me.toolbar.addCustomItems(tab, [btn]); + me.customButtonsArr.push({tab: tab.action, btn: btn}); + } return; } @@ -751,6 +763,8 @@ define([ !this.turnOffBackgroundPlugin(guid) && this.viewPlugins.closedPluginMode(guid, isIframePlugin); this.runAutoStartPlugins(); + + Common.UI.LayoutManager.clearCustomItems(guid); // remove custom toolbar buttons }, onPluginResize: function(size, minSize, maxSize, callback ) { @@ -908,6 +922,13 @@ define([ if (pluginVisible) pluginVisible = me.checkPluginVersion(apiVersion, item.minVersion); + if (item.guid === "asc.{E6978D28-0441-4BD7-8346-82FAD68BCA3B}") { + item.tab = { + "id": "view", + "separator": true + } + } + var props = { name : name, guid: item.guid, @@ -922,7 +943,7 @@ define([ isDisplayedInViewer: isDisplayedInViewer, isBackgroundPlugin: pluginVisible && isBackgroundPlugin, isSystem: isSystem, - tab: item.tab ? {action: item.tab.id, caption: ((typeof item.tab.text == 'object') ? item.tab.text[lang] || item.tab.text['en'] : item.tab.text) || ''} : undefined + tab: item.tab ? {action: item.tab.id, caption: ((typeof item.tab.text == 'object') ? item.tab.text[lang] || item.tab.text['en'] : item.tab.text) || '', separator: item.tab.separator} : undefined }; updatedItem ? updatedItem.set(props) : arr.push(new Common.Models.Plugin(props)); if (fromManager && !updatedItem && props.isBackgroundPlugin) {