1 | import { Widget } from '@phosphor/widgets';
|
2 | import { Message } from '@phosphor/messaging';
|
3 | import { Emitter, Event } from '../common/event';
|
4 | import { MaybePromise } from '../common/types';
|
5 | import { AbstractDialog } from './dialogs';
|
6 | import { Disposable } from '../common';
|
7 | export interface Saveable {
|
8 | readonly dirty: boolean;
|
9 | readonly onDirtyChanged: Event<void>;
|
10 | readonly autoSave: 'off' | 'afterDelay' | 'onFocusChange' | 'onWindowChange';
|
11 | |
12 |
|
13 |
|
14 | save(options?: SaveOptions): MaybePromise<void>;
|
15 | |
16 |
|
17 |
|
18 | revert?(options?: Saveable.RevertOptions): Promise<void>;
|
19 | |
20 |
|
21 |
|
22 | createSnapshot?(): Saveable.Snapshot;
|
23 | |
24 |
|
25 |
|
26 | applySnapshot?(snapshot: object): void;
|
27 | }
|
28 | export interface SaveableSource {
|
29 | readonly saveable: Saveable;
|
30 | }
|
31 | export declare class DelegatingSaveable implements Saveable {
|
32 | dirty: boolean;
|
33 | protected readonly onDirtyChangedEmitter: Emitter<void>;
|
34 | get onDirtyChanged(): Event<void>;
|
35 | autoSave: 'off' | 'afterDelay' | 'onFocusChange' | 'onWindowChange';
|
36 | save(options?: SaveOptions): Promise<void>;
|
37 | revert?(options?: Saveable.RevertOptions): Promise<void>;
|
38 | createSnapshot?(): Saveable.Snapshot;
|
39 | applySnapshot?(snapshot: object): void;
|
40 | protected _delegate?: Saveable;
|
41 | protected toDispose?: Disposable;
|
42 | set delegate(delegate: Saveable);
|
43 | }
|
44 | export declare namespace Saveable {
|
45 | interface RevertOptions {
|
46 | |
47 |
|
48 |
|
49 |
|
50 | soft?: boolean;
|
51 | }
|
52 | type Snapshot = {
|
53 | value: string;
|
54 | } | {
|
55 | read(): string | null;
|
56 | };
|
57 | function isSource(arg: unknown): arg is SaveableSource;
|
58 | function is(arg: unknown): arg is Saveable;
|
59 | function get(arg: unknown): Saveable | undefined;
|
60 | function getDirty(arg: unknown): Saveable | undefined;
|
61 | function isDirty(arg: unknown): boolean;
|
62 | function save(arg: unknown, options?: SaveOptions): Promise<void>;
|
63 | function confirmSaveBeforeClose(toClose: Iterable<Widget>, others: Widget[]): Promise<boolean | undefined>;
|
64 | function apply(widget: Widget, getOtherSaveables?: () => Array<Widget | SaveableWidget>, doSave?: (widget: Widget, options?: SaveOptions) => Promise<void>): SaveableWidget | undefined;
|
65 | function shouldSave(saveable: Saveable, cb: () => MaybePromise<boolean | undefined>): Promise<boolean | undefined>;
|
66 | }
|
67 | export interface SaveableWidget extends Widget {
|
68 | |
69 |
|
70 |
|
71 | closeWithoutSaving(doRevert?: boolean): Promise<void>;
|
72 | closeWithSaving(options?: SaveableWidget.CloseOptions): Promise<void>;
|
73 | }
|
74 | export declare const close: unique symbol;
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | export interface PostCreationSaveableWidget extends SaveableWidget {
|
80 | |
81 |
|
82 |
|
83 | [close](): void;
|
84 | }
|
85 | export declare namespace SaveableWidget {
|
86 | function is(widget: Widget | undefined): widget is SaveableWidget;
|
87 | function getDirty<T extends Widget>(widgets: Iterable<T>): IterableIterator<SaveableWidget & T>;
|
88 | function get<T extends Widget>(widgets: Iterable<T>, filter?: (widget: T) => boolean): IterableIterator<SaveableWidget & T>;
|
89 | interface CloseOptions {
|
90 | shouldSave?(): MaybePromise<boolean | undefined>;
|
91 | }
|
92 | }
|
93 |
|
94 |
|
95 |
|
96 | export declare const enum FormatType {
|
97 | |
98 |
|
99 |
|
100 | ON = 1,
|
101 | |
102 |
|
103 |
|
104 | OFF = 2,
|
105 | |
106 |
|
107 |
|
108 | DIRTY = 3
|
109 | }
|
110 | export interface SaveOptions {
|
111 | |
112 |
|
113 |
|
114 | readonly formatType?: FormatType;
|
115 | }
|
116 | export declare function setDirty(widget: Widget, dirty: boolean): void;
|
117 | export declare class ShouldSaveDialog extends AbstractDialog<boolean> {
|
118 | protected shouldSave: boolean;
|
119 | protected readonly dontSaveButton: HTMLButtonElement;
|
120 | constructor(widget: Widget);
|
121 | protected appendDontSaveButton(): HTMLButtonElement;
|
122 | protected onAfterAttach(msg: Message): void;
|
123 | get value(): boolean;
|
124 | }
|
125 | //# sourceMappingURL=saveable.d.ts.map |
\ | No newline at end of file |