1 | import {
|
2 | CancellablePromise,
|
3 | Disposable,
|
4 | Dock,
|
5 | Pane,
|
6 | PaneItemObservedEvent,
|
7 | PaneItemOpenedEvent,
|
8 | Panel,
|
9 | TextEditor,
|
10 | TextEditorObservedEvent,
|
11 | ViewModel,
|
12 | WorkspaceCenter,
|
13 | } from "../index";
|
14 |
|
15 | /** Represents the state of the user interface for the entire window. */
|
16 | export interface Workspace {
|
17 | // Event Subscription
|
18 | /**
|
19 | * Invoke the given callback with all current and future text editors in
|
20 | * the workspace.
|
21 | */
|
22 | observeTextEditors(callback: (editor: TextEditor) => void): Disposable;
|
23 |
|
24 | /**
|
25 | * Invoke the given callback with all current and future panes items in the
|
26 | * workspace.
|
27 | */
|
28 | observePaneItems(callback: (item: object) => void): Disposable;
|
29 |
|
30 | /** Invoke the given callback when the active pane item changes. */
|
31 | onDidChangeActivePaneItem(callback: (item: object) => void): Disposable;
|
32 |
|
33 | /** Invoke the given callback when the active pane item stops changing. */
|
34 | onDidStopChangingActivePaneItem(callback: (item: object) => void): Disposable;
|
35 |
|
36 | /**
|
37 | * Invoke the given callback when a text editor becomes the active text editor and
|
38 | * when there is no longer an active text editor.
|
39 | */
|
40 | onDidChangeActiveTextEditor(callback: (editor?: TextEditor) => void): Disposable;
|
41 |
|
42 | /**
|
43 | * Invoke the given callback with the current active pane item and with all
|
44 | * future active pane items in the workspace.
|
45 | */
|
46 | observeActivePaneItem(callback: (item: object) => void): Disposable;
|
47 |
|
48 | /**
|
49 | * Invoke the given callback with the current active text editor (if any), with all
|
50 | * future active text editors, and when there is no longer an active text editor.
|
51 | */
|
52 | observeActiveTextEditor(callback: (editor?: TextEditor) => void): Disposable;
|
53 |
|
54 | /**
|
55 | * Invoke the given callback whenever an item is opened. Unlike ::onDidAddPaneItem,
|
56 | * observers will be notified for items that are already present in the workspace
|
57 | * when they are reopened.
|
58 | */
|
59 | onDidOpen(callback: (event: PaneItemOpenedEvent) => void): Disposable;
|
60 |
|
61 | /** Invoke the given callback when a pane is added to the workspace. */
|
62 | onDidAddPane(callback: (event: { pane: Pane }) => void): Disposable;
|
63 |
|
64 | /** Invoke the given callback before a pane is destroyed in the workspace. */
|
65 | onWillDestroyPane(callback: (event: { pane: Pane }) => void): Disposable;
|
66 |
|
67 | /** Invoke the given callback when a pane is destroyed in the workspace. */
|
68 | onDidDestroyPane(callback: (event: { pane: Pane }) => void): Disposable;
|
69 |
|
70 | /** Invoke the given callback with all current and future panes in the workspace. */
|
71 | observePanes(callback: (pane: Pane) => void): Disposable;
|
72 |
|
73 | /** Invoke the given callback when the active pane changes. */
|
74 | onDidChangeActivePane(callback: (pane: Pane) => void): Disposable;
|
75 |
|
76 | /**
|
77 | * Invoke the given callback with the current active pane and when the
|
78 | * active pane changes.
|
79 | */
|
80 | observeActivePane(callback: (pane: Pane) => void): Disposable;
|
81 |
|
82 | /** Invoke the given callback when a pane item is added to the workspace. */
|
83 | onDidAddPaneItem(callback: (event: PaneItemObservedEvent) => void): Disposable;
|
84 |
|
85 | /**
|
86 | * Invoke the given callback when a pane item is about to be destroyed,
|
87 | * before the user is prompted to save it.
|
88 | * @param callback The function to be called before pane items are destroyed.
|
89 | * If this function returns a Promise, then the item will not be destroyed
|
90 | * until the promise resolves.
|
91 | */
|
92 | onWillDestroyPaneItem(callback: (event: PaneItemObservedEvent) => void | Promise<void>): Disposable;
|
93 |
|
94 | /** Invoke the given callback when a pane item is destroyed. */
|
95 | onDidDestroyPaneItem(callback: (event: PaneItemObservedEvent) => void): Disposable;
|
96 |
|
97 | /** Invoke the given callback when a text editor is added to the workspace. */
|
98 | onDidAddTextEditor(callback: (event: TextEditorObservedEvent) => void): Disposable;
|
99 |
|
100 | // Opening
|
101 | /**
|
102 | * Opens the given URI in Atom asynchronously. If the URI is already open,
|
103 | * the existing item for that URI will be activated. If no URI is given, or
|
104 | * no registered opener can open the URI, a new empty TextEditor will be created.
|
105 | */
|
106 | open(uri: string, options?: WorkspaceOpenOptions): Promise<object>;
|
107 | /**
|
108 | * Opens the given item in Atom asynchronously. If the item is already open,
|
109 | * the existing item will be activated. If no item is given, a new empty TextEditor
|
110 | * will be created.
|
111 | */
|
112 | open<T extends ViewModel = ViewModel>(item: T, options?: WorkspaceOpenOptions): Promise<T>;
|
113 | /**
|
114 | * Opens the given URI in Atom asynchronously. If the URI is already open,
|
115 | * the existing item for that URI will be activated. If no URI is given, or
|
116 | * no registered opener can open the URI, a new empty TextEditor will be created.
|
117 | */
|
118 | open(): Promise<TextEditor>;
|
119 |
|
120 | /**
|
121 | * Search the workspace for items matching the given URI and hide them.
|
122 | * Returns a boolean indicating whether any items were found (and hidden).
|
123 | */
|
124 | hide(itemOrURI: object | string): boolean;
|
125 |
|
126 | /**
|
127 | * Search the workspace for items matching the given URI. If any are found,
|
128 | * hide them. Otherwise, open the URL.
|
129 | * Returns a Promise that resolves when the item is shown or hidden.
|
130 | */
|
131 | toggle(itemOrURI: object | string): Promise<void>;
|
132 |
|
133 | /**
|
134 | * Creates a new item that corresponds to the provided URI.
|
135 | * If no URI is given, or no registered opener can open the URI, a new empty TextEditor
|
136 | * will be created.
|
137 | */
|
138 | createItemForURI(uri: string): Promise<object | TextEditor>;
|
139 |
|
140 | /** Returns a boolean that is true if object is a TextEditor. */
|
141 | isTextEditor(object: object): object is TextEditor;
|
142 |
|
143 | /**
|
144 | * Asynchronously reopens the last-closed item's URI if it hasn't already
|
145 | * been reopened.
|
146 | */
|
147 | reopenItem(): Promise<object | undefined>;
|
148 |
|
149 | /** Register an opener for a URI. */
|
150 | addOpener(opener: (uri: string, options?: WorkspaceOpenOptions) => ViewModel | undefined): Disposable;
|
151 |
|
152 | /** Create a new text editor. */
|
153 | buildTextEditor(params: object): TextEditor;
|
154 |
|
155 | // Pane Items
|
156 | /** Get all pane items in the workspace. */
|
157 | getPaneItems(): object[];
|
158 |
|
159 | /** Get the active Pane's active item. */
|
160 | getActivePaneItem(): object;
|
161 |
|
162 | /** Get all text editors in the workspace. */
|
163 | getTextEditors(): TextEditor[];
|
164 |
|
165 | /** Get the workspace center's active item if it is a TextEditor. */
|
166 | getActiveTextEditor(): TextEditor | undefined;
|
167 |
|
168 | // Panes
|
169 | /** Get the most recently focused pane container. */
|
170 | getActivePaneContainer(): Dock | WorkspaceCenter;
|
171 |
|
172 | /** Get all panes in the workspace. */
|
173 | getPanes(): Pane[];
|
174 |
|
175 | /** Get the active Pane. */
|
176 | getActivePane(): Pane;
|
177 |
|
178 | /** Make the next pane active. */
|
179 | activateNextPane(): boolean;
|
180 |
|
181 | /** Make the previous pane active. */
|
182 | activatePreviousPane(): boolean;
|
183 |
|
184 | /** Get the first pane container that contains an item with the given URI. */
|
185 | paneContainerForURI(uri: string): Dock | WorkspaceCenter | undefined;
|
186 |
|
187 | /** Get the first pane container that contains the given item. */
|
188 | paneContainerForItem(item: object): Dock | WorkspaceCenter | undefined;
|
189 |
|
190 | /** Get the first Pane with an item for the given URI. */
|
191 | paneForURI(uri: string): Pane | undefined;
|
192 |
|
193 | /** Get the Pane containing the given item. */
|
194 | paneForItem(item: object): Pane | undefined;
|
195 |
|
196 | // Pane Locations
|
197 | /** Get the WorkspaceCenter at the center of the editor window. */
|
198 | getCenter(): WorkspaceCenter;
|
199 |
|
200 | /** Get the Dock to the left of the editor window. */
|
201 | getLeftDock(): Dock;
|
202 |
|
203 | /** Get the Dock to the right of the editor window. */
|
204 | getRightDock(): Dock;
|
205 |
|
206 | /** Get the Dock below the editor window. */
|
207 | getBottomDock(): Dock;
|
208 |
|
209 | /** Returns all Pane containers. */
|
210 | getPaneContainers(): [WorkspaceCenter, Dock, Dock, Dock];
|
211 |
|
212 | // Panels
|
213 | /** Get an Array of all the panel items at the bottom of the editor window. */
|
214 | getBottomPanels(): Panel[];
|
215 |
|
216 | /** Adds a panel item to the bottom of the editor window. */
|
217 | addBottomPanel<T>(options: { item: T; visible?: boolean | undefined; priority?: number | undefined }): Panel<T>;
|
218 |
|
219 | /** Get an Array of all the panel items to the left of the editor window. */
|
220 | getLeftPanels(): Panel[];
|
221 |
|
222 | /** Adds a panel item to the left of the editor window. */
|
223 | addLeftPanel<T>(options: { item: T; visible?: boolean | undefined; priority?: number | undefined }): Panel<T>;
|
224 |
|
225 | /** Get an Array of all the panel items to the right of the editor window. */
|
226 | getRightPanels(): Panel[];
|
227 |
|
228 | /** Adds a panel item to the right of the editor window. */
|
229 | addRightPanel<T>(options: { item: T; visible?: boolean | undefined; priority?: number | undefined }): Panel<T>;
|
230 |
|
231 | /** Get an Array of all the panel items at the top of the editor window. */
|
232 | getTopPanels(): Panel[];
|
233 |
|
234 | /** Adds a panel item to the top of the editor window above the tabs. */
|
235 | addTopPanel<T>(options: { item: T; visible?: boolean | undefined; priority?: number | undefined }): Panel<T>;
|
236 |
|
237 | /** Get an Array of all the panel items in the header. */
|
238 | getHeaderPanels(): Panel[];
|
239 |
|
240 | /** Adds a panel item to the header. */
|
241 | addHeaderPanel<T>(options: { item: T; visible?: boolean | undefined; priority?: number | undefined }): Panel<T>;
|
242 |
|
243 | /** Get an Array of all the panel items in the footer. */
|
244 | getFooterPanels(): Panel[];
|
245 |
|
246 | /** Adds a panel item to the footer. */
|
247 | addFooterPanel<T>(options: { item: T; visible?: boolean | undefined; priority?: number | undefined }): Panel<T>;
|
248 |
|
249 | /** Get an Array of all the modal panel items. */
|
250 | getModalPanels(): Panel[];
|
251 |
|
252 | /** Adds a panel item as a modal dialog. */
|
253 | addModalPanel<T>(options: {
|
254 | item: T;
|
255 | visible?: boolean | undefined;
|
256 | priority?: number | undefined;
|
257 | autoFocus?: boolean | FocusableHTMLElement | undefined;
|
258 | }): Panel<T>;
|
259 |
|
260 | /**
|
261 | * Returns the Panel associated with the given item or null when the item
|
262 | * has no panel.
|
263 | */
|
264 | panelForItem<T>(item: T): Panel<T> | null;
|
265 |
|
266 | // Searching and Replacing
|
267 | /** Performs a search across all files in the workspace. */
|
268 | scan(regex: RegExp, iterator: (result: ScandalResult) => void): CancellablePromise<string | null>;
|
269 | /** Performs a search across all files in the workspace. */
|
270 | scan(
|
271 | regex: RegExp,
|
272 | options: WorkspaceScanOptions,
|
273 | iterator: (result: ScandalResult) => void,
|
274 | ): CancellablePromise<string | null>;
|
275 |
|
276 | /** Performs a replace across all the specified files in the project. */
|
277 | replace(
|
278 | regex: RegExp,
|
279 | replacementText: string,
|
280 | filePaths: readonly string[],
|
281 | iterator: (result: { filePath: string | undefined; replacements: number }) => void,
|
282 | ): Promise<void>;
|
283 | }
|
284 |
|
285 | export interface WorkspaceOpenOptions {
|
286 | /** A number indicating which row to move the cursor to initially. Defaults to 0. */
|
287 | initialLine?: number | undefined;
|
288 |
|
289 | /** A number indicating which column to move the cursor to initially. Defaults to 0. */
|
290 | initialColumn?: number | undefined;
|
291 |
|
292 | /**
|
293 | * Either 'left', 'right', 'up' or 'down'. If 'left', the item will be opened in
|
294 | * leftmost pane of the current active pane's row. If 'right', the item will be
|
295 | * opened in the rightmost pane of the current active pane's row. If only one pane
|
296 | * exists in the row, a new pane will be created. If 'up', the item will be opened
|
297 | * in topmost pane of the current active pane's column. If 'down', the item will be
|
298 | * opened in the bottommost pane of the current active pane's column. If only one pane
|
299 | * exists in the column, a new pane will be created.
|
300 | */
|
301 | split?: "left" | "right" | "up" | "down" | undefined;
|
302 |
|
303 | /**
|
304 | * A boolean indicating whether to call Pane::activate on containing pane.
|
305 | * Defaults to true.
|
306 | */
|
307 | activatePane?: boolean | undefined;
|
308 |
|
309 | /**
|
310 | * A boolean indicating whether to call Pane::activateItem on containing pane.
|
311 | * Defaults to true.
|
312 | */
|
313 | activateItem?: boolean | undefined;
|
314 |
|
315 | /**
|
316 | * A Boolean indicating whether or not the item should be opened in a pending state.
|
317 | * Existing pending items in a pane are replaced with new pending items when they
|
318 | * are opened.
|
319 | */
|
320 | pending?: boolean | undefined;
|
321 |
|
322 | /**
|
323 | * A boolean. If true, the workspace will attempt to activate an existing item for
|
324 | * the given URI on any pane. If false, only the active pane will be searched for
|
325 | * an existing item for the same URI. Defaults to false.
|
326 | */
|
327 | searchAllPanes?: boolean | undefined;
|
328 |
|
329 | /**
|
330 | * A String containing the name of the location in which this item should be opened.
|
331 | * If omitted, Atom will fall back to the last location in which a user has placed
|
332 | * an item with the same URI or, if this is a new URI, the default location specified
|
333 | * by the item.
|
334 | * NOTE: This option should almost always be omitted to honor user preference.
|
335 | */
|
336 | location?: "left" | "right" | "bottom" | "center" | undefined;
|
337 | }
|
338 |
|
339 | export interface WorkspaceScanOptions {
|
340 | /** An array of glob patterns to search within. */
|
341 | paths?: readonly string[] | undefined;
|
342 |
|
343 | /** A function to be periodically called with the number of paths searched. */
|
344 | onPathsSearched?(pathsSearched: number): void;
|
345 |
|
346 | /** The number of lines before the matched line to include in the results object. */
|
347 | leadingContextLineCount?: number | undefined;
|
348 |
|
349 | /** The number of lines after the matched line to include in the results object. */
|
350 | trailingContextLineCount?: number | undefined;
|
351 | }
|
352 |
|
353 | export interface ScandalResult {
|
354 | filePath: string;
|
355 | matches: Array<{
|
356 | matchText: string;
|
357 | lineText: string;
|
358 | lineTextOffset: number;
|
359 | range: [[number, number], [number, number]];
|
360 | leadingContextLines: string[];
|
361 | trailingContextLines: string[];
|
362 | }>;
|
363 | }
|
364 |
|
365 | /**
|
366 | * The type used by the `focus-trap` library to target a specific DOM node.
|
367 | *
|
368 | * A DOM node, a selector string (which will be passed to `document.querySelector()`
|
369 | * to find the DOM node), or a function that returns a DOM node.
|
370 | */
|
371 | export type FocusableHTMLElement = HTMLElement | string | { (): HTMLElement };
|