forked from jupyterlab/jupyterlab
/
edit.ts
124 lines (104 loc) · 2.84 KB
/
edit.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
121
122
123
124
// 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 an Edit menu.
*/
export interface IEditMenu extends IJupyterLabMenu {
/**
* A set storing IUndoers for the Edit menu.
*/
readonly undoers: Set<IEditMenu.IUndoer<Widget>>;
/**
* A set storing IClearers for the Edit menu.
*/
readonly clearers: Set<IEditMenu.IClearer<Widget>>;
/**
* A set storing IGoToLiners for the Edit menu.
*/
readonly goToLiners: Set<IEditMenu.IGoToLiner<Widget>>;
}
/**
* An extensible Edit menu for the application.
*/
export class EditMenu extends JupyterLabMenu implements IEditMenu {
/**
* Construct the edit menu.
*/
constructor(options: Menu.IOptions) {
super(options);
this.menu.title.label = 'Edit';
this.undoers = new Set<IEditMenu.IUndoer<Widget>>();
this.clearers = new Set<IEditMenu.IClearer<Widget>>();
this.goToLiners = new Set<IEditMenu.IGoToLiner<Widget>>();
}
/**
* A set storing IUndoers for the Edit menu.
*/
readonly undoers: Set<IEditMenu.IUndoer<Widget>>;
/**
* A set storing IClearers for the Edit menu.
*/
readonly clearers: Set<IEditMenu.IClearer<Widget>>;
/**
* A set storing IGoToLiners for the Edit menu.
*/
readonly goToLiners: Set<IEditMenu.IGoToLiner<Widget>>;
/**
* Dispose of the resources held by the edit menu.
*/
dispose(): void {
this.undoers.clear();
this.clearers.clear();
super.dispose();
}
}
/**
* Namespace for IEditMenu
*/
export namespace IEditMenu {
/**
* Interface for an activity that uses Undo/Redo.
*/
export interface IUndoer<T extends Widget> extends IMenuExtender<T> {
/**
* Execute an undo command for the activity.
*/
undo?: (widget: T) => void;
/**
* Execute a redo command for the activity.
*/
redo?: (widget: T) => void;
}
/**
* Interface for an activity that wants to register a 'Clear...' menu item
*/
export interface IClearer<T extends Widget> extends IMenuExtender<T> {
/**
* A name for the thing to be cleared, used for labeling `clearCurrent`.
*/
noun?: string;
/**
* A plural name for the thing to be cleared, used for labeling `clearAll`.
*/
pluralNoun?: string;
/**
* A function to clear the currently portion of activity.
*/
clearCurrent?: (widget: T) => void;
/**
* A function to clear all of an activity.
*/
clearAll?: (widget: T) => void;
}
/**
* Interface for an activity that uses Go to Line.
*/
export interface IGoToLiner<T extends Widget> extends IMenuExtender<T> {
/**
* Execute a go to line command for the activity.
*/
goToLine?: (widget: T) => void;
}
}