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