Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add more detail to panel switcher interaction
Conrad Irwin4540f04dbe4e
diff --git a/crates/ui2/src/components/icon_button.rs b/crates/ui2/src/components/icon_button.rsindex 4408c51f621..1f7b86baddf 100644--- a/crates/ui2/src/components/icon_button.rs+++ b/crates/ui2/src/components/icon_button.rs@@ -1,5 +1,5 @@use crate::{h_stack, prelude::*, ClickHandler, Icon, IconElement};-use gpui::{prelude::*, AnyView, MouseButton};+use gpui::{prelude::*, Action, AnyView, MouseButton};use std::sync::Arc;struct IconButtonHandlers<V: 'static> {@@ -69,6 +69,10 @@ impl<V: 'static> IconButton<V> {self}+ pub fn action(self, action: Box<dyn Action>) -> Self {+ self.on_click(move |this, cx| cx.dispatch_action(action.boxed_clone()))+ }+fn render(mut self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {let icon_color = match (self.state, self.color) {(InteractionState::Disabled, _) => TextColor::Disabled,diff --git a/crates/workspace2/src/dock.rs b/crates/workspace2/src/dock.rsindex 8e7f08252c8..eec0ce309a4 100644--- a/crates/workspace2/src/dock.rs+++ b/crates/workspace2/src/dock.rs@@ -1,8 +1,8 @@use crate::{status_bar::StatusItemView, Axis, Workspace};use gpui::{div, px, Action, AnyView, AppContext, Component, Div, Entity, EntityId, EventEmitter,- FocusHandle, FocusableView, ParentComponent, Render, Styled, Subscription, View, ViewContext,- WeakView, WindowContext,+ FocusHandle, FocusableView, ParentComponent, Render, SharedString, Styled, Subscription, View,+ ViewContext, WeakView, WindowContext,};use schemars::JsonSchema;use serde::{Deserialize, Serialize};@@ -416,6 +416,14 @@ impl Dock {}}+ pub fn toggle_action(&self) -> Box<dyn Action> {+ match self.position {+ DockPosition::Left => crate::ToggleLeftDock.boxed_clone(),+ DockPosition::Bottom => crate::ToggleBottomDock.boxed_clone(),+ DockPosition::Right => crate::ToggleRightDock.boxed_clone(),+ }+ }+// pub fn render_placeholder(&self, cx: &WindowContext) -> AnyElement<Workspace> {// todo!()// if let Some(active_entry) = self.visible_entry() {@@ -664,13 +672,22 @@ impl Render for PanelButtons {.filter_map(|(i, panel)| {let icon = panel.panel.icon(cx)?;let name = panel.panel.persistent_name();- let action = panel.panel.toggle_action(cx);- let action2 = action.boxed_clone();- let mut button = IconButton::new(panel.panel.persistent_name(), icon)- .when(i == active_index, |el| el.state(InteractionState::Active))- .on_click(move |this, cx| cx.dispatch_action(action.boxed_clone()))- .tooltip(move |_, cx| Tooltip::for_action(name, &*action2, cx));+ let mut button: IconButton<Self> = if i == active_index && is_open {+ let action = dock.toggle_action();+ let tooltip: SharedString =+ format!("Close {} dock", dock.position.to_label()).into();+ IconButton::new(name, icon)+ .state(InteractionState::Active)+ .action(action.boxed_clone())+ .tooltip(move |_, cx| Tooltip::for_action(tooltip.clone(), &*action, cx))+ } else {+ let action = panel.panel.toggle_action(cx);++ IconButton::new(name, icon)+ .action(action.boxed_clone())+ .tooltip(move |_, cx| Tooltip::for_action(name, &*action, cx))+ };Some(button)});diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rsindex f28675661de..7282e6839ab 100644--- a/crates/workspace2/src/workspace2.rs+++ b/crates/workspace2/src/workspace2.rs@@ -3213,8 +3213,8 @@ impl Workspace {})}- fn actions(div: Div<Self>) -> Div<Self> {- div+ fn actions(&self, div: Div<Self>) -> Div<Self> {+ self.add_workspace_actions_listeners(div)// cx.add_async_action(Workspace::open);// cx.add_async_action(Workspace::follow_next_collaborator);// cx.add_async_action(Workspace::close);@@ -3263,15 +3263,15 @@ impl Workspace {.on_action(|this, e: &ToggleLeftDock, cx| {this.toggle_dock(DockPosition::Left, cx);})- // cx.add_action(|workspace: &mut Workspace, _: &ToggleRightDock, cx| {- // workspace.toggle_dock(DockPosition::Right, cx);- // });- // cx.add_action(|workspace: &mut Workspace, _: &ToggleBottomDock, cx| {- // workspace.toggle_dock(DockPosition::Bottom, cx);- // });- // cx.add_action(|workspace: &mut Workspace, _: &CloseAllDocks, cx| {- // workspace.close_all_docks(cx);- // });+ .on_action(|workspace: &mut Workspace, _: &ToggleRightDock, cx| {+ workspace.toggle_dock(DockPosition::Right, cx);+ })+ .on_action(|workspace: &mut Workspace, _: &ToggleBottomDock, cx| {+ workspace.toggle_dock(DockPosition::Bottom, cx);+ })+ .on_action(|workspace: &mut Workspace, _: &CloseAllDocks, cx| {+ workspace.close_all_docks(cx);+ })// cx.add_action(Workspace::activate_pane_at_index);// cx.add_action(|workspace: &mut Workspace, _: &ReopenClosedItem, cx| {// workspace.reopen_closed_item(cx).detach();@@ -3616,7 +3616,7 @@ impl Render for Workspace {context.add("Workspace");let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();- self.add_workspace_actions_listeners(div())+ self.actions(div()).key_context(context).relative().size_full()