From 8d12f91bed5b5c52ca0dfb064d441e73a568a655 Mon Sep 17 00:00:00 2001 From: panr Date: Mon, 27 Jan 2020 12:17:37 +0100 Subject: [PATCH 1/4] Remove forceDisabled and clearForceDisabled methods, because WidgetToolbarRepository inherits them from Plugin --- src/widgettoolbarrepository.js | 75 ---------------------------------- 1 file changed, 75 deletions(-) diff --git a/src/widgettoolbarrepository.js b/src/widgettoolbarrepository.js index edd9a335..95a242a8 100644 --- a/src/widgettoolbarrepository.js +++ b/src/widgettoolbarrepository.js @@ -100,14 +100,6 @@ export default class WidgetToolbarRepository extends Plugin { */ this._balloon = this.editor.plugins.get( 'ContextualBalloon' ); - /** - * Holds identifiers for {@link #forceDisabled} mechanism. - * - * @type {Set.} - * @private - */ - this._disableStack = new Set(); - this.on( 'change:isEnabled', () => { this._updateToolbarsVisibility(); } ); @@ -171,67 +163,6 @@ export default class WidgetToolbarRepository extends Plugin { } ); } - /** - * Forces the plugin to be disabled. - * - * Plugin may be disabled by multiple features or algorithms (at once). When disabling a plugin, unique id should be passed - * (e.g. feature name). The same identifier should be used when {@link #clearForceDisabled enabling back} the plugin. - * The plugin becomes enabled only after all features {@link #clearForceDisabled enabled it back}. - * - * Disabling and enabling a plugin: - * - * const plugin = editor.plugins.get( 'WidgetToolbarRepository' ); - * - * plugin.isEnabled; // -> true - * plugin.forceDisabled( 'MyFeature' ); - * plugin.isEnabled; // -> false - * plugin.clearForceDisabled( 'MyFeature' ); - * plugin.isEnabled; // -> true - * - * Plugin disabled by multiple features: - * - * plugin.forceDisabled( 'MyFeature' ); - * plugin.forceDisabled( 'OtherFeature' ); - * plugin.clearForceDisabled( 'MyFeature' ); - * plugin.isEnabled; // -> false - * plugin.clearForceDisabled( 'OtherFeature' ); - * plugin.isEnabled; // -> true - * - * Multiple disabling with the same identifier is redundant: - * - * plugin.forceDisabled( 'MyFeature' ); - * plugin.forceDisabled( 'MyFeature' ); - * plugin.clearForceDisabled( 'MyFeature' ); - * plugin.isEnabled; // -> true - * - * **Note:** some plugins or algorithms may have more complex logic when it comes to enabling or disabling certain plugins, - * so the plugin might be still disabled after {@link #clearForceDisabled} was used. - * - * @param {String} id Unique identifier for disabling. Use the same id when {@link #clearForceDisabled enabling back} the plugin. - */ - forceDisabled( id ) { - this._disableStack.add( id ); - - if ( this._disableStack.size == 1 ) { - this.on( 'set:isEnabled', forceDisable, { priority: 'highest' } ); - this.isEnabled = false; - } - } - - /** - * Clears forced disable previously set through {@link #forceDisabled}. See {@link #forceDisabled}. - * - * @param {String} id Unique identifier, equal to the one passed in {@link #forceDisabled} call. - */ - clearForceDisabled( id ) { - this._disableStack.delete( id ); - - if ( this._disableStack.size == 0 ) { - this.off( 'set:isEnabled', forceDisable ); - this.isEnabled = true; - } - } - /** * Iterates over stored toolbars and makes them visible or hidden. * @@ -383,9 +314,3 @@ function isWidgetSelected( selection ) { * there is no such element). The function accepts an instance of {@link module:engine/view/selection~Selection}. * @property {String} balloonClassName CSS class for the widget balloon when a toolbar is displayed. */ - -// Helper function that forces command to be disabled. -function forceDisable( evt ) { - evt.return = false; - evt.stop(); -} From 0f1fe1c04fb04c98a9a15508743246d4139685b5 Mon Sep 17 00:00:00 2001 From: panr Date: Mon, 27 Jan 2020 12:46:04 +0100 Subject: [PATCH 2/4] Remove setting isEnabled state in WidgetToolbarRepository since it inherits isEnabled: true from Plugin --- src/widgettoolbarrepository.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/widgettoolbarrepository.js b/src/widgettoolbarrepository.js index 95a242a8..b2fb0015 100644 --- a/src/widgettoolbarrepository.js +++ b/src/widgettoolbarrepository.js @@ -70,23 +70,6 @@ export default class WidgetToolbarRepository extends Plugin { }, { priority: 'high' } ); } - /** - * Flag indicating whether a plugin is enabled or disabled. - * A disabled plugin won't show any toolbar. - * - * Plugin can be simply disabled like that: - * - * // Disable the plugin so that no toolbars are visible. - * editor.plugins.get( 'WidgetToolbarRepository' ).isEnabled = false; - * - * You can also use {@link #forceDisabled} method. - * - * @observable - * @readonly - * @member {Boolean} #isEnabled - */ - this.set( 'isEnabled', true ); - /** * A map of toolbar definitions. * From 6e1c3876f230d3e1015bdb864e6b6f0803f25861 Mon Sep 17 00:00:00 2001 From: panr Date: Mon, 27 Jan 2020 12:57:20 +0100 Subject: [PATCH 3/4] Bring back isEnabled observable --- src/widgettoolbarrepository.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/widgettoolbarrepository.js b/src/widgettoolbarrepository.js index b2fb0015..dc6ca754 100644 --- a/src/widgettoolbarrepository.js +++ b/src/widgettoolbarrepository.js @@ -70,6 +70,11 @@ export default class WidgetToolbarRepository extends Plugin { }, { priority: 'high' } ); } + /** + * @observable + */ + this.set( 'isEnabled', true ); + /** * A map of toolbar definitions. * From b7e92bd44359e3460ca9743ff365bb85b6e4c894 Mon Sep 17 00:00:00 2001 From: panr Date: Mon, 27 Jan 2020 13:10:58 +0100 Subject: [PATCH 4/4] Revert "Bring back isEnabled observable" This reverts commit 6e1c3876f230d3e1015bdb864e6b6f0803f25861. --- src/widgettoolbarrepository.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/widgettoolbarrepository.js b/src/widgettoolbarrepository.js index dc6ca754..b2fb0015 100644 --- a/src/widgettoolbarrepository.js +++ b/src/widgettoolbarrepository.js @@ -70,11 +70,6 @@ export default class WidgetToolbarRepository extends Plugin { }, { priority: 'high' } ); } - /** - * @observable - */ - this.set( 'isEnabled', true ); - /** * A map of toolbar definitions. *