Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/228283
Change subject: Allow the target to specify a command registry
......................................................................
Allow the target to specify a command registry
This would allow us to have multiple command sets loaded, but
only use a desired subset for each target.
Change-Id: Ie24369b9f7093e5d1d04dedd99c6bd95f3bde9dd
---
M src/ce/ve.ce.FocusableNode.js
M src/init/ve.init.Target.js
M src/ui/ve.ui.ContextItem.js
M src/ui/ve.ui.Sequence.js
M src/ui/ve.ui.Surface.js
M src/ui/ve.ui.Tool.js
M src/ui/widgets/ve.ui.ContextOptionWidget.js
M src/ve.TriggerListener.js
8 files changed, 12 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/83/228283/1
diff --git a/src/ce/ve.ce.FocusableNode.js b/src/ce/ve.ce.FocusableNode.js
index 2384400..72a9a4a 100644
--- a/src/ce/ve.ce.FocusableNode.js
+++ b/src/ce/ve.ce.FocusableNode.js
@@ -225,7 +225,7 @@
if ( !this.model.isInspectable() ) {
return false;
}
- var command = ve.ui.commandRegistry.getCommandForNode( this );
+ var command = ve.init.target.commandRegistry.getCommandForNode( this );
if ( command ) {
command.execute( this.focusableSurface.getSurface() );
}
diff --git a/src/init/ve.init.Target.js b/src/init/ve.init.Target.js
index a147d39..a429745 100644
--- a/src/init/ve.init.Target.js
+++ b/src/init/ve.init.Target.js
@@ -15,6 +15,7 @@
* @constructor
* @param {Object} [config] Configuration options
* @cfg {Object} [toolbarConfig] Configuration options for the toolbar
+ * @cfg {ve.ui.CommandRegistry} [commandRegistry] Command registry to use
*/
ve.init.Target = function VeInitTarget( config ) {
config = config || {};
@@ -25,11 +26,15 @@
// Mixin constructors
OO.EventEmitter.call( this );
+ // Register
+ ve.init.target = this;
+
// Properties
this.surfaces = [];
this.surface = null;
this.toolbar = null;
this.toolbarConfig = config.toolbarConfig;
+ this.commandRegistry = config.commandRegistry || ve.ui.commandRegistry;
this.documentTriggerListener = new ve.TriggerListener(
this.constructor.static.documentCommands );
this.targetTriggerListener = new ve.TriggerListener(
this.constructor.static.targetCommands );
@@ -44,9 +49,6 @@
this.onDocumentKeyDownHandler = this.onDocumentKeyDown.bind( this );
this.onTargetKeyDownHandler = this.onTargetKeyDown.bind( this );
this.bindHandlers();
-
- // Register
- ve.init.target = this;
};
/* Inheritance */
diff --git a/src/ui/ve.ui.ContextItem.js b/src/ui/ve.ui.ContextItem.js
index e24c5af..ca5053a 100644
--- a/src/ui/ve.ui.ContextItem.js
+++ b/src/ui/ve.ui.ContextItem.js
@@ -165,7 +165,7 @@
* @return {ve.ui.Command} Command
*/
ve.ui.ContextItem.prototype.getCommand = function () {
- return ve.ui.commandRegistry.lookup(
this.constructor.static.commandName );
+ return ve.init.target.commandRegistry.lookup(
this.constructor.static.commandName );
};
/**
diff --git a/src/ui/ve.ui.Sequence.js b/src/ui/ve.ui.Sequence.js
index fe4a733..b5fca70 100644
--- a/src/ui/ve.ui.Sequence.js
+++ b/src/ui/ve.ui.Sequence.js
@@ -60,7 +60,7 @@
ve.ui.Sequence.prototype.execute = function ( surface ) {
var range, executed, stripFragment,
surfaceModel = surface.getModel(),
- command = ve.ui.commandRegistry.lookup( this.getCommandName() );
+ command = ve.init.target.commandRegistry.lookup(
this.getCommandName() );
if ( !command ) {
throw new Error( 'Command not found: ' + this.getCommandName()
) ;
diff --git a/src/ui/ve.ui.Surface.js b/src/ui/ve.ui.Surface.js
index 56e3b74..55977c9 100644
--- a/src/ui/ve.ui.Surface.js
+++ b/src/ui/ve.ui.Surface.js
@@ -42,7 +42,7 @@
this.$menus = $( '<div>' );
this.$placeholder = $( '<div>' ).addClass( 've-ui-surface-placeholder'
);
this.triggerListener = new ve.TriggerListener( OO.simpleArrayDifference(
- config.includeCommands || Object.keys(
ve.ui.commandRegistry.registry ), config.excludeCommands || []
+ config.includeCommands || Object.keys(
ve.init.target.commandRegistry.registry ), config.excludeCommands || []
) );
if ( dataOrDoc instanceof ve.dm.Document ) {
// ve.dm.Document
diff --git a/src/ui/ve.ui.Tool.js b/src/ui/ve.ui.Tool.js
index 3f1530c..a3fe850 100644
--- a/src/ui/ve.ui.Tool.js
+++ b/src/ui/ve.ui.Tool.js
@@ -97,5 +97,5 @@
if ( this.constructor.static.commandName === null ) {
return null;
}
- return ve.ui.commandRegistry.lookup(
this.constructor.static.commandName );
+ return ve.init.target.commandRegistry.lookup(
this.constructor.static.commandName );
};
diff --git a/src/ui/widgets/ve.ui.ContextOptionWidget.js
b/src/ui/widgets/ve.ui.ContextOptionWidget.js
index 0175076..5b1409d 100644
--- a/src/ui/widgets/ve.ui.ContextOptionWidget.js
+++ b/src/ui/widgets/ve.ui.ContextOptionWidget.js
@@ -67,5 +67,5 @@
* @return {ve.ui.Command} Command
*/
ve.ui.ContextOptionWidget.prototype.getCommand = function () {
- return ve.ui.commandRegistry.lookup( this.tool.static.commandName );
+ return ve.init.target.commandRegistry.lookup(
this.tool.static.commandName );
};
diff --git a/src/ve.TriggerListener.js b/src/ve.TriggerListener.js
index abf6fed..f2aa85d 100644
--- a/src/ve.TriggerListener.js
+++ b/src/ve.TriggerListener.js
@@ -41,7 +41,7 @@
triggers = ve.ui.triggerRegistry.lookup( command );
if ( triggers ) {
for ( j = triggers.length - 1; j >= 0; j-- ) {
-
this.commandsByTrigger[triggers[j].toString()] = ve.ui.commandRegistry.lookup(
command );
+
this.commandsByTrigger[triggers[j].toString()] =
ve.init.target.commandRegistry.lookup( command );
}
this.triggers[command] = triggers;
}
--
To view, visit https://gerrit.wikimedia.org/r/228283
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie24369b9f7093e5d1d04dedd99c6bd95f3bde9dd
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits