Skip to content

Commit a562dab

Browse files
author
Eric Amodio
committed
Removes menu.command from registerAction2
1 parent eb4ebee commit a562dab

2 files changed

Lines changed: 38 additions & 43 deletions

File tree

src/vs/platform/actions/common/actions.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ export interface IAction2Options extends ICommandAction {
373373
/**
374374
* One or many menu items.
375375
*/
376-
menu?: OneOrN<{ id: MenuId } & Omit<IMenuItem, 'command'> & { command?: Partial<Omit<ICommandAction, 'id'>> }>;
376+
menu?: OneOrN<{ id: MenuId } & Omit<IMenuItem, 'command'>>;
377377

378378
/**
379379
* One keybinding.
@@ -396,7 +396,7 @@ export function registerAction2(ctor: { new(): Action2 }): IDisposable {
396396
const disposables = new DisposableStore();
397397
const action = new ctor();
398398

399-
const { f1, menu: menus, keybinding, description, ...command } = action.desc;
399+
const { f1, menu, keybinding, description, ...command } = action.desc;
400400

401401
// command
402402
disposables.add(CommandsRegistry.registerCommand({
@@ -406,14 +406,12 @@ export function registerAction2(ctor: { new(): Action2 }): IDisposable {
406406
}));
407407

408408
// menu
409-
if (Array.isArray(menus)) {
410-
for (let item of menus) {
411-
const { command: commandOverrides, ...menu } = item;
412-
disposables.add(MenuRegistry.appendMenuItem(item.id, { command: { ...command, ...commandOverrides }, ...menu }));
409+
if (Array.isArray(menu)) {
410+
for (let item of menu) {
411+
disposables.add(MenuRegistry.appendMenuItem(item.id, { command: { ...command }, ...item }));
413412
}
414-
} else if (menus) {
415-
const { command: commandOverrides, ...menu } = menus;
416-
disposables.add(MenuRegistry.appendMenuItem(menu.id, { command: { ...command, ...commandOverrides }, ...menu }));
413+
} else if (menu) {
414+
disposables.add(MenuRegistry.appendMenuItem(menu.id, { command: { ...command }, ...menu }));
417415
}
418416
if (f1) {
419417
disposables.add(MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: command }));

src/vs/workbench/contrib/timeline/browser/timelinePane.ts

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiati
2424
import { ITimelineService, TimelineChangeEvent, TimelineItem, TimelineOptions, TimelineProvidersChangeEvent, TimelineRequest, Timeline, TimelinePaneId } from 'vs/workbench/contrib/timeline/common/timeline';
2525
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
2626
import { SideBySideEditor, toResource } from 'vs/workbench/common/editor';
27-
import { ICommandService } from 'vs/platform/commands/common/commands';
27+
import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/commands';
2828
import { IThemeService, LIGHT, ThemeIcon } from 'vs/platform/theme/common/themeService';
2929
import { IViewDescriptorService } from 'vs/workbench/common/views';
3030
import { basename } from 'vs/base/common/path';
@@ -34,7 +34,7 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
3434
import { IActionViewItemProvider, ActionBar, ActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
3535
import { IAction, ActionRunner } from 'vs/base/common/actions';
3636
import { ContextAwareMenuEntryActionViewItem, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
37-
import { MenuItemAction, IMenuService, MenuId, registerAction2, Action2 } from 'vs/platform/actions/common/actions';
37+
import { MenuItemAction, IMenuService, MenuId, registerAction2, Action2, MenuRegistry } from 'vs/platform/actions/common/actions';
3838
import { fromNow } from 'vs/base/common/date';
3939
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
4040
import { escapeRegExpCharacters } from 'vs/base/common/strings';
@@ -932,38 +932,35 @@ class TimelinePaneCommands extends Disposable {
932932
}
933933
}));
934934

935-
this._register(registerAction2(class extends Action2 {
936-
constructor() {
937-
super({
938-
id: 'timeline.toggleFollowActiveEditor',
939-
title: { value: localize('timeline.toggleFollowActiveEditorCommand', "Toggle Active Editor Following"), original: 'Toggle Active Editor Following' },
940-
category: { value: localize('timeline', "Timeline"), original: 'Timeline' },
941-
menu: [{
942-
id: MenuId.TimelineTitle,
943-
command: {
944-
// title: localize(`timeline.toggleFollowActiveEditorCommand.stop`, "Stop following the Active Editor"),
945-
icon: { id: 'codicon/eye' }
946-
},
947-
group: 'navigation',
948-
order: 98,
949-
when: TimelineFollowActiveEditorContext
950-
},
951-
{
952-
id: MenuId.TimelineTitle,
953-
command: {
954-
// title: localize(`ToggleFollowActiveEditorCommand.follow`, "Follow the Active Editor"),
955-
icon: { id: 'codicon/eye-closed' }
956-
},
957-
group: 'navigation',
958-
order: 98,
959-
when: TimelineFollowActiveEditorContext.toNegated()
960-
}]
961-
});
962-
}
963-
run(accessor: ServicesAccessor, ...args: any[]) {
964-
pane.followActiveEditor = !pane.followActiveEditor;
965-
}
966-
}));
935+
this._register(CommandsRegistry.registerCommand('timeline.toggleFollowActiveEditor',
936+
(accessor: ServicesAccessor, ...args: any[]) => pane.followActiveEditor = !pane.followActiveEditor
937+
));
938+
939+
this._register(MenuRegistry.appendMenuItem(MenuId.TimelineTitle, ({
940+
command: {
941+
id: 'timeline.toggleFollowActiveEditor',
942+
title: { value: localize('timeline.toggleFollowActiveEditorCommand', "Toggle Active Editor Following"), original: 'Toggle Active Editor Following' },
943+
// title: localize(`timeline.toggleFollowActiveEditorCommand.stop`, "Stop following the Active Editor"),
944+
icon: { id: 'codicon/eye' },
945+
category: { value: localize('timeline', "Timeline"), original: 'Timeline' },
946+
},
947+
group: 'navigation',
948+
order: 98,
949+
when: TimelineFollowActiveEditorContext
950+
})));
951+
952+
this._register(MenuRegistry.appendMenuItem(MenuId.TimelineTitle, ({
953+
command: {
954+
id: 'timeline.toggleFollowActiveEditor',
955+
title: { value: localize('timeline.toggleFollowActiveEditorCommand', "Toggle Active Editor Following"), original: 'Toggle Active Editor Following' },
956+
// title: localize(`timeline.toggleFollowActiveEditorCommand.stop`, "Stop following the Active Editor"),
957+
icon: { id: 'codicon/eye-closed' },
958+
category: { value: localize('timeline', "Timeline"), original: 'Timeline' },
959+
},
960+
group: 'navigation',
961+
order: 98,
962+
when: TimelineFollowActiveEditorContext.toNegated()
963+
})));
967964

968965
this._register(timelineService.onDidChangeProviders(() => this.updateTimelineSourceFilters()));
969966
this.updateTimelineSourceFilters();

0 commit comments

Comments
 (0)