All files / src/ui/tools ve.ui.HistoryTool.js

63.63% Statements 21/33
0% Branches 0/4
0% Functions 0/6
63.63% Lines 21/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105                              1x                   1x                   1x                         1x             1x                             1x       1x 1x 1x 1x 1x   1x 1x                     1x       1x 1x 1x 1x 1x   1x 1x  
/*!
 * VisualEditor UserInterface HistoryTool classes.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * UserInterface history tool.
 *
 * @class
 * @extends ve.ui.Tool
 * @constructor
 * @param {OO.ui.ToolGroup} toolGroup
 * @param {Object} [config] Configuration options
 */
ve.ui.HistoryTool = function VeUiHistoryTool() {
	// Parent constructor
	ve.ui.HistoryTool.super.apply( this, arguments );
 
	// Events
	this.toolbar.connect( this, { surfaceChange: 'onSurfaceChange' } );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ui.HistoryTool, ve.ui.Tool );
 
/* Methods */
 
/**
 * Handle surface change events from the toolbar
 *
 * @param {ve.ui.Surface|null} oldSurface
 * @param {ve.ui.Surface|null} newSurface
 */
ve.ui.HistoryTool.prototype.onSurfaceChange = function ( oldSurface, newSurface ) {
	if ( oldSurface ) {
		oldSurface.getModel().disconnect( this );
	}
	if ( newSurface ) {
		newSurface.getModel().connect( this, { history: 'onHistory' } );
		this.onUpdateState( newSurface.getModel().getFragment() );
	}
};
 
/**
 * Handle history events on the surface model
 */
ve.ui.HistoryTool.prototype.onHistory = function () {
	this.onUpdateState( this.toolbar.getSurface().getModel().getFragment() );
};
 
/**
 * @inheritdoc
 */
ve.ui.HistoryTool.prototype.destroy = function () {
	this.toolbar.getSurface().getModel().disconnect( this );
	// Parent method
	ve.ui.HistoryTool.super.prototype.destroy.call( this );
};
 
/**
 * UserInterface undo tool.
 *
 * @class
 * @extends ve.ui.HistoryTool
 * @constructor
 * @param {OO.ui.ToolGroup} toolGroup
 * @param {Object} [config] Configuration options
 */
ve.ui.UndoHistoryTool = function VeUiUndoHistoryTool() {
	// Parent constructor
	ve.ui.UndoHistoryTool.super.apply( this, arguments );
};
OO.inheritClass( ve.ui.UndoHistoryTool, ve.ui.HistoryTool );
ve.ui.UndoHistoryTool.static.name = 'undo';
ve.ui.UndoHistoryTool.static.group = 'history';
ve.ui.UndoHistoryTool.static.icon = 'undo';
ve.ui.UndoHistoryTool.static.title =
	OO.ui.deferMsg( 'visualeditor-historybutton-undo-tooltip' );
ve.ui.UndoHistoryTool.static.commandName = 'undo';
ve.ui.toolFactory.register( ve.ui.UndoHistoryTool );
 
/**
 * UserInterface redo tool.
 *
 * @class
 * @extends ve.ui.HistoryTool
 * @constructor
 * @param {OO.ui.ToolGroup} toolGroup
 * @param {Object} [config] Configuration options
 */
ve.ui.RedoHistoryTool = function VeUiRedoHistoryTool() {
	// Parent constructor
	ve.ui.RedoHistoryTool.super.apply( this, arguments );
};
OO.inheritClass( ve.ui.RedoHistoryTool, ve.ui.HistoryTool );
ve.ui.RedoHistoryTool.static.name = 'redo';
ve.ui.RedoHistoryTool.static.group = 'history';
ve.ui.RedoHistoryTool.static.icon = 'redo';
ve.ui.RedoHistoryTool.static.title =
	OO.ui.deferMsg( 'visualeditor-historybutton-redo-tooltip' );
ve.ui.RedoHistoryTool.static.commandName = 'redo';
ve.ui.toolFactory.register( ve.ui.RedoHistoryTool );