mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Open Select Data Points from a checked Custom submenu item
This commit is contained in:
1 parent
95b4106694
commit
71cc84045d
3 files changed
+51
-1
No files matched your search
@@ -242,7 +242,7 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[
|
||||
(&["Image"], "Trap…", None, "image.trap"),
|
||||
(&["Image"], "---", None, "---"),
|
||||
(&["Image", "Analysis"], "Set Measurement Scale…", None, "image.analysis.setMeasurementScale"),
|
||||
(&["Image", "Analysis"], "Select Data Points…", None, "image.analysis.selectDataPoints"),
|
||||
(&["Image", "Analysis", "Select Data Points"], "Custom…", None, "image.analysis.selectDataPoints"),
|
||||
(&["Image", "Analysis"], "---", None, "---"),
|
||||
(&["Image", "Analysis"], "Record Measurements", None, "image.analysis.recordMeasurements"),
|
||||
(&["Image", "Analysis"], "---", None, "---"),
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::control::{ControlRequest, Reply};
|
||||
|
||||
const COMMAND: &str = "image.analysis.selectDataPoints";
|
||||
|
||||
fn call(app: &mut PhotocraftApp, method: &str, params: Value) -> Value {
|
||||
let ctx = app.ctx().clone();
|
||||
let (request, _) = ControlRequest::new(method, params);
|
||||
let Reply::Done(reply) = crate::control::handle(app, &ctx, &request) else { panic!("{method} replies immediately") };
|
||||
assert_eq!(reply["ok"], true, "{method}: {reply}");
|
||||
reply["result"].clone()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn data_points_submenu_has_only_a_checked_custom_item_and_opens_the_dialog() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 32, "height": 24})).unwrap();
|
||||
|
||||
let menu = call(&mut app, "ui.menu.list", json!({}));
|
||||
let rows = menu.as_array().unwrap();
|
||||
let titled_path = json!(["Image", "Analysis", "Select Data Points"]);
|
||||
let data_points: Vec<_> = rows.iter().filter(|row| row["path"] == titled_path || row["id"] == COMMAND).collect();
|
||||
assert_eq!(data_points.len(), 1, "one entry and no separator: {data_points:?}");
|
||||
let custom = data_points[0];
|
||||
assert_eq!(custom["path"], titled_path);
|
||||
assert_eq!(custom["id"], COMMAND);
|
||||
assert_eq!(custom["label"], "Custom…");
|
||||
assert_eq!(custom["checked"], true);
|
||||
assert_eq!(custom["enabled"], true);
|
||||
assert_eq!(custom["shortcut"], Value::Null);
|
||||
|
||||
let opened = call(&mut app, "ui.menu.invoke", json!({"id": custom["id"]}));
|
||||
assert_eq!(opened["dialog"], "dataPoints");
|
||||
assert!(app.dialog_open());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn data_points_submenu_keeps_the_engine_command_available_to_scripts() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
let selected = call(&mut app, "engine.execute", json!({"id": COMMAND, "params": {"selection": ["area"], "ruler": [], "count": []}}));
|
||||
assert_eq!(selected["dataPoints"]["selection"], json!(["area"]));
|
||||
assert!(!app.dialog_open());
|
||||
}
|
||||
@@ -30,6 +30,9 @@ mod tests;
|
||||
#[cfg(test)]
|
||||
mod sampler_menu_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod data_points_submenu_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../count_readout_tests.rs"]
|
||||
mod count_readout_tests;
|
||||
@@ -120,6 +123,8 @@ pub fn checked(app: &PhotocraftApp, id: &str) -> Option<bool> {
|
||||
"window.panel.notes" => Some(crate::panel_docking::is_shown(app, NOTES)),
|
||||
"image.analysis.rulerTool" => Some(app.ui.tool == Tool::Ruler),
|
||||
"image.analysis.countTool" => Some(app.ui.tool == Tool::Count),
|
||||
// The data point set is always Custom until named presets are supported.
|
||||
"image.analysis.selectDataPoints" => Some(true),
|
||||
_ => {
|
||||
// View › Proof Setup simulations: checked while that proof is shown.
|
||||
// A check item with no document too: an item's kind never changes (native menus).
|
||||
|
||||
Reference in new issue
Block a user