UI: keyboard shortcuts for dialog answers
Unsaved Changes: Enter is Save, Cmd+Backspace is Don't Save. Revert Project: Cmd+R is Revert (the button is now red). Delete Items: Cmd+D is Delete. Crash recovery: Enter is Open Auto-Save. Marker: Enter is OK, Cmd+Backspace is Delete (from a focused text field too). The macOS menu bar hands Cmd+D and Cmd+R back to the open prompt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
67434e9038
commit
50eddc1207
@@ -124,6 +124,8 @@ fn text_field(ui: &mut egui::Ui, app: &mut EffectcraftApp, id: &str, v: &mut Str
|
||||
pub fn dialog(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
let mut d = app.dialog_state.marker.clone();
|
||||
let (mut ok, mut cancel, mut delete) = (false, false, false);
|
||||
// Cmd+Backspace (Ctrl elsewhere) is Delete, in a text field too.
|
||||
let delete_key = super::dialogs::ui_command_key(ctx, egui::Key::Backspace);
|
||||
let title = d.title.clone();
|
||||
super::dialogs::modal(ctx, &title, vec2(520.0, 560.0), t, |ui| {
|
||||
egui::Grid::new("marker-grid").num_columns(2).spacing([12.0, 8.0]).show(ui, |ui| {
|
||||
@@ -217,7 +219,9 @@ pub fn dialog(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
});
|
||||
});
|
||||
app.dialog_state.marker = d.clone();
|
||||
if ok {
|
||||
delete |= delete_key && !ok && !cancel;
|
||||
// Enter is OK, unless a text field has it.
|
||||
if ok || (!cancel && !delete && super::dialogs::ui_enter(ctx)) {
|
||||
if let Err(e) = app.session.execute("markers.set", draft_params(&d)) {
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
@@ -496,5 +500,24 @@ mod tests {
|
||||
assert_eq!(m["label"], "Blue");
|
||||
app.session.undo();
|
||||
assert_eq!(app.session.execute("markers.list", json!({})).unwrap()[0]["chapter"], "");
|
||||
// Enter is OK and Cmd+Backspace is Delete.
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install(&ctx, &app.tokens, crate::i18n::language(&app));
|
||||
app.dialog_state.marker.chapter = "Entered".into();
|
||||
crate::panels::dialogs::press_key(&mut app, &ctx, egui::Key::Enter, egui::Modifiers::NONE);
|
||||
assert!(app.dialog.is_none());
|
||||
assert_eq!(app.session.execute("markers.list", json!({})).unwrap()[0]["chapter"], "Entered");
|
||||
open_dialog(&mut app, MarkerRef { layer: None, index: 0 }).unwrap();
|
||||
// Also from a focused text field: Tab to one, then press the key.
|
||||
for _ in 0..40 {
|
||||
if ctx.egui_wants_keyboard_input() {
|
||||
break;
|
||||
}
|
||||
crate::panels::dialogs::press_key(&mut app, &ctx, egui::Key::Tab, egui::Modifiers::NONE);
|
||||
}
|
||||
assert!(ctx.egui_wants_keyboard_input(), "a text field has focus");
|
||||
crate::panels::dialogs::press_key(&mut app, &ctx, egui::Key::Backspace, egui::Modifiers::COMMAND);
|
||||
assert!(app.dialog.is_none());
|
||||
assert_eq!(app.session.execute("markers.list", json!({})).unwrap().as_array().map(Vec::len), Some(0), "deleted");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user