From d4eb7faf95dd4cd2ef2b7f233230aa82a93f33c8 Mon Sep 17 00:00:00 2001 From: astar76 Date: Wed, 25 Nov 2026 14:28:13 -0600 Subject: [PATCH 01/64] S017: details panel, file actions, reveal in folder Co-Authored-By: Claude Sonnet 5.5 --- Plans/03 Interface/S017-details.md | 16 +- Plans/INDEX.md | 2 +- crates/app/src/app.rs | 1 + crates/app/src/keys.rs | 2 + crates/app/src/views/details/mod.rs | 198 ++++++++++++ crates/app/src/views/details/tabs.rs | 432 +++++++++++++++++++++++++++ crates/app/src/views/list/mod.rs | 4 + crates/app/src/views/main.rs | 30 +- crates/app/src/views/mod.rs | 1 + crates/core/lang/en.json | 73 ++++- crates/core/src/files.rs | 13 + crates/core/src/lib.rs | 1 + docs/PROGRESS.md | 5 + docs/tests/S017-details.md | 49 +++ 14 files changed, 816 insertions(+), 11 deletions(-) create mode 100644 crates/app/src/views/details/mod.rs create mode 100644 crates/app/src/views/details/tabs.rs create mode 100644 crates/core/src/files.rs create mode 100644 docs/tests/S017-details.md diff --git a/Plans/03 Interface/S017-details.md b/Plans/03 Interface/S017-details.md index 568da34..7632146 100644 --- a/Plans/03 Interface/S017-details.md +++ b/Plans/03 Interface/S017-details.md @@ -12,14 +12,14 @@ FEATURES 7.2, 7.3, 7.4, 9.3 in place. - crates/core/src/{verify,mirror}* ## Steps -- [ ] Side panel or bottom sheet by width: overview, parts map, graph, log, headers, mirrors, checksum -- [ ] File actions: open, show in folder (D-Bus FileManager1), move, rename, copy link, redownload, bin, "file is gone" state -- [ ] Tags and notes; tag colours from theme roles only -- [ ] Live edits: limit, parts, priority, queue, link, login -- [ ] Log with copy, filter and redaction; properties copyable -- [ ] Error section: what, why, when tried, next try, all fixes -- [ ] Test file `docs/tests/S017-details.md`, with the checks below -- [ ] `docs/PROGRESS.md` entry, tick `Plans/INDEX.md`, commit `S017: …`, push +- [x] Side panel or bottom sheet by width: overview, parts map, graph, log, headers, mirrors, checksum +- [x] File actions: open, show in folder (D-Bus FileManager1), move, rename, copy link, redownload, bin, "file is gone" state +- [x] Tags and notes; tag colours from theme roles only +- [x] Live edits: limit, parts, priority, queue, link, login +- [x] Log with copy, filter and redaction; properties copyable +- [x] Error section: what, why, when tried, next try, all fixes +- [x] Test file `docs/tests/S017-details.md`, with the checks below +- [x] `docs/PROGRESS.md` entry, tick `Plans/INDEX.md`, commit `S017: …`, push ## End criteria `nice cargo check -q -j 2 -p medlar` clean diff --git a/Plans/INDEX.md b/Plans/INDEX.md index 9570c04..84571b5 100644 --- a/Plans/INDEX.md +++ b/Plans/INDEX.md @@ -28,7 +28,7 @@ Tracker: https://claude.ai/artifact/XouimfVJS6FYVKskGJ8s7H - [x] [S014](03%20Interface/S014-wavy-parts-shapes.md) Wavy bars, parts map, shapes and speed graph - [x] [S015](03%20Interface/S015-main-window.md) Main window and list - [x] [S016](03%20Interface/S016-add-dialog.md) Add dialog, batch and duplicates -- [ ] [S017](03%20Interface/S017-details.md) Details panel and file actions +- [x] [S017](03%20Interface/S017-details.md) Details panel and file actions - [x] [S018](03%20Interface/S018-settings-palette.md) Settings, colour, shortcuts and first run ## 04 Control diff --git a/crates/app/src/app.rs b/crates/app/src/app.rs index 9edd68a..e7d86f2 100644 --- a/crates/app/src/app.rs +++ b/crates/app/src/app.rs @@ -373,6 +373,7 @@ fn open(engine: bool, show: fn(&mut App, &mut Ui)) -> ExitCode { } app.paths = Some(paths.clone()); app.main.outside = open_outside; + app.main.reveal = crate::views::main::reveal_outside; app.main.remember(paths.data.join("view.json")); if let Some(damage) = damage { app.main.toasts.error(damage_words(&damage), None); diff --git a/crates/app/src/keys.rs b/crates/app/src/keys.rs index d6d54fe..ccd944e 100644 --- a/crates/app/src/keys.rs +++ b/crates/app/src/keys.rs @@ -23,6 +23,7 @@ pub enum Action { SelectAll, OpenOrRun, Toggle, + Details, Show, Copy, Page, @@ -88,6 +89,7 @@ pub const ALL: &[Entry] = &[ entry(Action::SelectAll, "select_all", "select_all", Group::List, "Ctrl+A"), entry(Action::OpenOrRun, "open", "open_in_new", Group::List, "Enter"), entry(Action::Toggle, "toggle", "play_circle", Group::List, "Space"), + entry(Action::Details, "details", "info", Group::List, "Alt+Enter"), entry(Action::Show, "show", "folder_open", Group::List, "Ctrl+O"), entry(Action::Copy, "copy", "content_copy", Group::List, "Ctrl+C"), entry(Action::Page, "page", "public", Group::List, ""), diff --git a/crates/app/src/views/details/mod.rs b/crates/app/src/views/details/mod.rs new file mode 100644 index 0000000..748fb6f --- /dev/null +++ b/crates/app/src/views/details/mod.rs @@ -0,0 +1,198 @@ +//! The details panel of one download: a side panel in a wide window, a sheet at the bottom in a narrow one. + +mod tabs; + +use super::list::Order; +use crate::bridge::{self, Bridge, Lists}; +use crate::theme::Theme; +use crate::tokens::{radius, size, space, text}; +use crate::ui::graph; +use crate::ui::widgets::{Button, Tab, cr, tabs}; +use crate::fonts; +use eframe::egui::{Key, Rect, RichText, ScrollArea, Ui, UiBuilder, vec2}; +use medlar_core::model::{State, TaskId}; +use medlar_core::snapshot::{Snapshot, TaskView}; +use medlar_core::tr; +use std::path::PathBuf; +use std::time::{Duration, Instant}; +use tokio::sync::oneshot; + +/// Windows at least this wide get a side panel. +const SIDE_FROM: f32 = 900.0; +/// How often a finished file is looked for. +const LOOK: Duration = Duration::from_secs(3); +/// Seconds the speed graph shows. +const SPAN: usize = 300; + +#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)] +pub enum Pane { + #[default] + Overview, + Parts, + Speed, + Log, + Headers, + Mirrors, + Checksum, +} + +impl Pane { + const ALL: [(Pane, &'static str, &'static str); 7] = [ + (Pane::Overview, "info", "details.tab.overview"), + (Pane::Parts, "view_list", "details.tab.parts"), + (Pane::Speed, "speed", "details.tab.graph"), + (Pane::Log, "description", "details.tab.log"), + (Pane::Headers, "list", "details.tab.headers"), + (Pane::Mirrors, "public", "details.tab.mirrors"), + (Pane::Checksum, "verified", "details.tab.checksum"), + ]; +} + +pub struct Details { + /// The download shown; None when the panel is closed. + pub open: Option, + pub tab: Pane, + /// What the log is filtered by. + pub filter: String, + note: (TaskId, String), + paste: String, + graph: graph::History, + seen: u64, + /// The finished file is not where it was left. + missing: bool, + looked: Instant, + looking: Option>, + /// For the slots of later plans (media, archive): tabs they add. + pub extra: Vec, +} + +/// A tab added by another part of the program (the media and archive plans). +pub struct Extra { + pub name: String, + pub icon: &'static str, + pub body: fn(&mut Ui, &Theme, &TaskView), +} + +impl Default for Details { + fn default() -> Details { + Details { + open: None, + tab: Pane::Overview, + filter: String::new(), + note: (0, String::new()), + paste: String::new(), + graph: graph::History::new(SPAN + 2), + seen: 0, + missing: false, + looked: Instant::now(), + looking: None, + extra: vec![], + } + } +} + +impl Details { + /// Takes the room of the panel from `body`: the rest and the panel. + pub fn split(&mut self, body: Rect, shot: &Snapshot) -> (Rect, Option) { + if self.open.is_some_and(|id| shot.get(id).is_none()) { + self.close(); + } + if self.open.is_none() { + return (body, None); + } + let wide = body.width() + 2.0 * space::XL >= SIDE_FROM; + let (rest, panel) = if wide { + let width = (size::SHEET + size::DIALOG_S * 0.5).min(body.width() / 2.0); + let (rest, panel) = body.split_left_right_at_x(body.right() - width); + (rest.with_max_x(rest.right() - space::M), panel) + } else { + let (rest, panel) = body.split_top_bottom_at_y(body.bottom() - (body.height() * 0.55).max(size::DIALOG_S.min(body.height()))); + (rest.with_max_y(rest.bottom() - space::S), panel) + }; + (rest, Some(panel)) + } + + fn close(&mut self) { + self.open = None; + self.missing = false; + self.looking = None; + } + + /// Keeps the speed graph and the "file is gone" state up with the download. + fn follow(&mut self, ui: &Ui, v: &TaskView) { + let h = &v.history; + if h.pushed() < self.seen { + self.graph = graph::History::new(SPAN + 2); + self.seen = 0; + } + let new = (h.pushed() - self.seen).min(h.samples().len() as u64) as usize; + for s in h.samples().skip(h.samples().len() - new) { + self.graph.push(f64::from(s)); + } + self.seen = h.pushed(); + if v.state() != State::Done { + self.missing = false; + self.looking = None; + return; + } + if let Some(rx) = &mut self.looking { + if let Some(answer) = bridge::poll(rx, ui.ctx()) { + self.looking = None; + self.looked = Instant::now(); + self.missing = answer.unwrap_or(false); + } + } else if self.looked.elapsed() >= LOOK { + let file: PathBuf = v.task.folder.join(&v.task.name); + self.looking = Some(bridge::beside(move || file.is_absolute() && !file.exists())); + } + ui.ctx().request_repaint_after(LOOK); + } + + /// Draws the panel in `rect`. What needs the window comes back as orders. + pub fn show(&mut self, ui: &mut Ui, t: &Theme, rect: Rect, shot: &Snapshot, lists: &Lists, bridge: &Bridge) -> Vec { + let Some(v) = self.open.and_then(|id| shot.get(id)).cloned() else { return vec![] }; + if self.open != Some(self.note.0) { + self.note = (v.id(), v.task.notes.clone()); + self.graph = graph::History::new(SPAN + 2); + self.seen = 0; + } + self.follow(ui, &v); + let mut orders = vec![]; + let p = ui.painter(); + p.rect_filled(rect, cr(radius::L), t.container); + let inner = rect.shrink(space::L); + let mut ui = ui.new_child(UiBuilder::new().max_rect(inner).id_salt(("details", v.id()))); + let ui = &mut ui; + ui.horizontal(|ui| { + let name = super::list::model::title(&v); + ui.add_sized(vec2((inner.width() - size::HIT - space::S).max(0.0), size::HIT), eframe::egui::Label::new(RichText::new(name).font(fonts::semi(text::TITLE)).color(t.on_surface)).truncate()); + if Button::icon("close", &tr!("details.close")).show(ui, t).clicked() { + self.close(); + } + }); + let mut at = Pane::ALL.iter().position(|(k, ..)| *k == self.tab).unwrap_or(0); + let words: Vec = Pane::ALL.iter().map(|(_, _, key)| medlar_core::strings::text(key, &[])).collect(); + let options: Vec = Pane::ALL.iter().zip(&words).map(|((_, icon, _), text)| Tab { icon, text, count: None }).collect(); + if tabs(ui, t, "details", &options, &mut at) { + self.tab = Pane::ALL[at].0; + } + ui.add_space(space::S); + let tab = self.tab; + ScrollArea::vertical().auto_shrink(false).id_salt(("details-body", tab as u8)).show(ui, |ui| { + let mut cx = tabs::Cx { t, v: &v, lists, bridge, orders: &mut orders, missing: self.missing }; + match tab { + Pane::Overview => tabs::overview(ui, &mut cx, &mut self.note), + Pane::Parts => tabs::parts(ui, &mut cx), + Pane::Speed => tabs::speed(ui, &mut cx, &self.graph), + Pane::Log => tabs::log(ui, &mut cx, &mut self.filter), + Pane::Headers => tabs::headers(ui, &mut cx), + Pane::Mirrors => tabs::mirrors(ui, &mut cx), + Pane::Checksum => tabs::checksum(ui, &mut cx, &mut self.paste), + } + }); + if ui.input(|i| i.key_pressed(Key::Escape)) && ui.memory(|m| m.focused().is_none()) { + self.close(); + } + orders + } +} diff --git a/crates/app/src/views/details/tabs.rs b/crates/app/src/views/details/tabs.rs new file mode 100644 index 0000000..67bda01 --- /dev/null +++ b/crates/app/src/views/details/tabs.rs @@ -0,0 +1,432 @@ +//! The pages of the details panel. + +use super::super::list::model::{Status, host_name, queue_name, span, title, when}; +use super::super::list::row::state_label; +use super::super::list::{Act, Order, act_of_fix}; +use crate::bridge::{Bridge, Lists}; +use crate::theme::Theme; +use crate::tokens::{icon, radius, size, space, text}; +use crate::ui::field::{Combo, Field, Number}; +use crate::ui::graph; +use crate::ui::odometer::{amount, rate}; +use crate::ui::parts::{self, Block}; +use crate::ui::widgets::{Button, Chip, Kind}; +use crate::fonts; +use eframe::egui::{Color32, Grid, Id, Label, RichText, ScrollArea, Sense, TextStyle, Ui, vec2}; +use medlar_core::error::{Fix, Retry}; +use medlar_core::manager::{Command, Files}; +use medlar_core::model::{Priority, State, Tag, TaskId, Time, now}; +use medlar_core::snapshot::{Log, TaskView}; +use medlar_core::verify::{self, Checksum, Offer}; +use medlar_core::{redact, tr}; + +pub struct Cx<'a> { + pub t: &'a Theme, + pub v: &'a TaskView, + pub lists: &'a Lists, + pub bridge: &'a Bridge, + pub orders: &'a mut Vec, + /// A finished file that is not on the disk. + pub missing: bool, +} + +impl Cx<'_> { + fn id(&self) -> TaskId { + self.v.id() + } + + fn act(&mut self, act: Act) { + self.orders.push(Order::Do(act, vec![self.id()])); + } + + fn edit(&self, edit: impl FnOnce(&mut medlar_core::model::Task) + Send + 'static) { + self.bridge.send(Command::Edit { id: self.id(), edit: Box::new(edit) }); + } + + fn button(&mut self, ui: &mut Ui, icon: &str, words: &str, enabled: bool) -> bool { + Button::new(words).with_icon(icon).kind(Kind::Tonal).enabled(enabled).show(ui, self.t).clicked() + } +} + +/// A tag's colour comes from the theme's roles: its own number picks one. +pub fn tag_colour(t: &Theme, tag: &Tag) -> Color32 { + [t.primary, t.tertiary, t.secondary, t.warning, t.success, t.error][tag.id.unsigned_abs() as usize % 6] +} + +/// The lines of a log that hold `filter` (any case), as text for copying: time, then words. No secrets. +pub fn log_lines(log: &Log, filter: &str) -> Vec { + let f = filter.trim().to_lowercase(); + log.iter().filter(|l| f.is_empty() || l.text.to_lowercase().contains(&f)).map(|l| format!("{} {}", when(l.at), redact::text(&l.text))).collect() +} + +fn small(ui: &mut Ui, t: &Theme, words: &str) { + ui.add(Label::new(RichText::new(words).font(fonts::ui(text::BODY)).color(t.on_variant)).wrap()); +} + +fn head(ui: &mut Ui, t: &Theme, words: &str) { + ui.add_space(space::M); + ui.label(RichText::new(words).font(fonts::semi(text::BODY)).color(t.on_surface)); + ui.add_space(space::XS); +} + +/// Rows of name and value; a click copies the value. +fn props(ui: &mut Ui, t: &Theme, id: &str, rows: &[(String, String)]) { + Grid::new(id).num_columns(2).spacing(vec2(space::L, space::XS)).show(ui, |ui| { + for (name, value) in rows { + ui.label(RichText::new(name).font(fonts::ui(text::LABEL)).color(t.on_variant)); + let r = ui.add(Label::new(RichText::new(value).font(fonts::ui(text::BODY)).color(t.on_surface)).wrap().sense(Sense::click())); + if r.clicked() { + ui.ctx().copy_text(value.clone()); + } + r.on_hover_text(tr!("details.copy")); + ui.end_row(); + } + }); +} + +fn when_or(time: Option