[Plugins] Fix reset plugins. Remove custom buttons when plugin closes

This commit is contained in:
Julia Radzhabova
2024-10-03 22:31:47 +03:00
parent 4e62621af0
commit a5455f9684
2 changed files with 40 additions and 4 deletions

View File

@ -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
}
})();

View File

@ -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 ) {
@ -922,7 +936,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) {