Detailed changes
@@ -10,6 +10,7 @@ use itertools::Itertools;
use paths::contexts_dir;
use serde::{Deserialize, Serialize};
use std::{collections::VecDeque, path::Path, sync::Arc, time::Duration};
+use ui::ElementId;
use util::ResultExt as _;
const MAX_RECENTLY_OPENED_ENTRIES: usize = 6;
@@ -68,6 +69,15 @@ pub enum HistoryEntryId {
TextThread(Arc<Path>),
}
+impl Into<ElementId> for HistoryEntryId {
+ fn into(self) -> ElementId {
+ match self {
+ HistoryEntryId::AcpThread(session_id) => ElementId::Name(session_id.0.into()),
+ HistoryEntryId::TextThread(path) => ElementId::Path(path),
+ }
+ }
+}
+
#[derive(Serialize, Deserialize, Debug)]
enum SerializedRecentOpen {
AcpThread(String),
@@ -673,18 +673,9 @@ impl AcpHistoryEntryElement {
impl RenderOnce for AcpHistoryEntryElement {
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
- let (id, title, timestamp) = match &self.entry {
- HistoryEntry::AcpThread(thread) => (
- thread.id.to_string(),
- thread.title.clone(),
- thread.updated_at,
- ),
- HistoryEntry::TextThread(context) => (
- context.path.to_string_lossy().to_string(),
- context.title.clone(),
- context.mtime.to_utc(),
- ),
- };
+ let id = self.entry.id();
+ let title = self.entry.title();
+ let timestamp = self.entry.updated_at();
let formatted_time = {
let now = chrono::Utc::now();
@@ -701,7 +692,7 @@ impl RenderOnce for AcpHistoryEntryElement {
}
};
- ListItem::new(SharedString::from(id))
+ ListItem::new(id)
.rounded()
.toggle_state(self.selected)
.spacing(ListItemSpacing::Sparse)
@@ -2404,16 +2404,18 @@ impl AcpThreadView {
fn render_empty_state(&self, window: &mut Window, cx: &mut Context<Self>) -> AnyElement {
let loading = matches!(&self.thread_state, ThreadState::Loading { .. });
- let recent_history = self
- .history_store
- .update(cx, |history_store, cx| history_store.recent_entries(3, cx));
- let no_history = self
- .history_store
- .update(cx, |history_store, cx| history_store.is_empty(cx));
+ let render_history = self
+ .agent
+ .clone()
+ .downcast::<agent2::NativeAgentServer>()
+ .is_some()
+ && self
+ .history_store
+ .update(cx, |history_store, cx| !history_store.is_empty(cx));
v_flex()
.size_full()
- .when(no_history, |this| {
+ .when(!render_history, |this| {
this.child(
v_flex()
.size_full()
@@ -2445,7 +2447,10 @@ impl AcpThreadView {
})),
)
})
- .when(!no_history, |this| {
+ .when(render_history, |this| {
+ let recent_history = self
+ .history_store
+ .update(cx, |history_store, cx| history_store.recent_entries(3, cx));
this.justify_end().child(
v_flex()
.child(