mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 19:36:16 +00:00
Dialogs: Enter runs the default button in Find Font and the perspective grid dialogs
Find Font built its dialog without close_on_enter, so Enter in a field did nothing; it now runs Done, as the Effect Gallery and Composite Fonts dialogs do. Define Grid, Save Grid as Preset and the preset editor turned enter_confirms off. The dialog routes Enter to its enabled Accept button, which reports it as the pick of OK, so the held answer is filed as a click files it: Enter defines the grid or saves the preset, a refused name keeps the dialog open, and Enter does nothing while OK is disabled.
This commit is contained in:
@@ -482,7 +482,6 @@ impl StackDialog for GridDialog {
|
||||
.opened(Bind::bound(&mut self.open))
|
||||
.ok_enabled(finish || !self.held.is_waiting())
|
||||
.accept_stays_open(true)
|
||||
.enter_confirms(false)
|
||||
.show(ui, |ui, form, draft| {
|
||||
if finish {
|
||||
form.request_close_as(CloseReason::Activated);
|
||||
|
||||
@@ -147,6 +147,46 @@ fn define_grid_loads_and_saves_presets() {
|
||||
assert_eq!(app.session.prefs.perspective_presets.len(), 2);
|
||||
}
|
||||
|
||||
/// Enter pressed in the field that has the focus, then the passes that run the filed answer and close the dialog.
|
||||
fn enter(app: &mut VectorcraftApp) {
|
||||
let ctx = window(app);
|
||||
let key = |pressed| egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed, repeat: false, modifiers: Default::default() };
|
||||
crate::tests::synthetic::key_frame(app, &ctx, vec![key(true)]);
|
||||
crate::tests::synthetic::key_frame(app, &ctx, vec![key(false)]);
|
||||
frame(app);
|
||||
frame(app);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enter_is_ok_in_define_grid_and_save_grid_as_preset() {
|
||||
let mut app = app();
|
||||
// Define Grid: Enter in the focused field defines the grid and closes the dialog.
|
||||
app.run("ui.perspectiveGridDialog", json!({})).unwrap();
|
||||
set(&mut app, "angle", json!(30)).unwrap();
|
||||
frame(&mut app);
|
||||
frame(&mut app);
|
||||
assert!(window(&app).memory(|m| m.focused()).is_some(), "a field of the dialog has the focus");
|
||||
enter(&mut app);
|
||||
assert_eq!(kind(&app), None, "Enter closes Define Grid");
|
||||
assert!((grid(&app).viewing_angle() - 30.0).abs() < 1e-9, "Enter defines the grid");
|
||||
// Save Grid as Preset: Enter in the name field saves the preset and closes the dialog.
|
||||
app.run("ui.savePerspectivePreset", json!({})).unwrap();
|
||||
frame(&mut app);
|
||||
frame(&mut app);
|
||||
assert!(window(&app).memory(|m| m.focused()).is_some(), "a field of the dialog has the focus");
|
||||
enter(&mut app);
|
||||
assert_eq!(kind(&app), None, "Enter closes Save Grid as Preset");
|
||||
assert_eq!(app.session.prefs.perspective_presets.len(), 1, "Enter saves the preset");
|
||||
// A name the presets refuse: Enter files it, the refusal shows, and the dialog stays.
|
||||
app.run("ui.savePerspectivePreset", json!({})).unwrap();
|
||||
set(&mut app, "name", json!("[2P-Normal View]")).unwrap();
|
||||
frame(&mut app);
|
||||
frame(&mut app);
|
||||
enter(&mut app);
|
||||
assert_eq!(kind(&app).as_deref(), Some(super::perspective_grid::KIND), "a refused name keeps the dialog open");
|
||||
assert_eq!(app.session.prefs.perspective_presets.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_presets_manager_creates_edits_and_deletes_presets() {
|
||||
use super::perspective_presets::{self, Action};
|
||||
|
||||
@@ -511,7 +511,7 @@ impl StackDialog for FindFontDialog {
|
||||
.map_or_else(String::new, |f| format!("{} {} ({})", f["family"].as_str().unwrap_or(""), f["style"].as_str().unwrap_or(""), f["runs"]))
|
||||
};
|
||||
let row_text = |at: usize| shown.get(at).and_then(|&i| rows.get(i)).map_or_else(String::new, |r| row_label(&r.family, &r.style));
|
||||
let out = Dialog::new(tl!("Find Font").to_string()).buttons(buttons).show(ui, |ui, _| {
|
||||
let out = Dialog::new(tl!("Find Font").to_string()).buttons(buttons).close_on_enter(true).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
crate::panels::section(heading.clone()).show(ui, |ui, _| {
|
||||
let docs = Lines { len: count, text: &doc_text };
|
||||
@@ -1463,6 +1463,28 @@ mod tests {
|
||||
assert_eq!(row(&app)["status"], "missing");
|
||||
}
|
||||
|
||||
/// Enter in the field that has the focus is Done: the dialog closes, and no Find or Change runs.
|
||||
#[test]
|
||||
fn enter_is_done() {
|
||||
let mut app = new_app();
|
||||
app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
app.session.execute("text.create", &json!({"x": 10, "y": 40, "text": "Hi", "font": "Inter"})).unwrap();
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
let is_open = |app: &VectorcraftApp| app.dialogs().unwrap().with(|host| host.get::<FindFontDialog>().is_some());
|
||||
open(&mut app);
|
||||
crate::tests::synthetic::key_frame(&mut app, &ctx, vec![]);
|
||||
crate::tests::synthetic::key_frame(&mut app, &ctx, vec![]);
|
||||
assert!(is_open(&app));
|
||||
assert!(ctx.memory(|m| m.focused()).is_some(), "a field of the dialog has the focus");
|
||||
let undo = app.session.active().unwrap().history.undo.len();
|
||||
let key = |pressed| egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed, repeat: false, modifiers: Default::default() };
|
||||
crate::tests::synthetic::key_frame(&mut app, &ctx, vec![key(true)]);
|
||||
crate::tests::synthetic::key_frame(&mut app, &ctx, vec![key(false)]);
|
||||
crate::tests::synthetic::key_frame(&mut app, &ctx, vec![]);
|
||||
assert!(!is_open(&app), "Enter closes Find Font");
|
||||
assert_eq!(app.session.active().unwrap().history.undo.len(), undo, "Enter changes no font");
|
||||
}
|
||||
|
||||
/// Another document in front, and pattern editing entered and canceled, each give the list of
|
||||
/// the document in front as it is then.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user