mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Actions panel: Save Actions… suggests a Windows-safe name for device and control-character sets (CodeRabbit review on crates/ui-egui/src/panels/actions/tests.rs:883)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
7e00310493
commit
b67fb07557
4 files changed
+30
-7
No files matched your search
@@ -45,8 +45,11 @@ pub(crate) use open::{import, tag_exr_colorspace};
|
||||
use paths::is_file;
|
||||
#[cfg(test)]
|
||||
use paths::openable_name;
|
||||
pub use paths::{extension, holds, holds_at, is_template, layered_extension, list_images, losses_at, same_file, saves_in_place, template_name, untitled_name};
|
||||
pub(crate) use paths::{file_name, forward_slashes, is_windows_device_name, join, portable_device_name, read_file, sanitize, stem, write_file};
|
||||
pub use paths::{
|
||||
extension, holds, holds_at, is_template, layered_extension, list_images, losses_at, portable_device_name, same_file, saves_in_place, template_name,
|
||||
untitled_name,
|
||||
};
|
||||
pub(crate) use paths::{file_name, forward_slashes, is_windows_device_name, join, read_file, sanitize, stem, write_file};
|
||||
use processing::{conditional_mode_change, fit_image, flatten_all_effects, flatten_all_masks, image_processor, load_files_into_stack};
|
||||
use save::save_a_copy;
|
||||
pub(crate) use save::{SaveOpts, encode, save_doc};
|
||||
|
||||
@@ -212,7 +212,7 @@ pub(crate) fn sanitize(name: &str) -> String {
|
||||
|
||||
/// `name` with a `_` before its first dot when it is a Windows device name (`nul` → `nul_`,
|
||||
/// `com1.v2` → `com1_.v2`); a `_` at the end would leave the device stem in place.
|
||||
pub(crate) fn portable_device_name(name: String) -> String {
|
||||
pub fn portable_device_name(name: String) -> String {
|
||||
if !is_windows_device_name(&name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -446,15 +446,15 @@ fn save_dialog(app: &mut PhotocraftApp, set: Option<String>) -> Result<Value, St
|
||||
let bytes = r["data"].as_str().and_then(photocraft_engine::paint::tile::b64_decode).ok_or("the export returned no data")?;
|
||||
let n = r["actions"].as_array().map_or(0, Vec::len) as u64;
|
||||
let skipped = r["skipped"].as_array().map_or(0, Vec::len);
|
||||
// A set name can hold characters a file name can't (as in Keyboard Shortcuts' Save); the
|
||||
// file keeps the set's own name.
|
||||
// A set name can hold characters a file name can't (as in Keyboard Shortcuts' Save), or be a
|
||||
// Windows device name (`CON`); the file keeps the set's own name.
|
||||
let stem: String = r["set"]
|
||||
.as_str()
|
||||
.unwrap_or("Actions")
|
||||
.chars()
|
||||
.map(|c| if matches!(c, '/' | '\\' | ':' | '*' | '?' | '"' | '<' | '>' | '|') { '_' } else { c })
|
||||
.map(|c| if c.is_control() || matches!(c, '/' | '\\' | ':' | '*' | '?' | '"' | '<' | '>' | '|') { '_' } else { c })
|
||||
.collect();
|
||||
let file = format!("{stem}.atn");
|
||||
let file = format!("{}.atn", photocraft_engine::file_cmds::portable_device_name(stem));
|
||||
app.pick_save(&file, move |app, path| {
|
||||
let write = app.services.write.as_mut().ok_or("no writer configured")?;
|
||||
write(&path, &bytes)?;
|
||||
|
||||
@@ -951,6 +951,26 @@ fn save_set_on_an_empty_set_folder_opens_the_save_dialog() {
|
||||
);
|
||||
}
|
||||
|
||||
/// CodeRabbit review on #10459: a set named after a Windows device (`CON`, `com1.v2`) or holding a
|
||||
/// control character gets a suggested file name Windows can create.
|
||||
#[test]
|
||||
fn save_actions_suggests_a_windows_safe_name_for_device_and_control_character_sets() {
|
||||
use egui_kittest::kittest::Queryable;
|
||||
for (set, suggested) in [("CON", "CON_.atn"), ("com1.v2", "com1_.v2.atn"), ("Web\u{1}Print\tMail", "Web_Print_Mail.atn"), ("Print", "Print.atn")] {
|
||||
let (mut h, asked) = empty_set_save_harness(set);
|
||||
h.get_by_label(set).click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Save Actions…").click();
|
||||
h.run_steps(2);
|
||||
h.state_mut().poll_file_dialog(&egui::Context::default(), None);
|
||||
assert!(
|
||||
matches!(asked.borrow().as_slice(), [crate::file_dialog::FileDialogRequest::Save { suggested: s }] if s == suggested),
|
||||
"{set:?}: {:?}",
|
||||
asked.borrow()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moving_an_action_next_to_another_set_joins_it() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
|
||||
Reference in new issue
Block a user