Skip to content

Commit

Permalink
Merge pull request 'fix/plugin-macros' (#61) from fix/plugin-macros i…
Browse files Browse the repository at this point in the history
…nto release/v8.2.0
  • Loading branch information
Julia Radzhabova committed Oct 3, 2024
2 parents 4e62621 + 64b3855 commit 4324322
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
26 changes: 24 additions & 2 deletions apps/common/main/lib/controller/LayoutManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
})();

Expand Down
25 changes: 23 additions & 2 deletions apps/common/main/lib/controller/Plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit 4324322

Please sign in to comment.