Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit b7e4a51

Browse files
authored
Merge pull request #334 from jtpio/auto-backport-of-pr-328-on-0.3.x
Backport PR #328: Switch cell type from the cell menu
2 parents 27fbff9 + b906143 commit b7e4a51

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

packages/notebook-extension/src/index.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { Text, Time } from '@jupyterlab/coreutils';
1414

1515
import { IDocumentManager } from '@jupyterlab/docmanager';
1616

17+
import { IMainMenu } from '@jupyterlab/mainmenu';
18+
1719
import { NotebookPanel, INotebookTracker } from '@jupyterlab/notebook';
1820

1921
import { ISettingRegistry } from '@jupyterlab/settingregistry';
@@ -24,7 +26,7 @@ import { IRetroShell } from '@retrolab/application';
2426

2527
import { Poll } from '@lumino/polling';
2628

27-
import { Widget } from '@lumino/widgets';
29+
import { Menu, Widget } from '@lumino/widgets';
2830

2931
/**
3032
* The class for kernel status errors.
@@ -223,6 +225,43 @@ const kernelStatus: JupyterFrontEndPlugin<void> = {
223225
}
224226
};
225227

228+
/**
229+
* A plugin to customize notebook related menu entries
230+
* TODO: switch to settings define menus when fixed upstream: https://github.com/jupyterlab/jupyterlab/issues/11754
231+
*/
232+
const menuPlugin: JupyterFrontEndPlugin<void> = {
233+
id: '@retrolab/notebook-extension:menu-plugin',
234+
autoStart: true,
235+
requires: [IMainMenu, ITranslator],
236+
activate: (
237+
app: JupyterFrontEnd,
238+
mainMenu: IMainMenu,
239+
translator: ITranslator
240+
) => {
241+
const { commands } = app;
242+
const trans = translator.load('retrolab');
243+
244+
const cellTypeSubmenu = new Menu({ commands });
245+
cellTypeSubmenu.title.label = trans._p('menu', 'Cell Type');
246+
[
247+
'notebook:change-cell-to-code',
248+
'notebook:change-cell-to-markdown',
249+
'notebook:change-cell-to-raw'
250+
].forEach(command => {
251+
cellTypeSubmenu.addItem({
252+
command
253+
});
254+
});
255+
256+
mainMenu.runMenu.addItem({ type: 'separator', rank: 1000 });
257+
mainMenu.runMenu.addItem({
258+
type: 'submenu',
259+
submenu: cellTypeSubmenu,
260+
rank: 1010
261+
});
262+
}
263+
};
264+
226265
/**
227266
* A plugin to add an extra shortcut to execute a cell in place via Cmd-Enter on Mac.
228267
* TODO: switch to settings define menus when fixed upstream: https://github.com/jupyterlab/jupyterlab/issues/11754
@@ -341,6 +380,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
341380
checkpoints,
342381
kernelLogo,
343382
kernelStatus,
383+
menuPlugin,
344384
runShortcut,
345385
scrollOutput
346386
];
Loading
Loading

0 commit comments

Comments
 (0)