PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
feat(ui): pinned tools section on Home
Combiler016f9ec0f5764f
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 6eceff17e..0deaf2dd9 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -79,6 +79,7 @@ fn dialogs(app: &mut PdfCraftApp, ctx: &egui::Context) {Dialog::Print => 820.0,Dialog::FieldProps | Dialog::BulkFieldProps => 600.0,Dialog::About => 780.0,+ Dialog::PinTool => 540.0,_ => 520.0,});match dialog {@@ -1123,6 +1124,91 @@ fn dialogs(app: &mut PdfCraftApp, ctx: &egui::Context) {}}}+ Dialog::PinTool => {+ ui.horizontal(|ui| {+ ui.label(egui::RichText::new(tl!("Pin tools to Home")).font(theme::semibold(18.0)));+ ui.with_layout(Layout::right_to_left(Align::Center), |ui| {+ if widgets::ghost_button(ui, "x", tl!("Close")).clicked() {+ close = true;+ }+ });+ });+ ui.add_space(4.0);+ ui.label(egui::RichText::new(tl!("Select tools to display on your Home page for quick access.")).color(t.text_muted));+ ui.add_space(10.0);++ ui.horizontal(|ui| {+ let (icon_rect, _) = ui.allocate_exact_size(egui::vec2(18.0, 18.0), egui::Sense::hover());+ crate::icons::paint(ui, icon_rect, "search", 16.0, t.text_muted);+ ui.add(+ egui::TextEdit::singleline(&mut app.pin_tool_search)+ .hint_text(tl!("Search tools…"))+ .desired_width(ui.available_width() - 32.0),+ );+ if !app.pin_tool_search.is_empty() && widgets::ghost_button(ui, "x", tl!("Clear search")).clicked() {+ app.pin_tool_search.clear();+ }+ });+ ui.add_space(8.0);+ ui.separator();+ ui.add_space(6.0);++ let query = app.pin_tool_search.trim().to_lowercase();+ egui::ScrollArea::vertical().max_height(380.0).auto_shrink([false, true]).show(ui, |ui| {+ let mut toggle = None;+ for g in pdfcraft_engine::catalog::TOOL_GROUPS {+ let label = tl!(g.label);+ let blurb = g+ .sections+ .first()+ .map(|s| s.items.iter().take(4).map(|i| tl!(i.label)).collect::<Vec<_>>().join(" · "))+ .unwrap_or_default();+ if !query.is_empty()+ && !label.to_lowercase().contains(&query)+ && !blurb.to_lowercase().contains(&query)+ && !g.id.to_lowercase().contains(&query)+ {+ continue;+ }++ let pinned = app.is_tool_pinned(g.id);+ let (rect, resp) = ui.allocate_exact_size(egui::vec2(ui.available_width(), 44.0), egui::Sense::click());+ let press = theme::Press::track(ui, &resp);+ press.wash(ui, rect, 6, false);+ let body = rect.translate(press.offset());++ let color = egui::Color32::from_rgb(g.hue[0], g.hue[1], g.hue[2]);+ crate::icons::paint(ui, egui::Rect::from_min_size(body.min + egui::vec2(8.0, 11.0), egui::vec2(22.0, 22.0)), g.icon, 20.0, color);++ let btn_w = 78.0;+ let btn_rect = egui::Rect::from_center_size(body.right_center() - egui::vec2(btn_w / 2.0 + 8.0, 0.0), egui::vec2(btn_w, 26.0));+ let btn_resp = ui.interact(btn_rect, ui.id().with(("pin_modal_btn", g.id)), egui::Sense::click());+ let btn_hovered = btn_resp.hovered();++ let (btn_fill, btn_stroke, text_color, btn_label) = if pinned {+ (t.accent, egui::Stroke::NONE, egui::Color32::WHITE, tl!("Pinned"))+ } else if btn_hovered {+ (t.hover, egui::Stroke::new(1.0, t.border), t.text, tl!("Pin"))+ } else {+ (egui::Color32::TRANSPARENT, egui::Stroke::new(1.0, t.border), t.text_muted, tl!("Pin"))+ };++ ui.painter().rect(btn_rect, egui::CornerRadius::same(6), btn_fill, btn_stroke, egui::StrokeKind::Inside);+ ui.painter().text(btn_rect.center(), egui::Align2::CENTER_CENTER, btn_label, theme::medium(12.0), text_color);++ let max_w = (btn_rect.left() - body.left() - 44.0).max(10.0);+ widgets::row_text(ui, body.min + egui::vec2(38.0, 6.0), label, theme::semibold(13.5), t.text, max_w);+ widgets::row_text(ui, body.min + egui::vec2(38.0, 24.0), &blurb, theme::regular(11.0), t.text_muted, max_w);++ if btn_resp.clicked() || resp.clicked() {+ toggle = Some(g.id);+ }+ }+ if let Some(id) = toggle {+ app.toggle_pin_tool(id);+ }+ });+ }}ui.add_space(16.0);let changed = draft_changes(app).is_some_and(|c| !c.is_empty());@@ -1136,6 +1222,10 @@ fn dialogs(app: &mut PdfCraftApp, ctx: &egui::Context) {recover = Some(false);close = true;}+ } else if dialog == Dialog::PinTool {+ if widgets::pill_button(ui, tl!("Done"), true).clicked() {+ close = true;+ }} else if dialog == Dialog::NumberPages {if widgets::pill_button(ui, tl!("OK"), true).clicked() {apply_number = true;diff --git a/crates/ui-egui/src/home.rs b/crates/ui-egui/src/home.rsindex 3e70f34e4..5fdcd51ff 100644--- a/crates/ui-egui/src/home.rs+++ b/crates/ui-egui/src/home.rs@@ -18,6 +18,74 @@ fn card_lift(ui: &egui::Ui, t: &Tokens, rect: Rect, press: theme::Press) {}}+/// Render a single tool card with the standard lift, styling, icon, title, description, and action.+/// If `allow_unpin` is true, an unpin button appears on hover in the top right corner.+fn tool_card(+ app: &mut PdfCraftApp,+ ui: &mut egui::Ui,+ t: &Tokens,+ g: &'static catalog::ToolGroup,+ allow_unpin: bool,+) -> Option<&'static str> {+ let (rect, resp) = ui.allocate_exact_size(vec2(190.0, 104.0), Sense::click());+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tl!(g.label)));+ let press = theme::Press::track(ui, &resp);+ card_lift(ui, t, rect, press);+ let fill = press.fill(t.card, t.hover, t.pressed);+ ui.painter().rect(rect, CornerRadius::same(10), fill, Stroke::new(1.0, t.divider), egui::StrokeKind::Inside);+ let body = rect.translate(press.offset());+ let color = egui::Color32::from_rgb(g.hue[0], g.hue[1], g.hue[2]);+ icons::paint(ui, Rect::from_min_size(body.min + vec2(14.0, 14.0), vec2(22.0, 22.0)), g.icon, 21.0, color);++ let mut unpin_clicked = false;+ if allow_unpin && (ui.rect_contains_pointer(rect) || resp.hovered()) {+ let unpin_rect = Rect::from_center_size(body.right_top() + vec2(-18.0, 18.0), vec2(22.0, 22.0));+ let unpin_resp = ui.interact(unpin_rect, ui.id().with(("unpin_card_btn", g.id)), Sense::click());+ unpin_resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tl!("Unpin tool")));+ if unpin_resp.hovered() {+ ui.painter().rect_filled(unpin_rect, CornerRadius::same(4), t.pressed);+ }+ icons::paint(ui, unpin_rect.shrink(4.0), "x", 14.0, t.icon);+ if unpin_resp.on_hover_text(tl!("Unpin from Home")).clicked() {+ unpin_clicked = true;+ }+ }++ let mut title_job = egui::text::LayoutJob::simple_singleline(tl!(g.label).to_owned(), theme::semibold(13.5), t.text);+ title_job.wrap =+ egui::text::TextWrapping { max_width: body.width() - 58.0, max_rows: 1, break_anywhere: true, ..Default::default() };+ let title = ui.fonts_mut(|f| f.layout_job(title_job));+ let title_elided = title.elided;+ ui.painter().galley(body.min + vec2(44.0, 25.0 - title.size().y * 0.5), title, t.text);+ let blurb = g+ .sections+ .first()+ .map(|s| s.items.iter().take(3).map(|i| tl!(i.label)).collect::<Vec<_>>().join(" · "))+ .unwrap_or_default();+ // Fixed-height cards must leave room for their action in every language.+ let mut job = egui::text::LayoutJob::simple(blurb.clone(), theme::regular(11.5), t.text_muted, body.width() - 28.0);+ job.wrap.max_rows = 2;+ let galley = ui.fonts_mut(|f| f.layout_job(job));+ let blurb_elided = galley.elided;+ ui.painter().galley(body.min + vec2(14.0, 46.0), galley, t.text_muted);+ ui.painter().text(+ body.left_bottom() + vec2(14.0, -14.0),+ Align2::LEFT_CENTER,+ tl!("Use now"),+ theme::medium(12.0),+ t.accent_text,+ );+ let resp = if title_elided || blurb_elided { resp.on_hover_text(format!("{}\n{blurb}", tl!(g.label))) } else { resp };+ if unpin_clicked {+ Some(g.id)+ } else {+ if theme::hand(resp).clicked() {+ app.select_tool(g.id);+ }+ None+ }+}+pub fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) {let t = Tokens::get(ui.ctx());egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| {@@ -63,43 +131,7 @@ pub fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) {ui.spacing_mut().item_spacing = vec2(14.0, 14.0);for id in RECOMMENDED {let Some(g) = catalog::group(id) else { continue };- let (rect, resp) = ui.allocate_exact_size(vec2(190.0, 104.0), Sense::click());- resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tl!(g.label)));- let press = theme::Press::track(ui, &resp);- card_lift(ui, &t, rect, press);- let fill = press.fill(t.card, t.hover, t.pressed);- ui.painter().rect(rect, CornerRadius::same(10), fill, Stroke::new(1.0, t.divider), egui::StrokeKind::Inside);- let body = rect.translate(press.offset());- let color = egui::Color32::from_rgb(g.hue[0], g.hue[1], g.hue[2]);- icons::paint(ui, Rect::from_min_size(body.min + vec2(14.0, 14.0), vec2(22.0, 22.0)), g.icon, 21.0, color);- let mut title_job = egui::text::LayoutJob::simple_singleline(tl!(g.label).to_owned(), theme::semibold(13.5), t.text);- title_job.wrap =- egui::text::TextWrapping { max_width: body.width() - 58.0, max_rows: 1, break_anywhere: true, ..Default::default() };- let title = ui.fonts_mut(|f| f.layout_job(title_job));- let title_elided = title.elided;- ui.painter().galley(body.min + vec2(44.0, 25.0 - title.size().y * 0.5), title, t.text);- let blurb = g- .sections- .first()- .map(|s| s.items.iter().take(3).map(|i| tl!(i.label)).collect::<Vec<_>>().join(" · "))- .unwrap_or_default();- // Fixed-height cards must leave room for their action in every language.- let mut job = egui::text::LayoutJob::simple(blurb.clone(), theme::regular(11.5), t.text_muted, body.width() - 28.0);- job.wrap.max_rows = 2;- let galley = ui.fonts_mut(|f| f.layout_job(job));- let blurb_elided = galley.elided;- ui.painter().galley(body.min + vec2(14.0, 46.0), galley, t.text_muted);- ui.painter().text(- body.left_bottom() + vec2(14.0, -14.0),- Align2::LEFT_CENTER,- tl!("Use now"),- theme::medium(12.0),- t.accent_text,- );- let resp = if title_elided || blurb_elided { resp.on_hover_text(format!("{}\n{blurb}", tl!(g.label))) } else { resp };- if theme::hand(resp).clicked() {- app.select_tool(g.id);- }+ tool_card(app, ui, &t, g, false);}let (rect, resp) = ui.allocate_exact_size(vec2(170.0, 104.0), Sense::click());resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tl!("Open file")));@@ -121,6 +153,39 @@ pub fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) {});});+ ui.add_space(26.0);+ let mut unpin_tool = None;+ ui.horizontal(|ui| {+ ui.label(egui::RichText::new(tl!("Pinned Tools")).font(theme::semibold(17.0)));+ ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {+ if widgets::ghost_button(ui, "pin", tl!("Pin a tool…")).clicked() {+ app.dialog = Some(crate::Dialog::PinTool);+ }+ });+ });+ ui.add_space(4.0);+ if app.pinned_tools.is_empty() {+ ui.label(+ egui::RichText::new(tl!("Pin your favorite tools here for quick access."))+ .color(t.text_muted),+ );+ } else {+ ui.add_space(6.0);+ let pinned = app.pinned_tools.clone();+ ui.horizontal_wrapped(|ui| {+ ui.spacing_mut().item_spacing = vec2(14.0, 14.0);+ for id in &pinned {+ let Some(g) = catalog::group(id) else { continue };+ if let Some(to_unpin) = tool_card(app, ui, &t, g, true) {+ unpin_tool = Some(to_unpin);+ }+ }+ });+ }+ if let Some(id) = unpin_tool {+ app.unpin_tool(id);+ }+#[cfg(not(target_arch = "wasm32"))]{ui.add_space(26.0);diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 49fb3b5fc..2535adae8 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -338,6 +338,8 @@ pub enum Dialog {AuditSpace,/// Signatures ▸ Show certificate.CertificateViewer,+ /// Pin tools to Home: selection modal.+ PinTool,}#[derive(Clone, Copy, Debug, PartialEq, Eq)]@@ -574,6 +576,10 @@ pub struct PdfCraftApp {open_prepare_gate: Option<std::sync::Arc<open_worker::PrepareGate>>,/// Folders pinned to Home, and what they held when last listed.pub pinned: folders_ui::PinnedFolders,+ /// Tools pinned to Home, in user-defined order.+ pub pinned_tools: Vec<String>,+ /// Search query for the Pin a tool selection dialog.+ pub pin_tool_search: String,pub toast: Option<(String, f64)>,/// Whether the macOS title bar is drawn by us (traffic lights over our tab strip).pub integrated_titlebar: bool,@@ -922,6 +928,8 @@ impl PdfCraftApp {#[cfg(all(test, not(target_arch = "wasm32")))]open_prepare_gate: None,pinned: Default::default(),+ pinned_tools: Vec::new(),+ pin_tool_search: String::new(),toast: None,integrated_titlebar: false,window_controls: None,@@ -2026,6 +2034,48 @@ impl PdfCraftApp {self.pending_panel_reveals.push(docking::Panel::Tools);}+ /// Check whether a tool group is pinned to Home.+ pub fn is_tool_pinned(&self, id: &str) -> bool {+ self.pinned_tools.iter().any(|t| t == id)+ }++ /// Pin a tool group to Home. Returns true if newly pinned.+ pub fn pin_tool(&mut self, id: &str) -> bool {+ if pdfcraft_engine::catalog::group(id).is_none() {+ return false;+ }+ if !self.is_tool_pinned(id) {+ self.pinned_tools.push(id.to_string());+ if let Some(g) = pdfcraft_engine::catalog::group(id) {+ self.notify_fmt("Pinned {tool} to Home", &[("tool", tl!(g.label))]);+ }+ true+ } else {+ false+ }+ }++ /// Remove a tool group from Home.+ pub fn unpin_tool(&mut self, id: &str) {+ if let Some(pos) = self.pinned_tools.iter().position(|t| t == id) {+ self.pinned_tools.remove(pos);+ if let Some(g) = pdfcraft_engine::catalog::group(id) {+ self.notify_fmt("Unpinned {tool} from Home", &[("tool", tl!(g.label))]);+ }+ }+ }++ /// Toggle a tool group's pinned state on Home.+ pub fn toggle_pin_tool(&mut self, id: &str) -> bool {+ if self.is_tool_pinned(id) {+ self.unpin_tool(id);+ false+ } else {+ self.pin_tool(id);+ true+ }+ }+/// Enter a tool from the catalogue, Home, palette or control channel. Organize is a/// workspace, so opening its panel also opens the page grid (without toggling it off).pub(crate) fn select_tool(&mut self, id: &'static str) {@@ -2111,6 +2161,7 @@ impl PdfCraftApp {"reload_changed_files": self.reload_changed_files,"system_title_bar": self.system_title_bar,"pinned_folders": self.pinned.folders,+ "pinned_tools": self.pinned_tools,"theme": self.theme_preference,"scroll_speed": self.scroll_speed,"animation_effects": self.animation_effects,@@ -2200,6 +2251,15 @@ impl PdfCraftApp {self.reload_changed_files = on;}self.pinned.restore(&v["pinned_folders"]);+ if let Some(items) = v.get("pinned_tools").and_then(serde_json::Value::as_array) {+ let mut tools = Vec::new();+ for item in items.iter().filter_map(serde_json::Value::as_str) {+ if pdfcraft_engine::catalog::group(item).is_some() && !tools.contains(&item.to_string()) {+ tools.push(item.to_string());+ }+ }+ self.pinned_tools = tools;+ }if let Ok(preference) = serde_json::from_value::<ThemePreference>(v["theme"].clone()) {self.set_theme_preference(preference);}diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rsindex 7cd417d86..71e6e14e0 100644--- a/crates/ui-egui/src/panels.rs+++ b/crates/ui-egui/src/panels.rs@@ -58,7 +58,11 @@ fn all_tools(app: &mut PdfCraftApp, ui: &mut egui::Ui, t: &Tokens) {egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| {let shown = if app.all_tools_expanded { TOOL_GROUPS.len() } else { COLLAPSED_TOOLS.min(TOOL_GROUPS.len()) };for g in &TOOL_GROUPS[..shown] {- if tool_row(ui, t, g).clicked() {+ let pinned = app.is_tool_pinned(g.id);+ let (resp, pin_clicked) = tool_row(ui, t, g, pinned);+ if pin_clicked {+ app.toggle_pin_tool(g.id);+ } else if resp.clicked() {app.select_tool(g.id);}}@@ -89,21 +93,29 @@ fn row_label(ui: &mut egui::Ui, text: &str, font: egui::FontId, color: Color32,elided}-fn tool_row(ui: &mut egui::Ui, t: &Tokens, g: &ToolGroup) -> egui::Response {+fn tool_row(ui: &mut egui::Ui, t: &Tokens, g: &ToolGroup, is_pinned: bool) -> (egui::Response, bool) {let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 34.0), Sense::click());resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tl!(g.label)));let press = theme::Press::track(ui, &resp);press.wash(ui, rect, 6, false);let body = rect.translate(press.offset());icons::paint(ui, Rect::from_min_size(body.min + vec2(6.0, 7.0), vec2(20.0, 20.0)), g.icon, 19.0, hue(g));- let right_reserved = match (g.badge, g.availability) {- (Some(b), _) => ui.fonts_mut(|f| f.layout_no_wrap(tl!(b).to_owned(), theme::semibold(9.5), Color32::WHITE).size().x) + 26.0,++ let pin_rect = Rect::from_center_size(body.right_center() - vec2(14.0, 0.0), vec2(22.0, 22.0));+ let pin_resp = ui.interact(pin_rect, ui.id().with(("pin_toggle_row", g.id)), Sense::click());+ let pin_hovered = pin_resp.hovered();+ let mut pin_clicked = false;++ let pin_space = 26.0;+ let badge_or_hint_reserved = match (g.badge, g.availability) {+ (Some(b), _) => ui.fonts_mut(|f| f.layout_no_wrap(tl!(b).to_owned(), theme::semibold(9.5), Color32::WHITE).size().x) + 18.0,(None, Availability::Planned(m)) if resp.hovered() => {let hint = format!("{} · {m}", tl!("Planned"));- ui.fonts_mut(|f| f.layout_no_wrap(hint, theme::medium(10.5), t.text_faint).size().x) + 18.0+ ui.fonts_mut(|f| f.layout_no_wrap(hint, theme::medium(10.5), t.text_faint).size().x) + 10.0}- _ => 8.0,+ _ => 0.0,};+ let right_reserved = pin_space + badge_or_hint_reserved + 8.0;let clipped =row_label(ui, tl!(g.label), theme::regular(13.5), t.text, body.left_center() + vec2(36.0, 0.0), rect.width() - 36.0 - right_reserved);match (g.badge, g.availability) {@@ -111,14 +123,14 @@ fn tool_row(ui: &mut egui::Ui, t: &Tokens, g: &ToolGroup) -> egui::Response {let font = theme::semibold(9.5);let badge = tl!(b);let w = ui.fonts_mut(|f| f.layout_no_wrap(badge.to_string(), font.clone(), Color32::WHITE).size().x);- let r = Rect::from_center_size(body.right_center() - vec2(w / 2.0 + 10.0, 0.0), vec2(w + 10.0, 16.0));+ let r = Rect::from_center_size(body.right_center() - vec2(pin_space + w / 2.0 + 4.0, 0.0), vec2(w + 10.0, 16.0));ui.painter().rect_filled(r, CornerRadius::same(4), t.badge_new);ui.painter().text(r.center(), Align2::CENTER_CENTER, badge, font, Color32::WHITE);}// Planned tools: a quiet milestone hint instead of a chip, so the list stays calm.(None, Availability::Planned(m)) if resp.hovered() => {ui.painter().text(- body.right_center() - vec2(10.0, 0.0),+ body.right_center() - vec2(pin_space + 4.0, 0.0),Align2::RIGHT_CENTER,format!("{} · {m}", tl!("Planned")),theme::medium(10.5),@@ -127,13 +139,34 @@ fn tool_row(ui: &mut egui::Ui, t: &Tokens, g: &ToolGroup) -> egui::Response {}_ => {}}++ let row_hovered = ui.rect_contains_pointer(rect) || resp.hovered();+ if is_pinned || row_hovered || pin_hovered {+ if pin_hovered {+ ui.painter().rect_filled(pin_rect, CornerRadius::same(4), t.pressed);+ }+ let pin_tint = if is_pinned {+ t.accent_text+ } else if pin_hovered {+ t.text+ } else {+ t.text_faint+ };+ icons::paint(ui, pin_rect.shrink(3.0), "pin", 15.0, pin_tint);+ let tip = if is_pinned { tl!("Unpin from Home") } else { tl!("Pin to Home") };+ pin_resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tip));+ if theme::hand(pin_resp).on_hover_text(tip).clicked() {+ pin_clicked = true;+ }+ }+let tip = match g.availability {Availability::Ready => tl!("Available").to_string(),Availability::Planned(m) => format!("{} {m} — {}", tl!("Planned for milestone"), tl!("open to see what it will include")),Availability::Provider => tl!("Optional: needs an AI provider you configure").into(),};let tip = if clipped { format!("{} — {tip}", tl!(g.label)) } else { tip };- theme::hand(resp).on_hover_text(tip)+ (theme::hand(resp).on_hover_text(tip), pin_clicked)}fn tool_detail(app: &mut PdfCraftApp, ui: &mut egui::Ui, t: &Tokens, g: &'static ToolGroup) {diff --git a/crates/ui-egui/tests/pinned_tools.rs b/crates/ui-egui/tests/pinned_tools.rsnew file mode 100644index 000000000..55c84bc52--- /dev/null+++ b/crates/ui-egui/tests/pinned_tools.rs@@ -0,0 +1,163 @@+//! Pinned tools on Home: pin tools, unpin tools, persistence across sessions,+//! selection modal, and the sidebar pin toggle.++use egui_kittest::Harness;+use egui_kittest::kittest::Queryable;+use pdfcraft_ui_egui::{Dialog, LeftPanel, PdfCraftApp};++fn harness(setup: impl FnOnce(&mut PdfCraftApp) + 'static) -> Harness<'static, PdfCraftApp> {+ let mut h = Harness::builder().with_size(egui::vec2(1400.0, 1000.0)).build_eframe(move |_cc| {+ let mut app = PdfCraftApp::new();+ app.set_option("language", "en").unwrap();+ app.run_inline = true;+ setup(&mut app);+ app+ });+ h.run_steps(4);+ h+}++#[test]+fn state_operations_and_validation() {+ let mut app = PdfCraftApp::new();+ assert!(!app.is_tool_pinned("redact"));++ // Pinning a valid tool+ assert!(app.pin_tool("redact"));+ assert!(app.is_tool_pinned("redact"));+ assert_eq!(app.pinned_tools, vec!["redact"]);++ // Pinning already pinned tool returns false (no duplicates)+ assert!(!app.pin_tool("redact"));+ assert_eq!(app.pinned_tools, vec!["redact"]);++ // Pinning an invalid tool returns false+ assert!(!app.pin_tool("invalid_tool_unknown_id"));+ assert_eq!(app.pinned_tools, vec!["redact"]);++ // Pinning a second valid tool+ assert!(app.pin_tool("form"));+ assert_eq!(app.pinned_tools, vec!["redact", "form"]);++ // Unpinning+ app.unpin_tool("redact");+ assert!(!app.is_tool_pinned("redact"));+ assert!(app.is_tool_pinned("form"));+ assert_eq!(app.pinned_tools, vec!["form"]);++ // Unpinning non-existent tool does nothing+ app.unpin_tool("nonexistent");+ assert_eq!(app.pinned_tools, vec!["form"]);++ // Toggling+ assert!(!app.toggle_pin_tool("form")); // unpins+ assert!(!app.is_tool_pinned("form"));+ assert!(app.pinned_tools.is_empty());++ assert!(app.toggle_pin_tool("form")); // pins+ assert!(app.is_tool_pinned("form"));+ assert_eq!(app.pinned_tools, vec!["form"]);+}++#[test]+fn persistence_round_trip_and_sanitization() {+ let mut app = PdfCraftApp::new();+ app.pin_tool("protect");+ app.pin_tool("redact");++ let saved = app.persist();+ assert!(saved.contains("\"pinned_tools\""));++ let mut restored = PdfCraftApp::new();+ restored.restore(&saved);+ assert_eq!(restored.pinned_tools, vec!["protect", "redact"]);++ // Test sanitization: unknown tools are discarded and duplicates are removed, preserving order+ let malicious_or_corrupt = serde_json::json!({+ "pinned_tools": ["redact", "nonexistent_junk", "redact", "edit", "another_unknown", "protect"]+ })+ .to_string();+ restored.restore(&malicious_or_corrupt);+ assert_eq!(restored.pinned_tools, vec!["redact", "edit", "protect"]);+}++#[test]+fn home_shows_pinned_tools_section_and_placeholder() {+ let mut h = harness(|_| {});+ // When no tools are pinned, the placeholder message appears+ h.get_by_label_contains("Pinned Tools");+ h.get_by_label_contains("Pin your favorite tools here for quick access.");+ h.get_by_label("Pin a tool…");++ // Pin a tool and step forward+ h.state_mut().pin_tool("redact");+ h.run_steps(3);++ // Placeholder is gone and Redact card is shown+ assert!(h.query_by_label_contains("Pin your favorite tools here for quick access.").is_none());+ assert!(h.query_all_by_label("Redact a PDF").count() >= 1);++ // Unpin tool and verify placeholder returns+ h.state_mut().unpin_tool("redact");+ h.run_steps(3);+ h.get_by_label_contains("Pin your favorite tools here for quick access.");+}++#[test]+fn clicking_pinned_tool_card_selects_it() {+ let mut h = harness(|app| {+ app.pin_tool("redact");+ });+ h.run_steps(2);++ // The Redact card is rendered and can be clicked to select the tool+ let nodes: Vec<_> = h.query_all_by_label("Redact a PDF").collect();+ assert!(!nodes.is_empty());+ // Click the card+ nodes.last().unwrap().click();+ h.run_steps(3);++ // Redact tool panel is now active+ assert_eq!(h.state().left, LeftPanel::Tool("redact"));+}++#[test]+fn pin_tool_dialog_workflow() {+ let mut h = harness(|app| {+ app.dialog = Some(Dialog::PinTool);+ });+ h.run_steps(3);++ // Modal is open+ h.get_by_label_contains("Pin tools to Home");+ h.get_by_label("Done");++ // Pin a tool from inside the dialog+ assert!(!h.state().is_tool_pinned("scan"));+ h.state_mut().toggle_pin_tool("scan");+ assert!(h.state().is_tool_pinned("scan"));+ h.run_steps(2);++ // Close dialog with "Done"+ h.get_by_label("Done").click();+ h.run_steps(2);+ assert!(h.state().dialog.is_none());+}++#[test]+fn sidebar_pin_toggle_unpins_and_pins() {+ let mut h = harness(|app| {+ app.pin_tool("redact");+ });+ h.run_steps(2);+ assert!(h.state().is_tool_pinned("redact"));++ // Since redact is pinned, the pin toggle is rendered in the sidebar with "Unpin from Home"+ let unpin_btn = h.get_by_label("Unpin from Home");+ unpin_btn.click();+ h.run_steps(3);++ assert!(!h.state().is_tool_pinned("redact"));+ // Left panel did not navigate away (still AllTools)+ assert_eq!(h.state().left, LeftPanel::AllTools);+}