UNPKG

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