Move agent-mode toggling logic to the zed crate

Max Brunsfeld , cameron , and Eric Holk created

Co-authored-by: cameron <cameron.studdstreet@gmail.com>
Co-authored-by: Eric Holk <eric@zed.dev>

Change summary

crates/workspace/src/multi_workspace.rs | 10 ----------
crates/zed/src/zed.rs                   | 27 +++++++++++++++++++++++++++
2 files changed, 27 insertions(+), 10 deletions(-)

Detailed changes

crates/workspace/src/multi_workspace.rs 🔗

@@ -800,16 +800,6 @@ impl Render for MultiWorkspace {
                         this.activate_previous_workspace(window, cx);
                     },
                 ))
-                .on_action(cx.listener(
-                    |this: &mut Self, _: &zed_actions::agent::ToggleAgentMode, window, cx| {
-                        if this.is_singleton {
-                            this.set_singleton(false, window, cx);
-                            this.open_sidebar(cx);
-                        } else {
-                            this.set_singleton(true, window, cx);
-                        }
-                    },
-                ))
                 .when(self.multi_workspace_enabled(cx), |this| {
                     this.on_action(cx.listener(
                         |this: &mut Self, _: &ToggleWorkspaceSidebar, window, cx| {

crates/zed/src/zed.rs 🔗

@@ -285,9 +285,36 @@ pub fn init(cx: &mut App) {
         with_active_or_new_workspace(cx, |workspace, window, cx| {
             about(workspace, window, cx);
         });
+    })
+    .on_action(|_: &zed_actions::agent::ToggleAgentMode, cx| {
+        let Some(window) = cx.active_window() else {
+            return;
+        };
+        let Some(handle) = window.downcast::<MultiWorkspace>() else {
+            return;
+        };
+        handle
+            .update(cx, |multi_workspace, window, cx| {
+                toggle_agent_mode(multi_workspace, window, cx);
+            })
+            .log_err();
     });
 }
 
+fn toggle_agent_mode(
+    multi_workspace: &mut MultiWorkspace,
+    window: &mut Window,
+    cx: &mut Context<'_, MultiWorkspace>,
+) {
+    let is_singleton = multi_workspace.is_singleton();
+    if is_singleton {
+        multi_workspace.set_singleton(false, window, cx);
+        multi_workspace.open_sidebar(cx);
+    } else {
+        multi_workspace.set_singleton(true, window, cx);
+    }
+}
+
 fn bind_on_window_closed(cx: &mut App) -> Option<gpui::Subscription> {
     #[cfg(target_os = "macos")]
     {