Skip to content

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

File Handling: wire Lowercase Extension through Save As (#1941)

Reynold Hu60bce1894b38
diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs
index ed4feae4c..9337705be 100644
--- a/crates/engine/src/prefs.rs
+++ b/crates/engine/src/prefs.rs
@@ -848,7 +848,6 @@ pub const HIDDEN_UNTIL_IMPLEMENTED: &[&str] = &[
"tools.showTransformationValues",
"tools.doubleClickLayerMaskLaunchesSelectAndMask",
"fileHandling.imagePreviews",
- "fileHandling.lowercaseExtension",
"fileHandling.saveInBackground",
"fileHandling.ignoreExifProfileTag",
"fileHandling.maximizePsdCompatibility",
diff --git a/crates/ui-egui/src/file_dialog.rs b/crates/ui-egui/src/file_dialog.rs
index dd6600ff8..3b58e3574 100644
--- a/crates/ui-egui/src/file_dialog.rs
+++ b/crates/ui-egui/src/file_dialog.rs
@@ -104,7 +104,8 @@ impl PhotocraftApp {
Ok(json!({ "fileDialog": kind }))
}
- /// Ask where to save: `then` gets the chosen path.
+ /// Ask where to save: `then` gets the chosen path, with a lowercase extension when
+ /// Preferences ▸ File Handling › Lowercase Extension is on (its default).
pub(crate) fn pick_save(&mut self, suggested: &str, then: impl FnOnce(&mut Self, String) -> Result<Value, String> + 'static) -> Result<Value, String> {
let mut suggested = std::path::PathBuf::from(suggested);
// Export dialogs usually provide only a file name. Start beside the source document,
@@ -115,11 +116,24 @@ impl PhotocraftApp {
suggested = dir.join(suggested);
}
self.ask_file(FileDialogRequest::Save { suggested: suggested.to_string_lossy().into_owned() }, move |app, answer| match answer {
- FileDialogAnswer::SaveTo(path) => then(app, path),
+ FileDialogAnswer::SaveTo(path) => then(app, Self::lowercased_extension(app, path)),
_ => Err(UNEXPECTED.into()),
})
}
+ /// `X.PSD` → `X.psd`, only the extension: the stem and the folders keep the user's spelling.
+ fn lowercased_extension(app: &PhotocraftApp, path: String) -> String {
+ if !app.session.prefs().file_handling.lowercase_extension {
+ return path;
+ }
+ let p = std::path::Path::new(&path);
+ let Some(ext) = p.extension().and_then(|e| e.to_str()) else { return path };
+ if ext.bytes().all(|b| !b.is_ascii_uppercase()) {
+ return path;
+ }
+ p.with_extension(ext.to_ascii_lowercase()).to_string_lossy().into_owned()
+ }
+
/// Ask for a file a command reads (a script, notes, a placed image, presets): `then` gets its
/// name (the full path on the desktop) and bytes. A file that can't be read fails with
/// "<file name>: <why>".
diff --git a/crates/ui-egui/src/file_dialog/tests.rs b/crates/ui-egui/src/file_dialog/tests.rs
index 701f6ff2d..4fc25ab76 100644
--- a/crates/ui-egui/src/file_dialog/tests.rs
+++ b/crates/ui-egui/src/file_dialog/tests.rs
@@ -88,6 +88,29 @@ fn the_app_keeps_running_while_a_dialog_is_open() {
assert!(!app.file_dialog_open());
}
+/// Preferences ▸ File Handling ▸ Lowercase Extension (default on): the chosen path's extension
+/// is lowercased on the way to the writer; unchecked, the user's spelling is kept.
+#[test]
+fn save_paths_get_a_lowercase_extension_when_the_preference_is_on() {
+ let ctx = egui::Context::default();
+ {
+ let (mut app, open, written) = app();
+ menus::invoke(&mut app, &ctx, "file.saveAs", json!({})).unwrap();
+ app.poll_file_dialog(&ctx, None);
+ answer(&open, Some(FileDialogAnswer::SaveTo("/pics/CAT.PSD".into())));
+ app.poll_file_dialog(&ctx, None);
+ assert_eq!(*written.borrow(), ["/pics/CAT.psd"], "only the extension is lowercased");
+ assert_eq!(app.session.active().unwrap().path.as_deref(), Some("/pics/CAT.psd"));
+ }
+ let (mut app, open, written) = app();
+ app.run("prefs.set", json!({"path": "fileHandling.lowercaseExtension", "value": false})).unwrap();
+ menus::invoke(&mut app, &ctx, "file.saveAs", json!({})).unwrap();
+ app.poll_file_dialog(&ctx, None);
+ answer(&open, Some(FileDialogAnswer::SaveTo("/pics/CAT.PSD".into())));
+ app.poll_file_dialog(&ctx, None);
+ assert_eq!(*written.borrow(), ["/pics/CAT.PSD"], "off keeps the user's spelling");
+}
+
#[test]
fn save_and_export_dialogs_start_beside_the_document() {
let (mut app, open, _) = app();
diff --git a/docs/scorecard.md b/docs/scorecard.md
index 19ab073ab..6cc09b30d 100644
--- a/docs/scorecard.md
+++ b/docs/scorecard.md
@@ -9,7 +9,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js
| [Performance](#performance) | 3 | 22 | 14 | 48 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 7 not run, 7 not measurable yet (baseline 2026-10-05) |
| [File compatibility](#file-compatibility) | 4 | 12 | 11 | io corpus: oracle ≥ 146/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 236/309, round trip ≥ 307/309; photoshop oracles: oracle ≥ 133/256, round trip ≥ 258/256 |
| [Tools](#tools) | 13 | 14 | 8 | |
-| [Workspace and UI](#workspace-and-ui) | 5 | 6 | 12 | settings that do nothing: 52 of 141 (target 0) |
+| [Workspace and UI](#workspace-and-ui) | 5 | 6 | 12 | settings that do nothing: 51 of 141 (target 0) |
| [Type](#type) | 0 | 3 | 6 | |
| [Automation](#automation) | 3 | 2 | 6 | 627 of 627 menu items live (100.0%) |
| [Reliability](#reliability) | 5 | 0 | 2 | never-crash lints on 28 of 28 crates; panic_hunt present |
@@ -160,9 +160,9 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t
## Workspace and UI
-**Settings that do nothing: 52 of 141** (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: 51 of 141** (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`, `general.beep_when_done`, `general.export_clipboard`, `general.resize_image_during_place`, `general.always_create_smart_objects_when_placing`, `general.animated_zoom`, `general.zoom_resizes_windows`, `interface.show_channels_in_color`, `interface.dynamic_color_sliders`, `workspace.auto_collapse_icon_panels`, `workspace.auto_show_hidden_panels`, `workspace.open_documents_as_tabs`, `workspace.enable_floating_document_window_docking`, `workspace.large_tabs`, `workspace.enable_narrow_options_bar`, `tools.enable_flick_panning`, `tools.vary_round_brush_hardness_on_hud`, `tools.show_transformation_values`, `tools.double_click_layer_mask_launches_select_and_mask`, `file_handling.image_previews`, `file_handling.lowercase_extension`, `file_handling.save_in_background`, `file_handling.ignore_exif_profile_tag`, `file_handling.maximize_psd_compatibility`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `cursors.brush_preview_color`, `units_and_rulers.type_units`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `units_and_rulers.print_resolution`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.smart_quotes`, `type_.missing_glyph_protection`, `type_.show_font_names_in_english`, `type_.text_engine`, `type_.font_preview`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `enhanced_controls.zoom_with_trackpad_pinch`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`.
+Unread: `general.color_picker`, `general.beep_when_done`, `general.export_clipboard`, `general.resize_image_during_place`, `general.always_create_smart_objects_when_placing`, `general.animated_zoom`, `general.zoom_resizes_windows`, `interface.show_channels_in_color`, `interface.dynamic_color_sliders`, `workspace.auto_collapse_icon_panels`, `workspace.auto_show_hidden_panels`, `workspace.open_documents_as_tabs`, `workspace.enable_floating_document_window_docking`, `workspace.large_tabs`, `workspace.enable_narrow_options_bar`, `tools.enable_flick_panning`, `tools.vary_round_brush_hardness_on_hud`, `tools.show_transformation_values`, `tools.double_click_layer_mask_launches_select_and_mask`, `file_handling.image_previews`, `file_handling.save_in_background`, `file_handling.ignore_exif_profile_tag`, `file_handling.maximize_psd_compatibility`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `cursors.brush_preview_color`, `units_and_rulers.type_units`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `units_and_rulers.print_resolution`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.smart_quotes`, `type_.missing_glyph_protection`, `type_.show_font_names_in_english`, `type_.text_engine`, `type_.font_preview`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `enhanced_controls.zoom_with_trackpad_pinch`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`.
| Id | Target | Status | Issue | Note |
|---|---|---|---|---|