gui: MediaItem carries its DocumentID; drop the always-true activatable

Every MediaLibrary consumer built items with `activatable: true` and an id
stringified from a DocumentID, then parsed ItemActivated's string back into a
DocumentID. MediaItem::id and ItemActivated are DocumentIDs now, and the
activatable knob (true at all six construction sites) is gone, its rationale
folded into availability's doc. Render-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Greg ShuflinandClaude Opus 5.5 committed 2026-09-28 14:52:19 -07:00
1 parent 190af3cc91
commit 4ccee0c0b6
5 files changed
+37 -60

No files matched your search

+4 -10
View File
@@ -316,9 +316,7 @@ impl ComicsView {
// MediaLibrary used to do this itself; it no longer knows which of
// a consumer's tabs is the browsable one.
this.library.update(cx, |l, cx| l.set_active_tab(COMICS_TAB_LIBRARY, cx));
if let Ok(id) = event.0.to_string().parse::<DocumentID>() {
this.activate_item(id, cx);
}
this.activate_item(event.0.clone(), cx);
})
.detach();
cx.subscribe(&library, |this, _library, event: &BreadcrumbActivated, cx| {
@@ -490,7 +488,7 @@ impl ComicsView {
SharedString::default()
};
MediaItem {
id: node.id.to_string().into(),
id: node.id.clone(),
title: node.title.clone().into(),
subtitle,
thumbnail: self.thumbnails.get(&node.id).cloned(),
@@ -500,7 +498,6 @@ impl ComicsView {
// `fetch_comic_page_bytes_remote`) — so the availability marker never
// gates clickability, not even for `Unavailable`, whose evidence is
// only ever "no peer has told us", never "no peer has it".
activatable: true,
is_collection: node.is_collection,
}
}
@@ -561,12 +558,11 @@ impl ComicsView {
format!("Continue: {}", leaf.title).into()
};
Some(MediaItem {
id: leaf.id.to_string().into(),
id: leaf.id.clone(),
title: top.title.clone().into(),
subtitle,
thumbnail: this.thumbnails.get(&leaf.id).cloned(),
availability: leaf.availability,
activatable: true,
is_collection: false,
})
})
@@ -712,9 +708,7 @@ impl ComicsView {
if let Some(image) = cover {
this.update(cx, |this, cx| {
this.thumbnails.insert(display_id.clone(), image.clone());
this.library.update(cx, |l, cx| {
l.set_thumbnail(&display_id.to_string(), image, cx)
});
this.library.update(cx, |l, cx| l.set_thumbnail(&display_id, image, cx));
})
.ok();
}
+4 -12
View File
@@ -249,9 +249,7 @@ impl MusicView {
library
});
cx.subscribe(&library, |this, _library, event: &ItemActivated, cx| {
if let Ok(id) = event.0.to_string().parse::<DocumentID>() {
this.activate_item(id, cx);
}
this.activate_item(event.0.clone(), cx);
})
.detach();
cx.subscribe(&library, |this, _library, event: &BreadcrumbActivated, cx| {
@@ -438,16 +436,12 @@ impl MusicView {
fn entry_to_media_item(&self, entry: &LibraryEntry) -> MediaItem {
MediaItem {
id: entry.id.to_string().into(),
id: entry.id.clone(),
title: entry.title.clone().into(),
subtitle: entry.subtitle.clone().into(),
thumbnail: self.covers.get(&entry.id).cloned(),
// Only a track can be un-playable; a container always opens.
availability: entry.availability,
// Always activatable: a track whose audio lives on a peer is
// dimmed, but selecting it falls back to streaming it from
// whichever node holds it (see `select_track`).
activatable: true,
is_collection: entry.kind != LibraryEntryKind::Track,
}
}
@@ -461,12 +455,11 @@ impl MusicView {
SharedString::default()
};
MediaItem {
id: node.id.to_string().into(),
id: node.id.clone(),
title: node.title.clone().into(),
subtitle,
thumbnail: None,
availability: node.availability,
activatable: true,
is_collection: node.is_collection,
}
}
@@ -545,8 +538,7 @@ impl MusicView {
if let Some(image) = art {
this.update(cx, |this, cx| {
this.covers.insert(id.clone(), image.clone());
this.library
.update(cx, |l, cx| l.set_thumbnail(&id.to_string(), image, cx));
this.library.update(cx, |l, cx| l.set_thumbnail(&id, image, cx));
})
.ok();
}
+3 -7
View File
@@ -776,9 +776,7 @@ impl PdfViewerView {
cx.subscribe(&library, |this, _library, event: &ItemActivated, cx| {
// See the comics equivalent: the finder tab hands off to Library.
this.library.update(cx, |l, cx| l.set_active_tab(PDF_TAB_LIBRARY, cx));
if let Ok(id) = event.0.to_string().parse::<DocumentID>() {
this.open_pdf(id, cx);
}
this.open_pdf(event.0.clone(), cx);
})
.detach();
cx.subscribe(&library, |this, _library, event: &TabActivated, cx| {
@@ -968,7 +966,7 @@ impl PdfViewerView {
fn to_media_item(&self, item: &PdfListItem) -> MediaItem {
MediaItem {
id: item.id.to_string().into(),
id: item.id.clone(),
title: item.title.clone().into(),
subtitle: item.subtitle.clone().into(),
thumbnail: self.thumbnails.get(&item.id).cloned(),
@@ -978,7 +976,6 @@ impl PdfViewerView {
// the availability marker never gates clickability, not even for
// `Unavailable`, whose evidence is only ever "no peer has told us", never
// "no peer has it".
activatable: true,
is_collection: false,
}
}
@@ -1021,8 +1018,7 @@ impl PdfViewerView {
if let Some(image) = thumbnail {
this.update(cx, |this, cx| {
this.thumbnails.insert(id.clone(), image.clone());
this.library
.update(cx, |l, cx| l.set_thumbnail(&id.to_string(), image, cx));
this.library.update(cx, |l, cx| l.set_thumbnail(&id, image, cx));
})
.ok();
}
+2 -5
View File
@@ -90,9 +90,7 @@ impl VideoView {
library
});
cx.subscribe(&library, |this, _library, event: &ItemActivated, cx| {
if let Ok(id) = event.0.to_string().parse::<DocumentID>() {
this.activate_item(id, cx);
}
this.activate_item(event.0.clone(), cx);
})
.detach();
cx.subscribe(&library, |this, _library, event: &BreadcrumbActivated, cx| {
@@ -205,14 +203,13 @@ impl VideoView {
/// renders it as a folder placeholder regardless.
fn to_media_item(node: &VideoTreeItem) -> MediaItem {
MediaItem {
id: node.id.to_string().into(),
id: node.id.clone(),
title: node.title.clone().into(),
subtitle: node.duration_secs.map(format_duration).unwrap_or_default(),
// No decoder yet, so no frame to derive a poster thumbnail from — see
// the module doc comment.
thumbnail: None,
availability: node.availability,
activatable: true,
is_collection: node.is_collection,
}
}
+24 -26
View File
@@ -28,7 +28,7 @@ use gpui::{
KeyDownEvent, MouseButton, MouseMoveEvent, Pixels, RenderImage, ScrollHandle, SharedString,
UniformListScrollHandle, Window, div, img, point, prelude::*, px, uniform_list,
};
use synchronicity::documents::DocumentAvailability;
use synchronicity::documents::{DocumentAvailability, DocumentID};
use crate::assets::Icon;
use crate::components::availability;
@@ -81,22 +81,18 @@ const DIM_UNAVAILABLE: f32 = 0.5;
/// background executor); a missing one falls back to a glyph placeholder.
#[derive(Clone)]
pub struct MediaItem {
/// Stable id echoed back in [`ItemActivated`] when the item is clicked.
pub id: SharedString,
/// The item's document, echoed back in [`ItemActivated`] when it is
/// clicked. Every item can be activated — see [`Self::availability`].
pub id: DocumentID,
pub title: SharedString,
/// Secondary line (page count, author, …). Empty hides it.
pub subtitle: SharedString,
pub thumbnail: Option<Arc<RenderImage>>,
/// Where the underlying content can be read from — drives dimming and the
/// corner marker, never clickability (see [`activatable`](Self::activatable)).
/// corner marker, never clickability: every blob-backed agent streams
/// content it doesn't hold from whichever peer does, so a non-local item
/// is still openable.
pub availability: DocumentAvailability,
/// Whether activating this item does anything.
///
/// Deliberately independent of [`availability`](Self::availability): every
/// blob-backed agent streams content it doesn't hold from whichever peer
/// does, so a non-local item is still openable. Overloading the two into
/// one flag left that fallback permanently unreachable.
pub activatable: bool,
/// Whether activating this item should drill into it as a sub-collection
/// (the consumer pushes a breadcrumb and calls [`Self::set_items`] again
/// with its children) rather than open it directly. Purely a hint for
@@ -144,7 +140,7 @@ pub struct TabActivated(pub SharedString);
/// Emitted when the user activates (clicks, or presses Enter on) a local
/// library item; carries the item's [`MediaItem::id`].
pub struct ItemActivated(pub SharedString);
pub struct ItemActivated(pub DocumentID);
/// Emitted when a breadcrumb (see [`MediaLibrary::set_breadcrumbs`]) is
/// clicked, or Backspace is pressed while browsing with breadcrumbs set: `0`
@@ -180,7 +176,7 @@ pub struct MediaLibrary {
focus: FocusHandle,
/// Id of the keyboard-navigation cursor, if any. Doubles as the last
/// clicked item so mouse and keyboard stay in sync.
cursor: Option<SharedString>,
cursor: Option<DocumentID>,
/// Drill-in path labels below the implicit "Library" home crumb; empty
/// hides the breadcrumb bar entirely (the default — a consumer that
/// never calls [`Self::set_breadcrumbs`] looks exactly as it did before
@@ -292,8 +288,13 @@ impl MediaLibrary {
/// Attach a freshly-decoded cover to the item with `id` (a no-op if it's gone),
/// so agents can stream covers in as they decode rather than blocking the list.
pub fn set_thumbnail(&mut self, id: &str, thumbnail: Arc<RenderImage>, cx: &mut Context<Self>) {
if let Some(item) = self.items.iter_mut().find(|i| i.id == id) {
pub fn set_thumbnail(
&mut self,
id: &DocumentID,
thumbnail: Arc<RenderImage>,
cx: &mut Context<Self>,
) {
if let Some(item) = self.items.iter_mut().find(|i| &i.id == id) {
item.thumbnail = Some(thumbnail);
cx.notify();
}
@@ -323,7 +324,7 @@ impl MediaLibrary {
/// to its main browse tab on activation calls [`Self::set_active_tab`] from
/// its own [`ItemActivated`] handler — this component no longer knows which
/// of a consumer's tabs is the browsable one.
fn activate(&mut self, id: SharedString, cx: &mut Context<Self>) {
fn activate(&mut self, id: DocumentID, cx: &mut Context<Self>) {
self.cursor = Some(id.clone());
cx.emit(ItemActivated(id));
}
@@ -369,7 +370,7 @@ impl MediaLibrary {
let Some(id) = self.cursor.clone() else {
return;
};
if self.items.iter().any(|i| i.id == id && i.activatable) {
if self.items.iter().any(|i| i.id == id) {
cx.emit(ItemActivated(id));
}
}
@@ -722,7 +723,7 @@ impl MediaLibrary {
.flex_none()
.flex_col()
.w(scaled(CARD_WIDTH))
.when(item.activatable, |c| c.cursor_pointer())
.cursor_pointer()
.opacity(dimming(item.availability))
.child(
div()
@@ -734,7 +735,7 @@ impl MediaLibrary {
.border_1()
.border_color(theme.border_card)
.bg(theme.bg_card)
.when(item.activatable, |c| c.hover(|s| s.border_color(theme.accent)))
.hover(|s| s.border_color(theme.accent))
.when(is_cursor, |c| c.border_color(theme.accent))
.child(cover_art(theme, item, self.placeholder_icon, scaled(40.))),
)
@@ -781,9 +782,7 @@ impl MediaLibrary {
)
.children(availability::word(theme, item.availability)),
)
.when(item.activatable, |c| {
c.on_click(cx.listener(move |this, _, _, cx| this.activate(id.clone(), cx)))
})
.on_click(cx.listener(move |this, _, _, cx| this.activate(id.clone(), cx)))
}
fn render_list(&self, theme: &Theme, cx: &mut Context<Self>) -> impl IntoElement + use<> {
@@ -819,7 +818,8 @@ impl MediaLibrary {
.px_4()
.border_b_1()
.border_color(theme.border_card)
.when(item.activatable, |c| c.cursor_pointer().hover(|s| s.bg(theme.bg_hover)))
.cursor_pointer()
.hover(|s| s.bg(theme.bg_hover))
.opacity(dimming(item.availability))
.when(is_cursor, |c| c.bg(theme.bg_hover))
.child(
@@ -863,9 +863,7 @@ impl MediaLibrary {
// A list row has a trailing column doing nothing, so the state goes
// there in words and the thumbnail stays a thumbnail.
.children(availability::word(theme, item.availability))
.when(item.activatable, |c| {
c.on_click(cx.listener(move |this, _, _, cx| this.activate(id.clone(), cx)))
})
.on_click(cx.listener(move |this, _, _, cx| this.activate(id.clone(), cx)))
}
}