mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Merge pull request #18919
Co-authored-by: autocraft-bot[bot] <354215646+autocraft-bot[bot]@users.noreply.github.com>
This commit is contained in:
commit
810da14b4e
12 files changed
+295
-27
No files matched your search
@@ -69,7 +69,7 @@ pub(super) fn prepare(s: &Session, name: &str, shown: &str, path: Option<&str>,
|
||||
if s.authorize.is_some() || crate::jobs::authorization_installed() {
|
||||
return Err(EngineError::Other("RAW sidecar opening requires a trusted session; no implicit read capability is available".into()));
|
||||
}
|
||||
let prior = prior_settings(path)?;
|
||||
let prior = if defaults.ignore_xmp_sidecars { None } else { prior_settings(path)? };
|
||||
let crop = prior.as_ref().and_then(|(_, crop)| *crop);
|
||||
let prior = prior.map(|(settings, _)| settings);
|
||||
let mut settings = prior.clone().unwrap_or_default();
|
||||
|
||||
@@ -760,7 +760,7 @@ fn batch_quiet_raw_applies_prior_settings_and_workflow_without_touching_inputs()
|
||||
assert!(s.batch_open_notices.is_none());
|
||||
}
|
||||
|
||||
/// #9985: quiet RAW opening crops to the sidecar's crop, as the interactive open does.
|
||||
/// Quiet RAW opening applies a saved crop unless RAW Defaults ignores sidecars.
|
||||
#[test]
|
||||
fn batch_quiet_raw_applies_the_sidecar_crop() {
|
||||
use photocraft_raw::testgen::{DngSpec, mosaic, scene};
|
||||
@@ -771,14 +771,27 @@ fn batch_quiet_raw_applies_the_sidecar_crop() {
|
||||
std::fs::write(&path, &bytes).unwrap();
|
||||
let crop = photocraft_io::camera_raw_xmp::Crop { top: 0.25, left: 0.125, bottom: 0.75, right: 0.625 };
|
||||
let xmp = photocraft_io::camera_raw_xmp::save_with_crop(&photocraft_algo::camera_raw::CameraRaw::default(), Some(crop));
|
||||
std::fs::write(join(&dir, "raw.xmp"), &xmp).unwrap();
|
||||
let sidecar = join(&dir, "raw.xmp");
|
||||
std::fs::write(&sidecar, &xmp).unwrap();
|
||||
let mut s = crate::session();
|
||||
let output = join(&dir, "out");
|
||||
let p = json!({"input":[path],"output":output,"format":"psd","suppressOpenOptions":true,"suppressWarnings":true,"steps":[]});
|
||||
let result = s.execute("file.automate.batch", p).unwrap();
|
||||
let mut p = json!({"input":[path],"output":output,"format":"psd","suppressOpenOptions":true,"suppressWarnings":true,"steps":[]});
|
||||
let result = s.execute("file.automate.batch", p.clone()).unwrap();
|
||||
assert!(result["errors"].as_array().unwrap().is_empty(), "{result}");
|
||||
let actual = photocraft_io::import("raw.psd", &std::fs::read(join(&output, "raw.psd")).unwrap()).unwrap().document;
|
||||
assert_eq!((actual.size.width, actual.size.height), (12, 8), "the 24x16 frame cropped to x 3..15, y 4..12");
|
||||
|
||||
let ignored = join(&dir, "ignored");
|
||||
p["output"] = json!(ignored);
|
||||
// A directory at the sidecar path is refused by the ordinary reader even before XML is parsed.
|
||||
std::fs::rename(&sidecar, join(&dir, "original.xmp")).unwrap();
|
||||
std::fs::create_dir(&sidecar).unwrap();
|
||||
s.execute("prefs.set", json!({"path":"rawDefaults.ignoreXmpSidecars","value":true})).unwrap();
|
||||
let result = s.execute("file.automate.batch", p).unwrap();
|
||||
assert!(result["errors"].as_array().unwrap().is_empty(), "{result}");
|
||||
let actual = photocraft_io::import("raw.psd", &std::fs::read(join(&ignored, "raw.psd")).unwrap()).unwrap().document;
|
||||
assert_eq!((actual.size.width, actual.size.height), (24, 16), "ignoring sidecars keeps the full RAW extent");
|
||||
assert!(std::path::Path::new(&sidecar).is_dir());
|
||||
}
|
||||
|
||||
fn tmp(name: &str) -> String {
|
||||
|
||||
@@ -1189,8 +1189,12 @@ pub struct RawDefaults {
|
||||
pub demosaic: RawDemosaic,
|
||||
/// Keep a raw file's develop settings in a sidecar (`IMG_0001.xmp` beside `IMG_0001.CR2`),
|
||||
/// as Camera Raw's "Save image settings in: Sidecar .xmp files"; the sidecar is read again
|
||||
/// when the file is next opened. Off reads sidecars but never writes one.
|
||||
/// when the file is next opened. Off disables automatic writes.
|
||||
pub write_xmp_sidecars: bool,
|
||||
/// Ignore adjacent XMP sidecars when opening raws. Kept separate from
|
||||
/// `write_xmp_sidecars` so older clients can continue to use that preference: setting it
|
||||
/// selects the historical sidecar/read-only behavior and clears this flag.
|
||||
pub ignore_xmp_sidecars: bool,
|
||||
}
|
||||
|
||||
impl RawDefaults {
|
||||
@@ -1276,6 +1280,7 @@ impl Default for RawDefaults {
|
||||
open_in_camera_raw: true,
|
||||
demosaic: RawDemosaic::Ahd,
|
||||
write_xmp_sidecars: true,
|
||||
ignore_xmp_sidecars: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,16 @@ fn prefs_set(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Preserve the historical API: a client setting writeXmpSidecars still means that
|
||||
// adjacent sidecars are used, with `false` meaning read-only. The new ignore choice is
|
||||
// expressed by setting only ignoreXmpSidecars; it also disables automatic sidecar writes.
|
||||
let legacy_sidecar_choice = changes.iter().any(|(path, _)| path == "rawDefaults.writeXmpSidecars");
|
||||
let ignore_sidecars = changes.iter().rev().find(|(path, _)| path == "rawDefaults.ignoreXmpSidecars").and_then(|(_, value)| value.as_bool());
|
||||
if ignore_sidecars == Some(true) {
|
||||
s.prefs.edit(|prefs| prefs.raw_defaults.write_xmp_sidecars = false);
|
||||
} else if ignore_sidecars.is_none() && legacy_sidecar_choice {
|
||||
s.prefs.edit(|prefs| prefs.raw_defaults.ignore_xmp_sidecars = false);
|
||||
}
|
||||
if color_changed && let Err(e) = crate::color_cmds::validate_settings(&s.color().settings) {
|
||||
s.prefs.edit(|p| *p = saved_prefs);
|
||||
s.color_mut().settings = saved_color;
|
||||
@@ -105,6 +115,9 @@ fn prefs_reset(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Some(path) => {
|
||||
let mut next = s.prefs().clone();
|
||||
next.reset(Some(path)).map_err(|e| bad("prefs.reset", e))?;
|
||||
if path == "rawDefaults.writeXmpSidecars" {
|
||||
next.raw_defaults.ignore_xmp_sidecars = false;
|
||||
}
|
||||
s.edit_prefs(|p| *p = next);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! draws the tiles; this module holds the raws and their thumbnails.
|
||||
|
||||
use super::open::{Target, commit_open_raw, open_raw_with, return_on_failure};
|
||||
use super::sidecar::read_sidecar;
|
||||
use super::sidecar::read_configured_sidecar;
|
||||
use super::{CameraRaw, PhotocraftApp, RawOpen, Rect, Value, hosted, image, json, workspace_demosaic};
|
||||
use photocraft_engine::color_cmds::ColorExt;
|
||||
|
||||
@@ -155,8 +155,9 @@ pub(super) fn keep(app: &mut PhotocraftApp, settings: &CameraRaw, demosaic: phot
|
||||
|
||||
/// The settings Open develops a never-shown filmstrip raw with, and what they started from:
|
||||
/// its sidecar's, else the Camera Raw Defaults' Auto when that is on, else the defaults.
|
||||
pub(super) fn first_settings(app: &PhotocraftApp, raw: &RawOpen) -> (CameraRaw, Option<CameraRaw>) {
|
||||
if let Some((loaded, _, _)) = raw.path.as_deref().and_then(read_sidecar) {
|
||||
pub(super) fn first_settings(app: &PhotocraftApp, raw: &mut RawOpen) -> (CameraRaw, Option<CameraRaw>) {
|
||||
if let Some((loaded, report, _)) = raw.path.as_deref().and_then(|path| read_configured_sidecar(app, path)) {
|
||||
raw.crop = report.crop;
|
||||
return (loaded.clone(), Some(loaded));
|
||||
}
|
||||
let mut p = CameraRaw::default();
|
||||
@@ -194,10 +195,10 @@ pub(super) fn open_all(app: &mut PhotocraftApp, params: &CameraRaw, raw: &RawOpe
|
||||
}
|
||||
for id in others {
|
||||
let Some(held) = app.raw_shelf.iter().find(|h| h.raw.document == id) else { continue };
|
||||
let (held_raw, kept) = (held.raw.clone(), held.kept.clone());
|
||||
let (mut held_raw, kept) = (held.raw.clone(), held.kept.clone());
|
||||
let (p, loaded) = match kept {
|
||||
Some((p, original)) => (p, Some(original)),
|
||||
None => first_settings(app, &held_raw),
|
||||
None => first_settings(app, &mut held_raw),
|
||||
};
|
||||
match commit_open_raw(app, &p, &held_raw, loaded.as_ref()) {
|
||||
Ok(v) => {
|
||||
@@ -225,11 +226,12 @@ pub(super) fn done(app: &mut PhotocraftApp, settings: &CameraRaw) -> Value {
|
||||
let Some(raw) = app.raw.as_ref().and_then(|s| s.raw_open.clone()) else { return Value::Null };
|
||||
let mut raws = vec![(raw.clone(), settings.clone())];
|
||||
for held in app.raw_shelf.iter().filter(|h| h.raw.document != raw.document) {
|
||||
let mut held_raw = held.raw.clone();
|
||||
let p = match &held.kept {
|
||||
Some((p, _)) => p.clone(),
|
||||
None => first_settings(app, &held.raw).0,
|
||||
None => first_settings(app, &mut held_raw).0,
|
||||
};
|
||||
raws.push((held.raw.clone(), p));
|
||||
raws.push((held_raw, p));
|
||||
}
|
||||
let stored: Vec<Stored> = raws.iter().map(|(raw, p)| super::sidecar::store_sidecar(app, raw, p)).collect();
|
||||
let saved: Vec<&String> = stored.iter().filter_map(|s| if let Stored::Written(name) = s { Some(name) } else { None }).collect();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::convert::{RawStart, apply_raw_conversions, open_pixels, open_raw_pixels, output_sharpening, raw_conversions};
|
||||
use super::sidecar::{read_sidecar, write_sidecar};
|
||||
use super::sidecar::{read_configured_sidecar, write_sidecar};
|
||||
use super::{CameraRaw, LayerId, PhotocraftApp, Rect, Value, json};
|
||||
use photocraft_engine::color_cmds::ColorExt;
|
||||
|
||||
@@ -81,7 +81,7 @@ pub fn queue_open_dialog(
|
||||
demosaic: method,
|
||||
decoded: None,
|
||||
// Read now: a filmstrip raw that is never shown still opens with its sidecar's crop.
|
||||
crop: path.and_then(read_sidecar).and_then(|(_, report, _)| report.crop),
|
||||
crop: path.and_then(|path| read_configured_sidecar(app, path)).and_then(|(_, report, _)| report.crop),
|
||||
};
|
||||
let held = super::filmstrip::HeldRaw::new(app, raw);
|
||||
app.raw_shelf.push(held);
|
||||
@@ -97,6 +97,11 @@ pub(super) fn open_raw(app: &mut PhotocraftApp, ctx: &egui::Context, raw: RawOpe
|
||||
/// [`open_raw`], or with `kept` settings and the settings they started from (a filmstrip raw
|
||||
/// shown again).
|
||||
pub(super) fn open_raw_with(app: &mut PhotocraftApp, ctx: &egui::Context, mut raw: RawOpen, kept: Option<(CameraRaw, CameraRaw)>) -> Result<(), String> {
|
||||
// A filmstrip entry may have captured its crop before the user changed this preference.
|
||||
// Recheck at display time so an ignored sidecar cannot affect the eventual open.
|
||||
if app.session.prefs().raw_defaults.ignore_xmp_sidecars {
|
||||
raw.crop = None;
|
||||
}
|
||||
let index = document_index(app, raw.document).ok_or("the raw document was closed")?;
|
||||
app.session.set_active(index);
|
||||
let (layer, surf, _) = crate::distort_ui::active_pixels(app)?;
|
||||
@@ -108,7 +113,7 @@ pub(super) fn open_raw_with(app: &mut PhotocraftApp, ctx: &egui::Context, mut ra
|
||||
// status bar names what it could not apply.
|
||||
let mut params = CameraRaw::default();
|
||||
let mut from_sidecar = false;
|
||||
if let Some((loaded, report, file)) = raw.path.as_deref().and_then(read_sidecar) {
|
||||
if let Some((loaded, report, file)) = raw.path.as_deref().and_then(|path| read_configured_sidecar(app, path)) {
|
||||
params = loaded;
|
||||
raw.crop = report.crop;
|
||||
from_sidecar = true;
|
||||
@@ -196,6 +201,9 @@ pub(super) fn raw_stage(p: &CameraRaw) -> photocraft_io::raw::Tone {
|
||||
pub(super) fn commit_open_raw(app: &mut PhotocraftApp, params: &CameraRaw, raw: &RawOpen, loaded: Option<&CameraRaw>) -> Result<Value, String> {
|
||||
let index = document_index(app, raw.document).ok_or("the raw document was closed")?;
|
||||
write_sidecar(app, raw, params, loaded);
|
||||
// `open_all` can commit never-shown filmstrip raws whose crop was captured before Ignore
|
||||
// was selected. Recheck at commit so the preference covers those cached entries too.
|
||||
let crop = if app.session.prefs().raw_defaults.ignore_xmp_sidecars { None } else { raw.crop };
|
||||
let tuning = photocraft_io::raw::RawTuning {
|
||||
temperature: params.temperature,
|
||||
tint: params.tint,
|
||||
@@ -208,7 +216,7 @@ pub(super) fn commit_open_raw(app: &mut PhotocraftApp, params: &CameraRaw, raw:
|
||||
dehaze: params.dehaze,
|
||||
// The sidecar's crop: re-developing crops the document, before the Camera Raw step, so
|
||||
// the post-crop vignette centres on the crop as in Camera Raw.
|
||||
crop: raw.crop,
|
||||
crop,
|
||||
};
|
||||
// The open itself: the default settings, developed with the method it was opened with.
|
||||
let as_opened = photocraft_io::raw::RawTuning { demosaic: raw.developed_with, ..Default::default() };
|
||||
@@ -403,7 +411,7 @@ pub fn opened_without_dialog(app: &mut PhotocraftApp, index: usize, name: &str,
|
||||
crop: None,
|
||||
};
|
||||
let mut params = CameraRaw::default();
|
||||
let sidecar = path.and_then(read_sidecar).map(|(loaded, report, _)| {
|
||||
let sidecar = path.and_then(|path| read_configured_sidecar(app, path)).map(|(loaded, report, _)| {
|
||||
raw.crop = report.crop;
|
||||
loaded
|
||||
});
|
||||
|
||||
@@ -40,6 +40,12 @@ pub(super) fn read_sidecar(_: &str) -> Option<(CameraRaw, photocraft_io::camera_
|
||||
None
|
||||
}
|
||||
|
||||
/// Read a sidecar for the app's automatic open and filmstrip paths, unless the user chose to
|
||||
/// ignore adjacent XMP files. Explicit Load Settings remains a separate file-picker action.
|
||||
pub(super) fn read_configured_sidecar(app: &PhotocraftApp, path: &str) -> Option<(CameraRaw, photocraft_io::camera_raw_xmp::LoadReport, String)> {
|
||||
if app.session.prefs().raw_defaults.ignore_xmp_sidecars { None } else { read_sidecar(path) }
|
||||
}
|
||||
|
||||
/// Keep the develop settings beside the raw file (Camera Raw Defaults › Write xmp sidecars):
|
||||
/// written when the settings aren't the defaults or PhotoCraft's own sidecar is there, so a
|
||||
/// file reopens as it was developed. `loaded` are the settings the open started from: nothing
|
||||
@@ -48,7 +54,8 @@ pub(super) fn read_sidecar(_: &str) -> Option<(CameraRaw, photocraft_io::camera_
|
||||
/// never for a control or MCP request (it has no authority to write beside the user's files), and
|
||||
/// never fatal: a folder that can't be written to is reported in a notice.
|
||||
pub(super) fn write_sidecar(app: &mut PhotocraftApp, raw: &RawOpen, params: &CameraRaw, loaded: Option<&CameraRaw>) {
|
||||
if !app.session.prefs().raw_defaults.write_xmp_sidecars || loaded == Some(params) {
|
||||
let defaults = &app.session.prefs().raw_defaults;
|
||||
if defaults.ignore_xmp_sidecars || !defaults.write_xmp_sidecars || loaded == Some(params) {
|
||||
return;
|
||||
}
|
||||
store_sidecar(app, raw, params);
|
||||
@@ -68,13 +75,17 @@ pub(super) enum Stored {
|
||||
Failed,
|
||||
}
|
||||
|
||||
/// Writes `params` to `raw`'s sidecar under [`write_sidecar`]'s rules, whatever the preference
|
||||
/// (Done asks for it).
|
||||
/// Writes `params` to `raw`'s sidecar for the explicit Done action, even when automatic writing is
|
||||
/// off. Automation and Ignore remain hard stops.
|
||||
pub(super) fn store_sidecar(app: &mut PhotocraftApp, raw: &RawOpen, params: &CameraRaw) -> Stored {
|
||||
if app.automation_input || app.session.authorize.is_some() {
|
||||
log::info!("{}: sidecar not written for an automation request", raw.name);
|
||||
return Stored::Skipped;
|
||||
}
|
||||
if app.session.prefs().raw_defaults.ignore_xmp_sidecars {
|
||||
log::info!("{}: sidecar not written because sidecars are ignored", raw.name);
|
||||
return Stored::Skipped;
|
||||
}
|
||||
let Some(path) = raw.path.as_deref().filter(|p| !is_dng(p)) else { return Stored::Skipped };
|
||||
let sidecar = sidecar_path(path);
|
||||
let name = crate::file_open::display_name(&sidecar);
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn old_raw_defaults_keep_the_sidecar_read_only_state() {
|
||||
let old: photocraft_engine::prefs::RawDefaults = serde_json::from_value(json!({"writeXmpSidecars": false})).unwrap();
|
||||
assert!(!old.write_xmp_sidecars);
|
||||
assert!(!old.ignore_xmp_sidecars, "a missing field does not turn legacy read-only into Ignore");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sidecar_choice_round_trips_and_keeps_legacy_prefs_set_semantics() {
|
||||
let (mut app, _) = raw_app();
|
||||
app.run("prefs.set", json!({"path": "rawDefaults.ignoreXmpSidecars", "value": true})).unwrap();
|
||||
assert!(app.session.prefs().raw_defaults.ignore_xmp_sidecars);
|
||||
assert!(!app.session.prefs().raw_defaults.write_xmp_sidecars, "ignore disables automatic writes");
|
||||
|
||||
// Returning to Always from Ignore updates both parts of the selector's draft.
|
||||
app.run("prefs.set", json!({"values": {"rawDefaults.writeXmpSidecars": true, "rawDefaults.ignoreXmpSidecars": false}})).unwrap();
|
||||
assert!(app.session.prefs().raw_defaults.write_xmp_sidecars);
|
||||
assert!(!app.session.prefs().raw_defaults.ignore_xmp_sidecars);
|
||||
|
||||
// The intermediate read-only state remains distinguishable from Ignore.
|
||||
app.run("prefs.set", json!({"values": {"rawDefaults.writeXmpSidecars": false, "rawDefaults.ignoreXmpSidecars": false}})).unwrap();
|
||||
assert!(!app.session.prefs().raw_defaults.write_xmp_sidecars);
|
||||
assert!(!app.session.prefs().raw_defaults.ignore_xmp_sidecars);
|
||||
|
||||
// Older clients use only writeXmpSidecars: true means use/write sidecars; false means read-only.
|
||||
app.run("prefs.set", json!({"path": "rawDefaults.ignoreXmpSidecars", "value": true})).unwrap();
|
||||
app.run("prefs.set", json!({"path": "rawDefaults.writeXmpSidecars", "value": true})).unwrap();
|
||||
assert!(app.session.prefs().raw_defaults.write_xmp_sidecars);
|
||||
assert!(!app.session.prefs().raw_defaults.ignore_xmp_sidecars);
|
||||
app.run("prefs.set", json!({"path": "rawDefaults.writeXmpSidecars", "value": false})).unwrap();
|
||||
assert!(!app.session.prefs().raw_defaults.write_xmp_sidecars);
|
||||
assert!(!app.session.prefs().raw_defaults.ignore_xmp_sidecars);
|
||||
|
||||
// A rejected sibling change cannot leave the preference half-normalized.
|
||||
app.run("prefs.set", json!({"path": "rawDefaults.writeXmpSidecars", "value": true})).unwrap();
|
||||
assert!(app.run("prefs.set", json!({"values": {"rawDefaults.ignoreXmpSidecars": true, "rawDefaults.colorSpace": "unsupported"}}),).is_err());
|
||||
assert!(app.session.prefs().raw_defaults.write_xmp_sidecars);
|
||||
assert!(!app.session.prefs().raw_defaults.ignore_xmp_sidecars);
|
||||
}
|
||||
|
||||
/// Ignore skips sidecar reads for filmstrip and no-dialog opens, leaves the file untouched, and
|
||||
/// suppresses both automatic Open and explicit Done writes. Explicit Load Settings stays separate.
|
||||
#[test]
|
||||
fn ignore_sidecar_choice_skips_open_routes_but_keeps_explicit_file_import() {
|
||||
let mut source_settings = CameraRaw::default();
|
||||
source_settings.exposure = 1.0;
|
||||
let crop = photocraft_io::camera_raw_xmp::Crop { top: 0.25, left: 0.125, bottom: 0.75, right: 0.625 };
|
||||
let sidecar = photocraft_io::camera_raw_xmp::save_with_crop(&source_settings, Some(crop));
|
||||
let files = Arc::new(ScriptedFiles::answering([]));
|
||||
let (mut app, dng, dir, raw_path, written) = raw_with_sidecar_and_files("ignored-choice", Some(&sidecar), Some(files.clone()));
|
||||
let before = std::fs::read_to_string(sidecar_path(&raw_path)).unwrap();
|
||||
let ctx = app.ctx().clone();
|
||||
|
||||
// File-list admission may have captured a crop before the user changes the choice. Ignore
|
||||
// must still take effect when that queued filmstrip entry is shown.
|
||||
app.open_file(&raw_path, &dng).unwrap();
|
||||
let second_path = dir.join("IMG_0101.cr2").to_string_lossy().into_owned();
|
||||
std::fs::write(&second_path, &dng).unwrap();
|
||||
std::fs::write(sidecar_path(&second_path), &sidecar).unwrap();
|
||||
app.open_file(&second_path, &dng).unwrap();
|
||||
assert_eq!(app.raw_shelf.len(), 2);
|
||||
app.run("prefs.set", json!({"path": "rawDefaults.ignoreXmpSidecars", "value": true})).unwrap();
|
||||
filmstrip::open_held(&mut app, &ctx, 0).unwrap();
|
||||
assert_eq!(shown(&app).exposure, 0.0, "the ignored sidecar does not fill RAW Develop");
|
||||
let opened = menu(&mut app, &ctx, "filter.cameraRaw", &json!({"ui": {"set": {"contrast": 15}, "commit": true}})).unwrap().unwrap();
|
||||
assert_eq!(opened["opened"].as_array().map(Vec::len), Some(2));
|
||||
let sizes: Vec<_> = app.session.documents().iter().map(|st| (st.doc.size.width, st.doc.size.height)).collect();
|
||||
assert_eq!(sizes, [(48, 32); 2], "the shown and never-shown raws both ignore cached sidecar crops");
|
||||
assert!(written.lock().unwrap().is_empty(), "Ignore suppresses automatic filmstrip writes");
|
||||
assert_eq!(std::fs::read_to_string(sidecar_path(&raw_path)).unwrap(), before);
|
||||
assert_eq!(std::fs::read_to_string(sidecar_path(&second_path)).unwrap(), sidecar);
|
||||
|
||||
// The no-dialog open uses the same Ignore setting.
|
||||
app.run("prefs.set", json!({"path": "rawDefaults.openInCameraRaw", "value": false})).unwrap();
|
||||
let third_path = dir.join("IMG_0102.cr2").to_string_lossy().into_owned();
|
||||
std::fs::write(&third_path, &dng).unwrap();
|
||||
std::fs::write(sidecar_path(&third_path), &sidecar).unwrap();
|
||||
app.open_file(&third_path, &dng).unwrap();
|
||||
let st = app.session.active().unwrap();
|
||||
assert_eq!((st.doc.size.width, st.doc.size.height), (48, 32), "the no-dialog path ignores the crop too");
|
||||
assert_eq!(st.saved_revision, st.revision);
|
||||
|
||||
// Explicit Done is still a user-requested sidecar write in the legacy modes, but Ignore blocks it
|
||||
// before checking whether an adjacent file belongs to PhotoCraft.
|
||||
app.run("prefs.set", json!({"path": "rawDefaults.openInCameraRaw", "value": true})).unwrap();
|
||||
let fourth_path = dir.join("IMG_0103.cr2").to_string_lossy().into_owned();
|
||||
std::fs::write(&fourth_path, &dng).unwrap();
|
||||
open_dialog_at(&mut app, &ctx, &dng, &fourth_path);
|
||||
menu(&mut app, &ctx, "filter.cameraRaw", &json!({"ui": {"set": {"contrast": 20}}})).unwrap().unwrap();
|
||||
let done = done(&mut app, &ctx).unwrap();
|
||||
assert_eq!(done["saved"], json!([]));
|
||||
assert!(written.lock().unwrap().is_empty(), "Done cannot write in Ignore mode");
|
||||
|
||||
// The explicit Load Settings picker remains available even though automatic sidecar reads are ignored.
|
||||
files.queue(Picked::Contents(vec![("Manual.xmp".into(), {
|
||||
let mut settings = CameraRaw::default();
|
||||
settings.exposure = 0.75;
|
||||
photocraft_io::camera_raw_xmp::save(&settings).into_bytes()
|
||||
})]));
|
||||
let manual_path = dir.join("IMG_0104.cr2").to_string_lossy().into_owned();
|
||||
std::fs::write(&manual_path, &dng).unwrap();
|
||||
open_dialog_at(&mut app, &ctx, &dng, &manual_path);
|
||||
menu(&mut app, &ctx, "filter.cameraRaw", &json!({"ui": {"loadSettings": true}})).unwrap().unwrap();
|
||||
frame(&mut app);
|
||||
app.poll_file_dialog();
|
||||
frame(&mut app);
|
||||
assert!(matches!(files.requests().as_slice(), [request] if request.kind == PickKind::Open), "Load Settings asks for one file");
|
||||
assert_eq!(shown(&app).exposure, 0.75, "explicit file import remains available");
|
||||
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enabling_sidecars_after_queueing_applies_and_preserves_the_unshown_crop() {
|
||||
use photocraft_io::camera_raw_xmp::{Crop, load, save_with_crop};
|
||||
|
||||
let crop = Crop { top: 0.25, left: 0.125, bottom: 0.75, right: 0.625 };
|
||||
let mut settings = CameraRaw::default();
|
||||
settings.exposure = 1.0;
|
||||
for (tag, save_only) in [("unshown-crop-open", false), ("unshown-crop-done", true)] {
|
||||
let (mut app, dng, dir, first_path, written) = raw_with_sidecar(tag, None);
|
||||
let ctx = app.ctx().clone();
|
||||
let second_path = dir.join("IMG_0101.cr2").to_string_lossy().into_owned();
|
||||
let second_sidecar = sidecar_path(&second_path);
|
||||
std::fs::write(&second_path, &dng).unwrap();
|
||||
std::fs::write(&second_sidecar, save_with_crop(&settings, Some(crop))).unwrap();
|
||||
|
||||
app.run("prefs.set", json!({"path": "rawDefaults.ignoreXmpSidecars", "value": true})).unwrap();
|
||||
app.open_file(&first_path, &dng).unwrap();
|
||||
app.open_file(&second_path, &dng).unwrap();
|
||||
assert_eq!(app.raw_shelf.len(), 2);
|
||||
assert!(app.raw_shelf[1].raw.crop.is_none(), "Ignore omits the queued crop");
|
||||
filmstrip::open_held(&mut app, &ctx, 0).unwrap();
|
||||
app.run("prefs.set", json!({"values": {"rawDefaults.writeXmpSidecars": true, "rawDefaults.ignoreXmpSidecars": false}})).unwrap();
|
||||
|
||||
if save_only {
|
||||
let reply = done(&mut app, &ctx).unwrap();
|
||||
assert_eq!(reply["saved"], json!(["IMG_0101.xmp"]));
|
||||
let writes = written.lock().unwrap();
|
||||
let [(path, bytes)] = writes.as_slice() else { panic!("expected one sidecar write") };
|
||||
assert_eq!(path, &second_sidecar);
|
||||
let mut saved = CameraRaw::default();
|
||||
assert_eq!(load(&mut saved, bytes).unwrap().crop, Some(crop));
|
||||
assert_eq!(saved.exposure, settings.exposure);
|
||||
} else {
|
||||
let opened = menu(&mut app, &ctx, "filter.cameraRaw", &json!({"ui": {"commit": true}})).unwrap().unwrap();
|
||||
assert_eq!(opened["opened"].as_array().map(Vec::len), Some(2));
|
||||
let sizes: Vec<_> = app.session.documents().iter().map(|s| (s.doc.size.width, s.doc.size.height)).collect();
|
||||
assert_eq!(sizes, [(48, 32), (24, 16)], "Open All applies the crop to the unshown raw");
|
||||
assert!(written.lock().unwrap().is_empty(), "opening unchanged settings does not rewrite the sidecar");
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
}
|
||||
@@ -468,6 +468,10 @@ std::thread_local! {
|
||||
/// test is about to take. The turn is held until the test's thread ends (nextest runs each test
|
||||
/// in its own process, where this costs nothing).
|
||||
fn raw_app() -> (Box<PhotocraftApp>, Vec<u8>) {
|
||||
raw_app_with_files(None)
|
||||
}
|
||||
|
||||
fn raw_app_with_files(files: Option<Arc<dyn craft::host::Files>>) -> (Box<PhotocraftApp>, Vec<u8>) {
|
||||
use photocraft_raw::testgen::{DngSpec, mosaic, scene};
|
||||
static TURN: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
||||
RAW_OPEN_TURN.with(|held| {
|
||||
@@ -480,6 +484,7 @@ fn raw_app() -> (Box<PhotocraftApp>, Vec<u8>) {
|
||||
import: Some(Box::new(|name: &str, b: &[u8], opts: &photocraft_io::ImportOptions| {
|
||||
photocraft_io::import_with_options(name, b, opts).map(|r| (r.document, r.warnings)).map_err(|e| e.to_string())
|
||||
})),
|
||||
files,
|
||||
..Default::default()
|
||||
};
|
||||
let (w, h) = (48, 32);
|
||||
@@ -882,8 +887,9 @@ fn auto_tone_of_a_never_shown_raw_matches_the_dialogs() {
|
||||
}
|
||||
}
|
||||
let method = photocraft_io::raw::Demosaic::Ahd;
|
||||
let raw = RawOpen { document, name: "pattern.dng".into(), path: None, bytes: None, decoded: None, developed_with: method, demosaic: method, crop: None };
|
||||
let (unshown, _) = filmstrip::first_settings(&app, &raw);
|
||||
let mut raw =
|
||||
RawOpen { document, name: "pattern.dng".into(), path: None, bytes: None, decoded: None, developed_with: method, demosaic: method, crop: None };
|
||||
let (unshown, _) = filmstrip::first_settings(&app, &mut raw);
|
||||
open_raw(&mut app, &ctx, raw).unwrap();
|
||||
let current = shown(&app);
|
||||
let tone = |p: &CameraRaw| [p.exposure, p.contrast, p.highlights, p.shadows, p.whites, p.blacks];
|
||||
@@ -1098,7 +1104,15 @@ const LIGHTROOM_SIDECAR: &str = r#"<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="
|
||||
/// folder with `sidecar` beside it when given. Returns the app, the raw's bytes, the folder,
|
||||
/// the raw's path and the recorded writes.
|
||||
fn raw_with_sidecar(tag: &str, sidecar: Option<&str>) -> (Box<PhotocraftApp>, Vec<u8>, std::path::PathBuf, String, Written) {
|
||||
let (mut app, dng) = raw_app();
|
||||
raw_with_sidecar_and_files(tag, sidecar, None)
|
||||
}
|
||||
|
||||
fn raw_with_sidecar_and_files(
|
||||
tag: &str,
|
||||
sidecar: Option<&str>,
|
||||
files: Option<Arc<dyn craft::host::Files>>,
|
||||
) -> (Box<PhotocraftApp>, Vec<u8>, std::path::PathBuf, String, Written) {
|
||||
let (mut app, dng) = raw_app_with_files(files);
|
||||
let dir = std::env::temp_dir().join(format!("photocraft-sidecar-{tag}-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
@@ -1516,3 +1530,6 @@ fn done_keeps_the_raws_open_when_a_sidecar_write_fails() {
|
||||
assert!(app.raw.is_none() && !app.ui.status_error, "{}", app.ui.status);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[path = "sidecar_choice_tests.rs"]
|
||||
mod sidecar_choice_tests;
|
||||
@@ -39,6 +39,8 @@ const LIGHT_THEME: &str = "interface.lightTheme";
|
||||
const DARK_THEME: &str = "interface.darkTheme";
|
||||
const FAVORITE_THEMES: &str = "interface.favoriteThemes";
|
||||
const DENSITY: &str = "interface.density";
|
||||
const RAW_XMP_SIDECARS: &str = "rawDefaults.writeXmpSidecars";
|
||||
const RAW_IGNORE_XMP_SIDECARS: &str = "rawDefaults.ignoreXmpSidecars";
|
||||
const RAW_RESOLUTION: &str = "rawDefaults.resolution";
|
||||
const RAW_SHARPEN_FOR: &str = "rawDefaults.sharpenFor";
|
||||
const RAW_SHARPEN_AMOUNT: &str = "rawDefaults.sharpenAmount";
|
||||
@@ -99,6 +101,7 @@ impl CustomSettings<PrefPages> for PrefsCustom {
|
||||
MEMORY_PERCENT => memory_percent_row(ui, draft),
|
||||
MEMORY_MB => self.memory_mb_row(ui, draft),
|
||||
RENDERING_MODE => rendering_mode_row(ui, draft),
|
||||
RAW_XMP_SIDECARS => raw_xmp_sidecars_row(ui, draft),
|
||||
GPU_ADAPTER => self.gpu_rows(ui, draft),
|
||||
SCRATCH_DISKS => scratch_disks_row(ui, draft),
|
||||
"fileHandling.recentFiles" | "type.favoriteFonts" => self.clear_row(ui, key, draft),
|
||||
@@ -165,6 +168,43 @@ fn choose(ui: &mut egui::Ui, label: &str, salt: &'static str, current: String, o
|
||||
picked
|
||||
}
|
||||
|
||||
/// The reference offers embedded DNG XMP, sidecars, or ignoring sidecars. Embedded DNG writing
|
||||
/// is not supported here, so the selector exposes the two implemented choices and keeps the
|
||||
/// legacy choice to write only when Done is requested.
|
||||
fn raw_xmp_sidecars_row(ui: &mut egui::Ui, draft: &mut SettingsDraft) {
|
||||
let ignore: bool = draft.get(RAW_IGNORE_XMP_SIDECARS).unwrap_or(false);
|
||||
let write: bool = draft.get(RAW_XMP_SIDECARS).unwrap_or(true);
|
||||
let current = if ignore {
|
||||
"ignore"
|
||||
} else if write {
|
||||
"sidecars"
|
||||
} else {
|
||||
"readOnly"
|
||||
};
|
||||
let options = [
|
||||
("sidecars".into(), tl!("Always use sidecar XMP files").to_string()),
|
||||
("ignore".into(), tl!("Ignore sidecar XMP files").to_string()),
|
||||
("readOnly".into(), tl!("Use sidecars, write only on Done").to_string()),
|
||||
];
|
||||
if let Some(selected) = choose(ui, tl!("Sidecars"), "raw-xmp-sidecars", current.to_string(), &options) {
|
||||
match selected.as_str() {
|
||||
"sidecars" => {
|
||||
draft.set(RAW_XMP_SIDECARS, &true);
|
||||
draft.set(RAW_IGNORE_XMP_SIDECARS, &false);
|
||||
}
|
||||
"ignore" => {
|
||||
draft.set(RAW_XMP_SIDECARS, &false);
|
||||
draft.set(RAW_IGNORE_XMP_SIDECARS, &true);
|
||||
}
|
||||
"readOnly" => {
|
||||
draft.set(RAW_XMP_SIDECARS, &false);
|
||||
draft.set(RAW_IGNORE_XMP_SIDECARS, &false);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The choices a preference path lists, with their shown labels.
|
||||
fn choices_of(path: &str) -> Vec<(String, String)> {
|
||||
prefs::choices(path).unwrap_or(&[]).iter().map(|o| (o.to_string(), choice_label(o))).collect()
|
||||
|
||||
@@ -163,6 +163,7 @@ pub(super) fn rules(ctx: &egui::Context) -> Vec<SettingRule> {
|
||||
"unitsAndRulers.showRulers",
|
||||
"performance.useGpu",
|
||||
"performance.gpuBackend",
|
||||
"rawDefaults.ignoreXmpSidecars",
|
||||
] {
|
||||
tweak(&mut rules, path, |r| r.hidden());
|
||||
}
|
||||
@@ -199,6 +200,7 @@ pub(super) fn rules(ctx: &egui::Context) -> Vec<SettingRule> {
|
||||
for path in ["interface.appearanceMode", "performance.renderingMode", "performance.memoryUsageMb", "performance.memoryUsagePercent"] {
|
||||
tweak(&mut rules, path, |r| r.custom_rows());
|
||||
}
|
||||
tweak(&mut rules, "rawDefaults.writeXmpSidecars", |r| r.custom_rows());
|
||||
// The favourite fonts are the user's library, not a Type setting.
|
||||
tweak(&mut rules, "type.favoriteFonts", |r| r.keep_on_reset());
|
||||
|
||||
@@ -257,7 +259,7 @@ fn label_override(key: &str) -> Option<&'static str> {
|
||||
"gpuMemoryMb" => "GPU Memory (MB, 0 = Automatic)",
|
||||
"openInCameraRaw" => "Open in RAW Develop",
|
||||
"openAsSmartObject" => "Open as Smart Object",
|
||||
"writeXmpSidecars" => "Write XMP sidecars",
|
||||
"writeXmpSidecars" => "Sidecars",
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js
|
||||
| [Performance](#performance) | 3 | 22 | 59 | 93 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 55 not run, 4 not measurable yet (baseline 2026-10-05) |
|
||||
| [File compatibility](#file-compatibility) | 11 | 14 | 2 | io corpus: oracle ≥ 148/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 249/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 190/258, round trip ≥ 258/258 |
|
||||
| [Tools](#tools) | 36 | 9 | 0 | |
|
||||
| [Workspace and UI](#workspace-and-ui) | 15 | 6 | 2 | settings that do nothing: 9 of 205 (target 0) |
|
||||
| [Workspace and UI](#workspace-and-ui) | 15 | 6 | 2 | settings that do nothing: 9 of 206 (target 0) |
|
||||
| [Type](#type) | 6 | 6 | 0 | |
|
||||
| [Automation](#automation) | 6 | 4 | 2 | 663 of 663 menu items live (100.0%) |
|
||||
| [Reliability](#reliability) | 5 | 2 | 0 | never-crash lints on 28 of 28 crates; panic_hunt present |
|
||||
@@ -217,7 +217,7 @@ Corpus floors (`crates/io/tests/it/corpus.rs`): the enforced minimums; the corpu
|
||||
|
||||
## Workspace and UI
|
||||
|
||||
**Settings that do nothing: 9 of 205** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
|
||||
**Settings that do nothing: 9 of 206** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
|
||||
|
||||
Unread: `general.color_picker`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `workspace.enable_narrow_options_bar`, `performance.legacy_compositing`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `type_.text_engine`, `enhanced_controls.scrubby_slider_acceleration`.
|
||||
|
||||
|
||||
Reference in new issue
Block a user