Skip to content

Commit 17cae9a

Browse files
feat: add icons to the menu items
1 parent c095677 commit 17cae9a

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/index.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ import { INotebookTracker, NotebookActions } from "@jupyterlab/notebook";
1111

1212
import { CommandRegistry } from '@lumino/commands';
1313

14-
import { Menu } from '@lumino/widgets';
14+
import {
15+
MenuSvg,
16+
pythonIcon,
17+
terminalIcon,
18+
textEditorIcon,
19+
folderIcon,
20+
} from '@jupyterlab/ui-components';
1521

1622
import { listSnippets, Snippet, fetchSnippet } from "./snippets";
1723

@@ -52,7 +58,7 @@ function toTree(snippets: Snippet[]) {
5258
* @param path The current path in the tree.
5359
*/
5460
function createMenu(commands: CommandRegistry , tree: Tree, path: string[] = []) {
55-
const menu = new Menu({ commands });
61+
const menu = new MenuSvg({ commands });
5662
for (const [name, map] of tree.entries()) {
5763
const fullpath = path.concat(name);
5864
if (map.size === 0) {
@@ -63,6 +69,7 @@ function createMenu(commands: CommandRegistry , tree: Tree, path: string[] = [])
6369
} else {
6470
const submenu = createMenu(commands, map, path.concat(name));
6571
submenu.title.label = name;
72+
submenu.title.icon = folderIcon;
6673
menu.addItem({type: 'submenu', submenu});
6774
}
6875
}
@@ -91,9 +98,16 @@ const extension: JupyterFrontEndPlugin<void> = {
9198
}
9299

93100
commands.addCommand(CommandIDs.open, {
94-
label: args => {
95-
const label = args['label'] as string;
96-
return PathExt.basename(label, PathExt.extname(label));
101+
label: args => args['label'] as string,
102+
icon: args => {
103+
const ext = PathExt.extname(args['label'] as string);
104+
if (ext === '.py') {
105+
return pythonIcon;
106+
}
107+
if (ext === '.sh') {
108+
return terminalIcon;
109+
}
110+
return textEditorIcon;
97111
},
98112
execute: async args => {
99113
const path = args['path'] as string[];

0 commit comments

Comments
 (0)