@theia/keymaps 1.45.1 → 1.46.0-next.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,296 +1,296 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { inject, injectable } from '@theia/core/shared/inversify';
18
- import {
19
- CommandContribution,
20
- Command,
21
- CommandRegistry,
22
- MenuContribution,
23
- MenuModelRegistry
24
- } from '@theia/core/lib/common';
25
- import { AbstractViewContribution, codicon, Widget } from '@theia/core/lib/browser';
26
- import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
27
- import { CommonCommands, CommonMenus } from '@theia/core/lib/browser/common-frontend-contribution';
28
- import { KeymapsService } from './keymaps-service';
29
- import { Keybinding } from '@theia/core/lib/common/keybinding';
30
- import { KeybindingRegistry } from '@theia/core/lib/browser/keybinding';
31
- import { KeybindingItem, KeybindingWidget } from './keybindings-widget';
32
- import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
33
- import { nls } from '@theia/core/lib/common/nls';
34
-
35
- export namespace KeymapsCommands {
36
- export const OPEN_KEYMAPS = Command.toDefaultLocalizedCommand({
37
- id: 'keymaps:open',
38
- category: CommonCommands.PREFERENCES_CATEGORY,
39
- label: 'Open Keyboard Shortcuts',
40
- });
41
- export const OPEN_KEYMAPS_JSON = Command.toDefaultLocalizedCommand({
42
- id: 'keymaps:openJson',
43
- category: CommonCommands.PREFERENCES_CATEGORY,
44
- label: 'Open Keyboard Shortcuts (JSON)',
45
- });
46
- export const OPEN_KEYMAPS_JSON_TOOLBAR: Command = {
47
- id: 'keymaps:openJson.toolbar',
48
- iconClass: codicon('json')
49
- };
50
- export const CLEAR_KEYBINDINGS_SEARCH: Command = {
51
- id: 'keymaps.clearSearch',
52
- iconClass: codicon('clear-all')
53
- };
54
- export const COPY_KEYBINDING = Command.toLocalizedCommand({
55
- id: 'keymaps:keybinding.copy',
56
- category: CommonCommands.PREFERENCES_CATEGORY,
57
- label: 'Copy Keybinding'
58
- }, 'theia/keymaps/keybinding/copy', CommonCommands.PREFERENCES_CATEGORY_KEY);
59
- export const COPY_COMMAND_ID = Command.toLocalizedCommand({
60
- id: 'keymaps:keybinding.copyCommandId',
61
- category: CommonCommands.PREFERENCES_CATEGORY,
62
- label: 'Copy Keybinding Command ID'
63
- }, 'theia/keymaps/keybinding/copyCommandId', CommonCommands.PREFERENCES_CATEGORY_KEY);
64
- export const COPY_COMMAND_TITLE = Command.toLocalizedCommand({
65
- id: 'keymaps:keybinding.copyCommandTitle',
66
- category: CommonCommands.PREFERENCES_CATEGORY,
67
- label: 'Copy Keybinding Command Title'
68
- }, 'theia/keymaps/keybinding/copyCommandTitle', CommonCommands.PREFERENCES_CATEGORY_KEY);
69
- export const EDIT_KEYBINDING = Command.toLocalizedCommand({
70
- id: 'keymaps:keybinding.edit',
71
- category: CommonCommands.PREFERENCES_CATEGORY,
72
- label: 'Edit Keybinding...'
73
- }, 'theia/keymaps/keybinding/edit', CommonCommands.PREFERENCES_CATEGORY_KEY);
74
- export const EDIT_WHEN_EXPRESSION = Command.toLocalizedCommand({
75
- id: 'keymaps:keybinding.editWhenExpression',
76
- category: CommonCommands.PREFERENCES_CATEGORY,
77
- label: 'Edit Keybinding When Expression...'
78
- }, 'theia/keymaps/keybinding/editWhenExpression', CommonCommands.PREFERENCES_CATEGORY_KEY);
79
- export const ADD_KEYBINDING = Command.toDefaultLocalizedCommand({
80
- id: 'keymaps:keybinding.add',
81
- category: CommonCommands.PREFERENCES_CATEGORY,
82
- label: 'Add Keybinding...'
83
- });
84
- export const REMOVE_KEYBINDING = Command.toDefaultLocalizedCommand({
85
- id: 'keymaps:keybinding.remove',
86
- category: CommonCommands.PREFERENCES_CATEGORY,
87
- label: 'Remove Keybinding'
88
- });
89
- export const RESET_KEYBINDING = Command.toDefaultLocalizedCommand({
90
- id: 'keymaps:keybinding.reset',
91
- category: CommonCommands.PREFERENCES_CATEGORY,
92
- label: 'Reset Keybinding'
93
- });
94
- export const SHOW_SAME = Command.toDefaultLocalizedCommand({
95
- id: 'keymaps:keybinding.showSame',
96
- category: CommonCommands.PREFERENCES_CATEGORY,
97
- label: 'Show Same Keybindings'
98
- });
99
- }
100
-
101
- @injectable()
102
- export class KeymapsFrontendContribution extends AbstractViewContribution<KeybindingWidget> implements CommandContribution, MenuContribution, TabBarToolbarContribution {
103
-
104
- @inject(KeymapsService)
105
- protected readonly keymaps: KeymapsService;
106
-
107
- @inject(ClipboardService)
108
- protected readonly clipboard: ClipboardService;
109
-
110
- constructor() {
111
- super({
112
- widgetId: KeybindingWidget.ID,
113
- widgetName: KeybindingWidget.LABEL,
114
- defaultWidgetOptions: {
115
- area: 'main'
116
- },
117
- });
118
- }
119
-
120
- override registerCommands(commands: CommandRegistry): void {
121
- commands.registerCommand(KeymapsCommands.OPEN_KEYMAPS, {
122
- isEnabled: () => true,
123
- execute: () => this.openView({ activate: true })
124
- });
125
- commands.registerCommand(KeymapsCommands.OPEN_KEYMAPS_JSON, {
126
- isEnabled: () => true,
127
- execute: () => this.keymaps.open()
128
- });
129
- commands.registerCommand(KeymapsCommands.OPEN_KEYMAPS_JSON_TOOLBAR, {
130
- isEnabled: w => this.withWidget(w, () => true),
131
- isVisible: w => this.withWidget(w, () => true),
132
- execute: w => this.withWidget(w, widget => this.keymaps.open(widget)),
133
- });
134
- commands.registerCommand(KeymapsCommands.CLEAR_KEYBINDINGS_SEARCH, {
135
- isEnabled: w => this.withWidget(w, widget => widget.hasSearch()),
136
- isVisible: w => this.withWidget(w, () => true),
137
- execute: w => this.withWidget(w, widget => widget.clearSearch()),
138
- });
139
- commands.registerCommand(KeymapsCommands.COPY_KEYBINDING, {
140
- isEnabled: (...args) => this.withItem(() => true, ...args),
141
- isVisible: (...args) => this.withItem(() => true, ...args),
142
- execute: (...args) => this.withItem(item => this.clipboard.writeText(
143
- JSON.stringify(Keybinding.apiObjectify(KeybindingItem.keybinding(item)), undefined, ' ')
144
- ), ...args)
145
- });
146
- commands.registerCommand(KeymapsCommands.COPY_COMMAND_ID, {
147
- isEnabled: (...args) => this.withItem(() => true, ...args),
148
- isVisible: (...args) => this.withItem(() => true, ...args),
149
- execute: (...args) => this.withItem(item => this.clipboard.writeText(item.command.id), ...args)
150
- });
151
- commands.registerCommand(KeymapsCommands.COPY_COMMAND_TITLE, {
152
- isEnabled: (...args) => this.withItem(item => !!item.command.label, ...args),
153
- isVisible: (...args) => this.withItem(() => true, ...args),
154
- execute: (...args) => this.withItem(item => this.clipboard.writeText(item.command.label!), ...args)
155
- });
156
- commands.registerCommand(KeymapsCommands.EDIT_KEYBINDING, {
157
- isEnabled: (...args) => this.withWidgetItem(() => true, ...args),
158
- isVisible: (...args) => this.withWidgetItem(() => true, ...args),
159
- execute: (...args) => this.withWidgetItem((item, widget) => widget.editKeybinding(item), ...args)
160
- });
161
- commands.registerCommand(KeymapsCommands.EDIT_WHEN_EXPRESSION, {
162
- isEnabled: (...args) => this.withWidgetItem(item => !!item.keybinding, ...args),
163
- isVisible: (...args) => this.withWidgetItem(() => true, ...args),
164
- execute: (...args) => this.withWidgetItem((item, widget) => widget.editWhenExpression(item), ...args)
165
- });
166
- commands.registerCommand(KeymapsCommands.ADD_KEYBINDING, {
167
- isEnabled: (...args) => this.withWidgetItem(item => !!item.keybinding, ...args),
168
- isVisible: (...args) => this.withWidgetItem(item => !!item.keybinding, ...args),
169
- execute: (...args) => this.withWidgetItem((item, widget) => widget.addKeybinding(item), ...args)
170
- });
171
- commands.registerCommand(KeymapsCommands.REMOVE_KEYBINDING, {
172
- isEnabled: (...args) => this.withItem(item => !!item.keybinding, ...args),
173
- isVisible: (...args) => this.withItem(() => true, ...args),
174
- execute: (...args) => this.withItem(item => this.keymaps.unsetKeybinding(item.keybinding!), ...args)
175
- });
176
- commands.registerCommand(KeymapsCommands.RESET_KEYBINDING, {
177
- isEnabled: (...args) => this.withWidgetItem((item, widget) => widget.canResetKeybinding(item), ...args),
178
- isVisible: (...args) => this.withWidgetItem(() => true, ...args),
179
- execute: (...args) => this.withWidgetItem((item, widget) => widget.resetKeybinding(item), ...args)
180
- });
181
- commands.registerCommand(KeymapsCommands.SHOW_SAME, {
182
- isEnabled: (...args) => this.withWidgetItem(item => !!item.keybinding, ...args),
183
- isVisible: (...args) => this.withWidgetItem(() => true, ...args),
184
- execute: (...args) => this.withWidgetItem((item, widget) => widget.showSameKeybindings(item), ...args)
185
- });
186
- }
187
-
188
- override registerMenus(menus: MenuModelRegistry): void {
189
- menus.registerMenuAction(CommonMenus.FILE_SETTINGS_SUBMENU_OPEN, {
190
- commandId: KeymapsCommands.OPEN_KEYMAPS.id,
191
- label: nls.localizeByDefault('Keyboard Shortcuts'),
192
- order: 'a20'
193
- });
194
- menus.registerMenuAction(CommonMenus.MANAGE_SETTINGS, {
195
- commandId: KeymapsCommands.OPEN_KEYMAPS.id,
196
- label: nls.localizeByDefault('Keyboard Shortcuts'),
197
- order: 'a30'
198
- });
199
- menus.registerMenuAction(KeybindingWidget.COPY_MENU, {
200
- commandId: KeymapsCommands.COPY_KEYBINDING.id,
201
- label: nls.localizeByDefault('Copy'),
202
- order: 'a'
203
- });
204
- menus.registerMenuAction(KeybindingWidget.COPY_MENU, {
205
- commandId: KeymapsCommands.COPY_COMMAND_ID.id,
206
- label: nls.localizeByDefault('Copy Command ID'),
207
- order: 'b'
208
- });
209
- menus.registerMenuAction(KeybindingWidget.COPY_MENU, {
210
- commandId: KeymapsCommands.COPY_COMMAND_TITLE.id,
211
- label: nls.localizeByDefault('Copy Command Title'),
212
- order: 'c'
213
- });
214
- menus.registerMenuAction(KeybindingWidget.EDIT_MENU, {
215
- commandId: KeymapsCommands.EDIT_KEYBINDING.id,
216
- label: nls.localize('theia/keymaps/editKeybinding', 'Edit Keybinding...'),
217
- order: 'a'
218
- });
219
- menus.registerMenuAction(KeybindingWidget.EDIT_MENU, {
220
- commandId: KeymapsCommands.EDIT_WHEN_EXPRESSION.id,
221
- label: nls.localize('theia/keymaps/editWhenExpression', 'Edit When Expression...'),
222
- order: 'b'
223
- });
224
- menus.registerMenuAction(KeybindingWidget.ADD_MENU, {
225
- commandId: KeymapsCommands.ADD_KEYBINDING.id,
226
- label: nls.localizeByDefault('Add Keybinding...'),
227
- order: 'a'
228
- });
229
- menus.registerMenuAction(KeybindingWidget.REMOVE_MENU, {
230
- commandId: KeymapsCommands.REMOVE_KEYBINDING.id,
231
- label: nls.localizeByDefault('Remove Keybinding'),
232
- order: 'a'
233
- });
234
- menus.registerMenuAction(KeybindingWidget.REMOVE_MENU, {
235
- commandId: KeymapsCommands.RESET_KEYBINDING.id,
236
- label: nls.localizeByDefault('Reset Keybinding'),
237
- order: 'b'
238
- });
239
- menus.registerMenuAction(KeybindingWidget.SHOW_MENU, {
240
- commandId: KeymapsCommands.SHOW_SAME.id,
241
- label: nls.localizeByDefault('Show Same Keybindings'),
242
- order: 'a'
243
- });
244
- }
245
-
246
- override registerKeybindings(keybindings: KeybindingRegistry): void {
247
- keybindings.registerKeybinding({
248
- command: KeymapsCommands.OPEN_KEYMAPS.id,
249
- keybinding: 'ctrl+alt+,'
250
- });
251
- }
252
-
253
- async registerToolbarItems(toolbar: TabBarToolbarRegistry): Promise<void> {
254
- const widget = await this.widget;
255
- const onDidChange = widget.onDidUpdate;
256
- toolbar.registerItem({
257
- id: KeymapsCommands.OPEN_KEYMAPS_JSON_TOOLBAR.id,
258
- command: KeymapsCommands.OPEN_KEYMAPS_JSON_TOOLBAR.id,
259
- tooltip: nls.localizeByDefault('Open Keyboard Shortcuts (JSON)'),
260
- priority: 0,
261
- });
262
- toolbar.registerItem({
263
- id: KeymapsCommands.CLEAR_KEYBINDINGS_SEARCH.id,
264
- command: KeymapsCommands.CLEAR_KEYBINDINGS_SEARCH.id,
265
- tooltip: nls.localizeByDefault('Clear Keybindings Search Input'),
266
- priority: 1,
267
- onDidChange,
268
- });
269
- }
270
-
271
- /**
272
- * Determine if the current widget is the keybindings widget.
273
- */
274
- protected withWidget<T>(widget: Widget | undefined = this.tryGetWidget(), fn: (widget: KeybindingWidget) => T): T | false {
275
- if (widget instanceof KeybindingWidget && widget.id === KeybindingWidget.ID) {
276
- return fn(widget);
277
- }
278
- return false;
279
- }
280
-
281
- protected withItem<T>(fn: (item: KeybindingItem, ...rest: unknown[]) => T, ...args: unknown[]): T | false {
282
- const [item] = args;
283
- if (KeybindingItem.is(item)) {
284
- return fn(item, args.slice(1));
285
- }
286
- return false;
287
- }
288
-
289
- protected withWidgetItem<T>(fn: (item: KeybindingItem, widget: KeybindingWidget, ...rest: unknown[]) => T, ...args: unknown[]): T | false {
290
- const [item, widget] = args;
291
- if (widget instanceof KeybindingWidget && widget.id === KeybindingWidget.ID && KeybindingItem.is(item)) {
292
- return fn(item, widget, args.slice(2));
293
- }
294
- return false;
295
- }
296
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { inject, injectable } from '@theia/core/shared/inversify';
18
+ import {
19
+ CommandContribution,
20
+ Command,
21
+ CommandRegistry,
22
+ MenuContribution,
23
+ MenuModelRegistry
24
+ } from '@theia/core/lib/common';
25
+ import { AbstractViewContribution, codicon, Widget } from '@theia/core/lib/browser';
26
+ import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
27
+ import { CommonCommands, CommonMenus } from '@theia/core/lib/browser/common-frontend-contribution';
28
+ import { KeymapsService } from './keymaps-service';
29
+ import { Keybinding } from '@theia/core/lib/common/keybinding';
30
+ import { KeybindingRegistry } from '@theia/core/lib/browser/keybinding';
31
+ import { KeybindingItem, KeybindingWidget } from './keybindings-widget';
32
+ import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
33
+ import { nls } from '@theia/core/lib/common/nls';
34
+
35
+ export namespace KeymapsCommands {
36
+ export const OPEN_KEYMAPS = Command.toDefaultLocalizedCommand({
37
+ id: 'keymaps:open',
38
+ category: CommonCommands.PREFERENCES_CATEGORY,
39
+ label: 'Open Keyboard Shortcuts',
40
+ });
41
+ export const OPEN_KEYMAPS_JSON = Command.toDefaultLocalizedCommand({
42
+ id: 'keymaps:openJson',
43
+ category: CommonCommands.PREFERENCES_CATEGORY,
44
+ label: 'Open Keyboard Shortcuts (JSON)',
45
+ });
46
+ export const OPEN_KEYMAPS_JSON_TOOLBAR: Command = {
47
+ id: 'keymaps:openJson.toolbar',
48
+ iconClass: codicon('json')
49
+ };
50
+ export const CLEAR_KEYBINDINGS_SEARCH: Command = {
51
+ id: 'keymaps.clearSearch',
52
+ iconClass: codicon('clear-all')
53
+ };
54
+ export const COPY_KEYBINDING = Command.toLocalizedCommand({
55
+ id: 'keymaps:keybinding.copy',
56
+ category: CommonCommands.PREFERENCES_CATEGORY,
57
+ label: 'Copy Keybinding'
58
+ }, 'theia/keymaps/keybinding/copy', CommonCommands.PREFERENCES_CATEGORY_KEY);
59
+ export const COPY_COMMAND_ID = Command.toLocalizedCommand({
60
+ id: 'keymaps:keybinding.copyCommandId',
61
+ category: CommonCommands.PREFERENCES_CATEGORY,
62
+ label: 'Copy Keybinding Command ID'
63
+ }, 'theia/keymaps/keybinding/copyCommandId', CommonCommands.PREFERENCES_CATEGORY_KEY);
64
+ export const COPY_COMMAND_TITLE = Command.toLocalizedCommand({
65
+ id: 'keymaps:keybinding.copyCommandTitle',
66
+ category: CommonCommands.PREFERENCES_CATEGORY,
67
+ label: 'Copy Keybinding Command Title'
68
+ }, 'theia/keymaps/keybinding/copyCommandTitle', CommonCommands.PREFERENCES_CATEGORY_KEY);
69
+ export const EDIT_KEYBINDING = Command.toLocalizedCommand({
70
+ id: 'keymaps:keybinding.edit',
71
+ category: CommonCommands.PREFERENCES_CATEGORY,
72
+ label: 'Edit Keybinding...'
73
+ }, 'theia/keymaps/keybinding/edit', CommonCommands.PREFERENCES_CATEGORY_KEY);
74
+ export const EDIT_WHEN_EXPRESSION = Command.toLocalizedCommand({
75
+ id: 'keymaps:keybinding.editWhenExpression',
76
+ category: CommonCommands.PREFERENCES_CATEGORY,
77
+ label: 'Edit Keybinding When Expression...'
78
+ }, 'theia/keymaps/keybinding/editWhenExpression', CommonCommands.PREFERENCES_CATEGORY_KEY);
79
+ export const ADD_KEYBINDING = Command.toDefaultLocalizedCommand({
80
+ id: 'keymaps:keybinding.add',
81
+ category: CommonCommands.PREFERENCES_CATEGORY,
82
+ label: 'Add Keybinding...'
83
+ });
84
+ export const REMOVE_KEYBINDING = Command.toDefaultLocalizedCommand({
85
+ id: 'keymaps:keybinding.remove',
86
+ category: CommonCommands.PREFERENCES_CATEGORY,
87
+ label: 'Remove Keybinding'
88
+ });
89
+ export const RESET_KEYBINDING = Command.toDefaultLocalizedCommand({
90
+ id: 'keymaps:keybinding.reset',
91
+ category: CommonCommands.PREFERENCES_CATEGORY,
92
+ label: 'Reset Keybinding'
93
+ });
94
+ export const SHOW_SAME = Command.toDefaultLocalizedCommand({
95
+ id: 'keymaps:keybinding.showSame',
96
+ category: CommonCommands.PREFERENCES_CATEGORY,
97
+ label: 'Show Same Keybindings'
98
+ });
99
+ }
100
+
101
+ @injectable()
102
+ export class KeymapsFrontendContribution extends AbstractViewContribution<KeybindingWidget> implements CommandContribution, MenuContribution, TabBarToolbarContribution {
103
+
104
+ @inject(KeymapsService)
105
+ protected readonly keymaps: KeymapsService;
106
+
107
+ @inject(ClipboardService)
108
+ protected readonly clipboard: ClipboardService;
109
+
110
+ constructor() {
111
+ super({
112
+ widgetId: KeybindingWidget.ID,
113
+ widgetName: KeybindingWidget.LABEL,
114
+ defaultWidgetOptions: {
115
+ area: 'main'
116
+ },
117
+ });
118
+ }
119
+
120
+ override registerCommands(commands: CommandRegistry): void {
121
+ commands.registerCommand(KeymapsCommands.OPEN_KEYMAPS, {
122
+ isEnabled: () => true,
123
+ execute: () => this.openView({ activate: true })
124
+ });
125
+ commands.registerCommand(KeymapsCommands.OPEN_KEYMAPS_JSON, {
126
+ isEnabled: () => true,
127
+ execute: () => this.keymaps.open()
128
+ });
129
+ commands.registerCommand(KeymapsCommands.OPEN_KEYMAPS_JSON_TOOLBAR, {
130
+ isEnabled: w => this.withWidget(w, () => true),
131
+ isVisible: w => this.withWidget(w, () => true),
132
+ execute: w => this.withWidget(w, widget => this.keymaps.open(widget)),
133
+ });
134
+ commands.registerCommand(KeymapsCommands.CLEAR_KEYBINDINGS_SEARCH, {
135
+ isEnabled: w => this.withWidget(w, widget => widget.hasSearch()),
136
+ isVisible: w => this.withWidget(w, () => true),
137
+ execute: w => this.withWidget(w, widget => widget.clearSearch()),
138
+ });
139
+ commands.registerCommand(KeymapsCommands.COPY_KEYBINDING, {
140
+ isEnabled: (...args) => this.withItem(() => true, ...args),
141
+ isVisible: (...args) => this.withItem(() => true, ...args),
142
+ execute: (...args) => this.withItem(item => this.clipboard.writeText(
143
+ JSON.stringify(Keybinding.apiObjectify(KeybindingItem.keybinding(item)), undefined, ' ')
144
+ ), ...args)
145
+ });
146
+ commands.registerCommand(KeymapsCommands.COPY_COMMAND_ID, {
147
+ isEnabled: (...args) => this.withItem(() => true, ...args),
148
+ isVisible: (...args) => this.withItem(() => true, ...args),
149
+ execute: (...args) => this.withItem(item => this.clipboard.writeText(item.command.id), ...args)
150
+ });
151
+ commands.registerCommand(KeymapsCommands.COPY_COMMAND_TITLE, {
152
+ isEnabled: (...args) => this.withItem(item => !!item.command.label, ...args),
153
+ isVisible: (...args) => this.withItem(() => true, ...args),
154
+ execute: (...args) => this.withItem(item => this.clipboard.writeText(item.command.label!), ...args)
155
+ });
156
+ commands.registerCommand(KeymapsCommands.EDIT_KEYBINDING, {
157
+ isEnabled: (...args) => this.withWidgetItem(() => true, ...args),
158
+ isVisible: (...args) => this.withWidgetItem(() => true, ...args),
159
+ execute: (...args) => this.withWidgetItem((item, widget) => widget.editKeybinding(item), ...args)
160
+ });
161
+ commands.registerCommand(KeymapsCommands.EDIT_WHEN_EXPRESSION, {
162
+ isEnabled: (...args) => this.withWidgetItem(item => !!item.keybinding, ...args),
163
+ isVisible: (...args) => this.withWidgetItem(() => true, ...args),
164
+ execute: (...args) => this.withWidgetItem((item, widget) => widget.editWhenExpression(item), ...args)
165
+ });
166
+ commands.registerCommand(KeymapsCommands.ADD_KEYBINDING, {
167
+ isEnabled: (...args) => this.withWidgetItem(item => !!item.keybinding, ...args),
168
+ isVisible: (...args) => this.withWidgetItem(item => !!item.keybinding, ...args),
169
+ execute: (...args) => this.withWidgetItem((item, widget) => widget.addKeybinding(item), ...args)
170
+ });
171
+ commands.registerCommand(KeymapsCommands.REMOVE_KEYBINDING, {
172
+ isEnabled: (...args) => this.withItem(item => !!item.keybinding, ...args),
173
+ isVisible: (...args) => this.withItem(() => true, ...args),
174
+ execute: (...args) => this.withItem(item => this.keymaps.unsetKeybinding(item.keybinding!), ...args)
175
+ });
176
+ commands.registerCommand(KeymapsCommands.RESET_KEYBINDING, {
177
+ isEnabled: (...args) => this.withWidgetItem((item, widget) => widget.canResetKeybinding(item), ...args),
178
+ isVisible: (...args) => this.withWidgetItem(() => true, ...args),
179
+ execute: (...args) => this.withWidgetItem((item, widget) => widget.resetKeybinding(item), ...args)
180
+ });
181
+ commands.registerCommand(KeymapsCommands.SHOW_SAME, {
182
+ isEnabled: (...args) => this.withWidgetItem(item => !!item.keybinding, ...args),
183
+ isVisible: (...args) => this.withWidgetItem(() => true, ...args),
184
+ execute: (...args) => this.withWidgetItem((item, widget) => widget.showSameKeybindings(item), ...args)
185
+ });
186
+ }
187
+
188
+ override registerMenus(menus: MenuModelRegistry): void {
189
+ menus.registerMenuAction(CommonMenus.FILE_SETTINGS_SUBMENU_OPEN, {
190
+ commandId: KeymapsCommands.OPEN_KEYMAPS.id,
191
+ label: nls.localizeByDefault('Keyboard Shortcuts'),
192
+ order: 'a20'
193
+ });
194
+ menus.registerMenuAction(CommonMenus.MANAGE_SETTINGS, {
195
+ commandId: KeymapsCommands.OPEN_KEYMAPS.id,
196
+ label: nls.localizeByDefault('Keyboard Shortcuts'),
197
+ order: 'a30'
198
+ });
199
+ menus.registerMenuAction(KeybindingWidget.COPY_MENU, {
200
+ commandId: KeymapsCommands.COPY_KEYBINDING.id,
201
+ label: nls.localizeByDefault('Copy'),
202
+ order: 'a'
203
+ });
204
+ menus.registerMenuAction(KeybindingWidget.COPY_MENU, {
205
+ commandId: KeymapsCommands.COPY_COMMAND_ID.id,
206
+ label: nls.localizeByDefault('Copy Command ID'),
207
+ order: 'b'
208
+ });
209
+ menus.registerMenuAction(KeybindingWidget.COPY_MENU, {
210
+ commandId: KeymapsCommands.COPY_COMMAND_TITLE.id,
211
+ label: nls.localizeByDefault('Copy Command Title'),
212
+ order: 'c'
213
+ });
214
+ menus.registerMenuAction(KeybindingWidget.EDIT_MENU, {
215
+ commandId: KeymapsCommands.EDIT_KEYBINDING.id,
216
+ label: nls.localize('theia/keymaps/editKeybinding', 'Edit Keybinding...'),
217
+ order: 'a'
218
+ });
219
+ menus.registerMenuAction(KeybindingWidget.EDIT_MENU, {
220
+ commandId: KeymapsCommands.EDIT_WHEN_EXPRESSION.id,
221
+ label: nls.localize('theia/keymaps/editWhenExpression', 'Edit When Expression...'),
222
+ order: 'b'
223
+ });
224
+ menus.registerMenuAction(KeybindingWidget.ADD_MENU, {
225
+ commandId: KeymapsCommands.ADD_KEYBINDING.id,
226
+ label: nls.localizeByDefault('Add Keybinding...'),
227
+ order: 'a'
228
+ });
229
+ menus.registerMenuAction(KeybindingWidget.REMOVE_MENU, {
230
+ commandId: KeymapsCommands.REMOVE_KEYBINDING.id,
231
+ label: nls.localizeByDefault('Remove Keybinding'),
232
+ order: 'a'
233
+ });
234
+ menus.registerMenuAction(KeybindingWidget.REMOVE_MENU, {
235
+ commandId: KeymapsCommands.RESET_KEYBINDING.id,
236
+ label: nls.localizeByDefault('Reset Keybinding'),
237
+ order: 'b'
238
+ });
239
+ menus.registerMenuAction(KeybindingWidget.SHOW_MENU, {
240
+ commandId: KeymapsCommands.SHOW_SAME.id,
241
+ label: nls.localizeByDefault('Show Same Keybindings'),
242
+ order: 'a'
243
+ });
244
+ }
245
+
246
+ override registerKeybindings(keybindings: KeybindingRegistry): void {
247
+ keybindings.registerKeybinding({
248
+ command: KeymapsCommands.OPEN_KEYMAPS.id,
249
+ keybinding: 'ctrl+alt+,'
250
+ });
251
+ }
252
+
253
+ async registerToolbarItems(toolbar: TabBarToolbarRegistry): Promise<void> {
254
+ const widget = await this.widget;
255
+ const onDidChange = widget.onDidUpdate;
256
+ toolbar.registerItem({
257
+ id: KeymapsCommands.OPEN_KEYMAPS_JSON_TOOLBAR.id,
258
+ command: KeymapsCommands.OPEN_KEYMAPS_JSON_TOOLBAR.id,
259
+ tooltip: nls.localizeByDefault('Open Keyboard Shortcuts (JSON)'),
260
+ priority: 0,
261
+ });
262
+ toolbar.registerItem({
263
+ id: KeymapsCommands.CLEAR_KEYBINDINGS_SEARCH.id,
264
+ command: KeymapsCommands.CLEAR_KEYBINDINGS_SEARCH.id,
265
+ tooltip: nls.localizeByDefault('Clear Keybindings Search Input'),
266
+ priority: 1,
267
+ onDidChange,
268
+ });
269
+ }
270
+
271
+ /**
272
+ * Determine if the current widget is the keybindings widget.
273
+ */
274
+ protected withWidget<T>(widget: Widget | undefined = this.tryGetWidget(), fn: (widget: KeybindingWidget) => T): T | false {
275
+ if (widget instanceof KeybindingWidget && widget.id === KeybindingWidget.ID) {
276
+ return fn(widget);
277
+ }
278
+ return false;
279
+ }
280
+
281
+ protected withItem<T>(fn: (item: KeybindingItem, ...rest: unknown[]) => T, ...args: unknown[]): T | false {
282
+ const [item] = args;
283
+ if (KeybindingItem.is(item)) {
284
+ return fn(item, args.slice(1));
285
+ }
286
+ return false;
287
+ }
288
+
289
+ protected withWidgetItem<T>(fn: (item: KeybindingItem, widget: KeybindingWidget, ...rest: unknown[]) => T, ...args: unknown[]): T | false {
290
+ const [item, widget] = args;
291
+ if (widget instanceof KeybindingWidget && widget.id === KeybindingWidget.ID && KeybindingItem.is(item)) {
292
+ return fn(item, widget, args.slice(2));
293
+ }
294
+ return false;
295
+ }
296
+ }