feat: add tiles from gpui-components

This commit is contained in:
2024-12-18 07:54:40 +07:00
parent 0682612d42
commit 407db7a7d5
13 changed files with 1018 additions and 182 deletions

View File

@@ -4,7 +4,7 @@ use gpui::{
};
use std::{collections::HashMap, sync::Arc};
use super::{DockArea, DockItemInfo, DockItemState};
use super::{DockArea, PanelInfo, PanelState};
use crate::{button::Button, popup_menu::PopupMenu};
pub enum PanelEvent {
@@ -36,7 +36,7 @@ pub trait Panel: EventEmitter<PanelEvent> + FocusableView {
/// The title of the panel
fn title(&self, _cx: &WindowContext) -> AnyElement {
SharedString::from("Unnamed").into_any_element()
SharedString::from("Untitled").into_any_element()
}
/// The theme of the panel title, default is `None`.
@@ -65,13 +65,13 @@ pub trait Panel: EventEmitter<PanelEvent> + FocusableView {
}
/// Dump the panel, used to serialize the panel.
fn dump(&self, _cx: &AppContext) -> DockItemState {
DockItemState::new(self)
fn dump(&self, _cx: &AppContext) -> PanelState {
PanelState::new(self)
}
}
pub trait PanelView: 'static + Send + Sync {
fn panel_name(&self, _cx: &WindowContext) -> &'static str;
fn panel_name(&self, _cx: &AppContext) -> &'static str;
fn title(&self, _cx: &WindowContext) -> AnyElement;
fn title_style(&self, _cx: &WindowContext) -> Option<TitleStyle>;
fn closeable(&self, cx: &WindowContext) -> bool;
@@ -80,11 +80,11 @@ pub trait PanelView: 'static + Send + Sync {
fn toolbar_buttons(&self, cx: &WindowContext) -> Vec<Button>;
fn view(&self) -> AnyView;
fn focus_handle(&self, cx: &AppContext) -> FocusHandle;
fn dump(&self, cx: &AppContext) -> DockItemState;
fn dump(&self, cx: &AppContext) -> PanelState;
}
impl<T: Panel> PanelView for View<T> {
fn panel_name(&self, cx: &WindowContext) -> &'static str {
fn panel_name(&self, cx: &AppContext) -> &'static str {
self.read(cx).panel_name()
}
@@ -120,7 +120,7 @@ impl<T: Panel> PanelView for View<T> {
self.read(cx).focus_handle(cx)
}
fn dump(&self, cx: &AppContext) -> DockItemState {
fn dump(&self, cx: &AppContext) -> PanelState {
self.read(cx).dump(cx)
}
}
@@ -143,20 +143,20 @@ impl PartialEq for dyn PanelView {
}
}
type PanelRegistryItem = HashMap<
type Items = HashMap<
String,
Arc<
dyn Fn(
WeakView<DockArea>,
&DockItemState,
&DockItemInfo,
&PanelState,
&PanelInfo,
&mut WindowContext,
) -> Box<dyn PanelView>,
>,
>;
pub struct PanelRegistry {
pub(super) items: PanelRegistryItem,
pub(super) items: Items,
}
impl PanelRegistry {
@@ -178,12 +178,7 @@ impl Global for PanelRegistry {}
/// Register the Panel init by panel_name to global registry.
pub fn register_panel<F>(cx: &mut AppContext, panel_name: &str, deserialize: F)
where
F: Fn(
WeakView<DockArea>,
&DockItemState,
&DockItemInfo,
&mut WindowContext,
) -> Box<dyn PanelView>
F: Fn(WeakView<DockArea>, &PanelState, &PanelInfo, &mut WindowContext) -> Box<dyn PanelView>
+ 'static,
{
if cx.try_global::<PanelRegistry>().is_none() {