Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/contextitems/ve.ui.ToolContextItem.js

raw symbols SCIP
1 /*!
2 * VisualEditor ToolContextItem class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Context item for a tool.
9 *
10 * @class
11 * @extends ve.ui.LinearContextItem
12 *
13 * @param {ve.ui.LinearContext} context Context the item is in
14 * @param {ve.dm.Model} model Model the item is related to
15 * @param {Function} tool Tool class the item is based on
16 * @param {Object} [config] Configuration options
17 */
18 ve.ui.ToolContextItem = function VeUiToolContextItem( context, model, tool, config ) {
19 // Parent constructor
20 ve.ui.ToolContextItem.super.call( this, context, model, config );
21
22 // Properties
23 this.tool = tool;
24
25 // Initialization
26 this.setIcon( tool.static.icon );
27 this.setLabel( tool.static.title );
28 this.$element.addClass( 've-ui-toolContextItem' );
29 };
30
31 /* Inheritance */
32
33 OO.inheritClass( ve.ui.ToolContextItem, ve.ui.LinearContextItem );
34
35 /* Methods */
36
37 /**
38 * @inheritdoc
39 */
40 ve.ui.ToolContextItem.prototype.getCommand = function () {
41 return this.tool.static.getCommand( this.context.getSurface() );
42 };
43
44 /**
45 * Get a description of the model.
46 *
47 * @return {string} Description of model
48 */
49 ve.ui.ToolContextItem.prototype.getDescription = function () {
50 let description = '';
51
52 if ( this.model instanceof ve.dm.Annotation ) {
53 description = ve.ce.annotationFactory.getDescription( this.model );
54 } else if ( this.model instanceof ve.dm.Node ) {
55 description = ve.ce.nodeFactory.getDescription( this.model );
56 }
57
58 return description;
59 };