From d1bff043cd8ace0158be363b852d74144e32a806 Mon Sep 17 00:00:00 2001 From: cameron Date: Tue, 7 Apr 2026 23:02:12 +0100 Subject: [PATCH] move actions from sidebar trait to multiworkspace --- crates/sidebar/src/sidebar.rs | 21 ---- crates/workspace/src/multi_workspace.rs | 132 +++++++----------------- crates/workspace/src/workspace.rs | 5 +- 3 files changed, 42 insertions(+), 116 deletions(-) diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rs index 2a751f65fa085403635abfd23e878a5984d7b1af..a462196435f8fdd469a82d1f3a715c5b5bdd4d3c 100644 --- a/crates/sidebar/src/sidebar.rs +++ b/crates/sidebar/src/sidebar.rs @@ -3823,27 +3823,6 @@ impl WorkspaceSidebar for Sidebar { cx.notify(); } - fn toggle_thread_switcher( - &mut self, - select_last: bool, - window: &mut Window, - cx: &mut Context, - ) { - self.toggle_thread_switcher_impl(select_last, window, cx); - } - - fn cycle_project(&mut self, forward: bool, window: &mut Window, cx: &mut Context) { - self.cycle_project_impl(forward, window, cx); - } - - fn cycle_thread(&mut self, forward: bool, window: &mut Window, cx: &mut Context) { - self.cycle_thread_impl(forward, window, cx); - } - - fn move_workspace_to_new_window(&mut self, window: &mut Window, cx: &mut Context) { - self.on_move_workspace_to_new_window(&MoveWorkspaceToNewWindow, window, cx); - } - fn serialized_state(&self, _cx: &App) -> Option { let serialized = SerializedSidebar { width: Some(f32::from(self.width)), diff --git a/crates/workspace/src/multi_workspace.rs b/crates/workspace/src/multi_workspace.rs index 28be17faf554948f0e9c37998392636656b58f5c..96b153be05b5668f527ce7ab3269cdcbcf1c72de 100644 --- a/crates/workspace/src/multi_workspace.rs +++ b/crates/workspace/src/multi_workspace.rs @@ -2,9 +2,9 @@ use anyhow::Result; use feature_flags::{AgentV2FeatureFlag, FeatureFlagAppExt}; use gpui::PathPromptOptions; use gpui::{ - AnyView, App, Context, DragMoveEvent, Entity, EntityId, EventEmitter, FocusHandle, Focusable, - ManagedView, MouseButton, Pixels, Render, Subscription, Task, Tiling, Window, WindowId, - actions, deferred, px, + Action as _, AnyView, App, Context, DragMoveEvent, Entity, EntityId, EventEmitter, FocusHandle, + Focusable, ManagedView, MouseButton, Pixels, Render, Subscription, Task, Tiling, Window, + WindowId, actions, deferred, px, }; use project::{DirectoryLister, DisableAiSettings, Project, ProjectGroupKey}; use settings::Settings; @@ -120,23 +120,6 @@ pub trait Sidebar: Focusable + Render + EventEmitter + Sized { } /// Makes focus reset back to the search editor upon toggling the sidebar from outside fn prepare_for_focus(&mut self, _window: &mut Window, _cx: &mut Context) {} - /// Opens or cycles the thread switcher popup. - fn toggle_thread_switcher( - &mut self, - _select_last: bool, - _window: &mut Window, - _cx: &mut Context, - ) { - } - - /// Activates the next or previous project group. - fn cycle_project(&mut self, _forward: bool, _window: &mut Window, _cx: &mut Context) {} - - /// Activates the next or previous thread in sidebar order. - fn cycle_thread(&mut self, _forward: bool, _window: &mut Window, _cx: &mut Context) {} - - /// Moves the active workspace's project group to a new window. - fn move_workspace_to_new_window(&mut self, _window: &mut Window, _cx: &mut Context) {} /// Return an opaque JSON blob of sidebar-specific state to persist. fn serialized_state(&self, _cx: &App) -> Option { @@ -162,11 +145,6 @@ pub trait SidebarHandle: 'static + Send + Sync { fn has_notifications(&self, cx: &App) -> bool; fn to_any(&self) -> AnyView; fn entity_id(&self) -> EntityId; - fn toggle_thread_switcher(&self, select_last: bool, window: &mut Window, cx: &mut App); - fn cycle_project(&self, forward: bool, window: &mut Window, cx: &mut App); - fn cycle_thread(&self, forward: bool, window: &mut Window, cx: &mut App); - fn move_workspace_to_new_window(&self, window: &mut Window, cx: &mut App); - fn is_threads_list_view_active(&self, cx: &App) -> bool; fn side(&self, cx: &App) -> SidebarSide; @@ -217,42 +195,6 @@ impl SidebarHandle for Entity { Entity::entity_id(self) } - fn toggle_thread_switcher(&self, select_last: bool, window: &mut Window, cx: &mut App) { - let entity = self.clone(); - window.defer(cx, move |window, cx| { - entity.update(cx, |this, cx| { - this.toggle_thread_switcher(select_last, window, cx); - }); - }); - } - - fn cycle_project(&self, forward: bool, window: &mut Window, cx: &mut App) { - let entity = self.clone(); - window.defer(cx, move |window, cx| { - entity.update(cx, |this, cx| { - this.cycle_project(forward, window, cx); - }); - }); - } - - fn cycle_thread(&self, forward: bool, window: &mut Window, cx: &mut App) { - let entity = self.clone(); - window.defer(cx, move |window, cx| { - entity.update(cx, |this, cx| { - this.cycle_thread(forward, window, cx); - }); - }); - } - - fn move_workspace_to_new_window(&self, window: &mut Window, cx: &mut App) { - let entity = self.clone(); - window.defer(cx, move |window, cx| { - entity.update(cx, |this, cx| { - this.move_workspace_to_new_window(window, cx); - }); - }); - } - fn is_threads_list_view_active(&self, cx: &App) -> bool { self.read(cx).is_threads_list_view_active() } @@ -492,6 +434,20 @@ impl MultiWorkspace { } } + fn dispatch_to_sidebar( + &self, + action: Box, + window: &mut Window, + cx: &mut App, + ) { + if let Some(sidebar) = &self.sidebar { + let focus_handle = sidebar.focus_handle(cx); + window.defer(cx, move |window, cx| { + focus_handle.dispatch_action(&*action, window, cx); + }); + } + } + pub fn open_sidebar(&mut self, cx: &mut Context) { self.sidebar_open = true; if let ActiveWorkspace::Transient(workspace) = &self.active_workspace { @@ -1502,40 +1458,32 @@ impl Render for MultiWorkspace { )) .on_action(cx.listener( |this: &mut Self, action: &ToggleThreadSwitcher, window, cx| { - if let Some(sidebar) = &this.sidebar { - sidebar.toggle_thread_switcher(action.select_last, window, cx); - } + this.dispatch_to_sidebar(action.boxed_clone(), window, cx); }, )) - .on_action(cx.listener(|this: &mut Self, _: &NextProject, window, cx| { - if let Some(sidebar) = &this.sidebar { - sidebar.cycle_project(true, window, cx); - } - })) - .on_action( - cx.listener(|this: &mut Self, _: &PreviousProject, window, cx| { - if let Some(sidebar) = &this.sidebar { - sidebar.cycle_project(false, window, cx); - } - }), - ) - .on_action(cx.listener(|this: &mut Self, _: &NextThread, window, cx| { - if let Some(sidebar) = &this.sidebar { - sidebar.cycle_thread(true, window, cx); - } - })) - .on_action( - cx.listener(|this: &mut Self, _: &PreviousThread, window, cx| { - if let Some(sidebar) = &this.sidebar { - sidebar.cycle_thread(false, window, cx); - } - }), - ) .on_action(cx.listener( - |this: &mut Self, _: &MoveWorkspaceToNewWindow, window, cx| { - if let Some(sidebar) = &this.sidebar { - sidebar.move_workspace_to_new_window(window, cx); - } + |this: &mut Self, action: &NextProject, window, cx| { + this.dispatch_to_sidebar(action.boxed_clone(), window, cx); + }, + )) + .on_action(cx.listener( + |this: &mut Self, action: &PreviousProject, window, cx| { + this.dispatch_to_sidebar(action.boxed_clone(), window, cx); + }, + )) + .on_action(cx.listener( + |this: &mut Self, action: &NextThread, window, cx| { + this.dispatch_to_sidebar(action.boxed_clone(), window, cx); + }, + )) + .on_action(cx.listener( + |this: &mut Self, action: &PreviousThread, window, cx| { + this.dispatch_to_sidebar(action.boxed_clone(), window, cx); + }, + )) + .on_action(cx.listener( + |this: &mut Self, action: &MoveWorkspaceToNewWindow, window, cx| { + this.dispatch_to_sidebar(action.boxed_clone(), window, cx); }, )) }) diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index a5d0048ad89f500d78a1376b2c4700708718f6d0..c46691fd00cc975370d281ac272373487bb2efeb 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -33,9 +33,8 @@ pub use dock::Panel; pub use multi_workspace::{ CloseWorkspaceSidebar, DraggedSidebar, FocusWorkspaceSidebar, MoveWorkspaceToNewWindow, MultiWorkspace, MultiWorkspaceEvent, NewThread, NextProject, NextThread, PreviousProject, - PreviousThread, ShowFewerThreads, ShowMoreThreads, Sidebar, SidebarEvent, - SidebarHandle, SidebarRenderState, SidebarSide, ToggleWorkspaceSidebar, - sidebar_side_context_menu, + PreviousThread, ShowFewerThreads, ShowMoreThreads, Sidebar, SidebarEvent, SidebarHandle, + SidebarRenderState, SidebarSide, ToggleWorkspaceSidebar, sidebar_side_context_menu, }; pub use path_list::{PathList, SerializedPathList}; pub use toast_layer::{ToastAction, ToastLayer, ToastView};