UNPKG

10.7 kBTypeScriptView Raw
1import { TabBar, Widget, DockPanel, Panel } from '@phosphor/widgets';
2import { AttachedProperty } from '@phosphor/properties';
3import { TabBarRenderer, SideTabBar } from './tab-bars';
4import { SidebarMenuWidget, SidebarMenu } from './sidebar-menu-widget';
5import { SplitPositionHandler } from './split-panels';
6import { FrontendApplicationStateService } from '../frontend-application-state';
7import { TheiaDockPanel } from './theia-dock-panel';
8import { SidePanelToolbar } from './side-panel-toolbar';
9import { TabBarToolbarRegistry, TabBarToolbar } from './tab-bar-toolbar';
10import { DisposableCollection } from '../../common/disposable';
11import { ContextMenuRenderer } from '../context-menu-renderer';
12import { MenuPath } from '../../common/menu';
13import { SidebarBottomMenuWidget } from './sidebar-bottom-menu-widget';
14import { SidebarTopMenuWidget } from './sidebar-top-menu-widget';
15/** The class name added to the left and right area panels. */
16export declare const LEFT_RIGHT_AREA_CLASS = "theia-app-sides";
17export declare const SidePanelHandlerFactory: unique symbol;
18export declare const SIDE_PANEL_TOOLBAR_CONTEXT_MENU: MenuPath;
19/**
20 * A class which manages a dock panel and a related side bar. This is used for the left and right
21 * panel of the application shell.
22 */
23export declare class SidePanelHandler {
24 /**
25 * A property that can be attached to widgets in order to determine the insertion index
26 * of their title in the tab bar.
27 */
28 protected static readonly rankProperty: AttachedProperty<Widget, number | undefined>;
29 /**
30 * The tab bar displays the titles of the widgets in the side panel. Visibility of the widgets
31 * is controlled entirely through tab selection: a widget is revealed by setting the `currentTitle`
32 * accordingly in the tab bar, and the panel is hidden by setting that property to `null`. The
33 * tab bar itself remains visible as long as there is at least one widget.
34 */
35 tabBar: SideTabBar;
36 /**
37 * The menu placed on the sidebar top.
38 * Displayed as icons.
39 * Open menus when on clicks.
40 */
41 topMenu: SidebarMenuWidget;
42 /**
43 * The menu placed on the sidebar bottom.
44 * Displayed as icons.
45 * Open menus when on clicks.
46 */
47 bottomMenu: SidebarMenuWidget;
48 /**
49 * A tool bar, which displays a title and widget specific command buttons.
50 */
51 toolBar: SidePanelToolbar;
52 /**
53 * The widget container is a dock panel in `single-document` mode, which means that the panel
54 * cannot be split.
55 */
56 dockPanel: TheiaDockPanel;
57 /**
58 * The panel that contains the tab bar and the dock panel. This one is hidden whenever the dock
59 * panel is empty.
60 */
61 container: Panel;
62 /**
63 * The current state of the side panel.
64 */
65 readonly state: SidePanel.State;
66 /**
67 * The shell area where the panel is placed. This property should not be modified directly, but
68 * only by calling `create`.
69 */
70 protected side: 'left' | 'right';
71 /**
72 * Options that control the behavior of the side panel.
73 */
74 protected options: SidePanel.Options;
75 protected tabBarToolBarRegistry: TabBarToolbarRegistry;
76 protected tabBarToolBarFactory: () => TabBarToolbar;
77 protected tabBarRendererFactory: () => TabBarRenderer;
78 protected sidebarTopWidgetFactory: () => SidebarTopMenuWidget;
79 protected sidebarBottomWidgetFactory: () => SidebarBottomMenuWidget;
80 protected splitPositionHandler: SplitPositionHandler;
81 protected readonly applicationStateService: FrontendApplicationStateService;
82 protected readonly dockPanelFactory: TheiaDockPanel.Factory;
83 protected readonly contextMenuRenderer: ContextMenuRenderer;
84 /**
85 * Create the side bar and dock panel widgets.
86 */
87 create(side: 'left' | 'right', options: SidePanel.Options): void;
88 protected createSideBar(): SideTabBar;
89 protected createSidePanel(): TheiaDockPanel;
90 protected createToolbar(): SidePanelToolbar;
91 protected createSidebarTopMenu(): SidebarTopMenuWidget;
92 protected createSidebarBottomMenu(): SidebarBottomMenuWidget;
93 protected createSidebarMenu<T extends SidebarMenuWidget>(factory: () => T): T;
94 protected showContextMenu(e: MouseEvent): void;
95 protected createContainer(): Panel;
96 /**
97 * Create an object that describes the current side panel layout. This object may contain references
98 * to widgets; these need to be transformed before the layout can be serialized.
99 */
100 getLayoutData(): SidePanel.LayoutData;
101 /**
102 * Apply a side panel layout that has been previously created with `getLayoutData`.
103 */
104 setLayoutData(layoutData: SidePanel.LayoutData): void;
105 /**
106 * Activate a widget residing in the side panel by ID.
107 *
108 * @returns the activated widget if it was found
109 */
110 activate(id: string): Widget | undefined;
111 /**
112 * Expand a widget residing in the side panel by ID. If no ID is given and the panel is
113 * currently collapsed, the last active tab of this side panel is expanded. If no tab
114 * was expanded previously, the first one is taken.
115 *
116 * @returns the expanded widget if it was found
117 */
118 expand(id?: string): Widget | undefined;
119 /**
120 * Collapse the sidebar so no items are expanded.
121 */
122 collapse(): Promise<void>;
123 /**
124 * Add a widget and its title to the dock panel and side bar.
125 *
126 * If the widget is already added, it will be moved.
127 */
128 addWidget(widget: Widget, options: SidePanel.WidgetOptions): void;
129 /**
130 * Add a menu to the sidebar top.
131 *
132 * If the menu is already added, it will be ignored.
133 */
134 addTopMenu(menu: SidebarMenu): void;
135 /**
136 * Remove a menu from the sidebar top.
137 *
138 * @param menuId id of the menu to remove
139 */
140 removeTopMenu(menuId: string): void;
141 /**
142 * Add a menu to the sidebar bottom.
143 *
144 * If the menu is already added, it will be ignored.
145 */
146 addBottomMenu(menu: SidebarMenu): void;
147 /**
148 * Remove a menu from the sidebar bottom.
149 *
150 * @param menuId id of the menu to remove
151 */
152 removeBottomMenu(menuId: string): void;
153 protected updateToolbarTitle: () => void;
154 /**
155 * Refresh the visibility of the side bar and dock panel.
156 */
157 refresh(): void;
158 /**
159 * Sets the size of the side panel.
160 *
161 * @param size the desired size (width) of the panel in pixels.
162 */
163 resize(size: number): void;
164 /**
165 * Compute the current width of the panel. This implementation assumes that the parent of
166 * the panel container is a `SplitPanel`.
167 */
168 protected getPanelSize(): number | undefined;
169 /**
170 * Determine the default size to apply when the panel is expanded for the first time.
171 */
172 protected getDefaultPanelSize(): number | undefined;
173 /**
174 * Modify the width of the panel. This implementation assumes that the parent of the panel
175 * container is a `SplitPanel`.
176 */
177 protected setPanelSize(size: number): Promise<void>;
178 protected readonly toDisposeOnCurrentTabChanged: DisposableCollection;
179 /**
180 * Handle a `currentChanged` signal from the sidebar. The side panel is refreshed so it displays
181 * the new selected widget.
182 */
183 protected onCurrentTabChanged(sender: SideTabBar, { currentTitle, currentIndex }: TabBar.ICurrentChangedArgs<Widget>): void;
184 /**
185 * Handle a `tabDetachRequested` signal from the sidebar. A drag is started so the widget can be
186 * moved to another application shell area.
187 */
188 protected onTabDetachRequested(sender: SideTabBar, { title, tab, clientX, clientY }: TabBar.ITabDetachRequestedArgs<Widget>): void;
189 protected onWidgetAdded(sender: DockPanel, widget: Widget): void;
190 protected onWidgetRemoved(sender: DockPanel, widget: Widget): void;
191 protected updateSashState(sidePanelElement: Panel | null, sidePanelCollapsed: boolean): void;
192}
193export declare namespace SidePanel {
194 /**
195 * Options that control the behavior of side panels.
196 */
197 interface Options {
198 /**
199 * When a widget is being dragged and the distance of the mouse cursor to the shell border
200 * is below this threshold, the respective side panel is expanded so the widget can be dropped
201 * into that panel. Set this to `-1` to disable expanding the side panel while dragging.
202 */
203 expandThreshold: number;
204 /**
205 * The duration in milliseconds of the animation shown when a side panel is expanded.
206 * Set this to `0` to disable expansion animation.
207 */
208 expandDuration: number;
209 /**
210 * The ratio of the available shell size to use as initial size for the side panel.
211 */
212 initialSizeRatio: number;
213 /**
214 * How large the panel should be when it's expanded and empty.
215 */
216 emptySize: number;
217 }
218 /**
219 * The options for adding a widget to a side panel.
220 */
221 interface WidgetOptions {
222 /**
223 * The rank order of the widget among its siblings.
224 */
225 rank?: number;
226 }
227 /**
228 * Data to save and load the layout of a side panel.
229 */
230 interface LayoutData {
231 type: 'sidepanel';
232 items?: WidgetItem[];
233 size?: number;
234 }
235 /**
236 * Data structure used to save and restore the side panel layout.
237 */
238 interface WidgetItem extends WidgetOptions {
239 /** Can be undefined in case the widget could not be restored. */
240 widget?: Widget;
241 expanded?: boolean;
242 pinned?: boolean;
243 }
244 interface State {
245 /**
246 * Indicates whether the panel is empty.
247 */
248 empty: boolean;
249 /**
250 * Indicates whether the panel is expanded, collapsed, or in a transition between the two.
251 */
252 expansion: ExpansionState;
253 /**
254 * A promise that is resolved when the currently pending side panel updates are done.
255 */
256 pendingUpdate: Promise<void>;
257 /**
258 * The index of the last tab that was selected. When the panel is expanded, it tries to restore
259 * the tab selection to the previous state.
260 */
261 lastActiveTabIndex?: number;
262 /**
263 * The width or height of the panel before it was collapsed. When the panel is expanded, it tries
264 * to restore its size to this value.
265 */
266 lastPanelSize?: number;
267 }
268 enum ExpansionState {
269 collapsed = "collapsed",
270 expanding = "expanding",
271 expanded = "expanded",
272 collapsing = "collapsing"
273 }
274}
275//# sourceMappingURL=side-panel-handler.d.ts.map
\No newline at end of file