2011-12-05 21:10:19 +00:00
|
|
|
/**
|
|
|
|
* Creates an es.HistoryButtonTool object.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {es.ButtonTool}
|
|
|
|
* @param {es.ToolbarView} toolbar
|
|
|
|
* @param {String} name
|
|
|
|
*/
|
2011-12-09 21:16:42 +00:00
|
|
|
es.HistoryButtonTool = function( toolbar, name, title, data ) {
|
2011-12-05 21:10:19 +00:00
|
|
|
// Inheritance
|
2011-12-09 21:16:42 +00:00
|
|
|
es.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;
|
2011-12-04 02:59:53 +00:00
|
|
|
};
|
|
|
|
|
2011-12-05 21:10:19 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2011-12-04 02:59:53 +00:00
|
|
|
es.HistoryButtonTool.prototype.onClick = function() {
|
|
|
|
switch ( this.name ) {
|
|
|
|
case 'undo':
|
|
|
|
this.toolbar.surfaceView.model.undo( 1 );
|
|
|
|
break;
|
|
|
|
case 'redo':
|
|
|
|
this.toolbar.surfaceView.model.redo( 1 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
es.HistoryButtonTool.prototype.updateState = function( annotations ) {
|
2011-12-31 01:44:34 +00:00
|
|
|
var surfaceModel = this.toolbar.surfaceView.model;
|
|
|
|
switch( this.name ) {
|
|
|
|
case 'undo':
|
|
|
|
this.enabled = surfaceModel.bigStack.length - surfaceModel.undoIndex > 0;
|
|
|
|
break;
|
|
|
|
case 'redo':
|
|
|
|
this.enabled = surfaceModel.undoIndex > 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateEnabled();
|
|
|
|
}
|
|
|
|
|
2011-12-04 02:59:53 +00:00
|
|
|
|
2011-12-05 21:10:19 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2011-12-04 02:59:53 +00:00
|
|
|
es.Tool.tools.undo = {
|
2011-12-09 21:16:42 +00:00
|
|
|
'constructor': es.HistoryButtonTool,
|
|
|
|
'name': 'undo',
|
|
|
|
'title': 'Undo (ctrl/cmd + Z)'
|
2011-12-04 02:59:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
es.Tool.tools.redo = {
|
2011-12-09 21:16:42 +00:00
|
|
|
'constructor': es.HistoryButtonTool,
|
|
|
|
'name': 'redo',
|
|
|
|
'title': 'Redo (ctrl/cmd + shift + Z)'
|
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
|
|
|
|
2011-12-05 21:10:19 +00:00
|
|
|
es.extendClass( es.HistoryButtonTool, es.ButtonTool );
|