diff --git a/modules/syntaxhighlight/ve.ui.MWSyntaxHighlightSimpleSurface.js b/modules/syntaxhighlight/ve.ui.MWSyntaxHighlightSimpleSurface.js index 764817a3ba..9f02e72953 100644 --- a/modules/syntaxhighlight/ve.ui.MWSyntaxHighlightSimpleSurface.js +++ b/modules/syntaxhighlight/ve.ui.MWSyntaxHighlightSimpleSurface.js @@ -90,7 +90,7 @@ ve.ui.MWSyntaxHighlightSimpleSurface = function VeUiMWSyntaxHighlightSimpleSurfa this.searchRegex = null; this.searchHasResult = false; - this.toolbar = new ve.ui.Toolbar({ '$$': this.$$ }); + this.toolbar = new ve.ui.Toolbar( ve.ui.syntaxHighlightEditorToolFactory, { '$$': this.$$ }); this.toolbar.setup([{ 'include':[ 'synhiUndo', 'synhiRedo', 'synhiIndent', 'synhiBeautify' ] }]); diff --git a/modules/syntaxhighlight/ve.ui.MWSyntaxHighlightTool.js b/modules/syntaxhighlight/ve.ui.MWSyntaxHighlightTool.js index 160a01652f..259cb7fbf1 100644 --- a/modules/syntaxhighlight/ve.ui.MWSyntaxHighlightTool.js +++ b/modules/syntaxhighlight/ve.ui.MWSyntaxHighlightTool.js @@ -37,6 +37,12 @@ ve.ui.MWSyntaxHighlightTool.static.autoAdd = true; ve.ui.toolFactory.register( ve.ui.MWSyntaxHighlightTool ); +/* + * Factory for SyntaxHighlight tools. + */ +ve.ui.syntaxHighlightEditorToolFactory = new ve.ui.ToolFactory(); + +/* SyntaxHighlight Editor Tools */ ve.ui.MWSyntaxHighlightEditorTool = function VeUiMWSyntaxHighlightEditorTool( toolbar, config ) { // Parent constructor @@ -67,7 +73,7 @@ ve.ui.MWSynHiUndoTool.static.method = 'undo'; ve.ui.MWSynHiUndoTool.static.icon = 'undo'; ve.ui.MWSynHiUndoTool.static.titleMessage = 'visualeditor-historybutton-undo-tooltip'; ve.ui.MWSynHiUndoTool.static.autoAdd = false; -ve.ui.toolFactory.register( ve.ui.MWSynHiUndoTool ); +ve.ui.syntaxHighlightEditorToolFactory.register( ve.ui.MWSynHiUndoTool ); ve.ui.MWSynHiRedoTool = function VeUiMWSynHiRedoTool( toolbar, config ) { ve.ui.MWSyntaxHighlightEditorTool.call( this, toolbar, config ); @@ -79,7 +85,7 @@ ve.ui.MWSynHiRedoTool.static.method = 'redo'; ve.ui.MWSynHiRedoTool.static.icon = 'redo'; ve.ui.MWSynHiRedoTool.static.titleMessage = 'visualeditor-historybutton-redo-tooltip'; ve.ui.MWSynHiRedoTool.static.autoAdd = false; -ve.ui.toolFactory.register( ve.ui.MWSynHiRedoTool ); +ve.ui.syntaxHighlightEditorToolFactory.register( ve.ui.MWSynHiRedoTool ); ve.ui.MWSynHiIndentTool = function VeUiMWSynHiIndentTool( toolbar, config ) { ve.ui.MWSyntaxHighlightEditorTool.call( this, toolbar, config ); @@ -91,7 +97,7 @@ ve.ui.MWSynHiIndentTool.static.method = 'indent'; ve.ui.MWSynHiIndentTool.static.icon = 'indent-list'; ve.ui.MWSynHiIndentTool.static.titleMessage = ''; ve.ui.MWSynHiIndentTool.static.autoAdd = false; -ve.ui.toolFactory.register( ve.ui.MWSynHiIndentTool ); +ve.ui.syntaxHighlightEditorToolFactory.register( ve.ui.MWSynHiIndentTool ); ve.ui.MWSynHiBeautifyTool = function VeUiMWSynHiBeautifyTool( toolbar, config ) { ve.ui.MWSyntaxHighlightEditorTool.call( this, toolbar, config ); @@ -103,4 +109,4 @@ ve.ui.MWSynHiBeautifyTool.static.method = 'doBeautify'; ve.ui.MWSynHiBeautifyTool.static.icon = 'reformat'; ve.ui.MWSynHiBeautifyTool.static.titleMessage = ''; ve.ui.MWSynHiBeautifyTool.static.autoAdd = false; -ve.ui.toolFactory.register( ve.ui.MWSynHiBeautifyTool ); \ No newline at end of file +ve.ui.syntaxHighlightEditorToolFactory.register( ve.ui.MWSynHiBeautifyTool ); \ No newline at end of file diff --git a/modules/ve/ui/tools/ve.ui.DialogTool.js b/modules/ve/ui/tools/ve.ui.DialogTool.js index 2ba9f48ab4..6033fdbcaf 100644 --- a/modules/ve/ui/tools/ve.ui.DialogTool.js +++ b/modules/ve/ui/tools/ve.ui.DialogTool.js @@ -76,6 +76,8 @@ ve.ui.DialogTool.prototype.onSelect = function () { */ ve.ui.DialogTool.prototype.onUpdateState = function ( nodes ) { if ( nodes.length ) { - this.setActive( ve.ui.toolFactory.getToolForNode( nodes[0] ) === this.constructor ); + this.setActive( + this.toolbar.getToolFactory().getToolForNode( nodes[0] ) === this.constructor + ); } }; diff --git a/modules/ve/ui/tools/ve.ui.InspectorTool.js b/modules/ve/ui/tools/ve.ui.InspectorTool.js index c62cd92dcd..39a7828c94 100644 --- a/modules/ve/ui/tools/ve.ui.InspectorTool.js +++ b/modules/ve/ui/tools/ve.ui.InspectorTool.js @@ -75,9 +75,8 @@ ve.ui.InspectorTool.prototype.onSelect = function () { * @param {ve.dm.AnnotationSet} partial Annotations that cover some or all of the current selection */ ve.ui.InspectorTool.prototype.onUpdateState = function ( nodes, full ) { - this.setActive( - ve.ui.toolFactory.getToolsForAnnotations( full ).indexOf( this.constructor ) !== -1 - ); + var toolFactory = this.toolbar.getToolFactory(); + this.setActive( toolFactory.getToolsForAnnotations( full ).indexOf( this.constructor ) !== -1 ); }; /** diff --git a/modules/ve/ui/ve.ui.SurfaceToolbar.js b/modules/ve/ui/ve.ui.SurfaceToolbar.js index 24b72130ed..d120338ff9 100644 --- a/modules/ve/ui/ve.ui.SurfaceToolbar.js +++ b/modules/ve/ui/ve.ui.SurfaceToolbar.js @@ -22,7 +22,7 @@ ve.ui.SurfaceToolbar = function VeUiSurfaceToolbar( surface, options ) { options = options || {}; // Parent constructor - ve.ui.Toolbar.call( this, options ); + ve.ui.Toolbar.call( this, ve.ui.toolFactory, options ); // Properties this.surface = surface; diff --git a/modules/ve/ui/ve.ui.ToolGroup.js b/modules/ve/ui/ve.ui.ToolGroup.js index a48d583911..1e0a7442ea 100644 --- a/modules/ve/ui/ve.ui.ToolGroup.js +++ b/modules/ve/ui/ve.ui.ToolGroup.js @@ -53,7 +53,7 @@ ve.ui.ToolGroup = function VeUiToolGroup( toolbar, config ) { 'mouseover': ve.bind( this.onMouseOver, this ), 'mouseout': ve.bind( this.onMouseOut, this ) } ); - ve.ui.toolFactory.connect( this, { 'register': 'onToolFactoryRegister' } ); + this.toolbar.getToolFactory().connect( this, { 'register': 'onToolFactoryRegister' } ); ve.ui.triggerRegistry.connect( this, { 'register': 'onTriggerRegistryRegister' } ); // Initialization @@ -267,7 +267,9 @@ ve.ui.ToolGroup.prototype.populate = function () { names = {}, add = [], remove = [], - list = ve.ui.toolFactory.getTools( this.include, this.exclude, this.promote, this.demote ); + list = this.toolbar.getToolFactory().getTools( + this.include, this.exclude, this.promote, this.demote + ); // Build a list of needed tools for ( i = 0, len = list.length; i < len; i++ ) { @@ -276,7 +278,8 @@ ve.ui.ToolGroup.prototype.populate = function () { tool = this.tools[name]; if ( !tool ) { // Auto-initialize tools on first use - this.tools[name] = tool = ve.ui.toolFactory.create( name, this.toolbar ); + this.tools[name] = tool = + this.toolbar.getToolFactory().create( name, this.toolbar ); this.updateToolTitle( name ); } this.toolbar.reserveTool( name ); @@ -315,7 +318,7 @@ ve.ui.ToolGroup.prototype.destroy = function () { var name; this.clearItems(); - ve.ui.toolFactory.disconnect( this ); + this.toolbar.getToolFactory().disconnect( this ); for ( name in this.tools ) { this.toolbar.releaseTool( name ); this.tools[name].disconnect( this ).destroy(); diff --git a/modules/ve/ui/ve.ui.Toolbar.js b/modules/ve/ui/ve.ui.Toolbar.js index 697ae0d708..4f6246f609 100644 --- a/modules/ve/ui/ve.ui.Toolbar.js +++ b/modules/ve/ui/ve.ui.Toolbar.js @@ -14,11 +14,12 @@ * @mixins ve.ui.GroupElement * * @constructor + * @param {ve.Factory} toolFactory Factory for creating tools * @param {Object} [options] Configuration options * @cfg {boolean} [actions] Add an actions section opposite to the tools * @cfg {boolean} [shadow] Add a shadow below the toolbar */ -ve.ui.Toolbar = function VeUiToolbar( options ) { +ve.ui.Toolbar = function VeUiToolbar( toolFactory, options ) { // Configuration initialization options = options || {}; @@ -30,6 +31,7 @@ ve.ui.Toolbar = function VeUiToolbar( options ) { ve.ui.GroupElement.call( this, this.$$( '
' ) ); // Properties + this.toolFactory = toolFactory; this.groups = []; this.tools = {}; this.$bar = this.$$( '
' ); @@ -64,6 +66,16 @@ ve.mixinClass( ve.ui.Toolbar, ve.ui.GroupElement ); /* Methods */ +/** + * Get the tool factory. + * + * @method + * @returns {ve.Factory} Tool factory + */ +ve.ui.Toolbar.prototype.getToolFactory = function () { + return this.toolFactory; +}; + /** * Sets up handles and preloads required information for the toolbar to work. * This must be called immediately after it is attached to a visible document.