2013-08-27 23:28:29 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface HistoryTool classes.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UserInterface history tool.
|
|
|
|
*
|
|
|
|
* @class
|
2013-10-09 20:09:59 +00:00
|
|
|
* @extends OO.ui.Tool
|
2013-08-27 23:28:29 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {ve.ui.SurfaceToolbar} toolbar
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-08-27 23:28:29 +00:00
|
|
|
*/
|
|
|
|
ve.ui.HistoryTool = function VeUiHistoryTool( toolbar, config ) {
|
|
|
|
// Parent constructor
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.Tool.call( this, toolbar, config );
|
2013-08-27 23:28:29 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
this.toolbar.getSurface().getModel().connect( this, { 'history': 'onUpdateState' } );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.setDisabled( true );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.inheritClass( ve.ui.HistoryTool, OO.ui.Tool );
|
2013-08-27 23:28:29 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* History action method to use.
|
|
|
|
*
|
|
|
|
* @abstract
|
|
|
|
* @static
|
|
|
|
* @property {string}
|
|
|
|
* @inheritable
|
|
|
|
*/
|
|
|
|
ve.ui.HistoryTool.static.method = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Surface model method to check state with.
|
|
|
|
*
|
|
|
|
* @abstract
|
|
|
|
* @static
|
|
|
|
* @property {string}
|
|
|
|
* @inheritable
|
|
|
|
*/
|
|
|
|
ve.ui.HistoryTool.static.check = '';
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the tool being selected.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ui.HistoryTool.prototype.onSelect = function () {
|
|
|
|
this.toolbar.getSurface().execute( 'history', this.constructor.static.method );
|
|
|
|
this.setActive( false );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.HistoryTool.prototype.onUpdateState = function () {
|
|
|
|
this.setDisabled( !this.toolbar.getSurface().getModel()[this.constructor.static.check]() );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.HistoryTool.prototype.destroy = function () {
|
|
|
|
this.toolbar.getSurface().getModel().disconnect( this );
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.Tool.prototype.destroy.call( this );
|
2013-08-27 23:28:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UserInterface undo tool.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.HistoryTool
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.ui.SurfaceToolbar} toolbar
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-08-27 23:28:29 +00:00
|
|
|
*/
|
|
|
|
ve.ui.UndoHistoryTool = function VeUiUndoHistoryTool( toolbar, config ) {
|
|
|
|
ve.ui.HistoryTool.call( this, toolbar, config );
|
|
|
|
};
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.ui.UndoHistoryTool, ve.ui.HistoryTool );
|
2013-08-27 23:28:29 +00:00
|
|
|
ve.ui.UndoHistoryTool.static.name = 'undo';
|
|
|
|
ve.ui.UndoHistoryTool.static.group = 'history';
|
|
|
|
ve.ui.UndoHistoryTool.static.icon = 'undo';
|
|
|
|
ve.ui.UndoHistoryTool.static.titleMessage = 'visualeditor-historybutton-undo-tooltip';
|
|
|
|
ve.ui.UndoHistoryTool.static.method = 'undo';
|
|
|
|
ve.ui.UndoHistoryTool.static.check = 'hasPastState';
|
|
|
|
ve.ui.toolFactory.register( ve.ui.UndoHistoryTool );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UserInterface redo tool.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.HistoryTool
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.ui.SurfaceToolbar} toolbar
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-08-27 23:28:29 +00:00
|
|
|
*/
|
|
|
|
ve.ui.RedoHistoryTool = function VeUiRedoHistoryTool( toolbar, config ) {
|
|
|
|
ve.ui.HistoryTool.call( this, toolbar, config );
|
|
|
|
};
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.ui.RedoHistoryTool, ve.ui.HistoryTool );
|
2013-08-27 23:28:29 +00:00
|
|
|
ve.ui.RedoHistoryTool.static.name = 'redo';
|
|
|
|
ve.ui.RedoHistoryTool.static.group = 'history';
|
|
|
|
ve.ui.RedoHistoryTool.static.icon = 'redo';
|
|
|
|
ve.ui.RedoHistoryTool.static.titleMessage = 'visualeditor-historybutton-redo-tooltip';
|
|
|
|
ve.ui.RedoHistoryTool.static.method = 'redo';
|
|
|
|
ve.ui.RedoHistoryTool.static.check = 'hasFutureState';
|
|
|
|
ve.ui.toolFactory.register( ve.ui.RedoHistoryTool );
|