mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 19:36:16 +00:00
Dialogs: Enter runs the default button in Recolor Artwork and Graph Data
Recolor Artwork and Graph Data turned enter_confirms off, so Enter in a field that does not use Enter did nothing. The dialog now routes that Enter to its enabled OK button, the same path a click takes, and the held answer is filed: in Recolor Artwork, Enter is OK and the dialog closes; in Graph Data, Enter is Apply and the window stays open. The Graph Data entry box and the sheet still take Enter to move the picked cell down, and nothing is applied. Enter does nothing while OK is disabled.
This commit is contained in:
@@ -712,7 +712,6 @@ impl StackDialog for GraphDataDialog {
|
||||
.ok_label(tl!("Apply"))
|
||||
.ok_enabled(!held.is_waiting())
|
||||
.accept_stays_open(true)
|
||||
.enter_confirms(false)
|
||||
// The sheet owns the scroll; the controls above it stay in view.
|
||||
.collection_body(true)
|
||||
.shaped(|dialog| dialog.initial_focus(Initial::Default))
|
||||
@@ -1015,6 +1014,41 @@ mod tests {
|
||||
assert!(app.dialogs().is_some_and(|d| d.with(|host| host.is_open::<GraphDataDialog>())));
|
||||
}
|
||||
|
||||
/// Enter in the entry box and in the sheet moves the picked cell down and applies nothing. Enter in a field that
|
||||
/// does not use it is Apply: the graph is redrawn and the window stays open.
|
||||
#[test]
|
||||
fn enter_moves_in_the_entry_box_and_the_sheet_and_applies_elsewhere() {
|
||||
let (mut app, id) = app_with(",a,b\nQ1,1,2\nQ2,3,4\nQ3,5,6", "column");
|
||||
let before = data(&mut app, id);
|
||||
open(&mut app).unwrap();
|
||||
set_field(&app, "sel", json!([1, 1])).unwrap();
|
||||
let mut h = harness(app);
|
||||
h.run_steps(4);
|
||||
// The entry box.
|
||||
h.get_by_label("Cell Value").click();
|
||||
h.run_steps(2);
|
||||
edit(h.state(), |d| d.entry.text = "9".into());
|
||||
h.key_press(egui::Key::Enter);
|
||||
h.run_steps(3);
|
||||
assert_eq!(read(h.state(), |d| (active(&d.state), cell_of(&d.sheet.grid, 1, 1))), ((2, 1), "9".to_string()), "Enter moves down");
|
||||
assert_eq!(data(h.state_mut(), id), before, "Enter in the entry box applies nothing");
|
||||
// The sheet.
|
||||
h.get_by_label("Q1").click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(read(h.state(), |d| active(&d.state)), (1, 0), "the click picks the cell");
|
||||
h.key_press(egui::Key::Enter);
|
||||
h.run_steps(3);
|
||||
assert_eq!(read(h.state(), |d| active(&d.state)), (2, 0), "Enter moves down in the sheet");
|
||||
assert_eq!(data(h.state_mut(), id), before, "Enter in the sheet applies nothing");
|
||||
// A field that does not use Enter.
|
||||
h.get_by_label("Column Width").click();
|
||||
h.run_steps(2);
|
||||
h.key_press(egui::Key::Enter);
|
||||
h.run_steps(4);
|
||||
assert_eq!(data(h.state_mut(), id)["rows"][0][0], json!(9.0), "Enter applies the sheet");
|
||||
assert!(h.state().dialogs().is_some_and(|d| d.with(|host| host.is_open::<GraphDataDialog>())), "the window stays open");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_entry_box_writes_its_text_and_moves_the_picked_cell() {
|
||||
let (mut app, id) = app_with(",a,b\nQ1,1,2", "column");
|
||||
|
||||
@@ -1807,10 +1807,7 @@ impl RecolorDialog {
|
||||
let mut preview = self.fields.bool("preview");
|
||||
let footer = ResetFooter::new(ui, None, true);
|
||||
let RecolorDialog { fields, feed, filed, ends, row_menu, .. } = self;
|
||||
// PLAN: Enter is not OK here: a form whose OK stays open closes on Enter without reporting it as its OK
|
||||
// (form_dialogs/form.rs:429, :534), which would close a held dialog unanswered; the forms owner makes
|
||||
// `FormDialog` report Enter as the pick of OK when `accept_stays_open` is on.
|
||||
let mut form = FormDialog::new(tl!(TITLE), Bind::bound(fields)).accept_stays_open(true).enter_confirms(false).ok_enabled(!waiting);
|
||||
let mut form = FormDialog::new(tl!(TITLE), Bind::bound(fields)).accept_stays_open(true).ok_enabled(!waiting);
|
||||
if art {
|
||||
form = form.preview(Some(Bind::bound(&mut preview)));
|
||||
}
|
||||
|
||||
@@ -103,6 +103,11 @@ impl Recolor {
|
||||
self
|
||||
}
|
||||
|
||||
/// The widget that has the keyboard focus.
|
||||
pub(crate) fn focused(&self) -> Option<egui::Id> {
|
||||
self.fixture.focused()
|
||||
}
|
||||
|
||||
/// Sets `field` as `ui.dialog.set` does, before the next frame; a refused value leaves the
|
||||
/// dialog as it was.
|
||||
pub(crate) fn set(&mut self, field: &str, value: Value) -> Result<(), String> {
|
||||
|
||||
@@ -235,6 +235,25 @@ fn the_dialog_reduces_previews_and_applies_as_one_undo_step() {
|
||||
assert_eq!(colors(&mut r.app()), 5);
|
||||
}
|
||||
|
||||
/// Enter in the field that has the focus is OK: the color group is made with the name typed, and the dialog closes.
|
||||
#[test]
|
||||
fn enter_in_a_field_is_ok() {
|
||||
let mut r = open(app(), json!({"colors": ["#ff8000", "#0080ff"]}));
|
||||
r.settled();
|
||||
r.set("groupName", json!("Enter Group")).unwrap();
|
||||
r.settled();
|
||||
r.click_label("Color Group:");
|
||||
r.settled();
|
||||
assert!(r.focused().is_some(), "a field of the dialog has the focus");
|
||||
let groups = r.app().session.doc().unwrap().doc.swatch_groups.len();
|
||||
key(&mut r, Key::Enter);
|
||||
assert!(!r.is_open(), "Enter closes Recolor Artwork");
|
||||
let app = r.app();
|
||||
let doc = &app.session.doc().unwrap().doc;
|
||||
assert_eq!(doc.swatch_groups.len(), groups + 1, "Enter makes the color group, as OK does");
|
||||
assert_eq!(doc.swatch_groups.last().map(|g| g.name.as_str()), Some("Enter Group"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn presets_open_colour_jobs_and_libraries_and_both_tabs_draw() {
|
||||
let mut app = app();
|
||||
|
||||
Reference in New Issue
Block a user