1 | import { ISessionContext, SessionContext } from '@jupyterlab/apputils';
|
2 | import { IDocumentProviderFactory } from '@jupyterlab/docprovider';
|
3 | import { ModelDB } from '@jupyterlab/observables';
|
4 | import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
|
5 | import { Contents, ServiceManager } from '@jupyterlab/services';
|
6 | import { ITranslator } from '@jupyterlab/translation';
|
7 | import { IDisposable } from '@lumino/disposable';
|
8 | import { ISignal } from '@lumino/signaling';
|
9 | import { Widget } from '@lumino/widgets';
|
10 | import { DocumentRegistry } from './registry';
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | export declare class Context<T extends DocumentRegistry.IModel = DocumentRegistry.IModel> implements DocumentRegistry.IContext<T> {
|
17 | |
18 |
|
19 |
|
20 | constructor(options: Context.IOptions<T>);
|
21 | /**
|
22 | * A signal emitted when the path changes.
|
23 | */
|
24 | get pathChanged(): ISignal<this, string>;
|
25 | /**
|
26 | * A signal emitted when the model is saved or reverted.
|
27 | */
|
28 | get fileChanged(): ISignal<this, Contents.IModel>;
|
29 | /**
|
30 | * A signal emitted on the start and end of a saving operation.
|
31 | */
|
32 | get saveState(): ISignal<this, DocumentRegistry.SaveState>;
|
33 | /**
|
34 | * A signal emitted when the context is disposed.
|
35 | */
|
36 | get disposed(): ISignal<this, void>;
|
37 | /**
|
38 | * Configurable margin used to detect document modification conflicts, in milliseconds
|
39 | */
|
40 | get lastModifiedCheckMargin(): number;
|
41 | set lastModifiedCheckMargin(value: number);
|
42 | /**
|
43 | * Get the model associated with the document.
|
44 | */
|
45 | get model(): T;
|
46 | /**
|
47 | * The client session object associated with the context.
|
48 | */
|
49 | readonly sessionContext: SessionContext;
|
50 | /**
|
51 | * The current path associated with the document.
|
52 | */
|
53 | get path(): string;
|
54 | /**
|
55 | * The current local path associated with the document.
|
56 | * If the document is in the default notebook file browser,
|
57 | * this is the same as the path.
|
58 | */
|
59 | get localPath(): string;
|
60 | /**
|
61 | * The current contents model associated with the document.
|
62 | *
|
63 | * #### Notes
|
64 | * The contents model will be null until the context is populated.
|
65 | * It will have an empty `contents` field.
|
66 | */
|
67 | get contentsModel(): Contents.IModel | null;
|
68 | /**
|
69 | * Get the model factory name.
|
70 | *
|
71 | * #### Notes
|
72 | * This is not part of the `IContext` API.
|
73 | */
|
74 | get factoryName(): string;
|
75 | /**
|
76 | * Test whether the context is disposed.
|
77 | */
|
78 | get isDisposed(): boolean;
|
79 | /**
|
80 | * Dispose of the resources held by the context.
|
81 | */
|
82 | dispose(): void;
|
83 | /**
|
84 | * Whether the context is ready.
|
85 | */
|
86 | get isReady(): boolean;
|
87 | /**
|
88 | * A promise that is fulfilled when the context is ready.
|
89 | */
|
90 | get ready(): Promise<void>;
|
91 | /**
|
92 | * The url resolver for the context.
|
93 | */
|
94 | readonly urlResolver: IRenderMime.IResolver;
|
95 | /**
|
96 | * Initialize the context.
|
97 | *
|
98 | * @param isNew - Whether it is a new file.
|
99 | *
|
100 | * @returns a promise that resolves upon initialization.
|
101 | */
|
102 | initialize(isNew: boolean): Promise<void>;
|
103 | /**
|
104 | * Rename the document.
|
105 | *
|
106 | * @param newName - the new name for the document.
|
107 | */
|
108 | rename(newName: string): Promise<void>;
|
109 | /**
|
110 | * Save the document contents to disk.
|
111 | */
|
112 | save(): Promise<void>;
|
113 | /**
|
114 | * Save the document to a different path chosen by the user.
|
115 | */
|
116 | saveAs(): Promise<void>;
|
117 | /**
|
118 | * Download a file.
|
119 | *
|
120 | * @param path - The path of the file to be downloaded.
|
121 | *
|
122 | * @returns A promise which resolves when the file has begun
|
123 | * downloading.
|
124 | */
|
125 | download(): Promise<void>;
|
126 | /**
|
127 | * Revert the document contents to disk contents.
|
128 | */
|
129 | revert(): Promise<void>;
|
130 | /**
|
131 | * Create a checkpoint for the file.
|
132 | */
|
133 | createCheckpoint(): Promise<Contents.ICheckpointModel>;
|
134 | /**
|
135 | * Delete a checkpoint for the file.
|
136 | */
|
137 | deleteCheckpoint(checkpointId: string): Promise<void>;
|
138 | /**
|
139 | * Restore the file to a known checkpoint state.
|
140 | */
|
141 | restoreCheckpoint(checkpointId?: string): Promise<void>;
|
142 | /**
|
143 | * List available checkpoints for a file.
|
144 | */
|
145 | listCheckpoints(): Promise<Contents.ICheckpointModel[]>;
|
146 | /**
|
147 | * Add a sibling widget to the document manager.
|
148 | *
|
149 | * @param widget - The widget to add to the document manager.
|
150 | *
|
151 | * @param options - The desired options for adding the sibling.
|
152 | *
|
153 | * @returns A disposable used to remove the sibling if desired.
|
154 | *
|
155 | * #### Notes
|
156 | * It is assumed that the widget has the same model and context
|
157 | * as the original widget.
|
158 | */
|
159 | addSibling(widget: Widget, options?: DocumentRegistry.IOpenOptions): IDisposable;
|
160 | /**
|
161 | * Handle a change on the contents manager.
|
162 | */
|
163 | private _onFileChanged;
|
164 | /**
|
165 | * Handle a change to a session property.
|
166 | */
|
167 | private _onSessionChanged;
|
168 | /**
|
169 | * Update our contents model, without the content.
|
170 | */
|
171 | private _updateContentsModel;
|
172 | /**
|
173 | * Handle an initial population.
|
174 | */
|
175 | private _populate;
|
176 | /**
|
177 | * Rename the document.
|
178 | *
|
179 | * @param newName - the new name for the document.
|
180 | */
|
181 | private _rename;
|
182 | /**
|
183 | * Save the document contents to disk.
|
184 | */
|
185 | private _save;
|
186 | /**
|
187 | * Revert the document contents to disk contents.
|
188 | *
|
189 | * @param initializeModel - call the model's initialization function after
|
190 | * deserializing the content.
|
191 | */
|
192 | private _revert;
|
193 | /**
|
194 | * Save a file, dealing with conflicts.
|
195 | */
|
196 | private _maybeSave;
|
197 | /**
|
198 | * Handle a save/load error with a dialog.
|
199 | */
|
200 | private _handleError;
|
201 | /**
|
202 | * Add a checkpoint the file is writable.
|
203 | */
|
204 | private _maybeCheckpoint;
|
205 | /**
|
206 | * Handle a time conflict.
|
207 | */
|
208 | private _timeConflict;
|
209 | /**
|
210 | * Handle a time conflict.
|
211 | */
|
212 | private _maybeOverWrite;
|
213 | /**
|
214 | * Finish a saveAs operation given a new path.
|
215 | */
|
216 | private _finishSaveAs;
|
217 | protected translator: ITranslator;
|
218 | private _trans;
|
219 | private _manager;
|
220 | private _opener;
|
221 | private _model;
|
222 | private _modelDB;
|
223 | private _path;
|
224 | private _lineEnding;
|
225 | private _factory;
|
226 | private _contentsModel;
|
227 | private _readyPromise;
|
228 | private _populatedPromise;
|
229 | private _isPopulated;
|
230 | private _isReady;
|
231 | private _isDisposed;
|
232 | private _pathChanged;
|
233 | private _fileChanged;
|
234 | private _saveState;
|
235 | private _disposed;
|
236 | private _dialogs;
|
237 | private _provider;
|
238 | private _ydoc;
|
239 | private _ycontext;
|
240 | private _lastModifiedCheckMargin;
|
241 | private _timeConflictModalIsOpen;
|
242 | }
|
243 | /**
|
244 | * A namespace for `Context` statics.
|
245 | */
|
246 | export declare namespace Context {
|
247 | |
248 |
|
249 |
|
250 | interface IOptions<T extends DocumentRegistry.IModel> {
|
251 | |
252 |
|
253 |
|
254 | manager: ServiceManager.IManager;
|
255 | |
256 |
|
257 |
|
258 | factory: DocumentRegistry.IModelFactory<T>;
|
259 | |
260 |
|
261 |
|
262 | path: string;
|
263 | |
264 |
|
265 |
|
266 | collaborative?: boolean;
|
267 | |
268 |
|
269 |
|
270 | kernelPreference?: ISessionContext.IKernelPreference;
|
271 | |
272 |
|
273 |
|
274 | docProviderFactory?: IDocumentProviderFactory;
|
275 | |
276 |
|
277 |
|
278 | modelDBFactory?: ModelDB.IFactory;
|
279 | |
280 |
|
281 |
|
282 | opener?: (widget: Widget) => void;
|
283 | |
284 |
|
285 |
|
286 | setBusy?: () => IDisposable;
|
287 | |
288 |
|
289 |
|
290 | sessionDialogs?: ISessionContext.IDialogs;
|
291 | |
292 |
|
293 |
|
294 | translator?: ITranslator;
|
295 | |
296 |
|
297 |
|
298 | lastModifiedCheckMargin?: number;
|
299 | }
|
300 | }
|