2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor user interface HistoryButtonTool class.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2012-07-19 00:11:26 +00:00
|
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2011-12-05 21:10:19 +00:00
|
|
|
/**
|
2012-02-06 23:50:56 +00:00
|
|
|
* Creates an ve.ui.HistoryButtonTool object.
|
2012-03-03 00:17:15 +00:00
|
|
|
*
|
2011-12-05 21:10:19 +00:00
|
|
|
* @class
|
|
|
|
* @constructor
|
2012-02-06 23:50:56 +00:00
|
|
|
* @extends {ve.ui.ButtonTool}
|
|
|
|
* @param {ve.ui.Toolbar} toolbar
|
2011-12-05 21:10:19 +00:00
|
|
|
* @param {String} name
|
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.ui.HistoryButtonTool = function ( toolbar, name, title, data ) {
|
2011-12-05 21:10:19 +00:00
|
|
|
// Inheritance
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.ui.ButtonTool.call( this, toolbar, name, title );
|
2011-12-05 21:10:19 +00:00
|
|
|
|
|
|
|
// Properties
|
2011-12-04 02:59:53 +00:00
|
|
|
this.data = data;
|
2011-12-31 01:44:34 +00:00
|
|
|
this.enabled = false;
|
2012-06-20 01:20:28 +00:00
|
|
|
|
2012-08-11 08:14:56 +00:00
|
|
|
this.toolbar.getSurfaceView().model.on( 'history', ve.bind( this.updateState, this ) );
|
2011-12-04 02:59:53 +00:00
|
|
|
};
|
|
|
|
|
2011-12-05 21:10:19 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.ui.HistoryButtonTool.prototype.onClick = function () {
|
2011-12-04 02:59:53 +00:00
|
|
|
switch ( this.name ) {
|
|
|
|
case 'undo':
|
|
|
|
case 'redo':
|
2012-06-20 01:20:28 +00:00
|
|
|
if ( this.isButtonEnabled( this.name ) ) {
|
|
|
|
var surfaceView = this.toolbar.getSurfaceView();
|
|
|
|
surfaceView.stopPolling();
|
|
|
|
surfaceView.showSelection(
|
|
|
|
surfaceView.getModel()[this.name]( 1 ) || surfaceView.model.selection
|
|
|
|
);
|
|
|
|
surfaceView.clearPollData();
|
|
|
|
surfaceView.startPolling();
|
|
|
|
}
|
2011-12-04 02:59:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.ui.HistoryButtonTool.prototype.updateState = function ( annotations ) {
|
2012-06-20 01:20:28 +00:00
|
|
|
this.enabled = this.isButtonEnabled( this.name );
|
|
|
|
this.updateEnabled();
|
|
|
|
};
|
|
|
|
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.ui.HistoryButtonTool.prototype.isButtonEnabled = function ( name ) {
|
2012-06-20 01:20:28 +00:00
|
|
|
var surfaceModel = this.toolbar.getSurfaceView().getModel();
|
|
|
|
switch( name ) {
|
2011-12-31 01:44:34 +00:00
|
|
|
case 'undo':
|
2012-06-20 01:20:28 +00:00
|
|
|
return surfaceModel.bigStack.length - surfaceModel.undoIndex > 0;
|
2011-12-31 01:44:34 +00:00
|
|
|
case 'redo':
|
2012-06-20 01:20:28 +00:00
|
|
|
return surfaceModel.undoIndex > 0;
|
|
|
|
default:
|
|
|
|
return false;
|
2011-12-31 01:44:34 +00:00
|
|
|
}
|
2012-03-03 00:17:15 +00:00
|
|
|
};
|
2011-12-31 01:44:34 +00:00
|
|
|
|
2011-12-05 21:10:19 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.ui.Tool.tools.undo = {
|
|
|
|
'constructor': ve.ui.HistoryButtonTool,
|
2011-12-09 21:16:42 +00:00
|
|
|
'name': 'undo',
|
2012-06-20 01:20:28 +00:00
|
|
|
'title': ve.msg( 'visualeditor-historybutton-undo-tooltip' )
|
2011-12-04 02:59:53 +00:00
|
|
|
};
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.ui.Tool.tools.redo = {
|
|
|
|
'constructor': ve.ui.HistoryButtonTool,
|
2011-12-09 21:16:42 +00:00
|
|
|
'name': 'redo',
|
2012-06-20 01:20:28 +00:00
|
|
|
'title': ve.msg( 'visualeditor-historybutton-redo-tooltip' )
|
2011-12-04 02:59:53 +00:00
|
|
|
};
|
|
|
|
|
2011-12-05 21:10:19 +00:00
|
|
|
/* Inhertiance */
|
2011-12-04 02:59:53 +00:00
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.extendClass( ve.ui.HistoryButtonTool, ve.ui.ButtonTool );
|