Skip to content

Commit 3dda6ea

Browse files
committed
add customize layout icons
refs #137633
1 parent 33fd4dc commit 3dda6ea

File tree

1 file changed

+55
-20
lines changed

1 file changed

+55
-20
lines changed

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

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
2525
import { AuxiliaryBarVisibleContext, PanelAlignmentContext, PanelVisibleContext, SideBarVisibleContext, FocusedViewContext, InEditorZenModeContext, IsCenteredLayoutContext, EditorAreaVisibleContext, IsFullscreenContext } from 'vs/workbench/common/contextkeys';
2626
import { Codicon } from 'vs/base/common/codicons';
2727
import { DisposableStore } from 'vs/base/common/lifecycle';
28+
import { registerIcon } from 'vs/platform/theme/common/iconRegistry';
29+
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
2830

2931
// --- Close Side Bar
3032

@@ -1016,22 +1018,44 @@ registerAction2(DecreaseViewSizeAction);
10161018
registerAction2(DecreaseViewWidthAction);
10171019
registerAction2(DecreaseViewHeightAction);
10181020

1021+
const menubarIcon = registerIcon('menu-bar', Codicon.menu, localize('menuBarIcon', "Represents the menu bar"));
1022+
const activityBarLeftIcon = registerIcon('activity-bar-left', Codicon.layoutActivitybarLeft, localize('activityBarLeft', "Represents the activity bar in the left position"));
1023+
const activityBarRightIcon = registerIcon('activity-bar-right', Codicon.layoutActivitybarRight, localize('activityBarRight', "Represents the activity bar in the right position"));
1024+
const panelLeftIcon = registerIcon('panel-left', Codicon.layoutSidebarLeft, localize('panelLeft', "Represents the side bar or side panel in the left position"));
1025+
const panelRightIcon = registerIcon('panel-right', Codicon.layoutSidebarRight, localize('panelRight', "Represents the side bar or side panel in the right position"));
1026+
const panelIcon = registerIcon('panel-bottom', Codicon.layoutPanel, localize('panelBottom', "Represents the bottom panel"));
1027+
const statusBarIcon = registerIcon('statusBar', Codicon.layoutStatusbar, localize('statusBarIcon', "Represents the status bar"));
1028+
1029+
const panelAlignmentLeftIcon = registerIcon('panel-align-left', Codicon.layoutPanelLeft, localize('panelBottomLeft', "Represents the bottom panel alignment set to the left"));
1030+
const panelAlignmentRightIcon = registerIcon('panel-align-right', Codicon.layoutPanelRight, localize('panelBottomRight', "Represents the bottom panel alignment set to the right"));
1031+
const panelAlignmentCenterIcon = registerIcon('panel-align-center', Codicon.layoutPanelCenter, localize('panelBottomCenter', "Represents the bottom panel alignment set to the center"));
1032+
const panelAlignmentJustifyIcon = registerIcon('panel-align-justify', Codicon.layoutPanelJustify, localize('panelBottomJustify', "Represents the bottom panel alignment set to justified"));
1033+
1034+
type ContextualLayoutVisualIcon = { iconA: ThemeIcon, iconB: ThemeIcon, whenA: ContextKeyExpression };
1035+
type LayoutVisualIcon = ThemeIcon | ContextualLayoutVisualIcon;
1036+
1037+
function isContextualLayoutVisualIcon(icon: LayoutVisualIcon): icon is ContextualLayoutVisualIcon {
1038+
return (icon as ContextualLayoutVisualIcon).iconA !== undefined;
1039+
}
1040+
10191041
interface CustomizeLayoutItem {
10201042
id: string;
10211043
active: ContextKeyExpression;
10221044
label: string;
10231045
activeIcon: Codicon;
1046+
visualIcon?: LayoutVisualIcon;
10241047
activeAriaLabel: string;
10251048
inactiveIcon?: Codicon;
10261049
inactiveAriaLabel?: string;
10271050
useButtons: boolean;
10281051
}
10291052

1030-
const CreateToggleLayoutItem = (id: string, active: ContextKeyExpression, label: string): CustomizeLayoutItem => {
1053+
const CreateToggleLayoutItem = (id: string, active: ContextKeyExpression, label: string, visualIcon?: LayoutVisualIcon): CustomizeLayoutItem => {
10311054
return {
10321055
id,
10331056
active,
10341057
label,
1058+
visualIcon,
10351059
activeIcon: Codicon.eye,
10361060
inactiveIcon: Codicon.eyeClosed,
10371061
activeAriaLabel: localize('visible', "Visible"),
@@ -1040,11 +1064,12 @@ const CreateToggleLayoutItem = (id: string, active: ContextKeyExpression, label:
10401064
};
10411065
};
10421066

1043-
const CreateOptionLayoutItem = (id: string, active: ContextKeyExpression, label: string): CustomizeLayoutItem => {
1067+
const CreateOptionLayoutItem = (id: string, active: ContextKeyExpression, label: string, visualIcon?: LayoutVisualIcon): CustomizeLayoutItem => {
10441068
return {
10451069
id,
10461070
active,
10471071
label,
1072+
visualIcon,
10481073
activeIcon: Codicon.check,
10491074
activeAriaLabel: localize('active', "Active"),
10501075
useButtons: false
@@ -1054,27 +1079,27 @@ const CreateOptionLayoutItem = (id: string, active: ContextKeyExpression, label:
10541079
const MenuBarToggledContext = ContextKeyExpr.and(IsMacNativeContext.toNegated(), ContextKeyExpr.notEquals('config.window.menuBarVisibility', 'hidden'), ContextKeyExpr.notEquals('config.window.menuBarVisibility', 'toggle'), ContextKeyExpr.notEquals('config.window.menuBarVisibility', 'compact')) as ContextKeyExpression;
10551080
const ToggleVisibilityActions: CustomizeLayoutItem[] = [];
10561081
if (!isMacintosh || !isNative) {
1057-
ToggleVisibilityActions.push(CreateToggleLayoutItem('workbench.action.toggleMenuBar', MenuBarToggledContext, localize('menuBar', "Menu Bar")));
1082+
ToggleVisibilityActions.push(CreateToggleLayoutItem('workbench.action.toggleMenuBar', MenuBarToggledContext, localize('menuBar', "Menu Bar"), menubarIcon));
10581083
}
10591084

10601085
ToggleVisibilityActions.push(...[
1061-
CreateToggleLayoutItem(ToggleActivityBarVisibilityAction.ID, ContextKeyExpr.equals('config.workbench.activityBar.visible', true), localize('activityBar', "Activity Bar")),
1062-
CreateToggleLayoutItem(ToggleSidebarVisibilityAction.ID, SideBarVisibleContext, localize('sideBar', "Side Bar")),
1063-
CreateToggleLayoutItem(TogglePanelAction.ID, PanelVisibleContext, localize('panel', "Panel")),
1064-
CreateToggleLayoutItem(ToggleAuxiliaryBarAction.ID, AuxiliaryBarVisibleContext, localize('sidePanel', "Side Panel")),
1065-
CreateToggleLayoutItem(ToggleStatusbarVisibilityAction.ID, ContextKeyExpr.equals('config.workbench.statusBar.visible', true), localize('statusBar', "Status Bar")),
1086+
CreateToggleLayoutItem(ToggleActivityBarVisibilityAction.ID, ContextKeyExpr.equals('config.workbench.activityBar.visible', true), localize('activityBar', "Activity Bar"), { whenA: ContextKeyExpr.equals('config.workbench.sideBar.location', 'left'), iconA: activityBarLeftIcon, iconB: activityBarRightIcon }),
1087+
CreateToggleLayoutItem(ToggleSidebarVisibilityAction.ID, SideBarVisibleContext, localize('sideBar', "Side Bar"), { whenA: ContextKeyExpr.equals('config.workbench.sideBar.location', 'left'), iconA: panelLeftIcon, iconB: panelRightIcon }),
1088+
CreateToggleLayoutItem(TogglePanelAction.ID, PanelVisibleContext, localize('panel', "Panel"), panelIcon),
1089+
CreateToggleLayoutItem(ToggleAuxiliaryBarAction.ID, AuxiliaryBarVisibleContext, localize('sidePanel', "Side Panel"), { whenA: ContextKeyExpr.equals('config.workbench.sideBar.location', 'left'), iconA: panelRightIcon, iconB: panelLeftIcon }),
1090+
CreateToggleLayoutItem(ToggleStatusbarVisibilityAction.ID, ContextKeyExpr.equals('config.workbench.statusBar.visible', true), localize('statusBar', "Status Bar"), statusBarIcon),
10661091
]);
10671092

10681093
const MoveSideBarActions: CustomizeLayoutItem[] = [
1069-
CreateOptionLayoutItem(MoveSidebarLeftAction.ID, ContextKeyExpr.equals('config.workbench.sideBar.location', 'left'), localize('leftSideBar', "Left")),
1070-
CreateOptionLayoutItem(MoveSidebarRightAction.ID, ContextKeyExpr.equals('config.workbench.sideBar.location', 'right'), localize('rightSideBar', "Right")),
1094+
CreateOptionLayoutItem(MoveSidebarLeftAction.ID, ContextKeyExpr.equals('config.workbench.sideBar.location', 'left'), localize('leftSideBar', "Left"), panelLeftIcon),
1095+
CreateOptionLayoutItem(MoveSidebarRightAction.ID, ContextKeyExpr.equals('config.workbench.sideBar.location', 'right'), localize('rightSideBar', "Right"), panelRightIcon),
10711096
];
10721097

10731098
const AlignPanelActions: CustomizeLayoutItem[] = [
1074-
CreateOptionLayoutItem('workbench.action.alignPanelLeft', PanelAlignmentContext.isEqualTo('left'), localize('leftPanel', "Left")),
1075-
CreateOptionLayoutItem('workbench.action.alignPanelRight', PanelAlignmentContext.isEqualTo('right'), localize('rightPanel', "Right")),
1076-
CreateOptionLayoutItem('workbench.action.alignPanelCenter', PanelAlignmentContext.isEqualTo('center'), localize('centerPanel', "Center")),
1077-
CreateOptionLayoutItem('workbench.action.alignPanelJustify', PanelAlignmentContext.isEqualTo('justify'), localize('justifyPanel', "Justify")),
1099+
CreateOptionLayoutItem('workbench.action.alignPanelLeft', PanelAlignmentContext.isEqualTo('left'), localize('leftPanel', "Left"), panelAlignmentLeftIcon),
1100+
CreateOptionLayoutItem('workbench.action.alignPanelRight', PanelAlignmentContext.isEqualTo('right'), localize('rightPanel', "Right"), panelAlignmentRightIcon),
1101+
CreateOptionLayoutItem('workbench.action.alignPanelCenter', PanelAlignmentContext.isEqualTo('center'), localize('centerPanel', "Center"), panelAlignmentCenterIcon),
1102+
CreateOptionLayoutItem('workbench.action.alignPanelJustify', PanelAlignmentContext.isEqualTo('justify'), localize('justifyPanel', "Justify"), panelAlignmentJustifyIcon),
10781103
];
10791104

10801105
const MiscLayoutOptions: CustomizeLayoutItem[] = [
@@ -1108,12 +1133,22 @@ registerAction2(class CustomizeLayoutAction extends Action2 {
11081133
getItems(contextKeyService: IContextKeyService): (IQuickPickItem | IQuickPickSeparator)[] {
11091134
const toQuickPickItem = (item: CustomizeLayoutItem): IQuickPickItem => {
11101135
const toggled = item.active.evaluate(contextKeyService.getContext(null));
1111-
const label = item.useButtons ?
1136+
let label = item.useButtons ?
11121137
item.label :
11131138
item.label + (toggled && item.activeIcon ? ` $(${item.activeIcon.id})` : (!toggled && item.inactiveIcon ? ` $(${item.inactiveIcon.id})` : ''));
11141139
const ariaLabel =
11151140
item.label + (toggled && item.activeAriaLabel ? ` (${item.activeAriaLabel})` : (!toggled && item.inactiveAriaLabel ? ` (${item.inactiveAriaLabel})` : ''));
11161141

1142+
if (item.visualIcon) {
1143+
let icon = item.visualIcon;
1144+
if (isContextualLayoutVisualIcon(icon)) {
1145+
const useIconA = icon.whenA.evaluate(contextKeyService.getContext(null));
1146+
icon = useIconA ? icon.iconA : icon.iconB;
1147+
}
1148+
1149+
label = `$(${icon.id}) ${label}`;
1150+
}
1151+
11171152
return {
11181153
type: 'item',
11191154
id: item.id,
@@ -1131,22 +1166,22 @@ registerAction2(class CustomizeLayoutAction extends Action2 {
11311166
return [
11321167
{
11331168
type: 'separator',
1134-
label: localize('toggleVisibility', "Toggle Visibility")
1169+
label: localize('toggleVisibility', "Visibility")
11351170
},
11361171
...ToggleVisibilityActions.map(toQuickPickItem),
11371172
{
11381173
type: 'separator',
1139-
label: localize('moveSideBar', "Move Side Bar")
1174+
label: localize('sideBarPosition', "Side Bar Position")
11401175
},
11411176
...MoveSideBarActions.map(toQuickPickItem),
11421177
{
11431178
type: 'separator',
1144-
label: localize('alignPanel', "Align Panel")
1179+
label: localize('panelAlignment', "Panel Alignment")
11451180
},
11461181
...AlignPanelActions.map(toQuickPickItem),
11471182
{
11481183
type: 'separator',
1149-
label: localize('layoutModes', "Layout Modes"),
1184+
label: localize('layoutModes', "Modes"),
11501185
},
11511186
...MiscLayoutOptions.map(toQuickPickItem),
11521187
];
@@ -1160,7 +1195,7 @@ registerAction2(class CustomizeLayoutAction extends Action2 {
11601195
quickPick.items = this.getItems(contextKeyService);
11611196
quickPick.ignoreFocusOut = true;
11621197
quickPick.hideInput = true;
1163-
quickPick.title = localize('layoutOptionsQuickPickTitle', "Layout Options");
1198+
quickPick.title = localize('customizeLayoutQuickPickTitle', "Customize Layout");
11641199

11651200
quickPick.buttons = [
11661201
{

0 commit comments

Comments
 (0)