Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/tools/ve.ui.HistoryTool.js

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