diff --git a/crates/engine-core/src/cmd/print_cmds.rs b/crates/engine-core/src/cmd/print_cmds.rs index 55e600c5a9..2ea6350824 100644 --- a/crates/engine-core/src/cmd/print_cmds.rs +++ b/crates/engine-core/src/cmd/print_cmds.rs @@ -1569,6 +1569,11 @@ fn package(s: &mut Session, p: &Value) -> Result { for (_, _, l) in doc.walk() { let LayerContent::Smart(so) = &l.content else { continue }; let SmartSource::Linked { path } = &so.source else { continue }; + // PSD stores embedded placed files as Linked sources keyed by their UUID. Their payload + // remains in the document's global blocks, so they are not filesystem links to collect. + if photocraft_io::linked::embedded_payload(&doc.metadata, path).is_some() { + continue; + } if missing.contains(path) { continue; } @@ -1849,3 +1854,7 @@ mod package_clash_name_tests; #[cfg(test)] #[path = "print_cmds/package_layer_rename_tests.rs"] mod package_layer_rename_tests; + +#[cfg(test)] +#[path = "print_cmds/package_psd_embedded_tests.rs"] +mod package_psd_embedded_tests; diff --git a/crates/engine-core/src/cmd/print_cmds/package_psd_embedded_tests.rs b/crates/engine-core/src/cmd/print_cmds/package_psd_embedded_tests.rs new file mode 100644 index 0000000000..58f499ac59 --- /dev/null +++ b/crates/engine-core/src/cmd/print_cmds/package_psd_embedded_tests.rs @@ -0,0 +1,60 @@ +//! PSD-embedded smart objects are represented as Linked UUID sources, but their bytes live in the +//! document's preserved `lnk2` blocks. Package must leave those sources in the document rather +//! than treating UUIDs as missing files. + +use super::*; +use photocraft_doc::{Affine, Layer, SmartObject, SmartSource}; +use std::sync::Arc; + +fn temp_dir() -> (tempfile::TempDir, String) { + let root = tempfile::Builder::new().prefix("photocraft-package-psd-").tempdir().unwrap(); + let path = root.path().to_string_lossy().replace('\\', "/"); + (root, path) +} + +#[test] +fn package_skips_psd_embedded_sources_but_collects_external_links() { + let (_root, dir) = temp_dir(); + let external = format!("{dir}/external.png"); + let mut source = crate::session(); + source.execute("file.new", json!({"width": 4, "height": 4, "background": "#336699"})).unwrap(); + crate::file_cmds::save_doc(&source.active().unwrap().doc, &external, None).unwrap(); + + let mut s = crate::session(); + s.execute("file.new", json!({"width": 40, "height": 30, "background": "#ffffff"})).unwrap(); + s.edit("PSD embedded and external links", |doc, active| { + let embedded = photocraft_io::linked::LinkedFile { uuid: "embedded-uuid".into(), file_name: "embedded.pcraft".into(), bytes: vec![1, 2, 3] }; + let block = photocraft_io::linked::encode_linked_file(&embedded); + doc.metadata.psd_global_blocks.push((*b"8BIM", *b"lnk2", Arc::new(block))); + let embedded_layer = Layer::new("Embedded", LayerContent::Smart(SmartObject::new(SmartSource::Linked { path: embedded.uuid }, Affine::IDENTITY, None))); + let external_layer = + Layer::new("External", LayerContent::Smart(SmartObject::new(SmartSource::Linked { path: external.clone() }, Affine::IDENTITY, None))); + let parent = active.unwrap(); + let embedded_id = doc.insert_above(Some(parent), embedded_layer); + doc.insert_above(Some(embedded_id), external_layer); + Ok(()) + }) + .unwrap(); + + let result = s.execute("file.package", json!({"dir": format!("{dir}/out")})).unwrap(); + assert_eq!(result["missing"], json!([])); + assert_eq!(result["links"].as_array().unwrap().len(), 1); + assert!(result["links"][0].as_str().unwrap().ends_with("Links/external.png")); + + let packaged_path = result["document"].as_str().unwrap(); + let packaged = photocraft_io::import("packaged.pcraft", &std::fs::read(packaged_path).unwrap()).unwrap().document; + let embedded_sources: Vec = packaged + .walk() + .iter() + .filter_map(|(_, _, layer)| match &layer.content { + LayerContent::Smart(smart) => match &smart.source { + SmartSource::Linked { path } if path == "embedded-uuid" => Some(path.clone()), + _ => None, + }, + _ => None, + }) + .collect(); + assert_eq!(embedded_sources, vec!["embedded-uuid"]); + let (_, payload) = photocraft_io::linked::embedded_payload(&packaged.metadata, "embedded-uuid").expect("the embedded payload survives packaging"); + assert_eq!(payload, [1, 2, 3]); +} diff --git a/crates/ui-egui/src/burn_refusal_alert_tests.rs b/crates/ui-egui/src/burn_refusal_alert_tests.rs new file mode 100644 index 0000000000..3cef9750bf --- /dev/null +++ b/crates/ui-egui/src/burn_refusal_alert_tests.rs @@ -0,0 +1,84 @@ +//! #12672: when the Burn tool can't work on the layer (a hidden target layer, Lock All, Lock Image +//! Pixels, a group's pixels), a press opens the reference application's alert with OK and changes +//! nothing; Lock position still burns. The Brush keeps its alerts, the other tools keep today's +//! behaviour. + +use serde_json::json; + +use super::brush_refusal_alert_tests::{active, alerts, app, refused, steps, stroke}; +use super::*; +use crate::control::{ControlRequest, Reply, handle}; + +#[test] +fn a_hidden_target_layer() { + let mut app = app(Tool::Burn); + let id = active(&app); + app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap(); + refused(&mut app, "Could not use the burn tool because the target layer is hidden."); + assert!(app.ui.status.is_empty() || !app.ui.status_error, "no status-bar error as well: {:?}", app.ui.status); +} + +#[test] +fn lock_all_and_lock_image_pixels() { + // Both are the one "the layer is locked." alert in the reference application. + for lock in ["all", "pixels"] { + let mut app = app(Tool::Burn); + app.run("layer.lockLayers", json!({ lock: true })).unwrap(); + refused(&mut app, "Could not use the burn tool because the layer is locked."); + } +} + +#[test] +fn a_group_is_active() { + let mut app = app(Tool::Burn); + app.run("layer.new.group", json!({})).unwrap(); + refused(&mut app, "Could not use the burn tool because the pixels in a group cannot be edited without merging the group."); +} + +#[test] +fn lock_position_still_burns() { + let mut app = app(Tool::Burn); + app.run("layer.lockLayers", json!({"position": true})).unwrap(); + let before = steps(&app); + stroke(&mut app); + assert!(alerts(&app).is_empty(), "Lock position is no refusal: {:?}", alerts(&app)); + assert_eq!(steps(&app), before + 1, "the stroke was applied"); +} + +#[test] +fn the_alert_is_listed_and_confirmed_over_the_control_channel() { + let ctx = egui::Context::default(); + let mut app = app(Tool::Burn); + app.run("layer.lockLayers", json!({"pixels": true})).unwrap(); + stroke(&mut app); + let mut call = |method: &str, params: serde_json::Value| { + let (req, _rx) = ControlRequest::new(method, params); + match handle(&mut app, &ctx, &req) { + Reply::Done(v) => v, + _ => panic!("{method}: expected an immediate reply"), + } + }; + let inspect = call("ui.inspect", json!({})); + let dialog = &inspect["result"]["dialogs"][0]; + assert_eq!(dialog["fields"]["message"], "Could not use the burn tool because the layer is locked.", "{inspect}"); + assert_eq!(call("ui.dialog.confirm", json!({"dialog": dialog["id"]}))["ok"], true); + assert!(alerts(&app).is_empty()); +} + +#[test] +fn the_brush_and_the_other_tools_keep_todays_behaviour() { + // The Brush: no alert for Lock Image Pixels. + let mut app = self::app(Tool::Brush); + app.run("layer.lockLayers", json!({"pixels": true})).unwrap(); + stroke(&mut app); + assert!(alerts(&app).is_empty()); + // The Dodge tool, the Burn tool's neighbour in the toolbar, has no layer alerts yet: the status + // bar says a hidden target. + let mut app = self::app(Tool::Dodge); + let id = active(&app); + app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap(); + stroke(&mut app); + assert!(alerts(&app).is_empty()); + assert_eq!(app.ui.status, photocraft_engine::hidden_target::HIDDEN); + assert_eq!(tool_name(&app, Tool::Dodge), None); +} diff --git a/crates/ui-egui/src/dialogs/assign_profile_layers_alert.rs b/crates/ui-egui/src/dialogs/assign_profile_layers_alert.rs index 6e16df36eb..79ff243332 100644 --- a/crates/ui-egui/src/dialogs/assign_profile_layers_alert.rs +++ b/crates/ui-egui/src/dialogs/assign_profile_layers_alert.rs @@ -1,9 +1,11 @@ //! Edit › Assign Profile on a document with layers first asks whether to go on (#14235): giving the document another -//! profile can change how its layers look. OK (the default) and Cancel, and a "Don't show again" box kept with the -//! other dialog preferences. OK opens the Assign Profile dialog; Cancel or Escape ends the command with nothing changed. -//! A document with only a Background layer never asks, nor does `edit.assignProfile` run with params (scripts, -//! actions, agents, the control channel), which the menu arm leaves to the command. +//! profile can change how its layers look. A warning icon beside the text (#16683), OK (the default) and Cancel, and a +//! "Don't show again" box kept with the other dialog preferences. OK opens the Assign Profile dialog; Cancel or Escape +//! ends the command with nothing changed. A document with only a Background layer never asks, nor does +//! `edit.assignProfile` run with params (scripts, actions, agents, the control channel), which the menu arm leaves to +//! the command. +use craft::behavior::IconId; use craft::ui::dialog::{DialogId, PromptAnswer, PromptChoice, StandardPrompt}; use super::alerts; @@ -30,6 +32,7 @@ pub fn asks(app: &PhotocraftApp) -> bool { pub fn open(app: &mut PhotocraftApp) -> DialogId { let prompt = StandardPrompt::custom(tl!(QUESTION).to_owned()) .title(tl!("Assign Profile").to_owned()) + .icon(IconId::new("warning")) .button(PromptChoice::Proceed, tl!("OK").to_owned()) .button(PromptChoice::Cancel, tl!("Cancel").to_owned()) .dont_show_again() diff --git a/crates/ui-egui/src/dialogs/assign_profile_layers_alert_tests.rs b/crates/ui-egui/src/dialogs/assign_profile_layers_alert_tests.rs index f1235e4e53..98e10359ec 100644 --- a/crates/ui-egui/src/dialogs/assign_profile_layers_alert_tests.rs +++ b/crates/ui-egui/src/dialogs/assign_profile_layers_alert_tests.rs @@ -1,9 +1,12 @@ //! #14235: Edit › Assign Profile on a document with layers asks first, with OK, Cancel and an unticked "Don't show //! again". OK opens the Assign Profile dialog, Cancel changes nothing; a flat document and a run with params never ask; -//! a ticked box with OK keeps the question away. +//! a ticked box with OK keeps the question away. #16683: the question shows a warning icon beside its text. use craft::ui::dialog::{DialogId, StackDialog as _, StandardPrompt}; use craft::ui::patterns::form_dialogs::HostedParamDialog; +use egui::accesskit::Role; +use egui_kittest::Harness; +use egui_kittest::kittest::Queryable; use serde_json::{Value, json}; use super::alerts; @@ -56,6 +59,24 @@ fn a_document_with_layers_asks_before_the_dialog() { assert_eq!(steps(&app), before); } +#[test] +fn the_question_shows_a_warning_icon_beside_its_text() { + let app = app(true); + let mut h = Harness::builder() + .with_size(egui::vec2(1200.0, 800.0)) + .with_max_steps(64) + .with_context(app.ctx().clone()) + .build_ui_state(|ui, app: &mut Box| crate::dialogs::run(app, ui), app); + PhotocraftApp::setup_context(&h.ctx, Default::default()); + menu(h.state_mut()); + h.run_steps(4); + let title = h.get_by_role_and_label(Role::Heading, "Assign Profile").rect(); + let message = h.get_by_label_contains("Assign a profile anyway?").rect(); + // The prompt draws the icon unnamed, so it shows in the layout: the title starts at the content's start, the + // message after the icon on its row. + assert!(message.left() > title.left() + 8.0, "the message starts after the icon: {message:?} vs title {title:?}"); +} + #[test] fn ok_opens_the_assign_profile_dialog() { let mut app = app(true); diff --git a/crates/ui-egui/src/dialogs/blend_options.rs b/crates/ui-egui/src/dialogs/blend_options.rs index 8a714d5457..23314de5d0 100644 --- a/crates/ui-egui/src/dialogs/blend_options.rs +++ b/crates/ui-egui/src/dialogs/blend_options.rs @@ -2,13 +2,16 @@ //! Layers panel's, so a mode has one key and one shortcut everywhere. Fill, Stroke and Fade grey the modes the active //! document's colour mode and depth can't use (#13806, #14647). -use craft::ui::patterns::form_dialogs::{DialogFields, Param, ParamKind}; +use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, Param, ParamKind, ParamResult}; use craft::ui::runtime::env::Label; +use craft::ui::runtime::memory::{SaveKey, saved_value, set_saved_value}; use photocraft_color::BlendMode; use serde_json::{Map, Value, json}; use crate::PhotocraftApp; +const PRESERVE: &str = "preserveTransparency"; + /// A blend-mode row `key` over the Layers panel's mode list (`group` adds Pass Through), opening on `current`. pub(crate) fn blend_param(key: &str, label: impl Into