mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
actions: add editable PhotoCraft Essentials presets
Seed starter actions once, preserve custom libraries, and expose a restore command in the Actions panel and automation APIs. Generated with Codex.
This commit is contained in:
1 parent
6f85054288
commit
5d8980222a
29 files changed
+363
-11
No files matched your search
@@ -0,0 +1,225 @@
|
||||
//! Independently authored starter actions, composed from PhotoCraft commands. The preset
|
||||
//! store seeds these once; an explicit command restores missing names without replacing edits.
|
||||
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::actions_cmds::{Action, ActionState};
|
||||
use crate::commands::CommandSpec;
|
||||
use crate::{EngineError, Result, Session};
|
||||
|
||||
pub(crate) const VERSION: u32 = 1;
|
||||
const SET: &str = "PhotoCraft Essentials";
|
||||
|
||||
fn defaults() -> Vec<Action> {
|
||||
[
|
||||
("Auto Tone", "image.autoTone", json!({})),
|
||||
("Auto Contrast", "image.autoContrast", json!({})),
|
||||
("Auto Color", "image.autoColor", json!({})),
|
||||
("Select Subject", "select.subject", json!({"sampleAllLayers": true, "mode": "replace"})),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, id, params)| Action { set: Some(SET.into()), ..Action::new(name, vec![(id.into(), params)]) })
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Preserve custom actions, including a user's edited default with the same name.
|
||||
pub(crate) fn append_missing(state: &mut ActionState) -> Vec<String> {
|
||||
let mut added = Vec::new();
|
||||
for action in defaults() {
|
||||
if !state.list.iter().any(|have| have.name == action.name) {
|
||||
added.push(action.name.clone());
|
||||
state.list.push(action);
|
||||
}
|
||||
}
|
||||
if !added.is_empty() {
|
||||
state.touch();
|
||||
}
|
||||
added
|
||||
}
|
||||
|
||||
fn enabled(s: &Session) -> std::result::Result<(), String> {
|
||||
if s.actions.recording.is_some() || s.actions.playing > 0 {
|
||||
return Err("Stop recording or playing an action before loading defaults".into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn load(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let bad = |msg: String| EngineError::BadParams { cmd: "actions.loadDefaults".into(), msg };
|
||||
enabled(s).map_err(bad)?;
|
||||
if !p.is_object() {
|
||||
return Err(bad("parameters must be an object".into()));
|
||||
}
|
||||
Ok(json!({"added": append_missing(&mut s.actions), "set": SET}))
|
||||
}
|
||||
|
||||
pub fn specs() -> Vec<CommandSpec> {
|
||||
vec![CommandSpec {
|
||||
id: "actions.loadDefaults",
|
||||
label: "Load Default Actions",
|
||||
menu: &[],
|
||||
shortcut: None,
|
||||
params: "{} → {added:[name…], set}. Append missing PhotoCraft Essentials actions; existing names and edits are preserved. No document needed. Unavailable during recording or playback.",
|
||||
enabled,
|
||||
run: load,
|
||||
journal: false,
|
||||
}]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::actions_cmds::ActionsFile;
|
||||
use crate::preset_store::{ACTIONS_FILE, MemBackend, PresetBackend, open};
|
||||
use photocraft_geom::Rect;
|
||||
|
||||
fn attached(mem: &MemBackend) -> Session {
|
||||
let mut s = Session::new();
|
||||
assert!(s.attach_preset_store(open(Box::new(mem.clone()))).is_empty());
|
||||
s
|
||||
}
|
||||
|
||||
fn saved(mem: &MemBackend) -> ActionsFile {
|
||||
serde_json::from_slice(&mem.read(ACTIONS_FILE, 1 << 20).unwrap()).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_defaults_preserves_names_and_edits_and_is_idempotent() {
|
||||
let mut s = Session::new();
|
||||
assert!(s.actions.list.is_empty(), "headless sessions remain hermetic");
|
||||
let custom = Action::new("Auto Tone", vec![("image.flipCanvasHorizontal".into(), json!({}))]);
|
||||
s.actions.list.push(custom.clone());
|
||||
let loaded = s.execute("actions.loadDefaults", json!({})).unwrap();
|
||||
assert_eq!(loaded["added"], json!(["Auto Contrast", "Auto Color", "Select Subject"]));
|
||||
assert_eq!(s.actions.list[0], custom);
|
||||
assert!(s.actions.list.iter().skip(1).all(|a| a.set.as_deref() == Some(SET)));
|
||||
let rev = s.actions.rev;
|
||||
assert_eq!(s.execute("actions.loadDefaults", json!({})).unwrap()["added"], json!([]));
|
||||
assert_eq!(s.actions.rev, rev, "unchanged defaults do not cause a store write");
|
||||
assert!(s.journal.is_empty());
|
||||
assert!(s.active().is_none());
|
||||
|
||||
for bad in [Value::Null, json!([]), json!("defaults"), json!(true), json!(1)] {
|
||||
assert!(s.execute("actions.loadDefaults", bad).is_err());
|
||||
}
|
||||
s.execute("actions.record", json!({"name": "Recording"})).unwrap();
|
||||
assert!(!s.is_enabled("actions.loadDefaults"));
|
||||
assert!(s.execute("actions.loadDefaults", json!({})).is_err());
|
||||
s.execute("actions.stop", json!({})).unwrap();
|
||||
s.actions.playing = 1;
|
||||
assert!(load(&mut s, &json!({})).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn defaults_seed_once_and_restore_only_when_requested() {
|
||||
let mem = MemBackend::default();
|
||||
let mut s = attached(&mem);
|
||||
assert_eq!(s.actions.list, defaults());
|
||||
assert_eq!(saved(&mem).defaults_version, VERSION);
|
||||
s.execute("actions.delete", json!({"action": "Auto Tone"})).unwrap();
|
||||
s.execute("actions.rename", json!({"action": "Auto Color", "name": "My Color"})).unwrap();
|
||||
let customized = s.actions.list.clone();
|
||||
let mut restarted = attached(&mem);
|
||||
assert_eq!(restarted.actions.list, customized, "deleted and renamed defaults stay customized on restart");
|
||||
assert_eq!(restarted.execute("actions.loadDefaults", json!({})).unwrap()["added"], json!(["Auto Tone", "Auto Color"]));
|
||||
assert_eq!(attached(&mem).actions.list, restarted.actions.list);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn old_store_and_early_actions_win_over_defaults() {
|
||||
let mem = MemBackend::default();
|
||||
let custom = Action::new("Auto Tone", vec![("select.all".into(), json!({}))]);
|
||||
let disk = Action::new("My Workflow", vec![]);
|
||||
// Old files have no defaults_version field.
|
||||
mem.write(ACTIONS_FILE, &serde_json::to_vec(&json!({"version": 1, "actions": [custom, disk]})).unwrap()).unwrap();
|
||||
let mut s = Session::new();
|
||||
let early = Action::new("Auto Color", vec![("select.deselect".into(), json!({}))]);
|
||||
s.actions.list.push(early.clone());
|
||||
s.attach_preset_store(open(Box::new(mem.clone())));
|
||||
assert_eq!(&s.actions.list[..3], &[early, custom, disk]);
|
||||
assert_eq!(
|
||||
s.actions.list.iter().map(|a| a.name.as_str()).collect::<Vec<_>>(),
|
||||
["Auto Color", "Auto Tone", "My Workflow", "Auto Contrast", "Select Subject"]
|
||||
);
|
||||
assert_eq!(saved(&mem).defaults_version, VERSION);
|
||||
assert_eq!(attached(&mem).actions.list, s.actions.list);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unreadable_actions_are_not_seeded_or_overwritten() {
|
||||
for bytes in [b"{".as_slice(), br#"{"version":999,"actions":[]}"#.as_slice()] {
|
||||
let mem = MemBackend::default();
|
||||
mem.write(ACTIONS_FILE, bytes).unwrap();
|
||||
let mut s = Session::new();
|
||||
assert!(!s.attach_preset_store(open(Box::new(mem.clone()))).is_empty());
|
||||
assert!(s.actions.list.is_empty());
|
||||
s.execute("actions.loadDefaults", json!({})).unwrap();
|
||||
assert_eq!(s.actions.list, defaults(), "explicit recovery is available in memory");
|
||||
assert_eq!(mem.read(ACTIONS_FILE, 1 << 20).unwrap(), bytes, "the unreadable original remains recoverable");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auto_defaults_play_on_pixels_and_undo_at_every_depth() {
|
||||
for depth in [8, 16, 32] {
|
||||
let mut s = Session::new();
|
||||
s.execute("actions.loadDefaults", json!({})).unwrap();
|
||||
s.execute("file.new", json!({"width": 64, "height": 64, "depth": depth})).unwrap();
|
||||
s.edit("ramp", |doc, _| {
|
||||
let surf = doc.layers[0].surface_mut().unwrap();
|
||||
for x in 0..64 {
|
||||
let v = 0.3 + 0.4 * x as f32 / 63.0;
|
||||
surf.fill_rect(Rect::new(x, 0, x + 1, 64), &[v, v * 0.9, v * 0.8, 1.0]);
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let pixel = |s: &Session, x| s.active().unwrap().doc.layers[0].surface().unwrap().pixel(x, 0);
|
||||
let before = (pixel(&s, 0), pixel(&s, 63));
|
||||
let history = s.active().unwrap().history.past_len();
|
||||
for name in ["Auto Tone", "Auto Contrast", "Auto Color"] {
|
||||
let played = s.execute("actions.play", json!({"action": name})).unwrap();
|
||||
assert_eq!(played["ran"], 1, "{name} at {depth}: {played}");
|
||||
assert!(played.get("failed").is_none());
|
||||
let (a, b) = (pixel(&s, 0), pixel(&s, 63));
|
||||
let (lo, hi) = if name == "Auto Contrast" { (a[2], b[0]) } else { (a[0], b[0]) };
|
||||
assert!(lo < 0.05 && hi > 0.95, "{name} at {depth}: {a:?} {b:?}");
|
||||
assert_eq!(s.active().unwrap().history.past_len(), history + 1);
|
||||
assert!(s.undo());
|
||||
assert_eq!((pixel(&s, 0), pixel(&s, 63)), before);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subject_default_samples_visible_layers_and_undo_restores_selection() {
|
||||
for depth in [8, 16, 32] {
|
||||
let mut s = Session::new();
|
||||
s.execute("actions.loadDefaults", json!({})).unwrap();
|
||||
s.execute("file.new", json!({"width": 200, "height": 160, "depth": depth})).unwrap();
|
||||
s.edit("disc", |doc, _| {
|
||||
let surf = doc.layers[0].surface_mut().unwrap();
|
||||
surf.fill_rect(Rect::new(0, 0, 200, 160), &[0.25, 0.45, 0.7, 1.0]);
|
||||
for y in 0..160 {
|
||||
for x in 0..200 {
|
||||
if (x - 100) * (x - 100) + (y - 80) * (y - 80) <= 45 * 45 {
|
||||
surf.fill_rect(Rect::new(x, y, x + 1, y + 1), &[0.9, 0.3, 0.15, 1.0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
s.execute("layer.new.layer", json!({"name": "Empty active layer"})).unwrap();
|
||||
s.execute("select.all", json!({})).unwrap();
|
||||
let played = s.execute("actions.play", json!({"action": "Select Subject"})).unwrap();
|
||||
assert_eq!(played["ran"], 1, "{depth}: {played}");
|
||||
assert!(played.get("failed").is_none());
|
||||
let coverage = |s: &Session, x, y| s.active().unwrap().doc.selection.as_ref().unwrap().sample_channel(x, y, 0);
|
||||
assert!(coverage(&s, 100, 80) > 0.9, "the subject on the underlying layer is selected");
|
||||
assert!(coverage(&s, 0, 0) < 0.1, "replace mode removes the old background selection");
|
||||
assert!(s.undo());
|
||||
assert!(coverage(&s, 0, 0) > 0.9);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,9 @@ impl Action {
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ActionsFile {
|
||||
pub version: u32,
|
||||
/// Starter set last seeded. Older stores default to zero; deletions after seeding persist.
|
||||
#[serde(default)]
|
||||
pub defaults_version: u32,
|
||||
pub actions: Vec<Action>,
|
||||
}
|
||||
|
||||
@@ -1248,8 +1251,8 @@ mod tests {
|
||||
let mut t = Session::new();
|
||||
t.attach_preset_store(crate::preset_store::open_dir(&dir));
|
||||
let listed = t.execute("actions.list", json!({})).unwrap();
|
||||
assert_eq!(listed["actions"][0]["name"], "Kept");
|
||||
assert_eq!(listed["actions"][0]["steps"], 1);
|
||||
let kept = listed["actions"].as_array().unwrap().iter().find(|a| a["name"] == "Kept").unwrap();
|
||||
assert_eq!(kept["steps"], 1);
|
||||
assert_eq!(t.execute("actions.get", json!({"action": "Kept"})).unwrap()["steps"][0][0], "layer.new.layer");
|
||||
|
||||
// An action created before the store finishes loading is kept, and a different one on
|
||||
|
||||
@@ -1326,6 +1326,7 @@ fn build() -> Vec<CommandSpec> {
|
||||
v.extend(crate::mask_view_cmds::specs());
|
||||
v.extend(crate::layer_mask_props_cmds::specs());
|
||||
v.extend(crate::actions_cmds::specs());
|
||||
v.extend(crate::action_defaults::specs());
|
||||
// The dispatch guard's unit test needs a command that panics on purpose (REL-3).
|
||||
#[cfg(test)]
|
||||
v.push(test_panic_command());
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#![forbid(unsafe_code)]
|
||||
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
|
||||
|
||||
pub mod action_defaults;
|
||||
pub mod actions_cmds;
|
||||
pub mod actions_edit_cmds;
|
||||
pub mod adjust_cmds;
|
||||
|
||||
@@ -548,6 +548,8 @@ pub struct PresetStore {
|
||||
index: Option<IndexFile>,
|
||||
/// [`crate::actions_cmds::ActionState::rev`] last written (or loaded).
|
||||
actions_rev: u64,
|
||||
/// Starter set last offered to this store, independent of later user deletions or renames.
|
||||
actions_defaults_version: u32,
|
||||
/// `actions.json` exists but failed to load: left on disk untouched, so it is never written.
|
||||
actions_skipped: bool,
|
||||
warnings: Vec<String>,
|
||||
@@ -643,7 +645,7 @@ pub fn open(backend: Box<dyn PresetBackend>) -> Opened {
|
||||
|
||||
let loaded_actions = load_actions(backend.as_ref(), &mut warnings);
|
||||
let actions_skipped = loaded_actions.is_none();
|
||||
let actions = loaded_actions.unwrap_or_default();
|
||||
let (actions, actions_defaults_version) = loaded_actions.map(|f| (f.actions, f.defaults_version)).unwrap_or_default();
|
||||
let mut store = PresetStore {
|
||||
backend,
|
||||
synced_rev: None,
|
||||
@@ -652,6 +654,7 @@ pub fn open(backend: Box<dyn PresetBackend>) -> Opened {
|
||||
tips: HashMap::new(),
|
||||
index: None,
|
||||
actions_rev: 0,
|
||||
actions_defaults_version,
|
||||
actions_skipped,
|
||||
warnings: Vec::new(),
|
||||
cache: Mutex::new(TipCache { limit: TIP_CACHE_BYTES, ..Default::default() }),
|
||||
@@ -715,17 +718,17 @@ pub fn open(backend: Box<dyn PresetBackend>) -> Opened {
|
||||
|
||||
/// `actions.json`: a missing file is an empty list. Anything else unreadable is a warning.
|
||||
/// The saved actions; `None` when `actions.json` exists but could not be loaded.
|
||||
fn load_actions(backend: &dyn PresetBackend, warnings: &mut Vec<String>) -> Option<Vec<crate::actions_cmds::Action>> {
|
||||
fn load_actions(backend: &dyn PresetBackend, warnings: &mut Vec<String>) -> Option<crate::actions_cmds::ActionsFile> {
|
||||
let bytes = match backend.read(ACTIONS_FILE, MAX_ACTIONS_BYTES) {
|
||||
Ok(b) => b,
|
||||
Err(e) if missing_file(&e) => return Some(Vec::new()),
|
||||
Err(e) if missing_file(&e) => return Some(crate::actions_cmds::ActionsFile { version: 1, defaults_version: 0, actions: Vec::new() }),
|
||||
Err(e) => {
|
||||
warnings.push(format!("actions: {ACTIONS_FILE} skipped: {e}"));
|
||||
return None;
|
||||
}
|
||||
};
|
||||
match serde_json::from_slice::<crate::actions_cmds::ActionsFile>(&bytes) {
|
||||
Ok(file) if file.version == 1 => Some(file.actions),
|
||||
Ok(file) if file.version == 1 => Some(file),
|
||||
Ok(file) => {
|
||||
warnings.push(format!("actions: {ACTIONS_FILE} skipped: unsupported version {}", file.version));
|
||||
None
|
||||
@@ -1054,7 +1057,7 @@ impl PresetStore {
|
||||
self.actions_rev = rev;
|
||||
return;
|
||||
}
|
||||
let file = crate::actions_cmds::ActionsFile { version: 1, actions: list.to_vec() };
|
||||
let file = crate::actions_cmds::ActionsFile { version: 1, defaults_version: self.actions_defaults_version, actions: list.to_vec() };
|
||||
let bytes = match serde_json::to_vec_pretty(&file) {
|
||||
Ok(b) => b,
|
||||
Err(e) => {
|
||||
@@ -1108,7 +1111,8 @@ impl Session {
|
||||
}
|
||||
self.preset_store = Some(store);
|
||||
// In-memory actions (created before the store finished loading) win on name. Disk-only
|
||||
// names are appended. An empty session takes the disk list and does not rewrite it.
|
||||
// names are appended. An empty session takes the disk list without rewriting it,
|
||||
// except when the one-time starter set migration below is needed.
|
||||
if self.actions.list.is_empty() {
|
||||
self.actions.list = disk;
|
||||
self.actions.rev = 1;
|
||||
@@ -1123,6 +1127,16 @@ impl Session {
|
||||
}
|
||||
self.actions.rev = self.actions.rev.saturating_add(1).max(1);
|
||||
}
|
||||
if let Some(st) = self.preset_store.as_mut()
|
||||
&& !st.actions_skipped
|
||||
&& st.actions_defaults_version < crate::action_defaults::VERSION
|
||||
{
|
||||
// Merge after disk and early in-memory actions so neither is overwritten. Persist
|
||||
// the marker even when all names collide, so a later deletion stays deleted.
|
||||
crate::action_defaults::append_missing(&mut self.actions);
|
||||
st.actions_defaults_version = crate::action_defaults::VERSION;
|
||||
self.actions.touch();
|
||||
}
|
||||
self.brush_presets_changed();
|
||||
self.sync_preset_store();
|
||||
if let Some(st) = self.preset_store.as_mut() {
|
||||
|
||||
@@ -112,7 +112,7 @@ fn group_with_sampled_8_and_16_bit_tips_round_trips() {
|
||||
let dir = TempDir::new("roundtrip");
|
||||
let (mut s, w) = session(&dir);
|
||||
assert!(w.is_empty(), "{w:?}");
|
||||
assert!(dir.files().is_empty(), "attaching an empty store writes nothing");
|
||||
assert_eq!(dir.files(), [ACTIONS_FILE], "only starter actions are written when attaching an empty store");
|
||||
let mut a = sampled("Eight", "Inks", tip8(64, 48, 1));
|
||||
a.brush.dual_brush.tip = TipShape::Sampled(tip8(12, 12, 5));
|
||||
a.brush.texture.pattern = Pattern::Tile(tip16(32, 32, 7));
|
||||
@@ -163,7 +163,7 @@ fn commands_persist_and_delete_removes_from_disk() {
|
||||
assert!(photocraft_paint::presets::find(&t.tools.presets, "Doodle").is_some());
|
||||
assert!(photocraft_paint::presets::find(&t.tools.presets, "Scribble").is_none());
|
||||
s.execute("brush.presets.delete", json!({"name": "Doodle"})).unwrap();
|
||||
assert_eq!(dir.files(), [INDEX_FILE], "the group file and its tip are gone");
|
||||
assert_eq!(dir.files(), [ACTIONS_FILE, INDEX_FILE], "the group file and its tip are gone");
|
||||
let (t, _) = session(&dir);
|
||||
assert!(photocraft_paint::presets::find(&t.tools.presets, "Doodle").is_none());
|
||||
}
|
||||
|
||||
@@ -436,6 +436,9 @@ pub fn stopped(app: &mut PhotocraftApp, fields: &serde_json::Map<String, Value>)
|
||||
/// The Actions entries of the panel group's menu ("…").
|
||||
pub fn panel_menu(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let mut act: Option<&str> = None;
|
||||
if ui.add_enabled(app.session.is_enabled("actions.loadDefaults"), egui::Button::new(tl!("Load Default Actions"))).clicked() {
|
||||
act = Some("defaults");
|
||||
}
|
||||
if ui.button(tl!("Load Actions…")).clicked() {
|
||||
act = Some("load");
|
||||
}
|
||||
@@ -451,6 +454,7 @@ pub fn panel_menu(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let Some(a) = act else { return };
|
||||
ui.close();
|
||||
let r = match a {
|
||||
"defaults" => load_defaults(app),
|
||||
"load" => load_dialog(app),
|
||||
"stop" => insert_stop_dialog(app),
|
||||
_ => save_dialog(app, None),
|
||||
@@ -463,6 +467,21 @@ pub fn panel_menu(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
}
|
||||
}
|
||||
|
||||
fn load_defaults(app: &mut PhotocraftApp) -> Result<Value, String> {
|
||||
let result = app.run("actions.loadDefaults", json!({}))?;
|
||||
if let Some(name) = result["added"].as_array().and_then(|names| names.first()).and_then(Value::as_str)
|
||||
&& let Some(index) = app.session.actions.list.iter().position(|action| action.name == name)
|
||||
{
|
||||
app.ui.actions.selected = Some(index);
|
||||
app.ui.actions.selected_step = None;
|
||||
app.ui.actions.renaming = None;
|
||||
if let Some(set) = result["set"].as_str() {
|
||||
app.ui.actions.collapsed_sets.retain(|collapsed| collapsed != set);
|
||||
}
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct DragRow {
|
||||
action: usize,
|
||||
@@ -642,6 +661,12 @@ pub fn panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
}
|
||||
egui::ScrollArea::vertical().id_salt("actions-rows").max_height(max_h).min_scrolled_height(max_h).auto_shrink([false, false]).show(ui, |ui| {
|
||||
if rows.is_empty() {
|
||||
if ui.button(tl!("Load Default Actions")).clicked()
|
||||
&& let Err(error) = load_defaults(app)
|
||||
{
|
||||
app.ui.status = error;
|
||||
app.ui.status_error = true;
|
||||
}
|
||||
ui.label(egui::RichText::new(tl!("Record ● a sequence of edits, then play ▶ it on any document.")).color(t.text_faint).size(11.5));
|
||||
}
|
||||
if egui::DragAndDrop::has_payload_of_type::<DragRow>(ui.ctx()) {
|
||||
@@ -911,6 +936,53 @@ pub fn panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn default_actions_load_from_empty_panel_and_play() {
|
||||
use egui_kittest::{Harness, kittest::Queryable};
|
||||
let app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
let mut h = Harness::builder().with_size(vec2(360.0, 400.0)).build_ui_state(|ui, app| panel(app, ui), app);
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Load Default Actions").click();
|
||||
h.run_steps(3);
|
||||
assert!(h.query_by_label("PhotoCraft Essentials").is_some());
|
||||
for name in ["Auto Tone", "Auto Contrast", "Auto Color", "Select Subject"] {
|
||||
assert!(h.query_by_label(name).is_some(), "missing preset {name}");
|
||||
}
|
||||
assert_eq!(h.state().ui.actions.selected, Some(0));
|
||||
h.state_mut().run("file.new", json!({"width": 16, "height": 16})).unwrap();
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Play selection").click();
|
||||
h.run_steps(3);
|
||||
assert!(!h.state().ui.status_error, "{}", h.state().ui.status);
|
||||
assert!(h.state().session.journal.iter().any(|(id, _)| id == "image.autoTone"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_actions_flyout_preserves_custom_actions_and_reveals_restored_set() {
|
||||
use egui_kittest::{Harness, kittest::Queryable};
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
let custom = Action::new("Auto Tone", vec![("view.fitOnScreen".into(), json!({}))]);
|
||||
app.session.actions.list.push(custom.clone());
|
||||
app.ui.actions.collapsed_sets.push("PhotoCraft Essentials".into());
|
||||
let mut h = Harness::builder().with_size(vec2(360.0, 400.0)).build_ui_state(
|
||||
|ui, app| {
|
||||
ui.menu_button("Actions menu", |ui| panel_menu(app, ui));
|
||||
panel(app, ui);
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Actions menu").click();
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Load Default Actions").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().session.actions.list[0], custom);
|
||||
assert_eq!(h.state().session.actions.list.len(), 4);
|
||||
assert_eq!(h.state().ui.actions.selected, Some(1));
|
||||
assert!(h.state().ui.actions.collapsed_sets.is_empty());
|
||||
assert!(h.query_by_label("Select Subject").is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn actions_list_grows_with_panel_and_keeps_footer_visible() {
|
||||
use egui_kittest::{Harness, kittest::Queryable};
|
||||
|
||||
@@ -3734,3 +3734,4 @@ navigator Zoom Zvětšení
|
||||
@plural {n} action|{n} actions {n} akce|{n} akce|{n} akcí
|
||||
Auto Add/Delete Automaticky přidat/odstranit
|
||||
ICO is limited to 256 × 256 pixels ICO je omezen na 256 × 256 pixelů
|
||||
Load Default Actions Načíst výchozí akce
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -2768,3 +2768,4 @@ curves Smooth Glätten
|
||||
@plural {n} action|{n} actions {n} Aktion|{n} Aktionen
|
||||
Auto Add/Delete Autom. hinzuf./löschen
|
||||
ICO is limited to 256 × 256 pixels ICO ist auf 256 × 256 Pixel begrenzt
|
||||
Load Default Actions Standardaktionen laden
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -3823,3 +3823,4 @@ curves Smooth Εξομάλυνση
|
||||
@plural {n} action|{n} actions {n} ενέργεια|{n} ενέργειες
|
||||
Auto Add/Delete Αυτόματη προσθήκη/διαγραφή
|
||||
ICO is limited to 256 × 256 pixels Το ICO περιορίζεται σε 256 × 256 εικονοστοιχεία
|
||||
Load Default Actions Φόρτωση προεπιλεγμένων ενεργειών
|
||||
|
Can't render this file because it contains an unexpected character in line 1029 and column 18.
|
@@ -2809,3 +2809,4 @@ curves Smooth Suavizar
|
||||
@plural {n} action|{n} actions {n} acción|{n} acciones
|
||||
Auto Add/Delete Añadir/eliminar automáticamente
|
||||
ICO is limited to 256 × 256 pixels ICO está limitado a 256 × 256 píxeles
|
||||
Load Default Actions Cargar acciones predeterminadas
|
||||
|
Can't render this file because it contains an unexpected character in line 4 and column 47.
|
@@ -3127,3 +3127,4 @@ curves Smooth Lisser
|
||||
@plural {n} action|{n} actions {n} action|{n} actions
|
||||
Auto Add/Delete Ajout/suppr. auto
|
||||
ICO is limited to 256 × 256 pixels Le format ICO est limité à 256 × 256 pixels
|
||||
Load Default Actions Charger les actions par défaut
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -4047,3 +4047,4 @@ cameraRaw Yellow Sárga
|
||||
Color Indicates: A szín jelzése:
|
||||
Ink Characteristics Festék jellemzői
|
||||
Solidity: Fedőképesség:
|
||||
Load Default Actions Alapértelmezett műveletek betöltése
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -3114,3 +3114,4 @@ curves Smooth Haluskan
|
||||
@plural {n} action|{n} actions {n} tindakan
|
||||
Auto Add/Delete Tambah/Hapus Otomatis
|
||||
ICO is limited to 256 × 256 pixels ICO dibatasi hingga 256 × 256 piksel
|
||||
Load Default Actions Muat Aksi Default
|
||||
|
Can't render this file because it contains an unexpected character in line 4 and column 47.
|
@@ -4090,3 +4090,4 @@ navigator Zoom Zoom
|
||||
@plural {n} action|{n} actions {n} azione|{n} azioni
|
||||
Auto Add/Delete Aggiungi/elimina automaticamente
|
||||
ICO is limited to 256 × 256 pixels ICO è limitato a 256 × 256 pixel
|
||||
Load Default Actions Carica azioni predefinite
|
||||
|
Can't render this file because it contains an unexpected character in line 2637 and column 53.
|
@@ -3803,3 +3803,4 @@ curves Smooth スムーズ
|
||||
Reset All Locked Settings ロックされた設定をすべて初期化
|
||||
Copy Texture to Other Tools テクスチャを他のツールにコピー
|
||||
ICO is limited to 256 × 256 pixels ICO は 256 × 256 ピクセルまでです
|
||||
Load Default Actions 既定のアクションを読み込み
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -3299,3 +3299,4 @@ curves Smooth 매끄럽게
|
||||
@plural {n} action|{n} actions 액션 {n}개
|
||||
Auto Add/Delete 자동 추가/삭제
|
||||
ICO is limited to 256 × 256 pixels ICO는 256 × 256픽셀로 제한됩니다
|
||||
Load Default Actions 기본 액션 불러오기
|
||||
|
Can't render this file because it contains an unexpected character in line 3150 and column 53.
|
@@ -3885,3 +3885,4 @@ curves Smooth Vloeiend maken
|
||||
@plural {n} action|{n} actions {n} handeling|{n} handelingen
|
||||
Auto Add/Delete Automatisch toevoegen/verwijderen
|
||||
ICO is limited to 256 × 256 pixels ICO is beperkt tot 256 × 256 pixels
|
||||
Load Default Actions Standaardacties laden
|
||||
|
Can't render this file because it contains an unexpected character in line 8 and column 34.
|
@@ -3723,3 +3723,4 @@ curves Smooth Wygładź
|
||||
@plural {n} action|{n} actions {n} operacja|{n} operacje|{n} operacji
|
||||
Auto Add/Delete Automatyczne dodawanie/usuwanie
|
||||
ICO is limited to 256 × 256 pixels ICO jest ograniczony do 256 × 256 pikseli
|
||||
Load Default Actions Wczytaj domyślne operacje
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -3915,3 +3915,4 @@ layerLabel No Color Sem cor
|
||||
@plural {n} action|{n} actions {n} ação|{n} ações
|
||||
Auto Add/Delete Adicionar/excluir automaticamente
|
||||
ICO is limited to 256 × 256 pixels ICO é limitado a 256 × 256 pixels
|
||||
Load Default Actions Carregar ações padrão
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -3071,3 +3071,4 @@ curves Smooth Сгладить
|
||||
@plural {n} action|{n} actions {n} операция|{n} операции|{n} операций
|
||||
Auto Add/Delete Автодобавление/удаление
|
||||
ICO is limited to 256 × 256 pixels ICO ограничен размером 256 × 256 пикселей
|
||||
Load Default Actions Загрузить действия по умолчанию
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -4201,3 +4201,4 @@ shape Appearance Izgled
|
||||
Color Indicates: Boja označava:
|
||||
Ink Characteristics Karakteristike mastila
|
||||
Solidity: Punoća:
|
||||
Load Default Actions Učitaj podrazumevane radnje
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -3858,3 +3858,4 @@ cameraData Lens Lens
|
||||
Color Indicates: Rengin Gösterdiği:
|
||||
Ink Characteristics Mürekkep Özellikleri
|
||||
Solidity: Doluluk:
|
||||
Load Default Actions Varsayılan Eylemleri Yükle
|
||||
|
Can't render this file because it contains an unexpected character in line 8 and column 34.
|
@@ -3824,3 +3824,4 @@ curves Smooth Згладити
|
||||
@plural {n} action|{n} actions {n} операція|{n} операції|{n} операцій
|
||||
Auto Add/Delete Автододавання/видалення
|
||||
ICO is limited to 256 × 256 pixels ICO обмежено розміром 256 × 256 пікселів
|
||||
Load Default Actions Завантажити типові дії
|
||||
|
Can't render this file because it contains an unexpected character in line 1384 and column 18.
|
@@ -3611,3 +3611,4 @@ curves Smooth Làm mượt
|
||||
Choose a gradient file (.grd). Chọn tệp chuyển sắc (.grd).
|
||||
Auto Add/Delete Tự động thêm/xóa
|
||||
ICO is limited to 256 × 256 pixels ICO giới hạn ở 256 × 256 pixel
|
||||
Load Default Actions Tải thao tác mặc định
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -2734,3 +2734,4 @@ curves Smooth 平滑
|
||||
@plural {n} action|{n} actions {n} 个动作
|
||||
Auto Add/Delete 自动添加/删除
|
||||
ICO is limited to 256 × 256 pixels ICO 最大为 256 × 256 像素
|
||||
Load Default Actions 载入默认动作
|
||||
|
Can't render this file because it contains an unexpected character in line 2583 and column 53.
|
@@ -2719,3 +2719,4 @@ curves Smooth 平滑
|
||||
@plural {n} action|{n} actions {n} 個動作
|
||||
Auto Add/Delete 自動增加/刪除
|
||||
ICO is limited to 256 × 256 pixels ICO 最大為 256 × 256 像素
|
||||
Load Default Actions 載入預設動作
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -121,6 +121,7 @@ store expose and persist the same setting; scripts keep using canonical command
|
||||
| `type.caret` | `{"layer":id?,"index":char}`: caret segment in document pixels, `{"index","line","segment":[[x,y],[x,y]]}` (rotated and vertical type included) |
|
||||
| `type.navigate` | `{"layer":id?,"index":char,"move":"wordPrev\|wordNext\|linePrev\|lineNext\|lineStart\|lineEnd\|start\|end","x":px?}`: neighbouring caret. `x` keeps the column across line moves. Result `{"index"}` |
|
||||
| `actions.list` | `{}` → `{actions:[{name, steps}], recording}` (the name being recorded, or null) |
|
||||
| `actions.loadDefaults` | `{}` → `{added:[names], set}`. Append missing PhotoCraft Essentials actions without replacing same-name actions. Available without a document; refused while recording or playing an action. |
|
||||
| `actions.get` | `{"action": name or index}` → `{name, steps:[[id, params], …], disabled:[step, …]}`. `steps` is the shape `file.automate.batch` and droplets take; `disabled` lists the 0-based steps playback skips |
|
||||
| `actions.record` | `{"name":"Red"}` starts a new action (default name `Action N`). `{"action": name or index}` appends to one that exists |
|
||||
| `actions.stop` | `{}` → `{action, steps}`. Copies replayable journal entries since `actions.record` (queries and action-editing commands omitted) |
|
||||
@@ -130,7 +131,18 @@ store expose and persist the same setting; scripts keep using canonical command
|
||||
| `actions.toggle` | `{"action": name or index, "step": index?, "enabled": bool?}` → `{action, disabled}`. Switches one 0-based step (pending recorded steps included) on or off; omitting `enabled` flips it. Without `step`, switches every step: on unless all already are. Playback, Batch and droplets skip steps that are off. In the desktop panel, click a step's check box |
|
||||
| `actions.rename` | `{"action": name or index, "name": str}` → `{action, index}`. Empty, whitespace-only or duplicate names are rejected and keep the old name. Nested `actions.play` steps that call the action by name and its function key follow the new name. In the desktop panel, double-click an action's name to rename it in place (Enter commits, Esc cancels) |
|
||||
|
||||
The Actions list fills the resizable dock group.
|
||||
The Actions list fills the resizable dock group. **PhotoCraft Essentials** supplies Auto Tone,
|
||||
Auto Contrast, Auto Color, and Select Subject. These are original, editable single-step actions
|
||||
using PhotoCraft's existing commands. The three auto adjustments work on the active pixel layer
|
||||
and respect the selection; Select Subject samples the visible image using PhotoCraft's current
|
||||
subject-detection heuristic. Each successful edit can be undone normally.
|
||||
|
||||
The set is added once when the desktop or web preset store opens, including for existing users.
|
||||
Saved actions keep their order and definitions; a same-name action is preserved. Deleting or
|
||||
renaming a default stays that way after restart. **Load Default Actions** in the Actions panel's
|
||||
menu (also offered by an empty panel) adds missing defaults again. CLI/MCP sessions can use
|
||||
`actions.loadDefaults` explicitly. Background blur is not included: composing Select Subject,
|
||||
Inverse, and Blur cannot safely handle the detector finding no subject.
|
||||
|
||||
The Actions panel shows replayable steps immediately while recording. Click an individual
|
||||
step to select it, then use the trash button to remove that step; selecting the action
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# Implementation decisions
|
||||
|
||||
## 2026-10-13: Editable starter actions (#4779)
|
||||
|
||||
PhotoCraft Essentials uses existing commands as ordinary editable actions. Add the set once after saved actions load, preserving names and order; persist a starter-set version so deleted or renamed actions stay that way. Explicit Load Default Actions adds missing names without replacing edits. Keep headless sessions empty until that command is called. Background blur needs a separate atomic operation: a recorded Select Subject → Inverse → Blur sequence can act on an old selection when subject detection finds nothing.
|
||||
|
||||
## 2026-10-10: Smart Object contents identity (#2163)
|
||||
|
||||
Smart Object instances carry a document-scoped contents ID separately from their layer ID. Normal duplicates preserve it; New Smart Object via Copy creates a new one. Contents edits update the matching instances together, retaining their individual placement and filters. Copies into another document remap contents IDs as a batch, preserving sharing within the copied layers without joining existing destination objects.
|
||||
|
||||
Reference in new issue
Block a user