-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
index.ts
185 lines (159 loc) · 4.97 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { CommandToolbarButton } from '@jupyterlab/apputils';
import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
import { IRunningSessionManagers, RunningSessions } from '@jupyterlab/running';
import { ITranslator } from '@jupyterlab/translation';
import {
consoleIcon,
folderIcon,
notebookIcon,
runningIcon,
terminalIcon
} from '@jupyterlab/ui-components';
import { TabPanel } from '@lumino/widgets';
/**
* Plugin to add extra buttons to the file browser to create new notebooks and files
*/
const newFiles: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/tree-extension:buttons',
requires: [IFileBrowserFactory, ITranslator],
autoStart: true,
activate: (
app: JupyterFrontEnd,
filebrowser: IFileBrowserFactory,
translator: ITranslator
) => {
const { commands } = app;
const browser = filebrowser.defaultBrowser;
const trans = translator.load('notebook');
// wrapper commands to be able to override the label
const newNotebookCommand = 'tree:new-notebook';
commands.addCommand(newNotebookCommand, {
label: trans.__('New Notebook'),
icon: notebookIcon,
execute: () => {
return commands.execute('notebook:create-new');
}
});
const newNotebook = new CommandToolbarButton({
commands,
id: newNotebookCommand
});
const newFile = new CommandToolbarButton({
commands,
id: 'filebrowser:create-new-file'
});
browser.toolbar.insertItem(0, 'new-notebook', newNotebook);
browser.toolbar.insertItem(1, 'new-file', newFile);
}
};
/**
* Plugin to add a "New Console" button to the file browser toolbar.
*/
const newConsole: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/tree-extension:new-console',
requires: [IFileBrowserFactory, ITranslator],
autoStart: true,
activate: (
app: JupyterFrontEnd,
filebrowser: IFileBrowserFactory,
translator: ITranslator
) => {
const { commands } = app;
const browser = filebrowser.defaultBrowser;
const trans = translator.load('notebook');
const newConsoleCommand = 'tree:new-console';
commands.addCommand(newConsoleCommand, {
label: trans.__('New Console'),
icon: consoleIcon,
execute: () => {
return commands.execute('console:create');
}
});
const newConsole = new CommandToolbarButton({
commands,
id: newConsoleCommand
});
browser.toolbar.insertItem(2, 'new-console', newConsole);
}
};
/**
* Plugin to add a "New Terminal" button to the file browser toolbar.
*/
const newTerminal: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/tree-extension:new-terminal',
requires: [IFileBrowserFactory, ITranslator],
autoStart: true,
activate: (
app: JupyterFrontEnd,
filebrowser: IFileBrowserFactory,
translator: ITranslator
) => {
const { commands } = app;
const browser = filebrowser.defaultBrowser;
const trans = translator.load('notebook');
const newTerminalCommand = 'tree:new-terminal';
commands.addCommand(newTerminalCommand, {
label: trans.__('New Terminal'),
icon: terminalIcon,
execute: () => {
return commands.execute('terminal:create-new');
}
});
const newTerminal = new CommandToolbarButton({
commands,
id: newTerminalCommand
});
browser.toolbar.insertItem(3, 'new-terminal', newTerminal);
}
};
/**
* A plugin to add the file browser widget to an ILabShell
*/
const browserWidget: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/tree-extension:widget',
requires: [IFileBrowserFactory, ITranslator],
optional: [IRunningSessionManagers],
autoStart: true,
activate: (
app: JupyterFrontEnd,
factory: IFileBrowserFactory,
translator: ITranslator,
manager: IRunningSessionManagers | null
): void => {
const tabPanel = new TabPanel({ tabPlacement: 'top', tabsMovable: true });
tabPanel.addClass('jp-TreePanel');
const trans = translator.load('notebook');
const { defaultBrowser: browser } = factory;
browser.title.label = trans.__('Files');
browser.node.setAttribute('role', 'region');
browser.node.setAttribute('aria-label', trans.__('File Browser Section'));
browser.title.icon = folderIcon;
tabPanel.addWidget(browser);
tabPanel.tabBar.addTab(browser.title);
if (manager) {
const running = new RunningSessions(manager, translator);
running.id = 'jp-running-sessions';
running.title.label = trans.__('Running');
running.title.icon = runningIcon;
tabPanel.addWidget(running);
tabPanel.tabBar.addTab(running.title);
}
app.shell.add(tabPanel, 'main', { rank: 100 });
}
};
/**
* Export the plugins as default.
*/
const plugins: JupyterFrontEndPlugin<any>[] = [
newFiles,
newConsole,
newTerminal,
browserWidget
];
export default plugins;