Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge PR #1035: The status bar's error count opens the Preflight panel

aionggc71749264388
diff --cc crates/ui-egui/src/chrome.rs
index 790545ca9,5855b3f9a..da05cfef1
--- a/crates/ui-egui/src/chrome.rs
+++ b/crates/ui-egui/src/chrome.rs
@@@ -799,22 -709,21 +799,21 @@@ pub fn status_bar(app: &mut DesignApp,
4.0,
if errors == 0 { Color32::from_rgb(60, 200, 90) } else { Color32::from_rgb(235, 50, 50) },
);
- crate::rtl::label(
- ui,
- egui::RichText::new(if errors == 0 {
- format!("{} ▾", crate::i18n::tr(&app.ui.language, "No errors"))
- } else {
- format!(
- "{} ▾",
- crate::i18n::count_label(
- &app.ui.language,
- if errors == 1 && !crate::i18n::category_first(&app.ui.language) { "error" } else { "errors" },
- errors
- )
- )
- })
- .font(small.clone()),
- );
+ let count = if errors == 0 {
+ format!("{} ▾", crate::i18n::tr(&app.ui.language, "No errors"))
+ } else {
+ format!(
+ "{} ▾",
- crate::i18n::count_label(&app.ui.language, if errors == 1 && app.ui.language != "uk" { "error" } else { "errors" }, errors)
++ crate::i18n::count_label(&app.ui.language, if errors == 1 && !crate::i18n::category_first(&app.ui.language) { "error" } else { "errors" }, errors)
+ )
+ };
+ // As in InDesign, the count opens a menu that leads to the Preflight panel.
+ crate::menus::menu_button(ui, egui::RichText::new(count).font(small.clone()), |ui| {
+ if ui.button(crate::i18n::tr(&app.ui.language, "Preflight Panel…")).clicked() {
+ let _ = app.run("window.panel", json!({"panel": "preflight"}));
+ ui.close();
+ }
+ });
ui.add_space(12.0);
ui.label(egui::RichText::new(&app.ui.status).font(small).color(t.text_dim));
});
@@@ -1114,113 -894,26 +1113,129 @@@ mod tests
app
}
+ /// A document with a rectangle selected, so the object controls are enabled.
+ fn app_with_selection() -> crate::DesignApp {
+ let mut app = app();
+ app.run("file.new", serde_json::json!({})).unwrap();
+ app.run("frame.create", serde_json::json!({"rect": [72, 72, 300, 200]})).unwrap();
+ app.run("edit.selectAll", serde_json::json!({})).unwrap();
+ app
+ }
+
+ /// The rect of an object Control panel group.
+ fn group(h: &egui_kittest::Harness<'static, test_window::Window>, id: &str) -> egui::Rect {
+ h.ctx.read_response(egui::Id::new(("object_control", id))).unwrap().rect
+ }
+
+ /// The rect of the node with this label, preferring the one in the Control bar's row: the
+ /// Properties panel has buttons with the same names.
fn rect(h: &egui_kittest::Harness<'static, test_window::Window>, label: &str) -> egui::Rect {
- h.get_by_label(label).rect()
+ let bar = test_window::panel_rect(h, "control_bar");
+ h.query_all_by_label(label).map(|n| n.rect()).find(|r| bar.y_range().contains(r.center().y)).unwrap_or_else(|| h.get_by_label(label).rect())
+ }
+
+ /// The application bar's search field (German interface).
+ fn search_node<'h>(h: &'h egui_kittest::Harness<'static, test_window::Window>) -> egui_kittest::Node<'h> {
+ h.get_by(|n| n.role() == egui::accesskit::Role::TextInput && n.placeholder() == Some("Suchen"))
+ }
+
+ /// A document with two frames, the Selection tool, German menus, and the search field clicked.
+ fn searching() -> egui_kittest::Harness<'static, test_window::Window> {
+ let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.ui.language = "de".into();
+ let mut h = test_window::open(app, vec2(1440.0, 900.0));
+ let app = &mut h.state_mut().app;
+ app.run("frame.create", serde_json::json!({"rect": [36, 36, 200, 200]})).unwrap();
+ app.run("frame.create", serde_json::json!({"rect": [236, 36, 400, 200]})).unwrap();
+ app.run("edit.deselectAll", serde_json::json!({})).unwrap();
+ h.run_steps(4);
+ let field = search_node(&h).rect();
+ test_window::click_at(&mut h, field.center());
+ assert!(h.ctx.memory(|m| m.has_focus(super::search_id())), "a click gives the field the keyboard");
+ h
+ }
+
+ /// A match in the search's list, whose accessible label ends in its shortcut.
+ fn row<'h>(h: &'h egui_kittest::Harness<'static, test_window::Window>, label: &'static str) -> Option<egui_kittest::Node<'h>> {
+ h.query_by(move |n| n.label().is_some_and(|l| l == label || l.starts_with(&format!("{label} "))))
+ }
+
+ fn items(h: &egui_kittest::Harness<'static, test_window::Window>) -> (usize, usize) {
+ let d = h.state().app.session.active().unwrap();
+ (d.doc.spreads.iter().flat_map(|sp| &sp.items).count(), d.selection.items.len())
+ }
+
+ #[test]
+ fn the_search_field_finds_and_runs_menu_commands() {
+ let mut h = searching();
+ h.event(egui::Event::Text("gruppier".into()));
+ h.run_steps(4);
+ assert!(row(&h, "Gruppieren").is_some(), "the German label is listed");
+ assert!(row(&h, "Gruppierung aufheben").is_some());
+ // Nothing is selected, so Group is off and Return doesn't run it.
+ assert!(row(&h, "Gruppieren").is_some_and(|n| n.accesskit_node().is_disabled()));
+ h.key_press(egui::Key::Enter);
+ h.run_steps(4);
+ assert_eq!(items(&h), (2, 0), "a disabled command doesn't run");
+ // Select both frames, then ↓ ↑ Return runs the first match, as Object › Group would.
+ h.state_mut().app.run("edit.selectAll", serde_json::json!({})).unwrap();
+ h.key_press(egui::Key::ArrowDown);
+ h.run_steps(2);
+ h.key_press(egui::Key::ArrowUp);
+ h.run_steps(2);
+ h.key_press(egui::Key::Enter);
+ h.run_steps(4);
+ assert_eq!(items(&h).0, 1, "the two frames are grouped");
+ assert!(row(&h, "Gruppieren").is_none(), "the matches closed");
+ assert!(!h.ctx.memory(|m| m.has_focus(super::search_id())), "the field gave the keyboard back");
+ }
+
+ #[test]
+ fn keys_typed_in_the_search_field_stay_out_of_the_document() {
+ let mut h = searching();
+ h.state_mut().app.run("edit.selectAll", serde_json::json!({})).unwrap();
+ // Escape would switch this tool back to the Selection tool.
+ h.state_mut().app.run("tool.select", serde_json::json!({"tool": "rectangleFrame"})).unwrap();
+ h.run_steps(2);
+ // Tool keys, Delete and Backspace edit the query; the tool and the frames stay.
+ for key in [egui::Key::P, egui::Key::T, egui::Key::M, egui::Key::Delete, egui::Key::Backspace] {
+ h.key_press(key);
+ h.run_steps(2);
+ }
+ h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
+ h.run_steps(2);
+ assert_eq!(h.state().app.session.tool_id(), "rectangleFrame");
+ assert_eq!(items(&h), (2, 2), "nothing was deleted or deselected");
+ h.event(egui::Event::Text("zz-no-such-command".into()));
+ h.run_steps(4);
+ assert!(h.query_by_label("Keine passenden Befehle").is_some());
+ // Escape closes the matches and clears the field without touching the document.
+ h.key_press(egui::Key::Escape);
+ h.run_steps(4);
+ assert!(h.query_by_label("Keine passenden Befehle").is_none());
+ assert!(!h.ctx.text_edit_focused());
+ assert_eq!(h.state().app.session.tool_id(), "rectangleFrame");
+ assert_eq!(items(&h), (2, 2));
+ let field = search_node(&h);
+ assert_eq!(field.value().unwrap_or_default(), "", "the query is cleared");
}
+ /// The status bar's preflight count is a menu; its Preflight Panel entry shows the panel.
+ #[test]
+ fn status_bar_error_count_opens_the_preflight_panel() {
+ let mut app = app();
+ app.run("file.new", serde_json::json!({})).unwrap();
+ app.ui.dock_tab = "properties".into();
+ let mut h = test_window::open(app, vec2(1200.0, 700.0));
+ h.get_by_label("No errors ▾").click();
+ h.run_steps(3);
+ h.get_by_label("Preflight Panel…").click();
+ h.run_steps(3);
+ // Preflight is not a dock tab: `window.panel` shows it as its own panel.
+ assert_eq!(h.state().app.ui.open_panel.as_deref(), Some("preflight"));
+ h.get_by_label("Preflight");
+ }
+
/// A very long document name made its tab grow past the window, hiding the close button
/// and the tabs after it (#603).
#[test]