mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 19:41:36 -05:00
ui.inspect names the JavaScript Files dialog's selected file as svgInteractivity.info does, hides a hidden library's panel closed in the dock, and replaces a file:C: URL whole; automation tests read the keymap's saved sets, settle the dialogs before comparing their fields and draw a held OK's closing pass
This commit is contained in:
@@ -149,6 +149,8 @@ pub fn inspect(app: &VectorcraftApp, ctx: &egui::Context) -> Value {
|
||||
}
|
||||
leave_out_unreadable_paths(fields);
|
||||
}
|
||||
let mut dialogs = app.dialogs().map_or_else(|| json!([]), |dialogs| dialogs.with(|host| craft::automation::dialogs::inspect(host)));
|
||||
crate::dialogs::javascript_files::show_selected(app, &mut dialogs);
|
||||
json!({
|
||||
"scriptRunning": app.session.script_running(),
|
||||
"scriptReport": app.session.shown_script_report(),
|
||||
@@ -156,7 +158,7 @@ pub fn inspect(app: &VectorcraftApp, ctx: &egui::Context) -> Value {
|
||||
"toolOptions": app.session.tool_options(),
|
||||
"ui": ui,
|
||||
// The window's open dialogs, the top one last, with their fields.
|
||||
"dialogs": app.dialogs().map_or_else(|| json!([]), |dialogs| dialogs.with(|host| craft::automation::dialogs::inspect(host))),
|
||||
"dialogs": dialogs,
|
||||
// Not saved with the UI state, so not in `ui`: 0 normal … 3 Presentation Mode.
|
||||
"screenMode": app.ui.screen_mode,
|
||||
// The Contextual Task Bar: pinned (not saved either); `ui.locate` finds where it shows.
|
||||
@@ -214,10 +216,11 @@ pub fn inspect(app: &VectorcraftApp, ctx: &egui::Context) -> Value {
|
||||
}
|
||||
|
||||
/// The fields of the UI state, by their keys in `ui.inspect`'s `ui`, that hold panel ids: the panel
|
||||
/// popped out of the collapsed column, the docking layout, closed panels' places and groups, the panels
|
||||
/// shown as icons or collapsed, and the older floating panels' record.
|
||||
const PANEL_FIELDS: [&str; 7] =
|
||||
["open_panel", "docking", "docking_hidden", "docking_hidden_groups", "docking_icons", "docking_collapsed", "floating_panels"];
|
||||
/// popped out of the collapsed column, the dock's workspace (its layout, closed and floated panels), the older
|
||||
/// docking layout, closed panels' places and groups, the panels shown as icons or collapsed, and the older floating
|
||||
/// panels' record.
|
||||
const PANEL_FIELDS: [&str; 8] =
|
||||
["open_panel", "dock", "docking", "docking_hidden", "docking_hidden_groups", "docking_icons", "docking_collapsed", "floating_panels"];
|
||||
|
||||
/// The ids of the loaded libraries (`loaded/<path>`) that the UI state refers to and whose file the
|
||||
/// request may not read, each with the id a reply shows instead: `loaded/<file name>`, as a library
|
||||
@@ -673,7 +676,8 @@ impl<'a> Found<'a> {
|
||||
|
||||
/// Where a `file:` URL that holds `from`, an absolute path found at `at` in `text`, begins: `at` less
|
||||
/// the `file:` before it, with `//` and a host (`localhost`, another host or none) between them, in any
|
||||
/// case of its letters; before a drive, the host is followed by a `/` too. `at` when no such URL holds it.
|
||||
/// case of its letters; before a drive, the host is followed by a `/` too, or the drive follows `file:` at once
|
||||
/// (`file:C:/x`). `at` when no such URL holds it.
|
||||
fn url_start(text: &str, at: usize, from: &str) -> usize {
|
||||
let drive = matches!(from.as_bytes(), [drive, b':', ..] if drive.is_ascii_alphabetic());
|
||||
if !from.starts_with('/') && !drive {
|
||||
@@ -684,7 +688,7 @@ fn url_start(text: &str, at: usize, from: &str) -> usize {
|
||||
let rest = &before[scheme + "file:".len()..];
|
||||
let host = |h: &str| h.chars().all(|c| c.is_alphanumeric() || matches!(c, '.' | '-' | '_' | ':' | '[' | ']' | '%'));
|
||||
let holds = if drive {
|
||||
rest.strip_prefix("//").and_then(|r| r.strip_suffix('/')).is_some_and(host)
|
||||
rest.is_empty() || rest.strip_prefix("//").and_then(|r| r.strip_suffix('/')).is_some_and(host)
|
||||
} else {
|
||||
rest.is_empty() || rest.strip_prefix("//").is_some_and(host)
|
||||
};
|
||||
|
||||
@@ -34,6 +34,18 @@ use crate::panels::svg_interactivity::caption;
|
||||
/// documents.
|
||||
const KEY: &str = "javascriptFiles";
|
||||
|
||||
/// Names the file selected in an open JavaScript Files dialog, in `ui.inspect`'s list of open `dialogs`, as
|
||||
/// `svgInteractivity.info` names the active document's linked files: outside the read roots, by its file name alone.
|
||||
pub(crate) fn show_selected(app: &VectorcraftApp, dialogs: &mut Value) {
|
||||
let (Some(st), Some(open)) = (app.session.active(), dialogs.as_array_mut()) else { return };
|
||||
let id = dialog_id(KEY).value().to_string();
|
||||
for dialog in open.iter_mut().filter(|d| d["id"] == id.as_str()) {
|
||||
if let Some(Value::String(selected)) = dialog.pointer_mut("/fields/selected") {
|
||||
*selected = shown_script(st, selected).into_owned();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What the body asks [`pump`] to do with the app.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum Pending {
|
||||
|
||||
@@ -1494,7 +1494,11 @@ fn ui_inspect_hides_a_library_panels_path_in_shortcut_overrides() {
|
||||
app.ui.shortcut_sets.save_as("Mine", overrides, &crate::shortcut_editor::BUILTINS).unwrap();
|
||||
let r = request(&mut app, &tx, "ui.inspect", json!({}));
|
||||
let shown = "panel:library:swatches:loaded/b.svg";
|
||||
assert_eq!(r["result"]["ui"]["shortcut_sets"]["sets"]["Mine"][shown], "Cmd+Alt+Shift+F7", "{r}");
|
||||
// The sets are saved in the keymap's own form: a list of named sets, each a list of overrides.
|
||||
let sets = r["result"]["ui"]["shortcut_sets"]["sets"].as_array().cloned().unwrap_or_default();
|
||||
let mine = sets.iter().find(|set| set["name"] == "Mine").map_or(Value::Null, |set| set["overrides"].clone());
|
||||
let keys = mine.as_array().and_then(|o| o.iter().find(|entry| entry["command"] == shown)).map(|entry| entry["keys"].clone());
|
||||
assert_eq!(keys, Some(json!(["Cmd+Alt+Shift+F7"])), "{r}");
|
||||
let hidden = json!(s(base.join("outside"))).to_string();
|
||||
assert!(!r.to_string().contains(hidden.trim_matches('"')), "no path outside the root: {r}");
|
||||
let _ = std::fs::remove_dir_all(base);
|
||||
@@ -1647,8 +1651,15 @@ fn dialog_set_cannot_redirect_parameter_dialog() {
|
||||
json!({"fields": [{"field": "width", "value": 30}, {"field": "__command", "value": "file.close"}], "action": "confirm"}),
|
||||
],
|
||||
);
|
||||
let id = open_dialogs(&app).pop().expect("the parameter dialog").id;
|
||||
let r = request(&mut app, &tx, "ui.dialog.set", json!({"field": "width", "value": 30, "action": "confirm"}));
|
||||
assert_eq!(r["ok"], true, "{r}");
|
||||
// The dialog holds its OK for the pump; the OK the pump accepted closes it in the dialog's next pass, which
|
||||
// `request`'s bare frames don't draw.
|
||||
let (ctx, host) = (app.ui_ctx.clone().expect("a window context"), app.dialogs().expect("the window's dialog host"));
|
||||
if host.with(|h| h.held_state(id) == Some(craft::ui::dialog::HeldOk::Accepted) && h.confirm_by_id(&ctx, id)) {
|
||||
crate::dialogs::host::pump(&mut app, &ctx);
|
||||
}
|
||||
assert!(open_dialogs(&app).is_empty() && objects(&app) == 1, "OK ran the dialog's command");
|
||||
assert_eq!(first_object(&app), (10.0, 30.0), "with its fixed x and the width set");
|
||||
}
|
||||
@@ -1722,6 +1733,9 @@ fn dialog_set_cannot_open_save_preset() {
|
||||
let saved = |app: &VectorcraftApp| (app.session.prefs.pdf_presets.len(), app.session.prefs.print_presets.len());
|
||||
for open in ["ui.savePdfDialog", "file.print"] {
|
||||
app.run(open, json!({})).unwrap();
|
||||
// The pump gives the dialog the fields it derives (Print's inks and summary) before they are compared.
|
||||
let ctx = app.ui_ctx.clone().unwrap_or_default();
|
||||
crate::dialogs::host::pump(&mut app, &ctx);
|
||||
let presets = saved(&app);
|
||||
refused_sets(
|
||||
&mut app,
|
||||
|
||||
Reference in New Issue
Block a user