UNPKG

5.82 kBTypeScriptView Raw
1import { IChangedArgs } from '@jupyterlab/coreutils';
2import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry';
3import { ITranslator } from '@jupyterlab/translation';
4import { IDisposable } from '@lumino/disposable';
5import { IMessageHandler, Message } from '@lumino/messaging';
6import { ISignal } from '@lumino/signaling';
7import { Widget } from '@lumino/widgets';
8/**
9 * A class that maintains the lifecycle of file-backed widgets.
10 */
11export declare class DocumentWidgetManager implements IDisposable {
12 /**
13 * Construct a new document widget manager.
14 */
15 constructor(options: DocumentWidgetManager.IOptions);
16 /**
17 * A signal emitted when one of the documents is activated.
18 */
19 get activateRequested(): ISignal<this, string>;
20 /**
21 * Whether to ask confirmation to close a tab or not.
22 */
23 get confirmClosingDocument(): boolean;
24 set confirmClosingDocument(v: boolean);
25 /**
26 * Signal triggered when an attribute changes.
27 */
28 get stateChanged(): ISignal<DocumentWidgetManager, IChangedArgs<any>>;
29 /**
30 * Test whether the document widget manager is disposed.
31 */
32 get isDisposed(): boolean;
33 /**
34 * Dispose of the resources used by the widget manager.
35 */
36 dispose(): void;
37 /**
38 * Create a widget for a document and handle its lifecycle.
39 *
40 * @param factory - The widget factory.
41 *
42 * @param context - The document context object.
43 *
44 * @returns A widget created by the factory.
45 *
46 * @throws If the factory is not registered.
47 */
48 createWidget(factory: DocumentRegistry.WidgetFactory, context: DocumentRegistry.Context): IDocumentWidget;
49 /**
50 * When a new widget is created, we need to hook it up
51 * with some signals, update the widget extensions (for
52 * this kind of widget) in the docregistry, among
53 * other things.
54 */
55 private _initializeWidget;
56 /**
57 * Install the message hook for the widget and add to list
58 * of known widgets.
59 *
60 * @param context - The document context object.
61 *
62 * @param widget - The widget to adopt.
63 */
64 adoptWidget(context: DocumentRegistry.Context, widget: IDocumentWidget): void;
65 /**
66 * See if a widget already exists for the given context and widget name.
67 *
68 * @param context - The document context object.
69 *
70 * @returns The found widget, or `undefined`.
71 *
72 * #### Notes
73 * This can be used to use an existing widget instead of opening
74 * a new widget.
75 */
76 findWidget(context: DocumentRegistry.Context, widgetName: string): IDocumentWidget | undefined;
77 /**
78 * Get the document context for a widget.
79 *
80 * @param widget - The widget of interest.
81 *
82 * @returns The context associated with the widget, or `undefined`.
83 */
84 contextForWidget(widget: Widget): DocumentRegistry.Context | undefined;
85 /**
86 * Clone a widget.
87 *
88 * @param widget - The source widget.
89 *
90 * @returns A new widget or `undefined`.
91 *
92 * #### Notes
93 * Uses the same widget factory and context as the source, or throws
94 * if the source widget is not managed by this manager.
95 */
96 cloneWidget(widget: Widget): IDocumentWidget | undefined;
97 /**
98 * Close the widgets associated with a given context.
99 *
100 * @param context - The document context object.
101 */
102 closeWidgets(context: DocumentRegistry.Context): Promise<void>;
103 /**
104 * Dispose of the widgets associated with a given context
105 * regardless of the widget's dirty state.
106 *
107 * @param context - The document context object.
108 */
109 deleteWidgets(context: DocumentRegistry.Context): Promise<void>;
110 /**
111 * Filter a message sent to a message handler.
112 *
113 * @param handler - The target handler of the message.
114 *
115 * @param msg - The message dispatched to the handler.
116 *
117 * @returns `false` if the message should be filtered, of `true`
118 * if the message should be dispatched to the handler as normal.
119 */
120 messageHook(handler: IMessageHandler, msg: Message): boolean;
121 /**
122 * Set the caption for widget title.
123 *
124 * @param widget - The target widget.
125 */
126 protected setCaption(widget: Widget): Promise<void>;
127 /**
128 * Handle `'close-request'` messages.
129 *
130 * @param widget - The target widget.
131 *
132 * @returns A promise that resolves with whether the widget was closed.
133 */
134 protected onClose(widget: Widget): Promise<boolean>;
135 /**
136 * Dispose of widget regardless of widget's dirty state.
137 *
138 * @param widget - The target widget.
139 */
140 protected onDelete(widget: Widget): Promise<void>;
141 /**
142 * Ask the user whether to close an unsaved file.
143 */
144 private _maybeClose;
145 /**
146 * Handle the disposal of a widget.
147 */
148 private _widgetDisposed;
149 /**
150 * Handle the disposal of a widget.
151 */
152 private _onWidgetDisposed;
153 /**
154 * Handle a file changed signal for a context.
155 */
156 private _onFileChanged;
157 /**
158 * Handle a path changed signal for a context.
159 */
160 private _onPathChanged;
161 protected translator: ITranslator;
162 private _registry;
163 private _activateRequested;
164 private _confirmClosingTab;
165 private _isDisposed;
166 private _stateChanged;
167}
168/**
169 * A namespace for document widget manager statics.
170 */
171export declare namespace DocumentWidgetManager {
172 /**
173 * The options used to initialize a document widget manager.
174 */
175 interface IOptions {
176 /**
177 * A document registry instance.
178 */
179 registry: DocumentRegistry;
180 /**
181 * The application language translator.
182 */
183 translator?: ITranslator;
184 }
185}