Add the New Console button to the file browser

This commit is contained in:
Jeremy Tuloup 2021-08-30 08:58:04 +02:00
parent f2a2a68b09
commit d3d829de4a
2 changed files with 24 additions and 7 deletions

View File

@ -54,14 +54,15 @@ const redirect: JupyterFrontEndPlugin<void> = {
autoStart: true,
activate: (app: JupyterFrontEnd, tracker: IConsoleTracker) => {
const baseUrl = PageConfig.getBaseUrl();
tracker.widgetAdded.connect((send, console) => {
tracker.widgetAdded.connect(async (send, console) => {
const widget = find(app.shell.widgets('main'), w => w.id === console.id);
if (widget) {
// bail if the console is already added to the main area
return;
}
const name = console.sessionContext.name;
window.open(`${baseUrl}retro/consoles/${name}`, '_blank');
const { sessionContext } = console;
await sessionContext.ready;
window.open(`${baseUrl}retro/consoles/${sessionContext.name}`, '_blank');
});
}
};

View File

@ -14,6 +14,7 @@ import { IRunningSessionManagers, RunningSessions } from '@jupyterlab/running';
import { ITranslator } from '@jupyterlab/translation';
import {
consoleIcon,
notebookIcon,
runningIcon,
terminalIcon
@ -23,9 +24,9 @@ import { TabPanel } from '@lumino/widgets';
/**
* Plugin to add extra buttons to the file browser to create
* new notebooks, files and terminals.
* new notebooks, consoles, files and terminals.
*/
const newFiles: JupyterFrontEndPlugin<void> = {
const newButtons: JupyterFrontEndPlugin<void> = {
id: '@retrolab/tree-extension:buttons',
requires: [IFileBrowserFactory],
autoStart: true,
@ -43,18 +44,33 @@ const newFiles: JupyterFrontEndPlugin<void> = {
}
});
const newConsoleCommand = 'tree:new-console';
commands.addCommand(newConsoleCommand, {
label: 'New Console',
icon: consoleIcon,
execute: () => {
return commands.execute('console:create');
}
});
const newNotebook = new CommandToolbarButton({
commands,
id: newNotebookCommand
});
const newConsole = new CommandToolbarButton({
commands,
id: newConsoleCommand
});
const newFile = new CommandToolbarButton({
commands,
id: 'filebrowser:create-new-file'
});
browser.toolbar.insertItem(0, 'new-notebook', newNotebook);
browser.toolbar.insertItem(1, 'new-file', newFile);
browser.toolbar.insertItem(1, 'new-console', newConsole);
browser.toolbar.insertItem(2, 'new-file', newFile);
}
};
@ -125,7 +141,7 @@ const browserWidget: JupyterFrontEndPlugin<void> = {
* Export the plugins as default.
*/
const plugins: JupyterFrontEndPlugin<any>[] = [
newFiles,
newButtons,
newTerminal,
browserWidget
];