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