mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 19:41:36 -05:00
Keys reach tools and panels as production routed them: Enter opens a selection tool's Move dialog or what the tool asks for; while a tool's gesture runs its keys go to it and its own shortcut ends it; Escape reaches what it ends; framework sets made for other apps (blend mode, layer order, find bar, warp pins, rich text editor) give up their keys; the Tools panel and toolbars come back when shown again and Window › Toolbars checks the shown ones; Unlock All and Show All keep their Shift+Alt group alternate; Escape in Help keeps its query; dimmed rows say they are not available; the Control bar's Select Similar menu shows its ampersand and Global Edit Options closes while Global Edit runs; the app bar's search keeps production's name; an sRGB monitor profile converts nothing. Tests: dialogs keyed by their command, the window frame that builds the keymap or applies claims, production's Pen clicks, held OKs answered through the pump
This commit is contained in:
@@ -52,7 +52,7 @@ pub(crate) use raster::{KeptFrame, color_image, color_image_owned, render_job};
|
||||
pub(crate) use rulers::{general_lengths, stroke_lengths};
|
||||
pub(crate) use task_bar::{TASK_BAR_ACTIONS, TASK_BAR_CHIPS, has_colors, is_task_bar_action, read_hidden_task_bar_actions};
|
||||
pub use tool_adapter::{apply_requests, dispatch, mods};
|
||||
pub(crate) use tool_adapter::{in_gesture, pose_on_page};
|
||||
pub(crate) use tool_adapter::{busy_tool, in_gesture, pose_on_page};
|
||||
|
||||
/// Which body a document's canvas runs: the current window's interactive one, or a display-only
|
||||
/// pane of a tiled or floating window.
|
||||
|
||||
@@ -144,6 +144,68 @@ impl<'a> SessionTool<'a> {
|
||||
apply_requests(&mut app, r);
|
||||
true
|
||||
}
|
||||
|
||||
/// Enter that the tool does not claim, while no gesture runs: it takes what the tool asks of the UI (Rotate,
|
||||
/// Scale, Reflect and Shear open their dialog), and with a selection tool it opens the Move dialog, as a
|
||||
/// double-click on the tool's button does. Taken only when a dialog opened, so that Enter is not also its OK.
|
||||
fn enter(&self, mods: Mods) -> bool {
|
||||
let mut app = self.app();
|
||||
if app.session.tool_busy() {
|
||||
return false;
|
||||
}
|
||||
let open = |app: &VectorcraftApp| app.dialogs().map_or(0, |d| d.with(|h| h.open_dialogs().len()));
|
||||
let before = open(&app);
|
||||
let r = app.session.tool_key(EngineKey::Enter, mods, self.view);
|
||||
apply_requests(&mut app, r);
|
||||
let tool = app.session.tool_id().to_owned();
|
||||
if open(&app) == before && vectorcraft_tools::catalog::is_selection_tool(&tool) {
|
||||
// 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
|
||||
}
|
||||
|
||||
/// A key the tool does not claim while its gesture runs: arrows and digits still reach it, with no modifier (a
|
||||
/// grid's rows and columns, the Perspective Selection tool's planes); other keys do nothing then.
|
||||
fn busy_key(&self, key: EngineKey) -> bool {
|
||||
let mut app = self.app();
|
||||
if !busy_tool(&app) {
|
||||
return false;
|
||||
}
|
||||
if matches!(key, EngineKey::Left | EngineKey::Right | EngineKey::Up | EngineKey::Down | EngineKey::Digit(_)) {
|
||||
let r = app.session.tool_key(key, Mods::default(), self.view);
|
||||
apply_requests(&mut app, r);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// While the gesture runs, the active tool's own shortcut chooses it again between clicks, which ends the gesture
|
||||
/// (W with the Blend tool's first pick held finishes the blend); any other plain key does nothing.
|
||||
fn again(&self, chord: Chord) -> bool {
|
||||
let mut app = self.app();
|
||||
if !busy_tool(&app) {
|
||||
return false;
|
||||
}
|
||||
let active = format!("tool:{}", app.session.tool_id());
|
||||
let own = app.ui_ctx.as_ref().and_then(craft::ui::runtime::commands::keymap).is_some_and(|keymap| {
|
||||
match keymap.lookup(&chord, false, &craft::keymap::Active::NONE) {
|
||||
craft::keymap::Lookup::Run(command) => command.id == active,
|
||||
craft::keymap::Lookup::Cycle(commands) => commands.iter().any(|command| command.id == active),
|
||||
_ => false,
|
||||
}
|
||||
});
|
||||
if own && !app.session.pointer_held() {
|
||||
let tool = app.session.tool_id().to_owned();
|
||||
app.select_tool(&tool);
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the active tool's gesture runs (a press, an open pick or loop), outside text editing: production gave the
|
||||
/// keys to the tool then and ran no shortcut.
|
||||
pub(crate) fn busy_tool(app: &VectorcraftApp) -> bool {
|
||||
app.session.tool_busy() && !app.session.tool_wants_text()
|
||||
}
|
||||
|
||||
/// The engine's key for the letter or digit key `key`, from its physical name (`KeyA`, `Digit5`).
|
||||
@@ -157,6 +219,10 @@ fn engine_key(chord: Chord) -> Option<(EngineKey, bool)> {
|
||||
Key::Tab => (EngineKey::Tab, shift),
|
||||
Key::Home => (EngineKey::Home, shift),
|
||||
Key::End => (EngineKey::End, shift),
|
||||
Key::Left => (EngineKey::Left, shift),
|
||||
Key::Right => (EngineKey::Right, shift),
|
||||
Key::Up => (EngineKey::Up, shift),
|
||||
Key::Down => (EngineKey::Down, shift),
|
||||
key => {
|
||||
let name = key.code_name();
|
||||
if let Some(letter) = name.strip_prefix("Key").and_then(|l| l.chars().next()) {
|
||||
@@ -306,6 +372,10 @@ impl CanvasTool for SessionTool<'_> {
|
||||
_ => &[],
|
||||
};
|
||||
let mut claims = ToolClaims::NONE.keys(keys);
|
||||
// While a gesture runs the plain keys are the tool's: no single-key shortcut runs then.
|
||||
if busy_tool(&app) {
|
||||
claims = claims.keyboard();
|
||||
}
|
||||
if claim(&mut app, EngineKey::Delete) {
|
||||
claims = claims.deletes();
|
||||
}
|
||||
@@ -326,7 +396,7 @@ impl CanvasTool for SessionTool<'_> {
|
||||
(false, _, true) => (EngineKey::Up, Key::Up),
|
||||
(false, _, false) => (EngineKey::Down, Key::Down),
|
||||
};
|
||||
if self.send_key(k, tool_mods(*mods, space)) {
|
||||
if self.send_key(k, tool_mods(*mods, space)) || self.busy_key(k) {
|
||||
return true;
|
||||
}
|
||||
// An arrow an application command is bound to runs it, as production's keymap ran it first; one it
|
||||
@@ -345,16 +415,29 @@ impl CanvasTool for SessionTool<'_> {
|
||||
!bound
|
||||
}
|
||||
ToolKey::Delete { forward, .. } => self.send_key(if *forward { EngineKey::Delete } else { EngineKey::Backspace }, held),
|
||||
ToolKey::Submit => self.send_key(EngineKey::Enter, held),
|
||||
ToolKey::Submit => self.send_key(EngineKey::Enter, held) || self.enter(held),
|
||||
ToolKey::Cancel => {
|
||||
// In Presentation Mode Escape leaves the mode: the tool takes none.
|
||||
if self.app().ui.screen_mode == 3 {
|
||||
return false;
|
||||
}
|
||||
let ends = self.app().session.tool_ends_on_escape(self.view);
|
||||
self.send_key(EngineKey::Escape, held) || ends
|
||||
if self.send_key(EngineKey::Escape, held) {
|
||||
return true;
|
||||
}
|
||||
// What Escape ends (a loop, a path being drawn, a running gesture) gets it whether or not the tool
|
||||
// claims it.
|
||||
let mut app = self.app();
|
||||
if !ends && !app.session.tool_busy() {
|
||||
return false;
|
||||
}
|
||||
let r = app.session.tool_key(EngineKey::Escape, held, self.view);
|
||||
apply_requests(&mut app, r);
|
||||
true
|
||||
}
|
||||
ToolKey::Kept(chord) => {
|
||||
engine_key(*chord).is_some_and(|(k, shift)| self.send_key(k, Mods { shift, ..held }) || self.busy_key(k)) || self.again(*chord)
|
||||
}
|
||||
ToolKey::Kept(chord) => engine_key(*chord).is_some_and(|(k, shift)| self.send_key(k, Mods { shift, ..held })),
|
||||
ToolKey::AltTap => self.send_key(EngineKey::AltTap, held),
|
||||
_ => false,
|
||||
}
|
||||
|
||||
@@ -99,7 +99,9 @@ impl Trailing {
|
||||
Trailing::Arrange => arrange_documents(app, ui),
|
||||
Trailing::Search => {
|
||||
// PLAN: assumed `Button::command` is bound by a `&str` command id; the command opens the palette.
|
||||
// Named as production's field, not after the command's menu row.
|
||||
Button::command(PALETTE)
|
||||
.label(tl!("Search commands"))
|
||||
.icon(IconSpec::svg(IconId::new("search")))
|
||||
.variant(Variant::SECONDARY)
|
||||
.align(HAlign::Start)
|
||||
|
||||
@@ -271,8 +271,12 @@ fn global_edit_options(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let on = app.session.active().is_some_and(|d| d.global_edit.is_some());
|
||||
let label = tl!("Global Edit Options");
|
||||
ranked(ui, rank::DETAIL, |ui| {
|
||||
let options = IconButton::new(IconId::new("chevron-down")).label(label).enabled(!on).popup(PopupKind::Menu).show(ui);
|
||||
Menu::new(label).opened_by(&options, Trigger::Click).show(ui, |ui, _| crate::panels::properties::global_edit_options(app, ui));
|
||||
let options = IconButton::new(IconId::new("chevron-down")).label(label).enabled(!on).show(ui);
|
||||
// Properties' popover with the bar's own flag: closed while Global Edit is on, and it stays closed after.
|
||||
let id = options.response.id.with("open");
|
||||
let mut open = ui.data(|d| d.get_temp::<bool>(id)).unwrap_or(false);
|
||||
crate::panels::properties::global_edit_popover(app, ui, &options.response, &mut open);
|
||||
ui.data_mut(|d| d.insert_temp(id, open));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -377,7 +381,8 @@ fn trailing_select_similar(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let options = IconButton::new(IconId::new("chevron-down")).label(label).enabled(enabled).popup(PopupKind::Menu).show(ui);
|
||||
Menu::new(label).opened_by(&options, Trigger::Click).show(ui, |ui, _| {
|
||||
for &(by, on) in &kept {
|
||||
if MenuItem::new(similar_label(by)).check(on).show(ui).ran {
|
||||
// A menu row reads `&` as its mnemonic marker: `&&` is the character.
|
||||
if MenuItem::new(similar_label(by).replace('&', "&&")).check(on).show(ui).ran {
|
||||
params = Some(json!({ "by": by }));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -932,9 +932,11 @@ fn properties_delete(bar: &mut Shown, shown: &str) -> Target {
|
||||
delete
|
||||
}
|
||||
|
||||
/// A press and release of `key` through the window's whole frame, as the keyboard sends it.
|
||||
/// A press and release of `key` through the window's whole frame, as the keyboard sends it. The window's first frame
|
||||
/// builds its keymap and the keys the tool claims, as a running window has them before any key.
|
||||
fn key_through_the_app(app: &mut crate::VectorcraftApp, key: egui::Key, modifiers: egui::Modifiers) {
|
||||
let ctx = crate::testing::ui_context();
|
||||
crate::tests_synthetic::key_frame(app, &ctx, vec![]);
|
||||
let event = |pressed| egui::Event::Key { key, physical_key: None, pressed, repeat: false, modifiers };
|
||||
crate::tests_synthetic::key_frame(app, &ctx, vec![event(true)]);
|
||||
crate::tests_synthetic::key_frame(app, &ctx, vec![event(false)]);
|
||||
|
||||
@@ -71,6 +71,11 @@ pub(crate) fn panel_id(id: u32) -> String {
|
||||
format!("toolbar:{id}")
|
||||
}
|
||||
|
||||
/// Whether `bar` is on, as Window › Toolbars checks it: its panel is in the layout, though Tab may hide it for now.
|
||||
pub(crate) fn is_on(ui: &UiState, bar: &CustomToolbar) -> bool {
|
||||
panel_docking::layout_of(ui).contains(&panel_id(bar.id))
|
||||
}
|
||||
|
||||
/// The toolbar named `name`, whatever its case.
|
||||
pub(crate) fn find<'a>(ui: &'a UiState, name: &str) -> Option<&'a CustomToolbar> {
|
||||
let k = key(name);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use craft::cms::{Builtin, Profile};
|
||||
use craft::cms::Profile;
|
||||
use craft::color_ui::display::{DisplayTransform, check_monitor};
|
||||
use craft::color_ui::ui::ProfileWords;
|
||||
use serde_json::{Value, json};
|
||||
@@ -260,7 +260,10 @@ pub fn check_profile(icc: &[u8]) -> Result<(), String> {
|
||||
fn build(icc: &[u8]) -> Result<DisplayTransform, String> {
|
||||
check_profile(icc)?;
|
||||
let monitor = Profile::parse(icc).map_err(|e| e.to_string())?;
|
||||
DisplayTransform::new(Arc::new(Builtin::Srgb.profile().clone()), Arc::new(monitor)).map_err(|e| e.to_string())
|
||||
// The canvas holds the document's sRGB: a monitor profile of that sRGB converts nothing.
|
||||
let srgb = vectorcraft_color::cms::icc_bytes(vectorcraft_color::cms::SRGB).map_err(|e| e.to_string())?;
|
||||
let source = Profile::parse(&srgb).map_err(|e| e.to_string())?;
|
||||
DisplayTransform::new(Arc::new(source), Arc::new(monitor)).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// One opaque sRGB color through `t`.
|
||||
|
||||
@@ -184,6 +184,22 @@ fn hash_listed_names(ui: &UiState, h: &mut DefaultHasher) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The prefixes of linked command sets made for other apps, which VectorCraft does not route: their keys (Shift+=
|
||||
/// and Alt+Shift+letters for blend modes, Cmd+[ and Cmd+] for layer order, Cmd+G and F3 for a find bar, Insert for
|
||||
/// warp pins, a rich text editor's Cmd+Enter and Cmd+Shift+B, which the Type tool's editor has) are VectorCraft's own
|
||||
/// commands' keys, so the catalog drops them.
|
||||
const UNROUTED_SETS: [&str; 6] = ["blendMode.", "layersPanel.", "find.", "pinWarp.", "perspectiveWarp.", "textEditor."];
|
||||
|
||||
/// The commands of [`UNROUTED_SETS`] that come with default keys.
|
||||
static UNROUTED: std::sync::LazyLock<Vec<String>> = std::sync::LazyLock::new(|| {
|
||||
craft::ui::runtime::commands::sets()
|
||||
.into_iter()
|
||||
.flat_map(|set| (set.defs)().unwrap_or_default())
|
||||
.filter(|def| !def.defaults.is_empty() && UNROUTED_SETS.iter().any(|prefix| def.command.id.starts_with(prefix)))
|
||||
.map(|def| def.command.id)
|
||||
.collect()
|
||||
});
|
||||
|
||||
fn rebuild(app: &mut VectorcraftApp, target: Target) {
|
||||
// The Symbols panel menu's states read the selection's instances from the walk this keeps.
|
||||
crate::panels::symbols::cache_instances(app);
|
||||
@@ -207,7 +223,7 @@ fn rebuild(app: &mut VectorcraftApp, target: Target) {
|
||||
let options = LayoutOptions::new(APP_NAME).label(&translate_label);
|
||||
let laid = layout(&bar, target, &options).bar;
|
||||
match AppCatalog::new(defs, generation(&listed, &crate::panels::actions::function_keys(&app.ui.actions))) {
|
||||
Ok(catalog) => app.menus.catalog = Some(catalog),
|
||||
Ok(catalog) => app.menus.catalog = Some(UNROUTED.iter().fold(catalog, |catalog, id| catalog.replace_defaults(id.as_str(), Vec::new()))),
|
||||
// A refused catalog is a bug in the rows; the last good one keeps the commands working.
|
||||
Err(e) => eprintln!("menu catalog refused: {e:?}"),
|
||||
}
|
||||
@@ -259,9 +275,9 @@ fn catalog_defs(app: &VectorcraftApp, refs: &[(CommandRef, String, bool)], state
|
||||
}
|
||||
let shown = display_label(app, id, &d.label);
|
||||
if shown != d.label {
|
||||
state = state.title(shown);
|
||||
state = state.title(shown.clone());
|
||||
}
|
||||
if let Some(reason) = Some(enabled).filter(|e| !e).and_then(|_| why_off(app, id).flatten()) {
|
||||
if let Some(reason) = Some(enabled).filter(|e| !e).and_then(|_| off_reason(app, id, &shown)) {
|
||||
state = state.hint(reason);
|
||||
}
|
||||
states.set(d.command.clone(), state);
|
||||
@@ -269,6 +285,11 @@ fn catalog_defs(app: &VectorcraftApp, refs: &[(CommandRef, String, bool)], state
|
||||
defs
|
||||
}
|
||||
|
||||
/// What a dimmed row named `label` says: the engine's reason, else that the command is not available right now.
|
||||
fn off_reason(app: &VectorcraftApp, id: &str, label: &str) -> Option<String> {
|
||||
why_off(app, id).map(|why| why.unwrap_or_else(|| crate::i18n::msg(&format!("command `{label}` is not available right now"))))
|
||||
}
|
||||
|
||||
/// The tree turned into the bar's nodes, with the state of every item it keeps.
|
||||
struct Build<'a> {
|
||||
app: &'a VectorcraftApp,
|
||||
@@ -332,7 +353,7 @@ impl Build<'_> {
|
||||
} else if enabled {
|
||||
None
|
||||
} else {
|
||||
why_off(self.app, id).flatten()
|
||||
off_reason(self.app, id, &self.item_title(id, params, &item.label))
|
||||
};
|
||||
if let Some(tip) = tip {
|
||||
state = state.hint(tip.clone());
|
||||
@@ -361,7 +382,6 @@ impl Build<'_> {
|
||||
let run_with = |mods: Mods, p: Value| Alternate::new(mods, CommandRef::with_params(id, p));
|
||||
let held = |shift: bool, alt: bool| Mods { cmd: false, ctrl: false, alt, shift };
|
||||
match id {
|
||||
"object.unlockAll" | "object.showAll" => item.alternate(run_with(held(true, true), json!({ "scope": "group" }))),
|
||||
"ui.expandDialog" => item.alternate(run_with(held(false, true), json!({ "immediate": true }))),
|
||||
crate::addons::select::link_status::COMMAND => {
|
||||
item.alternate(run_with(held(true, false), crate::addons::select::link_status::with_shift(params.clone())))
|
||||
|
||||
@@ -83,9 +83,11 @@ pub fn checked(app: &VectorcraftApp, id: &str, p: &Value) -> Option<bool> {
|
||||
&& crate::custom_toolbars::drawer_target(&app.ui).map(crate::custom_toolbars::key)
|
||||
== p.get("toolbar").and_then(Value::as_str).map(crate::custom_toolbars::key)
|
||||
}
|
||||
"window.toolbar.custom" => {
|
||||
p.get("name").and_then(Value::as_str).and_then(|name| crate::custom_toolbars::find(&app.ui, name)).is_some_and(|b| b.shown)
|
||||
}
|
||||
"window.toolbar.custom" => p
|
||||
.get("name")
|
||||
.and_then(Value::as_str)
|
||||
.and_then(|name| crate::custom_toolbars::find(&app.ui, name))
|
||||
.is_some_and(|b| crate::custom_toolbars::is_on(&app.ui, b)),
|
||||
"window.floatTools" => {
|
||||
let tool = p.get("tool").and_then(Value::as_str).unwrap_or("");
|
||||
let toolbar = p.get("toolbar").and_then(Value::as_str);
|
||||
|
||||
@@ -314,12 +314,16 @@ fn discover_finds_commands_by_their_shown_menu_label() {
|
||||
fn discover_results_show_the_current_shortcut_and_language_after_a_change() {
|
||||
// Help searches in the window's interface language.
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()));
|
||||
// The keymap is the window's: its frame builds it, and builds it again with the shortcuts as they changed.
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
app_frame(&mut app, &ctx, vec![]);
|
||||
let found = app.run("help.discover.search", json!({"query": "file.newDialog"})).unwrap();
|
||||
let index = found["results"].as_array().unwrap().iter().position(|hit| hit["id"] == "file.newDialog").unwrap();
|
||||
assert_eq!(found["results"][index]["shortcut"], "Cmd+N");
|
||||
app.run("help.discover.choose", json!({"index": index})).unwrap();
|
||||
app.run("window.panel.close", json!({"panel": "discover"})).unwrap();
|
||||
app.run("shortcuts.set", json!({"id": "file.newDialog", "shortcut": "Cmd+Alt+Shift+F9"})).unwrap();
|
||||
app_frame(&mut app, &ctx, vec![]);
|
||||
|
||||
let reopened = app.run("help.discover", json!({})).unwrap();
|
||||
assert_eq!(reopened["query"], "file.newDialog");
|
||||
@@ -331,6 +335,7 @@ fn discover_results_show_the_current_shortcut_and_language_after_a_change() {
|
||||
assert_eq!(picked["location"]["shortcut"], "Cmd+Alt+Shift+F9");
|
||||
|
||||
app.run("shortcuts.set", json!({"id": "file.newDialog", "shortcut": "Cmd+Alt+Shift+F8"})).unwrap();
|
||||
app_frame(&mut app, &ctx, vec![]);
|
||||
let text = crate::tests_labels::painted_text(&mut app, crate::panels::discover::show);
|
||||
// PLAN: assumed `keymap::chord_text(&str) -> String`, the text the chord shows as
|
||||
assert!(text.contains(&crate::keymap::chord_text("Cmd+Alt+Shift+F8")), "{text}");
|
||||
|
||||
@@ -6,6 +6,13 @@ use craft::menu::{Item, ItemRole, Platforms};
|
||||
|
||||
use crate::i18n::LangExt as _;
|
||||
|
||||
/// `label` running `id`, and with Shift+Alt held as it is chosen, `id` within the selected object's group.
|
||||
fn within_group(label: &'static str, id: &'static str) -> Node {
|
||||
let held = craft::keymap::Mods { cmd: false, ctrl: false, alt: true, shift: true };
|
||||
let group = craft::ui::menu::Alternate::new(held, CommandRef::with_params(id, json!({ "scope": "group" })));
|
||||
Node::Item(Item::new(CommandRef::with_params(id, serde_json::Value::Null), label).alternate(group))
|
||||
}
|
||||
|
||||
/// The in-window and native menu tree. The in-window bar skips the VectorCraft menu (see
|
||||
/// `menu_bar`); the native Mac bar is composed from the whole tree (see `native_menu`).
|
||||
/// `english_names` is Preferences › Type › Show Font Names in English (the Type → Font labels
|
||||
@@ -220,7 +227,7 @@ pub fn menu_tree_named(english_names: bool, listed: &Listed) -> Vec<(&'static st
|
||||
"Lock",
|
||||
vec![c("Selection", "object.lock"), c("All Artwork Above", "object.lock.above"), c("Other Layers", "object.lock.otherLayers")],
|
||||
),
|
||||
c("Unlock All", "object.unlockAll"),
|
||||
within_group("Unlock All", "object.unlockAll"),
|
||||
sub(
|
||||
"Hide",
|
||||
vec![
|
||||
@@ -230,7 +237,7 @@ pub fn menu_tree_named(english_names: bool, listed: &Listed) -> Vec<(&'static st
|
||||
c("Unselected Artwork", "object.hide.unselected"),
|
||||
],
|
||||
),
|
||||
c("Show All", "object.showAll"),
|
||||
within_group("Show All", "object.showAll"),
|
||||
Sep,
|
||||
c("Expand…", "ui.expandDialog"),
|
||||
c("Expand Appearance", "effect.expandAppearance"),
|
||||
|
||||
@@ -472,7 +472,7 @@ fn tool_home(app: &VectorcraftApp, tool: &str) -> String {
|
||||
});
|
||||
let active = app.session.tool_id();
|
||||
let custom = |shown: bool| {
|
||||
app.ui.custom_toolbars.iter().filter(|b| b.shown == shown).find_map(|bar| {
|
||||
app.ui.custom_toolbars.iter().filter(|b| crate::custom_toolbars::is_on(&app.ui, b) == shown).find_map(|bar| {
|
||||
let slot = bar.slots.iter().find(|s| s.iter().any(|t| t == tool))?;
|
||||
let tools: Vec<&'static str> = slot.iter().filter_map(|id| vectorcraft_tools::tool_info(id).map(|t| t.id)).collect();
|
||||
if tools.len() > 1 && tools.first().is_some_and(|first| crate::toolbar::is_floating(app, Some(&bar.name), first)) {
|
||||
|
||||
@@ -464,8 +464,9 @@ pub(crate) fn reveal_panel(app: &mut VectorcraftApp, panel: &str) -> Result<Valu
|
||||
}
|
||||
return Ok(json!({"open": panel}));
|
||||
}
|
||||
let id = normalize(panel).ok_or_else(|| format!("unknown panel `{panel}`"))?;
|
||||
place_panel(app, id)
|
||||
// A tool rail (the Tools panel, a toolbar made with New Toolbar) comes back as a Window-menu panel does.
|
||||
let id = panel_id(panel).ok_or_else(|| format!("unknown panel `{panel}`"))?;
|
||||
place_panel(app, &id)
|
||||
}
|
||||
|
||||
/// `window.collapseDock {collapsed?}`: collapse every dock column of panels to icons, or expand the
|
||||
|
||||
@@ -339,17 +339,18 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
if std::mem::take(&mut app.ui.discover.focus) {
|
||||
focus::request(ui.ctx(), FocusTarget::Id(field.response.id));
|
||||
}
|
||||
if query != app.ui.discover.query
|
||||
&& let Err(e) = app.run("help.discover.search", json!({"query": query}))
|
||||
{
|
||||
app.status(e);
|
||||
}
|
||||
// Escape closes the panel and keeps the query the search field clears with it, so Help opens on it again.
|
||||
if field.escaped {
|
||||
if let Err(e) = app.run("window.panel.close", json!({"panel": ID})) {
|
||||
app.status(e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if query != app.ui.discover.query
|
||||
&& let Err(e) = app.run("help.discover.search", json!({"query": query}))
|
||||
{
|
||||
app.status(e);
|
||||
}
|
||||
let mut chosen = None;
|
||||
let mut home = false;
|
||||
let mut back = false;
|
||||
|
||||
@@ -261,7 +261,7 @@ mod object_sections;
|
||||
mod transform_section;
|
||||
mod type_sections;
|
||||
|
||||
pub(crate) use appearance_section::{GlobalEditKey, global_edit_options};
|
||||
pub(crate) use appearance_section::{GlobalEditKey, global_edit_popover};
|
||||
pub(crate) use artboard_sections::{ArtboardSizeChoice, artboard_presets, artboard_size_controls, artboard_size_row};
|
||||
pub use transform_section::transform_section;
|
||||
pub use type_sections::type_sections;
|
||||
|
||||
@@ -42,6 +42,15 @@ pub(crate) fn run_fired(app: &mut VectorcraftApp, ctx: &egui::Context, fired: &F
|
||||
app.status(why);
|
||||
return;
|
||||
}
|
||||
// While a tool's gesture runs, keys run no command; the active tool's own shortcut, between clicks, chooses it
|
||||
// again, which ends the gesture.
|
||||
if fired.source == FireSource::Key && fired.phase != FirePhase::Release && crate::canvas::busy_tool(app) {
|
||||
let active = app.session.tool_id().to_owned();
|
||||
if command.id.strip_prefix("tool:") == Some(active.as_str()) && !app.session.pointer_held() {
|
||||
app.select_tool(&active);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let Some(tool) = command.id.strip_prefix("tool:") {
|
||||
match fired.phase {
|
||||
FirePhase::Release => held_tool::release(app, ctx, fired),
|
||||
|
||||
@@ -56,6 +56,14 @@ fn frame(app: &mut VectorcraftApp, events: Vec<egui::Event>) {
|
||||
key_frame(app, &ctx, events);
|
||||
}
|
||||
|
||||
/// Gives the current document's canvas the keyboard, as a press on it does, and runs the frame that applies it: the
|
||||
/// keys a tool claims reach the canvas that has the keyboard, and these tests drive the gesture past the canvas.
|
||||
fn focus_canvas(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
let win = crate::doc_windows::current(app).expect("a document window");
|
||||
craft::ui::runtime::focus::request(ctx, craft::ui::runtime::focus::FocusTarget::Id(crate::canvas::canvas_id(win)));
|
||||
key_frame(app, ctx, vec![]);
|
||||
}
|
||||
|
||||
/// `n` empty frames, `0.05` s each.
|
||||
fn idle(app: &mut VectorcraftApp, ctx: &egui::Context, n: usize) {
|
||||
for _ in 0..n {
|
||||
@@ -132,6 +140,8 @@ fn dialog_field(app: &VectorcraftApp, key: &str) -> Option<Value> {
|
||||
/// OK (`ok`) or Cancel in the window's top dialog, and the app's pump over the answer.
|
||||
pub(super) fn close_top_dialog(app: &mut VectorcraftApp, ok: bool) {
|
||||
let ctx = app.ui_ctx.clone().expect("a window context");
|
||||
// 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");
|
||||
@@ -313,7 +323,9 @@ fn the_blend_tool_shortcut_finishes_the_blend() {
|
||||
#[test]
|
||||
fn the_pen_shortcut_ends_the_path_being_drawn() {
|
||||
use vectorcraft_tools::{PointerEvent, PointerKind};
|
||||
let mut app = new_app();
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 600, "height": 300})).unwrap();
|
||||
ready(&mut app);
|
||||
app.select_tool("pen");
|
||||
let click = |app: &mut VectorcraftApp, x: f64| {
|
||||
let v = app.view_info();
|
||||
@@ -325,11 +337,11 @@ fn the_pen_shortcut_ends_the_path_being_drawn() {
|
||||
path.map(|pd| pd.subpaths.iter().map(|sp| sp.anchors.len()).collect::<Vec<_>>())
|
||||
};
|
||||
click(&mut app, 100.0);
|
||||
click(&mut app, 190.0);
|
||||
click(&mut app, 200.0);
|
||||
let first = app.session.active().unwrap().selection.objects[0];
|
||||
frame(&mut app, typed(Key::P, Modifiers::NONE, "p"));
|
||||
assert_eq!(app.session.tool_id(), "pen");
|
||||
click(&mut app, 150.0);
|
||||
click(&mut app, 300.0);
|
||||
assert_eq!(anchors(&app, first), Some(vec![2]), "the path keeps its two anchors");
|
||||
let second = app.session.active().unwrap().selection.objects[0];
|
||||
assert_ne!(second, first, "the click starts a new path");
|
||||
@@ -716,7 +728,8 @@ fn cmd_alt_shift_j_opens_average_and_join() {
|
||||
let before = app.session.doc().unwrap().doc.clone();
|
||||
let j = || tap(Key::J, cmd() | Modifiers::ALT | Modifiers::SHIFT);
|
||||
frame(&mut app, j());
|
||||
assert_eq!(dialog_kind(&app).as_deref(), Some("averageJoin"));
|
||||
// A dialog is keyed by the command its OK runs.
|
||||
assert_eq!(dialog_kind(&app).as_deref(), Some("path.averageJoin"));
|
||||
close_top_dialog(&mut app, false);
|
||||
assert!(dialog_kind(&app).is_none());
|
||||
assert_eq!(app.session.doc().unwrap().doc, before, "Cancel changes nothing");
|
||||
@@ -1051,6 +1064,7 @@ fn arrows_while_dragging_a_grid_change_its_rows_and_columns() {
|
||||
let grid = |app: &mut VectorcraftApp, keys: &[Key]| {
|
||||
app.session.pointer(&PointerEvent::new(PointerKind::Down, 100.0, 80.0), view).unwrap();
|
||||
app.session.pointer(&PointerEvent::new(PointerKind::Drag, 300.0, 220.0), view).unwrap();
|
||||
focus_canvas(app, &ctx);
|
||||
for &key in keys {
|
||||
key_frame(app, &ctx, press(key, Modifiers::NONE));
|
||||
}
|
||||
@@ -1076,6 +1090,7 @@ fn grid_drag_letters_take_plain_and_shift_presses() {
|
||||
let ctx = ready(&mut app);
|
||||
app.session.pointer(&PointerEvent::new(PointerKind::Down, 100.0, 80.0), view).unwrap();
|
||||
app.session.pointer(&PointerEvent::new(PointerKind::Drag, 300.0, 220.0), view).unwrap();
|
||||
focus_canvas(&mut app, &ctx);
|
||||
let skews = |app: &VectorcraftApp| (app.session.tool_options()["radialSkew"].clone(), app.session.tool_options()["concentricSkew"].clone());
|
||||
key_frame(&mut app, &ctx, press(Key::V, Modifiers::NONE));
|
||||
assert_eq!(skews(&app), (json!(10.0), json!(0.0)));
|
||||
@@ -1135,6 +1150,7 @@ fn polygonal_lasso_takes_backspace_delete_enter_and_escape_while_a_loop_is_open(
|
||||
for (x, y) in [(80.0, 80.0), (140.0, 80.0), (300.0, 300.0)] {
|
||||
click(&mut app, x, y);
|
||||
}
|
||||
focus_canvas(&mut app, &ctx);
|
||||
key_frame(&mut app, &ctx, tap(Key::Backspace, Modifiers::NONE));
|
||||
assert!(app.session.active().unwrap().doc.node(id).is_some(), "Backspace leaves the selected art");
|
||||
click(&mut app, 300.0, 300.0);
|
||||
@@ -1147,6 +1163,7 @@ fn polygonal_lasso_takes_backspace_delete_enter_and_escape_while_a_loop_is_open(
|
||||
for (x, y) in [(80.0, 80.0), (140.0, 80.0), (300.0, 300.0)] {
|
||||
click(&mut app, x, y);
|
||||
}
|
||||
focus_canvas(&mut app, &ctx);
|
||||
key_frame(&mut app, &ctx, tap(Key::Backspace, Modifiers::NONE));
|
||||
click(&mut app, 80.0, 140.0);
|
||||
key_frame(&mut app, &ctx, tap(Key::Enter, Modifiers::NONE));
|
||||
@@ -1394,13 +1411,13 @@ fn enter_opens_the_tools_dialog_and_leaves_it_open() {
|
||||
assert_eq!(dialog_kind(&app), None, "nothing is selected");
|
||||
app.session.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 50, "height": 30})).unwrap();
|
||||
for (tool, dialog) in [
|
||||
("selection", "move"),
|
||||
("directSelection", "move"),
|
||||
("groupSelection", "move"),
|
||||
("rotate", "rotate"),
|
||||
("scale", "scale"),
|
||||
("reflect", "reflect"),
|
||||
("shear", "shear"),
|
||||
("selection", "object.move"),
|
||||
("directSelection", "object.move"),
|
||||
("groupSelection", "object.move"),
|
||||
("rotate", "object.rotate"),
|
||||
("scale", "object.scale"),
|
||||
("reflect", "object.reflect"),
|
||||
("shear", "object.shear"),
|
||||
] {
|
||||
app.select_tool(tool);
|
||||
let before = steps(&app);
|
||||
@@ -1411,7 +1428,7 @@ fn enter_opens_the_tools_dialog_and_leaves_it_open() {
|
||||
assert_eq!(steps(&app), before, "{tool}: the Enter that opened it didn't confirm it");
|
||||
// With its default values only Reflect changes the art.
|
||||
key_frame(&mut app, &ctx, enter());
|
||||
let after = (before.0 + usize::from(dialog == "reflect"), before.1 + 1);
|
||||
let after = (before.0 + usize::from(dialog == "object.reflect"), before.1 + 1);
|
||||
assert_eq!((dialog_kind(&app), steps(&app)), (None, after), "{tool}: Enter confirms");
|
||||
}
|
||||
app.select_tool("rectangle");
|
||||
@@ -1444,7 +1461,7 @@ fn enter_after_a_drag_repeats_its_offset() {
|
||||
assert!(step > 0.0);
|
||||
key_frame(&mut app, &ctx, vec![]);
|
||||
key_frame(&mut app, &ctx, enter());
|
||||
assert_eq!(dialog_kind(&app).as_deref(), Some("move"), "Enter opens Move");
|
||||
assert_eq!(dialog_kind(&app).as_deref(), Some("object.move"), "Enter opens Move");
|
||||
assert_eq!(dialog_field(&app, "dx").and_then(|v| v.as_f64()).map(f64::round), Some(step));
|
||||
set_top_field(&mut app, "copy", json!(true));
|
||||
key_frame(&mut app, &ctx, enter());
|
||||
|
||||
@@ -99,13 +99,18 @@ fn set_field(app: &VectorcraftApp, key: &str, value: serde_json::Value) {
|
||||
app.dialogs().expect("a window").with(|host| host.set_json_field(&ctx, id, key, value)).unwrap_or_else(|e| panic!("{key}: {e}"));
|
||||
}
|
||||
|
||||
/// Answers the open tool-options dialog with OK or Cancel; the frame's pump takes the answer.
|
||||
/// Answers the open tool-options dialog with OK or Cancel; the frame's pump takes the answer. A held OK files the
|
||||
/// answer for the pump and the dialog closes once the pump accepted it.
|
||||
fn answer(app: &mut VectorcraftApp, ok: bool) {
|
||||
let (id, _) = tool_dialog(app).expect("the dialog is open");
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
let taken = app.dialogs().expect("a window").with(|host| if ok { host.confirm_by_id(&ctx, id) } else { host.cancel_by_id(&ctx, id) });
|
||||
assert!(taken, "the dialog took the answer");
|
||||
crate::dialogs::host::pump(app, &ctx);
|
||||
if ok {
|
||||
crate::tests::picks::answer_dialog(app, id, &[], true);
|
||||
} else {
|
||||
app.dialogs().expect("a window").with(|host| host.cancel_by_id(&ctx, id));
|
||||
crate::dialogs::host::pump(app, &ctx);
|
||||
}
|
||||
assert!(tool_dialog(app).is_none_or(|(open, _)| open != id), "the dialog took the answer");
|
||||
}
|
||||
|
||||
/// A double-click on a tool's button opens what `open_options` opens: the artboard's, a graph's and the tools' dialogs
|
||||
|
||||
Reference in New Issue
Block a user