Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better panel context menu #170294

Merged
merged 1 commit into from Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/vs/platform/actions/common/actions.ts
Expand Up @@ -83,8 +83,8 @@ export class MenuId {
static readonly MenubarHelpMenu = new MenuId('MenubarHelpMenu');
static readonly MenubarLayoutMenu = new MenuId('MenubarLayoutMenu');
static readonly MenubarNewBreakpointMenu = new MenuId('MenubarNewBreakpointMenu');
static readonly MenubarPanelAlignmentMenu = new MenuId('MenubarPanelAlignmentMenu');
static readonly MenubarPanelPositionMenu = new MenuId('MenubarPanelPositionMenu');
static readonly PanelAlignmentMenu = new MenuId('PanelAlignmentMenu');
static readonly PanelPositionMenu = new MenuId('PanelPositionMenu');
static readonly MenubarPreferencesMenu = new MenuId('MenubarPreferencesMenu');
static readonly MenubarRecentMenu = new MenuId('MenubarRecentMenu');
static readonly MenubarSelectionMenu = new MenuId('MenubarSelectionMenu');
Expand Down
25 changes: 5 additions & 20 deletions src/vs/workbench/browser/parts/panel/panelActions.ts
Expand Up @@ -6,7 +6,6 @@
import 'vs/css!./media/panelpart';
import { localize } from 'vs/nls';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { Action } from 'vs/base/common/actions';
import { MenuId, MenuRegistry, registerAction2, Action2, IAction2Options } from 'vs/platform/actions/common/actions';
import { Categories } from 'vs/platform/action/common/actionCommonCategories';
import { IWorkbenchLayoutService, PanelAlignment, Parts, Position, positionToString } from 'vs/workbench/services/layout/browser/layoutService';
Expand Down Expand Up @@ -137,7 +136,7 @@ function createAlignmentPanelActionConfig(id: string, title: ICommandActionTitle
}


export const PositionPanelActionConfigs: PanelActionConfig<Position>[] = [
const PositionPanelActionConfigs: PanelActionConfig<Position>[] = [
createPositionPanelActionConfig(PositionPanelActionId.LEFT, { value: localize('positionPanelLeft', 'Move Panel Left'), original: 'Move Panel Left' }, localize('positionPanelLeftShort', "Left"), Position.LEFT),
createPositionPanelActionConfig(PositionPanelActionId.RIGHT, { value: localize('positionPanelRight', 'Move Panel Right'), original: 'Move Panel Right' }, localize('positionPanelRightShort', "Right"), Position.RIGHT),
createPositionPanelActionConfig(PositionPanelActionId.BOTTOM, { value: localize('positionPanelBottom', 'Move Panel To Bottom'), original: 'Move Panel To Bottom' }, localize('positionPanelBottomShort', "Bottom"), Position.BOTTOM),
Expand All @@ -151,24 +150,10 @@ const AlignPanelActionConfigs: PanelActionConfig<PanelAlignment>[] = [
createAlignmentPanelActionConfig(AlignPanelActionId.JUSTIFY, { value: localize('alignPanelJustify', 'Set Panel Alignment to Justify'), original: 'Set Panel Alignment to Justify' }, localize('alignPanelJustifyShort', "Justify"), 'justify'),
];

const positionByActionId = new Map(PositionPanelActionConfigs.map(config => [config.id, config.value]));
export class SetPanelPositionAction extends Action {
constructor(
id: string,
label: string,
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService
) {
super(id, label);
}

override async run(): Promise<void> {
const position = positionByActionId.get(this.id);
this.layoutService.setPanelPosition(position === undefined ? Position.BOTTOM : position);
}
}

MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
submenu: MenuId.MenubarPanelPositionMenu,
submenu: MenuId.PanelPositionMenu,
title: localize('positionPanel', "Panel Position"),
group: '3_workbench_layout_move',
order: 4
Expand All @@ -192,7 +177,7 @@ PositionPanelActionConfigs.forEach(positionPanelAction => {
}
});

MenuRegistry.appendMenuItem(MenuId.MenubarPanelPositionMenu, {
MenuRegistry.appendMenuItem(MenuId.PanelPositionMenu, {
command: {
id,
title: shortLabel,
Expand All @@ -203,7 +188,7 @@ PositionPanelActionConfigs.forEach(positionPanelAction => {
});

MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
submenu: MenuId.MenubarPanelAlignmentMenu,
submenu: MenuId.PanelAlignmentMenu,
title: localize('alignPanel', "Align Panel"),
group: '3_workbench_layout_move',
order: 5
Expand All @@ -227,7 +212,7 @@ AlignPanelActionConfigs.forEach(alignPanelAction => {
}
});

MenuRegistry.appendMenuItem(MenuId.MenubarPanelAlignmentMenu, {
MenuRegistry.appendMenuItem(MenuId.PanelAlignmentMenu, {
command: {
id,
title: shortLabel,
Expand Down
23 changes: 16 additions & 7 deletions src/vs/workbench/browser/parts/panel/panelPart.ts
Expand Up @@ -6,7 +6,7 @@
import 'vs/css!./media/basepanelpart';
import 'vs/css!./media/panelpart';
import { localize } from 'vs/nls';
import { IAction, Separator, toAction } from 'vs/base/common/actions';
import { IAction, Separator, SubmenuAction, toAction } from 'vs/base/common/actions';
import { Event } from 'vs/base/common/event';
import { Registry } from 'vs/platform/registry/common/platform';
import { ActionsOrientation, prepareActions } from 'vs/base/browser/ui/actionbar/actionbar';
Expand All @@ -18,7 +18,7 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { PanelActivityAction, TogglePanelAction, PlaceHolderPanelActivityAction, PlaceHolderToggleCompositePinnedAction, PositionPanelActionConfigs, SetPanelPositionAction } from 'vs/workbench/browser/parts/panel/panelActions';
import { PanelActivityAction, TogglePanelAction, PlaceHolderPanelActivityAction, PlaceHolderToggleCompositePinnedAction } from 'vs/workbench/browser/parts/panel/panelActions';
import { IThemeService, ThemeIcon } from 'vs/platform/theme/common/themeService';
import { PANEL_BACKGROUND, PANEL_BORDER, PANEL_ACTIVE_TITLE_FOREGROUND, PANEL_INACTIVE_TITLE_FOREGROUND, PANEL_ACTIVE_TITLE_BORDER, EDITOR_DRAG_AND_DROP_BACKGROUND, PANEL_DRAG_AND_DROP_BORDER } from 'vs/workbench/common/theme';
import { contrastBorder, badgeBackground, badgeForeground } from 'vs/platform/theme/common/colorRegistry';
Expand All @@ -38,7 +38,7 @@ import { IActivity } from 'vs/workbench/common/activity';
import { HoverPosition } from 'vs/base/browser/ui/hover/hoverWidget';
import { Extensions as PaneCompositeExtensions, PaneComposite, PaneCompositeDescriptor, PaneCompositeRegistry } from 'vs/workbench/browser/panecomposite';
import { CompositeMenuActions } from 'vs/workbench/browser/actions';
import { MenuId } from 'vs/platform/actions/common/actions';
import { IMenuService, MenuId } from 'vs/platform/actions/common/actions';
import { IComposite } from 'vs/workbench/common/composite';
import { IPaneCompositePart, IPaneCompositeSelectorPart } from 'vs/workbench/browser/parts/paneCompositePart';
import { IPartOptions } from 'vs/workbench/browser/part';
Expand All @@ -47,6 +47,7 @@ import { URI } from 'vs/base/common/uri';
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { PlaceHolderToggleCompositeBadgeAction } from 'vs/workbench/browser/parts/activitybar/activitybarActions';
import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';

interface ICachedPanel {
id: string;
Expand Down Expand Up @@ -928,6 +929,7 @@ export class PanelPart extends BasePanelPart {
@IContextKeyService contextKeyService: IContextKeyService,
@IExtensionService extensionService: IExtensionService,
@ICommandService private commandService: ICommandService,
@IMenuService private menuService: IMenuService,
) {
super(
notificationService,
Expand Down Expand Up @@ -979,12 +981,19 @@ export class PanelPart extends BasePanelPart {

protected fillExtraContextMenuActions(actions: IAction[]): void {

const panelPositionMenu = this.menuService.createMenu(MenuId.PanelPositionMenu, this.contextKeyService);
const panelAlignMenu = this.menuService.createMenu(MenuId.PanelAlignmentMenu, this.contextKeyService);
const positionActions: IAction[] = [];
const alignActions: IAction[] = [];
createAndFillInContextMenuActions(panelPositionMenu, { shouldForwardArgs: true }, { primary: [], secondary: positionActions });
createAndFillInContextMenuActions(panelAlignMenu, { shouldForwardArgs: true }, { primary: [], secondary: alignActions });
panelAlignMenu.dispose();
panelPositionMenu.dispose();

actions.push(...[
new Separator(),
...PositionPanelActionConfigs
// show the contextual menu item if it is not in that position
.filter(({ when }) => this.contextKeyService.contextMatchesRules(when))
.map(({ id, title }) => this.instantiationService.createInstance(SetPanelPositionAction, id, title.value)),
new SubmenuAction('workbench.action.panel.position', localize('panel position', "Panel Position"), positionActions),
new SubmenuAction('workbench.action.panel.align', localize('align panel', "Align Panel"), alignActions),
toAction({ id: TogglePanelAction.ID, label: localize('hidePanel', "Hide Panel"), run: () => this.commandService.executeCommand(TogglePanelAction.ID) })
]);
}
Expand Down