diff --git a/packages/statusbar-extension/package.json b/packages/statusbar-extension/package.json index fab8f7bd2123..2591ff5d1fe6 100644 --- a/packages/statusbar-extension/package.json +++ b/packages/statusbar-extension/package.json @@ -37,8 +37,10 @@ "@jupyterlab/apputils": "^1.0.0-alpha.3", "@jupyterlab/cells": "^1.0.0-alpha.3", "@jupyterlab/console": "^1.0.0-alpha.3", + "@jupyterlab/coreutils": "^3.0.0-alpha.3", "@jupyterlab/docregistry": "^1.0.0-alpha.3", "@jupyterlab/fileeditor": "^1.0.0-alpha.3", + "@jupyterlab/mainmenu": "^1.0.0-alpha.3", "@jupyterlab/notebook": "^1.0.0-alpha.4", "@jupyterlab/statusbar": "^1.0.0-alpha.3", "@phosphor/widgets": "^1.6.0" diff --git a/packages/statusbar-extension/schema/plugin.json b/packages/statusbar-extension/schema/plugin.json index 17f6b5ecdd8a..9a8b3a07d181 100644 --- a/packages/statusbar-extension/schema/plugin.json +++ b/packages/statusbar-extension/schema/plugin.json @@ -21,6 +21,12 @@ "memory-usage-item", "saving-status-item" ] + }, + "visible": { + "type": "boolean", + "title": "Status Bar Visibility", + "description": "Whether to show status bar or not", + "default": true } }, "additionalProperties": false, diff --git a/packages/statusbar-extension/src/index.ts b/packages/statusbar-extension/src/index.ts index 4c30d2cd3a9a..7afde6c827eb 100644 --- a/packages/statusbar-extension/src/index.ts +++ b/packages/statusbar-extension/src/index.ts @@ -7,7 +7,7 @@ import { JupyterFrontEndPlugin } from '@jupyterlab/application'; -import { IClientSession } from '@jupyterlab/apputils'; +import { IClientSession, ICommandPalette } from '@jupyterlab/apputils'; import { Cell, CodeCell } from '@jupyterlab/cells'; @@ -36,6 +36,10 @@ import { StatusBar } from '@jupyterlab/statusbar'; +import { ISettingRegistry } from '@jupyterlab/coreutils'; + +import { IMainMenu } from '@jupyterlab/mainmenu'; + import { Title, Widget } from '@phosphor/widgets'; export const STATUSBAR_PLUGIN_ID = '@jupyterlab/statusbar-extension:plugin'; @@ -47,7 +51,13 @@ const statusBar: JupyterFrontEndPlugin = { id: STATUSBAR_PLUGIN_ID, provides: IStatusBar, autoStart: true, - activate: (app: JupyterFrontEnd, labShell: ILabShell | null) => { + activate: ( + app: JupyterFrontEnd, + labShell: ILabShell | null, + settingRegistry: ISettingRegistry | null, + mainMenu: IMainMenu | null, + palette: ICommandPalette | null + ) => { const statusBar = new StatusBar(); statusBar.id = 'jp-main-statusbar'; app.shell.add(statusBar, 'bottom'); @@ -59,9 +69,52 @@ const statusBar: JupyterFrontEndPlugin = { }); } + const category: string = 'Main Area'; + const command: string = 'statusbar:toggle'; + + app.commands.addCommand(command, { + label: 'Show Status Bar', + execute: (args: any) => { + statusBar.setHidden(statusBar.isVisible); + if (settingRegistry) { + settingRegistry.set( + STATUSBAR_PLUGIN_ID, + 'visible', + statusBar.isVisible + ); + } + }, + isToggled: () => statusBar.isVisible + }); + + if (palette) { + palette.addItem({ command, category }); + } + if (mainMenu) { + mainMenu.viewMenu.addGroup([{ command }], 1); + } + + if (settingRegistry) { + const updateSettings = (settings: ISettingRegistry.ISettings): void => { + const visible = settings.get('visible').composite as boolean; + statusBar.setHidden(!visible); + }; + + Promise.all([settingRegistry.load(STATUSBAR_PLUGIN_ID), app.restored]) + .then(([settings]) => { + updateSettings(settings); + settings.changed.connect(settings => { + updateSettings(settings); + }); + }) + .catch((reason: Error) => { + console.error(reason.message); + }); + } + return statusBar; }, - optional: [ILabShell] + optional: [ILabShell, ISettingRegistry, IMainMenu, ICommandPalette] }; /** diff --git a/packages/statusbar-extension/tsconfig.json b/packages/statusbar-extension/tsconfig.json index d0d6245041c1..494257101a73 100644 --- a/packages/statusbar-extension/tsconfig.json +++ b/packages/statusbar-extension/tsconfig.json @@ -18,12 +18,18 @@ { "path": "../console" }, + { + "path": "../coreutils" + }, { "path": "../docregistry" }, { "path": "../fileeditor" }, + { + "path": "../mainmenu" + }, { "path": "../notebook" },