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

Commit

Permalink
Merge pull request #334 from jtpio/auto-backport-of-pr-328-on-0.3.x
Browse files Browse the repository at this point in the history
Backport PR #328: Switch cell type from the cell menu
  • Loading branch information
jtpio authored Jan 27, 2022
2 parents 27fbff9 + b906143 commit b7e4a51
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
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.

0 comments on commit b7e4a51

Please sign in to comment.