@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
205 lines • 12.2 kB
TypeScript
import { DockLayout, DockPanel, ExtractableWidget, TabBar, Widget } from './widgets/index.js';
import { MessageService } from '../common/message-service.js';
import { ApplicationShell, DockPanelRenderer } from './shell/application-shell.js';
import { Emitter } from '../common/event.js';
import { SecondaryWindowOptions, SecondaryWindowRootWidget, SecondaryWindowService } from './window/secondary-window-service.js';
import { KeybindingRegistry } from './keybinding.js';
import { TheiaDockPanel } from './shell/theia-dock-panel.js';
import { ILogger } from '../common/logger.js';
import { NativeTabDragService } from './shell/native-tab-drag-service.js';
import { WindowService } from './window/window-service.js';
import { PreferenceService } from '../common/preferences/index.js';
import { WindowFocusService } from './window/window-focus-service.js';
/** Widgets to be contained inside a DockPanel in the secondary window. */
declare class SecondaryWindowDockPanelWidget extends SecondaryWindowRootWidget {
protected _widgets: Widget[];
protected dockPanel: TheiaDockPanel;
/** The bounds of the window when it was closed */
closedBounds: SecondaryWindowHandler.WindowBounds | undefined;
constructor(dockPanelFactory: TheiaDockPanel.Factory, dockPanelRendererFactory: (document?: Document | ShadowRoot) => DockPanelRenderer, closeHandler: (sender: TabBar<Widget>, args: TabBar.ITabCloseRequestedArgs<Widget>) => boolean, secondaryWindow: Window, dropOptions?: Pick<TheiaDockPanel.IOptions, 'canDropWidget' | 'onWillDropWidget'> & {
/** Called when a widget has been dropped on this window, it must be tracked with {@link track} */
onDidDropWidget(widget: Widget): void;
});
get widgets(): ReadonlyArray<Widget>;
addWidget(widget: Widget, disposeCallback: () => void, options?: TheiaDockPanel.AddOptions): void;
/**
* Tracks the given widget, which has been added to the dock panel of this window.
*
* @param disposeCallback called when the widget leaves this window
*/
track(widget: Widget, disposeCallback: () => void): void;
getTabBar(widget: Widget): TabBar<Widget> | undefined;
/**
* @returns the widgets in the order of the dock panel's layout
*/
getLayoutWidgets(): Widget[];
saveLayout(): DockPanel.ILayoutConfig;
/**
* Restores the layout of the dock panel. The widgets of the layout must be tracked with {@link track} beforehand.
*/
restoreLayout(config: DockPanel.ILayoutConfig): void;
}
/**
* Offers functionality to move a widget out of the main window to a newly created window.
* Widgets must explicitly implement the `ExtractableWidget` interface to support this.
*
* This handler manages the opened secondary windows and sets up messaging between them and the Theia main window.
* In addition, it provides access to the extracted widgets and provides notifications when widgets are added to or removed from this handler.
*
*/
export declare class SecondaryWindowHandler {
/** List of widgets in secondary windows. */
protected readonly _widgets: Widget[];
protected applicationShell: ApplicationShell;
protected dockPanelRendererFactory: (document?: Document | ShadowRoot) => DockPanelRenderer;
protected keybindings: KeybindingRegistry;
protected dockPanelFactory: TheiaDockPanel.Factory;
protected readonly logger: ILogger;
protected readonly onWillAddWidgetEmitter: Emitter<[Widget, Window]>;
/** Subscribe to get notified when a widget is added to this handler, i.e. the widget was moved to an secondary window . */
readonly onWillAddWidget: import("../common/event.js").Event<[Widget, Window]>;
protected readonly onDidAddWidgetEmitter: Emitter<[Widget, Window]>;
/** Subscribe to get notified when a widget is added to this handler, i.e. the widget was moved to an secondary window . */
readonly onDidAddWidget: import("../common/event.js").Event<[Widget, Window]>;
protected readonly onWillRemoveWidgetEmitter: Emitter<[Widget, Window]>;
/** Subscribe to get notified when a widget is removed from this handler, i.e. the widget's window was closed or the widget was disposed. */
readonly onWillRemoveWidget: import("../common/event.js").Event<[Widget, Window]>;
protected readonly onDidRemoveWidgetEmitter: Emitter<[Widget, Window]>;
/** Subscribe to get notified when a widget is removed from this handler, i.e. the widget's window was closed or the widget was disposed. */
readonly onDidRemoveWidget: import("../common/event.js").Event<[Widget, Window]>;
protected readonly messageService: MessageService;
protected readonly secondaryWindowService: SecondaryWindowService;
protected readonly nativeTabDragService: NativeTabDragService;
protected readonly windowService: WindowService;
protected readonly preferenceService: PreferenceService;
protected readonly windowFocusService: WindowFocusService;
/**
* The secondary windows that are being restored, see {@link setLayoutData}, and have not been loaded yet.
* Their widgets are not tracked yet, so they are stored with the layout as they were restored.
*/
protected readonly pendingWindows: Map<Window, SecondaryWindowHandler.LayoutData>;
/** @returns List of widgets in secondary windows. */
get widgets(): ReadonlyArray<Widget>;
/**
* Sets up message forwarding from the main window to secondary windows.
* Does nothing if this service has already been initialized.
*
* @param shell The `ApplicationShell` that widgets will be moved out from.
* @param dockPanelRendererFactory A factory function to create a `DockPanelRenderer` for use in secondary windows.
*/
init(shell: ApplicationShell, dockPanelRendererFactory: (document?: Document | ShadowRoot) => DockPanelRenderer): void;
/**
* Focuses the window in which a tab has been dropped and the widget of the tab. The drag started in another window,
* or outside of the main area, which keeps the focus otherwise.
*/
protected focusDroppedWidget(widget: Widget, target: Window): void;
/**
* Moves the given widget to a new window.
*
* @param widget the widget to extract
* @param options optional options for the created window, e.g. its screen position
*/
moveWidgetToSecondaryWindow(widget: ExtractableWidget, options?: SecondaryWindowOptions): void;
/**
* Opens a secondary window and sets up its root widget once the window has been loaded.
*
* @param widget the widget the window is created for, its label is used as the window title
* @param options the options for the created window, e.g. its bounds
* @param populate adds the widgets to the root widget of the loaded window
* @param onDidFailToLoad called if the loaded window cannot host widgets, the window is closed then
* @returns the created window or `undefined` if it could not be created
*/
protected openSecondaryWindow(widget: ExtractableWidget, options: SecondaryWindowOptions | undefined, populate: (newWindow: Window, rootWidget: SecondaryWindowDockPanelWidget) => void, onDidFailToLoad?: (newWindow: Window) => void): Window | undefined;
/**
* @returns the bounds of the given window, the size as expected by `window.open`
*/
protected getWindowBounds(win: Window): SecondaryWindowHandler.WindowBounds;
/**
* @returns the data to restore the open secondary windows with their widgets, see {@link setLayoutData}
*/
getLayoutData(): SecondaryWindowHandler.LayoutData[];
/**
* Opens secondary windows with the widgets of the given layout data, see {@link getLayoutData}.
* The widgets are added to the main window instead if the `window.restoreSecondaryWindows` preference is disabled,
* or if their window cannot be opened, e.g. because a browser blocks the popup.
*/
setLayoutData(layoutData: SecondaryWindowHandler.LayoutData[]): Promise<void>;
protected restoreSecondaryWindow(data: SecondaryWindowHandler.LayoutData, openWindow: boolean): void;
protected collectLayoutWidgets(area: DockLayout.AreaConfig | null): Widget[];
/**
* Removes the widgets that do not match the given predicate from the given layout. Empty areas are removed when the layout is restored.
*/
protected removeFromLayout(area: DockLayout.AreaConfig | null, keep: (widget: Widget) => boolean): void;
protected setupHtmlLanguageAttributes(element: HTMLElement): void;
/**
* Moves the given widget from its secondary window back to the main window.
* The secondary window is closed once it does not contain any widgets anymore.
*
* @param widget the widget to move back
*/
moveWidgetToMainWindow(widget: Widget): Promise<void>;
/**
* Moves all widgets of the given secondary window back to the main window, which closes the secondary window.
*
* @param secondaryWindow the window to move the widgets from
*/
moveAllWidgetsToMainWindow(secondaryWindow: Window): Promise<void>;
/**
* Only widgets that can be moved to secondary windows, or that are in a secondary window already, can be dropped on secondary windows.
*/
protected canDropInSecondaryWindow(widget: Widget): boolean;
protected onWillDropInSecondaryWindow(widget: Widget): void;
protected onDidDropInSecondaryWindow(widget: Widget, secondaryWindow: Window, rootWidget: SecondaryWindowDockPanelWidget): void;
private onWidgetRemove;
addWidgetToSecondaryWindow(widget: Widget, secondaryWindow: Window, options?: TheiaDockPanel.AddOptions): void;
onTabCloseRequested(_sender: TabBar<Widget>, _args: TabBar.ITabCloseRequestedArgs<Widget>): boolean;
/**
* If the given widget is tracked by this handler, activate it and focus its secondary window.
*
* @param widgetId The widget to activate specified by its id
* @returns The activated `ExtractableWidget` or `undefined` if the given widget id is unknown to this handler.
*/
activateWidget(widgetId: string): ExtractableWidget | Widget | undefined;
/**
* If the given widget is tracked by this handler, reveal it by focussing its secondary window.
*
* @param widgetId The widget to reveal specified by its id
* @returns The revealed `ExtractableWidget` or `undefined` if the given widget id is unknown to this handler.
*/
revealWidget(widgetId: string): ExtractableWidget | Widget | undefined;
getFocusedWindow(): Window | undefined;
protected addWidget(widget: Widget, win: Window): void;
protected removeWidget(widget: Widget, win: Window): void;
getTabBarFor(widget: Widget): TabBar<Widget> | undefined;
}
export declare namespace SecondaryWindowHandler {
/**
* The screen bounds of a secondary window.
*/
interface WindowBounds {
x: number;
y: number;
width: number;
height: number;
}
/**
* Data to save and restore a secondary window with its widgets.
*/
interface LayoutData {
bounds?: WindowBounds;
/** The layout of the window's dock panel */
config: DockPanel.ILayoutConfig;
/** The areas of the main window to move the widgets of `config` back to, in the order of the widgets in `config` */
restoreAreas?: ApplicationShell.Area[];
}
/**
* @returns the area of the main window to move a widget back to whose previous area is the given one
*/
function getMainWindowArea(previousArea: ApplicationShell.Area | undefined): ApplicationShell.Area;
}
export declare function getDefaultRestoreArea(window: Window): ApplicationShell.Area | undefined;
export declare function getAllWidgetsFromSecondaryWindow(window: Window): ReadonlyArray<Widget> | undefined;
export declare function extractSecondaryWindowRootWidget(widget: Widget | undefined | null): SecondaryWindowRootWidget | undefined;
export declare function extractSecondaryWindow(widget: Widget | undefined | null): Window | undefined;
export {};
//# sourceMappingURL=secondary-window-handler.d.ts.map