Merge branch 'main' into search2
This commit is contained in:
+130
-55
@@ -8,7 +8,9 @@ use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use theme2::ActiveTheme;
|
||||
use ui::{h_stack, menu_handle, ContextMenu, IconButton, InteractionState, Tooltip};
|
||||
use ui::{
|
||||
h_stack, menu_handle, ContextMenu, IconButton, InteractionState, Label, ListEntry, Tooltip,
|
||||
};
|
||||
|
||||
pub enum PanelEvent {
|
||||
ChangePosition,
|
||||
@@ -40,7 +42,7 @@ pub trait Panel: FocusableView + EventEmitter<PanelEvent> {
|
||||
}
|
||||
|
||||
pub trait PanelHandle: Send + Sync {
|
||||
fn id(&self) -> EntityId;
|
||||
fn entity_id(&self) -> EntityId;
|
||||
fn persistent_name(&self) -> &'static str;
|
||||
fn position(&self, cx: &WindowContext) -> DockPosition;
|
||||
fn position_is_valid(&self, position: DockPosition, cx: &WindowContext) -> bool;
|
||||
@@ -62,8 +64,8 @@ impl<T> PanelHandle for View<T>
|
||||
where
|
||||
T: Panel,
|
||||
{
|
||||
fn id(&self) -> EntityId {
|
||||
self.entity_id()
|
||||
fn entity_id(&self) -> EntityId {
|
||||
Entity::entity_id(self)
|
||||
}
|
||||
|
||||
fn persistent_name(&self) -> &'static str {
|
||||
@@ -254,20 +256,19 @@ impl Dock {
|
||||
}
|
||||
}
|
||||
|
||||
// todo!()
|
||||
// pub fn set_panel_zoomed(&mut self, panel: &AnyView, zoomed: bool, cx: &mut ViewContext<Self>) {
|
||||
// for entry in &mut self.panel_entries {
|
||||
// if entry.panel.as_any() == panel {
|
||||
// if zoomed != entry.panel.is_zoomed(cx) {
|
||||
// entry.panel.set_zoomed(zoomed, cx);
|
||||
// }
|
||||
// } else if entry.panel.is_zoomed(cx) {
|
||||
// entry.panel.set_zoomed(false, cx);
|
||||
// }
|
||||
// }
|
||||
pub fn set_panel_zoomed(&mut self, panel: &AnyView, zoomed: bool, cx: &mut ViewContext<Self>) {
|
||||
for entry in &mut self.panel_entries {
|
||||
if entry.panel.entity_id() == panel.entity_id() {
|
||||
if zoomed != entry.panel.is_zoomed(cx) {
|
||||
entry.panel.set_zoomed(zoomed, cx);
|
||||
}
|
||||
} else if entry.panel.is_zoomed(cx) {
|
||||
entry.panel.set_zoomed(false, cx);
|
||||
}
|
||||
}
|
||||
|
||||
// cx.notify();
|
||||
// }
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn zoom_out(&mut self, cx: &mut ViewContext<Self>) {
|
||||
for entry in &mut self.panel_entries {
|
||||
@@ -277,42 +278,91 @@ impl Dock {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn add_panel<T: Panel>(&mut self, panel: View<T>, cx: &mut ViewContext<Self>) {
|
||||
pub(crate) fn add_panel<T: Panel>(
|
||||
&mut self,
|
||||
panel: View<T>,
|
||||
workspace: WeakView<Workspace>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
let subscriptions = [
|
||||
cx.observe(&panel, |_, _, cx| cx.notify()),
|
||||
cx.subscribe(&panel, |this, panel, event, cx| {
|
||||
match event {
|
||||
PanelEvent::ChangePosition => {
|
||||
//todo!()
|
||||
// see: Workspace::add_panel_with_extra_event_handler
|
||||
}
|
||||
PanelEvent::ZoomIn => {
|
||||
//todo!()
|
||||
// see: Workspace::add_panel_with_extra_event_handler
|
||||
}
|
||||
PanelEvent::ZoomOut => {
|
||||
// todo!()
|
||||
// // see: Workspace::add_panel_with_extra_event_handler
|
||||
}
|
||||
PanelEvent::Activate => {
|
||||
if let Some(ix) = this
|
||||
.panel_entries
|
||||
.iter()
|
||||
.position(|entry| entry.panel.id() == panel.id())
|
||||
{
|
||||
this.set_open(true, cx);
|
||||
this.activate_panel(ix, cx);
|
||||
//` todo!()
|
||||
// cx.focus(&panel);
|
||||
cx.subscribe(&panel, move |this, panel, event, cx| match event {
|
||||
PanelEvent::ChangePosition => {
|
||||
let new_position = panel.read(cx).position(cx);
|
||||
|
||||
let Ok(new_dock) = workspace.update(cx, |workspace, cx| {
|
||||
if panel.is_zoomed(cx) {
|
||||
workspace.zoomed_position = Some(new_position);
|
||||
}
|
||||
}
|
||||
PanelEvent::Close => {
|
||||
if this.visible_panel().map_or(false, |p| p.id() == panel.id()) {
|
||||
this.set_open(false, cx);
|
||||
match new_position {
|
||||
DockPosition::Left => &workspace.left_dock,
|
||||
DockPosition::Bottom => &workspace.bottom_dock,
|
||||
DockPosition::Right => &workspace.right_dock,
|
||||
}
|
||||
}
|
||||
PanelEvent::Focus => todo!(),
|
||||
.clone()
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let was_visible = this.is_open()
|
||||
&& this.visible_panel().map_or(false, |active_panel| {
|
||||
active_panel.entity_id() == Entity::entity_id(&panel)
|
||||
});
|
||||
|
||||
this.remove_panel(&panel, cx);
|
||||
|
||||
new_dock.update(cx, |new_dock, cx| {
|
||||
new_dock.add_panel(panel.clone(), workspace.clone(), cx);
|
||||
if was_visible {
|
||||
new_dock.set_open(true, cx);
|
||||
new_dock.activate_panel(this.panels_len() - 1, cx);
|
||||
}
|
||||
});
|
||||
}
|
||||
PanelEvent::ZoomIn => {
|
||||
this.set_panel_zoomed(&panel.to_any(), true, cx);
|
||||
if !panel.has_focus(cx) {
|
||||
cx.focus_view(&panel);
|
||||
}
|
||||
workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
workspace.zoomed = Some(panel.downgrade().into());
|
||||
workspace.zoomed_position = Some(panel.read(cx).position(cx));
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
PanelEvent::ZoomOut => {
|
||||
this.set_panel_zoomed(&panel.to_any(), false, cx);
|
||||
workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
if workspace.zoomed_position == Some(this.position) {
|
||||
workspace.zoomed = None;
|
||||
workspace.zoomed_position = None;
|
||||
}
|
||||
cx.notify();
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
PanelEvent::Activate => {
|
||||
if let Some(ix) = this
|
||||
.panel_entries
|
||||
.iter()
|
||||
.position(|entry| entry.panel.entity_id() == Entity::entity_id(&panel))
|
||||
{
|
||||
this.set_open(true, cx);
|
||||
this.activate_panel(ix, cx);
|
||||
cx.focus_view(&panel);
|
||||
}
|
||||
}
|
||||
PanelEvent::Close => {
|
||||
if this
|
||||
.visible_panel()
|
||||
.map_or(false, |p| p.entity_id() == Entity::entity_id(&panel))
|
||||
{
|
||||
this.set_open(false, cx);
|
||||
}
|
||||
}
|
||||
PanelEvent::Focus => todo!(),
|
||||
}),
|
||||
];
|
||||
|
||||
@@ -335,7 +385,7 @@ impl Dock {
|
||||
if let Some(panel_ix) = self
|
||||
.panel_entries
|
||||
.iter()
|
||||
.position(|entry| entry.panel.id() == panel.id())
|
||||
.position(|entry| entry.panel.entity_id() == Entity::entity_id(panel))
|
||||
{
|
||||
if panel_ix == self.active_panel_index {
|
||||
self.active_panel_index = 0;
|
||||
@@ -396,7 +446,7 @@ impl Dock {
|
||||
pub fn panel_size(&self, panel: &dyn PanelHandle, cx: &WindowContext) -> Option<f32> {
|
||||
self.panel_entries
|
||||
.iter()
|
||||
.find(|entry| entry.panel.id() == panel.id())
|
||||
.find(|entry| entry.panel.entity_id() == panel.entity_id())
|
||||
.map(|entry| entry.panel.size(cx))
|
||||
}
|
||||
|
||||
@@ -620,6 +670,7 @@ impl Render for PanelButtons {
|
||||
let dock = self.dock.read(cx);
|
||||
let active_index = dock.active_panel_index;
|
||||
let is_open = dock.is_open;
|
||||
let dock_position = dock.position;
|
||||
|
||||
let (menu_anchor, menu_attach) = match dock.position {
|
||||
DockPosition::Left => (AnchorCorner::BottomLeft, AnchorCorner::TopLeft),
|
||||
@@ -632,9 +683,10 @@ impl Render for PanelButtons {
|
||||
.panel_entries
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(i, panel)| {
|
||||
let icon = panel.panel.icon(cx)?;
|
||||
let name = panel.panel.persistent_name();
|
||||
.filter_map(|(i, entry)| {
|
||||
let icon = entry.panel.icon(cx)?;
|
||||
let name = entry.panel.persistent_name();
|
||||
let panel = entry.panel.clone();
|
||||
|
||||
let mut button: IconButton<Self> = if i == active_index && is_open {
|
||||
let action = dock.toggle_action();
|
||||
@@ -645,7 +697,7 @@ impl Render for PanelButtons {
|
||||
.action(action.boxed_clone())
|
||||
.tooltip(move |_, cx| Tooltip::for_action(tooltip.clone(), &*action, cx))
|
||||
} else {
|
||||
let action = panel.panel.toggle_action(cx);
|
||||
let action = entry.panel.toggle_action(cx);
|
||||
|
||||
IconButton::new(name, icon)
|
||||
.action(action.boxed_clone())
|
||||
@@ -656,7 +708,30 @@ impl Render for PanelButtons {
|
||||
menu_handle()
|
||||
.id(name)
|
||||
.menu(move |_, cx| {
|
||||
cx.build_view(|cx| ContextMenu::new(cx).header("SECTION"))
|
||||
const POSITIONS: [DockPosition; 3] = [
|
||||
DockPosition::Left,
|
||||
DockPosition::Right,
|
||||
DockPosition::Bottom,
|
||||
];
|
||||
ContextMenu::build(cx, |mut menu, cx| {
|
||||
for position in POSITIONS {
|
||||
if position != dock_position
|
||||
&& panel.position_is_valid(position, cx)
|
||||
{
|
||||
let panel = panel.clone();
|
||||
menu = menu.entry(
|
||||
ListEntry::new(Label::new(format!(
|
||||
"Dock {}",
|
||||
position.to_label()
|
||||
))),
|
||||
move |_, cx| {
|
||||
panel.set_position(position, cx);
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
menu
|
||||
})
|
||||
})
|
||||
.anchor(menu_anchor)
|
||||
.attach(menu_attach)
|
||||
|
||||
@@ -15,6 +15,8 @@ pub enum NotificationEvent {
|
||||
|
||||
pub trait Notification: EventEmitter<NotificationEvent> + Render {}
|
||||
|
||||
impl<V: EventEmitter<NotificationEvent> + Render> Notification for V {}
|
||||
|
||||
pub trait NotificationHandle: Send {
|
||||
fn id(&self) -> EntityId;
|
||||
fn to_any(&self) -> AnyView;
|
||||
@@ -164,7 +166,7 @@ impl Workspace {
|
||||
}
|
||||
|
||||
pub mod simple_message_notification {
|
||||
use super::{Notification, NotificationEvent};
|
||||
use super::NotificationEvent;
|
||||
use gpui::{AnyElement, AppContext, Div, EventEmitter, Render, TextStyle, ViewContext};
|
||||
use serde::Deserialize;
|
||||
use std::{borrow::Cow, sync::Arc};
|
||||
@@ -359,7 +361,6 @@ pub mod simple_message_notification {
|
||||
// }
|
||||
|
||||
impl EventEmitter<NotificationEvent> for MessageNotification {}
|
||||
impl Notification for MessageNotification {}
|
||||
}
|
||||
|
||||
pub trait NotifyResultExt {
|
||||
|
||||
@@ -24,6 +24,7 @@ use std::{
|
||||
Arc,
|
||||
},
|
||||
};
|
||||
|
||||
use ui::v_stack;
|
||||
use ui::{prelude::*, Icon, IconButton, IconElement, TextColor, Tooltip};
|
||||
use util::truncate_and_remove_front;
|
||||
@@ -1480,15 +1481,10 @@ impl Pane {
|
||||
// Right Side
|
||||
.child(
|
||||
div()
|
||||
// We only use absolute here since we don't
|
||||
// have opacity or `hidden()` yet
|
||||
.absolute()
|
||||
.neg_top_7()
|
||||
.px_1()
|
||||
.flex()
|
||||
.flex_none()
|
||||
.gap_2()
|
||||
.group_hover("tab_bar", |this| this.top_0())
|
||||
// Nav Buttons
|
||||
.child(
|
||||
div()
|
||||
@@ -1933,7 +1929,7 @@ impl Render for Pane {
|
||||
.child(self.render_tab_bar(cx))
|
||||
.child(self.toolbar.clone())
|
||||
.child(if let Some(item) = self.active_item() {
|
||||
div().flex_1().child(item.to_any())
|
||||
div().flex().flex_1().child(item.to_any())
|
||||
} else {
|
||||
// todo!()
|
||||
div().child("Empty Pane")
|
||||
|
||||
@@ -56,7 +56,7 @@ impl StatusBar {
|
||||
fn render_left_tools(&self, cx: &mut ViewContext<Self>) -> impl Component<Self> {
|
||||
h_stack()
|
||||
.items_center()
|
||||
.gap_1()
|
||||
.gap_2()
|
||||
.children(self.left_items.iter().map(|item| item.to_any()))
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,6 @@ use std::{
|
||||
};
|
||||
use theme2::{ActiveTheme, ThemeSettings};
|
||||
pub use toolbar::{ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView};
|
||||
|
||||
pub use ui;
|
||||
use util::ResultExt;
|
||||
use uuid::Uuid;
|
||||
@@ -814,7 +813,9 @@ impl Workspace {
|
||||
DockPosition::Right => &self.right_dock,
|
||||
};
|
||||
|
||||
dock.update(cx, |dock, cx| dock.add_panel(panel, cx));
|
||||
dock.update(cx, |dock, cx| {
|
||||
dock.add_panel(panel, self.weak_self.clone(), cx)
|
||||
});
|
||||
}
|
||||
|
||||
pub fn status_bar(&self) -> &View<StatusBar> {
|
||||
@@ -3665,7 +3666,7 @@ impl Render for Workspace {
|
||||
&self.app_state,
|
||||
cx,
|
||||
))
|
||||
.child(div().flex().flex_1().child(self.bottom_dock.clone())),
|
||||
.child(self.bottom_dock.clone()),
|
||||
)
|
||||
// Right Dock
|
||||
.child(
|
||||
@@ -3678,19 +3679,6 @@ impl Render for Workspace {
|
||||
),
|
||||
)
|
||||
.child(self.status_bar.clone())
|
||||
.z_index(8)
|
||||
// Debug
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.z_index(9)
|
||||
.absolute()
|
||||
.top_20()
|
||||
.left_1_4()
|
||||
.w_40()
|
||||
.gap_2(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user