diff --git a/crates/ui-egui/src/app/catalog.rs b/crates/ui-egui/src/app/catalog.rs index 732940ae9..f1936d41e 100644 --- a/crates/ui-egui/src/app/catalog.rs +++ b/crates/ui-egui/src/app/catalog.rs @@ -65,6 +65,7 @@ pub static UI_COMMANDS: &[UiCommand] = &[ UiCommand { id: "app.palette", label: "Command Palette", params: "{}" }, UiCommand { id: "app.preferences", label: "Preferences…", params: "{}" }, UiCommand { id: "app.openDialog", label: "Open…", params: "{purpose?}" }, + UiCommand { id: "app.forgetRecent", label: "Remove from Recent", params: "{path} → {recent: [paths]}" }, UiCommand { id: "app.insertPictureDialog", label: "Picture from File…", params: "{}" }, UiCommand { id: "app.smartArtPictureDialog", label: "Insert Picture in Diagram…", params: "{id?, index}" }, UiCommand { id: "app.changePictureDialog", label: "Change Picture…", params: "{}" }, diff --git a/crates/ui-egui/src/app/commands.rs b/crates/ui-egui/src/app/commands.rs index a837af7f2..c23094b50 100644 --- a/crates/ui-egui/src/app/commands.rs +++ b/crates/ui-egui/src/app/commands.rs @@ -285,6 +285,14 @@ impl SlideApp { } "app.preferences" => self.open_dialog("preferences", p.clone()), "app.openDialog" => self.pick_and_open(), + "app.forgetRecent" => { + let path = p.get("path").and_then(Value::as_str).ok_or("missing `path`")?; + if !self.ui.recent.iter().any(|recent| recent == path) { + return Err(format!("`{path}` is not in the Recent list")); + } + self.forget_recent(path); + return Ok(json!({"recent": self.ui.recent})); + } "app.insertPictureDialog" => self.pick_and_insert("picture", "insert.picture"), "app.smartArtPictureDialog" => { if !self.host.files().can_pick() { diff --git a/crates/ui-egui/src/backstage.rs b/crates/ui-egui/src/backstage.rs index 969f67593..9abe00eaa 100644 --- a/crates/ui-egui/src/backstage.rs +++ b/crates/ui-egui/src/backstage.rs @@ -7,7 +7,7 @@ //! [`SlideApp::print_pdf`], [`SlideApp::save_as_dialog`]); the state here is UI-only and never //! saved. Recent presentations are listed by path: nothing on disk is read until one is picked. -use craft::menu::ribbon::{BackstageEntry, BackstageEvent, BackstageView}; +use craft::menu::ribbon::{BackLook, BackstageEntry, BackstageEvent, BackstageView}; use craft::ui::contract::{BodyCx, Show as _}; use craft::ui::display::Text; use egui::Ui; @@ -315,7 +315,13 @@ pub(crate) fn page(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_>) { let bottom = view_entries(bottom); // Measuring does not consume the request: the real pass takes it once. let focus_shown = !craft::ui::runtime::measure::active(ui.ctx()) && std::mem::take(&mut bs.focus_shown); - let mut view = BackstageView::new(Nav::Page(bs.page)).back(has_doc).group(&first).group(&document).bottom(&bottom).focus_shown(focus_shown); + let mut view = BackstageView::new(Nav::Page(bs.page)) + .back(has_doc) + .back_look(BackLook::Glyph) + .group(&first) + .group(&document) + .bottom(&bottom) + .focus_shown(focus_shown); if bs.page != Page::Home { view = view.heading(bs.page.label()); } diff --git a/crates/ui-egui/src/backstage/files.rs b/crates/ui-egui/src/backstage/files.rs index 7366902cb..d3cf477a5 100644 --- a/crates/ui-egui/src/backstage/files.rs +++ b/crates/ui-egui/src/backstage/files.rs @@ -11,7 +11,7 @@ use craft::ui::layout_components::{Row, Stack}; use craft::ui::list::{List, ListRow, ThumbAspect, ThumbSize}; use craft::ui::sections::Section; -use craft::ui::shell::{RecentFile, RecentList, StartAction}; +use craft::ui::shell::{RecentFile, RecentList, RecentRemove, StartAction}; use craft::ui::style::TypeRole; use craft::ui::text::TextField; use craft::ui::tile_grid::{CardText, Tile, TileGrid}; @@ -161,7 +161,9 @@ fn recent_actions(app: &mut SlideApp, actions: Vec) { for action in actions { match action { StartAction::OpenRecent(path) => app.open_path_in_background(&path.to_string_lossy()), - StartAction::RemoveRecent(path) => app.forget_recent(&path.to_string_lossy()), + StartAction::RemoveRecent(path) => { + let _ = app.run("app.forgetRecent", json!({"path": path.to_string_lossy()})); + } StartAction::ClearRecent => app.ui.recent.clear(), #[cfg(not(target_arch = "wasm32"))] StartAction::RevealRecent(path) if craft::platform::open::CAN_REVEAL => { @@ -197,10 +199,11 @@ pub(super) fn home(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs: &m let files = recent_files(app, &bs.query); let empty = recent_empty(&bs.query); let shown = RecentList::new(&files) + .remove(RecentRemove::Always) .max_recent(8) .empty(empty) .controls(|ui, _| { - let _ = TextField::search("Search for a file", Bind::bound(&mut bs.query)).show(ui); + let _ = TextField::search("Search for a file", Bind::bound(&mut bs.query)).placeholder("Search for a file").show(ui); }) .show(ui); recent_actions(app, shown.actions); @@ -214,7 +217,7 @@ pub(super) fn home(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs: &m pub(super) fn new_page(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs: &mut Backstage) { show_tiles(app, ui, "Blank presentation", &[NewTile::blank()], true); let _ = Divider::horizontal().show(ui); - let _ = TextField::search("Search for themes and templates", Bind::bound(&mut bs.query)).show(ui); + let _ = TextField::search("Search for themes and templates", Bind::bound(&mut bs.query)).placeholder("Search for themes and templates").show(ui); let themes = theme_tiles(&bs.query, usize::MAX, false); let templates = template_tiles(&bs.query, usize::MAX); show_tiles(app, ui, "Themes", &themes, false); @@ -264,9 +267,9 @@ pub(super) fn open_page(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, b }); let _ = Divider::vertical().show(ui); Stack::new().fill_width().show(ui, |ui, _| { - let _ = TextField::search("Search for a file", Bind::bound(&mut bs.query)).show(ui); + let _ = TextField::search("Search for a file", Bind::bound(&mut bs.query)).placeholder("Search for a file").show(ui); let files = recent_files(app, &bs.query); - let shown = RecentList::new(&files).heading("Presentations").empty(recent_empty(&bs.query)).show(ui); + let shown = RecentList::new(&files).remove(RecentRemove::Always).heading("Presentations").empty(recent_empty(&bs.query)).show(ui); recent_actions(app, shown.actions); }); }); diff --git a/crates/ui-egui/src/backstage/info.rs b/crates/ui-egui/src/backstage/info.rs index 69c167ea9..ef2cf1acb 100644 --- a/crates/ui-egui/src/backstage/info.rs +++ b/crates/ui-egui/src/backstage/info.rs @@ -1,6 +1,6 @@ use super::{Backstage, Icon, Outcome, Page, SlideApp, Ui, Value, json}; use crate::app::files::SaveOutcome; -use craft::behavior::{ColumnWidth, IconId}; +use craft::behavior::ColumnWidth; use craft::ui::buttons::{Arrangement, Button, Link}; use craft::ui::contract::{Bind, BodyCx, Entry, FieldLayout, LabelScheme, Props as _, Show as _, ShowContainer as _, Sizing, WrapWidth}; use craft::ui::display::{Picture, Shade, Text}; @@ -42,7 +42,7 @@ pub(super) const PROPERTIES: [(&str, &str, &str); 7] = [ pub(super) fn task_row(ui: &mut Ui, icon: Icon, label: &'static str, title: &'static str, detail: &'static str, enabled: bool) -> bool { Row::new() .show(ui, |ui, _| { - let pressed = Button::new(label).icon(IconId::new(icon.name())).arrangement(Arrangement::Stacked).enabled(enabled).show(ui).clicked(); + let pressed = Button::new(label).icon(icon.id()).arrangement(Arrangement::Stacked).enabled(enabled).show(ui).clicked(); Stack::new().wrap_width(WrapWidth::Column).show(ui, |ui, _| { Text::new(title).role(TypeRole::Heading).show(ui); Text::new(detail).shade(Shade::Muted).show(ui); diff --git a/crates/ui-egui/src/backstage/print.rs b/crates/ui-egui/src/backstage/print.rs index 5ca33c1d6..a1089fe5c 100644 --- a/crates/ui-egui/src/backstage/print.rs +++ b/crates/ui-egui/src/backstage/print.rs @@ -288,7 +288,7 @@ fn choose( row = row.lines(detail); } if let Some(icon) = icon { - row = row.icon(craft::behavior::IconId::new(icon.name()).into()); + row = row.icon(icon.id().into()); } row }); @@ -331,12 +331,7 @@ pub(super) fn export(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs: Text::new("• Opens on any device with a PDF viewer").show(ui); Text::new("• The presentation keeps its own file").show(ui); Checkbox::new(Bind::bound(&mut bs.pdf_hidden)).label("Include hidden slides").show(ui); - if Button::new("Create PDF") - .icon(craft::behavior::IconId::new(Icon::File.name())) - .arrangement(Arrangement::Stacked) - .show(ui) - .clicked() - { + if Button::new("Create PDF").icon(Icon::File.id()).arrangement(Arrangement::Stacked).show(ui).clicked() { app.export_as("pdf", json!({"includeHidden": bs.pdf_hidden})); } } @@ -357,12 +352,7 @@ pub(super) fn export(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs: Field::new("Slides per page").show(ui, |ui, _| { Select::new("Slides per page", Bind::bound(&mut bs.handouts_per_page), &entries).show(ui); }); - if Button::new("Create Handouts") - .icon(craft::behavior::IconId::new(Icon::Notes.name())) - .arrangement(Arrangement::Stacked) - .show(ui) - .clicked() - { + if Button::new("Create Handouts").icon(Icon::Notes.id()).arrangement(Arrangement::Stacked).show(ui).clicked() { app.export_as("pdf", json!({"layout": "handouts", "perPage": bs.handouts_per_page})); } } @@ -379,7 +369,7 @@ pub(super) fn export(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs: .show(ui); } if Button::new("Save As") - .icon(craft::behavior::IconId::new(Icon::SaveAs.name())) + .icon(Icon::SaveAs.id()) .arrangement(Arrangement::Stacked) .enabled(types.iter().any(|entry| entry.0 == bs.file_type)) .show(ui) diff --git a/crates/ui-egui/src/backstage/tests.rs b/crates/ui-egui/src/backstage/tests.rs index 4368057ab..635411ce5 100644 --- a/crates/ui-egui/src/backstage/tests.rs +++ b/crates/ui-egui/src/backstage/tests.rs @@ -139,12 +139,13 @@ fn open_lists_recent_files_and_opens_one() { h.state_mut().ui.recent = vec![path.clone(), dir.join("Other.pptx").to_string_lossy().to_string()]; h.state_mut().run("app.backstage", json!({"page": "open"})).unwrap(); h.run_steps(3); - assert!(h.query_by_label_contains("Other.pptx").is_some()); + // The row and its remove button both name the file. + assert!(h.query_all_by_label_contains("Other.pptx").next().is_some()); h.get_by_role_and_label(Role::TextInput, "Search for a file").click(); h.run_steps(2); h.get_by_role_and_label(Role::TextInput, "Search for a file").type_text("quarter"); h.run_steps(2); - assert!(h.query_by_label_contains("Other.pptx").is_none(), "the search filters by file name"); + assert!(h.query_all_by_label_contains("Other.pptx").next().is_none(), "the search filters by file name"); page_choice(&h, "Quarterly review.pptx").click(); wait_for_open(&mut h); assert_eq!(h.state().session.documents().len(), 2); @@ -154,6 +155,24 @@ fn open_lists_recent_files_and_opens_one() { let _ = std::fs::remove_dir_all(&dir); } +/// A recent row's remove button and the automation command drop only that file, and the command refuses a path that +/// is not in the list instead of reporting success. +#[test] +fn a_recent_row_removes_its_file_through_the_command() { + let mut h = new_app(); + let (kept, removed) = ("/decks/kept.pptx".to_string(), "/decks/removed.pptx".to_string()); + h.state_mut().ui.recent = vec![kept.clone(), removed.clone()]; + h.state_mut().run("app.backstage", json!({"page": "open"})).unwrap(); + h.run_steps(3); + h.get_by_role_and_label(Role::Button, "Remove removed.pptx from Recent").click(); + h.run_steps(3); + assert_eq!(h.state().ui.recent, vec![kept.clone()], "the clicked row's file left the list"); + assert!(h.query_all_by_label_contains("removed.pptx").next().is_none(), "its row is gone"); + assert!(h.state_mut().run("app.forgetRecent", json!({"path": removed})).is_err(), "a path not in the list is an error"); + let reply = h.state_mut().run("app.forgetRecent", json!({"path": kept})).unwrap(); + assert_eq!(reply["recent"], json!([])); +} + #[test] fn save_as_and_export_run_the_file_commands() { let files = Arc::new(ScriptedFiles::new().saving_suggested()); diff --git a/crates/ui-egui/src/sizes.json b/crates/ui-egui/src/sizes.json index 8bd8d12d0..5f5f4241f 100644 --- a/crates/ui-egui/src/sizes.json +++ b/crates/ui-egui/src/sizes.json @@ -1,11 +1,14 @@ { "all": { "radius.surface": 8, + "size.page.column": 1180, "typography.body.size": 13, "typography.body_strong.size": 13, "typography.caption.size": 11, "typography.heading.line_height": 24, "typography.heading.size": 18, - "typography.label.size": 13 + "typography.label.size": 13, + "typography.title.line_height": 24, + "typography.title.size": 18 } } diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rs index 5589d4d0c..dce93f7fb 100644 --- a/crates/ui-egui/src/theme.rs +++ b/crates/ui-egui/src/theme.rs @@ -265,7 +265,7 @@ pub fn to_color32(c: deckcraft_color::Rgba) -> Color32 { Color32::from_rgba_unmultiplied(c.r, c.g, c.b, c.a) } -/// DeckCraft's overrides of the suite's size sets (`sizes.json`): its interface type scale and surface rounding. One +/// DeckCraft's overrides of the suite's size sets (`sizes.json`): its interface type scale, surface rounding and File page column. One /// shared value, so every root that carries it keeps one identity for the token cache. pub fn app_sizes() -> std::sync::Arc { static SIZES: std::sync::LazyLock> =