Skip to content

Commit

Permalink
use registerAction2 (#163174)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Oct 10, 2022
1 parent 3a3177c commit 77f39a3
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 32 deletions.
21 changes: 16 additions & 5 deletions src/vs/workbench/contrib/logs/browser/logs.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
*--------------------------------------------------------------------------------------------*/

import { Registry } from 'vs/platform/registry/common/platform';
import { IWorkbenchActionRegistry, Extensions as WorkbenchActionExtensions } from 'vs/workbench/common/actions';
import { Categories } from 'vs/platform/action/common/actionCommonCategories';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
import { OpenWindowSessionLogFileAction } from 'vs/workbench/contrib/logs/common/logsActions';
import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { Disposable } from 'vs/base/common/lifecycle';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { LogsDataCleaner } from 'vs/workbench/contrib/logs/common/logsDataCleaner';

class WebLogOutputChannels extends Disposable implements IWorkbenchContribution {
Expand All @@ -26,8 +25,20 @@ class WebLogOutputChannels extends Disposable implements IWorkbenchContribution
private registerWebContributions(): void {
this.instantiationService.createInstance(LogsDataCleaner);

const workbenchActionsRegistry = Registry.as<IWorkbenchActionRegistry>(WorkbenchActionExtensions.WorkbenchActions);
workbenchActionsRegistry.registerWorkbenchAction(SyncActionDescriptor.from(OpenWindowSessionLogFileAction), 'Developer: Open Window Log File (Session)...', Categories.Developer.value);
registerAction2(class extends Action2 {
constructor() {
super({
id: OpenWindowSessionLogFileAction.ID,
title: OpenWindowSessionLogFileAction.TITLE,
category: Categories.Developer,
f1: true
});
}
run(servicesAccessor: ServicesAccessor): Promise<void> {
return servicesAccessor.get(IInstantiationService).createInstance(OpenWindowSessionLogFileAction, OpenWindowSessionLogFileAction.ID, OpenWindowSessionLogFileAction.TITLE.value).run();
}
});

}

}
Expand Down
20 changes: 15 additions & 5 deletions src/vs/workbench/contrib/logs/common/logs.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

import * as nls from 'vs/nls';
import { Registry } from 'vs/platform/registry/common/platform';
import { IWorkbenchActionRegistry, Extensions as WorkbenchActionExtensions } from 'vs/workbench/common/actions';
import { Categories } from 'vs/platform/action/common/actionCommonCategories';
import { Action2, registerAction2, SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
import { SetLogLevelAction } from 'vs/workbench/contrib/logs/common/logsActions';
import * as Constants from 'vs/workbench/contrib/logs/common/logConstants';
import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
Expand All @@ -17,13 +16,24 @@ import { IOutputService, registerLogChannel } from 'vs/workbench/services/output
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
import { IProductService } from 'vs/platform/product/common/productService';
import { URI } from 'vs/base/common/uri';

const workbenchActionsRegistry = Registry.as<IWorkbenchActionRegistry>(WorkbenchActionExtensions.WorkbenchActions);
workbenchActionsRegistry.registerWorkbenchAction(SyncActionDescriptor.from(SetLogLevelAction), 'Developer: Set Log Level...', Categories.Developer.value);
registerAction2(class extends Action2 {
constructor() {
super({
id: SetLogLevelAction.ID,
title: SetLogLevelAction.TITLE,
category: Categories.Developer,
f1: true
});
}
run(servicesAccessor: ServicesAccessor): Promise<void> {
return servicesAccessor.get(IInstantiationService).createInstance(SetLogLevelAction, SetLogLevelAction.ID, SetLogLevelAction.TITLE.value).run();
}
});

class LogOutputChannels extends Disposable implements IWorkbenchContribution {

Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/logs/common/logsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
export class SetLogLevelAction extends Action {

static readonly ID = 'workbench.action.setLogLevel';
static readonly LABEL = nls.localize('setLogLevel', "Set Log Level...");
static readonly TITLE = { value: nls.localize('setLogLevel', "Set Log Level..."), original: 'Set Log Level...' };

constructor(id: string, label: string,
@IQuickInputService private readonly quickInputService: IQuickInputService,
Expand Down Expand Up @@ -61,7 +61,7 @@ export class SetLogLevelAction extends Action {
export class OpenWindowSessionLogFileAction extends Action {

static readonly ID = 'workbench.action.openSessionLogFile';
static readonly LABEL = nls.localize('openSessionLogFile', "Open Window Log File (Session)...");
static readonly TITLE = { value: nls.localize('openSessionLogFile', "Open Window Log File (Session)..."), original: 'Open Window Log File (Session)...' };

constructor(id: string, label: string,
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

import * as nls from 'vs/nls';
import { Registry } from 'vs/platform/registry/common/platform';
import { IWorkbenchActionRegistry, Extensions as WorkbenchActionExtensions } from 'vs/workbench/common/actions';
import { Categories } from 'vs/platform/action/common/actionCommonCategories';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
import { OpenLogsFolderAction, OpenExtensionLogsFolderAction } from 'vs/workbench/contrib/logs/electron-sandbox/logsActions';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions, IWorkbenchContribution } from 'vs/workbench/common/contributions';
import * as Constants from 'vs/workbench/contrib/logs/common/logConstants';
Expand All @@ -19,6 +18,8 @@ import { URI } from 'vs/base/common/uri';
import { join } from 'vs/base/common/path';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { registerLogChannel } from 'vs/workbench/services/output/common/output';
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';

class NativeLogOutputChannels extends Disposable implements IWorkbenchContribution {

Expand All @@ -43,8 +44,32 @@ class NativeLogOutputChannels extends Disposable implements IWorkbenchContributi

}

Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(NativeLogOutputChannels, LifecyclePhase.Restored);
registerAction2(class extends Action2 {
constructor() {
super({
id: OpenLogsFolderAction.ID,
title: OpenLogsFolderAction.TITLE,
category: Categories.Developer,
f1: true
});
}
run(servicesAccessor: ServicesAccessor): Promise<void> {
return servicesAccessor.get(IInstantiationService).createInstance(OpenLogsFolderAction, OpenLogsFolderAction.ID, OpenLogsFolderAction.TITLE.value).run();
}
});

const workbenchActionsRegistry = Registry.as<IWorkbenchActionRegistry>(WorkbenchActionExtensions.WorkbenchActions);
workbenchActionsRegistry.registerWorkbenchAction(SyncActionDescriptor.from(OpenLogsFolderAction), 'Developer: Open Logs Folder', Categories.Developer.value);
workbenchActionsRegistry.registerWorkbenchAction(SyncActionDescriptor.from(OpenExtensionLogsFolderAction), 'Developer: Open Extension Logs Folder', Categories.Developer.value);
registerAction2(class extends Action2 {
constructor() {
super({
id: OpenExtensionLogsFolderAction.ID,
title: OpenExtensionLogsFolderAction.TITLE,
category: Categories.Developer,
f1: true
});
}
run(servicesAccessor: ServicesAccessor): Promise<void> {
return servicesAccessor.get(IInstantiationService).createInstance(OpenExtensionLogsFolderAction, OpenExtensionLogsFolderAction.ID, OpenExtensionLogsFolderAction.TITLE.value).run();
}
});

Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(NativeLogOutputChannels, LifecyclePhase.Restored);
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/logs/electron-sandbox/logsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { IFileService } from 'vs/platform/files/common/files';
export class OpenLogsFolderAction extends Action {

static readonly ID = 'workbench.action.openLogsFolder';
static readonly LABEL = nls.localize('openLogsFolder', "Open Logs Folder");
static readonly TITLE = { value: nls.localize('openLogsFolder', "Open Logs Folder"), original: 'Open Logs Folder' };

constructor(id: string, label: string,
@INativeWorkbenchEnvironmentService private readonly environmentService: INativeWorkbenchEnvironmentService,
Expand All @@ -31,7 +31,7 @@ export class OpenLogsFolderAction extends Action {
export class OpenExtensionLogsFolderAction extends Action {

static readonly ID = 'workbench.action.openExtensionLogsFolder';
static readonly LABEL = nls.localize('openExtensionLogsFolder', "Open Extension Logs Folder");
static readonly TITLE = { value: nls.localize('openExtensionLogsFolder', "Open Extension Logs Folder"), original: 'Open Extension Logs Folder' };

constructor(id: string, label: string,
@INativeWorkbenchEnvironmentService private readonly environmentSerice: INativeWorkbenchEnvironmentService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
import * as assert from 'assert';
import * as uuid from 'vs/base/common/uuid';
import { OS, OperatingSystem } from 'vs/base/common/platform';
import { Registry } from 'vs/platform/registry/common/platform';
import { Action } from 'vs/base/common/actions';
import { KeyCode } from 'vs/base/common/keyCodes';
import { SimpleKeybinding, ChordKeybinding } from 'vs/base/common/keybindings';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
Expand All @@ -22,6 +18,7 @@ import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayo

import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { IKeybindingItemEntry } from 'vs/workbench/services/preferences/common/preferences';
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';

interface Modifiers {
metaKey?: boolean;
Expand All @@ -30,12 +27,6 @@ interface Modifiers {
shiftKey?: boolean;
}

class AnAction extends Action {
constructor(id: string) {
super(id);
}
}

suite('KeybindingsEditorModel', () => {

let instantiationService: TestInstantiationService;
Expand Down Expand Up @@ -677,8 +668,16 @@ suite('KeybindingsEditorModel', () => {
}

function registerCommandWithTitle(command: string, title: string): void {
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
registry.registerWorkbenchAction(SyncActionDescriptor.create(AnAction, command, title, { primary: 0 }), '');
registerAction2(class extends Action2 {
constructor() {
super({
id: command,
title,
f1: true
});
}
async run(): Promise<void> { }
});
}

function assertKeybindingItems(actual: ResolvedKeybindingItem[], expected: ResolvedKeybindingItem[]) {
Expand Down

0 comments on commit 77f39a3

Please sign in to comment.