|
1 |
| -import { |
2 |
| - IDisposable, |
3 |
| - DisposableStore, |
4 |
| -} from 'monaco-editor/esm/vs/base/common/lifecycle'; |
5 |
| -import { ContextKeyExpr } from 'monaco-editor/esm/vs/platform/contextkey/common/contextkey'; |
6 |
| -import { KeybindingsRegistry } from 'monaco-editor/esm/vs/platform/keybinding/common/keybindingsRegistry'; |
7 |
| -import { ServicesAccessor } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation'; |
8 |
| -import { CommandsRegistry } from 'monaco-editor/esm/vs/platform/commands/common/commands'; |
9 | 1 | import { localize } from 'monaco-editor/esm/vs/nls';
|
10 |
| -import { |
11 |
| - MenuRegistry, |
12 |
| - MenuId, |
13 |
| -} from 'monaco-editor/esm/vs/platform/actions/common/actions'; |
| 2 | + |
| 3 | +export interface IDisposable { |
| 4 | + dispose(): void; |
| 5 | +} |
14 | 6 |
|
15 | 7 | export enum KeybindingWeight {
|
16 | 8 | EditorCore = 0,
|
@@ -40,81 +32,3 @@ export const CATEGORIES = {
|
40 | 32 | original: 'Developer',
|
41 | 33 | },
|
42 | 34 | };
|
43 |
| - |
44 |
| -export abstract class Action2 { |
45 |
| - constructor( |
46 |
| - readonly desc: Readonly<{ |
47 |
| - /** |
48 |
| - * Specify visible in quick access view |
49 |
| - */ |
50 |
| - f1: boolean; |
51 |
| - [key: string]: any; |
52 |
| - }> |
53 |
| - ) {} |
54 |
| - abstract run(accessor: ServicesAccessor, ...args: any[]): any; |
55 |
| -} |
56 |
| - |
57 |
| -export function registerAction2(ctor: { new (): Action2 }): IDisposable { |
58 |
| - const disposables = new DisposableStore(); |
59 |
| - // eslint-disable-next-line new-cap |
60 |
| - const action = new ctor(); |
61 |
| - |
62 |
| - const { f1, menu, keybinding, description, ...command } = action.desc; |
63 |
| - |
64 |
| - // command |
65 |
| - disposables.add( |
66 |
| - CommandsRegistry.registerCommand({ |
67 |
| - id: command.id, |
68 |
| - handler: (accessor, ...args) => action.run(accessor, ...args), |
69 |
| - description: description, |
70 |
| - }) |
71 |
| - ); |
72 |
| - |
73 |
| - // menu |
74 |
| - if (Array.isArray(menu)) { |
75 |
| - disposables.add( |
76 |
| - MenuRegistry.appendMenuItems( |
77 |
| - menu.map((item) => ({ |
78 |
| - id: item.id, |
79 |
| - item: { command, ...item }, |
80 |
| - })) |
81 |
| - ) |
82 |
| - ); |
83 |
| - } else if (menu) { |
84 |
| - disposables.add( |
85 |
| - MenuRegistry.appendMenuItem(menu.id, { command, ...menu }) |
86 |
| - ); |
87 |
| - } |
88 |
| - if (f1) { |
89 |
| - disposables.add( |
90 |
| - MenuRegistry.appendMenuItem(MenuId.CommandPalette, { |
91 |
| - command, |
92 |
| - when: command.precondition, |
93 |
| - }) |
94 |
| - ); |
95 |
| - disposables.add(MenuRegistry.addCommand(command)); |
96 |
| - } |
97 |
| - |
98 |
| - // keybinding |
99 |
| - if (Array.isArray(keybinding)) { |
100 |
| - for (const item of keybinding) { |
101 |
| - KeybindingsRegistry.registerKeybindingRule({ |
102 |
| - ...item, |
103 |
| - id: command.id, |
104 |
| - when: command.precondition |
105 |
| - ? ContextKeyExpr.and(command.precondition, item.when) |
106 |
| - : item.when, |
107 |
| - }); |
108 |
| - } |
109 |
| - } else if (keybinding) { |
110 |
| - KeybindingsRegistry.registerKeybindingRule({ |
111 |
| - ...keybinding, |
112 |
| - id: command.id, |
113 |
| - when: command.precondition |
114 |
| - ? ContextKeyExpr.and(command.precondition, keybinding.when) |
115 |
| - : keybinding.when, |
116 |
| - }); |
117 |
| - } |
118 |
| - |
119 |
| - return disposables; |
120 |
| -} |
0 commit comments