forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.ts
120 lines (102 loc) · 2.68 KB
/
file.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
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
Menu, Widget
} from '@phosphor/widgets';
import {
IJupyterLabMenu, IMenuExtender, JupyterLabMenu
} from './labmenu';
/**
* An interface for a File menu.
*/
export
interface IFileMenu extends IJupyterLabMenu {
/**
* A submenu for creating new files/launching new activities.
*/
readonly newMenu: IJupyterLabMenu;
/**
* The close and cleanup extension point.
*/
readonly closeAndCleaners: Set<IFileMenu.ICloseAndCleaner<Widget>>;
/**
* A set storing IConsoleCreators for the File menu.
*/
readonly consoleCreators: Set<IFileMenu.IConsoleCreator<Widget>>;
}
/**
* An extensible FileMenu for the application.
*/
export
class FileMenu extends JupyterLabMenu implements IFileMenu {
constructor(options: Menu.IOptions) {
super(options);
this.menu.title.label = 'File';
// Create the "New" submenu.
this.newMenu = new JupyterLabMenu(options, false);
this.newMenu.menu.title.label = 'New';
this.closeAndCleaners =
new Set<IFileMenu.ICloseAndCleaner<Widget>>();
this.consoleCreators =
new Set<IFileMenu.IConsoleCreator<Widget>>();
}
/**
* The New submenu.
*/
readonly newMenu: JupyterLabMenu;
/**
* The close and cleanup extension point.
*/
readonly closeAndCleaners: Set<IFileMenu.ICloseAndCleaner<Widget>>;
/**
* A set storing IConsoleCreators for the Kernel menu.
*/
readonly consoleCreators: Set<IFileMenu.IConsoleCreator<Widget>>;
/**
* Dispose of the resources held by the file menu.
*/
dispose(): void {
this.newMenu.dispose();
this.consoleCreators.clear();
super.dispose();
}
}
/**
* Namespace for IFileMenu
*/
export
namespace IFileMenu {
/**
* Interface for an activity that has some cleanup action associated
* with it in addition to merely closing its widget in the main area.
*/
export
interface ICloseAndCleaner<T extends Widget> extends IMenuExtender<T> {
/**
* A label to use for the activity that is being cleaned up.
*/
name: string;
/**
* A label to use for the cleanup action.
*/
action: string;
/**
* A function to perform the close and cleanup action.
*/
closeAndCleanup: (widget: T) => Promise<void>;
}
/**
* Interface for a command to create a console for an activity.
*/
export
interface IConsoleCreator<T extends Widget> extends IMenuExtender<T> {
/**
* A label to use for the activity for which a console is being created.
*/
name: string;
/**
* The function to create the console.
*/
createConsole: (widget: T) => Promise<void>;
}
}