UNPKG

9.09 kBTypeScriptView Raw
1import { IChangedArgs } from '@jupyterlab/coreutils';
2import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry';
3import { Contents, Kernel, ServiceManager } from '@jupyterlab/services';
4import { Token } from '@lumino/coreutils';
5import { IDisposable } from '@lumino/disposable';
6import { ISignal } from '@lumino/signaling';
7import { Widget } from '@lumino/widgets';
8/**
9 * The document registry token.
10 */
11export declare const IDocumentManager: Token<IDocumentManager>;
12/**
13 * The document widget opener token.
14 */
15export declare const IDocumentWidgetOpener: Token<IDocumentWidgetOpener>;
16/**
17 * The recent documents database token.
18 */
19export declare const IRecentsManager: Token<IRecentsManager>;
20/**
21 * The interface for a document manager.
22 */
23export interface IDocumentManager extends IDisposable {
24 /**
25 * The registry used by the manager.
26 */
27 readonly registry: DocumentRegistry;
28 /**
29 * The service manager used by the manager.
30 */
31 readonly services: ServiceManager.IManager;
32 /**
33 * A signal emitted when one of the documents is activated.
34 */
35 readonly activateRequested: ISignal<this, string>;
36 /**
37 * Whether to autosave documents.
38 */
39 autosave: boolean;
40 /**
41 * Whether to ask confirmation to close a tab or not.
42 */
43 confirmClosingDocument: boolean;
44 /**
45 * Determines the time interval for autosave in seconds.
46 */
47 autosaveInterval: number;
48 /**
49 * Defines max acceptable difference, in milliseconds, between last modified timestamps on disk and client.
50 */
51 lastModifiedCheckMargin: number;
52 /**
53 * Whether to ask the user to rename untitled file on first manual save.
54 */
55 renameUntitledFileOnSave: boolean;
56 /**
57 * Signal triggered when an attribute changes.
58 */
59 readonly stateChanged: ISignal<IDocumentManager, IChangedArgs<any>>;
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 * Duplicate a file.
135 *
136 * @param path - The full path to the file to be duplicated.
137 *
138 * @returns A promise which resolves when the file is duplicated.
139 *
140 */
141 duplicate(path: string): Promise<Contents.IModel>;
142 /**
143 * See if a widget already exists for the given path and widget name.
144 *
145 * @param path - The file path to use.
146 *
147 * @param widgetName - The name of the widget factory to use. 'default' will use the default widget.
148 *
149 * @returns The found widget, or `undefined`.
150 *
151 * #### Notes
152 * This can be used to find an existing widget instead of opening
153 * a new widget.
154 */
155 findWidget(path: string, widgetName?: string | null): IDocumentWidget | undefined;
156 /**
157 * Create a new untitled file.
158 *
159 * @param options - The file content creation options.
160 */
161 newUntitled(options: Contents.ICreateOptions): Promise<Contents.IModel>;
162 /**
163 * Open a file and return the widget used to view it.
164 *
165 * @param path - The file path to open.
166 *
167 * @param widgetName - The name of the widget factory to use. 'default' will use the default widget.
168 *
169 * @param kernel - An optional kernel name/id to override the default.
170 *
171 * @returns The created widget, or `undefined`.
172 *
173 * #### Notes
174 * This function will return `undefined` if a valid widget factory
175 * cannot be found.
176 */
177 open(path: string, widgetName?: string, kernel?: Partial<Kernel.IModel>, options?: DocumentRegistry.IOpenOptions): IDocumentWidget | undefined;
178 /**
179 * Open a file and return the widget used to view it.
180 * Reveals an already existing editor.
181 *
182 * @param path - The file path to open.
183 *
184 * @param widgetName - The name of the widget factory to use. 'default' will use the default widget.
185 *
186 * @param kernel - An optional kernel name/id to override the default.
187 *
188 * @returns The created widget, or `undefined`.
189 *
190 * #### Notes
191 * This function will return `undefined` if a valid widget factory
192 * cannot be found.
193 */
194 openOrReveal(path: string, widgetName?: string, kernel?: Partial<Kernel.IModel>, options?: DocumentRegistry.IOpenOptions): IDocumentWidget | undefined;
195 /**
196 * Overwrite a file.
197 *
198 * @param oldPath - The full path to the original file.
199 *
200 * @param newPath - The full path to the new file.
201 *
202 * @returns A promise containing the new file contents model.
203 */
204 overwrite(oldPath: string, newPath: string): Promise<Contents.IModel>;
205 /**
206 * Rename a file or directory.
207 *
208 * @param oldPath - The full path to the original file.
209 *
210 * @param newPath - The full path to the new file.
211 *
212 * @returns A promise containing the new file contents model. The promise
213 * will reject if the newPath already exists. Use [[overwrite]] to overwrite
214 * a file.
215 */
216 rename(oldPath: string, newPath: string): Promise<Contents.IModel>;
217}
218/**
219 * The interface for a widget opener.
220 */
221export interface IDocumentWidgetOpener {
222 /**
223 * Open the given widget.
224 */
225 open(widget: IDocumentWidget, options?: DocumentRegistry.IOpenOptions): void;
226 /**
227 * A signal emitted when a widget is opened
228 */
229 readonly opened: ISignal<IDocumentWidgetOpener, IDocumentWidget>;
230}
231/**
232 * Recent opened items manager.
233 */
234export interface IRecentsManager extends IDisposable {
235 /**
236 * Get the recently opened documents.
237 */
238 readonly recentlyOpened: RecentDocument[];
239 /**
240 * Get the recently closed items.
241 */
242 readonly recentlyClosed: RecentDocument[];
243 /**
244 * Signal emitted when either of the list changes.
245 */
246 readonly changed: ISignal<IRecentsManager, void>;
247 /**
248 * Check if the recent item is valid, remove if it from both lists if it is not.
249 */
250 validate(recent: RecentDocument): Promise<boolean>;
251 /**
252 * Add a new path to the recent list.
253 */
254 addRecent(document: Omit<RecentDocument, 'root'>, event: 'opened' | 'closed'): void;
255 /**
256 * Remove the document from recents list.
257 */
258 removeRecent(document: RecentDocument, event: 'opened' | 'closed'): void;
259}
260/**
261 * The interface for a recent document.
262 */
263export type RecentDocument = {
264 /**
265 * The server root path.
266 *
267 * Allows to select only the currently accessible documents.
268 */
269 root: string;
270 /**
271 * The path to the document.
272 */
273 path: string;
274 /**
275 * The document content type or `directory` literal for directories.
276 */
277 contentType: string;
278 /**
279 * The factory that was used when the document was most recently opened or closed.
280 */
281 factory?: string;
282};