mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-30 12:11:32 +08:00
Add the New Console button to the file browser
This commit is contained in:
parent
f2a2a68b09
commit
d3d829de4a
@ -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');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -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
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user