提交 ebcd231a 编写于 作者: J Johannes Rieken

remove registerAction infavor of `registerAction2`

上级 d5b37e30
......@@ -8,7 +8,7 @@ import { SyncDescriptor0, createSyncDescriptor } from 'vs/platform/instantiation
import { IConstructorSignature2, createDecorator, BrandedService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IKeybindings, KeybindingsRegistry, IKeybindingRule } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { ICommandService, ICommandHandler, CommandsRegistry } from 'vs/platform/commands/common/commands';
import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event';
import { URI, UriComponents } from 'vs/base/common/uri';
......@@ -343,67 +343,6 @@ export class SyncActionDescriptor {
}
}
export interface IActionDescriptor {
id: string;
handler: ICommandHandler;
// ICommandUI
title?: ILocalizedString;
category?: string;
f1?: boolean;
//
menu?: {
menuId: MenuId,
when?: ContextKeyExpr;
group?: string;
};
//
keybinding?: {
when?: ContextKeyExpr;
weight?: number;
keys: IKeybindings;
};
}
export function registerAction(desc: IActionDescriptor) {
const { id, handler, title, category, menu, keybinding } = desc;
// 1) register as command
CommandsRegistry.registerCommand(id, handler);
// 2) menus
if (menu && title) {
let command = { id, title, category };
let { menuId, when, group } = menu;
MenuRegistry.appendMenuItem(menuId, {
command,
when,
group
});
}
// 3) keybindings
if (keybinding) {
let { when, weight, keys } = keybinding;
KeybindingsRegistry.registerKeybindingRule({
id,
when,
weight: weight || 0,
primary: keys.primary,
secondary: keys.secondary,
linux: keys.linux,
mac: keys.mac,
win: keys.win
});
}
}
//#region --- IAction2
export interface IAction2Description extends ICommandAction {
......@@ -414,7 +353,7 @@ export interface IAction2Description extends ICommandAction {
export interface IAction2 {
readonly desc: IAction2Description;
run(accessor: ServicesAccessor, args: any[]): any;
run(accessor: ServicesAccessor, ...args: any): any;
}
export function registerAction2(action: IAction2): IDisposable {
......@@ -422,7 +361,7 @@ export function registerAction2(action: IAction2): IDisposable {
disposables.add(CommandsRegistry.registerCommand({
id: action.desc.id,
handler: (accessor, ...args) => action.run(accessor, args),
handler: (accessor, ...args) => action.run(accessor, ...args),
description: undefined,
}));
......
......@@ -6,7 +6,7 @@
import { localize } from 'vs/nls';
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
import { Registry } from 'vs/platform/registry/common/platform';
import { SyncActionDescriptor, MenuRegistry, MenuId, registerAction } from 'vs/platform/actions/common/actions';
import { SyncActionDescriptor, MenuRegistry, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { ExtensionsLabel, ExtensionsChannelId, PreferencesLabel, IExtensionManagementService, IExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IExtensionManagementServerService, IExtensionTipsService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
......@@ -341,10 +341,16 @@ MenuRegistry.appendMenuItem(MenuId.GlobalActivity, {
// Extension Context Menu
registerAction({
id: 'workbench.extensions.action.copyExtension',
title: { value: localize('workbench.extensions.action.copyExtension', "Copy"), original: 'Copy' },
async handler(accessor, extensionId: string) {
registerAction2({
desc: {
id: 'workbench.extensions.action.copyExtension',
title: { value: localize('workbench.extensions.action.copyExtension', "Copy"), original: 'Copy' },
menu: {
id: MenuId.ExtensionContext,
group: '1_copy'
}
},
async run(accessor, extensionId: string) {
const extensionWorkbenchService = accessor.get(IExtensionsWorkbenchService);
let extension = extensionWorkbenchService.local.filter(e => areSameExtensions(e.identifier, { id: extensionId }))[0]
|| (await extensionWorkbenchService.queryGallery({ names: [extensionId], pageSize: 1 }, CancellationToken.None)).firstPage[0];
......@@ -358,37 +364,36 @@ registerAction({
const clipboardStr = `${name}\n${id}\n${description}\n${verision}\n${publisher}${link ? '\n' + link : ''}`;
await accessor.get(IClipboardService).writeText(clipboardStr);
}
},
menu: {
menuId: MenuId.ExtensionContext,
group: '1_copy'
},
}
});
registerAction({
id: 'workbench.extensions.action.copyExtensionId',
title: { value: localize('workbench.extensions.action.copyExtensionId', "Copy Extension Id"), original: 'Copy Extension Id' },
async handler(accessor, id: string) {
await accessor.get(IClipboardService).writeText(id);
registerAction2({
desc: {
id: 'workbench.extensions.action.copyExtensionId',
title: { value: localize('workbench.extensions.action.copyExtensionId', "Copy Extension Id"), original: 'Copy Extension Id' },
menu: {
id: MenuId.ExtensionContext,
group: '1_copy'
}
},
menu: {
menuId: MenuId.ExtensionContext,
group: '1_copy'
async run(accessor, id: string) {
await accessor.get(IClipboardService).writeText(id);
},
});
registerAction({
id: 'workbench.extensions.action.configure',
title: { value: localize('workbench.extensions.action.configure', "Configure..."), original: 'Configure...' },
async handler(accessor, id: string) {
await accessor.get(IPreferencesService).openSettings(false, `@ext:${id}`);
registerAction2({
desc: {
id: 'workbench.extensions.action.configure',
title: { value: localize('workbench.extensions.action.configure', "Configure..."), original: 'Configure...' },
menu: {
id: MenuId.ExtensionContext,
group: '2_configure',
when: ContextKeyExpr.and(ContextKeyExpr.equals('extensionStatus', 'installed'), ContextKeyExpr.has('extensionHasConfiguration'))
}
},
menu: {
menuId: MenuId.ExtensionContext,
group: '2_configure',
when: ContextKeyExpr.and(ContextKeyExpr.equals('extensionStatus', 'installed'), ContextKeyExpr.has('extensionHasConfiguration'))
async run(accessor, id: string) {
await accessor.get(IPreferencesService).openSettings(false, `@ext:${id}`);
},
});
const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
......
......@@ -13,7 +13,7 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { localize } from 'vs/nls';
import { Marker, RelatedInformation } from 'vs/workbench/contrib/markers/browser/markersModel';
import { MarkersView, getMarkersView } from 'vs/workbench/contrib/markers/browser/markersView';
import { MenuId, MenuRegistry, SyncActionDescriptor, registerAction } from 'vs/platform/actions/common/actions';
import { MenuId, MenuRegistry, SyncActionDescriptor, registerAction2 } from 'vs/platform/actions/common/actions';
import { TogglePanelAction } from 'vs/workbench/browser/panel';
import { Registry } from 'vs/platform/registry/common/platform';
import { ShowProblemsPanelAction } from 'vs/workbench/contrib/markers/browser/markersViewActions';
......@@ -136,103 +136,113 @@ registry.registerWorkbenchAction(SyncActionDescriptor.create(ToggleMarkersPanelA
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_M
}), 'View: Toggle Problems (Errors, Warnings, Infos)', Messages.MARKERS_PANEL_VIEW_CATEGORY);
registry.registerWorkbenchAction(SyncActionDescriptor.create(ShowProblemsPanelAction, ShowProblemsPanelAction.ID, ShowProblemsPanelAction.LABEL), 'View: Focus Problems (Errors, Warnings, Infos)', Messages.MARKERS_PANEL_VIEW_CATEGORY);
registerAction({
id: Constants.MARKER_COPY_ACTION_ID,
title: { value: localize('copyMarker', "Copy"), original: 'Copy' },
async handler(accessor) {
await copyMarker(accessor.get(IPanelService), accessor.get(IClipboardService));
registerAction2({
desc: {
id: Constants.MARKER_COPY_ACTION_ID,
title: { value: localize('copyMarker', "Copy"), original: 'Copy' },
menu: {
id: MenuId.ProblemsPanelContext,
when: Constants.MarkerFocusContextKey,
group: 'navigation'
},
keybinding: {
weight: KeybindingWeight.WorkbenchContrib,
primary: KeyMod.CtrlCmd | KeyCode.KEY_C,
when: Constants.MarkerFocusContextKey
},
},
menu: {
menuId: MenuId.ProblemsPanelContext,
when: Constants.MarkerFocusContextKey,
group: 'navigation'
async run(accessor) {
await copyMarker(accessor.get(IPanelService), accessor.get(IClipboardService));
},
keybinding: {
weight: KeybindingWeight.WorkbenchContrib,
keys: {
primary: KeyMod.CtrlCmd | KeyCode.KEY_C
},
when: Constants.MarkerFocusContextKey
}
});
registerAction({
id: Constants.MARKER_COPY_MESSAGE_ACTION_ID,
title: { value: localize('copyMessage', "Copy Message"), original: 'Copy Message' },
async handler(accessor) {
registerAction2({
desc: {
id: Constants.MARKER_COPY_MESSAGE_ACTION_ID,
title: { value: localize('copyMessage', "Copy Message"), original: 'Copy Message' },
menu: {
id: MenuId.ProblemsPanelContext,
when: Constants.MarkerFocusContextKey,
group: 'navigation'
},
},
async run(accessor) {
await copyMessage(accessor.get(IPanelService), accessor.get(IClipboardService));
},
menu: {
menuId: MenuId.ProblemsPanelContext,
when: Constants.MarkerFocusContextKey,
group: 'navigation'
}
});
registerAction({
id: Constants.RELATED_INFORMATION_COPY_MESSAGE_ACTION_ID,
title: { value: localize('copyMessage', "Copy Message"), original: 'Copy Message' },
async handler(accessor) {
await copyRelatedInformationMessage(accessor.get(IPanelService), accessor.get(IClipboardService));
registerAction2({
desc: {
id: Constants.RELATED_INFORMATION_COPY_MESSAGE_ACTION_ID,
title: { value: localize('copyMessage', "Copy Message"), original: 'Copy Message' },
menu: {
id: MenuId.ProblemsPanelContext,
when: Constants.RelatedInformationFocusContextKey,
group: 'navigation'
}
},
menu: {
menuId: MenuId.ProblemsPanelContext,
when: Constants.RelatedInformationFocusContextKey,
group: 'navigation'
async run(accessor) {
await copyRelatedInformationMessage(accessor.get(IPanelService), accessor.get(IClipboardService));
}
});
registerAction({
id: Constants.FOCUS_PROBLEMS_FROM_FILTER,
handler(accessor) {
focusProblemsView(accessor.get(IPanelService));
},
keybinding: {
when: Constants.MarkerPanelFilterFocusContextKey,
weight: KeybindingWeight.WorkbenchContrib,
keys: {
registerAction2({
desc: {
id: Constants.FOCUS_PROBLEMS_FROM_FILTER,
title: localize('focusProblemsList', "Focus problems view"),
keybinding: {
when: Constants.MarkerPanelFilterFocusContextKey,
weight: KeybindingWeight.WorkbenchContrib,
primary: KeyMod.CtrlCmd | KeyCode.DownArrow
},
}
},
run(accessor) {
focusProblemsView(accessor.get(IPanelService));
}
});
registerAction({
id: Constants.MARKERS_PANEL_FOCUS_FILTER,
handler(accessor) {
focusProblemsFilter(accessor.get(IPanelService));
},
keybinding: {
when: Constants.MarkerPanelFocusContextKey,
weight: KeybindingWeight.WorkbenchContrib,
keys: {
registerAction2({
desc: {
id: Constants.MARKERS_PANEL_FOCUS_FILTER,
title: localize('focusProblemsFilter', "Focus problems filter"),
keybinding: {
when: Constants.MarkerPanelFocusContextKey,
weight: KeybindingWeight.WorkbenchContrib,
primary: KeyMod.CtrlCmd | KeyCode.KEY_F
},
}
},
run(accessor) {
focusProblemsFilter(accessor.get(IPanelService));
}
});
registerAction({
id: Constants.MARKERS_PANEL_SHOW_MULTILINE_MESSAGE,
handler(accessor) {
registerAction2({
desc: {
id: Constants.MARKERS_PANEL_SHOW_MULTILINE_MESSAGE,
title: { value: localize('show multiline', "Show message in multiple lines"), original: 'Problems: Show message in multiple lines' },
category: localize('problems', "Problems"),
menu: {
id: MenuId.CommandPalette,
when: ActivePanelContext.isEqualTo(Constants.MARKERS_PANEL_ID)
}
},
run(accessor) {
const markersView = getMarkersView(accessor.get(IPanelService));
if (markersView) {
markersView.markersViewModel.multiline = true;
}
},
title: { value: localize('show multiline', "Show message in multiple lines"), original: 'Problems: Show message in multiple lines' },
category: localize('problems', "Problems"),
menu: {
menuId: MenuId.CommandPalette,
when: ActivePanelContext.isEqualTo(Constants.MARKERS_PANEL_ID)
}
});
registerAction({
id: Constants.MARKERS_PANEL_SHOW_SINGLELINE_MESSAGE,
handler(accessor) {
registerAction2({
desc: {
id: Constants.MARKERS_PANEL_SHOW_SINGLELINE_MESSAGE,
title: { value: localize('show singleline', "Show message in single line"), original: 'Problems: Show message in single line' },
category: localize('problems', "Problems"),
menu: {
id: MenuId.CommandPalette,
when: ActivePanelContext.isEqualTo(Constants.MARKERS_PANEL_ID)
}
},
run(accessor) {
const markersView = getMarkersView(accessor.get(IPanelService));
if (markersView) {
markersView.markersViewModel.multiline = false;
}
},
title: { value: localize('show singleline', "Show message in single line"), original: 'Problems: Show message in single line' },
category: localize('problems', "Problems"),
menu: {
menuId: MenuId.CommandPalette,
when: ActivePanelContext.isEqualTo(Constants.MARKERS_PANEL_ID)
}
});
......
......@@ -7,7 +7,7 @@ import * as nls from 'vs/nls';
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
import { ModesRegistry } from 'vs/editor/common/modes/modesRegistry';
import { Registry } from 'vs/platform/registry/common/platform';
import { MenuId, MenuRegistry, SyncActionDescriptor, registerAction } from 'vs/platform/actions/common/actions';
import { MenuId, MenuRegistry, SyncActionDescriptor, registerAction2 } from 'vs/platform/actions/common/actions';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { OutputService, LogContentProvider } from 'vs/workbench/contrib/output/browser/outputServices';
......@@ -89,14 +89,16 @@ actionRegistry.registerWorkbenchAction(SyncActionDescriptor.create(ShowLogsOutpu
actionRegistry.registerWorkbenchAction(SyncActionDescriptor.create(OpenOutputLogFileAction, OpenOutputLogFileAction.ID, OpenOutputLogFileAction.LABEL), 'Developer: Open Log File...', devCategory);
// Define clear command, contribute to editor context menu
registerAction({
id: 'editor.action.clearoutput',
title: { value: nls.localize('clearOutput.label', "Clear Output"), original: 'Clear Output' },
menu: {
menuId: MenuId.EditorContext,
when: CONTEXT_IN_OUTPUT
registerAction2({
desc: {
id: 'editor.action.clearoutput',
title: { value: nls.localize('clearOutput.label', "Clear Output"), original: 'Clear Output' },
menu: {
id: MenuId.EditorContext,
when: CONTEXT_IN_OUTPUT
},
},
handler(accessor) {
run(accessor) {
const activeChannel = accessor.get(IOutputService).getActiveChannel();
if (activeChannel) {
activeChannel.clear();
......@@ -104,14 +106,16 @@ registerAction({
}
});
registerAction({
id: 'workbench.action.openActiveLogOutputFile',
title: { value: nls.localize('openActiveLogOutputFile', "Open Active Log Output File"), original: 'Open Active Log Output File' },
menu: {
menuId: MenuId.CommandPalette,
when: CONTEXT_ACTIVE_LOG_OUTPUT
registerAction2({
desc: {
id: 'workbench.action.openActiveLogOutputFile',
title: { value: nls.localize('openActiveLogOutputFile', "Open Active Log Output File"), original: 'Open Active Log Output File' },
menu: {
id: MenuId.CommandPalette,
when: CONTEXT_ACTIVE_LOG_OUTPUT
},
},
handler(accessor) {
run(accessor) {
accessor.get(IInstantiationService).createInstance(OpenLogOutputFile).run();
}
});
......
......@@ -12,7 +12,7 @@ import { Disposable } from 'vs/base/common/lifecycle';
import { isMacintosh } from 'vs/base/common/platform';
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { MenuId, IMenuService, MenuItemAction, IMenu, MenuRegistry, registerAction } from 'vs/platform/actions/common/actions';
import { MenuId, IMenuService, MenuItemAction, IMenu, MenuRegistry, registerAction2 } from 'vs/platform/actions/common/actions';
import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchContributionsExtensions } from 'vs/workbench/common/contributions';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { StatusbarAlignment, IStatusbarService, IStatusbarEntryAccessor, IStatusbarEntry } from 'vs/workbench/services/statusbar/common/statusbar';
......@@ -71,28 +71,28 @@ export class RemoteWindowActiveIndicator extends Disposable implements IWorkbenc
const category = nls.localize('remote.category', "Remote");
registerAction({
id: WINDOW_ACTIONS_COMMAND_ID,
category,
title: { value: nls.localize('remote.showMenu', "Show Remote Menu"), original: 'Show Remote Menu' },
menu: {
menuId: MenuId.CommandPalette
registerAction2({
desc: {
id: WINDOW_ACTIONS_COMMAND_ID,
category,
title: { value: nls.localize('remote.showMenu', "Show Remote Menu"), original: 'Show Remote Menu' },
f1: true,
},
handler: (_accessor) => this.showIndicatorActions(this.windowCommandMenu)
run: () => this.showIndicatorActions(this.windowCommandMenu)
});
this.remoteAuthority = environmentService.configuration.remoteAuthority;
Deprecated_RemoteAuthorityContext.bindTo(this.contextKeyService).set(this.remoteAuthority || '');
if (this.remoteAuthority) {
registerAction({
id: CLOSE_REMOTE_COMMAND_ID,
category,
title: { value: nls.localize('remote.close', "Close Remote Connection"), original: 'Close Remote Connection' },
menu: {
menuId: MenuId.CommandPalette
registerAction2({
desc: {
id: CLOSE_REMOTE_COMMAND_ID,
category,
title: { value: nls.localize('remote.close', "Close Remote Connection"), original: 'Close Remote Connection' },
f1: true
},
handler: (_accessor) => this.remoteAuthority && hostService.openWindow({ forceReuseWindow: true })
run: () => this.remoteAuthority && hostService.openWindow({ forceReuseWindow: true })
});
// Pending entry until extensions are ready
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册