From 3185922bb3460eae40aa08084682db608cfa69c4 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Fri, 4 Dec 2020 21:33:56 +0100 Subject: [PATCH] Toggle header visibility --- packages/application-extension/package.json | 2 ++ packages/application-extension/src/index.ts | 39 +++++++++++++++++++-- packages/application/src/shell.ts | 7 ++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/packages/application-extension/package.json b/packages/application-extension/package.json index 43131b5ef..c33d3d32c 100644 --- a/packages/application-extension/package.json +++ b/packages/application-extension/package.json @@ -44,7 +44,9 @@ "@jupyterlab/codemirror": "^3.0.0-rc.12", "@jupyterlab/docregistry": "^3.0.0-rc.12", "@jupyterlab/docmanager": "^3.0.0-rc.12", + "@jupyterlab/mainmenu": "^3.0.0-rc.12", "@jupyterlab/notebook": "^3.0.0-rc.12", + "@jupyterlab/settingregistry": "^3.0.0-rc.12", "@jupyterlab/translation": "^3.0.0-rc.12", "@lumino/widgets": "^1.14.0" }, diff --git a/packages/application-extension/src/index.ts b/packages/application-extension/src/index.ts index ad1c8ffea..aaffc3231 100644 --- a/packages/application-extension/src/index.ts +++ b/packages/application-extension/src/index.ts @@ -19,6 +19,8 @@ import { PageConfig, Text, Time } from '@jupyterlab/coreutils'; import { IDocumentManager, renameDialog } from '@jupyterlab/docmanager'; +import { IMainMenu } from '@jupyterlab/mainmenu'; + import { NotebookPanel } from '@jupyterlab/notebook'; import { ITranslator, TranslationManager } from '@jupyterlab/translation'; @@ -62,7 +64,10 @@ const KERNEL_STATUS_FADE_OUT_CLASS = 'jp-ClassicKernelStatus-fade'; * The command IDs used by the application plugin. */ namespace CommandIDs { - export const open = 'docmanager:open'; + /** + * Toggle Top Bar visibility + */ + export const toggleTop = 'application:toggle-top'; } /** @@ -391,6 +396,35 @@ const title: JupyterFrontEndPlugin = { } }; +/** + * Plugin to toggle the top header visibility. + */ +const topVisibility: JupyterFrontEndPlugin = { + id: '@jupyterlab-classic/application-extension:top', + requires: [IClassicShell], + optional: [IMainMenu], + activate: ( + app: JupyterFrontEnd, + classicShell: IClassicShell, + menu: IMainMenu | null + ) => { + const top = classicShell.top; + + app.commands.addCommand(CommandIDs.toggleTop, { + label: 'Show Header', + execute: (args: any) => { + top.setHidden(top.isVisible); + }, + isToggled: () => top.isVisible + }); + + if (menu) { + menu.viewMenu.addGroup([{ command: CommandIDs.toggleTop }], 2); + } + }, + autoStart: true +}; + /** * A simplified Translator */ @@ -426,7 +460,7 @@ const tree: JupyterFrontEndPlugin = { const [, path] = matches; app.restored.then(() => { - commands.execute(CommandIDs.open, { + commands.execute('docmanager:open', { path, factory: NOTEBOOK_FACTORY }); @@ -453,6 +487,7 @@ const plugins: JupyterFrontEndPlugin[] = [ shell, spacer, title, + topVisibility, translator, tree ]; diff --git a/packages/application/src/shell.ts b/packages/application/src/shell.ts index 32211bc8c..737c1beb1 100644 --- a/packages/application/src/shell.ts +++ b/packages/application/src/shell.ts @@ -114,6 +114,13 @@ export class ClassicShell extends Widget implements JupyterFrontEnd.IShell { return this._main.widgets[0]; } + /** + * Get the top area panel + */ + get top(): Widget { + return this._topHandler.panel; + } + /** * Return the list of widgets for the given area. *