2013-10-23 23:27:12 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface Command class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Command that executes an action.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
*
|
|
|
|
* @constructor
|
2013-12-11 20:01:45 +00:00
|
|
|
* @param {string} name Symbolic name for the command
|
2013-10-23 23:27:12 +00:00
|
|
|
* @param {string} action Action to execute when command is triggered
|
|
|
|
* @param {string} method Method to call on action when executing
|
|
|
|
* @param {Mixed...} [data] Additional data to pass to the action when executing
|
|
|
|
*/
|
2013-12-11 20:01:45 +00:00
|
|
|
ve.ui.Command = function VeUiCommand( name, action, method ) {
|
|
|
|
this.name = name;
|
2013-10-23 23:27:12 +00:00
|
|
|
this.action = action;
|
|
|
|
this.method = method;
|
2013-12-11 20:01:45 +00:00
|
|
|
this.data = Array.prototype.slice.call( arguments, 3 );
|
2013-10-23 23:27:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute command on a surface.
|
|
|
|
*
|
|
|
|
* @param {ve.ui.Surface} surface Surface to execute command on
|
|
|
|
* @returns {Mixed} Result of command execution.
|
|
|
|
*/
|
|
|
|
ve.ui.Command.prototype.execute = function ( surface ) {
|
|
|
|
return surface.execute.apply( surface, [ this.action, this.method ].concat( this.data ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get command action.
|
|
|
|
*
|
|
|
|
* @returns {string} action Action to execute when command is triggered
|
|
|
|
*/
|
|
|
|
ve.ui.Command.prototype.getAction = function () {
|
|
|
|
return this.action;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get command method.
|
|
|
|
*
|
|
|
|
* @returns {string} method Method to call on action when executing
|
|
|
|
*/
|
|
|
|
ve.ui.Command.prototype.getMethod = function () {
|
|
|
|
return this.method;
|
|
|
|
};
|
|
|
|
|
2013-12-11 20:01:45 +00:00
|
|
|
/**
|
|
|
|
* Get command name.
|
|
|
|
*
|
|
|
|
* @returns {string} name The symbolic name of the command.
|
|
|
|
*/
|
|
|
|
ve.ui.Command.prototype.getName = function () {
|
|
|
|
return this.name;
|
|
|
|
};
|
|
|
|
|
2013-10-23 23:27:12 +00:00
|
|
|
/**
|
|
|
|
* Get command data.
|
|
|
|
*
|
|
|
|
* @returns {Array} data Additional data to pass to the action when executing
|
|
|
|
*/
|
|
|
|
ve.ui.Command.prototype.getData = function () {
|
|
|
|
return this.data;
|
|
|
|
};
|