mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-12-01 02:36:02 +01:00
Merge pull request #8485 from codeiou/command-palette-runs
fix(ui): the command palette runs what is picked in it
This commit is contained in:
7 files changed
+103
-10
No files matched your search
@@ -108,7 +108,6 @@ fn palette_entries(app: &PdfCraftApp, ctx: &egui::Context) -> Vec<HelpEntry> {
|
||||
let mut entries = app.menu_bar(ctx).help_entries(Target::current(), &crate::menus::layout_options());
|
||||
for group in TOOL_GROUPS {
|
||||
if group.availability == Availability::Ready {
|
||||
// PLAN: assumed `tool.group` reads a `group` parameter (pdf-chrome-w9)
|
||||
let select = CommandRef::with_params("tool.group", serde_json::json!({ "group": group.id }));
|
||||
entries.push(HelpEntry::new(select, tl!(group.label)).with_path([tl!("Tool")]));
|
||||
}
|
||||
|
||||
@@ -261,6 +261,13 @@ impl PdfCraftApp {
|
||||
self.select_tool(ctx, g.id);
|
||||
}
|
||||
}
|
||||
// The palette's tool rows (`chrome::mode_bar`) name the group in a parameter.
|
||||
"tool.group" => {
|
||||
let group = fired.command.params.get("group").and_then(serde_json::Value::as_str).and_then(pdfcraft_engine::catalog::group);
|
||||
if let Some(g) = group {
|
||||
self.select_tool(ctx, g.id);
|
||||
}
|
||||
}
|
||||
_ => return false,
|
||||
}
|
||||
true
|
||||
|
||||
@@ -122,7 +122,10 @@ pub(crate) fn shared_catalog(mac: bool) -> Option<AppCatalog> {
|
||||
/// The command state for this frame: the gate, the catalog and a state row for every command. The rows go into the
|
||||
/// app's tracked states (`PdfCraftApp::command_states`) only when one changed, so the runtime reads them again only then.
|
||||
pub(crate) fn command_input(app: &mut PdfCraftApp, ctx: &egui::Context) -> CommandInput {
|
||||
let gated = menus::gated(app);
|
||||
// The dialogs and prompts `modal_open` counts gate every command. The palette doesn't: it lists and runs the
|
||||
// commands as the window under it has them, closing before the pick runs, and its modal layer keeps the keys from
|
||||
// them while it is open.
|
||||
let gated = app.modal_open();
|
||||
// Edit ▸ Paste asks the platform for the clipboard in the pass the row is picked, as production's menu did, and
|
||||
// reaches the app with what it holds, as ⌘V does. Organize pastes its own picked pages and Prepare Form its own
|
||||
// fields, at once, as `run_fired` sends them.
|
||||
|
||||
@@ -297,8 +297,9 @@ pub(crate) fn layout_options() -> LayoutOptions<'static> {
|
||||
LayoutOptions::new(APP_NAME).label(&translate)
|
||||
}
|
||||
|
||||
/// Whether a dialog, a prompt or the command palette holds the window: the one gate over commands
|
||||
/// and the menus.
|
||||
/// Whether a dialog, a prompt or the command palette holds the window: the gate over the menu bar's
|
||||
/// keys and the native menu. The command gate (`commands::catalog::command_input`) leaves the
|
||||
/// palette out, so the palette lists and runs the commands as the window under it has them.
|
||||
pub(crate) fn gated(app: &PdfCraftApp) -> bool {
|
||||
app.modal_open() || app.palette_open
|
||||
}
|
||||
@@ -313,7 +314,7 @@ pub(crate) fn text_editing(ctx: &egui::Context) -> bool {
|
||||
impl PdfCraftApp {
|
||||
/// The app's menus for this frame, before the platform layout: every item's label, shortcut,
|
||||
/// enabled and checked state follow the item's command (`commands::catalog::command_input`). A
|
||||
/// modal dialog doesn't grey anything here; that is the command gate's job ([`gated`]).
|
||||
/// modal dialog doesn't grey anything here; the command gate there does.
|
||||
pub fn menu_bar(&self, ctx: &egui::Context) -> MenuBar {
|
||||
let mac = crate::commands::mac_shortcuts(ctx);
|
||||
let mut used: Vec<&str> = Vec::new();
|
||||
|
||||
@@ -468,6 +468,90 @@ fn the_pages_menu_comes_from_the_registry() {
|
||||
assert_eq!(app.session.get(app.views[0].id).unwrap().info.pages.len(), 2);
|
||||
}
|
||||
|
||||
/// The palette runs what is picked in it, by Enter or by a click: a command's row is enabled as the window under the
|
||||
/// palette has it, since the palette closes before the command runs, and a tool's row opens that tool.
|
||||
#[test]
|
||||
fn the_palette_runs_what_is_picked_in_it() {
|
||||
use egui_kittest::kittest::NodeT;
|
||||
// Ctrl+K, type `query`, then Enter or a click on the row labelled `label`, which must be enabled.
|
||||
fn pick(h: &mut Harness<'static, PdfCraftApp>, query: &str, label: &str, click: bool) {
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::K);
|
||||
h.run_steps(3);
|
||||
assert!(palette_open(h), "Ctrl+K opens the palette");
|
||||
h.event(egui::Event::Text(query.into()));
|
||||
h.run_steps(2);
|
||||
{
|
||||
let row = h.get_by(|n| n.role() == egui::accesskit::Role::ListBoxOption && n.label().is_some_and(|l| l.starts_with(label)));
|
||||
assert!(!row.accesskit_node().is_disabled(), "the palette lists {label} enabled");
|
||||
if click {
|
||||
row.click();
|
||||
} else {
|
||||
h.key_press(Key::Enter);
|
||||
}
|
||||
}
|
||||
h.run_steps(3);
|
||||
assert!(!palette_open(h), "the palette closed with the pick of {label}");
|
||||
}
|
||||
let mut h = harness();
|
||||
let id = h.state().views[0].id;
|
||||
let rotation = |h: &Harness<'static, PdfCraftApp>| h.state().session.get(id).unwrap().info.pages[0].rotation;
|
||||
pick(&mut h, "rotate pages clockwise", "Rotate pages clockwise", false);
|
||||
assert_eq!(rotation(&h), 90, "Enter ran the command");
|
||||
pick(&mut h, "rotate pages clockwise", "Rotate pages clockwise", true);
|
||||
assert_eq!(rotation(&h), 180, "a click on the row ran it");
|
||||
pick(&mut h, "redact a pdf", "Redact a PDF", false);
|
||||
assert_eq!(h.state().left, pdfcraft_ui_egui::LeftPanel::Tool("redact"), "the tool's row opened the tool");
|
||||
}
|
||||
|
||||
/// While the palette is open it holds the window: a shortcut runs no command under it, Ctrl+Z with nothing to undo in
|
||||
/// its field leaves the document's last edit alone, and the toolbar's buttons under it can't be pressed.
|
||||
#[test]
|
||||
fn the_open_palette_holds_the_window() {
|
||||
use egui_kittest::kittest::NodeT;
|
||||
let mut h = harness();
|
||||
let id = h.state().views[0].id;
|
||||
let rotation = |h: &Harness<'static, PdfCraftApp>| h.state().session.get(id).unwrap().info.pages[0].rotation;
|
||||
let print_disabled =
|
||||
|h: &Harness<'static, PdfCraftApp>| h.get_by_role_and_label(egui::accesskit::Role::Button, "Print…").accesskit_node().is_disabled();
|
||||
assert!(h.execute("page.rotate"));
|
||||
h.run_steps(3);
|
||||
assert_eq!(rotation(&h), 90);
|
||||
assert!(!print_disabled(&h), "Print… is enabled with a document open");
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::K);
|
||||
h.run_steps(3);
|
||||
assert!(palette_open(&h), "Ctrl+K opens the palette");
|
||||
assert!(print_disabled(&h), "the toolbar's Print… is disabled under the palette");
|
||||
for key in [Key::Z, Key::L, Key::Backslash] {
|
||||
h.key_press_modifiers(Modifiers::COMMAND, key);
|
||||
h.run_steps(3);
|
||||
}
|
||||
assert_eq!(rotation(&h), 90, "Ctrl+Z in the palette's field undid nothing in the document");
|
||||
assert!(!h.state().full_screen(), "Ctrl+L left the window as it was");
|
||||
assert_eq!(h.state().views.len(), 1, "Ctrl+\\ split no view");
|
||||
assert!(palette_open(&h), "the palette is still open");
|
||||
}
|
||||
|
||||
/// A dialog that opens over the open palette (as automation or a prompt can) disables the palette's rows: the command
|
||||
/// gate still counts dialogs, though no longer the palette itself.
|
||||
#[test]
|
||||
fn a_dialog_over_the_open_palette_disables_its_rows() {
|
||||
use egui_kittest::kittest::NodeT;
|
||||
let mut h = harness();
|
||||
let row_disabled = |h: &Harness<'static, PdfCraftApp>| {
|
||||
let row =
|
||||
h.get_by(|n| n.role() == egui::accesskit::Role::ListBoxOption && n.label().is_some_and(|l| l.starts_with("Rotate pages clockwise")));
|
||||
row.accesskit_node().is_disabled()
|
||||
};
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::K);
|
||||
h.run_steps(3);
|
||||
h.event(egui::Event::Text("rotate pages clockwise".into()));
|
||||
h.run_steps(2);
|
||||
assert!(!row_disabled(&h), "the row is enabled with no dialog open");
|
||||
assert!(h.execute("app.preferences"));
|
||||
h.run_steps(3);
|
||||
assert!(row_disabled(&h), "Preferences over the palette disables the row");
|
||||
}
|
||||
|
||||
/// Check that Open Recent lists a recorded file and opens it in a new active tab without replacing the
|
||||
/// original.
|
||||
#[test]
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
//! Split view: an edit made after both views drew their frame (#3149) leaves neither showing the
|
||||
//! old page.
|
||||
|
||||
use crate::support::AppHarness as _;
|
||||
use craft::ui::primitives::textures::TextureState; // PLAN: assumed facade path of `TextureState`
|
||||
use egui::{Key, Modifiers};
|
||||
use egui_kittest::Harness;
|
||||
@@ -45,7 +44,6 @@ fn page_size(s: &PdfCraftApp, i: usize) -> Option<egui::Vec2> {
|
||||
/// The palette runs its command after the page area was drawn, as a dialog's OK does: the page
|
||||
/// turns after both views drew the old one. Both panes must end up drawing the turned page, never
|
||||
/// the stale portrait one.
|
||||
#[ignore = "known gap of the egui-to-craft port: see docs/port-known-gaps.md"]
|
||||
#[test]
|
||||
fn a_late_edit_turns_the_page_in_both_panes() {
|
||||
let mut h = harness();
|
||||
@@ -58,9 +56,11 @@ fn a_late_edit_turns_the_page_in_both_panes() {
|
||||
wait(&mut h, "both panes drawn", |s| portrait(s, 0) && portrait(s, 1));
|
||||
let id = h.state().views[0].id;
|
||||
let rotation = |h: &Harness<'static, PdfCraftApp>| h.state().session.get(id).unwrap().info.pages[0].rotation;
|
||||
h.set_option("palette", "rotate pages clockwise").unwrap();
|
||||
h.run_steps(2);
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::K);
|
||||
h.run_steps(3);
|
||||
assert!(h.state().palette_open);
|
||||
h.event(egui::Event::Text("rotate pages clockwise".into()));
|
||||
h.run_steps(2);
|
||||
h.key_press(Key::Enter);
|
||||
// Frame by frame, to look at the one that turned the page.
|
||||
for _ in 0..10 {
|
||||
|
||||
@@ -9,4 +9,3 @@ fixed. Framework items (F-n) are in the port workspace's follow-up list.
|
||||
| `editing::paragraph_edges_and_frames_are_caught_without_aiming_for_the_hairline` | a click off the text doesn't apply the typing | F-115 follow-up: the edge band and the click-off rule overlap |
|
||||
| `marks::the_preview_shows_the_page_the_range_selects_under_the_marks` | the stamp preview doesn't show the selected page | F-161: the preview overlay's clip is inverted and its geometry a pass behind |
|
||||
| `panel_snapshots::every_panel_matches_its_snapshot` | all 11 accessibility-tree snapshots differ after updating the dock queries | L-298 defers pixel snapshots; these text snapshots need separate review |
|
||||
| `split_view_render::a_late_edit_turns_the_page_in_both_panes` | the palette does not turn the page | the port's palette control ignores the search value; production puts it in the query, which the shared palette now keeps in its own session. Typing the query and pressing Enter or activating the matching row also left rotation at zero; the pane rendering assertion has not yet been reached |
|
||||
Reference in new issue
Block a user