Debian Codegraph @

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

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface ChangeDirectionalityTool class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * UserInterface change view directionality 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.ChangeDirectionalityTool = function VeUiChangeDirectionalityTool() {
17 // Parent constructor
18 ve.ui.ChangeDirectionalityTool.super.apply( this, arguments );
19
20 this.modelDir = null;
21
22 this.setDisabled( false );
23 };
24
25 /* Inheritance */
26
27 OO.inheritClass( ve.ui.ChangeDirectionalityTool, ve.ui.Tool );
28
29 /* Static Properties */
30
31 ve.ui.ChangeDirectionalityTool.static.name = 'changeDirectionality';
32
33 ve.ui.ChangeDirectionalityTool.static.group = 'utility';
34
35 ve.ui.ChangeDirectionalityTool.static.icon = 'textDirRTL';
36
37 ve.ui.ChangeDirectionalityTool.static.title =
38 OO.ui.deferMsg( 'visualeditor-changedir-rtl' );
39
40 ve.ui.ChangeDirectionalityTool.static.autoAddToCatchall = false;
41
42 ve.ui.ChangeDirectionalityTool.static.commandName = 'changeDirectionality';
43
44 ve.ui.ChangeDirectionalityTool.static.deactivateOnSelect = false;
45
46 /* Methods */
47
48 /**
49 * @inheritdoc
50 */
51 ve.ui.ChangeDirectionalityTool.prototype.onUpdateState = function ( fragment ) {
52 // Parent method
53 ve.ui.ChangeDirectionalityTool.super.prototype.onUpdateState.apply( this, arguments );
54
55 const modelDir = fragment.getDocument().getDir();
56
57 if ( modelDir !== this.modelDir ) {
58 // Icons used here textDirLTR, textDirRTL
59 this.setIcon( 'textDir' + ( modelDir === 'ltr' ? 'RTL' : 'LTR' ) );
60 // The following messages are used here:
61 // * visualeditor-changedir-tool-ltr
62 // * visualeditor-changedir-tool-rtl
63 this.setTitle( ve.msg( 'visualeditor-changedir-tool-' + ( modelDir === 'ltr' ? 'rtl' : 'ltr' ) ) );
64 this.modelDir = modelDir;
65 }
66
67 const viewDir = this.toolbar.getSurface().getView().getDocument().getDir();
68 this.setActive( viewDir !== modelDir );
69 };
70
71 /* Registration */
72
73 ve.ui.toolFactory.register( ve.ui.ChangeDirectionalityTool );