Skip to content

Commit

Permalink
Move cell type menus to the settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Apr 2, 2022
1 parent 4b889ff commit 9dfcc37
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 41 deletions.
31 changes: 31 additions & 0 deletions packages/application-extension/schema/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,37 @@
"rank": 20
}
]
},
{
"id": "jp-mainmenu-run",
"items": [
{
"type": "separator",
"rank": 1000
},
{
"type": "submenu",
"rank": 1010,
"submenu": {
"id": "jp-runmenu-change-cell-type",
"label": "Cell Type",
"items": [
{
"command": "notebook:change-cell-to-code",
"rank": 0
},
{
"command": "notebook:change-cell-to-markdown",
"rank": 0
},
{
"command": "notebook:change-cell-to-raw",
"rank": 0
}
]
}
}
]
}
]
},
Expand Down
42 changes: 1 addition & 41 deletions packages/notebook-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ 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';
Expand All @@ -26,7 +24,7 @@ import { INotebookShell } from '@jupyter-notebook/application';

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

import { Menu, Widget } from '@lumino/widgets';
import { Widget } from '@lumino/widgets';

/**
* The class for kernel status errors.
Expand Down Expand Up @@ -225,43 +223,6 @@ 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: '@jupyter-notebook/notebook-extension:menu-plugin',
autoStart: true,
requires: [IMainMenu, ITranslator],
activate: (
app: JupyterFrontEnd,
mainMenu: IMainMenu,
translator: ITranslator
) => {
const { commands } = app;
const trans = translator.load('notebook');

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 enable scrolling for outputs by default.
* Mimic the logic from the classic notebook, as found here:
Expand Down Expand Up @@ -358,7 +319,6 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
checkpoints,
kernelLogo,
kernelStatus,
menuPlugin,
scrollOutput
];

Expand Down

0 comments on commit 9dfcc37

Please sign in to comment.