@workbench-kit/shell-react 0.0.2-prototype.0.2.6 → 0.0.2-prototype.0.2.8
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.
- package/README.md +41 -0
- package/package.json +9 -9
- package/src/{chat-ai-mock-proposals.ts → chat/ai-mock-proposals.ts} +39 -39
- package/src/{chat-command-input.ts → chat/command-input.ts} +52 -52
- package/src/{chat-command-policy.ts → chat/command-policy.ts} +54 -54
- package/src/{chat-command-surface.tsx → chat/command-surface.tsx} +155 -155
- package/src/{use-workbench-chat-command-proposals.ts → chat/use-chat-command-proposals.ts} +194 -194
- package/src/{chat-view-data.ts → chat/view-data.ts} +20 -20
- package/src/{chat-view.tsx → chat/view.tsx} +220 -220
- package/src/{command-inspector-surface.tsx → commands/inspector-surface.tsx} +46 -46
- package/src/{use-workbench-command-descriptors.ts → commands/use-command-descriptors.ts} +41 -41
- package/src/{use-context-key-revision.ts → commands/use-context-key-revision.ts} +18 -18
- package/src/{commands-view-data.ts → commands/view-data.ts} +17 -17
- package/src/{commands-view.tsx → commands/view.tsx} +43 -43
- package/src/devtools/WorkbenchDevtoolsPanel.tsx +124 -124
- package/src/devtools/WorkbenchDevtoolsShell.tsx +17 -17
- package/src/devtools/index.ts +11 -11
- package/src/devtools/use-workbench-devtools-snapshot.ts +84 -84
- package/src/devtools/workbench-devtools-snapshot.ts +140 -140
- package/src/devtools/workbench-devtools.css +82 -82
- package/src/{editor-area-dnd.ts → editor/area-dnd.ts} +69 -69
- package/src/{editor-area-model.ts → editor/area-model.ts} +71 -71
- package/src/{editor-area.css → editor/area.css} +454 -454
- package/src/{editor-area.tsx → editor/area.tsx} +676 -676
- package/src/{editor-host-surface.tsx → editor/host-surface.tsx} +631 -634
- package/src/{editor-pane-visibility.ts → editor/pane-visibility.ts} +130 -130
- package/src/{editor-resource.ts → editor/resource.ts} +36 -36
- package/src/{editor-state-storage.ts → editor/state-storage.ts} +182 -193
- package/src/{editor-tab-context-menu.ts → editor/tab-context-menu.ts} +118 -118
- package/src/{use-editor.ts → editor/use-editor.ts} +114 -107
- package/src/{editor-view-providers.tsx → editor/view-providers.tsx} +552 -552
- package/src/{editor-workspace-file-availability.ts → editor/workspace-file-availability.ts} +15 -15
- package/src/{editor-workspace-reconcile.tsx → editor/workspace-reconcile.tsx} +31 -28
- package/src/{explorer-context-menu.ts → explorer/context-menu.ts} +114 -114
- package/src/{createCommandWorkspaceExplorerPort.ts → explorer/create-command-workspace-explorer-port.ts} +86 -86
- package/src/{explorer-reveal.ts → explorer/reveal.ts} +112 -112
- package/src/{search-view-data.ts → explorer/search-view-data.ts} +15 -15
- package/src/{search-view.tsx → explorer/search-view.tsx} +65 -62
- package/src/{use-active-workspace-path.ts → explorer/use-active-workspace-path.ts} +15 -15
- package/src/{explorer-view-data.ts → explorer/view-data.ts} +58 -58
- package/src/{explorer-view.tsx → explorer/view.tsx} +227 -224
- package/src/{extension-context-menu.ts → extensions/context-menu.ts} +52 -52
- package/src/{extension-management-model.ts → extensions/management-model.ts} +313 -313
- package/src/{use-extension-management.ts → extensions/use-extension-management.ts} +241 -193
- package/src/{extensions-view-data.ts → extensions/view-data.ts} +19 -19
- package/src/{extensions-view.tsx → extensions/view.tsx} +63 -38
- package/src/{field-remap-demo.tsx → field-remap/demo.tsx} +18 -18
- package/src/{field-remap-editor-surface.tsx → field-remap/editor-surface.tsx} +36 -36
- package/src/{field-remap-flow-adapter.ts → field-remap/flow-adapter.ts} +240 -240
- package/src/{field-remap-flow.tsx → field-remap/flow.tsx} +369 -369
- package/src/{field-remap-graph.tsx → field-remap/graph.tsx} +559 -559
- package/src/field-remap/jsonata-transform.ts +166 -0
- package/src/{field-remap-panel.tsx → field-remap/panel.tsx} +193 -175
- package/src/{field-remap-samples.ts → field-remap/samples.ts} +352 -352
- package/src/{table-mapping-adapter.ts → field-remap/table-mapping-adapter.ts} +59 -59
- package/src/{field-remap-tree.tsx → field-remap/tree.tsx} +404 -404
- package/src/{field-remap-view-data.ts → field-remap/view-data.ts} +16 -16
- package/src/{field-remap-view.css → field-remap/view.css} +676 -676
- package/src/{field-remap-view.tsx → field-remap/view.tsx} +86 -86
- package/src/index.ts +212 -199
- package/src/{json-form-source-patch.ts → jdw/json-form-source-patch.ts} +323 -323
- package/src/{jdw-lab-view-data.ts → jdw/lab-view-data.ts} +25 -25
- package/src/{jdw-lab-view.css → jdw/lab-view.css} +21 -21
- package/src/{jdw-lab-view.tsx → jdw/lab-view.tsx} +79 -79
- package/src/{jdw-widget-form-view.tsx → jdw/widget-form-view.tsx} +68 -65
- package/src/{jdw-widget-preview-view.tsx → jdw/widget-preview-view.tsx} +54 -51
- package/src/{keybinding-overrides-storage.ts → management/keybinding-overrides-storage.ts} +49 -57
- package/src/{keybinding-management-settings.tsx → management/keybinding-settings.tsx} +16 -16
- package/src/{management-palette-commands.ts → management/palette-commands.ts} +38 -38
- package/src/{preference-settings-storage.ts → management/preference-settings-storage.ts} +50 -58
- package/src/{management-settings-ids.ts → management/settings-ids.ts} +12 -12
- package/src/{management-settings.tsx → management/settings.tsx} +96 -75
- package/src/{use-command-management.ts → management/use-command-management.ts} +191 -191
- package/src/{use-keybinding-management.ts → management/use-keybinding-management.ts} +130 -130
- package/src/{shell-model.tsx → shell/model.tsx} +149 -149
- package/src/{provider.tsx → shell/provider.tsx} +603 -573
- package/src/{shell-secondary-actions.tsx → shell/secondary-actions.tsx} +59 -59
- package/src/{shell-settings-constants.ts → shell/settings-constants.ts} +9 -9
- package/src/{shell-settings.tsx → shell/settings.tsx} +599 -599
- package/src/{shell.tsx → shell/shell.tsx} +680 -649
- package/src/{shell-titlebar-layout-controls.tsx → shell/titlebar-layout-controls.tsx} +4 -4
- package/src/{shell-view-host.tsx → shell/view-host.tsx} +212 -199
- package/src/{workbench-appearance-storage.ts → workbench/appearance-storage.ts} +107 -115
- package/src/{workbench-command-host.tsx → workbench/command-host.tsx} +243 -243
- package/src/{workbench-command-palette.ts → workbench/command-palette.ts} +208 -208
- package/src/{workbench-keybinding-bridge.ts → workbench/keybinding-bridge.ts} +54 -54
- package/src/{workbench-layout-storage.ts → workbench/layout-storage.ts} +134 -145
- package/src/{workbench-profile-modal.tsx → workbench/profile-modal.tsx} +118 -118
- package/src/{workbench-shell-command-registration.ts → workbench/shell-command-registration.ts} +58 -58
- package/src/{workbench-startup-gate.tsx → workbench/startup-gate.tsx} +136 -136
- package/src/{workbench-status-sections.ts → workbench/status-sections.ts} +43 -43
- package/src/{use-persisted-workbench-appearance.ts → workbench/use-persisted-appearance.ts} +33 -33
- package/src/{workbench-user-commands.ts → workbench/user-commands.ts} +46 -46
- package/src/{workspace-view-state.ts → workbench/workspace-view-state.ts} +35 -35
- package/src/jsonata-transform.ts +0 -36
|
@@ -1,191 +1,191 @@
|
|
|
1
|
-
import { useEffect, useMemo, useReducer, useState } from 'react';
|
|
2
|
-
import type { ExtensionCommandFeatureSpec, ExtensionRegistry } from '@workbench-kit/workbench-core';
|
|
3
|
-
import {
|
|
4
|
-
buildCommandManagementGroups,
|
|
5
|
-
countCommandManagementEntries,
|
|
6
|
-
type CommandManagementRunState,
|
|
7
|
-
} from '@workbench-kit/react/workbench/management';
|
|
8
|
-
import { createWorkbenchShellCommands } from '@workbench-kit/react/workbench';
|
|
9
|
-
|
|
10
|
-
import { useWorkbench } from '
|
|
11
|
-
import {
|
|
12
|
-
collectExtensionCommandFeaturesById,
|
|
13
|
-
resolveShellCommandActivities,
|
|
14
|
-
} from '
|
|
15
|
-
|
|
16
|
-
export function useCommandManagementModel() {
|
|
17
|
-
const { executeCommand, extensionRegistry } = useWorkbench();
|
|
18
|
-
const [lastRun, setLastRun] = useState<CommandManagementRunState | undefined>();
|
|
19
|
-
const [refreshToken, refreshRegistry] = useReducer((count: number) => count + 1, 0);
|
|
20
|
-
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
const commandDisposable = extensionRegistry.commands.onDidRegisterCommand(() => {
|
|
23
|
-
refreshRegistry();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
return () => {
|
|
27
|
-
commandDisposable.dispose();
|
|
28
|
-
};
|
|
29
|
-
}, [extensionRegistry]);
|
|
30
|
-
|
|
31
|
-
const groups = useMemo(
|
|
32
|
-
() => buildCommandManagementModelGroups(extensionRegistry, refreshToken),
|
|
33
|
-
[extensionRegistry, refreshToken],
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const totalCount = countCommandManagementEntries(groups);
|
|
37
|
-
|
|
38
|
-
const runCommand = async (commandId: string) => {
|
|
39
|
-
setLastRun({
|
|
40
|
-
commandId,
|
|
41
|
-
status: 'running',
|
|
42
|
-
timestamp: Date.now(),
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
await executeCommand(commandId);
|
|
47
|
-
setLastRun({
|
|
48
|
-
commandId,
|
|
49
|
-
status: 'success',
|
|
50
|
-
timestamp: Date.now(),
|
|
51
|
-
});
|
|
52
|
-
} catch (error) {
|
|
53
|
-
setLastRun({
|
|
54
|
-
commandId,
|
|
55
|
-
message: error instanceof Error ? error.message : 'Command failed.',
|
|
56
|
-
status: 'error',
|
|
57
|
-
timestamp: Date.now(),
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
groups,
|
|
64
|
-
lastRun,
|
|
65
|
-
refreshRegistry,
|
|
66
|
-
runCommand,
|
|
67
|
-
totalCount,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function buildCommandManagementModelGroups(
|
|
72
|
-
extensionRegistry: ExtensionRegistry,
|
|
73
|
-
_refreshToken = 0,
|
|
74
|
-
) {
|
|
75
|
-
const shellCommands = createWorkbenchShellCommands({
|
|
76
|
-
activities: resolveShellCommandActivities(extensionRegistry),
|
|
77
|
-
includeSettings: true,
|
|
78
|
-
includeSidebarToggle: true,
|
|
79
|
-
});
|
|
80
|
-
const shellCommandIds = new Set(shellCommands.map((command) => command.id));
|
|
81
|
-
const commandFeaturesById = collectExtensionCommandFeaturesById(extensionRegistry);
|
|
82
|
-
|
|
83
|
-
return buildCommandManagementGroups({
|
|
84
|
-
extensionCommands: collectExtensionCommandEntries(
|
|
85
|
-
extensionRegistry,
|
|
86
|
-
shellCommandIds,
|
|
87
|
-
commandFeaturesById,
|
|
88
|
-
),
|
|
89
|
-
keybindingsByCommandId: collectKeybindingsByCommandId(extensionRegistry),
|
|
90
|
-
menuSurfacesByCommandId: collectMenuSurfacesByCommandId(extensionRegistry),
|
|
91
|
-
shellCommands: shellCommands.map((command) => ({
|
|
92
|
-
category: command.category ?? 'Workbench',
|
|
93
|
-
handler:
|
|
94
|
-
extensionRegistry.commands.getCommand(command.id)?.handler ??
|
|
95
|
-
command.handler ??
|
|
96
|
-
command.run,
|
|
97
|
-
id: command.id,
|
|
98
|
-
label: typeof command.label === 'string' ? command.label : (command.title ?? command.id),
|
|
99
|
-
})),
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function collectExtensionCommandEntries(
|
|
104
|
-
extensionRegistry: ExtensionRegistry,
|
|
105
|
-
skippedCommandIds: ReadonlySet<string>,
|
|
106
|
-
commandFeaturesById: ReadonlyMap<string, ExtensionCommandFeatureSpec>,
|
|
107
|
-
) {
|
|
108
|
-
const entries: Array<{
|
|
109
|
-
category?: string | undefined;
|
|
110
|
-
description?: string | undefined;
|
|
111
|
-
extensionId: string;
|
|
112
|
-
extensionLabel: string;
|
|
113
|
-
handler?: unknown;
|
|
114
|
-
id: string;
|
|
115
|
-
label: string;
|
|
116
|
-
}> = [];
|
|
117
|
-
const seen = new Set<string>();
|
|
118
|
-
|
|
119
|
-
for (const feature of extensionRegistry.getFeatureSpecs()) {
|
|
120
|
-
const extensionLabel = feature.displayName;
|
|
121
|
-
|
|
122
|
-
for (const contribution of feature.commands) {
|
|
123
|
-
const command = extensionRegistry.commands.getCommand(contribution.id);
|
|
124
|
-
if (!command || seen.has(contribution.id) || skippedCommandIds.has(contribution.id)) {
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
seen.add(contribution.id);
|
|
129
|
-
entries.push({
|
|
130
|
-
category: command.category ?? contribution.category,
|
|
131
|
-
description: contribution.description,
|
|
132
|
-
extensionId: feature.id,
|
|
133
|
-
extensionLabel,
|
|
134
|
-
handler: command.handler,
|
|
135
|
-
id: command.id,
|
|
136
|
-
label: command.title ?? contribution.title ?? command.id,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
for (const command of extensionRegistry.commands.getCommands()) {
|
|
142
|
-
if (seen.has(command.id) || skippedCommandIds.has(command.id)) {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
entries.push({
|
|
147
|
-
category: command.category,
|
|
148
|
-
description: commandFeaturesById.get(command.id)?.description,
|
|
149
|
-
extensionId: 'runtime',
|
|
150
|
-
extensionLabel: 'Runtime',
|
|
151
|
-
handler: command.handler,
|
|
152
|
-
id: command.id,
|
|
153
|
-
label: command.title ?? command.id,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return entries;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function collectKeybindingsByCommandId(extensionRegistry: ExtensionRegistry) {
|
|
161
|
-
const keybindingsByCommandId: Record<string, string> = {};
|
|
162
|
-
|
|
163
|
-
for (const keybinding of extensionRegistry.keybindings.getKeybindings()) {
|
|
164
|
-
if (!keybindingsByCommandId[keybinding.command]) {
|
|
165
|
-
keybindingsByCommandId[keybinding.command] = keybinding.key;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return keybindingsByCommandId;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function collectMenuSurfacesByCommandId(extensionRegistry: ExtensionRegistry) {
|
|
173
|
-
const menuSurfacesByCommandId = new Map<string, Set<string>>();
|
|
174
|
-
|
|
175
|
-
for (const menuItem of extensionRegistry.menus.getMenuItems()) {
|
|
176
|
-
if (!menuItem.menu || !menuItem.command) {
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const surfaces = menuSurfacesByCommandId.get(menuItem.command) ?? new Set<string>();
|
|
181
|
-
surfaces.add(menuItem.menu);
|
|
182
|
-
menuSurfacesByCommandId.set(menuItem.command, surfaces);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return Object.fromEntries(
|
|
186
|
-
[...menuSurfacesByCommandId.entries()].map(([commandId, surfaces]) => [
|
|
187
|
-
commandId,
|
|
188
|
-
[...surfaces].sort(),
|
|
189
|
-
]),
|
|
190
|
-
);
|
|
191
|
-
}
|
|
1
|
+
import { useEffect, useMemo, useReducer, useState } from 'react';
|
|
2
|
+
import type { ExtensionCommandFeatureSpec, ExtensionRegistry } from '@workbench-kit/workbench-core';
|
|
3
|
+
import {
|
|
4
|
+
buildCommandManagementGroups,
|
|
5
|
+
countCommandManagementEntries,
|
|
6
|
+
type CommandManagementRunState,
|
|
7
|
+
} from '@workbench-kit/react/workbench/management';
|
|
8
|
+
import { createWorkbenchShellCommands } from '@workbench-kit/react/workbench';
|
|
9
|
+
|
|
10
|
+
import { useWorkbench } from '../shell/provider.js';
|
|
11
|
+
import {
|
|
12
|
+
collectExtensionCommandFeaturesById,
|
|
13
|
+
resolveShellCommandActivities,
|
|
14
|
+
} from '../workbench/command-palette.js';
|
|
15
|
+
|
|
16
|
+
export function useCommandManagementModel() {
|
|
17
|
+
const { executeCommand, extensionRegistry } = useWorkbench();
|
|
18
|
+
const [lastRun, setLastRun] = useState<CommandManagementRunState | undefined>();
|
|
19
|
+
const [refreshToken, refreshRegistry] = useReducer((count: number) => count + 1, 0);
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const commandDisposable = extensionRegistry.commands.onDidRegisterCommand(() => {
|
|
23
|
+
refreshRegistry();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return () => {
|
|
27
|
+
commandDisposable.dispose();
|
|
28
|
+
};
|
|
29
|
+
}, [extensionRegistry]);
|
|
30
|
+
|
|
31
|
+
const groups = useMemo(
|
|
32
|
+
() => buildCommandManagementModelGroups(extensionRegistry, refreshToken),
|
|
33
|
+
[extensionRegistry, refreshToken],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const totalCount = countCommandManagementEntries(groups);
|
|
37
|
+
|
|
38
|
+
const runCommand = async (commandId: string) => {
|
|
39
|
+
setLastRun({
|
|
40
|
+
commandId,
|
|
41
|
+
status: 'running',
|
|
42
|
+
timestamp: Date.now(),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
await executeCommand(commandId);
|
|
47
|
+
setLastRun({
|
|
48
|
+
commandId,
|
|
49
|
+
status: 'success',
|
|
50
|
+
timestamp: Date.now(),
|
|
51
|
+
});
|
|
52
|
+
} catch (error) {
|
|
53
|
+
setLastRun({
|
|
54
|
+
commandId,
|
|
55
|
+
message: error instanceof Error ? error.message : 'Command failed.',
|
|
56
|
+
status: 'error',
|
|
57
|
+
timestamp: Date.now(),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
groups,
|
|
64
|
+
lastRun,
|
|
65
|
+
refreshRegistry,
|
|
66
|
+
runCommand,
|
|
67
|
+
totalCount,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function buildCommandManagementModelGroups(
|
|
72
|
+
extensionRegistry: ExtensionRegistry,
|
|
73
|
+
_refreshToken = 0,
|
|
74
|
+
) {
|
|
75
|
+
const shellCommands = createWorkbenchShellCommands({
|
|
76
|
+
activities: resolveShellCommandActivities(extensionRegistry),
|
|
77
|
+
includeSettings: true,
|
|
78
|
+
includeSidebarToggle: true,
|
|
79
|
+
});
|
|
80
|
+
const shellCommandIds = new Set(shellCommands.map((command) => command.id));
|
|
81
|
+
const commandFeaturesById = collectExtensionCommandFeaturesById(extensionRegistry);
|
|
82
|
+
|
|
83
|
+
return buildCommandManagementGroups({
|
|
84
|
+
extensionCommands: collectExtensionCommandEntries(
|
|
85
|
+
extensionRegistry,
|
|
86
|
+
shellCommandIds,
|
|
87
|
+
commandFeaturesById,
|
|
88
|
+
),
|
|
89
|
+
keybindingsByCommandId: collectKeybindingsByCommandId(extensionRegistry),
|
|
90
|
+
menuSurfacesByCommandId: collectMenuSurfacesByCommandId(extensionRegistry),
|
|
91
|
+
shellCommands: shellCommands.map((command) => ({
|
|
92
|
+
category: command.category ?? 'Workbench',
|
|
93
|
+
handler:
|
|
94
|
+
extensionRegistry.commands.getCommand(command.id)?.handler ??
|
|
95
|
+
command.handler ??
|
|
96
|
+
command.run,
|
|
97
|
+
id: command.id,
|
|
98
|
+
label: typeof command.label === 'string' ? command.label : (command.title ?? command.id),
|
|
99
|
+
})),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function collectExtensionCommandEntries(
|
|
104
|
+
extensionRegistry: ExtensionRegistry,
|
|
105
|
+
skippedCommandIds: ReadonlySet<string>,
|
|
106
|
+
commandFeaturesById: ReadonlyMap<string, ExtensionCommandFeatureSpec>,
|
|
107
|
+
) {
|
|
108
|
+
const entries: Array<{
|
|
109
|
+
category?: string | undefined;
|
|
110
|
+
description?: string | undefined;
|
|
111
|
+
extensionId: string;
|
|
112
|
+
extensionLabel: string;
|
|
113
|
+
handler?: unknown;
|
|
114
|
+
id: string;
|
|
115
|
+
label: string;
|
|
116
|
+
}> = [];
|
|
117
|
+
const seen = new Set<string>();
|
|
118
|
+
|
|
119
|
+
for (const feature of extensionRegistry.getFeatureSpecs()) {
|
|
120
|
+
const extensionLabel = feature.displayName;
|
|
121
|
+
|
|
122
|
+
for (const contribution of feature.commands) {
|
|
123
|
+
const command = extensionRegistry.commands.getCommand(contribution.id);
|
|
124
|
+
if (!command || seen.has(contribution.id) || skippedCommandIds.has(contribution.id)) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
seen.add(contribution.id);
|
|
129
|
+
entries.push({
|
|
130
|
+
category: command.category ?? contribution.category,
|
|
131
|
+
description: contribution.description,
|
|
132
|
+
extensionId: feature.id,
|
|
133
|
+
extensionLabel,
|
|
134
|
+
handler: command.handler,
|
|
135
|
+
id: command.id,
|
|
136
|
+
label: command.title ?? contribution.title ?? command.id,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
for (const command of extensionRegistry.commands.getCommands()) {
|
|
142
|
+
if (seen.has(command.id) || skippedCommandIds.has(command.id)) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
entries.push({
|
|
147
|
+
category: command.category,
|
|
148
|
+
description: commandFeaturesById.get(command.id)?.description,
|
|
149
|
+
extensionId: 'runtime',
|
|
150
|
+
extensionLabel: 'Runtime',
|
|
151
|
+
handler: command.handler,
|
|
152
|
+
id: command.id,
|
|
153
|
+
label: command.title ?? command.id,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return entries;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function collectKeybindingsByCommandId(extensionRegistry: ExtensionRegistry) {
|
|
161
|
+
const keybindingsByCommandId: Record<string, string> = {};
|
|
162
|
+
|
|
163
|
+
for (const keybinding of extensionRegistry.keybindings.getKeybindings()) {
|
|
164
|
+
if (!keybindingsByCommandId[keybinding.command]) {
|
|
165
|
+
keybindingsByCommandId[keybinding.command] = keybinding.key;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return keybindingsByCommandId;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function collectMenuSurfacesByCommandId(extensionRegistry: ExtensionRegistry) {
|
|
173
|
+
const menuSurfacesByCommandId = new Map<string, Set<string>>();
|
|
174
|
+
|
|
175
|
+
for (const menuItem of extensionRegistry.menus.getMenuItems()) {
|
|
176
|
+
if (!menuItem.menu || !menuItem.command) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const surfaces = menuSurfacesByCommandId.get(menuItem.command) ?? new Set<string>();
|
|
181
|
+
surfaces.add(menuItem.menu);
|
|
182
|
+
menuSurfacesByCommandId.set(menuItem.command, surfaces);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return Object.fromEntries(
|
|
186
|
+
[...menuSurfacesByCommandId.entries()].map(([commandId, surfaces]) => [
|
|
187
|
+
commandId,
|
|
188
|
+
[...surfaces].sort(),
|
|
189
|
+
]),
|
|
190
|
+
);
|
|
191
|
+
}
|
|
@@ -1,130 +1,130 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
buildKeybindingManagementEntries,
|
|
4
|
-
type KeybindingDefinition,
|
|
5
|
-
} from '@workbench-kit/platform';
|
|
6
|
-
import { createWorkbenchShellCommands } from '@workbench-kit/react/workbench';
|
|
7
|
-
import type { ExtensionRegistry } from '@workbench-kit/workbench-core';
|
|
8
|
-
|
|
9
|
-
import { useWorkbench } from '
|
|
10
|
-
import { resolveShellCommandActivities } from '
|
|
11
|
-
|
|
12
|
-
export function useKeybindingManagementModel() {
|
|
13
|
-
const {
|
|
14
|
-
extensionRegistry,
|
|
15
|
-
keybindingOverrides,
|
|
16
|
-
resetCommandKeybindingOverride,
|
|
17
|
-
setCommandKeybindingOverride,
|
|
18
|
-
} = useWorkbench();
|
|
19
|
-
|
|
20
|
-
const defaults = useMemo(
|
|
21
|
-
() => extensionRegistry.keybindings.getKeybindings(),
|
|
22
|
-
[extensionRegistry, keybindingOverrides.length],
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
const entries = useMemo(
|
|
26
|
-
() =>
|
|
27
|
-
buildKeybindingManagementEntries({
|
|
28
|
-
commands: collectKeybindingManagementCommands(extensionRegistry),
|
|
29
|
-
defaults,
|
|
30
|
-
overrides: keybindingOverrides,
|
|
31
|
-
}),
|
|
32
|
-
[defaults, extensionRegistry, keybindingOverrides],
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const overrideCount = keybindingOverrides.length;
|
|
36
|
-
|
|
37
|
-
const setKeybinding = (commandId: string, key: string | undefined) => {
|
|
38
|
-
const defaultKey = defaults.find((binding) => binding.command === commandId)?.key;
|
|
39
|
-
if (!key || key === defaultKey) {
|
|
40
|
-
resetCommandKeybindingOverride(commandId);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
setCommandKeybindingOverride(commandId, key);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
entries,
|
|
49
|
-
overrideCount,
|
|
50
|
-
resetKeybinding: resetCommandKeybindingOverride,
|
|
51
|
-
setKeybinding,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function collectKeybindingManagementCommands(extensionRegistry: ExtensionRegistry) {
|
|
56
|
-
const commands: Array<{
|
|
57
|
-
category?: string | undefined;
|
|
58
|
-
id: string;
|
|
59
|
-
label: string;
|
|
60
|
-
sourceLabel?: string | undefined;
|
|
61
|
-
}> = [];
|
|
62
|
-
const seen = new Set<string>();
|
|
63
|
-
const shellCommands = createWorkbenchShellCommands({
|
|
64
|
-
activities: resolveShellCommandActivities(extensionRegistry),
|
|
65
|
-
includeSettings: true,
|
|
66
|
-
includeSidebarToggle: true,
|
|
67
|
-
});
|
|
68
|
-
const shellCommandIds = new Set(shellCommands.map((command) => command.id));
|
|
69
|
-
|
|
70
|
-
for (const extension of extensionRegistry.getExtensions()) {
|
|
71
|
-
const extensionLabel = extension.manifest.displayName ?? extension.manifest.id;
|
|
72
|
-
|
|
73
|
-
for (const contribution of extension.manifest.contributes?.commands ?? []) {
|
|
74
|
-
const command = extensionRegistry.commands.getCommand(contribution.command);
|
|
75
|
-
if (!command || seen.has(contribution.command) || shellCommandIds.has(contribution.command)) {
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
seen.add(contribution.command);
|
|
80
|
-
commands.push({
|
|
81
|
-
category: command.category ?? contribution.category,
|
|
82
|
-
id: command.id,
|
|
83
|
-
label: command.title ?? contribution.title ?? command.id,
|
|
84
|
-
sourceLabel: extensionLabel,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
for (const command of extensionRegistry.commands.getCommands()) {
|
|
90
|
-
if (seen.has(command.id) || shellCommandIds.has(command.id)) {
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
commands.push({
|
|
95
|
-
category: command.category,
|
|
96
|
-
id: command.id,
|
|
97
|
-
label: command.title ?? command.id,
|
|
98
|
-
sourceLabel: 'Runtime',
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
for (const command of shellCommands) {
|
|
103
|
-
if (seen.has(command.id)) {
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const label =
|
|
108
|
-
typeof command.label === 'function'
|
|
109
|
-
? command.id
|
|
110
|
-
: typeof command.label === 'string'
|
|
111
|
-
? command.label
|
|
112
|
-
: command.id;
|
|
113
|
-
|
|
114
|
-
seen.add(command.id);
|
|
115
|
-
commands.push({
|
|
116
|
-
category: 'Workbench',
|
|
117
|
-
id: command.id,
|
|
118
|
-
label,
|
|
119
|
-
sourceLabel: 'Workbench Shell',
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return commands;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function toKeybindingOverrideDefinitions(
|
|
127
|
-
overrides: readonly KeybindingDefinition[],
|
|
128
|
-
): KeybindingDefinition[] {
|
|
129
|
-
return overrides.map((binding) => ({ ...binding }));
|
|
130
|
-
}
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
buildKeybindingManagementEntries,
|
|
4
|
+
type KeybindingDefinition,
|
|
5
|
+
} from '@workbench-kit/platform';
|
|
6
|
+
import { createWorkbenchShellCommands } from '@workbench-kit/react/workbench';
|
|
7
|
+
import type { ExtensionRegistry } from '@workbench-kit/workbench-core';
|
|
8
|
+
|
|
9
|
+
import { useWorkbench } from '../shell/provider.js';
|
|
10
|
+
import { resolveShellCommandActivities } from '../workbench/command-palette.js';
|
|
11
|
+
|
|
12
|
+
export function useKeybindingManagementModel() {
|
|
13
|
+
const {
|
|
14
|
+
extensionRegistry,
|
|
15
|
+
keybindingOverrides,
|
|
16
|
+
resetCommandKeybindingOverride,
|
|
17
|
+
setCommandKeybindingOverride,
|
|
18
|
+
} = useWorkbench();
|
|
19
|
+
|
|
20
|
+
const defaults = useMemo(
|
|
21
|
+
() => extensionRegistry.keybindings.getKeybindings(),
|
|
22
|
+
[extensionRegistry, keybindingOverrides.length],
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const entries = useMemo(
|
|
26
|
+
() =>
|
|
27
|
+
buildKeybindingManagementEntries({
|
|
28
|
+
commands: collectKeybindingManagementCommands(extensionRegistry),
|
|
29
|
+
defaults,
|
|
30
|
+
overrides: keybindingOverrides,
|
|
31
|
+
}),
|
|
32
|
+
[defaults, extensionRegistry, keybindingOverrides],
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const overrideCount = keybindingOverrides.length;
|
|
36
|
+
|
|
37
|
+
const setKeybinding = (commandId: string, key: string | undefined) => {
|
|
38
|
+
const defaultKey = defaults.find((binding) => binding.command === commandId)?.key;
|
|
39
|
+
if (!key || key === defaultKey) {
|
|
40
|
+
resetCommandKeybindingOverride(commandId);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setCommandKeybindingOverride(commandId, key);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
entries,
|
|
49
|
+
overrideCount,
|
|
50
|
+
resetKeybinding: resetCommandKeybindingOverride,
|
|
51
|
+
setKeybinding,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function collectKeybindingManagementCommands(extensionRegistry: ExtensionRegistry) {
|
|
56
|
+
const commands: Array<{
|
|
57
|
+
category?: string | undefined;
|
|
58
|
+
id: string;
|
|
59
|
+
label: string;
|
|
60
|
+
sourceLabel?: string | undefined;
|
|
61
|
+
}> = [];
|
|
62
|
+
const seen = new Set<string>();
|
|
63
|
+
const shellCommands = createWorkbenchShellCommands({
|
|
64
|
+
activities: resolveShellCommandActivities(extensionRegistry),
|
|
65
|
+
includeSettings: true,
|
|
66
|
+
includeSidebarToggle: true,
|
|
67
|
+
});
|
|
68
|
+
const shellCommandIds = new Set(shellCommands.map((command) => command.id));
|
|
69
|
+
|
|
70
|
+
for (const extension of extensionRegistry.getExtensions()) {
|
|
71
|
+
const extensionLabel = extension.manifest.displayName ?? extension.manifest.id;
|
|
72
|
+
|
|
73
|
+
for (const contribution of extension.manifest.contributes?.commands ?? []) {
|
|
74
|
+
const command = extensionRegistry.commands.getCommand(contribution.command);
|
|
75
|
+
if (!command || seen.has(contribution.command) || shellCommandIds.has(contribution.command)) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
seen.add(contribution.command);
|
|
80
|
+
commands.push({
|
|
81
|
+
category: command.category ?? contribution.category,
|
|
82
|
+
id: command.id,
|
|
83
|
+
label: command.title ?? contribution.title ?? command.id,
|
|
84
|
+
sourceLabel: extensionLabel,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
for (const command of extensionRegistry.commands.getCommands()) {
|
|
90
|
+
if (seen.has(command.id) || shellCommandIds.has(command.id)) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
commands.push({
|
|
95
|
+
category: command.category,
|
|
96
|
+
id: command.id,
|
|
97
|
+
label: command.title ?? command.id,
|
|
98
|
+
sourceLabel: 'Runtime',
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
for (const command of shellCommands) {
|
|
103
|
+
if (seen.has(command.id)) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const label =
|
|
108
|
+
typeof command.label === 'function'
|
|
109
|
+
? command.id
|
|
110
|
+
: typeof command.label === 'string'
|
|
111
|
+
? command.label
|
|
112
|
+
: command.id;
|
|
113
|
+
|
|
114
|
+
seen.add(command.id);
|
|
115
|
+
commands.push({
|
|
116
|
+
category: 'Workbench',
|
|
117
|
+
id: command.id,
|
|
118
|
+
label,
|
|
119
|
+
sourceLabel: 'Workbench Shell',
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return commands;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function toKeybindingOverrideDefinitions(
|
|
127
|
+
overrides: readonly KeybindingDefinition[],
|
|
128
|
+
): KeybindingDefinition[] {
|
|
129
|
+
return overrides.map((binding) => ({ ...binding }));
|
|
130
|
+
}
|