mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
6774cd74f3
Changes: * Pass toolGroup into tools instead of toolbar * Split tool labels into title and accel * Make toolbars provide accelerator labels * Remove getLabelText method since it's not being used and is likely not useful * Make tools update their own labels * Only show accelerator information for triggers that are active in the surface * Make surface toolbars listen to commands being added and update tools accordingly * Introduce command object to encapsulate command info Change-Id: Ieac4bfa63b63ac0a9dee154af3007a33b4d447ff
117 lines
3.1 KiB
JavaScript
117 lines
3.1 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface ListTool classes.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* UserInterface list tool.
|
|
*
|
|
* @abstract
|
|
* @class
|
|
* @extends OO.ui.Tool
|
|
* @constructor
|
|
* @param {OO.ui.ToolGroup} toolGroup
|
|
* @param {Object} [config] Configuration options
|
|
*/
|
|
ve.ui.ListTool = function VeUiListTool( toolGroup, config ) {
|
|
// Parent constructor
|
|
OO.ui.Tool.call( this, toolGroup, config );
|
|
|
|
// Properties
|
|
this.method = null;
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.ListTool, OO.ui.Tool );
|
|
|
|
/**
|
|
* List style the tool applies.
|
|
*
|
|
* @abstract
|
|
* @static
|
|
* @property {string}
|
|
* @inheritable
|
|
*/
|
|
ve.ui.ListTool.static.style = '';
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle the tool being selected.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.ListTool.prototype.onSelect = function () {
|
|
if ( this.method === 'wrap' ) {
|
|
this.toolbar.surface.execute( 'list', 'wrap', this.constructor.static.style );
|
|
} else if ( this.method === 'unwrap' ) {
|
|
this.toolbar.surface.execute( 'list', 'unwrap' );
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Handle the toolbar state being updated.
|
|
*
|
|
* @method
|
|
* @param {ve.dm.Node[]} nodes List of nodes covered by the current selection
|
|
* @param {ve.dm.AnnotationSet} full Annotations that cover all of the current selection
|
|
* @param {ve.dm.AnnotationSet} partial Annotations that cover some or all of the current selection
|
|
*/
|
|
ve.ui.ListTool.prototype.onUpdateState = function ( nodes ) {
|
|
var i, len,
|
|
style = this.constructor.static.style,
|
|
all = !!nodes.length;
|
|
|
|
for ( i = 0, len = nodes.length; i < len; i++ ) {
|
|
if ( !nodes[i].hasMatchingAncestor( 'list', { 'style': style } ) ) {
|
|
all = false;
|
|
break;
|
|
}
|
|
}
|
|
this.method = all ? 'unwrap' : 'wrap';
|
|
this.setActive( all );
|
|
};
|
|
|
|
/**
|
|
* UserInterface bullet tool.
|
|
*
|
|
* @class
|
|
* @extends ve.ui.ListTool
|
|
* @constructor
|
|
* @param {OO.ui.ToolGroup} toolGroup
|
|
* @param {Object} [config] Configuration options
|
|
*/
|
|
ve.ui.BulletListTool = function VeUiBulletListTool( toolGroup, config ) {
|
|
ve.ui.ListTool.call( this, toolGroup, config );
|
|
};
|
|
OO.inheritClass( ve.ui.BulletListTool, ve.ui.ListTool );
|
|
ve.ui.BulletListTool.static.name = 'bullet';
|
|
ve.ui.BulletListTool.static.group = 'structure';
|
|
ve.ui.BulletListTool.static.icon = 'bullet-list';
|
|
ve.ui.BulletListTool.static.titleMessage = 'visualeditor-listbutton-bullet-tooltip';
|
|
ve.ui.BulletListTool.static.style = 'bullet';
|
|
ve.ui.toolFactory.register( ve.ui.BulletListTool );
|
|
|
|
/**
|
|
* UserInterface number tool.
|
|
*
|
|
* @class
|
|
* @extends ve.ui.ListTool
|
|
* @constructor
|
|
* @param {OO.ui.ToolGroup} toolGroup
|
|
* @param {Object} [config] Configuration options
|
|
*/
|
|
ve.ui.NumberListTool = function VeUiNumberListTool( toolGroup, config ) {
|
|
ve.ui.ListTool.call( this, toolGroup, config );
|
|
};
|
|
OO.inheritClass( ve.ui.NumberListTool, ve.ui.ListTool );
|
|
ve.ui.NumberListTool.static.name = 'number';
|
|
ve.ui.NumberListTool.static.group = 'structure';
|
|
ve.ui.NumberListTool.static.icon = 'number-list';
|
|
ve.ui.NumberListTool.static.titleMessage = 'visualeditor-listbutton-number-tooltip';
|
|
ve.ui.NumberListTool.static.style = 'number';
|
|
ve.ui.toolFactory.register( ve.ui.NumberListTool );
|