mirror of
https://github.com/jupyter/notebook.git
synced 2025-03-01 12:56:54 +08:00
Merge pull request #114 from jtpio/new-terminal-plugin
Move the "New Terminal" button to its own plugin
This commit is contained in:
commit
d31291fed9
65
app/index.js
65
app/index.js
@ -124,35 +124,42 @@ async function main() {
|
||||
// The motivation here is to only load a specific set of plugins dependending on
|
||||
// the current page
|
||||
const page = PageConfig.getOption('classicPage');
|
||||
if (page === 'tree') {
|
||||
mods = mods.concat([
|
||||
require('@jupyterlab-classic/tree-extension'),
|
||||
require('@jupyterlab/running-extension')
|
||||
]);
|
||||
} else if (page === 'notebooks') {
|
||||
mods = mods.concat([
|
||||
require('@jupyterlab/completer-extension').default.filter(({ id }) =>
|
||||
['@jupyterlab/completer-extension:notebooks'].includes(id)
|
||||
),
|
||||
require('@jupyterlab/tooltip-extension').default.filter(({ id }) =>
|
||||
[
|
||||
'@jupyterlab/tooltip-extension:manager',
|
||||
'@jupyterlab/tooltip-extension:notebooks'
|
||||
].includes(id)
|
||||
)
|
||||
]);
|
||||
} else if (page === 'edit') {
|
||||
mods = mods.concat([
|
||||
require('@jupyterlab/completer-extension').default.filter(({ id }) =>
|
||||
['@jupyterlab/completer-extension:files'].includes(id)
|
||||
),
|
||||
require('@jupyterlab/fileeditor-extension').default.filter(({ id }) =>
|
||||
['@jupyterlab/fileeditor-extension:plugin'].includes(id)
|
||||
),
|
||||
require('@jupyterlab-classic/tree-extension').default.filter(({ id }) =>
|
||||
['@jupyterlab-classic/tree-extension:factory'].includes(id)
|
||||
)
|
||||
]);
|
||||
switch (page) {
|
||||
case 'tree': {
|
||||
mods = mods.concat([
|
||||
require('@jupyterlab-classic/tree-extension'),
|
||||
require('@jupyterlab/running-extension')
|
||||
]);
|
||||
break;
|
||||
}
|
||||
case 'notebooks': {
|
||||
mods = mods.concat([
|
||||
require('@jupyterlab/completer-extension').default.filter(({ id }) =>
|
||||
['@jupyterlab/completer-extension:notebooks'].includes(id)
|
||||
),
|
||||
require('@jupyterlab/tooltip-extension').default.filter(({ id }) =>
|
||||
[
|
||||
'@jupyterlab/tooltip-extension:manager',
|
||||
'@jupyterlab/tooltip-extension:notebooks'
|
||||
].includes(id)
|
||||
)
|
||||
]);
|
||||
break;
|
||||
}
|
||||
case 'edit': {
|
||||
mods = mods.concat([
|
||||
require('@jupyterlab/completer-extension').default.filter(({ id }) =>
|
||||
['@jupyterlab/completer-extension:files'].includes(id)
|
||||
),
|
||||
require('@jupyterlab/fileeditor-extension').default.filter(({ id }) =>
|
||||
['@jupyterlab/fileeditor-extension:plugin'].includes(id)
|
||||
),
|
||||
require('@jupyterlab-classic/tree-extension').default.filter(({ id }) =>
|
||||
['@jupyterlab-classic/tree-extension:factory'].includes(id)
|
||||
)
|
||||
]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,7 +124,7 @@ namespace CommandIDs {
|
||||
* Plugin to add extra buttons to the file browser to create
|
||||
* new notebooks, files and terminals.
|
||||
*/
|
||||
const buttons: JupyterFrontEndPlugin<void> = {
|
||||
const newFiles: JupyterFrontEndPlugin<void> = {
|
||||
id: '@jupyterlab-classic/tree-extension:buttons',
|
||||
requires: [IFileBrowserFactory],
|
||||
autoStart: true,
|
||||
@ -142,15 +142,6 @@ const buttons: JupyterFrontEndPlugin<void> = {
|
||||
}
|
||||
});
|
||||
|
||||
const newTerminalCommand = 'tree:new-terminal';
|
||||
commands.addCommand(newTerminalCommand, {
|
||||
label: 'New Terminal',
|
||||
icon: terminalIcon,
|
||||
execute: () => {
|
||||
return commands.execute('terminal:create-new');
|
||||
}
|
||||
});
|
||||
|
||||
const newNotebook = new CommandToolbarButton({
|
||||
commands,
|
||||
id: newNotebookCommand
|
||||
@ -161,13 +152,36 @@ const buttons: JupyterFrontEndPlugin<void> = {
|
||||
id: CommandIDs.createNewFile
|
||||
});
|
||||
|
||||
browser.toolbar.insertItem(0, 'new-notebook', newNotebook);
|
||||
browser.toolbar.insertItem(1, 'new-file', newFile);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Plugin to add a "New Terminal" button to the file browser toolbar.
|
||||
*/
|
||||
const newTerminal: JupyterFrontEndPlugin<void> = {
|
||||
id: '@jupyterlab-classic/tree-extension:new-terminal',
|
||||
requires: [IFileBrowserFactory],
|
||||
autoStart: true,
|
||||
activate: (app: JupyterFrontEnd, filebrowser: IFileBrowserFactory) => {
|
||||
const { commands } = app;
|
||||
const browser = filebrowser.defaultBrowser;
|
||||
|
||||
const newTerminalCommand = 'tree:new-terminal';
|
||||
commands.addCommand(newTerminalCommand, {
|
||||
label: 'New Terminal',
|
||||
icon: terminalIcon,
|
||||
execute: () => {
|
||||
return commands.execute('terminal:create-new');
|
||||
}
|
||||
});
|
||||
|
||||
const newTerminal = new CommandToolbarButton({
|
||||
commands,
|
||||
id: newTerminalCommand
|
||||
});
|
||||
|
||||
browser.toolbar.insertItem(0, 'new-notebook', newNotebook);
|
||||
browser.toolbar.insertItem(1, 'new-file', newFile);
|
||||
browser.toolbar.insertItem(2, 'new-terminal', newTerminal);
|
||||
}
|
||||
};
|
||||
@ -964,5 +978,10 @@ namespace Private {
|
||||
/**
|
||||
* Export the plugins as default.
|
||||
*/
|
||||
const plugins: JupyterFrontEndPlugin<any>[] = [browser, buttons, factory];
|
||||
const plugins: JupyterFrontEndPlugin<any>[] = [
|
||||
browser,
|
||||
factory,
|
||||
newFiles,
|
||||
newTerminal
|
||||
];
|
||||
export default plugins;
|
||||
|
Loading…
Reference in New Issue
Block a user