diff --git a/packages/application-extension/src/index.tsx b/packages/application-extension/src/index.tsx index d9cf0a57085b..e4c7ec8054af 100644 --- a/packages/application-extension/src/index.tsx +++ b/packages/application-extension/src/index.tsx @@ -90,14 +90,14 @@ namespace CommandIDs { */ const main: JupyterFrontEndPlugin = { id: '@jupyterlab/application-extension:main', - requires: [ICommandPalette, IRouter, IWindowResolver], - optional: [IConnectionLost], + requires: [IRouter, IWindowResolver], + optional: [ICommandPalette, IConnectionLost], activate: ( app: JupyterFrontEnd, - palette: ICommandPalette, router: IRouter, resolver: IWindowResolver, - connectionLost: IConnectionLost | undefined + palette: ICommandPalette | null, + connectionLost: IConnectionLost | null ) => { if (!(app instanceof JupyterLab)) { throw new Error(`${main.id} must be activated in JupyterLab.`); @@ -486,7 +486,7 @@ const sidebar: JupyterFrontEndPlugin = { /** * Add the main application commands. */ -function addCommands(app: JupyterLab, palette: ICommandPalette): void { +function addCommands(app: JupyterLab, palette: ICommandPalette | null): void { const { commands, contextMenu, shell } = app; const category = 'Main Area'; @@ -572,7 +572,6 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void { shell.activateNextTab(); } }); - palette.addItem({ command: CommandIDs.activateNextTab, category }); commands.addCommand(CommandIDs.activatePreviousTab, { label: 'Activate Previous Tab', @@ -580,7 +579,6 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void { shell.activatePreviousTab(); } }); - palette.addItem({ command: CommandIDs.activatePreviousTab, category }); commands.addCommand(CommandIDs.activateNextTabBar, { label: 'Activate Next Tab Bar', @@ -588,7 +586,6 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void { shell.activateNextTabBar(); } }); - palette.addItem({ command: CommandIDs.activateNextTabBar, category }); commands.addCommand(CommandIDs.activatePreviousTabBar, { label: 'Activate Previous Tab Bar', @@ -596,7 +593,6 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void { shell.activatePreviousTabBar(); } }); - palette.addItem({ command: CommandIDs.activatePreviousTabBar, category }); // A CSS selector targeting tabs in the main area. This is a very // specific selector since we really only want tabs that are @@ -614,7 +610,6 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void { } } }); - palette.addItem({ command: CommandIDs.close, category }); contextMenu.addItem({ command: CommandIDs.close, selector: tabSelector, @@ -627,7 +622,6 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void { shell.closeAll(); } }); - palette.addItem({ command: CommandIDs.closeAll, category }); commands.addCommand(CommandIDs.closeOtherTabs, { label: () => `Close All Other Tabs`, @@ -648,7 +642,6 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void { closeWidgets(otherWidgets); } }); - palette.addItem({ command: CommandIDs.closeOtherTabs, category }); contextMenu.addItem({ command: CommandIDs.closeOtherTabs, selector: tabSelector, @@ -667,7 +660,6 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void { closeWidgets(widgetsRightOf(widget)); } }); - palette.addItem({ command: CommandIDs.closeRightTabs, category }); contextMenu.addItem({ command: CommandIDs.closeRightTabs, selector: tabSelector, @@ -689,7 +681,6 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void { isToggled: () => !shell.leftCollapsed, isVisible: () => !shell.isEmpty('left') }); - palette.addItem({ command: CommandIDs.toggleLeftArea, category }); app.commands.addCommand(CommandIDs.toggleRightArea, { label: () => 'Show Right Sidebar', @@ -706,7 +697,6 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void { isToggled: () => !shell.rightCollapsed, isVisible: () => !shell.isEmpty('right') }); - palette.addItem({ command: CommandIDs.toggleRightArea, category }); app.commands.addCommand(CommandIDs.togglePresentationMode, { label: () => 'Presentation Mode', @@ -716,7 +706,6 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void { isToggled: () => shell.presentationMode, isVisible: () => true }); - palette.addItem({ command: CommandIDs.togglePresentationMode, category }); app.commands.addCommand(CommandIDs.setMode, { isVisible: args => { @@ -744,7 +733,21 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void { return app.commands.execute(CommandIDs.setMode, args); } }); - palette.addItem({ command: CommandIDs.toggleMode, category }); + + if (palette) { + palette.addItem({ command: CommandIDs.activateNextTab, category }); + palette.addItem({ command: CommandIDs.activatePreviousTab, category }); + palette.addItem({ command: CommandIDs.activateNextTabBar, category }); + palette.addItem({ command: CommandIDs.activatePreviousTabBar, category }); + palette.addItem({ command: CommandIDs.close, category }); + palette.addItem({ command: CommandIDs.closeAll, category }); + palette.addItem({ command: CommandIDs.closeOtherTabs, category }); + palette.addItem({ command: CommandIDs.closeRightTabs, category }); + palette.addItem({ command: CommandIDs.toggleLeftArea, category }); + palette.addItem({ command: CommandIDs.toggleRightArea, category }); + palette.addItem({ command: CommandIDs.togglePresentationMode, category }); + palette.addItem({ command: CommandIDs.toggleMode, category }); + } } /** diff --git a/packages/console-extension/src/index.ts b/packages/console-extension/src/index.ts index 4dc70aa1d01f..655f4f8a92bf 100644 --- a/packages/console-extension/src/index.ts +++ b/packages/console-extension/src/index.ts @@ -97,8 +97,6 @@ const tracker: JupyterFrontEndPlugin = { id: '@jupyterlab/console-extension:tracker', provides: IConsoleTracker, requires: [ - IMainMenu, - ICommandPalette, ConsolePanel.IContentFactory, IEditorServices, ILayoutRestorer, @@ -106,7 +104,13 @@ const tracker: JupyterFrontEndPlugin = { IRenderMimeRegistry, ISettingRegistry ], - optional: [ILauncher, ILabStatus, ISessionContextDialogs], + optional: [ + IMainMenu, + ICommandPalette, + ILauncher, + ILabStatus, + ISessionContextDialogs + ], activate: activateConsole, autoStart: true }; @@ -136,14 +140,14 @@ export default plugins; */ async function activateConsole( app: JupyterFrontEnd, - mainMenu: IMainMenu, - palette: ICommandPalette, contentFactory: ConsolePanel.IContentFactory, editorServices: IEditorServices, restorer: ILayoutRestorer, browserFactory: IFileBrowserFactory, rendermime: IRenderMimeRegistry, settingRegistry: ISettingRegistry, + mainMenu: IMainMenu | null, + palette: ICommandPalette | null, launcher: ILauncher | null, status: ILabStatus | null, sessionDialogs: ISessionContextDialogs | null @@ -511,90 +515,94 @@ async function activateConsole( isEnabled }); - // Add command palette items - [ - CommandIDs.create, - CommandIDs.linebreak, - CommandIDs.clear, - CommandIDs.runUnforced, - CommandIDs.runForced, - CommandIDs.restart, - CommandIDs.interrupt, - CommandIDs.changeKernel, - CommandIDs.closeAndShutdown - ].forEach(command => { - palette.addItem({ command, category, args: { isPalette: true } }); - }); - - // Add a console creator to the File menu - mainMenu.fileMenu.newMenu.addGroup([{ command: CommandIDs.create }], 0); - - // Add a close and shutdown command to the file menu. - mainMenu.fileMenu.closeAndCleaners.add({ - tracker, - action: 'Shutdown', - name: 'Console', - closeAndCleanup: (current: ConsolePanel) => { - return showDialog({ - title: 'Shut down the console?', - body: `Are you sure you want to close "${current.title.label}"?`, - buttons: [Dialog.cancelButton(), Dialog.warnButton()] - }).then(result => { - if (result.button.accept) { - return current.console.sessionContext.shutdown().then(() => { - current.dispose(); - }); - } else { - return void 0; - } - }); - } - } as IFileMenu.ICloseAndCleaner); + if (palette) { + // Add command palette items + [ + CommandIDs.create, + CommandIDs.linebreak, + CommandIDs.clear, + CommandIDs.runUnforced, + CommandIDs.runForced, + CommandIDs.restart, + CommandIDs.interrupt, + CommandIDs.changeKernel, + CommandIDs.closeAndShutdown + ].forEach(command => { + palette.addItem({ command, category, args: { isPalette: true } }); + }); + } - // Add a kernel user to the Kernel menu - mainMenu.kernelMenu.kernelUsers.add({ - tracker, - interruptKernel: current => { - let kernel = current.console.sessionContext.session?.kernel; - if (kernel) { - return kernel.interrupt(); - } - return Promise.resolve(void 0); - }, - noun: 'Console', - restartKernel: current => - sessionDialogs!.restart(current.console.sessionContext), - restartKernelAndClear: current => { - return sessionDialogs! - .restart(current.console.sessionContext) - .then(restarted => { - if (restarted) { - current.console.clear(); + if (mainMenu) { + // Add a console creator to the File menu + mainMenu.fileMenu.newMenu.addGroup([{ command: CommandIDs.create }], 0); + + // Add a close and shutdown command to the file menu. + mainMenu.fileMenu.closeAndCleaners.add({ + tracker, + action: 'Shutdown', + name: 'Console', + closeAndCleanup: (current: ConsolePanel) => { + return showDialog({ + title: 'Shut down the console?', + body: `Are you sure you want to close "${current.title.label}"?`, + buttons: [Dialog.cancelButton(), Dialog.warnButton()] + }).then(result => { + if (result.button.accept) { + return current.console.sessionContext.shutdown().then(() => { + current.dispose(); + }); + } else { + return void 0; } - return restarted; }); - }, - changeKernel: current => - sessionDialogs!.selectKernel(current.console.sessionContext), - shutdownKernel: current => current.console.sessionContext.shutdown() - } as IKernelMenu.IKernelUser); - - // Add a code runner to the Run menu. - mainMenu.runMenu.codeRunners.add({ - tracker, - noun: 'Cell', - pluralNoun: 'Cells', - run: current => current.console.execute(true) - } as IRunMenu.ICodeRunner); - - // Add a clearer to the edit menu - mainMenu.editMenu.clearers.add({ - tracker, - noun: 'Console Cells', - clearCurrent: (current: ConsolePanel) => { - return current.console.clear(); - } - } as IEditMenu.IClearer); + } + } as IFileMenu.ICloseAndCleaner); + + // Add a kernel user to the Kernel menu + mainMenu.kernelMenu.kernelUsers.add({ + tracker, + interruptKernel: current => { + let kernel = current.console.sessionContext.session?.kernel; + if (kernel) { + return kernel.interrupt(); + } + return Promise.resolve(void 0); + }, + noun: 'Console', + restartKernel: current => + sessionDialogs!.restart(current.console.sessionContext), + restartKernelAndClear: current => { + return sessionDialogs! + .restart(current.console.sessionContext) + .then(restarted => { + if (restarted) { + current.console.clear(); + } + return restarted; + }); + }, + changeKernel: current => + sessionDialogs!.selectKernel(current.console.sessionContext), + shutdownKernel: current => current.console.sessionContext.shutdown() + } as IKernelMenu.IKernelUser); + + // Add a code runner to the Run menu. + mainMenu.runMenu.codeRunners.add({ + tracker, + noun: 'Cell', + pluralNoun: 'Cells', + run: current => current.console.execute(true) + } as IRunMenu.ICodeRunner); + + // Add a clearer to the edit menu + mainMenu.editMenu.clearers.add({ + tracker, + noun: 'Console Cells', + clearCurrent: (current: ConsolePanel) => { + return current.console.clear(); + } + } as IEditMenu.IClearer); + } // For backwards compatibility and clarity, we explicitly label the run // keystroke with the actual effected change, rather than the generic @@ -634,21 +642,23 @@ async function activateConsole( }) ); - mainMenu.settingsMenu.addGroup( - [ - { - type: 'submenu' as Menu.ItemType, - submenu: executeMenu - } - ], - 10 - ); + if (mainMenu) { + mainMenu.settingsMenu.addGroup( + [ + { + type: 'submenu' as Menu.ItemType, + submenu: executeMenu + } + ], + 10 + ); - // Add kernel information to the application help menu. - mainMenu.helpMenu.kernelUsers.add({ - tracker, - getKernel: current => current.sessionContext.session?.kernel - } as IHelpMenu.IKernelUser); + // Add kernel information to the application help menu. + mainMenu.helpMenu.kernelUsers.add({ + tracker, + getKernel: current => current.sessionContext.session?.kernel + } as IHelpMenu.IKernelUser); + } app.contextMenu.addItem({ command: CommandIDs.clear, diff --git a/packages/hub-extension/src/index.ts b/packages/hub-extension/src/index.ts index 9444bcad6372..5c01e9944d4c 100644 --- a/packages/hub-extension/src/index.ts +++ b/packages/hub-extension/src/index.ts @@ -35,8 +35,8 @@ export namespace CommandIDs { function activateHubExtension( app: JupyterFrontEnd, paths: JupyterFrontEnd.IPaths, - palette: ICommandPalette, - mainMenu: IMainMenu + palette: ICommandPalette | null, + mainMenu: IMainMenu | null ): void { const hubHost = paths.urls.hubHost || ''; const hubPrefix = paths.urls.hubPrefix || ''; @@ -85,14 +85,18 @@ function activateHubExtension( } }); - // Add commands and menu itmes. - mainMenu.fileMenu.addGroup( - [{ command: CommandIDs.controlPanel }, { command: CommandIDs.logout }], - 100 - ); - const category = 'Hub'; - palette.addItem({ category, command: CommandIDs.controlPanel }); - palette.addItem({ category, command: CommandIDs.logout }); + // Add palette and menu itmes. + if (mainMenu) { + mainMenu.fileMenu.addGroup( + [{ command: CommandIDs.controlPanel }, { command: CommandIDs.logout }], + 100 + ); + } + if (palette) { + const category = 'Hub'; + palette.addItem({ category, command: CommandIDs.controlPanel }); + palette.addItem({ category, command: CommandIDs.logout }); + } } /** @@ -101,7 +105,8 @@ function activateHubExtension( const hubExtension: JupyterFrontEndPlugin = { activate: activateHubExtension, id: 'jupyter.extensions.hub-extension', - requires: [JupyterFrontEnd.IPaths, ICommandPalette, IMainMenu], + requires: [JupyterFrontEnd.IPaths], + optional: [ICommandPalette, IMainMenu], autoStart: true }; diff --git a/packages/launcher-extension/src/index.ts b/packages/launcher-extension/src/index.ts index ff501aae42ef..d3c6de9cb00f 100644 --- a/packages/launcher-extension/src/index.ts +++ b/packages/launcher-extension/src/index.ts @@ -27,7 +27,8 @@ namespace CommandIDs { const plugin: JupyterFrontEndPlugin = { activate, id: '@jupyterlab/launcher-extension:plugin', - requires: [ICommandPalette, ILabShell], + requires: [ILabShell], + optional: [ICommandPalette], provides: ILauncher, autoStart: true }; @@ -42,8 +43,8 @@ export default plugin; */ function activate( app: JupyterFrontEnd, - palette: ICommandPalette, - labShell: ILabShell + labShell: ILabShell, + palette: ICommandPalette | null ): ILauncher { const { commands } = app; const model = new LauncherModel(); @@ -79,7 +80,9 @@ function activate( } }); - palette.addItem({ command: CommandIDs.create, category: 'Launcher' }); + if (palette) { + palette.addItem({ command: CommandIDs.create, category: 'Launcher' }); + } return model; } diff --git a/packages/mainmenu-extension/src/index.ts b/packages/mainmenu-extension/src/index.ts index 8e0d43e837ff..98427ef72d2c 100644 --- a/packages/mainmenu-extension/src/index.ts +++ b/packages/mainmenu-extension/src/index.ts @@ -116,13 +116,13 @@ export namespace CommandIDs { */ const plugin: JupyterFrontEndPlugin = { id: '@jupyterlab/mainmenu-extension:plugin', - requires: [ICommandPalette, IRouter], - optional: [ILabShell], + requires: [IRouter], + optional: [ICommandPalette, ILabShell], provides: IMainMenu, activate: ( app: JupyterFrontEnd, - palette: ICommandPalette, router: IRouter, + palette: ICommandPalette | null, labShell: ILabShell | null ): IMainMenu => { const { commands } = app; @@ -203,28 +203,30 @@ const plugin: JupyterFrontEndPlugin = { } }); - // Add some of the commands defined here to the command palette. - if (menu.fileMenu.quitEntry) { + if (palette) { + // Add some of the commands defined here to the command palette. + if (menu.fileMenu.quitEntry) { + palette.addItem({ + command: CommandIDs.shutdown, + category: 'Main Area' + }); + palette.addItem({ + command: CommandIDs.logout, + category: 'Main Area' + }); + } + palette.addItem({ - command: CommandIDs.shutdown, - category: 'Main Area' + command: CommandIDs.shutdownAllKernels, + category: 'Kernel Operations' }); + palette.addItem({ - command: CommandIDs.logout, + command: CommandIDs.activatePreviouslyUsedTab, category: 'Main Area' }); } - palette.addItem({ - command: CommandIDs.shutdownAllKernels, - category: 'Kernel Operations' - }); - - palette.addItem({ - command: CommandIDs.activatePreviouslyUsedTab, - category: 'Main Area' - }); - app.shell.add(logo, 'top'); app.shell.add(menu, 'top'); diff --git a/packages/settingeditor-extension/src/index.ts b/packages/settingeditor-extension/src/index.ts index fb4c7bc8f3be..128217657226 100644 --- a/packages/settingeditor-extension/src/index.ts +++ b/packages/settingeditor-extension/src/index.ts @@ -47,9 +47,9 @@ const plugin: JupyterFrontEndPlugin = { IEditorServices, IStateDB, IRenderMimeRegistry, - ICommandPalette, ILabStatus ], + optional: [ICommandPalette], autoStart: true, provides: ISettingEditorTracker, activate @@ -65,8 +65,8 @@ function activate( editorServices: IEditorServices, state: IStateDB, rendermime: IRenderMimeRegistry, - palette: ICommandPalette, - status: ILabStatus + status: ILabStatus, + palette: ICommandPalette | null ): ISettingEditorTracker { const { commands, shell } = app; const namespace = 'setting-editor'; @@ -141,7 +141,9 @@ function activate( }, label: 'Advanced Settings Editor' }); - palette.addItem({ category: 'Settings', command: CommandIDs.open }); + if (palette) { + palette.addItem({ category: 'Settings', command: CommandIDs.open }); + } commands.addCommand(CommandIDs.revert, { execute: () => {