|
@@ -5,6 +5,10 @@ import {
|
|
|
ContentsManager, Kernel, Session, utils
|
|
|
} from '@jupyterlab/services';
|
|
|
|
|
|
+import {
|
|
|
+ find
|
|
|
+} from 'phosphor/lib/algorithm/searching';
|
|
|
+
|
|
|
import {
|
|
|
JSONObject
|
|
|
} from 'phosphor/lib/algorithm/json';
|
|
@@ -89,6 +93,11 @@ const LANDSCAPE_ICON_CLASS = 'jp-MainAreaLandscapeIcon';
|
|
|
*/
|
|
|
const CONSOLE_ICON_CLASS = 'jp-ImageCodeConsole';
|
|
|
|
|
|
+/**
|
|
|
+ * A regex for console names.
|
|
|
+ */
|
|
|
+const CONSOLE_REGEX = /^console-(\d)+-[0-9a-f]+$/;
|
|
|
+
|
|
|
/**
|
|
|
* The console panel instance tracker.
|
|
|
*/
|
|
@@ -99,7 +108,7 @@ const tracker = new InstanceTracker<ConsolePanel>();
|
|
|
* The interface for a start console.
|
|
|
*/
|
|
|
interface ICreateConsoleArgs extends JSONObject {
|
|
|
- sessionId?: string;
|
|
|
+ id?: string;
|
|
|
path?: string;
|
|
|
kernel?: Kernel.IModel;
|
|
|
preferredLanguage?: string;
|
|
@@ -221,9 +230,12 @@ function activateConsole(app: JupyterLab, services: IServiceManager, rendermime:
|
|
|
let name = `Console ${++count}`;
|
|
|
|
|
|
// If we get a session, use it.
|
|
|
- if (args.sessionId) {
|
|
|
- return manager.connectTo(args.sessionId).then(session => {
|
|
|
+ if (args.id) {
|
|
|
+ return manager.connectTo(args.id).then(session => {
|
|
|
+ name = session.path.split('/').pop();
|
|
|
+ name = `Console ${name.match(CONSOLE_REGEX)[1]}`;
|
|
|
createConsole(session, name);
|
|
|
+ manager.listRunning(); // Trigger a refresh.
|
|
|
return session.id;
|
|
|
});
|
|
|
}
|
|
@@ -234,7 +246,7 @@ function activateConsole(app: JupyterLab, services: IServiceManager, rendermime:
|
|
|
if (ContentsManager.extname(path)) {
|
|
|
path = ContentsManager.dirname(path);
|
|
|
}
|
|
|
- path = `${path}/console-${utils.uuid()}`;
|
|
|
+ path = `${path}/console-${count}-${utils.uuid()}`;
|
|
|
|
|
|
// Get the kernel model.
|
|
|
return getKernel(args, name).then(kernel => {
|
|
@@ -249,6 +261,7 @@ function activateConsole(app: JupyterLab, services: IServiceManager, rendermime:
|
|
|
};
|
|
|
return manager.startNew(options).then(session => {
|
|
|
createConsole(session, name);
|
|
|
+ manager.listRunning(); // Trigger a refresh.
|
|
|
return session.id;
|
|
|
});
|
|
|
});
|
|
@@ -259,11 +272,29 @@ function activateConsole(app: JupyterLab, services: IServiceManager, rendermime:
|
|
|
commands.addCommand(command, {
|
|
|
execute: (args: JSONObject) => {
|
|
|
let id = args['id'];
|
|
|
- tracker.forEach(widget => {
|
|
|
+ tracker.find(widget => {
|
|
|
if (widget.content.session.id === id) {
|
|
|
widget.content.inject(args['code'] as string);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ command = 'console:open';
|
|
|
+ commands.addCommand(command, {
|
|
|
+ execute: (args: JSONObject) => {
|
|
|
+ let id = args['id'];
|
|
|
+ let widget = tracker.find(value => {
|
|
|
+ if (value.content.session.id === id) {
|
|
|
+ return true;
|
|
|
}
|
|
|
});
|
|
|
+ if (widget) {
|
|
|
+ app.shell.activateMain(widget.id);
|
|
|
+ } else {
|
|
|
+ app.commands.execute('console:create', { id });
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
|