Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Interface switcher menu #309

Merged
merged 3 commits into from
Dec 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/lab-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@
"@jupyterlab/mainmenu": "^3.2.0",
"@jupyterlab/notebook": "^3.2.0",
"@jupyterlab/translation": "^3.2.0",
"@jupyterlab/ui-components": "^3.2.0",
"@lumino/commands": "^1.15.0",
"@lumino/disposable": "^1.7.0",
"@retrolab/application": "^0.3.13",
"@retrolab/ui-components": "^0.3.13"
"@retrolab/application": "^0.3.13"
},
"devDependencies": {
"@jupyterlab/builder": "^3.2.0",
Expand Down
47 changes: 17 additions & 30 deletions packages/lab-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
JupyterFrontEndPlugin
} from '@jupyterlab/application';

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

import { PageConfig } from '@jupyterlab/coreutils';

Expand All @@ -17,16 +17,10 @@ import { INotebookTracker, NotebookPanel } from '@jupyterlab/notebook';

import { ITranslator } from '@jupyterlab/translation';

import {
jupyterIcon,
jupyterFaviconIcon,
LabIcon
} from '@jupyterlab/ui-components';
import { Menu, MenuBar } from '@lumino/widgets';

import { IRetroShell } from '@retrolab/application';

import { retroSunIcon } from '@retrolab/ui-components';

/**
* The command IDs used by the application plugin.
*/
Expand Down Expand Up @@ -56,7 +50,6 @@ interface ISwitcherChoice {
command: string;
commandLabel: string;
buttonLabel: string;
icon: LabIcon;
urlPrefix: string;
}

Expand Down Expand Up @@ -84,13 +77,17 @@ const launchButtons: JupyterFrontEndPlugin<void> = {
labShell: ILabShell | null
) => {
if (!notebookTracker) {
// to prevent showing the toolbar button in RetroLab
// to prevent showing the toolbar button in non-notebook pages
return;
}

const { commands, shell } = app;
const baseUrl = PageConfig.getBaseUrl();
const trans = translator.load('retrolab');
const menubar = new MenuBar();
const switcher = new Menu({ commands });
switcher.title.label = trans.__('Interface');
menubar.addMenu(switcher);

const isEnabled = () => {
return (
Expand All @@ -100,11 +97,10 @@ const launchButtons: JupyterFrontEndPlugin<void> = {
};

const addInterface = (option: ISwitcherChoice) => {
const { command, icon, buttonLabel, commandLabel, urlPrefix } = option;
const { command, commandLabel, urlPrefix } = option;
commands.addCommand(command, {
label: args => (args.noLabel ? '' : commandLabel),
caption: commandLabel,
icon,
execute: () => {
const current = notebookTracker.currentWidget;
if (!current) {
Expand All @@ -123,29 +119,14 @@ const launchButtons: JupyterFrontEndPlugin<void> = {
menu.viewMenu.addGroup([{ command }], 1);
}

notebookTracker.widgetAdded.connect(
async (sender: INotebookTracker, panel: NotebookPanel) => {
panel.toolbar.insertBefore(
'kernelName',
buttonLabel,
new CommandToolbarButton({
commands,
id: command,
args: { noLabel: 1 }
})
);
await panel.context.ready;
commands.notifyCommandChanged();
}
);
switcher.addItem({ command });
};

// always add Classic
addInterface({
command: 'retrolab:open-classic',
commandLabel: trans.__('Open With %1', 'Classic Notebook'),
buttonLabel: 'openClassic',
icon: jupyterIcon,
urlPrefix: `${baseUrl}tree/`
});

Expand All @@ -154,7 +135,6 @@ const launchButtons: JupyterFrontEndPlugin<void> = {
command: 'retrolab:open-retro',
commandLabel: trans.__('Open With %1', 'RetroLab'),
buttonLabel: 'openRetro',
icon: retroSunIcon,
urlPrefix: `${baseUrl}retro/tree/`
});
}
Expand All @@ -164,10 +144,17 @@ const launchButtons: JupyterFrontEndPlugin<void> = {
command: 'retrolab:open-lab',
commandLabel: trans.__('Open With %1', 'JupyterLab'),
buttonLabel: 'openLab',
icon: jupyterFaviconIcon,
urlPrefix: `${baseUrl}doc/tree/`
});
}

notebookTracker.widgetAdded.connect(
async (sender: INotebookTracker, panel: NotebookPanel) => {
panel.toolbar.insertBefore('kernelName', 'interface-switcher', menubar);
await panel.context.ready;
commands.notifyCommandChanged();
}
);
}
};

Expand Down
3 changes: 0 additions & 3 deletions packages/lab-extension/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
"references": [
{
"path": "../application"
},
{
"path": "../ui-components"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ui-tests/test/mobile.spec.ts-snapshots/notebook-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ui-tests/test/mobile.spec.ts-snapshots/notebook-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.