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();
|
Remainder JSHint fixes on modules/ve/*
[jshint]
ce/ve.ce.Surface.js: line 670, col 9, Too many var statements.
ce/ve.ce.Surface.js: line 695, col 6, Missing semicolon.
ce/ve.ce.Surface.js: line 726, col 22, Expected '===' and instead saw '=='.
ce/ve.ce.Surface.js: line 726, col 41, Expected '===' and instead saw '=='.
ce/ve.ce.Surface.js: line 733, col 13, Too many var statements.
ce/ve.ce.Surface.js: line 734, col 24, Expected '===' and instead saw '=='.
ce/ve.ce.Surface.js: line 1013, col 13, Too many var statements.
ce/ve.ce.Surface.js: line 1019, col 17, Too many var statements.
ce/ve.ce.Surface.js: line 1023, col 18, Too many ar statements.
ce/ve.ce.Surface.js: line 1027, col 13, Too many var statements.
dm/annotations/ve.dm.LinkAnnotation.js: line 70, col 52, Insecure '.'.
dm/ve.dm.Converter.js: line 383, col 29, Empty block.
dm/ve.dm.Converter.js: line 423, col 33, Empty block.
Commands:
* jshint .
* ack '(if|else|function|switch|for|while)\('
* Sublime Text 2:
Find(*): (if|else|function|switch|for|while)\(
Replace: $1 (
* ack ' ' -Q # double spaces, except in certain comments
Change-Id: I8e34bf2924bc8688fdf8acef08bbc4f6707e93be
2012-09-02 21:45:01 +00:00
|
|
|
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 );
|