From d01c739ae31dc012b037ddc7b114c3239b9753ec Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 18 Nov 2026 16:15:25 -0500 Subject: [PATCH] pdf-chrome-w14: net change of 3 commits - pdf-chrome-w14: written from its sheet - pdf-chrome-w14: repair 1 - pdf-chrome-w14: review fixes (review-1) --- crates/ui-egui/src/panels/bookmarks.rs | 673 +++++++++++-------------- crates/ui-egui/src/panels/pages.rs | 451 ++++------------- crates/ui-egui/tests/it/bookmarks.rs | 65 --- 3 files changed, 393 insertions(+), 796 deletions(-) diff --git a/crates/ui-egui/src/panels/bookmarks.rs b/crates/ui-egui/src/panels/bookmarks.rs index baf84d7b44..09bda93902 100644 --- a/crates/ui-egui/src/panels/bookmarks.rs +++ b/crates/ui-egui/src/panels/bookmarks.rs @@ -1,4 +1,17 @@ -use super::{DocInfo, Nav, OutlineItem, Rect, Sense, Tokens, icons, pos2, theme, vec2}; +use super::{Nav, PanelResult, PanelRow, PdfCraftApp}; +use craft::behavior::{DisplayOrder, GesturePhase, ItemSource, Mixed, Selection}; +use craft::keymap::CommandRef; +use craft::ui::buttons::IconButton; +use craft::ui::choice::Checkbox; +use craft::behavior::IconId; +use craft::ui::contract::{ActivateOn, Bind, CollectionEvent, Props, SelectMode, Show, ShowCollection, ShowContainer, request_rename}; +use craft::ui::primitives::IconSpec; +use craft::ui::list::{HueTarget, List, ListRow, OpenSet}; +use craft::ui::menu::{Menu, MenuItem}; +use craft::ui::notices::Notice; +use craft::ui::style::DataColor; +use craft::ui::text::TextField; +use pdfcraft_render::OutlineItem; /// What the user asked to do with a bookmark (applied after the panel is drawn). #[derive(Clone, Debug, PartialEq)] @@ -34,426 +47,310 @@ pub enum BmAction { FromTextStyles, } -/// Matching titles plus their ancestors, keeping document paths rather than filtered indexes. -/// `query` is folded with [`pdfcraft_render::text::fold_case`], as titles are here. -pub(super) fn outline_matches(items: &[OutlineItem], query: &str) -> std::collections::HashSet> { - let mut matches = std::collections::HashSet::new(); - if query.is_empty() { - return matches; +/// Outline nesting the panel lists; the engine bounds what it reads, this bounds what the panel walks. +const MAX_DEPTH: usize = 256; + +/// The id of a document's bookmark list, so a new bookmark's rename can be requested from outside the panel. +pub(crate) fn list_id(doc: pdfcraft_engine::DocId) -> egui::Id { + egui::Id::new(("bookmark-list", doc.0)) +} + +/// Asks the bookmark list of `doc` to open the rename editor on the bookmark at `path`. +pub(crate) fn start_rename(ctx: &egui::Context, doc: pdfcraft_engine::DocId, path: &[usize]) { + request_rename(ctx, list_id(doc), &path.to_vec()); +} + +/// The Bookmark options menu rows. +pub(super) fn options_menu(_app: &PdfCraftApp) -> Vec { + [ + "bookmark.from_structure", + "bookmark.from_text_styles", + "bookmark.paste", + "bookmark.expand_all", + "bookmark.collapse_all", + "bookmark.expand_level", + ] + .into_iter() + .map(|id| PanelRow::Command(CommandRef::new(id))) + .collect() +} + +/// The header's New bookmark button, shown while the document may be edited. +pub(super) fn header(app: &PdfCraftApp, ui: &mut egui::Ui) { + let editable = app.active_ids().and_then(|(_, id)| app.session.get(id)).is_some_and(|d| d.allows_assembly() && d.read_only_reason.is_none()); + if editable { + IconButton::command(IconSpec::svg(IconId::new("bookmark-plus")), CommandRef::new("bookmark.add")).show(ui); } - let mut pending: Vec<_> = items.iter().enumerate().map(|(i, item)| (vec![i], item)).collect(); - while let Some((path, item)) = pending.pop() { - if pdfcraft_render::text::fold_case(&item.title).contains(query) { - let mut ancestor = path.clone(); - while !ancestor.is_empty() { - matches.insert(ancestor.clone()); - ancestor.pop(); +} + +/// Opens the groups of `outline` shallower than `level` and closes the others: `usize::MAX` opens every group, `0` +/// closes every group. +pub(crate) fn expand_to(view: &mut crate::DocView, outline: &[OutlineItem], level: usize) { + fn walk(items: &[OutlineItem], depth: usize, level: usize, path: &mut Vec, open: &mut OpenSet>) { + if depth >= MAX_DEPTH { + return; + } + for (i, item) in items.iter().enumerate() { + path.push(i); + if !item.children.is_empty() { + open.set(path, depth < level); + walk(&item.children, depth + 1, level, path, open); } - } - for (i, child) in item.children.iter().enumerate() { - let mut child_path = path.clone(); - child_path.push(i); - pending.push((child_path, child)); + path.pop(); } } - matches + // PLAN: assumed `DocView::bookmarks_open: OpenSet>` (pdf-canvas-w8); the outline's open state lives + // on the view, not in the document. + walk(outline, 0, level, &mut Vec::new(), &mut view.bookmarks_open); } -pub(super) struct OutlineCtx<'a> { - pub(super) nav: &'a mut Option