mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 15:21:17 -05:00
Menu clicks and held keys as production ran them: a menu row ending in … that carries params opens its dialog on them (Clean Up…); Enter that opens the held tool's dialog uses the tool; the window losing the keyboard ends its holds without going back; Cut, Copy and Paste take F2, F3 and F4 back when only a component's own command (a preset row's Rename) also has the key. Tests: Find and Replace and the Smooth and Simplify sliders are named by their command, a held OK is answered through the pump, the colour picker is read by its key, the modifier-only override test uses a tool that has a default key
This commit is contained in:
@@ -162,7 +162,12 @@ impl<'a> SessionTool<'a> {
|
||||
// Nothing selected: it fails and nothing opens (the menu item is disabled then too).
|
||||
let _ = crate::toolbar::open_options(&mut app, &tool);
|
||||
}
|
||||
open(&app) > before
|
||||
let opened = open(&app) > before;
|
||||
// The dialog uses the tool a held key chose.
|
||||
if opened {
|
||||
crate::shortcuts::note_tool_use(&mut app);
|
||||
}
|
||||
opened
|
||||
}
|
||||
|
||||
/// A key the tool does not claim while its gesture runs: arrows and digits still reach it, with no modifier (a
|
||||
|
||||
@@ -1323,7 +1323,9 @@ fn give_back_function_keys(keymap: &mut Keymap) {
|
||||
let primary = Binding::new(primary);
|
||||
matches!(texts, [text] if Binding::parse(text).is_ok_and(|b| b == primary))
|
||||
});
|
||||
if pinned && keymap.holders(&alias).iter().all(|c| *c == command) {
|
||||
// A component's own F2 (a preset row's Rename) acts only where that component has the keys.
|
||||
let app_holder = |c: &craft::keymap::CommandRef| keymap.bindable(c).is_none_or(|d| d.scope.is_app());
|
||||
if pinned && keymap.holders(&alias).iter().filter(|c| app_holder(c)).all(|c| *c == command) {
|
||||
keymap.reset(&command);
|
||||
}
|
||||
}
|
||||
@@ -1622,8 +1624,9 @@ mod tests {
|
||||
/// one leaves the entry without a shortcut.
|
||||
#[test]
|
||||
fn saved_modifier_only_overrides_give_the_default_back() {
|
||||
let km = keymap_with(overrides(json!({"tool:groupSelection": "Shift+ShiftLeft", "edit.preferences": ""})));
|
||||
let group = command_of("tool:groupSelection");
|
||||
// The Selection tool has a default key to give back; the Group Selection tool production's test used has none.
|
||||
let km = keymap_with(overrides(json!({"tool:selection": "Shift+ShiftLeft", "edit.preferences": ""})));
|
||||
let group = command_of("tool:selection");
|
||||
assert!(!km.default_bindings(&group).is_empty());
|
||||
assert_eq!(km.bindings(&group), km.default_bindings(&group));
|
||||
assert!(!km.problems().is_empty(), "the text that is no chord is reported");
|
||||
|
||||
@@ -82,7 +82,7 @@ pub(crate) fn run_fired(app: &mut VectorcraftApp, ctx: &egui::Context, fired: &F
|
||||
crate::panels::artboards::select_all(app);
|
||||
return;
|
||||
}
|
||||
match menu_target(command) {
|
||||
match menu_target(command).or_else(|| clicked_row(app, fired.source, command)) {
|
||||
Some((id, params)) => crate::menus::invoke(app, &id, params),
|
||||
None => crate::menus::invoke(app, &command.id, shortcut_params(command)),
|
||||
}
|
||||
@@ -236,3 +236,16 @@ fn shortcut_params(c: &CommandRef) -> serde_json::Value {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
/// What a click on the menu bar's or the canvas menu's row `c` runs ([`crate::menus::click_target`]): a "…" row with
|
||||
/// params opens its dialog on them (Clean Up…). `None` for a command that no menu fired.
|
||||
fn clicked_row(app: &VectorcraftApp, source: FireSource, c: &CommandRef) -> Option<(String, serde_json::Value)> {
|
||||
if source != FireSource::Menu || c.params.as_object().is_none_or(serde_json::Map::is_empty) {
|
||||
return None;
|
||||
}
|
||||
let row = crate::menus::menu_entries(app)
|
||||
.into_iter()
|
||||
.chain(crate::menus::context_entries(app))
|
||||
.find(|e| e.command.as_deref() == Some(c.id.as_str()) && e.params == c.params)?;
|
||||
Some(crate::menus::click_target(&row.label, &c.id, &c.params))
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,12 @@ pub(super) fn release(app: &mut VectorcraftApp, ctx: &egui::Context, fired: &Fir
|
||||
/// open, goes back once that ends. Choosing another tool or turning the preference off ends every
|
||||
/// hold without going back.
|
||||
pub(super) fn follow(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
// The keys go to another window: whatever release comes later, or none, ends this window's holds without going
|
||||
// back.
|
||||
if ctx.input(|i| i.events.iter().any(|e| matches!(e, egui::Event::WindowFocused(false)))) {
|
||||
app.held_tool.retain(|h| h.viewport != ctx.viewport_id());
|
||||
return;
|
||||
}
|
||||
// Each step looks at the key held last; one that goes back hands over to the key under it.
|
||||
loop {
|
||||
let gesture = app.session.tool_busy() || app.session.pointer_held();
|
||||
|
||||
@@ -116,8 +116,21 @@ fn zoom(app: &mut VectorcraftApp) -> f64 {
|
||||
}
|
||||
|
||||
/// The key of the window's top dialog.
|
||||
/// The key of the window's top dialog, else the command of what opened in its place: the framework's Find and
|
||||
/// Replace dialog, which has no key, or the Smooth or Simplify slider, which the app shows over the canvas.
|
||||
fn dialog_kind(app: &VectorcraftApp) -> Option<String> {
|
||||
crate::tests::picks::open_dialogs(app).pop().and_then(|d| d.key)
|
||||
let find = || app.dialogs().is_some_and(|d| d.with(|h| h.is_open::<craft::text::ui::find::FindReplaceDialog>()));
|
||||
let strip = || {
|
||||
[(crate::dialogs::smooth_slider::showing(app), "object.path.smooth"), (crate::dialogs::simplify_slider::showing(app), "object.path.simplify")]
|
||||
.into_iter()
|
||||
.find_map(|(on, id)| on.then(|| id.to_string()))
|
||||
};
|
||||
match crate::tests::picks::open_dialogs(app).pop() {
|
||||
Some(d) if d.key.is_some() => d.key,
|
||||
Some(_) if find() => Some(crate::dialogs::find_replace::COMMAND.to_string()),
|
||||
Some(_) => None,
|
||||
None => strip(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The effect of the open Effect dialog, when the window's top dialog is it (its key is `effect`;
|
||||
@@ -143,9 +156,14 @@ pub(super) fn close_top_dialog(app: &mut VectorcraftApp, ok: bool) {
|
||||
// A dialog opened after the window's pass shows in its next one, and only a shown dialog takes an answer.
|
||||
key_frame(app, &ctx, vec![]);
|
||||
let id = crate::tests::picks::open_dialogs(app).pop().expect("a dialog is open").id;
|
||||
let host = app.dialogs().expect("the window's dialog host");
|
||||
assert!(host.with(|h| if ok { h.confirm_by_id(&ctx, id) } else { h.cancel_by_id(&ctx, id) }), "the dialog stayed open");
|
||||
crate::dialogs::host::pump(app, &ctx);
|
||||
if ok {
|
||||
// A dialog that holds its OK closes once the pump accepted the answer.
|
||||
crate::tests::picks::answer_dialog(app, id, &[], true);
|
||||
} else {
|
||||
app.dialogs().expect("the window's dialog host").with(|h| h.cancel_by_id(&ctx, id));
|
||||
crate::dialogs::host::pump(app, &ctx);
|
||||
}
|
||||
assert!(crate::tests::picks::open_dialogs(app).iter().all(|d| d.id != id), "the dialog stayed open");
|
||||
}
|
||||
|
||||
/// Sets `field` of the window's top dialog as a person editing it would.
|
||||
@@ -749,12 +767,13 @@ fn a_key_assigned_to_the_color_picker_opens_it_for_the_proxy_in_front() {
|
||||
let ctx = ready(&mut app);
|
||||
let key = || tap(Key::F12, cmd() | Modifiers::ALT | Modifiers::SHIFT);
|
||||
let opened = |app: &mut VectorcraftApp| {
|
||||
let stroke = (dialog_kind(app).as_deref() == Some("colorPicker")).then(|| dialog_field(app, "stroke") == Some(json!(true)));
|
||||
// The framework's picker is keyed by the paint it edits.
|
||||
let stroke = app.dialogs()?.with(|h| h.get::<craft::color_ui::ui::ColorPickerDialog>().map(|p| p.key() == "stroke"))?;
|
||||
close_top_dialog(app, false);
|
||||
stroke
|
||||
Some(stroke)
|
||||
};
|
||||
key_frame(&mut app, &ctx, key());
|
||||
assert_eq!(opened(&mut app), Some(false), "no document: the fill");
|
||||
assert_eq!(opened(&mut app), Some(false), "no document: the fill; {}", app.ui.status);
|
||||
app.run("paint.toggleActive", json!({"fill": false})).unwrap();
|
||||
key_frame(&mut app, &ctx, key());
|
||||
assert_eq!(opened(&mut app), Some(true), "the Stroke proxy in front: the stroke");
|
||||
|
||||
Reference in New Issue
Block a user