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

Switch cell type from the cell menu #328

Merged
merged 5 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion packages/notebook-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -341,6 +380,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
checkpoints,
kernelLogo,
kernelStatus,
menuPlugin,
runShortcut,
scrollOutput
];
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.