use std::{collections::HashMap, sync::Arc}; use crate::{button::Button, popup_menu::PopupMenu}; use gpui::{ AnyElement, AnyView, AppContext, EventEmitter, FocusHandle, FocusableView, Global, Hsla, IntoElement, SharedString, View, ViewContext, WeakView, WindowContext, }; use rust_i18n::t; use super::{DockArea, PanelInfo, PanelState}; pub enum PanelEvent { ZoomIn, ZoomOut, LayoutChanged, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum PanelStyle { /// Display the TabBar when there are multiple tabs, otherwise display the simple title. Default, /// Always display the tab bar. TabBar, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct TitleStyle { pub background: Hsla, pub foreground: Hsla, } /// The Panel trait used to define the panel. #[allow(unused_variables)] pub trait Panel: EventEmitter + FocusableView { /// The name of the panel used to serialize, deserialize and identify the panel. /// /// This is used to identify the panel when deserializing the panel. /// Once you have defined a panel name, this must not be changed. fn panel_name(&self) -> &'static str; /// The title of the panel fn title(&self, cx: &WindowContext) -> AnyElement { SharedString::from(t!("Dock.Unnamed")).into_any_element() } /// The theme of the panel title, default is `None`. fn title_style(&self, cx: &WindowContext) -> Option { None } /// Whether the panel can be closed, default is `true`. fn closeable(&self, cx: &WindowContext) -> bool { true } /// Return true if the panel is zoomable, default is `false`. fn zoomable(&self, cx: &WindowContext) -> bool { true } /// Set active state of the panel. /// /// This method will be called when the panel is active or inactive. /// /// The last_active_panel and current_active_panel will be touched when the panel is active. #[allow(unused_variables)] fn set_active(&self, active: bool, cx: &ViewContext) {} /// Set zoomed state of the panel. /// /// This method will be called when the panel is zoomed or unzoomed. /// /// Only current Panel will touch this method. fn set_zoomed(&self, zoomed: bool, cx: &ViewContext) {} /// The addition popup menu of the panel, default is `None`. fn popup_menu(&self, this: PopupMenu, cx: &WindowContext) -> PopupMenu { this } /// The addition toolbar buttons of the panel used to show in the right of the title bar, default is `None`. fn toolbar_buttons(&self, cx: &WindowContext) -> Vec