Programmatically add cell type menu entries

Jeremy Tuloup 4 years ago
parent d2d9531314
commit 7d433ed583

@ -15,38 +15,6 @@
"rank": 20
}
]
},
{
"id": "jp-mainmenu-run",
"label": "Cell",
"items": [
{
"type": "separator",
"rank": 1000
},
{
"type": "submenu",
"rank": 1010,
"submenu": {
"id": "jp-mainmenu-run-cell-type",
"label": "Cell Type",
"items": [
{
"command": "notebook:change-cell-to-code",
"rank": 0
},
{
"command": "notebook:change-cell-to-markdown",
"rank": 10
},
{
"command": "notebook:change-cell-to-raw",
"rank": 20
}
]
}
}
]
}
]
},

@ -14,6 +14,8 @@ import { Text, Time } from '@jupyterlab/coreutils';
import { IDocumentManager } from '@jupyterlab/docmanager';
import { IMainMenu } from '@jupyterlab/mainmenu';
import { NotebookPanel, INotebookTracker } from '@jupyterlab/notebook';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
@ -24,7 +26,7 @@ import { IRetroShell } from '@retrolab/application';
import { Poll } from '@lumino/polling';
import { Widget } from '@lumino/widgets';
import { Menu, Widget } from '@lumino/widgets';
/**
* The class for kernel status errors.
@ -223,6 +225,43 @@ const kernelStatus: JupyterFrontEndPlugin<void> = {
}
};
/**
* A plugin to customize notebook related menu entries
* TODO: switch to settings define menus when fixed upstream: https://github.com/jupyterlab/jupyterlab/issues/11754
*/
const menuPlugin: JupyterFrontEndPlugin<void> = {
id: '@retrolab/notebook-extension:menu-plugin',
autoStart: true,
requires: [IMainMenu, ITranslator],
activate: (
app: JupyterFrontEnd,
mainMenu: IMainMenu,
translator: ITranslator
) => {
const { commands } = app;
const trans = translator.load('retrolab');
const cellTypeSubmenu = new Menu({ commands });
cellTypeSubmenu.title.label = trans._p('menu', 'Cell Type');
[
'notebook:change-cell-to-code',
'notebook:change-cell-to-markdown',
'notebook:change-cell-to-raw'
].forEach(command => {
cellTypeSubmenu.addItem({
command
});
});
mainMenu.runMenu.addItem({ type: 'separator', rank: 1000 });
mainMenu.runMenu.addItem({
type: 'submenu',
submenu: cellTypeSubmenu,
rank: 1010
});
}
};
/**
* A plugin to add an extra shortcut to execute a cell in place via Cmd-Enter on Mac.
* TODO: switch to settings define menus when fixed upstream: https://github.com/jupyterlab/jupyterlab/issues/11754
@ -341,6 +380,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
checkpoints,
kernelLogo,
kernelStatus,
menuPlugin,
runShortcut,
scrollOutput
];

@ -14,7 +14,7 @@ const MENU_PATHS = [
'File>New',
'Edit',
'View',
'Cell',
'Run',
'Kernel',
'Settings',
'Settings>Theme',

Loading…
Cancel
Save