Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logout button #6087

Merged
merged 2 commits into from May 2, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 31 additions & 12 deletions packages/mainmenu-extension/src/index.ts
Expand Up @@ -10,7 +10,8 @@ import { Menu, Widget } from '@phosphor/widgets';
import {
ILabShell,
JupyterFrontEnd,
JupyterFrontEndPlugin
JupyterFrontEndPlugin,
IRouter
} from '@jupyterlab/application';

import { ICommandPalette, showDialog, Dialog } from '@jupyterlab/apputils';
Expand Down Expand Up @@ -60,7 +61,9 @@ export namespace CommandIDs {

export const createConsole = 'filemenu:create-console';

export const quit = 'filemenu:quit';
export const shutdown = 'filemenu:shutdown';

export const logout = 'filemenu:logout';

export const openKernel = 'kernelmenu:open';

Expand Down Expand Up @@ -115,12 +118,13 @@ export namespace CommandIDs {
*/
const plugin: JupyterFrontEndPlugin<IMainMenu> = {
id: '@jupyterlab/mainmenu-extension:plugin',
requires: [ICommandPalette],
requires: [ICommandPalette, IRouter],
optional: [IInspector, ILabShell],
provides: IMainMenu,
activate: (
app: JupyterFrontEnd,
palette: ICommandPalette,
router: IRouter,
inspector: IInspector | null,
labShell: ILabShell | null
): IMainMenu => {
Expand All @@ -140,7 +144,7 @@ const plugin: JupyterFrontEndPlugin<IMainMenu> = {

// Create the application menus.
createEditMenu(app, menu.editMenu);
createFileMenu(app, menu.fileMenu, inspector);
createFileMenu(app, menu.fileMenu, router, inspector);
createKernelMenu(app, menu.kernelMenu);
createRunMenu(app, menu.runMenu);
createSettingsMenu(app, menu.settingsMenu);
Expand Down Expand Up @@ -200,7 +204,7 @@ const plugin: JupyterFrontEndPlugin<IMainMenu> = {
// Add some of the commands defined here to the command palette.
if (menu.fileMenu.quitEntry) {
palette.addItem({
command: CommandIDs.quit,
command: CommandIDs.shutdown,
category: 'Main Area'
});
}
Expand Down Expand Up @@ -300,6 +304,7 @@ export function createEditMenu(app: JupyterFrontEnd, menu: EditMenu): void {
export function createFileMenu(
app: JupyterFrontEnd,
menu: FileMenu,
router: IRouter,
inspector: IInspector | null
): void {
const commands = menu.menu.commands;
Expand Down Expand Up @@ -342,14 +347,17 @@ export function createFileMenu(
execute: Private.delegateExecute(app, menu.consoleCreators, 'createConsole')
});

commands.addCommand(CommandIDs.quit, {
label: 'Quit',
caption: 'Quit JupyterLab',
commands.addCommand(CommandIDs.shutdown, {
label: 'Shutdown',
caption: 'Shut down JupyterLab',
execute: () => {
return showDialog({
title: 'Quit confirmation',
body: 'Please confirm you want to quit JupyterLab.',
buttons: [Dialog.cancelButton(), Dialog.warnButton({ label: 'Quit' })]
title: 'Shut down confirmation',
jasongrout marked this conversation as resolved.
Show resolved Hide resolved
body: 'Please confirm you want to shut down JupyterLab.',
buttons: [
Dialog.cancelButton(),
Dialog.warnButton({ label: 'Shut Down' })
]
}).then(result => {
if (result.button.accept) {
let setting = ServerConnection.makeSettings();
Expand Down Expand Up @@ -383,6 +391,14 @@ export function createFileMenu(
}
});

commands.addCommand(CommandIDs.logout, {
label: 'Logout',
caption: 'Log out of JupyterLab',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title: 'Logout confirmation',

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a confirmation dialog for logout, should I add one? The classic notebook didn't

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's the difference, we don't need a title because we don't have a dialog? Okay, never mind. Let's go with the classic behavior for now, unless there is a strong reason to change.

execute: () => {
router.navigate('/logout', { hard: true });
}
});

// Add the new group
const newGroup = [
{ type: 'submenu' as Menu.ItemType, submenu: menu.newMenu.menu },
Expand Down Expand Up @@ -424,7 +440,10 @@ export function createFileMenu(
});

// Add the quit group.
const quitGroup = [{ command: 'filemenu:quit' }];
const quitGroup = [
{ command: 'filemenu:logout' },
{ command: 'filemenu:shutdown' }
];

menu.addGroup(newGroup, 0);
menu.addGroup(newViewGroup, 1);
Expand Down