mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 00:30:44 +00:00
Merge "Make toolbars, toolgroups and tools toolFactory independent"
This commit is contained in:
commit
2b46215a2c
|
@ -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' ]
|
||||
}]);
|
||||
|
|
|
@ -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 );
|
||||
ve.ui.syntaxHighlightEditorToolFactory.register( ve.ui.MWSynHiBeautifyTool );
|
|
@ -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
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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 );
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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.$$( '<div>' ) );
|
||||
|
||||
// Properties
|
||||
this.toolFactory = toolFactory;
|
||||
this.groups = [];
|
||||
this.tools = {};
|
||||
this.$bar = this.$$( '<div>' );
|
||||
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue