From a4077bb775f48dbd9a314dbbea3966f356e9aada Mon Sep 17 00:00:00 2001 From: Dilip-Jain <59838651+Dilip-Jain@users.noreply.github.com> Date: Mon, 9 Oct 2023 21:46:40 +0530 Subject: [PATCH] Added Edit Notebook Metadata Option (#6402) Edit Notebook Metadata plugin added under Edit Menu for functionality similar to classic-notebook. Clicking on the option under the menu opens up the Notebook Tools widget in the right sidebar and expands the Additional Tools (which contains the Notebook Metadata editor) collapsible section (default: collapsed). --- packages/notebook-extension/src/index.ts | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index e4d217c577..3e6456d98f 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -478,12 +478,65 @@ const trusted: JupyterFrontEndPlugin = { }, }; +/** + * Add a command to open right sidebar for Editing Notebook Metadata when clicking on "Edit Notebook Metadata" under Edit menu + */ +const editNotebookMetadata: JupyterFrontEndPlugin = { + id: '@jupyter-notebook/notebook-extension:edit-notebook-metadata', + autoStart: true, + requires: [IMainMenu], + optional: [ITranslator, INotebookTools], + activate: ( + app: JupyterFrontEnd, + menu: IMainMenu, + translator: ITranslator | null, + notebookTools: INotebookTools | null + ) => { + const { commands } = app; + translator = translator ?? nullTranslator; + const trans = translator.load('notebook'); + + const id = 'notebook:edit-metadata'; + commands.addCommand(id, { + label: trans.__('Edit Notebook Metadata'), + execute: async () => { + const command = 'application:toggle-panel'; + const args = { + side: 'right', + title: `Show Notebook Tools`, + id: 'notebook-tools', + } + + // Check if Show Notebook Tools (Right Sidebar) is open (expanded) + if (!commands.isToggled(command, args)){ + await commands.execute(command, args).then(_ => { + + // For expanding the 'Advanced Tools' section (default: collapsed) + if (notebookTools){ + let tools = (notebookTools?.layout as any).widgets; + tools.forEach((tool: any) => { + if (tool.widget.title.label === 'Advanced Tools' && tool.collapsed){ + tool.toggle() + } + }); + } + }); + } + }, + }); + + // Add `Edit Notebook Metadata` option to Edit menu + menu.editMenu.addItem({type: 'command', command: id, rank: 40}) + }, +}; + /** * Export the plugins as default. */ const plugins: JupyterFrontEndPlugin[] = [ checkpoints, closeTab, + editNotebookMetadata, kernelLogo, kernelStatus, notebookToolsWidget,