Skip to content

Commit 8488049

Browse files
committed
wip: submenu icons
1 parent 7cae7a0 commit 8488049

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface IMenuItem {
4747
export interface ISubmenuItem {
4848
title: string | ILocalizedString;
4949
submenu: MenuId;
50+
icon?: Icon;
5051
when?: ContextKeyExpression;
5152
group?: 'navigation' | string;
5253
order?: number;

src/vs/workbench/api/common/menusExtensionPoint.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace schema {
3535
export interface IUserFriendlySubmenu {
3636
id: string;
3737
label: string;
38+
icon?: IUserFriendlyIcon;
3839
}
3940

4041
export function parseMenuId(value: string): MenuId | undefined {
@@ -214,12 +215,31 @@ namespace schema {
214215
type: 'object',
215216
properties: {
216217
id: {
217-
description: localize('submenu.id', 'Identifier of the menu to display as a submenu.'),
218+
description: localize('vscode.extension.contributes.submenu.id', 'Identifier of the menu to display as a submenu.'),
218219
type: 'string'
219220
},
220221
label: {
221-
description: localize('submenu.label', 'The label of the menu item which leads to this submenu.'),
222+
description: localize('vscode.extension.contributes.submenu.label', 'The label of the menu item which leads to this submenu.'),
222223
type: 'string'
224+
},
225+
icon: {
226+
description: localize('vscode.extension.contributes.submenu.icon', '(Optional) Icon which is used to represent the submenu in the UI. Either a file path, an object with file paths for dark and light themes, or a theme icon references, like `\\$(zap)`'),
227+
anyOf: [{
228+
type: 'string'
229+
},
230+
{
231+
type: 'object',
232+
properties: {
233+
light: {
234+
description: localize('vscode.extension.contributes.submenu.icon.light', 'Icon path when a light theme is used'),
235+
type: 'string'
236+
},
237+
dark: {
238+
description: localize('vscode.extension.contributes.submenu.icon.dark', 'Icon path when a dark theme is used'),
239+
type: 'string'
240+
}
241+
}
242+
}]
223243
}
224244
}
225245
};
@@ -543,6 +563,7 @@ commandsExtensionPoint.setHandler(extensions => {
543563
interface IRegisteredSubmenu {
544564
readonly id: MenuId;
545565
readonly label: string;
566+
readonly icon?: { dark: URI; light?: URI; } | ThemeIcon;
546567
}
547568

548569
const _submenus = new Map<string, IRegisteredSubmenu>();
@@ -578,9 +599,22 @@ submenusExtensionPoint.setHandler(extensions => {
578599
return;
579600
}
580601

602+
let absoluteIcon: { dark: URI; light?: URI; } | ThemeIcon | undefined;
603+
if (entry.value.icon) {
604+
if (typeof entry.value.icon === 'string') {
605+
absoluteIcon = ThemeIcon.fromString(entry.value.icon) || { dark: resources.joinPath(extension.description.extensionLocation, entry.value.icon) };
606+
} else {
607+
absoluteIcon = {
608+
dark: resources.joinPath(extension.description.extensionLocation, entry.value.icon.dark),
609+
light: resources.joinPath(extension.description.extensionLocation, entry.value.icon.light)
610+
};
611+
}
612+
}
613+
581614
const item: IRegisteredSubmenu = {
582615
id: new MenuId(`api:${entry.value.id}`),
583-
label: entry.value.label
616+
label: entry.value.label,
617+
icon: absoluteIcon
584618
};
585619

586620
_submenus.set(entry.value.id, item);
@@ -673,7 +707,7 @@ menusExtensionPoint.setHandler(extensions => {
673707
continue;
674708
}
675709

676-
item = { submenu: submenu.id, title: submenu.label, group: undefined, order: undefined, when: undefined };
710+
item = { submenu: submenu.id, icon: submenu.icon, title: submenu.label, group: undefined, order: undefined, when: undefined };
677711
}
678712

679713
if (menuItem.group) {

0 commit comments

Comments
 (0)