@jupyterlab/workspaces-extension 4.2.0-alpha.2

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/src/sidebar.ts ADDED
@@ -0,0 +1,106 @@
1
+ /* -----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+ import {
6
+ JupyterFrontEnd,
7
+ JupyterFrontEndPlugin
8
+ } from '@jupyterlab/application';
9
+ import { IWindowResolver } from '@jupyterlab/apputils';
10
+ import { IWorkspaceCommands, IWorkspacesModel } from '@jupyterlab/workspaces';
11
+ import { IRunningSessionManagers, IRunningSessions } from '@jupyterlab/running';
12
+ import { ITranslator, nullTranslator } from '@jupyterlab/translation';
13
+ import { Workspace } from '@jupyterlab/services';
14
+ import { WORKSPACE_ITEM_CLASS } from './commands';
15
+ import { blankIcon, checkIcon, deleteIcon } from '@jupyterlab/ui-components';
16
+
17
+ /**
18
+ * The extension populating sidebar with workspaces list.
19
+ */
20
+ export const workspacesSidebar: JupyterFrontEndPlugin<void> = {
21
+ id: '@jupyterlab/workspaces-extension:sidebar',
22
+ description: 'Populates running sidebar with workspaces.',
23
+ requires: [
24
+ IWorkspaceCommands,
25
+ IWorkspacesModel,
26
+ IRunningSessionManagers,
27
+ IWindowResolver
28
+ ],
29
+ optional: [ITranslator],
30
+ autoStart: true,
31
+ activate: async (
32
+ app: JupyterFrontEnd,
33
+ commands: IWorkspaceCommands,
34
+ model: IWorkspacesModel,
35
+ managers: IRunningSessionManagers,
36
+ resolver: IWindowResolver,
37
+ translator: ITranslator | null
38
+ ) => {
39
+ const trans = (translator ?? nullTranslator).load('jupyterlab');
40
+
41
+ class WorkspaceItem implements IRunningSessions.IRunningItem {
42
+ constructor(workspace: Workspace.IWorkspace) {
43
+ this._workspace = workspace;
44
+ this.context = workspace.metadata.id;
45
+ this.className = WORKSPACE_ITEM_CLASS;
46
+ }
47
+ readonly className: string;
48
+ readonly context: string;
49
+ open() {
50
+ return app.commands.execute(commands.open, {
51
+ workspace: this._workspace.metadata.id
52
+ });
53
+ }
54
+ async shutdown() {
55
+ await app.commands.execute(commands.deleteWorkspace, {
56
+ workspace: this._workspace.metadata.id
57
+ });
58
+ await model.refresh();
59
+ }
60
+ icon() {
61
+ return resolver.name === this._workspace.metadata.id
62
+ ? checkIcon
63
+ : blankIcon;
64
+ }
65
+ label() {
66
+ return this._workspace.metadata.id;
67
+ }
68
+ labelTitle() {
69
+ return trans.__(
70
+ '%1 workspace with %2 tabs, last modified on %3',
71
+ this._workspace.metadata.id,
72
+ (this._workspace.data['layout-restorer:data'] as any)?.main?.dock
73
+ ?.widgets?.length,
74
+ this._workspace.metadata['last_modified']
75
+ );
76
+ }
77
+
78
+ private _workspace: Workspace.IWorkspace;
79
+ }
80
+ managers.add({
81
+ name: trans.__('Workspaces'),
82
+ running: () => {
83
+ return model.workspaces.map((workspace: Workspace.IWorkspace) => {
84
+ return new WorkspaceItem(workspace);
85
+ });
86
+ },
87
+ shutdownAll: async () => {
88
+ await Promise.all(
89
+ model.workspaces.map(workspace => model.remove(workspace.metadata.id))
90
+ );
91
+ await model.refresh();
92
+ },
93
+ shutdownItemIcon: deleteIcon,
94
+ refreshRunning: async () => {
95
+ await model.refresh();
96
+ },
97
+ runningChanged: model.refreshed,
98
+ shutdownLabel: (item: IRunningSessions.IRunningItem) =>
99
+ trans.__('Delete %1', item.label() as string),
100
+ shutdownAllLabel: trans.__('Delete All'),
101
+ shutdownAllConfirmationText: trans.__(
102
+ 'Are you sure you want to delete all workspaces? Deleted workspaces cannot be recovered.'
103
+ )
104
+ });
105
+ }
106
+ };
@@ -0,0 +1,11 @@
1
+ /*-----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+
6
+ /* This file was auto-generated by ensurePackage() in @jupyterlab/buildutils */
7
+ @import url('~@jupyterlab/ui-components/style/index.css');
8
+ @import url('~@jupyterlab/apputils/style/index.css');
9
+ @import url('~@jupyterlab/application/style/index.css');
10
+ @import url('~@jupyterlab/filebrowser/style/index.css');
11
+ @import url('~@jupyterlab/running/style/index.css');
package/style/index.js ADDED
@@ -0,0 +1,11 @@
1
+ /*-----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+
6
+ /* This file was auto-generated by ensurePackage() in @jupyterlab/buildutils */
7
+ import '@jupyterlab/ui-components/style/index.js';
8
+ import '@jupyterlab/apputils/style/index.js';
9
+ import '@jupyterlab/application/style/index.js';
10
+ import '@jupyterlab/filebrowser/style/index.js';
11
+ import '@jupyterlab/running/style/index.js';