Skip to content

Commit

Permalink
Add commands to file menu, command palette.
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-r-rose authored and blink1073 committed Jun 7, 2019
1 parent 8f3c6e7 commit d99a4e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/application/src/frontend.ts
Expand Up @@ -43,7 +43,7 @@ export abstract class JupyterFrontEnd<
// The default restored promise if one does not exist in the options.
const restored = new Promise<void>(resolve => {
requestAnimationFrame(() => {
resolve(void 0);
resolve();
});
});

Expand Down
31 changes: 15 additions & 16 deletions packages/hub-extension/src/index.ts
Expand Up @@ -3,11 +3,10 @@
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

import { Menu } from '@phosphor/widgets';

import { ICommandPalette } from '@jupyterlab/apputils';

import {
IRouter,
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
Expand All @@ -30,16 +29,17 @@ export namespace CommandIDs {
*/
function activateHubExtension(
app: JupyterFrontEnd,
router: IRouter,
paths: JupyterFrontEnd.IPaths,
palette: ICommandPalette,
mainMenu: IMainMenu
): void {
const hubHost = paths.urls.hubHost;
const hubPrefix = paths.urls.hubPrefix;
const hubHost = paths.urls.hubHost || '';
const hubPrefix = paths.urls.hubPrefix || '';
const baseUrl = paths.urls.base;

// Bail if not running on JupyterHub.
if (!hubPrefix || !hubHost) {
if (!hubPrefix) {
return;
}

Expand All @@ -48,33 +48,32 @@ function activateHubExtension(
hubPrefix: hubPrefix
});

const category = 'Hub';
const { commands } = app;

commands.addCommand(CommandIDs.controlPanel, {
label: 'Control Panel',
label: 'Hub Control Panel',
caption: 'Open the Hub control panel in a new browser tab',
execute: () => {
window.open(hubHost + URLExt.join(hubPrefix, 'home'), '_blank');
}
});

commands.addCommand(CommandIDs.logout, {
label: 'Logout',
label: 'Log Out',
caption: 'Log out of the Hub',
execute: () => {
window.location.href = hubHost + URLExt.join(baseUrl, 'logout');
}
});

// Add commands and menu itmes.
let menu = new Menu({ commands });
menu.title.label = category;
[CommandIDs.controlPanel, CommandIDs.logout].forEach(command => {
palette.addItem({ command, category });
menu.addItem({ command });
});
mainMenu.addMenu(menu, { rank: 100 });
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 });
}

/**
Expand All @@ -83,7 +82,7 @@ function activateHubExtension(
const hubExtension: JupyterFrontEndPlugin<void> = {
activate: activateHubExtension,
id: 'jupyter.extensions.hub-extension',
requires: [JupyterFrontEnd.IPaths, ICommandPalette, IMainMenu],
requires: [IRouter, JupyterFrontEnd.IPaths, ICommandPalette, IMainMenu],
autoStart: true
};

Expand Down

0 comments on commit d99a4e3

Please sign in to comment.