extension-examples
extension-examples copied to clipboard
Main menu example does not add menu, just the command
Description
When I follow the instructions and run the main-menu example, no menu is added just the command in the command pallet. I believe this is because some automatic loading of the schema for the menu does not work. I tried to use the code in a new project using the latest stable jupyter (^4.0.0). It behaved the same.
Reproduce
Follow the instructions in the example project.
No menu is added to Jupyter.
Expected behavior
I expect a menu to be added as per the description and animation.
Context
- Operating System and version: Linux Ubuntu 22.04
- Browser and version: Firefox & Chrome as of June 2024
- JupyterLab version: version pinned in repository and ^4.0.0
In a new clean project, I am able to build a menu using code such as this:
import {
JupyterFrontEnd,
JupyterFrontEndPlugin,
} from '@jupyterlab/application';
import { IMainMenu } from '@jupyterlab/mainmenu';
import { ICommandPalette } from '@jupyterlab/apputils';
import {
MenuSvg
} from '@jupyterlab/ui-components';
/**
* Initialization data for a main menu extension.
*/
const extension: JupyterFrontEndPlugin<void> = {
id: 'main-menu',
autoStart: true,
requires: [IMainMenu, ICommandPalette],
activate: (app: JupyterFrontEnd,
MainMenu: IMainMenu,
palette: ICommandPalette) => {
const { commands } = app;
// Add a command
const command = 'Item-1:JPSLMenu2:main-menu';
commands.addCommand(command, {
label: 'Item 1',
caption: 'Item 1',
execute: (args: any) => {
console.log(
`Item 1 has been called ${args['origin']}.`
);
window.alert(
`Item 1 has been called ${args['origin']}.`
);
},
});
// Add the command to the command palette
const category = 'JPSL Tools';
palette.addItem({
command,
category,
args: { origin: 'from the palette' },
});
// Add a menu using API
const menu = new MenuSvg({ commands });
menu.title.label = "JPSL Tools";
menu.addItem({
command: command,
args:{label: "Item 1", origin: "from the menu"}
});
MainMenu.addMenu(menu);
The main-meu example in this repository is trying to do something else that does not appear to work currently.
Troubleshoot Output
Paste the output from running `jupyter troubleshoot` from the command line here. You may want to sanitize the paths in the output.
Command Line Output
Paste the output from your command line running `jupyter lab` here, use `--debug` if possible.
Browser Output
Paste the output from your browser Javascript console here, if applicable.