/
tokens.ts
351 lines (315 loc) · 9.06 KB
/
tokens.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { IChangedArgs } from '@jupyterlab/coreutils';
import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry';
import { Contents, Kernel, ServiceManager } from '@jupyterlab/services';
import { Token } from '@lumino/coreutils';
import { IDisposable } from '@lumino/disposable';
import { ISignal } from '@lumino/signaling';
import { Widget } from '@lumino/widgets';
/**
* The document registry token.
*/
export const IDocumentManager = new Token<IDocumentManager>(
'@jupyterlab/docmanager:IDocumentManager',
`A service for the manager for all
documents used by the application. Use this if you want to open and close documents,
create and delete files, and otherwise interact with the file system.`
);
/**
* The document widget opener token.
*/
export const IDocumentWidgetOpener = new Token<IDocumentWidgetOpener>(
'@jupyterlab/docmanager:IDocumentWidgetOpener',
`A service to open a widget.`
);
/**
* The recent documents database token.
*/
export const IRecentsManager = new Token<IRecentsManager>(
'@jupyterlab/docmanager:IRecentsManager',
`A service providing information about recently opened and closed documents`
);
/**
* The interface for a document manager.
*/
export interface IDocumentManager extends IDisposable {
/**
* The registry used by the manager.
*/
readonly registry: DocumentRegistry;
/**
* The service manager used by the manager.
*/
readonly services: ServiceManager.IManager;
/**
* A signal emitted when one of the documents is activated.
*/
readonly activateRequested: ISignal<this, string>;
/**
* Whether to autosave documents.
*/
autosave: boolean;
/**
* Whether to ask confirmation to close a tab or not.
*/
confirmClosingDocument: boolean;
/**
* Determines the time interval for autosave in seconds.
*/
autosaveInterval: number;
/**
* Defines max acceptable difference, in milliseconds, between last modified timestamps on disk and client.
*/
lastModifiedCheckMargin: number;
/**
* Whether to ask the user to rename untitled file on first manual save.
*/
renameUntitledFileOnSave: boolean;
/**
* Signal triggered when an attribute changes.
*/
readonly stateChanged: ISignal<IDocumentManager, IChangedArgs<any>>;
/**
* Clone a widget.
*
* @param widget - The source widget.
*
* @returns A new widget or `undefined`.
*
* #### Notes
* Uses the same widget factory and context as the source, or returns
* `undefined` if the source widget is not managed by this manager.
*/
cloneWidget(widget: Widget): IDocumentWidget | undefined;
/**
* Close all of the open documents.
*
* @returns A promise resolving when the widgets are closed.
*/
closeAll(): Promise<void>;
/**
* Close the widgets associated with a given path.
*
* @param path - The target path.
*
* @returns A promise resolving when the widgets are closed.
*/
closeFile(path: string): Promise<void>;
/**
* Get the document context for a widget.
*
* @param widget - The widget of interest.
*
* @returns The context associated with the widget, or `undefined` if no such
* context exists.
*/
contextForWidget(widget: Widget): DocumentRegistry.Context | undefined;
/**
* Copy a file.
*
* @param fromFile - The full path of the original file.
*
* @param toDir - The full path to the target directory.
*
* @returns A promise which resolves to the contents of the file.
*/
copy(fromFile: string, toDir: string): Promise<Contents.IModel>;
/**
* Create a new file and return the widget used to view it.
*
* @param path - The file path to create.
*
* @param widgetName - The name of the widget factory to use. 'default' will use the default widget.
*
* @param kernel - An optional kernel name/id to override the default.
*
* @returns The created widget, or `undefined`.
*
* #### Notes
* This function will return `undefined` if a valid widget factory
* cannot be found.
*/
createNew(
path: string,
widgetName?: string,
kernel?: Partial<Kernel.IModel>
): Widget | undefined;
/**
* Delete a file.
*
* @param path - The full path to the file to be deleted.
*
* @returns A promise which resolves when the file is deleted.
*
* #### Notes
* If there is a running session associated with the file and no other
* sessions are using the kernel, the session will be shut down.
*/
deleteFile(path: string): Promise<void>;
/**
* Duplicate a file.
*
* @param path - The full path to the file to be duplicated.
*
* @returns A promise which resolves when the file is duplicated.
*
*/
duplicate(path: string): Promise<Contents.IModel>;
/**
* See if a widget already exists for the given path and widget name.
*
* @param path - The file path to use.
*
* @param widgetName - The name of the widget factory to use. 'default' will use the default widget.
*
* @returns The found widget, or `undefined`.
*
* #### Notes
* This can be used to find an existing widget instead of opening
* a new widget.
*/
findWidget(
path: string,
widgetName?: string | null
): IDocumentWidget | undefined;
/**
* Create a new untitled file.
*
* @param options - The file content creation options.
*/
newUntitled(options: Contents.ICreateOptions): Promise<Contents.IModel>;
/**
* Open a file and return the widget used to view it.
*
* @param path - The file path to open.
*
* @param widgetName - The name of the widget factory to use. 'default' will use the default widget.
*
* @param kernel - An optional kernel name/id to override the default.
*
* @returns The created widget, or `undefined`.
*
* #### Notes
* This function will return `undefined` if a valid widget factory
* cannot be found.
*/
open(
path: string,
widgetName?: string,
kernel?: Partial<Kernel.IModel>,
options?: DocumentRegistry.IOpenOptions
): IDocumentWidget | undefined;
/**
* Open a file and return the widget used to view it.
* Reveals an already existing editor.
*
* @param path - The file path to open.
*
* @param widgetName - The name of the widget factory to use. 'default' will use the default widget.
*
* @param kernel - An optional kernel name/id to override the default.
*
* @returns The created widget, or `undefined`.
*
* #### Notes
* This function will return `undefined` if a valid widget factory
* cannot be found.
*/
openOrReveal(
path: string,
widgetName?: string,
kernel?: Partial<Kernel.IModel>,
options?: DocumentRegistry.IOpenOptions
): IDocumentWidget | undefined;
/**
* Overwrite a file.
*
* @param oldPath - The full path to the original file.
*
* @param newPath - The full path to the new file.
*
* @returns A promise containing the new file contents model.
*/
overwrite(oldPath: string, newPath: string): Promise<Contents.IModel>;
/**
* Rename a file or directory.
*
* @param oldPath - The full path to the original file.
*
* @param newPath - The full path to the new file.
*
* @returns A promise containing the new file contents model. The promise
* will reject if the newPath already exists. Use [[overwrite]] to overwrite
* a file.
*/
rename(oldPath: string, newPath: string): Promise<Contents.IModel>;
}
/**
* The interface for a widget opener.
*/
export interface IDocumentWidgetOpener {
/**
* Open the given widget.
*/
open(widget: IDocumentWidget, options?: DocumentRegistry.IOpenOptions): void;
/**
* A signal emitted when a widget is opened
*/
readonly opened: ISignal<IDocumentWidgetOpener, IDocumentWidget>;
}
/**
* Recent opened items manager.
*/
export interface IRecentsManager extends IDisposable {
/**
* Get the recently opened documents.
*/
readonly recentlyOpened: RecentDocument[];
/**
* Get the recently closed items.
*/
readonly recentlyClosed: RecentDocument[];
/**
* Signal emitted when either of the list changes.
*/
readonly changed: ISignal<IRecentsManager, void>;
/**
* Check if the recent item is valid, remove if it from both lists if it is not.
*/
validate(recent: RecentDocument): Promise<boolean>;
/**
* Add a new path to the recent list.
*/
addRecent(
document: Omit<RecentDocument, 'root'>,
event: 'opened' | 'closed'
): void;
/**
* Remove the document from recents list.
*/
removeRecent(document: RecentDocument, event: 'opened' | 'closed'): void;
}
/**
* The interface for a recent document.
*/
export type RecentDocument = {
/**
* The server root path.
*
* Allows to select only the currently accessible documents.
*/
root: string;
/**
* The path to the document.
*/
path: string;
/**
* The document content type or `directory` literal for directories.
*/
contentType: string;
/**
* The factory that was used when the document was most recently opened or closed.
*/
factory?: string;
};