Skip to content

Commit

Permalink
Merge pull request #2902 from ONLYOFFICE/fix/fix-plugins
Browse files Browse the repository at this point in the history
[common] Add asc_pluginStop, getUsedBackgroundPlugins methods, fix sr…
  • Loading branch information
JuliaRadzhabova authored Mar 28, 2024
2 parents ff37925 + d9cbca0 commit f2669e3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
27 changes: 14 additions & 13 deletions apps/common/main/lib/controller/Plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
},
Expand Down Expand Up @@ -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,
Expand All @@ -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 = [];
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
},

Expand Down
28 changes: 19 additions & 9 deletions apps/common/main/lib/view/Plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
}
}
},
Expand Down Expand Up @@ -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
});
});

Expand All @@ -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',
Expand All @@ -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);
Expand Down

0 comments on commit f2669e3

Please sign in to comment.