Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

fix(ui): unchanged Custom Proof Setup replaces active document proof profile (#3213)

buivanvu946a2aaebe9942
diff --git a/crates/engine/src/color_cmds.rs b/crates/engine/src/color_cmds.rs
index a2f50ce0d..d3ccf9e83 100644
--- a/crates/engine/src/color_cmds.rs
+++ b/crates/engine/src/color_cmds.rs
@@ -43,7 +43,7 @@ pub struct ProofSetup {
impl Default for ProofSetup {
fn default() -> Self {
ProofSetup {
- name: Builtin::CoatedCmyk.id().into(),
+ name: "working-cmyk".into(),
profile: Arc::new(Builtin::CoatedCmyk.profile().clone()),
intent: Intent::RelativeColorimetric,
bpc: true,
diff --git a/crates/ui-egui/src/filter_dialog.rs b/crates/ui-egui/src/filter_dialog.rs
index 95fef8f4f..11ca597ce 100644
--- a/crates/ui-egui/src/filter_dialog.rs
+++ b/crates/ui-egui/src/filter_dialog.rs
@@ -368,6 +368,9 @@ pub fn open(app: &mut PhotocraftApp, command: &str) -> Option<u64> {
if command == "edit.definePattern" {
fields.insert("name".into(), json!(photocraft_engine::pattern_cmds::default_name(&app.session)));
}
+ if command == "view.proofSetup" {
+ proof_setup_defaults(app, &mut fields);
+ }
if parse_spec(spec.params).iter().any(|p| p.kind == Kind::Document) {
// The document picker lists every open document (params refer to them by index).
let names: Vec<String> = app.session.documents().iter().map(|d| d.doc.name.clone()).collect();
@@ -411,6 +414,16 @@ fn warp_defaults(app: &PhotocraftApp, fields: &mut Map<String, Value>) {
fields.insert("orientation".into(), json!(if w.horizontal { "horizontal" } else { "vertical" }));
}
+/// Proof Setup reflects the active document's current proofing condition, never remembered values.
+fn proof_setup_defaults(app: &PhotocraftApp, fields: &mut Map<String, Value>) {
+ let Some(st) = app.session.active() else { return };
+ let pv = app.session.color.proof(st.doc.id);
+ fields.insert("profile".into(), json!(pv.setup.name));
+ fields.insert("intent".into(), json!(pv.setup.intent.id()));
+ fields.insert("bpc".into(), json!(pv.setup.bpc));
+ fields.insert("simulatePaper".into(), json!(pv.setup.simulate_paper));
+}
+
/// A filter dialog with live preview for `command` whose parameters follow `spec` (registry
/// notation) instead of the command's own; `fixed` params (e.g. a plug-in id) are passed through.
pub fn open_with_spec(app: &mut PhotocraftApp, command: &str, label: &str, spec: &str, fixed: Map<String, Value>) -> u64 {
@@ -777,6 +790,92 @@ mod tests {
assert!(!params_of(&f).as_object().unwrap().contains_key("reference"), "{f:?}");
}
+ /// View › Proof Setup (#3055): Custom Proof Setup opens with the active document's current
+ /// proof condition, preserving it on unchanged OK, ignoring stale remembered dialog values,
+ /// tracking document switching, applying edits, and leaving the document unchanged on Cancel.
+ #[test]
+ fn proof_setup_dialog_reflects_active_document_proof_condition() {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
+ let ctx = egui::Context::default();
+ app.run("file.new", json!({"width": 8, "height": 8})).unwrap();
+ let doc1_id = app.session.active().unwrap().doc.id;
+
+ // 0. A fresh document defaults to working-cmyk.
+ let d_fresh = crate::menus::invoke(&mut app, &ctx, "view.proofSetup.custom", Value::Null).unwrap()["dialog"].as_u64().unwrap();
+ assert_eq!(app.ui.dialog_mut(d_fresh).unwrap().fields["profile"], json!("working-cmyk"));
+ crate::dialogs::confirm(&mut app, d_fresh).unwrap();
+ assert_eq!(app.session.color.proof(doc1_id).setup.name, "working-cmyk");
+
+ // 1. Preset sets sRGB and turns Proof Colors on.
+ crate::menus::invoke(&mut app, &ctx, "view.proofSetup.internetStandardRgb", Value::Null).unwrap();
+ assert_eq!(app.session.color.proof(doc1_id).setup.name, "srgb");
+ assert!(app.session.color.proof(doc1_id).enabled);
+
+ // 2. Open Custom Proof Setup: starts with the active document's condition (sRGB).
+ let d_id = crate::menus::invoke(&mut app, &ctx, "view.proofSetup.custom", Value::Null).unwrap()["dialog"].as_u64().unwrap();
+ let fields = &app.ui.dialog_mut(d_id).unwrap().fields;
+ assert_eq!(fields["profile"], json!("srgb"));
+ assert_eq!(fields["intent"], json!("relative"));
+ assert_eq!(fields["bpc"], json!(true));
+ assert_eq!(fields["simulatePaper"], json!(false));
+
+ // 3. Unchanged OK preserves the document's condition and leaves Proof Colors enabled.
+ crate::dialogs::confirm(&mut app, d_id).unwrap();
+ let pv = app.session.color.proof(doc1_id);
+ assert_eq!(pv.setup.name, "srgb");
+ assert!(pv.enabled);
+
+ // 4. Stale remembered values do not override the active document.
+ app.session.prefs.edit(|prefs| {
+ prefs.dialogs.insert(
+ "view.proofSetup".into(),
+ json!({
+ "profile": "display-p3",
+ "intent": "perceptual",
+ "bpc": false,
+ "simulatePaper": true,
+ }),
+ );
+ });
+ let d_id = open(&mut app, "view.proofSetup").unwrap();
+ let fields = &app.ui.dialog_mut(d_id).unwrap().fields;
+ assert_eq!(fields["profile"], json!("srgb"), "reads active document, not remembered");
+ assert_eq!(fields["intent"], json!("relative"));
+ assert_eq!(fields["bpc"], json!(true));
+ assert_eq!(fields["simulatePaper"], json!(false));
+
+ // 5. Cancel preserves the document.
+ app.ui.close_dialog(d_id);
+ assert_eq!(app.session.color.proof(doc1_id).setup.name, "srgb");
+
+ // 6. Multiple documents: each document initializes the dialog to its own condition.
+ app.run("file.new", json!({"width": 8, "height": 8})).unwrap();
+ let doc2_id = app.session.active().unwrap().doc.id;
+ assert_ne!(doc1_id, doc2_id);
+ app.run("view.proofSetup", json!({"profile": "display-p3", "intent": "perceptual", "bpc": false, "simulatePaper": true})).unwrap();
+ assert_eq!(app.session.color.proof(doc2_id).setup.name, "display-p3");
+
+ let d_id2 = open(&mut app, "view.proofSetup").unwrap();
+ let fields2 = &app.ui.dialog_mut(d_id2).unwrap().fields;
+ assert_eq!(fields2["profile"], json!("display-p3"));
+ assert_eq!(fields2["intent"], json!("perceptual"));
+ assert_eq!(fields2["bpc"], json!(false));
+ assert_eq!(fields2["simulatePaper"], json!(true));
+ app.ui.close_dialog(d_id2);
+
+ // Switch back to doc1: dialog still reflects doc1's sRGB.
+ assert!(app.session.set_active(0));
+ let d_id1 = open(&mut app, "view.proofSetup").unwrap();
+ assert_eq!(app.ui.dialog_mut(d_id1).unwrap().fields["profile"], json!("srgb"));
+
+ // 7. Modifying the dialog updates the active document.
+ app.ui.dialog_mut(d_id1).unwrap().fields.insert("profile".into(), json!("adobe-rgb-compat"));
+ crate::dialogs::confirm(&mut app, d_id1).unwrap();
+ assert_eq!(app.session.color.proof(doc1_id).setup.name, "adobe-rgb-compat");
+ // doc2 is untouched
+ assert_eq!(app.session.color.proof(doc2_id).setup.name, "display-p3");
+ }
+
#[test]
fn indexed_counts_are_integer_json_while_dither_amounts_keep_their_decimals() {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());