mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
MCP: ui.menuDialog's params text lists every command whose dialog it opens
The params text of ui.menuDialog (and its copy in the MCP catalog) did not list the add-on and other commands whose dialogs ui.menuDialog also opens: Set Corners, Divide into Dashes, Bridge, Tangent Circle, Text Tweaker, Color Legend, `addon.arrange.randomizeOpacity`, `addon.arrange.sort`, Color Nearest, Select by Artboards, `type.smartPunctuation`, and the variable and data set dialogs. - The list now names those commands. The text says the variable and data set dialogs report the key `variables`, that the Color Nearest and Select by Artboards dialogs have no `key`, when Rename Variable, Set Data Set and Rename Data Set open, and that ui.dialog.set, ui.dialog.confirm and ui.dialog.cancel take the dialog's `id`. - A test runs ui.menuDialog for every command and fails when one opens a dialog that the params text does not list. The key test compares each dialog's key with the key the params text gives for its command.
This commit is contained in:
1 parent
3cbe61a6d0
commit
7eda2320dc
3 files changed
+77
-18
No files matched your search
@@ -1531,7 +1531,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.menuDialog",
|
||||
"Menu Dialog",
|
||||
"",
|
||||
"{command: object.move|object.rotate|object.scale|object.reflect|object.shear|object.transformEach|path.average|path.averageJoin|object.path.offsetPath|object.path.simplify|object.path.smooth|object.path.splitIntoGrid|object.vectorHalftone|artboard.rearrange|artboard.rename|object.envelope.makeWithWarp|object.envelope.resetWithWarp|object.envelope.makeWithMesh|object.envelope.resetWithMesh|object.envelope.options|addon.arrange.grid|addon.arrange.replace|addon.arrange.size|addon.packaging.setFoldAngle} open the dialog that command's menu item opens (its `key` in ui.inspect and ui.dialog is the command id, except `transformEach` for object.transformEach, `envelopeWarp` for object.envelope.makeWithWarp and object.envelope.resetWithWarp, `envelopeMesh` for object.envelope.makeWithMesh and object.envelope.resetWithMesh, and `envelopeOptions` for object.envelope.options; a slider over the canvas, not a dialog, for object.path.smooth, and for object.path.simplify until OK in its dialog keeps the settings (`retain`); Set Fold Angle's `angle` is the selected fold lines' angle, and it is refused while the selection has no fold line it can change; Scale and Transform Each have `corners` and `strokes`, from the preferences, which OK updates; Transform Each opens on the values it was last confirmed with (not `copy`), and its Copy button confirms with `copy: true`; the envelope dialogs start from the selected envelope, Make opens as Reset (`reset: true`) while one is selected)",
|
||||
"{command: object.move|object.rotate|object.scale|object.reflect|object.shear|object.transformEach|path.average|path.averageJoin|object.path.offsetPath|object.path.simplify|object.path.smooth|object.path.splitIntoGrid|object.vectorHalftone|artboard.rearrange|artboard.rename|object.envelope.makeWithWarp|object.envelope.resetWithWarp|object.envelope.makeWithMesh|object.envelope.resetWithMesh|object.envelope.options|addon.arrange.grid|addon.arrange.replace|addon.arrange.size|addon.packaging.setFoldAngle|addon.pathtools.cornerSet|addon.pathtools.divideDashes|addon.pathtools.bridge|addon.pathtools.tangentCircle|addon.type.textTweaker|addon.color.swatchLegend|addon.arrange.randomizeOpacity|addon.arrange.sort|addon.color.applyNearestSwatch|addon.select.byArtboards|type.smartPunctuation|variable.define|variable.rename|variable.bind|dataset.new|dataset.set|dataset.rename|dataset.select} open the dialog that command's menu item opens (its `key` in ui.inspect is the command id, except `transformEach` for object.transformEach, `envelopeWarp` for object.envelope.makeWithWarp and object.envelope.resetWithWarp, `envelopeMesh` for object.envelope.makeWithMesh and object.envelope.resetWithMesh, `variables` for variable.define and variable.rename and variable.bind and dataset.new and dataset.set and dataset.rename and dataset.select, and `envelopeOptions` for object.envelope.options; the dialogs of addon.color.applyNearestSwatch and addon.select.byArtboards have no `key`; a slider over the canvas, not a dialog, for object.path.smooth, and for object.path.simplify until OK in its dialog keeps the settings (`retain`); Set Fold Angle's `angle` is the selected fold lines' angle, and it is refused while the selection has no fold line it can change; Scale and Transform Each have `corners` and `strokes`, from the preferences, which OK updates; Transform Each opens on the values it was last confirmed with (not `copy`), and its Copy button confirms with `copy: true`; the envelope dialogs start from the selected envelope, Make opens as Reset (`reset: true`) while one is selected; variable.rename opens only while the document has a variable, and dataset.set and dataset.rename only while it has a data set, and otherwise the status bar says why; ui.dialog.set, ui.dialog.confirm and ui.dialog.cancel take the dialog's `id` from ui.inspect, or `top`, not its `key`)",
|
||||
),
|
||||
(
|
||||
"ui.widthPointEdit",
|
||||
|
||||
@@ -1011,6 +1011,13 @@ fn dialog_keys(app: &VectorcraftApp) -> Vec<String> {
|
||||
ui["dialogs"].as_array().into_iter().flatten().filter_map(|d| d["key"].as_str().map(str::to_string)).collect()
|
||||
}
|
||||
|
||||
/// The `key` of each dialog `ui.inspect` lists, bottom first, `None` for a dialog without one.
|
||||
fn dialog_entries(app: &VectorcraftApp) -> Vec<Option<String>> {
|
||||
let ctx = app.ui_ctx.clone().expect("a window app");
|
||||
let ui = crate::control::inspect(app, &ctx);
|
||||
ui["dialogs"].as_array().into_iter().flatten().map(|d| d["key"].as_str().map(str::to_string)).collect()
|
||||
}
|
||||
|
||||
/// A drawing every dialog `ui.menuDialog` lists can open on: two artboards and two selected rectangles, the first a
|
||||
/// crease, and for `command` a selected envelope when Reset or Envelope Options needs one.
|
||||
fn menu_dialog_app(command: &str) -> VectorcraftApp {
|
||||
@@ -1019,18 +1026,25 @@ fn menu_dialog_app(command: &str) -> VectorcraftApp {
|
||||
let crease = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 60, "height": 20})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 100, "y": 10, "width": 60, "height": 20})).unwrap();
|
||||
app.run(crate::addons::packaging::SET_ROLE, json!({"role": "crease", "ids": [crease]})).unwrap();
|
||||
// A variable and a data set, for the dialogs that edit one.
|
||||
app.session.execute("variable.define", &json!({"name": "Name", "kind": "text"})).unwrap();
|
||||
app.session.execute("dataset.new", &json!({"name": "Row"})).unwrap();
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
let envelope = match command {
|
||||
"object.envelope.resetWithWarp" | "object.envelope.options" => Some("object.envelope.makeWithWarp"),
|
||||
"object.envelope.resetWithMesh" => Some("object.envelope.makeWithMesh"),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(make) = envelope {
|
||||
if let Some(make) = envelope_for(command) {
|
||||
app.session.execute(make, &json!({})).unwrap();
|
||||
}
|
||||
app
|
||||
}
|
||||
|
||||
/// The command that makes the envelope `command`'s dialog needs selected, if it needs one.
|
||||
fn envelope_for(command: &str) -> Option<&'static str> {
|
||||
match command {
|
||||
"object.envelope.resetWithWarp" | "object.envelope.options" => Some("object.envelope.makeWithWarp"),
|
||||
"object.envelope.resetWithMesh" => Some("object.envelope.makeWithMesh"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The part of `doc` after `start`, up to the first of `ends`; empty when `doc` does not have `start`.
|
||||
fn clause<'a>(doc: &'a str, start: &str, ends: &[char]) -> &'a str {
|
||||
let Some(at) = doc.find(start) else { return "" };
|
||||
@@ -1043,31 +1057,44 @@ fn names(clause: &str, id: &str) -> bool {
|
||||
clause.split([' ', ',']).any(|word| word == id)
|
||||
}
|
||||
|
||||
/// Each command `ui.menuDialog`'s params text lists opens the dialog that text names, by the `key` `ui.inspect` and
|
||||
/// `ui.dialog` report: the command id unless the text names another key for that command, and no dialog for the
|
||||
/// commands the text says show a slider. Every key the text names is one a listed command opens.
|
||||
/// Each command `ui.menuDialog`'s params text lists opens the dialog that text names, by the `key` `ui.inspect`
|
||||
/// reports: the command id unless the text names another key for that command, none for the commands the text says
|
||||
/// have no key, and no dialog for the commands the text says show a slider. Every key the text names is one a listed
|
||||
/// command opens.
|
||||
#[test]
|
||||
fn menu_dialog_opens_the_dialog_keys_its_params_text_names() {
|
||||
let doc = crate::menus::UI_COMMANDS.iter().find(|c| c.0 == "ui.menuDialog").expect("registered").3;
|
||||
let list = doc.strip_prefix("{command: ").and_then(|rest| rest.split_once('}')).expect("a command list").0;
|
||||
let sliders = clause(doc, "not a dialog, for ", &[';']);
|
||||
let keyless = clause(doc, "the dialogs of ", &[';']);
|
||||
let except = clause(doc, "is the command id, except ", &[';']);
|
||||
let mut opened = Vec::new();
|
||||
for id in list.split('|') {
|
||||
let expected = except
|
||||
.split(',')
|
||||
.filter_map(|entry| entry.split_once('`')?.1.split_once("` for "))
|
||||
.find_map(|(key, commands)| names(commands, id).then_some(key))
|
||||
.unwrap_or(id);
|
||||
let mut app = menu_dialog_app(id);
|
||||
app.run("ui.menuDialog", json!({"command": id})).unwrap_or_else(|e| panic!("{id}: {e}"));
|
||||
settle(&mut app);
|
||||
let keys = dialog_keys(&app);
|
||||
let entries = dialog_entries(&app);
|
||||
assert_eq!(
|
||||
entries.last().is_some_and(Option::is_none),
|
||||
names(keyless, id),
|
||||
"{id}: whether its dialog has a `key` differs from the params text"
|
||||
);
|
||||
let keys: Vec<String> = entries.into_iter().flatten().collect();
|
||||
match keys.last() {
|
||||
None if names(keyless, id) => {}
|
||||
None => assert!(names(sliders, id), "{id} opens no dialog, and the params text does not say it shows a slider"),
|
||||
Some(key) if key == id => assert!(!names(sliders, id), "{id} opens a dialog, and the params text says it shows a slider"),
|
||||
Some(key) => assert!(
|
||||
names(clause(doc, &format!("`{key}` for "), &[',', ';']), id),
|
||||
"{id} opens `{key}`, which the params text does not name for it"
|
||||
),
|
||||
Some(key) => {
|
||||
assert!(!names(sliders, id), "{id} opens a dialog, and the params text says it shows a slider");
|
||||
assert_eq!(key, expected, "{id}: its dialog key differs from the params text");
|
||||
}
|
||||
}
|
||||
opened.extend(keys);
|
||||
}
|
||||
let except = clause(doc, "is the command id, except ", &[';']);
|
||||
for named in except.split('`').skip(1).step_by(2) {
|
||||
assert!(opened.iter().any(|key| key == named), "the params text names `{named}`, which no listed command opens");
|
||||
}
|
||||
@@ -1080,6 +1107,38 @@ fn menu_dialog_opens_the_dialog_keys_its_params_text_names() {
|
||||
assert_eq!(dialog_keys(&app), ["object.path.simplify"]);
|
||||
}
|
||||
|
||||
/// Every command whose dialog `ui.menuDialog` opens and `ui.inspect` lists, with a `key` or without one, is one its
|
||||
/// params text lists. Open Simplify and Smooth sliders count as dialogs too.
|
||||
#[test]
|
||||
fn menu_dialog_params_text_lists_every_command_whose_dialog_it_opens() {
|
||||
let doc = crate::menus::UI_COMMANDS.iter().find(|c| c.0 == "ui.menuDialog").expect("registered").3;
|
||||
let list: Vec<&str> = doc.strip_prefix("{command: ").and_then(|rest| rest.split_once('}')).expect("a command list").0.split('|').collect();
|
||||
let mut app = menu_dialog_app("");
|
||||
let ids: Vec<String> =
|
||||
app.session.commands().into_iter().map(|c| c.id.to_string()).chain(crate::menus::UI_COMMANDS.iter().map(|c| c.0.to_string())).collect();
|
||||
let mut missing = Vec::new();
|
||||
for id in ids {
|
||||
// The Reset and Envelope Options dialogs open only with an envelope selected.
|
||||
if envelope_for(&id).is_some() {
|
||||
app = menu_dialog_app(&id);
|
||||
}
|
||||
if app.run("ui.menuDialog", json!({"command": id})).is_err() {
|
||||
if envelope_for(&id).is_some() {
|
||||
app = menu_dialog_app("");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
settle(&mut app);
|
||||
let opened =
|
||||
!dialog_entries(&app).is_empty() || crate::dialogs::simplify_slider::showing(&app) || crate::dialogs::smooth_slider::showing(&app);
|
||||
if opened && !list.contains(&id.as_str()) {
|
||||
missing.push(id.clone());
|
||||
}
|
||||
app = menu_dialog_app("");
|
||||
}
|
||||
assert!(missing.is_empty(), "ui.menuDialog opens a dialog for {missing:?}, which its params text does not list");
|
||||
}
|
||||
|
||||
/// The transform, selection and Type on a Path tools' `tool.options` open dialogs whose `key` its params text names.
|
||||
#[test]
|
||||
fn tool_options_opens_the_dialog_keys_its_params_text_names() {
|
||||
|
||||
@@ -1532,7 +1532,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.menuDialog",
|
||||
"Menu Dialog",
|
||||
"",
|
||||
"{command: object.move|object.rotate|object.scale|object.reflect|object.shear|object.transformEach|path.average|path.averageJoin|object.path.offsetPath|object.path.simplify|object.path.smooth|object.path.splitIntoGrid|object.vectorHalftone|artboard.rearrange|artboard.rename|object.envelope.makeWithWarp|object.envelope.resetWithWarp|object.envelope.makeWithMesh|object.envelope.resetWithMesh|object.envelope.options|addon.arrange.grid|addon.arrange.replace|addon.arrange.size|addon.packaging.setFoldAngle} open the dialog that command's menu item opens (its `key` in ui.inspect and ui.dialog is the command id, except `transformEach` for object.transformEach, `envelopeWarp` for object.envelope.makeWithWarp and object.envelope.resetWithWarp, `envelopeMesh` for object.envelope.makeWithMesh and object.envelope.resetWithMesh, and `envelopeOptions` for object.envelope.options; a slider over the canvas, not a dialog, for object.path.smooth, and for object.path.simplify until OK in its dialog keeps the settings (`retain`); Set Fold Angle's `angle` is the selected fold lines' angle, and it is refused while the selection has no fold line it can change; Scale and Transform Each have `corners` and `strokes`, from the preferences, which OK updates; Transform Each opens on the values it was last confirmed with (not `copy`), and its Copy button confirms with `copy: true`; the envelope dialogs start from the selected envelope, Make opens as Reset (`reset: true`) while one is selected)",
|
||||
"{command: object.move|object.rotate|object.scale|object.reflect|object.shear|object.transformEach|path.average|path.averageJoin|object.path.offsetPath|object.path.simplify|object.path.smooth|object.path.splitIntoGrid|object.vectorHalftone|artboard.rearrange|artboard.rename|object.envelope.makeWithWarp|object.envelope.resetWithWarp|object.envelope.makeWithMesh|object.envelope.resetWithMesh|object.envelope.options|addon.arrange.grid|addon.arrange.replace|addon.arrange.size|addon.packaging.setFoldAngle|addon.pathtools.cornerSet|addon.pathtools.divideDashes|addon.pathtools.bridge|addon.pathtools.tangentCircle|addon.type.textTweaker|addon.color.swatchLegend|addon.arrange.randomizeOpacity|addon.arrange.sort|addon.color.applyNearestSwatch|addon.select.byArtboards|type.smartPunctuation|variable.define|variable.rename|variable.bind|dataset.new|dataset.set|dataset.rename|dataset.select} open the dialog that command's menu item opens (its `key` in ui.inspect is the command id, except `transformEach` for object.transformEach, `envelopeWarp` for object.envelope.makeWithWarp and object.envelope.resetWithWarp, `envelopeMesh` for object.envelope.makeWithMesh and object.envelope.resetWithMesh, `variables` for variable.define and variable.rename and variable.bind and dataset.new and dataset.set and dataset.rename and dataset.select, and `envelopeOptions` for object.envelope.options; the dialogs of addon.color.applyNearestSwatch and addon.select.byArtboards have no `key`; a slider over the canvas, not a dialog, for object.path.smooth, and for object.path.simplify until OK in its dialog keeps the settings (`retain`); Set Fold Angle's `angle` is the selected fold lines' angle, and it is refused while the selection has no fold line it can change; Scale and Transform Each have `corners` and `strokes`, from the preferences, which OK updates; Transform Each opens on the values it was last confirmed with (not `copy`), and its Copy button confirms with `copy: true`; the envelope dialogs start from the selected envelope, Make opens as Reset (`reset: true`) while one is selected; variable.rename opens only while the document has a variable, and dataset.set and dataset.rename only while it has a data set, and otherwise the status bar says why; ui.dialog.set, ui.dialog.confirm and ui.dialog.cancel take the dialog's `id` from ui.inspect, or `top`, not its `key`)",
|
||||
),
|
||||
(
|
||||
"ui.widthPointEdit",
|
||||
|
||||
Reference in new issue
Block a user