Debian Codegraph @

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

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface FragmentWindowTool classes.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * UserInterface fragment window tool.
9 *
10 * @abstract
11 * @class
12 * @extends ve.ui.WindowTool
13 * @constructor
14 * @param {OO.ui.ToolGroup} toolGroup
15 * @param {Object} [config] Configuration options
16 */
17 ve.ui.FragmentWindowTool = function VeUiFragmentWindowTool() {
18 // Parent constructor
19 ve.ui.FragmentWindowTool.super.apply( this, arguments );
20 };
21
22 /* Inheritance */
23
24 OO.inheritClass( ve.ui.FragmentWindowTool, ve.ui.WindowTool );
25
26 /* Static Properties */
27
28 /**
29 * Annotation or node models this tool is related to.
30 *
31 * Used by #isCompatibleWith.
32 *
33 * @static
34 * @property {Function[]}
35 * @inheritable
36 */
37 ve.ui.FragmentWindowTool.static.modelClasses = [];
38
39 ve.ui.FragmentWindowTool.static.deactivateOnSelect = false;
40
41 /* Methods */
42
43 /**
44 * @inheritdoc
45 */
46 ve.ui.FragmentWindowTool.static.isCompatibleWith = function ( model ) {
47 return ve.isInstanceOfAny( model, this.modelClasses );
48 };
49
50 /**
51 * @inheritdoc
52 */
53 ve.ui.FragmentWindowTool.prototype.onUpdateState = function ( fragment ) {
54 this.setActive( false );
55
56 // Grand-parent method
57 // Parent method is skipped because it set's active state based on which windows
58 // are open, which we override in this implementation
59 ve.ui.FragmentWindowTool.super.super.prototype.onUpdateState.apply( this, arguments );
60
61 const models = this.getSelectedModels( fragment );
62
63 for ( let i = 0, len = models.length; i < len; i++ ) {
64 if ( this.constructor.static.isCompatibleWith( models[ i ] ) ) {
65 this.setActive( true );
66 break;
67 }
68 }
69 };
70
71 /**
72 * Get list of selected nodes and annotations.
73 *
74 * @param {ve.dm.SurfaceFragment|null} fragment Surface fragment
75 * @return {ve.dm.Model[]} Selected models
76 */
77 ve.ui.FragmentWindowTool.prototype.getSelectedModels = function ( fragment ) {
78 return fragment ? fragment.getSelectedModels() : [];
79 };