UNPKG

3.03 kBTypeScriptView Raw
1import URI from '../common/uri';
2import { ContributionProvider, MaybePromise, Emitter, Event, Disposable } from '../common';
3export interface OpenerOptions {
4}
5export declare const OpenHandler: unique symbol;
6/**
7 * `OpenHandler` should be implemented to provide a new opener.
8 */
9export interface OpenHandler {
10 /**
11 * A unique id of this handler.
12 */
13 readonly id: string;
14 /**
15 * A human-readable name of this handler.
16 */
17 readonly label?: string;
18 /**
19 * A css icon class of this handler.
20 */
21 readonly iconClass?: string;
22 /**
23 * Test whether this handler can open the given URI for given options.
24 * Return a nonzero number if this handler can open; otherwise it cannot.
25 * Never reject.
26 *
27 * A returned value indicating a priority of this handler.
28 */
29 canHandle(uri: URI, options?: OpenerOptions): MaybePromise<number>;
30 /**
31 * Open a widget for the given URI and options.
32 * Resolve to an opened widget or undefined, e.g. if a page is opened.
33 * Never reject if `canHandle` return a positive number; otherwise should reject.
34 */
35 open(uri: URI, options?: OpenerOptions): MaybePromise<object | undefined>;
36}
37export declare const OpenerService: unique symbol;
38/**
39 * `OpenerService` provide an access to existing openers.
40 */
41export interface OpenerService {
42 /**
43 * Return all registered openers.
44 * Never reject.
45 */
46 getOpeners(): Promise<OpenHandler[]>;
47 /**
48 * Return all openers able to open the given URI for given options
49 * ordered according their priority.
50 * Never reject.
51 */
52 getOpeners(uri: URI, options?: OpenerOptions): Promise<OpenHandler[]>;
53 /**
54 * Return an opener with the higher priority for the given URI.
55 * Reject if such does not exist.
56 */
57 getOpener(uri: URI, options?: OpenerOptions): Promise<OpenHandler>;
58 /**
59 * Add open handler i.e. for custom editors
60 */
61 addHandler?(openHandler: OpenHandler): Disposable;
62 /**
63 * Event that fires when a new opener is added or removed.
64 */
65 onDidChangeOpeners?: Event<void>;
66}
67export declare function open(openerService: OpenerService, uri: URI, options?: OpenerOptions): Promise<object | undefined>;
68export declare class DefaultOpenerService implements OpenerService {
69 protected readonly handlersProvider: ContributionProvider<OpenHandler>;
70 protected readonly customEditorOpenHandlers: OpenHandler[];
71 protected readonly onDidChangeOpenersEmitter: Emitter<void>;
72 readonly onDidChangeOpeners: Event<void>;
73 constructor(handlersProvider: ContributionProvider<OpenHandler>);
74 addHandler(openHandler: OpenHandler): Disposable;
75 getOpener(uri: URI, options?: OpenerOptions): Promise<OpenHandler>;
76 getOpeners(uri?: URI, options?: OpenerOptions): Promise<OpenHandler[]>;
77 protected prioritize(uri: URI, options?: OpenerOptions): Promise<OpenHandler[]>;
78 protected getHandlers(): OpenHandler[];
79}
80//# sourceMappingURL=opener-service.d.ts.map
\No newline at end of file