diff --git a/src/panels/index.js b/src/panels/index.js index d97305e7f..c088a25c4 100644 --- a/src/panels/index.js +++ b/src/panels/index.js @@ -216,7 +216,7 @@ module.exports = () => { active() { this.getPanels().each(p => { p.get('buttons').each(btn => { - if (btn.get('active')) btn.trigger('updateActive'); + btn.get('active') && btn.trigger('updateActive'); }); }); }, diff --git a/src/panels/model/Buttons.js b/src/panels/model/Buttons.js index 9d343e0b9..63111d497 100644 --- a/src/panels/model/Buttons.js +++ b/src/panels/model/Buttons.js @@ -27,13 +27,12 @@ module.exports = Backbone.Collection.extend({ * * @return void * */ - deactivateAll(ctx) { - var context = ctx || ''; - this.forEach((model, index) => { - if (model.get('context') == context) { - model.set('active', false); - if (model.get('buttons').length) - model.get('buttons').deactivateAll(context); + deactivateAll(ctx, sender) { + const context = ctx || ''; + this.forEach(model => { + if (model.get('context') == context && model !== sender) { + model.set('active', false, { silent: 1 }); + model.trigger('updateActive', { fromCollection: 1 }); } }); }, @@ -49,8 +48,6 @@ module.exports = Backbone.Collection.extend({ this.forEach((model, index) => { if (model.get('context') == context) { model.set('disable', true); - if (model.get('buttons').length) - model.get('buttons').disableAllButtons(context); } }); }, diff --git a/src/panels/view/ButtonView.js b/src/panels/view/ButtonView.js index ef5b8b374..e92f5ecd8 100644 --- a/src/panels/view/ButtonView.js +++ b/src/panels/view/ButtonView.js @@ -75,33 +75,32 @@ module.exports = Backbone.View.extend({ * * @return void * */ - updateActive() { - const { model, commands, em } = this; + updateActive(opts = {}) { + const { model, commands, $el, activeCls } = this; + const { fromCollection } = opts; const context = model.get('context'); const options = model.get('options'); + const commandName = model.get('command'); let command = {}; - var editor = em && em.get ? em.get('Editor') : null; - var commandName = model.get('command'); - var cmdIsFunc = isFunction(commandName); if (commands && isString(commandName)) { command = commands.get(commandName) || {}; - } else if (cmdIsFunc) { + } else if (isFunction(commandName)) { command = commands.create({ run: commandName }); } else if (commandName !== null && isObject(commandName)) { command = commands.create(commandName); } if (model.get('active')) { - model.collection.deactivateAll(context); + !fromCollection && model.collection.deactivateAll(context, model); model.set('active', true, { silent: true }).trigger('checkActive'); commands.runCommand(command, { ...options, sender: model }); // Disable button if the command has no stop method command.noStop && model.set('active', false); } else { - this.$el.removeClass(this.activeCls); - model.collection.deactivateAll(context); + !fromCollection && model.collection.deactivateAll(context, model); + $el.removeClass(activeCls); commands.stopCommand(command, { ...options, sender: model, force: 1 }); } },