From c18d2c2f75db92dfb0371098eb973b3a2334bf63 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 18 Nov 2026 03:54:14 -0500 Subject: [PATCH] pdf-chrome-w5: net change of 4 commits - pdf-chrome-w5: written from its sheet - pdf-chrome-w5: repair 1 - pdf-chrome-w5: review fixes (review-1) - pdf-chrome-w5: resolve the words through the EnvView (lead, racheck) --- crates/ui-shell/src/shell/recent.rs | 24 +- crates/ui-shell/src/shell/start.rs | 358 +++++++++++++++++---- crates/ui-shell/src/shell/start/stories.rs | 114 +++++-- crates/ui-shell/src/shell/words.rs | 15 + crates/ui-shell/tests/it/shell/start.rs | 183 ++++++++++- 5 files changed, 587 insertions(+), 107 deletions(-) diff --git a/crates/ui-shell/src/shell/recent.rs b/crates/ui-shell/src/shell/recent.rs index f36334fa7..556f61dbe 100644 --- a/crates/ui-shell/src/shell/recent.rs +++ b/crates/ui-shell/src/shell/recent.rs @@ -27,7 +27,7 @@ pub struct RecentFile { pub opened: Option, /// Created, in seconds since the Unix epoch, for sorting by Created. pub created: Option, - /// A second line under the name. + /// A note the app gives ("12 pages · 2.4 MB"), shown in place of the age line. pub note: Option, } @@ -38,26 +38,24 @@ impl RecentFile { } /// This file last opened at `opened`, in seconds since the Unix epoch. - #[allow(dead_code)] // P3(pdf-chrome-w2): L-165 #[must_use] - pub fn opened(self, opened: i64) -> Self { - let _ = opened; - todo!("L-165") + pub fn opened(mut self, opened: i64) -> Self { + self.opened = Some(opened); + self } /// This file created at `created`, in seconds since the Unix epoch. - #[allow(dead_code)] // P3(pdf-chrome-w2): L-165 #[must_use] - pub fn created(self, created: i64) -> Self { - let _ = created; - todo!("L-165") + pub fn created(mut self, created: i64) -> Self { + self.created = Some(created); + self } - /// This file with a second line, `note`, under its name. + /// This file with `note` shown in place of its age line. #[must_use] - pub fn note(self, note: impl Into) -> Self { - let _ = note; - todo!("CH-C17") + pub fn note(mut self, note: impl Into) -> Self { + self.note = Some(note.into()); + self } } diff --git a/crates/ui-shell/src/shell/start.rs b/crates/ui-shell/src/shell/start.rs index 5e416b781..b2566a3a3 100644 --- a/crates/ui-shell/src/shell/start.rs +++ b/crates/ui-shell/src/shell/start.rs @@ -25,7 +25,7 @@ use crate::runtime::env::{AgeStyle, Env, Label}; use crate::sections::Section; use crate::style::{Corners, SurfaceKind, SurroundLook}; use crate::tile_grid::{CaptionPlace, GridZoom, Tile, TileGrid, TilePartEvent}; -use craft_behavior::{IconId, Proposal, SelectionChange, keyed}; +use craft_behavior::{DisplayOrder, IconId, ItemSource, Proposal, SelectionChange, keyed}; use craft_theme::Variant; use craft_theme::variant::Tone; use egui::{CornerRadius, Rect, Response, Ui, Vec2}; @@ -46,6 +46,9 @@ const RECENT_SHOWN: usize = 12; /// The revealed part of a recent row that takes the file off the list. const REMOVE: TrailingPart = TrailingPart::new(0); +/// The part of a listed pinned folder's heading that unpins the folder. +const UNPIN: TrailingPart = TrailingPart::new(0); + /// The commands of a recent file's context menu. They act on the file that has the lead in the recent files, which a /// secondary click or the context-menu key gives to the file the menu is for. Delete at the lead of the recent files is /// the list's own delete request and reports the same `RemoveRecent`; `Remove` shows that chord in the menu. @@ -143,34 +146,29 @@ pub struct PinnedFolder { impl PinnedFolder { /// A pinned folder at `path` shown as `name`, not yet listed, unfolded and not expanded. - #[allow(dead_code)] // P3(pdf-chrome-w2): L-165 pub fn new(path: impl Into, name: impl Into) -> Self { - let _ = (path, name); - todo!("L-165") + PinnedFolder { path: path.into(), name: name.into(), listing: None, folded: false, expanded: false } } /// This folder with its files, `listing`, as the app found them. - #[allow(dead_code)] // P3(pdf-chrome-w2): L-165 #[must_use] - pub fn listing(self, listing: FolderListing) -> Self { - let _ = listing; - todo!("L-165") + pub fn listing(mut self, listing: FolderListing) -> Self { + self.listing = Some(listing); + self } /// This folder shown folded (no files) or not. - #[allow(dead_code)] // P3(pdf-chrome-w2): L-165 #[must_use] - pub fn folded(self, folded: bool) -> Self { - let _ = folded; - todo!("L-165") + pub fn folded(mut self, folded: bool) -> Self { + self.folded = folded; + self } /// This folder listing all of its files, or only the first [`PINNED_FILES_SHOWN`]. - #[allow(dead_code)] // P3(pdf-chrome-w2): L-165 #[must_use] - pub fn expanded(self, expanded: bool) -> Self { - let _ = expanded; - todo!("L-165") + pub fn expanded(mut self, expanded: bool) -> Self { + self.expanded = expanded; + self } } @@ -205,18 +203,15 @@ pub struct PinnedFile { impl PinnedFile { /// A file at `path` shown as `name`, with no second line. - #[allow(dead_code)] // P3(pdf-chrome-w2): L-165 pub fn new(path: impl Into, name: impl Into) -> Self { - let _ = (path, name); - todo!("L-165") + PinnedFile { path: path.into(), name: name.into(), note: None } } /// This file with a second line, `note`, under its name. - #[allow(dead_code)] // P3(pdf-chrome-w2): L-165 #[must_use] - pub fn note(self, note: impl Into) -> Self { - let _ = note; - todo!("L-165") + pub fn note(mut self, note: impl Into) -> Self { + self.note = Some(note.into()); + self } } @@ -241,21 +236,32 @@ impl Outcome for StartOutput { /// The start screen, shown in a shell's body when no document is open. /// -/// - **Layout.** New and Open (the first Tab stops), then Recent with the view switch and the sort, Pinned Folders -/// when the app gives the list (even an empty one) and Templates when it gives any. The page scrolls as a whole, and each grid and list takes the height of its rows. +/// - **Layout.** New and Open (the first Tab stops; with `offers_new(false)` New is left out and Open leads), then the +/// host's [`StartPlace::BeforeRecent`] sections, Recent with the view switch and the sort (left out with +/// `max_recent(0)`), Pinned Folders when the app gives the list (even an empty one), Templates when it gives any, +/// then the host's [`StartPlace::AfterSections`] sections, in call order. The page scrolls as a whole, and each grid +/// and list takes the height of its rows. /// - **Recent files.** A grid of cards or a list, by the `view` binding, in the order of the `sort` binding. A click or /// Enter opens a file; arrows move; the context menu (secondary click, the menu key or Shift+F10) and the -/// [`StartRecentCommands`] remove it from the list, clear the list or show it in its folder. +/// [`StartRecentCommands`] remove it from the list, clear the list or show it in its folder. A file's +/// [`note`](RecentFile::note) shows in place of its age. +/// - **Pinned folders.** Each folder is a heading row. A listed folder holds its files, the first +/// [`PINNED_FILES_SHOWN`] until the app expands it, then a More row; the heading's trailing note says when the app is +/// still listing, cannot list, found no files or kept only the newest. The app owns fold and expansion: the +/// disclosure and Left/Right report [`StartAction::FoldPinned`], the More row [`StartAction::ExpandPinned`], and the +/// app passes `folded` and `expanded` back. /// - **Thumbnails.** With `thumbnails(store, source)`, each card, row and template asks the store for its /// [`ThumbKey`] at the size it paints: a placeholder until the picture is ready, a failure mark when loading failed, /// the file icon when the source has no picture for the key. Without it cards show the file icon. -/// - **Links.** `links` adds a rail beside the page (New and Open, then the links) in a room wide enough, else the -/// links follow the sections. A double click on the page's own room opens a file, as Open does. +/// - **Links.** `links` adds a rail beside the page (New and Open, then the links) in a room that holds the rail and +/// the sections' least width, host sections included, else the links follow the sections. A double click on the +/// page's own room opens a file, as Open does. /// - **No recent files.** With a `drop_hint` the Recent section is a card that opens a file on a click, Enter or Space. /// - **State.** The app owns the list, the view and the sort. The screen writes a changed view or sort through its /// binding and reports everything else as [`StartAction`]s. /// /// ```ignore +/// let folders = vec![PinnedFolder::new("/home/ana/Work", "Work").listing(listing)]; /// let out = StartScreen::new(Bind::bound(&mut view), Bind::bound(&mut sort), &recent).pinned(&folders).show(ui); /// for action in out.actions { /* the app opens, removes, pins... */ } /// ``` @@ -289,8 +295,14 @@ pub struct StartScreen<'a> { /// The New… button shows (true by default). #[prop] offers_new: bool, + /// The host's sections, each at its place, in call order. + sections: Vec<(StartPlace, HostSection<'a>)>, } +/// A host section's body. A cell, because the page's body runs for the measuring pass and the shown pass and calls +/// every section in both. +type HostSection<'a> = RefCell) + 'a>>; + /// A link on the start screen's rail. #[derive(Clone, Debug, PartialEq)] #[non_exhaustive] @@ -340,14 +352,16 @@ impl<'a> StartScreen<'a> { links: &[], drop_hint: None, offers_new: true, + sections: Vec::new(), } } - /// Shows `body` as a host section at `place` on the start screen. + /// Shows `body` as a host section at `place` on the start screen, after the sections given there before it. Its + /// least width counts in whether the rail fits beside the page. #[must_use] - pub fn section(self, place: StartPlace, body: impl FnMut(&mut Ui, &mut BodyCx<'_>) + 'a) -> Self { - let _ = (place, body); - todo!("CH-C17") + pub fn section(mut self, place: StartPlace, body: impl FnMut(&mut Ui, &mut BodyCx<'_>) + 'a) -> Self { + self.sections.push((place, RefCell::new(Box::new(body)))); + self } /// Cards, rows and templates ask `thumbnails.state(..)` for what they show; `source` gives each key's revision. @@ -361,7 +375,7 @@ impl<'a> StartScreen<'a> { #[derive(Clone, Debug, Default)] struct Leads { recent: Option, - pinned: Option, + pinned: Option, } /// The thumbnails and the source of each key's revision. @@ -374,6 +388,8 @@ struct Page<'p> { thumbnails: Option>, drop_hint: Option<&'p Label>, now: Option, + /// New… shows beside Open. + offers_new: bool, actions: &'p RefCell>, } @@ -382,6 +398,11 @@ impl<'p> Page<'p> { self.actions.borrow_mut().push(action); } + /// The line a recent file shows under its card's name and at its row's end: the app's note, else the age. + fn recent_detail(&self, file: &RecentFile) -> Option { + file.note.clone().or_else(|| self.age(file.opened)) + } + /// How long before `now` `then` was, in words; `None` when either time is unknown. fn age(&self, then: Option) -> Option { let (now, then) = (self.now?, then?); @@ -415,7 +436,7 @@ impl<'p> Page<'p> { .detail_line() .card() .aspect(f32::from(PICTURE_WIDE) / f32::from(PICTURE_HIGH)) - .zoom(GridZoom::Fixed(f64::from(CARD_ZOOM))) // P3(pdf-chrome-w5): WF-W12 + .zoom(GridZoom::Fixed(f64::from(CARD_ZOOM))) .fill_row() .sizing(Sizing::FillWidth) .natural_height(true) @@ -466,12 +487,12 @@ fn read_events(events: Vec>, lead: &mut Optio impl StartScreen<'_> { /// Shows the page across the available room and reports what the user did. pub fn show(self, ui: &mut Ui) -> StartOutput { - let StartScreen { view, sort, recent, pinned, templates, max_recent, now, thumbnails, links, drop_hint, offers_new: _ } = self; // P3(pdf-chrome-w5): CH-C17 + let StartScreen { view, sort, recent, pinned, templates, max_recent, now, thumbnails, links, drop_hint, offers_new, sections } = self; let env = Env::of(ui); let collator = env.collator(); let words = env.words::(); let actions = RefCell::new(Vec::new()); - let page = Page { env: &env, words: &words, thumbnails, drop_hint: drop_hint.as_ref(), now, actions: &actions }; + let page = Page { env: &env, words: &words, thumbnails, drop_hint: drop_hint.as_ref(), now, offers_new, actions: &actions }; let view = RefCell::new(view); let sort = RefCell::new(sort); @@ -486,25 +507,37 @@ impl StartScreen<'_> { link_items(ui, links); }; let page_stack = || Stack::new().gap(Gap::Section).pad(Pad::Regular).fill_width(); + // The host's sections at `place`, each one child of the page, so they stand one section gap apart. + let host_sections = |ui: &mut Ui, place: StartPlace| { + for (_, body) in sections.iter().filter(|(held, _)| *held == place) { + let _ = Stack::new().fill_width().show(ui, |ui, cx| { + let mut held = body.borrow_mut(); + let run: &mut dyn FnMut(&mut Ui, &mut BodyCx<'_>) = &mut **held; + run(ui, cx); + }); + } + }; // `beside` is whether the rail stands beside the page; without it New and Open lead the page and the links follow // the sections. let page_body = |ui: &mut Ui, cx: &mut BodyCx<'_>, beside: bool| { - let current_view = view.borrow_mut().reborrow().read(cx).and_then(|held| held.same().copied()).unwrap_or_default(); - let current_sort = sort.borrow_mut().reborrow().read(cx).and_then(|held| held.same().copied()).unwrap_or_default(); - let mut files: Vec = recent.iter().take(max_recent).cloned().collect(); - sort_recent(&mut files, current_sort, &collator); - if !beside { let _ = Row::new().gap(Gap::Tight).show(ui, |ui, _| new_and_open(&page, ui)); } - recent_section(&page, ui, &view, &sort, current_view, &files); + host_sections(ui, StartPlace::BeforeRecent); + if max_recent > 0 { + let current_view = view.borrow_mut().reborrow().read(cx).and_then(|held| held.same().copied()).unwrap_or_default(); + let current_sort = sort.borrow_mut().reborrow().read(cx).and_then(|held| held.same().copied()).unwrap_or_default(); + let mut files: Vec = recent.iter().take(max_recent).cloned().collect(); + sort_recent(&mut files, current_sort, &collator); + recent_section(&page, ui, &view, &sort, current_view, &files); + } if let Some(pinned) = pinned { - let paths: Vec = pinned.iter().map(|folder| folder.path.clone()).collect(); // P3(pdf-chrome-w5): CH-C18 - pinned_section(&page, ui, &paths); + pinned_section(&page, ui, pinned); } if !templates.is_empty() { templates_section(&page, ui, templates); } + host_sections(ui, StartPlace::AfterSections); if !beside && !links.is_empty() { let _ = Stack::new().gap(Gap::Tight).label(words.start_links.clone()).show(ui, |ui, _| link_items(ui, links)); } @@ -537,10 +570,10 @@ impl StartScreen<'_> { } } -/// New and Open, the first Tab stops of the page. +/// New and Open, the first Tab stops of the page; Open alone where the app offers no New. fn new_and_open(page: &Page<'_>, ui: &mut Ui) { let words = page.words; - if clicked(&Button::new(words.new.clone()).id_salt("new").variant(Variant::PRIMARY).show(ui)) { + if page.offers_new && clicked(&Button::new(words.new.clone()).id_salt("new").variant(Variant::PRIMARY).show(ui)) { page.push(StartAction::New); } if clicked(&Button::new(words.open.clone()).id_salt("open").show(ui)) { @@ -635,21 +668,22 @@ fn recent_section( let (response, (opened, removed)) = if current == RecentView::Grid { let out = page.grid::(words.recent.clone(), true).show_items(ui, &source, &mut |path, _| { let Some(file) = file_of(path) else { return Tile::new(Label::Empty) }; - page.tile(&file.name, page.age(file.opened), ThumbKey::Recent(file.path.clone())) - .corner_action(IconId::new("close"), StartRecentCommands::Remove) + page.tile(&file.name, page.recent_detail(file), ThumbKey::Recent(file.path.clone())) + .action(IconId::new("close"), StartRecentCommands::Remove) .tooltip(file.path.display().to_string()) }); - let corner: Vec = out + // The card's one action, its remove button, is action 0. + let action: Vec = out .response .events .iter() .filter_map(|event| match event { - CollectionEvent::Item(key, TilePartEvent::CornerAction) => Some(key.clone()), + CollectionEvent::Item(key, TilePartEvent::Action(0)) => Some(key.clone()), _ => None, }) .collect(); let (opened, mut removed) = read_events(out.response.events, &mut lead); - removed.extend(corner); + removed.extend(action); (out.response.response, (opened, removed)) } else { let out = List::::new(words.recent.clone()) @@ -661,8 +695,8 @@ fn recent_section( .show_items(ui, &source, &mut |path, _| { let Some(file) = file_of(path) else { return ListRow::new(Label::Empty) }; let row = ListRow::new(Label::from(file.name.clone())).detail(folder_of(&file.path)).tooltip(file.path.display().to_string()); - let row = match page.age(file.opened) { - Some(age) => row.trailing(age), + let row = match page.recent_detail(file) { + Some(detail) => row.trailing(detail), None => row, }; let row = row.trailing_part_revealed( @@ -711,7 +745,174 @@ fn recent_section( }); } -fn pinned_section(page: &Page<'_>, ui: &mut Ui, folders: &[PathBuf]) { +/// A row of the pinned folders' list. +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +enum PinnedKey { + /// The heading of the folder at this path. + Folder(PathBuf), + /// A file listed under `folder`; the folder is part of the key because nested pinned folders can list one file twice. + File { folder: PathBuf, path: PathBuf }, + /// The More row of the folder at this path. + More(PathBuf), +} + +impl PinnedKey { + /// What opening the row asks of the app, by a click, Enter or the menu's Open. + fn opened(self) -> StartAction { + match self { + PinnedKey::Folder(path) => StartAction::OpenPinned(path), + PinnedKey::File { path, .. } => StartAction::OpenPinnedFile(path), + PinnedKey::More(path) => StartAction::ExpandPinned(path), + } + } +} + +/// What a row of the pinned folders shows. +#[derive(Clone, Copy)] +enum PinnedRow<'f> { + Folder(&'f PinnedFolder), + File(&'f PinnedFile), + More { expanded: bool }, +} + +/// The files the app listed in `folder`; none while it is not listed. +fn listed_files(folder: &PinnedFolder) -> &[PinnedFile] { + match &folder.listing { + Some(FolderListing::Listed { files, .. }) => files, + _ => &[], + } +} + +/// The files of `folder` the list shows: none while folded, the first [`PINNED_FILES_SHOWN`] until expanded. +fn shown_files(folder: &PinnedFolder) -> &[PinnedFile] { + let files = listed_files(folder); + match (folder.folded, folder.expanded) { + (true, _) => &[], + (false, true) => files, + (false, false) => files.get(..PINNED_FILES_SHOWN).unwrap_or(files), + } +} + +/// The note at the end of a listed folder's heading: the state of its listing, or that the app kept only the newest +/// files; `None` for a folder whose files all show. +fn folder_note(words: &ShellWords, folder: &PinnedFolder) -> Option