Skip to content

Commit a6eccc3

Browse files
author
Benjamin Pasero
committed
debt - adopt action2 for developer actions
1 parent 673e35d commit a6eccc3

1 file changed

Lines changed: 63 additions & 66 deletions

File tree

src/vs/workbench/browser/actions/developerActions.ts

Lines changed: 63 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import 'vs/css!./media/actions';
77

8-
import { Action } from 'vs/base/common/actions';
98
import * as nls from 'vs/nls';
109
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1110
import { domEvent } from 'vs/base/browser/event';
@@ -19,29 +18,31 @@ import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
1918
import { timeout } from 'vs/base/common/async';
2019
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
2120
import { Registry } from 'vs/platform/registry/common/platform';
22-
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
23-
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
21+
import { registerAction2, Action2 } from 'vs/platform/actions/common/actions';
2422
import { IStorageService } from 'vs/platform/storage/common/storage';
2523
import { clamp } from 'vs/base/common/numbers';
2624
import { KeyCode } from 'vs/base/common/keyCodes';
2725
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
2826
import { ILogService } from 'vs/platform/log/common/log';
2927
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
28+
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
3029

31-
class InspectContextKeysAction extends Action {
30+
const developerCategory = nls.localize({ key: 'developer', comment: ['A developer on Code itself or someone diagnosing issues in Code'] }, "Developer");
3231

33-
static readonly ID = 'workbench.action.inspectContextKeys';
34-
static readonly LABEL = nls.localize('inspect context keys', "Inspect Context Keys");
32+
class InspectContextKeysAction extends Action2 {
3533

36-
constructor(
37-
id: string,
38-
label: string,
39-
@IContextKeyService private readonly contextKeyService: IContextKeyService
40-
) {
41-
super(id, label);
34+
constructor() {
35+
super({
36+
id: 'workbench.action.inspectContextKeys',
37+
title: { value: nls.localize('inspect context keys', "Inspect Context Keys"), original: 'Developer: Inspect Context Keys' },
38+
category: developerCategory,
39+
f1: true
40+
});
4241
}
4342

44-
async run(): Promise<void> {
43+
run(accessor: ServicesAccessor): void {
44+
const contextKeyService = accessor.get(IContextKeyService);
45+
4546
const disposables = new DisposableStore();
4647

4748
const stylesheet = createStyleSheet();
@@ -80,41 +81,42 @@ class InspectContextKeysAction extends Action {
8081
e.preventDefault();
8182
e.stopPropagation();
8283

83-
const context = this.contextKeyService.getContext(e.target as HTMLElement) as Context;
84+
const context = contextKeyService.getContext(e.target as HTMLElement) as Context;
8485
console.log(context.collectAllValues());
8586

8687
dispose(disposables);
8788
}, null, disposables);
8889
}
8990
}
9091

91-
class ToggleScreencastModeAction extends Action {
9292

93-
static readonly ID = 'workbench.action.toggleScreencastMode';
94-
static readonly LABEL = nls.localize('toggle screencast mode', "Toggle Screencast Mode");
93+
class ToggleScreencastModeAction extends Action2 {
9594

9695
static disposable: IDisposable | undefined;
9796

98-
constructor(
99-
id: string,
100-
label: string,
101-
@IKeybindingService private readonly keybindingService: IKeybindingService,
102-
@ILayoutService private readonly layoutService: ILayoutService,
103-
@IConfigurationService private readonly configurationService: IConfigurationService
104-
) {
105-
super(id, label);
97+
constructor() {
98+
super({
99+
id: 'workbench.action.toggleScreencastMode',
100+
title: { value: nls.localize('toggle screencast mode', "Toggle Screencast Mode"), original: 'Developer: Toggle Screencast Mode' },
101+
category: developerCategory,
102+
f1: true
103+
});
106104
}
107105

108-
async run(): Promise<void> {
106+
run(accessor: ServicesAccessor): void {
109107
if (ToggleScreencastModeAction.disposable) {
110108
ToggleScreencastModeAction.disposable.dispose();
111109
ToggleScreencastModeAction.disposable = undefined;
112110
return;
113111
}
114112

113+
const layoutService = accessor.get(ILayoutService);
114+
const configurationService = accessor.get(IConfigurationService);
115+
const keybindingService = accessor.get(IKeybindingService);
116+
115117
const disposables = new DisposableStore();
116118

117-
const container = this.layoutService.container;
119+
const container = layoutService.container;
118120
const mouseMarker = append(container, $('.screencast-mouse'));
119121
disposables.add(toDisposable(() => mouseMarker.remove()));
120122

@@ -142,17 +144,17 @@ class ToggleScreencastModeAction extends Action {
142144
disposables.add(toDisposable(() => keyboardMarker.remove()));
143145

144146
const updateKeyboardFontSize = () => {
145-
keyboardMarker.style.fontSize = `${clamp(this.configurationService.getValue<number>('screencastMode.fontSize') || 56, 20, 100)}px`;
147+
keyboardMarker.style.fontSize = `${clamp(configurationService.getValue<number>('screencastMode.fontSize') || 56, 20, 100)}px`;
146148
};
147149

148150
const updateKeyboardMarker = () => {
149-
keyboardMarker.style.bottom = `${clamp(this.configurationService.getValue<number>('screencastMode.verticalOffset') || 0, 0, 90)}%`;
151+
keyboardMarker.style.bottom = `${clamp(configurationService.getValue<number>('screencastMode.verticalOffset') || 0, 0, 90)}%`;
150152
};
151153

152154
updateKeyboardFontSize();
153155
updateKeyboardMarker();
154156

155-
disposables.add(this.configurationService.onDidChangeConfiguration(e => {
157+
disposables.add(configurationService.onDidChangeConfiguration(e => {
156158
if (e.affectsConfiguration('screencastMode.verticalOffset')) {
157159
updateKeyboardMarker();
158160
}
@@ -170,9 +172,9 @@ class ToggleScreencastModeAction extends Action {
170172
keyboardTimeout.dispose();
171173

172174
const event = new StandardKeyboardEvent(e);
173-
const shortcut = this.keybindingService.softDispatch(event, event.target);
175+
const shortcut = keybindingService.softDispatch(event, event.target);
174176

175-
if (shortcut || !this.configurationService.getValue<boolean>('screencastMode.onlyKeyboardShortcuts')) {
177+
if (shortcut || !configurationService.getValue<boolean>('screencastMode.onlyKeyboardShortcuts')) {
176178
if (
177179
event.ctrlKey || event.altKey || event.metaKey || event.shiftKey
178180
|| length > 20
@@ -182,7 +184,7 @@ class ToggleScreencastModeAction extends Action {
182184
length = 0;
183185
}
184186

185-
const keybinding = this.keybindingService.resolveKeyboardEvent(event);
187+
const keybinding = keybindingService.resolveKeyboardEvent(event);
186188
const label = keybinding.getLabel();
187189
const key = $('span.key', {}, label || '');
188190
length++;
@@ -202,59 +204,54 @@ class ToggleScreencastModeAction extends Action {
202204
}
203205
}
204206

205-
class LogStorageAction extends Action {
207+
class LogStorageAction extends Action2 {
206208

207-
static readonly ID = 'workbench.action.logStorage';
208-
static readonly LABEL = nls.localize({ key: 'logStorage', comment: ['A developer only action to log the contents of the storage for the current window.'] }, "Log Storage Database Contents");
209-
210-
constructor(
211-
id: string,
212-
label: string,
213-
@IStorageService private readonly storageService: IStorageService
214-
) {
215-
super(id, label);
209+
constructor() {
210+
super({
211+
id: 'workbench.action.logStorage',
212+
title: { value: nls.localize({ key: 'logStorage', comment: ['A developer only action to log the contents of the storage for the current window.'] }, "Log Storage Database Contents"), original: 'Developer: Log Storage Database Contents' },
213+
category: developerCategory,
214+
f1: true
215+
});
216216
}
217217

218-
async run(): Promise<void> {
219-
this.storageService.logStorage();
218+
run(accessor: ServicesAccessor): void {
219+
accessor.get(IStorageService).logStorage();
220220
}
221221
}
222222

223-
class LogWorkingCopiesAction extends Action {
224-
225-
static readonly ID = 'workbench.action.logWorkingCopies';
226-
static readonly LABEL = nls.localize({ key: 'logWorkingCopies', comment: ['A developer only action to log the working copies that exist.'] }, "Log Working Copies");
223+
class LogWorkingCopiesAction extends Action2 {
227224

228-
constructor(
229-
id: string,
230-
label: string,
231-
@ILogService private logService: ILogService,
232-
@IWorkingCopyService private workingCopyService: IWorkingCopyService
233-
) {
234-
super(id, label);
225+
constructor() {
226+
super({
227+
id: 'workbench.action.logWorkingCopies',
228+
title: { value: nls.localize({ key: 'logWorkingCopies', comment: ['A developer only action to log the working copies that exist.'] }, "Log Working Copies"), original: 'Developer: Log Working Copies' },
229+
category: developerCategory,
230+
f1: true
231+
});
235232
}
236233

237-
async run(): Promise<void> {
234+
run(accessor: ServicesAccessor): void {
235+
const workingCopyService = accessor.get(IWorkingCopyService);
236+
const logService = accessor.get(ILogService);
238237
const msg = [
239238
`Dirty Working Copies:`,
240-
...this.workingCopyService.dirtyWorkingCopies.map(workingCopy => workingCopy.resource.toString(true)),
239+
...workingCopyService.dirtyWorkingCopies.map(workingCopy => workingCopy.resource.toString(true)),
241240
``,
242241
`All Working Copies:`,
243-
...this.workingCopyService.workingCopies.map(workingCopy => workingCopy.resource.toString(true)),
242+
...workingCopyService.workingCopies.map(workingCopy => workingCopy.resource.toString(true)),
244243
];
245244

246-
this.logService.info(msg.join('\n'));
245+
logService.info(msg.join('\n'));
247246
}
248247
}
249248

250249
// --- Actions Registration
250+
registerAction2(InspectContextKeysAction);
251+
registerAction2(ToggleScreencastModeAction);
252+
registerAction2(LogStorageAction);
253+
registerAction2(LogWorkingCopiesAction);
251254

252-
const developerCategory = nls.localize({ key: 'developer', comment: ['A developer on Code itself or someone diagnosing issues in Code'] }, "Developer");
253-
const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
254-
registry.registerWorkbenchAction(SyncActionDescriptor.from(InspectContextKeysAction), 'Developer: Inspect Context Keys', developerCategory);
255-
registry.registerWorkbenchAction(SyncActionDescriptor.from(ToggleScreencastModeAction), 'Developer: Toggle Screencast Mode', developerCategory);
256-
registry.registerWorkbenchAction(SyncActionDescriptor.from(LogStorageAction), 'Developer: Log Storage Database Contents', developerCategory);
257-
registry.registerWorkbenchAction(SyncActionDescriptor.from(LogWorkingCopiesAction), 'Developer: Log Working Copies', developerCategory);
258255

259256
// Screencast Mode
260257
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);

0 commit comments

Comments
 (0)