@@ -573,6 +573,7 @@ impl AgentPanel {
panel.width = serialized_panel.width.map(|w| w.round());
if let Some(selected_agent) = serialized_panel.selected_agent {
panel.selected_agent = selected_agent;
+ panel.new_agent_thread(selected_agent, window, cx);
}
cx.notify();
});
@@ -1631,16 +1632,53 @@ impl AgentPanel {
menu
}
- pub fn set_selected_agent(&mut self, agent: AgentType, cx: &mut Context<Self>) {
+ pub fn set_selected_agent(
+ &mut self,
+ agent: AgentType,
+ window: &mut Window,
+ cx: &mut Context<Self>,
+ ) {
if self.selected_agent != agent {
self.selected_agent = agent;
self.serialize(cx);
+ self.new_agent_thread(agent, window, cx);
}
}
pub fn selected_agent(&self) -> AgentType {
self.selected_agent
}
+
+ pub fn new_agent_thread(
+ &mut self,
+ agent: AgentType,
+ window: &mut Window,
+ cx: &mut Context<Self>,
+ ) {
+ match agent {
+ AgentType::Zed => {
+ window.dispatch_action(
+ NewThread {
+ from_thread_id: None,
+ }
+ .boxed_clone(),
+ cx,
+ );
+ }
+ AgentType::TextThread => {
+ window.dispatch_action(NewTextThread.boxed_clone(), cx);
+ }
+ AgentType::NativeAgent => {
+ self.new_external_thread(Some(crate::ExternalAgent::NativeAgent), window, cx)
+ }
+ AgentType::Gemini => {
+ self.new_external_thread(Some(crate::ExternalAgent::Gemini), window, cx)
+ }
+ AgentType::ClaudeCode => {
+ self.new_external_thread(Some(crate::ExternalAgent::ClaudeCode), window, cx)
+ }
+ }
+ }
}
impl Focusable for AgentPanel {
@@ -2221,16 +2259,13 @@ impl AgentPanel {
panel.update(cx, |panel, cx| {
panel.set_selected_agent(
AgentType::Zed,
+ window,
cx,
);
});
}
});
}
- window.dispatch_action(
- NewThread::default().boxed_clone(),
- cx,
- );
}
}),
)
@@ -2250,13 +2285,13 @@ impl AgentPanel {
panel.update(cx, |panel, cx| {
panel.set_selected_agent(
AgentType::TextThread,
+ window,
cx,
);
});
}
});
}
- window.dispatch_action(NewTextThread.boxed_clone(), cx);
}
}),
)
@@ -2275,19 +2310,13 @@ impl AgentPanel {
panel.update(cx, |panel, cx| {
panel.set_selected_agent(
AgentType::NativeAgent,
+ window,
cx,
);
});
}
});
}
- window.dispatch_action(
- NewExternalAgentThread {
- agent: Some(crate::ExternalAgent::NativeAgent),
- }
- .boxed_clone(),
- cx,
- );
}
}),
)
@@ -2308,19 +2337,13 @@ impl AgentPanel {
panel.update(cx, |panel, cx| {
panel.set_selected_agent(
AgentType::Gemini,
+ window,
cx,
);
});
}
});
}
- window.dispatch_action(
- NewExternalAgentThread {
- agent: Some(crate::ExternalAgent::Gemini),
- }
- .boxed_clone(),
- cx,
- );
}
}),
)
@@ -2339,19 +2362,13 @@ impl AgentPanel {
panel.update(cx, |panel, cx| {
panel.set_selected_agent(
AgentType::ClaudeCode,
+ window,
cx,
);
});
}
});
}
- window.dispatch_action(
- NewExternalAgentThread {
- agent: Some(crate::ExternalAgent::ClaudeCode),
- }
- .boxed_clone(),
- cx,
- );
}
}),
);
@@ -146,7 +146,7 @@ pub struct NewExternalAgentThread {
agent: Option<ExternalAgent>,
}
-#[derive(Default, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema)]
+#[derive(Default, Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
enum ExternalAgent {
#[default]