1 | import { ISessionContext } from '@jupyterlab/apputils';
|
2 | import { IDocumentProviderFactory } from '@jupyterlab/docprovider';
|
3 | import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry';
|
4 | import { Contents, Kernel, ServiceManager } from '@jupyterlab/services';
|
5 | import { ITranslator } from '@jupyterlab/translation';
|
6 | import { IDisposable } from '@lumino/disposable';
|
7 | import { ISignal } from '@lumino/signaling';
|
8 | import { Widget } from '@lumino/widgets';
|
9 | import { IDocumentManager } from './tokens';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | export declare class DocumentManager implements IDocumentManager {
|
21 | |
22 |
|
23 |
|
24 | constructor(options: DocumentManager.IOptions);
|
25 | /**
|
26 | * The registry used by the manager.
|
27 | */
|
28 | readonly registry: DocumentRegistry;
|
29 | /**
|
30 | * The service manager used by the manager.
|
31 | */
|
32 | readonly services: ServiceManager.IManager;
|
33 | /**
|
34 | * A signal emitted when one of the documents is activated.
|
35 | */
|
36 | get activateRequested(): ISignal<this, string>;
|
37 | /**
|
38 | * Whether to autosave documents.
|
39 | */
|
40 | get autosave(): boolean;
|
41 | set autosave(value: boolean);
|
42 | /**
|
43 | * Determines the time interval for autosave in seconds.
|
44 | */
|
45 | get autosaveInterval(): number;
|
46 | set autosaveInterval(value: number);
|
47 | /**
|
48 | * Defines max acceptable difference, in milliseconds, between last modified timestamps on disk and client
|
49 | */
|
50 | get lastModifiedCheckMargin(): number;
|
51 | set lastModifiedCheckMargin(value: number);
|
52 | /**
|
53 | * Get whether the document manager has been disposed.
|
54 | */
|
55 | get isDisposed(): boolean;
|
56 | /**
|
57 | * Dispose of the resources held by the document manager.
|
58 | */
|
59 | dispose(): void;
|
60 | /**
|
61 | * Clone a widget.
|
62 | *
|
63 | * @param widget - The source widget.
|
64 | *
|
65 | * @returns A new widget or `undefined`.
|
66 | *
|
67 | * #### Notes
|
68 | * Uses the same widget factory and context as the source, or returns
|
69 | * `undefined` if the source widget is not managed by this manager.
|
70 | */
|
71 | cloneWidget(widget: Widget): IDocumentWidget | undefined;
|
72 | /**
|
73 | * Close all of the open documents.
|
74 | *
|
75 | * @returns A promise resolving when the widgets are closed.
|
76 | */
|
77 | closeAll(): Promise<void>;
|
78 | /**
|
79 | * Close the widgets associated with a given path.
|
80 | *
|
81 | * @param path - The target path.
|
82 | *
|
83 | * @returns A promise resolving when the widgets are closed.
|
84 | */
|
85 | closeFile(path: string): Promise<void>;
|
86 | /**
|
87 | * Get the document context for a widget.
|
88 | *
|
89 | * @param widget - The widget of interest.
|
90 | *
|
91 | * @returns The context associated with the widget, or `undefined` if no such
|
92 | * context exists.
|
93 | */
|
94 | contextForWidget(widget: Widget): DocumentRegistry.Context | undefined;
|
95 | /**
|
96 | * Copy a file.
|
97 | *
|
98 | * @param fromFile - The full path of the original file.
|
99 | *
|
100 | * @param toDir - The full path to the target directory.
|
101 | *
|
102 | * @returns A promise which resolves to the contents of the file.
|
103 | */
|
104 | copy(fromFile: string, toDir: string): Promise<Contents.IModel>;
|
105 | /**
|
106 | * Create a new file and return the widget used to view it.
|
107 | *
|
108 | * @param path - The file path to create.
|
109 | *
|
110 | * @param widgetName - The name of the widget factory to use. 'default' will use the default widget.
|
111 | *
|
112 | * @param kernel - An optional kernel name/id to override the default.
|
113 | *
|
114 | * @returns The created widget, or `undefined`.
|
115 | *
|
116 | * #### Notes
|
117 | * This function will return `undefined` if a valid widget factory
|
118 | * cannot be found.
|
119 | */
|
120 | createNew(path: string, widgetName?: string, kernel?: Partial<Kernel.IModel>): Widget | undefined;
|
121 | /**
|
122 | * Delete a file.
|
123 | *
|
124 | * @param path - The full path to the file to be deleted.
|
125 | *
|
126 | * @returns A promise which resolves when the file is deleted.
|
127 | *
|
128 | * #### Notes
|
129 | * If there is a running session associated with the file and no other
|
130 | * sessions are using the kernel, the session will be shut down.
|
131 | */
|
132 | deleteFile(path: string): Promise<void>;
|
133 | /**
|
134 | * See if a widget already exists for the given path and widget name.
|
135 | *
|
136 | * @param path - The file path to use.
|
137 | *
|
138 | * @param widgetName - The name of the widget factory to use. 'default' will use the default widget.
|
139 | *
|
140 | * @returns The found widget, or `undefined`.
|
141 | *
|
142 | * #### Notes
|
143 | * This can be used to find an existing widget instead of opening
|
144 | * a new widget.
|
145 | */
|
146 | findWidget(path: string, widgetName?: string | null): IDocumentWidget | undefined;
|
147 | /**
|
148 | * Create a new untitled file.
|
149 | *
|
150 | * @param options - The file content creation options.
|
151 | */
|
152 | newUntitled(options: Contents.ICreateOptions): Promise<Contents.IModel>;
|
153 | /**
|
154 | * Open a file and return the widget used to view it.
|
155 | *
|
156 | * @param path - The file path to open.
|
157 | *
|
158 | * @param widgetName - The name of the widget factory to use. 'default' will use the default widget.
|
159 | *
|
160 | * @param kernel - An optional kernel name/id to override the default.
|
161 | *
|
162 | * @returns The created widget, or `undefined`.
|
163 | *
|
164 | * #### Notes
|
165 | * This function will return `undefined` if a valid widget factory
|
166 | * cannot be found.
|
167 | */
|
168 | open(path: string, widgetName?: string, kernel?: Partial<Kernel.IModel>, options?: DocumentRegistry.IOpenOptions): IDocumentWidget | undefined;
|
169 | /**
|
170 | * Open a file and return the widget used to view it.
|
171 | * Reveals an already existing editor.
|
172 | *
|
173 | * @param path - The file path to open.
|
174 | *
|
175 | * @param widgetName - The name of the widget factory to use. 'default' will use the default widget.
|
176 | *
|
177 | * @param kernel - An optional kernel name/id to override the default.
|
178 | *
|
179 | * @returns The created widget, or `undefined`.
|
180 | *
|
181 | * #### Notes
|
182 | * This function will return `undefined` if a valid widget factory
|
183 | * cannot be found.
|
184 | */
|
185 | openOrReveal(path: string, widgetName?: string, kernel?: Partial<Kernel.IModel>, options?: DocumentRegistry.IOpenOptions): IDocumentWidget | undefined;
|
186 | /**
|
187 | * Overwrite a file.
|
188 | *
|
189 | * @param oldPath - The full path to the original file.
|
190 | *
|
191 | * @param newPath - The full path to the new file.
|
192 | *
|
193 | * @returns A promise containing the new file contents model.
|
194 | */
|
195 | overwrite(oldPath: string, newPath: string): Promise<Contents.IModel>;
|
196 | /**
|
197 | * Rename a file or directory.
|
198 | *
|
199 | * @param oldPath - The full path to the original file.
|
200 | *
|
201 | * @param newPath - The full path to the new file.
|
202 | *
|
203 | * @returns A promise containing the new file contents model. The promise
|
204 | * will reject if the newPath already exists. Use [[overwrite]] to overwrite
|
205 | * a file.
|
206 | */
|
207 | rename(oldPath: string, newPath: string): Promise<Contents.IModel>;
|
208 | /**
|
209 | * Find a context for a given path and factory name.
|
210 | */
|
211 | private _findContext;
|
212 | /**
|
213 | * Get the contexts for a given path.
|
214 | *
|
215 | * #### Notes
|
216 | * There may be more than one context for a given path if the path is open
|
217 | * with multiple model factories (for example, a notebook can be open with a
|
218 | * notebook model factory and a text model factory).
|
219 | */
|
220 | private _contextsForPath;
|
221 | /**
|
222 | * Create a context from a path and a model factory.
|
223 | */
|
224 | private _createContext;
|
225 | /**
|
226 | * Handle a context disposal.
|
227 | */
|
228 | private _onContextDisposed;
|
229 | /**
|
230 | * Get the widget factory for a given widget name.
|
231 | */
|
232 | private _widgetFactoryFor;
|
233 | /**
|
234 | * Creates a new document, or loads one from disk, depending on the `which` argument.
|
235 | * If `which==='create'`, then it creates a new document. If `which==='open'`,
|
236 | * then it loads the document from disk.
|
237 | *
|
238 | * The two cases differ in how the document context is handled, but the creation
|
239 | * of the widget and launching of the kernel are identical.
|
240 | */
|
241 | private _createOrOpenDocument;
|
242 | /**
|
243 | * Handle an activateRequested signal from the widget manager.
|
244 | */
|
245 | private _onActivateRequested;
|
246 | protected translator: ITranslator;
|
247 | private _activateRequested;
|
248 | private _contexts;
|
249 | private _opener;
|
250 | private _widgetManager;
|
251 | private _isDisposed;
|
252 | private _autosave;
|
253 | private _autosaveInterval;
|
254 | private _lastModifiedCheckMargin;
|
255 | private _when;
|
256 | private _setBusy;
|
257 | private _dialogs;
|
258 | private _docProviderFactory;
|
259 | private _collaborative;
|
260 | }
|
261 | /**
|
262 | * A namespace for document manager statics.
|
263 | */
|
264 | export declare namespace DocumentManager {
|
265 | |
266 |
|
267 |
|
268 | interface IOptions {
|
269 | |
270 |
|
271 |
|
272 | registry: DocumentRegistry;
|
273 | |
274 |
|
275 |
|
276 | manager: ServiceManager.IManager;
|
277 | |
278 |
|
279 |
|
280 | opener: IWidgetOpener;
|
281 | |
282 |
|
283 |
|
284 | when?: Promise<void>;
|
285 | |
286 |
|
287 |
|
288 | setBusy?: () => IDisposable;
|
289 | |
290 |
|
291 |
|
292 | sessionDialogs?: ISessionContext.IDialogs;
|
293 | |
294 |
|
295 |
|
296 | translator?: ITranslator;
|
297 | |
298 |
|
299 |
|
300 | docProviderFactory?: IDocumentProviderFactory;
|
301 | |
302 |
|
303 |
|
304 |
|
305 | collaborative?: boolean;
|
306 | }
|
307 | |
308 |
|
309 |
|
310 | interface IWidgetOpener {
|
311 | |
312 |
|
313 |
|
314 | open(widget: IDocumentWidget, options?: DocumentRegistry.IOpenOptions): void;
|
315 | }
|
316 | }
|