-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
run.ts
89 lines (78 loc) · 2.22 KB
/
run.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
// 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 Run menu.
*/
export interface IRunMenu extends IJupyterLabMenu {
/**
* A set storing ICodeRunner for the Run menu.
*
* ### Notes
* The key for the set may be used in menu labels.
*/
readonly codeRunners: Set<IRunMenu.ICodeRunner<Widget>>;
}
/**
* An extensible Run menu for the application.
*/
export class RunMenu extends JupyterLabMenu implements IRunMenu {
/**
* Construct the run menu.
*/
constructor(options: Menu.IOptions) {
super(options);
this.menu.title.label = 'Run';
this.codeRunners = new Set<IRunMenu.ICodeRunner<Widget>>();
}
/**
* A set storing ICodeRunner for the Run menu.
*
* ### Notes
* The key for the set may be used in menu labels.
*/
readonly codeRunners: Set<IRunMenu.ICodeRunner<Widget>>;
/**
* Dispose of the resources held by the run menu.
*/
dispose(): void {
this.codeRunners.clear();
super.dispose();
}
}
/**
* A namespace for RunMenu statics.
*/
export namespace IRunMenu {
/**
* An object that runs code, which may be
* registered with the Run menu.
*/
export interface ICodeRunner<T extends Widget> extends IMenuExtender<T> {
/**
* A string label for the thing that is being run,
* which is used to populate the menu labels.
*/
noun: string;
/**
* A function to run a chunk of code.
*/
run?: (widget: T) => Promise<void>;
/**
* A function to run the entirety of the code hosted by the widget.
*/
runAll?: (widget: T) => Promise<void>;
/**
* A function to restart and run all the code hosted by the widget, which
* returns a promise of whether the action was performed.
*/
restartAndRunAll?: (widget: T) => Promise<boolean>;
/**
* A function to restart and run all the code hosted by the widget
* up to the currently selected cell, which returns a promise of whether
* the action was performed.
*/
restartAndRunToSelected?: (widget: T) => Promise<boolean>;
}
}