@jupyterlab/running-extension 4.0.0-alpha.2 → 4.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +10 -0
- package/lib/index.js +7 -3
- package/lib/index.js.map +1 -1
- package/lib/kernels.d.ts +1 -1
- package/lib/kernels.js +173 -42
- package/lib/kernels.js.map +1 -1
- package/lib/opentabs.js +3 -4
- package/lib/opentabs.js.map +1 -1
- package/package.json +17 -14
- package/schema/plugin.json +37 -0
- package/src/index.ts +92 -0
- package/src/kernels.ts +269 -0
- package/src/opentabs.ts +122 -0
package/lib/index.d.ts
CHANGED
|
@@ -4,6 +4,16 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { JupyterFrontEndPlugin } from '@jupyterlab/application';
|
|
6
6
|
import { IRunningSessionManagers } from '@jupyterlab/running';
|
|
7
|
+
/**
|
|
8
|
+
* The command IDs used by the running plugin.
|
|
9
|
+
*/
|
|
10
|
+
export declare namespace CommandIDs {
|
|
11
|
+
const kernelNewConsole = "running:kernel-new-console";
|
|
12
|
+
const kernelNewNotebook = "running:kernel-new-notebook";
|
|
13
|
+
const kernelOpenSession = "running:kernel-open-session";
|
|
14
|
+
const kernelShutDown = "running:kernel-shut-down";
|
|
15
|
+
const showPanel = "running:show-panel";
|
|
16
|
+
}
|
|
7
17
|
/**
|
|
8
18
|
* The default running sessions extension.
|
|
9
19
|
*/
|
package/lib/index.js
CHANGED
|
@@ -13,8 +13,12 @@ import { addOpenTabsSessionManager } from './opentabs';
|
|
|
13
13
|
/**
|
|
14
14
|
* The command IDs used by the running plugin.
|
|
15
15
|
*/
|
|
16
|
-
var CommandIDs;
|
|
16
|
+
export var CommandIDs;
|
|
17
17
|
(function (CommandIDs) {
|
|
18
|
+
CommandIDs.kernelNewConsole = 'running:kernel-new-console';
|
|
19
|
+
CommandIDs.kernelNewNotebook = 'running:kernel-new-notebook';
|
|
20
|
+
CommandIDs.kernelOpenSession = 'running:kernel-open-session';
|
|
21
|
+
CommandIDs.kernelShutDown = 'running:kernel-shut-down';
|
|
18
22
|
CommandIDs.showPanel = 'running:show-panel';
|
|
19
23
|
})(CommandIDs || (CommandIDs = {}));
|
|
20
24
|
/**
|
|
@@ -53,10 +57,10 @@ function activate(app, translator, restorer, labShell) {
|
|
|
53
57
|
if (labShell) {
|
|
54
58
|
addOpenTabsSessionManager(runningSessionManagers, translator, labShell);
|
|
55
59
|
}
|
|
56
|
-
addKernelRunningSessionManager(runningSessionManagers, translator, app);
|
|
60
|
+
void addKernelRunningSessionManager(runningSessionManagers, translator, app);
|
|
57
61
|
// Rank has been chosen somewhat arbitrarily to give priority to the running
|
|
58
62
|
// sessions widget in the sidebar.
|
|
59
|
-
app.shell.add(running, 'left', { rank: 200 });
|
|
63
|
+
app.shell.add(running, 'left', { rank: 200, type: 'Sessions and Tabs' });
|
|
60
64
|
app.commands.addCommand(CommandIDs.showPanel, {
|
|
61
65
|
label: trans.__('Sessions and Tabs'),
|
|
62
66
|
execute: () => {
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAC3D;;;GAGG;AAEH,OAAO,EACL,SAAS,EACT,eAAe,EAGhB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,8BAA8B,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mapp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ernel manager (notebooks & consoles) to the running panel.
|
|
6
6
|
*/
|
|
7
|
-
export declare function addKernelRunningSessionManager(managers: IRunningSessionManagers, translator: ITranslator, app: JupyterFrontEnd): void
|
|
7
|
+
export declare function addKernelRunningSessionManager(managers: IRunningSessionManagers, translator: ITranslator, app: JupyterFrontEnd): Promise<void>;
|
package/lib/kernels.js
CHANGED
|
@@ -1,70 +1,201 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
3
|
import { PathExt } from '@jupyterlab/coreutils';
|
|
4
|
-
import { consoleIcon,
|
|
5
|
-
import {
|
|
4
|
+
import { closeIcon, consoleIcon, jupyterIcon, notebookIcon } from '@jupyterlab/ui-components';
|
|
5
|
+
import { Throttler } from '@lumino/polling';
|
|
6
|
+
import { Signal } from '@lumino/signaling';
|
|
7
|
+
import { CommandIDs } from '.';
|
|
8
|
+
const ITEM_CLASS = 'jp-mod-kernel';
|
|
6
9
|
/**
|
|
7
10
|
* Add the running kernel manager (notebooks & consoles) to the running panel.
|
|
8
11
|
*/
|
|
9
|
-
export function addKernelRunningSessionManager(managers, translator, app) {
|
|
12
|
+
export async function addKernelRunningSessionManager(managers, translator, app) {
|
|
13
|
+
const { commands, contextMenu, serviceManager } = app;
|
|
14
|
+
const { kernels, kernelspecs, sessions } = serviceManager;
|
|
15
|
+
const { runningChanged, RunningKernel } = Private;
|
|
16
|
+
const throttler = new Throttler(() => runningChanged.emit(undefined), 100);
|
|
10
17
|
const trans = translator.load('jupyterlab');
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
// Throttle signal emissions from the kernel and session managers.
|
|
19
|
+
kernels.runningChanged.connect(() => void throttler.invoke());
|
|
20
|
+
sessions.runningChanged.connect(() => void throttler.invoke());
|
|
21
|
+
// Wait until the relevant services are ready.
|
|
22
|
+
await Promise.all([kernels.ready, kernelspecs.ready, sessions.ready]);
|
|
23
|
+
// Add the kernels pane to the running sidebar.
|
|
16
24
|
managers.add({
|
|
17
25
|
name: trans.__('Kernels'),
|
|
18
|
-
running: () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
running: () => Array.from(kernels.running()).map(kernel => {
|
|
27
|
+
var _a;
|
|
28
|
+
return new RunningKernel({
|
|
29
|
+
commands,
|
|
30
|
+
kernel,
|
|
31
|
+
kernels,
|
|
32
|
+
sessions,
|
|
33
|
+
spec: (_a = kernelspecs.specs) === null || _a === void 0 ? void 0 : _a.kernelspecs[kernel.name],
|
|
34
|
+
trans
|
|
35
|
+
});
|
|
36
|
+
}),
|
|
37
|
+
shutdownAll: () => kernels.shutdownAll(),
|
|
38
|
+
refreshRunning: () => Promise.all([kernels.refreshRunning(), sessions.refreshRunning()]),
|
|
39
|
+
runningChanged,
|
|
40
|
+
shutdownLabel: trans.__('Shut Down Kernel'),
|
|
27
41
|
shutdownAllLabel: trans.__('Shut Down All'),
|
|
28
42
|
shutdownAllConfirmationText: trans.__('Are you sure you want to permanently shut down all running kernels?')
|
|
29
43
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
44
|
+
// Add running kernels commands to the registry.
|
|
45
|
+
const test = (node) => node.classList.contains(ITEM_CLASS);
|
|
46
|
+
commands.addCommand(CommandIDs.kernelNewConsole, {
|
|
47
|
+
icon: consoleIcon,
|
|
48
|
+
label: trans.__('New Console for Kernel'),
|
|
49
|
+
execute: args => {
|
|
50
|
+
var _a;
|
|
51
|
+
const node = app.contextMenuHitTest(test);
|
|
52
|
+
const id = (_a = args.id) !== null && _a !== void 0 ? _a : node === null || node === void 0 ? void 0 : node.dataset['context'];
|
|
53
|
+
if (id) {
|
|
54
|
+
return commands.execute('console:create', { kernelPreference: { id } });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
commands.addCommand(CommandIDs.kernelNewNotebook, {
|
|
59
|
+
icon: notebookIcon,
|
|
60
|
+
label: trans.__('New Notebook for Kernel'),
|
|
61
|
+
execute: args => {
|
|
62
|
+
var _a;
|
|
63
|
+
const node = app.contextMenuHitTest(test);
|
|
64
|
+
const id = (_a = args.id) !== null && _a !== void 0 ? _a : node === null || node === void 0 ? void 0 : node.dataset['context'];
|
|
65
|
+
if (id) {
|
|
66
|
+
return commands.execute('notebook:create-new', { kernelId: id });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
commands.addCommand(CommandIDs.kernelOpenSession, {
|
|
71
|
+
icon: args => args.type === 'console'
|
|
72
|
+
? consoleIcon
|
|
73
|
+
: args.type === 'notebook'
|
|
74
|
+
? notebookIcon
|
|
75
|
+
: undefined,
|
|
76
|
+
isEnabled: ({ path, type }) => !!type || path !== undefined,
|
|
77
|
+
label: ({ name, path }) => name ||
|
|
78
|
+
PathExt.basename(path || trans.__('Unknown Session')),
|
|
79
|
+
execute: ({ path, type }) => {
|
|
80
|
+
if (!type || path === undefined) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const command = type === 'console' ? 'console:open' : 'docmanager:open';
|
|
84
|
+
return commands.execute(command, { path });
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
commands.addCommand(CommandIDs.kernelShutDown, {
|
|
88
|
+
icon: closeIcon,
|
|
89
|
+
label: trans.__('Shut Down Kernel'),
|
|
90
|
+
execute: args => {
|
|
91
|
+
var _a;
|
|
92
|
+
const node = app.contextMenuHitTest(test);
|
|
93
|
+
const id = (_a = args.id) !== null && _a !== void 0 ? _a : node === null || node === void 0 ? void 0 : node.dataset['context'];
|
|
94
|
+
if (id) {
|
|
95
|
+
return kernels.shutdown(id);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
const sessionsItems = [];
|
|
100
|
+
// Populate connected sessions submenu when context menu is opened.
|
|
101
|
+
contextMenu.opened.connect(async () => {
|
|
102
|
+
var _a, _b, _c;
|
|
103
|
+
const submenu = (_b = (_a = contextMenu.menu.items.find(item => {
|
|
104
|
+
var _a;
|
|
105
|
+
return item.type === 'submenu' &&
|
|
106
|
+
((_a = item.submenu) === null || _a === void 0 ? void 0 : _a.id) === 'jp-contextmenu-connected-sessions';
|
|
107
|
+
})) === null || _a === void 0 ? void 0 : _a.submenu) !== null && _b !== void 0 ? _b : null;
|
|
108
|
+
if (!submenu) {
|
|
109
|
+
// Bail early if the connected session menu is not found
|
|
110
|
+
return;
|
|
33
111
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
112
|
+
// Empty the connected sessions submenu.
|
|
113
|
+
sessionsItems.forEach(item => item.dispose());
|
|
114
|
+
sessionsItems.length = 0;
|
|
115
|
+
submenu.clearItems();
|
|
116
|
+
const node = app.contextMenuHitTest(test);
|
|
117
|
+
const id = node === null || node === void 0 ? void 0 : node.dataset['context'];
|
|
118
|
+
if (!id) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
// Populate the submenu with sessions connected to this kernel.
|
|
122
|
+
const command = CommandIDs.kernelOpenSession;
|
|
123
|
+
for (const session of sessions.running()) {
|
|
124
|
+
if (id === ((_c = session.kernel) === null || _c === void 0 ? void 0 : _c.id)) {
|
|
125
|
+
const { name, path, type } = session;
|
|
126
|
+
sessionsItems.push(submenu.addItem({ command, args: { name, path, type } }));
|
|
38
127
|
}
|
|
39
|
-
|
|
40
|
-
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
var Private;
|
|
132
|
+
(function (Private) {
|
|
133
|
+
class RunningKernel {
|
|
134
|
+
constructor(options) {
|
|
135
|
+
this.className = ITEM_CLASS;
|
|
136
|
+
this.commands = options.commands;
|
|
137
|
+
this.kernel = options.kernel;
|
|
138
|
+
this.context = this.kernel.id;
|
|
139
|
+
this.kernels = options.kernels;
|
|
140
|
+
this.sessions = options.sessions;
|
|
141
|
+
this.spec = options.spec || null;
|
|
142
|
+
this.trans = options.trans;
|
|
143
|
+
}
|
|
144
|
+
get children() {
|
|
145
|
+
var _a;
|
|
146
|
+
const children = [];
|
|
147
|
+
const open = CommandIDs.kernelOpenSession;
|
|
148
|
+
const { commands } = this;
|
|
149
|
+
for (const session of this.sessions.running()) {
|
|
150
|
+
if (this.kernel.id === ((_a = session.kernel) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
151
|
+
const { name, path, type } = session;
|
|
152
|
+
children.push({
|
|
153
|
+
className: ITEM_CLASS,
|
|
154
|
+
context: this.kernel.id,
|
|
155
|
+
open: () => void commands.execute(open, { name, path, type }),
|
|
156
|
+
icon: () => type === 'console'
|
|
157
|
+
? consoleIcon
|
|
158
|
+
: type === 'notebook'
|
|
159
|
+
? notebookIcon
|
|
160
|
+
: jupyterIcon,
|
|
161
|
+
label: () => name,
|
|
162
|
+
labelTitle: () => path
|
|
163
|
+
});
|
|
164
|
+
}
|
|
41
165
|
}
|
|
166
|
+
return children;
|
|
42
167
|
}
|
|
43
168
|
shutdown() {
|
|
44
|
-
return
|
|
169
|
+
return this.kernels.shutdown(this.kernel.id);
|
|
45
170
|
}
|
|
46
171
|
icon() {
|
|
47
|
-
const {
|
|
48
|
-
if (
|
|
49
|
-
return
|
|
172
|
+
const { spec } = this;
|
|
173
|
+
if (!spec || !spec.resources) {
|
|
174
|
+
return jupyterIcon;
|
|
50
175
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return fileIcon;
|
|
176
|
+
return (spec.resources['logo-svg'] ||
|
|
177
|
+
spec.resources['logo-64x64'] ||
|
|
178
|
+
spec.resources['logo-32x32']);
|
|
55
179
|
}
|
|
56
180
|
label() {
|
|
57
|
-
|
|
181
|
+
const { kernel, spec } = this;
|
|
182
|
+
return (spec === null || spec === void 0 ? void 0 : spec.display_name) || kernel.name;
|
|
58
183
|
}
|
|
59
184
|
labelTitle() {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
185
|
+
var _a;
|
|
186
|
+
const { trans } = this;
|
|
187
|
+
const { id } = this.kernel;
|
|
188
|
+
const title = [`${this.label()}: ${id}`];
|
|
189
|
+
for (const session of this.sessions.running()) {
|
|
190
|
+
if (this.kernel.id === ((_a = session.kernel) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
191
|
+
const { path, type } = session;
|
|
192
|
+
title.push(trans.__(`%1\nPath: %2`, type, path));
|
|
193
|
+
}
|
|
65
194
|
}
|
|
66
|
-
return
|
|
195
|
+
return title.join('\n\n');
|
|
67
196
|
}
|
|
68
197
|
}
|
|
69
|
-
|
|
198
|
+
Private.RunningKernel = RunningKernel;
|
|
199
|
+
Private.runningChanged = new Signal({});
|
|
200
|
+
})(Private || (Private = {}));
|
|
70
201
|
//# sourceMappingURL=kernels.js.map
|
package/lib/kernels.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kernels.js","sourceRoot":"","sources":["../src/kernels.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAG3D,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"kernels.js","sourceRoot":"","sources":["../src/kernels.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAG3D,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAKhD,OAAO,EACL,SAAS,EACT,WAAW,EAEX,WAAW,EAEX,YAAY,EAEb,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;AAE/B,MAAM,UAAU,GAAG,eAAe,CAAC;AAEnC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,QAAiC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B,CAAC;QACJ,CAAC;QAED,KAAK;YACH,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;YAC9B,OAAO,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,YAAY,KAAI,MAAM,CAAC,IAAI,CAAC;QAC3C,CAAC;QAED,UAAU;;YACR,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;YACvB,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;YAC3B,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;YACzC,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE;gBAC7C,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE,MAAK,MAAA,OAAO,CAAC,MAAM,0CAAE,EAAE,CAAA,EAAE;oBACzC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;oBAC/B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;iBAClD;aACF;YACD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;KACF;IAtFY,qBAAa,gBAsFzB,CAAA;IAaY,sBAAc,GAAG,IAAI,MAAM,CAAmB,EAAE,CAAC,CAAC;AACjE,CAAC,EArGS,OAAO,KAAP,OAAO,QAqGhB"}
|
package/lib/opentabs.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
3
|
import { DocumentWidget } from '@jupyterlab/docregistry';
|
|
4
4
|
import { fileIcon, LabIcon } from '@jupyterlab/ui-components';
|
|
5
|
-
import { toArray } from '@lumino/algorithm';
|
|
6
5
|
import { Signal } from '@lumino/signaling';
|
|
7
6
|
/**
|
|
8
7
|
* A class used to consolidate the signals used to rerender the open tabs section.
|
|
@@ -53,15 +52,15 @@ export function addOpenTabsSessionManager(managers, translator, labShell) {
|
|
|
53
52
|
managers.add({
|
|
54
53
|
name: trans.__('Open Tabs'),
|
|
55
54
|
running: () => {
|
|
56
|
-
return
|
|
55
|
+
return Array.from(labShell.widgets('main')).map((widget) => {
|
|
57
56
|
signaler.addWidget(widget);
|
|
58
57
|
return new OpenTab(widget);
|
|
59
58
|
});
|
|
60
59
|
},
|
|
61
60
|
shutdownAll: () => {
|
|
62
|
-
|
|
61
|
+
for (const widget of labShell.widgets('main')) {
|
|
63
62
|
widget.close();
|
|
64
|
-
}
|
|
63
|
+
}
|
|
65
64
|
},
|
|
66
65
|
refreshRunning: () => {
|
|
67
66
|
return void 0;
|
package/lib/opentabs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opentabs.js","sourceRoot":"","sources":["../src/opentabs.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAG3D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,
|
|
1
|
+
{"version":3,"file":"opentabs.js","sourceRoot":"","sources":["../src/opentabs.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAG3D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAW,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;GAEG;AACH,MAAM,gBAAgB;IACpB,YAAY,QAAmB;QAiCvB,iBAAY,GAAG,IAAI,MAAM,CAAa,IAAI,CAAC,CAAC;QAE5C,aAAQ,GAAa,EAAE,CAAC;QAlC9B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC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,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;aACvC;YACD,OAAO,UAAU,CAAC;QACpB,CAAC;KAGF;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlab/running-extension",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.21",
|
|
4
4
|
"description": "JupyterLab - Running Sessions Extension",
|
|
5
5
|
"homepage": "https://github.com/jupyterlab/jupyterlab",
|
|
6
6
|
"bugs": {
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"lib/*.js",
|
|
29
29
|
"schema/*.json",
|
|
30
30
|
"style/**/*.css",
|
|
31
|
-
"style/index.js"
|
|
31
|
+
"style/index.js",
|
|
32
|
+
"src/**/*.{ts,tsx}"
|
|
32
33
|
],
|
|
33
34
|
"scripts": {
|
|
34
35
|
"build": "tsc -b",
|
|
@@ -37,21 +38,23 @@
|
|
|
37
38
|
"watch": "tsc -b --watch"
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"@jupyterlab/application": "^4.0.0-alpha.
|
|
41
|
-
"@jupyterlab/coreutils": "^6.0.0-alpha.
|
|
42
|
-
"@jupyterlab/docregistry": "^4.0.0-alpha.
|
|
43
|
-
"@jupyterlab/
|
|
44
|
-
"@jupyterlab/
|
|
45
|
-
"@jupyterlab/
|
|
46
|
-
"@jupyterlab/
|
|
47
|
-
"@
|
|
48
|
-
"@lumino/
|
|
49
|
-
"@lumino/
|
|
41
|
+
"@jupyterlab/application": "^4.0.0-alpha.21",
|
|
42
|
+
"@jupyterlab/coreutils": "^6.0.0-alpha.21",
|
|
43
|
+
"@jupyterlab/docregistry": "^4.0.0-alpha.21",
|
|
44
|
+
"@jupyterlab/rendermime-interfaces": "^3.8.0-alpha.21",
|
|
45
|
+
"@jupyterlab/running": "^4.0.0-alpha.21",
|
|
46
|
+
"@jupyterlab/services": "^7.0.0-alpha.21",
|
|
47
|
+
"@jupyterlab/translation": "^4.0.0-alpha.21",
|
|
48
|
+
"@jupyterlab/ui-components": "^4.0.0-alpha.36",
|
|
49
|
+
"@lumino/commands": "^2.0.0-rc.1",
|
|
50
|
+
"@lumino/polling": "^2.0.0-rc.1",
|
|
51
|
+
"@lumino/signaling": "^2.0.0-rc.1",
|
|
52
|
+
"@lumino/widgets": "^2.0.0-rc.1"
|
|
50
53
|
},
|
|
51
54
|
"devDependencies": {
|
|
52
55
|
"rimraf": "~3.0.0",
|
|
53
|
-
"typedoc": "~0.
|
|
54
|
-
"typescript": "~
|
|
56
|
+
"typedoc": "~0.23.25",
|
|
57
|
+
"typescript": "~5.0.1-rc"
|
|
55
58
|
},
|
|
56
59
|
"publishConfig": {
|
|
57
60
|
"access": "public"
|
package/schema/plugin.json
CHANGED
|
@@ -12,6 +12,43 @@
|
|
|
12
12
|
}
|
|
13
13
|
]
|
|
14
14
|
}
|
|
15
|
+
],
|
|
16
|
+
"context": [
|
|
17
|
+
{
|
|
18
|
+
"command": "running:kernel-new-console",
|
|
19
|
+
"selector": ".jp-RunningSessions-item.jp-mod-kernel",
|
|
20
|
+
"rank": 0
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"command": "running:kernel-new-notebook",
|
|
24
|
+
"selector": ".jp-RunningSessions-item.jp-mod-kernel",
|
|
25
|
+
"rank": 1
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"type": "separator",
|
|
29
|
+
"selector": ".jp-RunningSessions-item.jp-mod-kernel",
|
|
30
|
+
"rank": 2
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"type": "submenu",
|
|
34
|
+
"selector": ".jp-RunningSessions-item.jp-mod-kernel",
|
|
35
|
+
"rank": 3,
|
|
36
|
+
"submenu": {
|
|
37
|
+
"id": "jp-contextmenu-connected-sessions",
|
|
38
|
+
"label": "Connected Sessions…",
|
|
39
|
+
"items": []
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"type": "separator",
|
|
44
|
+
"selector": ".jp-RunningSessions-item.jp-mod-kernel",
|
|
45
|
+
"rank": 4
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"command": "running:kernel-shut-down",
|
|
49
|
+
"selector": ".jp-RunningSessions-item.jp-mod-kernel",
|
|
50
|
+
"rank": 5
|
|
51
|
+
}
|
|
15
52
|
]
|
|
16
53
|
},
|
|
17
54
|
"jupyter.lab.shortcuts": [
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
/**
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
* @module running-extension
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
ILabShell,
|
|
10
|
+
ILayoutRestorer,
|
|
11
|
+
JupyterFrontEnd,
|
|
12
|
+
JupyterFrontEndPlugin
|
|
13
|
+
} from '@jupyterlab/application';
|
|
14
|
+
import {
|
|
15
|
+
IRunningSessionManagers,
|
|
16
|
+
RunningSessionManagers,
|
|
17
|
+
RunningSessions
|
|
18
|
+
} from '@jupyterlab/running';
|
|
19
|
+
import { ITranslator } from '@jupyterlab/translation';
|
|
20
|
+
import { runningIcon } from '@jupyterlab/ui-components';
|
|
21
|
+
import { addKernelRunningSessionManager } from './kernels';
|
|
22
|
+
import { addOpenTabsSessionManager } from './opentabs';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The command IDs used by the running plugin.
|
|
26
|
+
*/
|
|
27
|
+
export namespace CommandIDs {
|
|
28
|
+
export const kernelNewConsole = 'running:kernel-new-console';
|
|
29
|
+
export const kernelNewNotebook = 'running:kernel-new-notebook';
|
|
30
|
+
export const kernelOpenSession = 'running:kernel-open-session';
|
|
31
|
+
export const kernelShutDown = 'running:kernel-shut-down';
|
|
32
|
+
export const showPanel = 'running:show-panel';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The default running sessions extension.
|
|
37
|
+
*/
|
|
38
|
+
const plugin: JupyterFrontEndPlugin<IRunningSessionManagers> = {
|
|
39
|
+
activate,
|
|
40
|
+
id: '@jupyterlab/running-extension:plugin',
|
|
41
|
+
provides: IRunningSessionManagers,
|
|
42
|
+
requires: [ITranslator],
|
|
43
|
+
optional: [ILayoutRestorer, ILabShell],
|
|
44
|
+
autoStart: true
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Export the plugin as default.
|
|
49
|
+
*/
|
|
50
|
+
export default plugin;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Activate the running plugin.
|
|
54
|
+
*/
|
|
55
|
+
function activate(
|
|
56
|
+
app: JupyterFrontEnd,
|
|
57
|
+
translator: ITranslator,
|
|
58
|
+
restorer: ILayoutRestorer | null,
|
|
59
|
+
labShell: ILabShell | null
|
|
60
|
+
): IRunningSessionManagers {
|
|
61
|
+
const trans = translator.load('jupyterlab');
|
|
62
|
+
const runningSessionManagers = new RunningSessionManagers();
|
|
63
|
+
const running = new RunningSessions(runningSessionManagers, translator);
|
|
64
|
+
running.id = 'jp-running-sessions';
|
|
65
|
+
running.title.caption = trans.__('Running Terminals and Kernels');
|
|
66
|
+
running.title.icon = runningIcon;
|
|
67
|
+
running.node.setAttribute('role', 'region');
|
|
68
|
+
running.node.setAttribute('aria-label', trans.__('Running Sessions section'));
|
|
69
|
+
|
|
70
|
+
// Let the application restorer track the running panel for restoration of
|
|
71
|
+
// application state (e.g. setting the running panel as the current side bar
|
|
72
|
+
// widget).
|
|
73
|
+
if (restorer) {
|
|
74
|
+
restorer.add(running, 'running-sessions');
|
|
75
|
+
}
|
|
76
|
+
if (labShell) {
|
|
77
|
+
addOpenTabsSessionManager(runningSessionManagers, translator, labShell);
|
|
78
|
+
}
|
|
79
|
+
void addKernelRunningSessionManager(runningSessionManagers, translator, app);
|
|
80
|
+
// Rank has been chosen somewhat arbitrarily to give priority to the running
|
|
81
|
+
// sessions widget in the sidebar.
|
|
82
|
+
app.shell.add(running, 'left', { rank: 200, type: 'Sessions and Tabs' });
|
|
83
|
+
|
|
84
|
+
app.commands.addCommand(CommandIDs.showPanel, {
|
|
85
|
+
label: trans.__('Sessions and Tabs'),
|
|
86
|
+
execute: () => {
|
|
87
|
+
app.shell.activateById(running.id);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return runningSessionManagers;
|
|
92
|
+
}
|
package/src/kernels.ts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { JupyterFrontEnd } from '@jupyterlab/application';
|
|
5
|
+
import { PathExt } from '@jupyterlab/coreutils';
|
|
6
|
+
import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
|
|
7
|
+
import { IRunningSessionManagers, IRunningSessions } from '@jupyterlab/running';
|
|
8
|
+
import { Kernel, KernelSpec, Session } from '@jupyterlab/services';
|
|
9
|
+
import { ITranslator } from '@jupyterlab/translation';
|
|
10
|
+
import {
|
|
11
|
+
closeIcon,
|
|
12
|
+
consoleIcon,
|
|
13
|
+
IDisposableMenuItem,
|
|
14
|
+
jupyterIcon,
|
|
15
|
+
LabIcon,
|
|
16
|
+
notebookIcon,
|
|
17
|
+
RankedMenu
|
|
18
|
+
} from '@jupyterlab/ui-components';
|
|
19
|
+
import { CommandRegistry } from '@lumino/commands';
|
|
20
|
+
import { Throttler } from '@lumino/polling';
|
|
21
|
+
import { Signal } from '@lumino/signaling';
|
|
22
|
+
import { CommandIDs } from '.';
|
|
23
|
+
|
|
24
|
+
const ITEM_CLASS = 'jp-mod-kernel';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Add the running kernel manager (notebooks & consoles) to the running panel.
|
|
28
|
+
*/
|
|
29
|
+
export async function addKernelRunningSessionManager(
|
|
30
|
+
managers: IRunningSessionManagers,
|
|
31
|
+
translator: ITranslator,
|
|
32
|
+
app: JupyterFrontEnd
|
|
33
|
+
): Promise<void> {
|
|
34
|
+
const { commands, contextMenu, serviceManager } = app;
|
|
35
|
+
const { kernels, kernelspecs, sessions } = serviceManager;
|
|
36
|
+
const { runningChanged, RunningKernel } = Private;
|
|
37
|
+
const throttler = new Throttler(() => runningChanged.emit(undefined), 100);
|
|
38
|
+
const trans = translator.load('jupyterlab');
|
|
39
|
+
|
|
40
|
+
// Throttle signal emissions from the kernel and session managers.
|
|
41
|
+
kernels.runningChanged.connect(() => void throttler.invoke());
|
|
42
|
+
sessions.runningChanged.connect(() => void throttler.invoke());
|
|
43
|
+
|
|
44
|
+
// Wait until the relevant services are ready.
|
|
45
|
+
await Promise.all([kernels.ready, kernelspecs.ready, sessions.ready]);
|
|
46
|
+
|
|
47
|
+
// Add the kernels pane to the running sidebar.
|
|
48
|
+
managers.add({
|
|
49
|
+
name: trans.__('Kernels'),
|
|
50
|
+
running: () =>
|
|
51
|
+
Array.from(kernels.running()).map(
|
|
52
|
+
kernel =>
|
|
53
|
+
new RunningKernel({
|
|
54
|
+
commands,
|
|
55
|
+
kernel,
|
|
56
|
+
kernels,
|
|
57
|
+
sessions,
|
|
58
|
+
spec: kernelspecs.specs?.kernelspecs[kernel.name],
|
|
59
|
+
trans
|
|
60
|
+
})
|
|
61
|
+
),
|
|
62
|
+
shutdownAll: () => kernels.shutdownAll(),
|
|
63
|
+
refreshRunning: () =>
|
|
64
|
+
Promise.all([kernels.refreshRunning(), sessions.refreshRunning()]),
|
|
65
|
+
runningChanged,
|
|
66
|
+
shutdownLabel: trans.__('Shut Down Kernel'),
|
|
67
|
+
shutdownAllLabel: trans.__('Shut Down All'),
|
|
68
|
+
shutdownAllConfirmationText: trans.__(
|
|
69
|
+
'Are you sure you want to permanently shut down all running kernels?'
|
|
70
|
+
)
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Add running kernels commands to the registry.
|
|
74
|
+
const test = (node: HTMLElement) => node.classList.contains(ITEM_CLASS);
|
|
75
|
+
commands.addCommand(CommandIDs.kernelNewConsole, {
|
|
76
|
+
icon: consoleIcon,
|
|
77
|
+
label: trans.__('New Console for Kernel'),
|
|
78
|
+
execute: args => {
|
|
79
|
+
const node = app.contextMenuHitTest(test);
|
|
80
|
+
const id = (args.id as string) ?? node?.dataset['context'];
|
|
81
|
+
if (id) {
|
|
82
|
+
return commands.execute('console:create', { kernelPreference: { id } });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
commands.addCommand(CommandIDs.kernelNewNotebook, {
|
|
87
|
+
icon: notebookIcon,
|
|
88
|
+
label: trans.__('New Notebook for Kernel'),
|
|
89
|
+
execute: args => {
|
|
90
|
+
const node = app.contextMenuHitTest(test);
|
|
91
|
+
const id = (args.id as string) ?? node?.dataset['context'];
|
|
92
|
+
if (id) {
|
|
93
|
+
return commands.execute('notebook:create-new', { kernelId: id });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
commands.addCommand(CommandIDs.kernelOpenSession, {
|
|
98
|
+
icon: args =>
|
|
99
|
+
args.type === 'console'
|
|
100
|
+
? consoleIcon
|
|
101
|
+
: args.type === 'notebook'
|
|
102
|
+
? notebookIcon
|
|
103
|
+
: undefined,
|
|
104
|
+
isEnabled: ({ path, type }) => !!type || path !== undefined,
|
|
105
|
+
label: ({ name, path }) =>
|
|
106
|
+
(name as string) ||
|
|
107
|
+
PathExt.basename((path as string) || trans.__('Unknown Session')),
|
|
108
|
+
execute: ({ path, type }) => {
|
|
109
|
+
if (!type || path === undefined) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const command = type === 'console' ? 'console:open' : 'docmanager:open';
|
|
113
|
+
return commands.execute(command, { path });
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
commands.addCommand(CommandIDs.kernelShutDown, {
|
|
117
|
+
icon: closeIcon,
|
|
118
|
+
label: trans.__('Shut Down Kernel'),
|
|
119
|
+
execute: args => {
|
|
120
|
+
const node = app.contextMenuHitTest(test);
|
|
121
|
+
const id = (args.id as string) ?? node?.dataset['context'];
|
|
122
|
+
if (id) {
|
|
123
|
+
return kernels.shutdown(id);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const sessionsItems: IDisposableMenuItem[] = [];
|
|
129
|
+
|
|
130
|
+
// Populate connected sessions submenu when context menu is opened.
|
|
131
|
+
contextMenu.opened.connect(async () => {
|
|
132
|
+
const submenu =
|
|
133
|
+
(contextMenu.menu.items.find(
|
|
134
|
+
item =>
|
|
135
|
+
item.type === 'submenu' &&
|
|
136
|
+
item.submenu?.id === 'jp-contextmenu-connected-sessions'
|
|
137
|
+
)?.submenu as RankedMenu) ?? null;
|
|
138
|
+
|
|
139
|
+
if (!submenu) {
|
|
140
|
+
// Bail early if the connected session menu is not found
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Empty the connected sessions submenu.
|
|
145
|
+
sessionsItems.forEach(item => item.dispose());
|
|
146
|
+
sessionsItems.length = 0;
|
|
147
|
+
submenu.clearItems();
|
|
148
|
+
|
|
149
|
+
const node = app.contextMenuHitTest(test);
|
|
150
|
+
const id = node?.dataset['context'];
|
|
151
|
+
if (!id) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Populate the submenu with sessions connected to this kernel.
|
|
156
|
+
const command = CommandIDs.kernelOpenSession;
|
|
157
|
+
for (const session of sessions.running()) {
|
|
158
|
+
if (id === session.kernel?.id) {
|
|
159
|
+
const { name, path, type } = session;
|
|
160
|
+
sessionsItems.push(
|
|
161
|
+
submenu.addItem({ command, args: { name, path, type } })
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
namespace Private {
|
|
169
|
+
export class RunningKernel implements IRunningSessions.IRunningItem {
|
|
170
|
+
constructor(options: RunningKernel.IOptions) {
|
|
171
|
+
this.className = ITEM_CLASS;
|
|
172
|
+
this.commands = options.commands;
|
|
173
|
+
this.kernel = options.kernel;
|
|
174
|
+
this.context = this.kernel.id;
|
|
175
|
+
this.kernels = options.kernels;
|
|
176
|
+
this.sessions = options.sessions;
|
|
177
|
+
this.spec = options.spec || null;
|
|
178
|
+
this.trans = options.trans;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
readonly className: string;
|
|
182
|
+
|
|
183
|
+
readonly context: string;
|
|
184
|
+
|
|
185
|
+
readonly commands: CommandRegistry;
|
|
186
|
+
|
|
187
|
+
readonly kernel: Kernel.IModel;
|
|
188
|
+
|
|
189
|
+
readonly kernels: Kernel.IManager;
|
|
190
|
+
|
|
191
|
+
readonly sessions: Session.IManager;
|
|
192
|
+
|
|
193
|
+
readonly spec: KernelSpec.ISpecModel | null;
|
|
194
|
+
|
|
195
|
+
readonly trans: IRenderMime.TranslationBundle;
|
|
196
|
+
|
|
197
|
+
get children(): IRunningSessions.IRunningItem[] {
|
|
198
|
+
const children: IRunningSessions.IRunningItem[] = [];
|
|
199
|
+
const open = CommandIDs.kernelOpenSession;
|
|
200
|
+
const { commands } = this;
|
|
201
|
+
for (const session of this.sessions.running()) {
|
|
202
|
+
if (this.kernel.id === session.kernel?.id) {
|
|
203
|
+
const { name, path, type } = session;
|
|
204
|
+
children.push({
|
|
205
|
+
className: ITEM_CLASS,
|
|
206
|
+
context: this.kernel.id,
|
|
207
|
+
open: () => void commands.execute(open, { name, path, type }),
|
|
208
|
+
icon: () =>
|
|
209
|
+
type === 'console'
|
|
210
|
+
? consoleIcon
|
|
211
|
+
: type === 'notebook'
|
|
212
|
+
? notebookIcon
|
|
213
|
+
: jupyterIcon,
|
|
214
|
+
label: () => name,
|
|
215
|
+
labelTitle: () => path
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return children;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
shutdown(): Promise<void> {
|
|
223
|
+
return this.kernels.shutdown(this.kernel.id);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
icon(): LabIcon | string {
|
|
227
|
+
const { spec } = this;
|
|
228
|
+
if (!spec || !spec.resources) {
|
|
229
|
+
return jupyterIcon;
|
|
230
|
+
}
|
|
231
|
+
return (
|
|
232
|
+
spec.resources['logo-svg'] ||
|
|
233
|
+
spec.resources['logo-64x64'] ||
|
|
234
|
+
spec.resources['logo-32x32']
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
label(): string {
|
|
239
|
+
const { kernel, spec } = this;
|
|
240
|
+
return spec?.display_name || kernel.name;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
labelTitle(): string {
|
|
244
|
+
const { trans } = this;
|
|
245
|
+
const { id } = this.kernel;
|
|
246
|
+
const title = [`${this.label()}: ${id}`];
|
|
247
|
+
for (const session of this.sessions.running()) {
|
|
248
|
+
if (this.kernel.id === session.kernel?.id) {
|
|
249
|
+
const { path, type } = session;
|
|
250
|
+
title.push(trans.__(`%1\nPath: %2`, type, path));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return title.join('\n\n');
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export namespace RunningKernel {
|
|
258
|
+
export interface IOptions {
|
|
259
|
+
commands: CommandRegistry;
|
|
260
|
+
kernel: Kernel.IModel;
|
|
261
|
+
kernels: Kernel.IManager;
|
|
262
|
+
sessions: Session.IManager;
|
|
263
|
+
spec?: KernelSpec.ISpecModel;
|
|
264
|
+
trans: IRenderMime.TranslationBundle;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export const runningChanged = new Signal<unknown, unknown>({});
|
|
269
|
+
}
|
package/src/opentabs.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { ILabShell } from '@jupyterlab/application';
|
|
5
|
+
import { DocumentWidget } from '@jupyterlab/docregistry';
|
|
6
|
+
import { IRunningSessionManagers, IRunningSessions } from '@jupyterlab/running';
|
|
7
|
+
import { ITranslator } from '@jupyterlab/translation';
|
|
8
|
+
import { fileIcon, LabIcon } from '@jupyterlab/ui-components';
|
|
9
|
+
import { ISignal, Signal } from '@lumino/signaling';
|
|
10
|
+
import { Widget } from '@lumino/widgets';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A class used to consolidate the signals used to rerender the open tabs section.
|
|
14
|
+
*/
|
|
15
|
+
class OpenTabsSignaler {
|
|
16
|
+
constructor(labShell: ILabShell) {
|
|
17
|
+
this._labShell = labShell;
|
|
18
|
+
this._labShell.layoutModified.connect(this._emitTabsChanged, this);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A signal that fires when the open tabs section should be rerendered.
|
|
23
|
+
*/
|
|
24
|
+
get tabsChanged(): ISignal<this, void> {
|
|
25
|
+
return this._tabsChanged;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Add a widget to watch for title changing.
|
|
30
|
+
*
|
|
31
|
+
* @param widget A widget whose title may change.
|
|
32
|
+
*/
|
|
33
|
+
addWidget(widget: Widget): void {
|
|
34
|
+
widget.title.changed.connect(this._emitTabsChanged, this);
|
|
35
|
+
this._widgets.push(widget);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Emit the main signal that indicates the open tabs should be rerendered.
|
|
40
|
+
*/
|
|
41
|
+
private _emitTabsChanged(): void {
|
|
42
|
+
this._widgets.forEach(widget => {
|
|
43
|
+
widget.title.changed.disconnect(this._emitTabsChanged, this);
|
|
44
|
+
});
|
|
45
|
+
this._widgets = [];
|
|
46
|
+
this._tabsChanged.emit(void 0);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private _tabsChanged = new Signal<this, void>(this);
|
|
50
|
+
private _labShell: ILabShell;
|
|
51
|
+
private _widgets: Widget[] = [];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Add the open tabs section to the running panel.
|
|
56
|
+
*
|
|
57
|
+
* @param managers - The IRunningSessionManagers used to register this section.
|
|
58
|
+
* @param translator - The translator to use.
|
|
59
|
+
* @param labShell - The ILabShell.
|
|
60
|
+
*/
|
|
61
|
+
export function addOpenTabsSessionManager(
|
|
62
|
+
managers: IRunningSessionManagers,
|
|
63
|
+
translator: ITranslator,
|
|
64
|
+
labShell: ILabShell
|
|
65
|
+
): void {
|
|
66
|
+
const signaler = new OpenTabsSignaler(labShell);
|
|
67
|
+
const trans = translator.load('jupyterlab');
|
|
68
|
+
|
|
69
|
+
managers.add({
|
|
70
|
+
name: trans.__('Open Tabs'),
|
|
71
|
+
running: () => {
|
|
72
|
+
return Array.from(labShell.widgets('main')).map((widget: Widget) => {
|
|
73
|
+
signaler.addWidget(widget);
|
|
74
|
+
return new OpenTab(widget);
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
shutdownAll: () => {
|
|
78
|
+
for (const widget of labShell.widgets('main')) {
|
|
79
|
+
widget.close();
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
refreshRunning: () => {
|
|
83
|
+
return void 0;
|
|
84
|
+
},
|
|
85
|
+
runningChanged: signaler.tabsChanged,
|
|
86
|
+
shutdownLabel: trans.__('Close'),
|
|
87
|
+
shutdownAllLabel: trans.__('Close All'),
|
|
88
|
+
shutdownAllConfirmationText: trans.__(
|
|
89
|
+
'Are you sure you want to close all open tabs?'
|
|
90
|
+
)
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
class OpenTab implements IRunningSessions.IRunningItem {
|
|
94
|
+
constructor(widget: Widget) {
|
|
95
|
+
this._widget = widget;
|
|
96
|
+
}
|
|
97
|
+
open() {
|
|
98
|
+
labShell.activateById(this._widget.id);
|
|
99
|
+
}
|
|
100
|
+
shutdown() {
|
|
101
|
+
this._widget.close();
|
|
102
|
+
}
|
|
103
|
+
icon() {
|
|
104
|
+
const widgetIcon = this._widget.title.icon;
|
|
105
|
+
return widgetIcon instanceof LabIcon ? widgetIcon : fileIcon;
|
|
106
|
+
}
|
|
107
|
+
label() {
|
|
108
|
+
return this._widget.title.label;
|
|
109
|
+
}
|
|
110
|
+
labelTitle() {
|
|
111
|
+
let labelTitle: string;
|
|
112
|
+
if (this._widget instanceof DocumentWidget) {
|
|
113
|
+
labelTitle = this._widget.context.path;
|
|
114
|
+
} else {
|
|
115
|
+
labelTitle = this._widget.title.label;
|
|
116
|
+
}
|
|
117
|
+
return labelTitle;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private _widget: Widget;
|
|
121
|
+
}
|
|
122
|
+
}
|