UNPKG

3.79 kBTypeScriptView Raw
1import URI from '../common/uri';
2import { MaybePromise, Emitter, Event } from '../common';
3import { BaseWidget } from './widgets';
4import { ApplicationShell } from './shell';
5import { OpenHandler, OpenerOptions } from './opener-service';
6import { WidgetManager } from './widget-manager';
7export declare type WidgetOpenMode = 'open' | 'reveal' | 'activate';
8/**
9 * `WidgetOpenerOptions` define serializable generic options used by the {@link WidgetOpenHandler}.
10 */
11export interface WidgetOpenerOptions extends OpenerOptions {
12 /**
13 * Determines whether the widget should be only opened, revealed or activated.
14 * By default is `activate`.
15 */
16 mode?: WidgetOpenMode;
17 /**
18 * Specify how an opened widget should be added to the shell.
19 * By default to the main area.
20 */
21 widgetOptions?: ApplicationShell.WidgetOptions;
22}
23/**
24 * Generic base class for {@link OpenHandler}s that are opening a widget for a given {@link URI}.
25 */
26export declare abstract class WidgetOpenHandler<W extends BaseWidget> implements OpenHandler {
27 protected readonly shell: ApplicationShell;
28 protected readonly widgetManager: WidgetManager;
29 protected readonly onCreatedEmitter: Emitter<W>;
30 /**
31 * Emit when a new widget is created.
32 */
33 readonly onCreated: Event<W>;
34 protected init(): void;
35 /**
36 * The widget open handler id.
37 *
38 * #### Implementation
39 * - A widget factory for this id should be registered.
40 * - Subclasses should not implement `WidgetFactory`
41 * to avoid exposing capabilities to create a widget outside of `WidgetManager`.
42 */
43 abstract readonly id: string;
44 abstract canHandle(uri: URI, options?: WidgetOpenerOptions): MaybePromise<number>;
45 /**
46 * Open a widget for the given uri and options.
47 * Reject if the given options are not widget options or a widget cannot be opened.
48 * @param uri the uri of the resource that should be opened.
49 * @param options the widget opener options.
50 *
51 * @returns promise of the widget that resolves when the widget has been opened.
52 */
53 open(uri: URI, options?: WidgetOpenerOptions): Promise<W>;
54 protected doOpen(widget: W, options?: WidgetOpenerOptions): Promise<void>;
55 /**
56 * Tries to get an existing widget for the given uri.
57 * @param uri the uri of the widget.
58 *
59 * @returns a promise that resolves to the existing widget or `undefined` if no widget for the given uri exists.
60 */
61 getByUri(uri: URI): Promise<W | undefined>;
62 /**
63 * Return an existing widget for the given uri or creates a new one.
64 *
65 * It does not open a widget, use {@link WidgetOpenHandler#open} instead.
66 * @param uri uri of the widget.
67 *
68 * @returns a promise of the existing or newly created widget.
69 */
70 getOrCreateByUri(uri: URI): Promise<W>;
71 /**
72 * Retrieves all open widgets that have been opened by this handler.
73 *
74 * @returns all open widgets for this open handler.
75 */
76 get all(): W[];
77 protected tryGetPendingWidget(uri: URI, options?: WidgetOpenerOptions): MaybePromise<W> | undefined;
78 protected getWidget(uri: URI, options?: WidgetOpenerOptions): Promise<W | undefined>;
79 protected getOrCreateWidget(uri: URI, options?: WidgetOpenerOptions): Promise<W>;
80 protected abstract createWidgetOptions(uri: URI, options?: WidgetOpenerOptions): Object;
81 /**
82 * Closes all widgets that have been opened by this open handler.
83 * @param options the close options that should be applied to all widgets.
84 *
85 * @returns a promise of all closed widgets that resolves after they have been closed.
86 */
87 closeAll(options?: ApplicationShell.CloseOptions): Promise<W[]>;
88}
89//# sourceMappingURL=widget-open-handler.d.ts.map
\No newline at end of file