UNPKG

14.9 kBTypeScriptView Raw
1import { interfaces } from 'inversify';
2import { IIterator } from '@phosphor/algorithm';
3import { Widget, Message, SplitPanel, BaseWidget, SplitLayout, LayoutItem, PanelLayout, DockPanel } from './widgets';
4import { Event as CommonEvent, Emitter } from '../common/event';
5import { Disposable, DisposableCollection } from '../common/disposable';
6import { CommandRegistry } from '../common/command';
7import { MenuModelRegistry, MenuPath } from '../common/menu';
8import { ApplicationShell, StatefulWidget, SplitPositionHandler } from './shell';
9import { FrontendApplicationStateService } from './frontend-application-state';
10import { ContextMenuRenderer, Anchor } from './context-menu-renderer';
11import { TabBarToolbarRegistry, TabBarToolbarFactory, TabBarToolbar, TabBarDelegator, TabBarToolbarItem } from './shell/tab-bar-toolbar';
12import { WidgetManager } from './widget-manager';
13import { ProgressBarFactory } from './progress-bar-factory';
14import { IDragEvent } from '@phosphor/dragdrop';
15import { TabBarDecoratorService } from './shell/tab-bar-decorator';
16export interface ViewContainerTitleOptions {
17 label: string;
18 caption?: string;
19 iconClass?: string;
20 closeable?: boolean;
21}
22export declare class ViewContainerIdentifier {
23 id: string;
24 progressLocationId?: string;
25}
26export interface DescriptionWidget {
27 description: string;
28 onDidChangeDescription: CommonEvent<void>;
29}
30export interface BadgeWidget {
31 badge?: number;
32 badgeTooltip?: string;
33 onDidChangeBadge: CommonEvent<void>;
34 onDidChangeBadgeTooltip: CommonEvent<void>;
35}
36export declare namespace DescriptionWidget {
37 function is(arg: unknown): arg is DescriptionWidget;
38}
39export declare namespace BadgeWidget {
40 function is(arg: unknown): arg is BadgeWidget;
41}
42/**
43 * A widget that may change it's internal structure dynamically.
44 * Current use is to update the toolbar when a contributed view is constructed "lazily".
45 */
46export interface DynamicToolbarWidget {
47 onDidChangeToolbarItems: CommonEvent<void>;
48}
49export declare namespace DynamicToolbarWidget {
50 function is(arg: unknown): arg is DynamicToolbarWidget;
51}
52/**
53 * A view container holds an arbitrary number of widgets inside a split panel.
54 * Each widget is wrapped in a _part_ that displays the widget title and toolbar
55 * and allows to collapse / expand the widget content.
56 */
57export declare class ViewContainer extends BaseWidget implements StatefulWidget, ApplicationShell.TrackableWidgetProvider, TabBarDelegator {
58 protected panel: SplitPanel;
59 protected currentPart: ViewContainerPart | undefined;
60 /**
61 * Disable dragging parts from/to this view container.
62 */
63 disableDNDBetweenContainers: boolean;
64 protected readonly applicationStateService: FrontendApplicationStateService;
65 protected readonly contextMenuRenderer: ContextMenuRenderer;
66 protected readonly commandRegistry: CommandRegistry;
67 protected readonly menuRegistry: MenuModelRegistry;
68 protected readonly widgetManager: WidgetManager;
69 protected readonly splitPositionHandler: SplitPositionHandler;
70 readonly options: ViewContainerIdentifier;
71 protected readonly toolbarRegistry: TabBarToolbarRegistry;
72 protected readonly toolbarFactory: TabBarToolbarFactory;
73 protected readonly onDidChangeTrackableWidgetsEmitter: Emitter<Widget[]>;
74 readonly onDidChangeTrackableWidgets: CommonEvent<Widget[]>;
75 protected readonly progressBarFactory: ProgressBarFactory;
76 protected readonly shell: ApplicationShell;
77 protected readonly decoratorService: TabBarDecoratorService;
78 protected init(): void;
79 protected configureLayout(layout: PanelLayout): void;
80 protected readonly toDisposeOnCurrentPart: DisposableCollection;
81 protected updateCurrentPart(part?: ViewContainerPart): void;
82 protected updateSplitterVisibility(): void;
83 protected titleOptions: ViewContainerTitleOptions | undefined;
84 setTitleOptions(titleOptions: ViewContainerTitleOptions | undefined): void;
85 protected readonly toDisposeOnUpdateTitle: DisposableCollection;
86 protected _tabBarDelegate: Widget;
87 updateTabBarDelegate(): void;
88 getTabBarDelegate(): Widget | undefined;
89 protected updateTitle(): void;
90 protected updateToolbarItems(allParts: ViewContainerPart[]): void;
91 protected getToggleVisibilityGroupLabel(): string;
92 protected registerToolbarItem(commandId: string, options?: Partial<Omit<TabBarToolbarItem, 'id' | 'command'>>): void;
93 protected findOriginalPart(): ViewContainerPart | undefined;
94 protected isCurrentTitle(titleOptions: ViewContainerTitleOptions | undefined): boolean;
95 protected findPartForAnchor(anchor: Anchor): ViewContainerPart | undefined;
96 protected readonly toRemoveWidgets: Map<string, DisposableCollection>;
97 protected createPartId(widget: Widget): string;
98 addWidget(widget: Widget, options?: ViewContainer.Factory.WidgetOptions, originalContainerId?: string, originalContainerTitle?: ViewContainerTitleOptions): Disposable;
99 protected attachNewPart(newPart: ViewContainerPart, insertIndex?: number): Disposable;
100 protected createPart(widget: Widget, partId: string, originalContainerId: string, originalContainerTitle?: ViewContainerTitleOptions, options?: ViewContainer.Factory.WidgetOptions): ViewContainerPart;
101 removeWidget(widget: Widget): boolean;
102 getParts(): ViewContainerPart[];
103 protected getPartIndex(partId: string | undefined): number;
104 getPartFor(widget: Widget): ViewContainerPart | undefined;
105 get containerLayout(): ViewContainerLayout;
106 protected get orientation(): SplitLayout.Orientation;
107 protected get enableAnimation(): boolean;
108 protected lastVisibleState: ViewContainer.State | undefined;
109 storeState(): ViewContainer.State;
110 protected doStoreState(): ViewContainer.State;
111 restoreState(state: ViewContainer.State): void;
112 protected doRestoreState(state: ViewContainer.State): void;
113 /**
114 * Register a command to toggle the visibility of the new part.
115 */
116 protected registerPart(toRegister: ViewContainerPart): void;
117 /**
118 * Register a menu action to toggle the visibility of the new part.
119 * The menu action is unregistered first to enable refreshing the order of menu actions.
120 */
121 protected refreshMenu(part: ViewContainerPart): void;
122 protected unregisterPart(part: ViewContainerPart): void;
123 protected get contextMenuPath(): MenuPath;
124 protected toggleVisibilityCommandId(part: ViewContainerPart): string;
125 protected get globalHideCommandId(): string;
126 protected moveBefore(toMovedId: string, moveBeforeThisId: string): void;
127 getTrackableWidgets(): Widget[];
128 protected fireDidChangeTrackableWidgets(): void;
129 activateWidget(id: string): Widget | undefined;
130 revealWidget(id: string): Widget | undefined;
131 protected revealPart(id: string): ViewContainerPart | undefined;
132 protected onActivateRequest(msg: Message): void;
133 protected onAfterAttach(msg: Message): void;
134 protected onBeforeHide(msg: Message): void;
135 protected onAfterShow(msg: Message): void;
136 protected onBeforeAttach(msg: Message): void;
137 protected onAfterDetach(msg: Message): void;
138 handleEvent(event: Event): void;
139 handleDragEnter(event: IDragEvent): void;
140 toDisposeOnDragEnd: DisposableCollection;
141 handleDragOver(event: IDragEvent): void;
142 handleDragLeave(event: IDragEvent): void;
143 handleDrop(event: IDragEvent): void;
144 protected registerDND(part: ViewContainerPart): Disposable;
145 protected getDockPanel(): DockPanel | undefined;
146 protected isSideDockPanel(widget: Widget): boolean;
147}
148export declare namespace ViewContainer {
149 const Factory: unique symbol;
150 interface Factory {
151 (options: ViewContainerIdentifier): ViewContainer;
152 }
153 namespace Factory {
154 interface WidgetOptions {
155 readonly order?: number;
156 readonly weight?: number;
157 readonly initiallyCollapsed?: boolean;
158 readonly canHide?: boolean;
159 readonly initiallyHidden?: boolean;
160 /**
161 * Disable dragging this part from its original container to other containers,
162 * But allow dropping parts from other containers on it,
163 * This option only applies to the `ViewContainerPart` and has no effect on the ViewContainer.
164 */
165 readonly disableDraggingToOtherContainers?: boolean;
166 }
167 interface WidgetDescriptor {
168 readonly widget: Widget | interfaces.ServiceIdentifier<Widget>;
169 readonly options?: WidgetOptions;
170 }
171 }
172 interface State {
173 title?: ViewContainerTitleOptions;
174 parts: ViewContainerPart.State[];
175 }
176 function getOrientation(node: HTMLElement): 'horizontal' | 'vertical';
177}
178/**
179 * Wrapper around a widget held by a view container. Adds a header to display the
180 * title, toolbar, and collapse / expand handle.
181 */
182export declare class ViewContainerPart extends BaseWidget {
183 readonly wrapped: Widget;
184 readonly partId: string;
185 protected currentContainerId: string;
186 readonly originalContainerId: string;
187 readonly originalContainerTitle: ViewContainerTitleOptions | undefined;
188 protected readonly toolbarRegistry: TabBarToolbarRegistry;
189 protected readonly toolbarFactory: TabBarToolbarFactory;
190 readonly options: ViewContainer.Factory.WidgetOptions;
191 protected readonly header: HTMLElement;
192 protected readonly body: HTMLElement;
193 protected readonly collapsedEmitter: Emitter<boolean>;
194 protected readonly contextMenuEmitter: Emitter<MouseEvent>;
195 protected readonly onTitleChangedEmitter: Emitter<void>;
196 readonly onTitleChanged: CommonEvent<void>;
197 protected readonly onDidFocusEmitter: Emitter<this>;
198 readonly onDidFocus: CommonEvent<this>;
199 protected readonly onPartMovedEmitter: Emitter<ViewContainer>;
200 readonly onDidMove: CommonEvent<ViewContainer>;
201 protected readonly onDidChangeDescriptionEmitter: Emitter<void>;
202 readonly onDidChangeDescription: CommonEvent<void>;
203 protected readonly onDidChangeBadgeEmitter: Emitter<void>;
204 readonly onDidChangeBadge: CommonEvent<void>;
205 protected readonly onDidChangeBadgeTooltipEmitter: Emitter<void>;
206 readonly onDidChangeBadgeTooltip: CommonEvent<void>;
207 protected readonly toolbar: TabBarToolbar;
208 protected _collapsed: boolean;
209 uncollapsedSize: number | undefined;
210 animatedSize: number | undefined;
211 protected readonly toNoDisposeWrapped: Disposable;
212 constructor(wrapped: Widget, partId: string, currentContainerId: string, originalContainerId: string, originalContainerTitle: ViewContainerTitleOptions | undefined, toolbarRegistry: TabBarToolbarRegistry, toolbarFactory: TabBarToolbarFactory, options?: ViewContainer.Factory.WidgetOptions);
213 get viewContainer(): ViewContainer | undefined;
214 get currentViewContainerId(): string;
215 get headerElement(): HTMLElement;
216 get collapsed(): boolean;
217 set collapsed(collapsed: boolean);
218 onPartMoved(newContainer: ViewContainer): void;
219 setHidden(hidden: boolean): void;
220 get canHide(): boolean;
221 get onCollapsed(): CommonEvent<boolean>;
222 get onContextMenu(): CommonEvent<MouseEvent>;
223 get minSize(): number;
224 protected readonly toShowHeader: DisposableCollection;
225 showTitle(): void;
226 hideTitle(): void;
227 get titleHidden(): boolean;
228 protected getScrollContainer(): HTMLElement;
229 protected registerContextMenu(): Disposable;
230 protected createContent(): {
231 header: HTMLElement;
232 body: HTMLElement;
233 disposable: Disposable;
234 };
235 protected createHeader(): {
236 header: HTMLElement;
237 disposable: Disposable;
238 };
239 protected handleResize(): void;
240 protected onResize(msg: Widget.ResizeMessage): void;
241 protected onUpdateRequest(msg: Message): void;
242 protected onAfterAttach(msg: Message): void;
243 protected onBeforeDetach(msg: Message): void;
244 protected onBeforeShow(msg: Message): void;
245 protected onAfterShow(msg: Message): void;
246 protected onBeforeHide(msg: Message): void;
247 protected onAfterHide(msg: Message): void;
248 protected onChildRemoved(msg: Widget.ChildMessage): void;
249 protected onActivateRequest(msg: Message): void;
250}
251export declare namespace ViewContainerPart {
252 /**
253 * Make sure to adjust the `line-height` of the `.theia-view-container .part > .header` CSS class when modifying this, and vice versa.
254 */
255 const HEADER_HEIGHT = 22;
256 interface State {
257 widget?: Widget;
258 partId: string;
259 collapsed: boolean;
260 hidden: boolean;
261 relativeSize?: number;
262 description?: string;
263 /** The original container to which this part belongs */
264 originalContainerId: string;
265 originalContainerTitle?: ViewContainerTitleOptions;
266 }
267 function closestPart(element: Element | EventTarget | null, selector?: string): Element | undefined;
268}
269export declare class ViewContainerLayout extends SplitLayout {
270 protected options: ViewContainerLayout.Options;
271 protected readonly splitPositionHandler: SplitPositionHandler;
272 constructor(options: ViewContainerLayout.Options, splitPositionHandler: SplitPositionHandler);
273 protected get items(): ReadonlyArray<LayoutItem & ViewContainerLayout.Item>;
274 iter(): IIterator<ViewContainerPart>;
275 get widgets(): ViewContainerPart[];
276 attachWidget(index: number, widget: ViewContainerPart): void;
277 getPartSize(part: ViewContainerPart): number | undefined;
278 /**
279 * Set the sizes of the view container parts according to the given weights
280 * by moving the split handles. This is similar to `setRelativeSizes` defined
281 * in `SplitLayout`, but here we properly consider the collapsed / expanded state.
282 */
283 setPartSizes(weights: (number | undefined)[]): void;
284 /**
285 * Determine the size of the split panel area that is available for widget content,
286 * i.e. excluding part headers and split handles.
287 */
288 getAvailableSize(): number;
289 /**
290 * Update a view container part that has been collapsed or expanded. The transition
291 * to the new state is animated.
292 */
293 updateCollapsed(part: ViewContainerPart, enableAnimation: boolean): void;
294 updateSashes(): void;
295 protected getFirstUncollapsedWidgetIndex(): number | undefined;
296 protected getLastUncollapsedWidgetIndex(): number | undefined;
297 protected onFitRequest(msg: Message): void;
298 /**
299 * Sinusoidal tween function for smooth animation.
300 */
301 protected tween(t: number): number;
302 setHandlePosition(index: number, position: number): Promise<void>;
303}
304export declare namespace ViewContainerLayout {
305 interface Options extends SplitLayout.IOptions {
306 headerSize: number;
307 animationDuration: number;
308 }
309 interface Item {
310 readonly widget: ViewContainerPart;
311 }
312}
313//# sourceMappingURL=view-container.d.ts.map
\No newline at end of file