forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
113 lines (88 loc) · 2.39 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
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
JupyterLab, JupyterLabPlugin
} from '@jupyterlab/application';
import {
ICommandPalette
} from '@jupyterlab/apputils';
import {
ILauncher, LauncherModel, Launcher
} from '@jupyterlab/launcher';
import {
toArray
} from '@phosphor/algorithm';
import {
JSONObject
} from '@phosphor/coreutils';
import {
Widget
} from '@phosphor/widgets';
import '../style/index.css';
/**
* The command IDs used by the launcher plugin.
*/
namespace CommandIDs {
export
const create = 'launcher:create';
}
/**
* A service providing an interface to the the launcher.
*/
const plugin: JupyterLabPlugin<ILauncher> = {
activate,
id: '@jupyterlab/launcher-extension:plugin',
requires: [ICommandPalette],
provides: ILauncher,
autoStart: true
};
/**
* Export the plugin as default.
*/
export default plugin;
/**
* Activate the launcher.
*/
function activate(app: JupyterLab, palette: ICommandPalette): ILauncher {
const { commands, shell } = app;
const model = new LauncherModel();
commands.addCommand(CommandIDs.create, {
label: 'New Launcher',
execute: (args: JSONObject) => {
const cwd = args['cwd'] ? String(args['cwd']) : '';
const id = `launcher-${Private.id++}`;
const callback = (item: Widget) => {
shell.addToMainArea(item, { ref: id });
shell.activateById(item.id);
};
const launcher = new Launcher({ cwd, callback });
launcher.model = model;
launcher.id = id;
launcher.title.label = 'Launcher';
launcher.title.iconClass = 'jp-LauncherIcon';
// If there are any other widgets open, remove the launcher close icon.
launcher.title.closable = !!toArray(shell.widgets('main')).length;
shell.addToMainArea(launcher);
if (args['activate'] !== false) {
shell.activateById(launcher.id);
}
shell.layoutModified.connect(() => {
// If there is only a launcher open, remove the close icon.
launcher.title.closable = toArray(shell.widgets('main')).length > 1;
}, launcher);
return launcher;
}
});
palette.addItem({ command: CommandIDs.create, category: 'Launcher'});
return model;
}
/**
* The namespace for module private data.
*/
namespace Private {
/**
* The incrementing id used for launcher widgets.
*/
export
let id = 0;
}