Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/ve.ui.CommandHelpRegistry.js

raw symbols SCIP
1 /*!
2 * VisualEditor CommandHelpRegistry class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Command help registry.
9 *
10 * @class
11 * @extends OO.Registry
12 * @constructor
13 */
14 ve.ui.CommandHelpRegistry = function VeUiCommandHelpRegistry() {
15 // Parent constructor
16 OO.Registry.call( this );
17 };
18
19 /* Inheritance */
20
21 OO.inheritClass( ve.ui.CommandHelpRegistry, OO.Registry );
22
23 /* Methods */
24
25 /**
26 * Register a command for display in the dialog.
27 *
28 * @static
29 * @param {string} groupName Dialog-category in which to display this
30 * @param {string} commandHelpName Name of the command help item.
31 * @param {Object} details Details about the command
32 * @param {Function|string} details.label Label describing the command. String or deferred message function.
33 * @param {string} [details.trigger] Symbolic name of trigger this for this command
34 * @param {string[]} [details.shortcuts] Keyboard shortcuts if this is not a real trigger (e.g. copy/paste)
35 * @param {string[]} [details.sequences] Symbolic names of sequences, if this is a sequence, not a trigger
36 */
37 ve.ui.CommandHelpRegistry.prototype.register = function ( groupName, commandHelpName, details ) {
38 const existingCommand = this.registry[ commandHelpName ];
39 if ( existingCommand ) {
40 if ( details.sequences ) {
41 details = ve.copy( details );
42 details.sequences = ( existingCommand.sequences || [] ).concat( details.sequences );
43 }
44 details = ve.extendObject( existingCommand, details );
45 }
46
47 const platform = ve.getSystemPlatform(),
48 platformKey = platform === 'mac' ? 'mac' : 'pc';
49
50 if ( details.shortcuts ) {
51 for ( let i = 0; i < details.shortcuts.length; i++ ) {
52 const shortcut = details.shortcuts[ i ];
53 if ( ve.isPlainObject( shortcut ) ) {
54 details.shortcuts[ i ] = shortcut[ platformKey ];
55 }
56 }
57 }
58
59 details.group = groupName;
60
61 OO.Registry.prototype.register.call( this, commandHelpName, details );
62 };
63
64 /**
65 * Get data for a given group of commands.
66 *
67 * @param {string} groupName Group name
68 * @return {Object} Commands associated with the group
69 */
70 ve.ui.CommandHelpRegistry.prototype.lookupByGroup = function ( groupName ) {
71 const matches = {};
72 for ( const commandHelpName in this.registry ) {
73 if ( groupName === this.registry[ commandHelpName ].group ) {
74 matches[ commandHelpName ] = this.registry[ commandHelpName ];
75 }
76 }
77 return matches;
78 };
79
80 /* Initialization */
81
82 ve.ui.commandHelpRegistry = new ve.ui.CommandHelpRegistry();
83
84 /* Registrations */
85
86 // Text styles
87 ve.ui.commandHelpRegistry.register( 'textStyle', 'bold', { trigger: 'bold', label: OO.ui.deferMsg( 'visualeditor-annotationbutton-bold-tooltip' ) } );
88 ve.ui.commandHelpRegistry.register( 'textStyle', 'italic', { trigger: 'italic', label: OO.ui.deferMsg( 'visualeditor-annotationbutton-italic-tooltip' ) } );
89 ve.ui.commandHelpRegistry.register( 'textStyle', 'link', { trigger: 'link', label: OO.ui.deferMsg( 'visualeditor-annotationbutton-link-tooltip' ) } );
90 ve.ui.commandHelpRegistry.register( 'textStyle', 'superscript', { trigger: 'superscript', label: OO.ui.deferMsg( 'visualeditor-annotationbutton-superscript-tooltip' ) } );
91 ve.ui.commandHelpRegistry.register( 'textStyle', 'subscript', { trigger: 'subscript', label: OO.ui.deferMsg( 'visualeditor-annotationbutton-subscript-tooltip' ) } );
92 ve.ui.commandHelpRegistry.register( 'textStyle', 'underline', { trigger: 'underline', label: OO.ui.deferMsg( 'visualeditor-annotationbutton-underline-tooltip' ) } );
93 ve.ui.commandHelpRegistry.register( 'textStyle', 'code', { trigger: 'code', label: OO.ui.deferMsg( 'visualeditor-annotationbutton-code-tooltip' ) } );
94 ve.ui.commandHelpRegistry.register( 'textStyle', 'strikethrough', { trigger: 'strikethrough', label: OO.ui.deferMsg( 'visualeditor-annotationbutton-strikethrough-tooltip' ) } );
95 ve.ui.commandHelpRegistry.register( 'textStyle', 'clear', { trigger: 'clear', label: OO.ui.deferMsg( 'visualeditor-clearbutton-tooltip' ) } );
96
97 // Clipboard
98 ve.ui.commandHelpRegistry.register( 'clipboard', 'cut', {
99 trigger: 'cut',
100 ignoreCommand: true,
101 label: OO.ui.deferMsg( 'visualeditor-clipboard-cut' )
102 } );
103 ve.ui.commandHelpRegistry.register( 'clipboard', 'copy', {
104 trigger: 'copy',
105 ignoreCommand: true,
106 label: OO.ui.deferMsg( 'visualeditor-clipboard-copy' )
107 } );
108 ve.ui.commandHelpRegistry.register( 'clipboard', 'paste', {
109 trigger: 'paste',
110 ignoreCommand: true,
111 label: OO.ui.deferMsg( 'visualeditor-clipboard-paste' )
112 } );
113 ve.ui.commandHelpRegistry.register( 'clipboard', 'pasteSpecial', { trigger: 'pasteSpecial', label: OO.ui.deferMsg( 'visualeditor-clipboard-paste-special' ) } );
114
115 // Dialog
116 ve.ui.commandHelpRegistry.register( 'dialog', 'dialogCancel', {
117 shortcuts: [ 'escape' ],
118 label: OO.ui.deferMsg( 'visualeditor-command-dialog-cancel' )
119 } );
120 ve.ui.commandHelpRegistry.register( 'dialog', 'dialogConfirm', {
121 shortcuts: [ {
122 mac: 'cmd+enter',
123 pc: 'ctrl+enter'
124 } ],
125 label: OO.ui.deferMsg( 'visualeditor-command-dialog-confirm' )
126 } );
127 ve.ui.commandHelpRegistry.register( 'dialog', 'focusContext', {
128 trigger: 'focusContext',
129 label: OO.ui.deferMsg( 'visualeditor-command-dialog-focus-context' )
130 } );
131
132 // Formatting
133 ve.ui.commandHelpRegistry.register( 'formatting', 'paragraph', { trigger: 'paragraph', label: OO.ui.deferMsg( 'visualeditor-formatdropdown-format-paragraph' ) } );
134 ve.ui.commandHelpRegistry.register( 'formatting', 'heading', { shortcuts: [ 'ctrl+1-6' ], checkCommand: 'heading1', label: OO.ui.deferMsg( 'visualeditor-formatdropdown-format-heading-label' ) } );
135 ve.ui.commandHelpRegistry.register( 'formatting', 'pre', { trigger: 'preformatted', label: OO.ui.deferMsg( 'visualeditor-formatdropdown-format-preformatted' ) } );
136 ve.ui.commandHelpRegistry.register( 'formatting', 'blockquote', { trigger: 'blockquote', label: OO.ui.deferMsg( 'visualeditor-formatdropdown-format-blockquote' ) } );
137 ve.ui.commandHelpRegistry.register( 'formatting', 'indentIn', { trigger: 'indent', label: OO.ui.deferMsg( 'visualeditor-indentationbutton-indent-tooltip' ) } );
138 ve.ui.commandHelpRegistry.register( 'formatting', 'indentOut', { trigger: 'outdent', label: OO.ui.deferMsg( 'visualeditor-indentationbutton-outdent-tooltip' ) } );
139 ve.ui.commandHelpRegistry.register( 'formatting', 'listBullet', { sequences: [ 'bulletStar' ], label: OO.ui.deferMsg( 'visualeditor-listbutton-bullet-tooltip' ) } );
140 ve.ui.commandHelpRegistry.register( 'formatting', 'listNumber', { sequences: [ 'numberDot' ], label: OO.ui.deferMsg( 'visualeditor-listbutton-number-tooltip' ) } );
141
142 // History
143 ve.ui.commandHelpRegistry.register( 'history', 'undo', { trigger: 'undo', label: OO.ui.deferMsg( 'visualeditor-historybutton-undo-tooltip' ) } );
144 ve.ui.commandHelpRegistry.register( 'history', 'redo', { trigger: 'redo', label: OO.ui.deferMsg( 'visualeditor-historybutton-redo-tooltip' ) } );
145
146 // Other
147 ve.ui.commandHelpRegistry.register( 'other', 'findAndReplace', { trigger: 'findAndReplace', label: OO.ui.deferMsg( 'visualeditor-find-and-replace-title' ) } );
148 ve.ui.commandHelpRegistry.register( 'other', 'findNext', { trigger: 'findNext', label: OO.ui.deferMsg( 'visualeditor-find-and-replace-next-button' ) } );
149 ve.ui.commandHelpRegistry.register( 'other', 'findPrevious', { trigger: 'findPrevious', label: OO.ui.deferMsg( 'visualeditor-find-and-replace-previous-button' ) } );
150 ve.ui.commandHelpRegistry.register( 'other', 'selectAll', { trigger: 'selectAll', label: OO.ui.deferMsg( 'visualeditor-content-select-all' ) } );
151 ve.ui.commandHelpRegistry.register( 'other', 'changeDirectionality', { trigger: 'changeDirectionality', label: OO.ui.deferMsg( 'visualeditor-changedir' ) } );
152 ve.ui.commandHelpRegistry.register( 'other', 'commandHelp', { trigger: 'commandHelp', label: OO.ui.deferMsg( 'visualeditor-dialog-command-help-title' ) } );
153
154 // Insert
155 ve.ui.commandHelpRegistry.register( 'insert', 'horizontalRule', { sequences: [ 'horizontalRule' ], label: OO.ui.deferMsg( 'visualeditor-horizontalrule-tooltip' ) } );