Let a photographer name the state they liked, and go back to it or look at it
FR-DEV-5 asked for named snapshots of an edit state and FR-DEV-7 for a comparison against a chosen one, and neither existed. The history stack is per sitting and forgotten with it, on purpose — the gap that mattered was an automatically saved mis-drag with no way back, and that was closed first. What was left was the other half: a state the photographer wants to keep *because* it is worth keeping, which is a different thing from a step and is not served by making the steps last longer. A snapshot is an edit state, and an edit state is exactly what a sidecar version stores, so it is stored as one: a `[version]` block carrying `snapshot-of = <uuid>`. The parameters, the masks and their parts, the repairs and the film all arrive through the blocks that already carry them, a merge keys on the uuid as it does for any version, and a build that predates the key reads the block as a named version and keeps it — the right failure. Only the pointer is new. The one reader that has to know is `default_version`, which must never answer with a snapshot: a file whose edit is missing is not a file whose edit is one of its saved moments. The snapshots of an edit are listed by that pointer, oldest first, the same on every device. Writing them back removes what this sitting deleted and puts in what it holds, and leaves standing whatever it never saw — a snapshot the other device took since the photograph was opened here is not this device's to remove by not knowing about it. That is the rule the version merge already keeps, applied one level down, and it is why the save carries the deleted ids rather than replacing the list wholesale as the masks are. Each is re-pointed at the uuid the save settled on, because the default may have been fused onto its canonical identity since the snapshot was taken. Restoring is one history step, so undo takes it back whole, as a paste is. Taking and deleting are not steps: they change nothing about the photograph, and an undo that removed a snapshot would be undoing a decision to remember. Holding the eye beside one renders the snapshot and hands the edit straight back — the same suspension "Before" uses, against a point the photographer chose rather than the file. Two sessions on the same photograph get ids that cannot collide, stamped with the second and a random word, because the merge folds equal ids into one.
This commit is contained in:
@@ -778,6 +778,27 @@ pub struct DevelopSession {
|
||||
/// a history the *call sites* had to remember would be one press of undo
|
||||
/// away from wrong every time a control is added.
|
||||
history: History,
|
||||
/// TRACES: FR-DEV-5
|
||||
/// The named snapshots of this edit, as the sidecar had them plus what
|
||||
/// this sitting took, minus what it deleted.
|
||||
///
|
||||
/// Beside the history rather than inside it, because they answer a
|
||||
/// different question. The history is what was done in this sitting and
|
||||
/// is deliberately forgotten with it; a snapshot is a state the
|
||||
/// photographer *named*, which is the act of saying it should outlive
|
||||
/// the sitting. It is persisted as a version of the sidecar pointing at
|
||||
/// this one (`Version::snapshot_of`), which is what makes it survive a
|
||||
/// restart and reach the other device.
|
||||
snapshots: Vec<dr_pipeline::Version>,
|
||||
/// The ids of snapshots deleted this sitting, so the save can remove
|
||||
/// them from the file without removing what another device added since
|
||||
/// — see `Sidecar::replace_snapshots`.
|
||||
removed_snapshots: Vec<String>,
|
||||
/// TRACES: FR-DEV-7
|
||||
/// The snapshot the canvas is showing instead of the edit, while a
|
||||
/// comparison is held. Viewing state: nothing about the edit changes,
|
||||
/// and it goes down with the session.
|
||||
compared_snapshot: Option<String>,
|
||||
demosaiced: Arc<DemosaicedImage>,
|
||||
adjust: AdjustPass,
|
||||
/// TRACES: FR-DSP-7
|
||||
@@ -1041,6 +1062,9 @@ impl DevelopSession {
|
||||
ctx: ctx.clone(),
|
||||
graph,
|
||||
history,
|
||||
snapshots: Vec::new(),
|
||||
removed_snapshots: Vec::new(),
|
||||
compared_snapshot: None,
|
||||
demosaiced: Arc::new(demosaiced),
|
||||
adjust: AdjustPass::new(ctx),
|
||||
histogram: HistogramPass::new(ctx)
|
||||
@@ -5446,6 +5470,162 @@ impl DevelopSession {
|
||||
self.history.reset(&self.graph);
|
||||
}
|
||||
|
||||
// ---- named snapshots ---------------------------------------------------
|
||||
|
||||
/// TRACES: FR-DEV-5
|
||||
/// Hand the session the snapshots its sidecar holds. Called once, on
|
||||
/// open, beside [`Self::apply_version`].
|
||||
pub fn set_snapshots(&mut self, snapshots: Vec<dr_pipeline::Version>) {
|
||||
self.snapshots = snapshots;
|
||||
self.removed_snapshots.clear();
|
||||
}
|
||||
|
||||
/// The snapshots as they stand, oldest first.
|
||||
pub fn snapshots(&self) -> &[dr_pipeline::Version] {
|
||||
&self.snapshots
|
||||
}
|
||||
|
||||
/// The ids deleted this sitting, for the save.
|
||||
pub fn removed_snapshots(&self) -> &[String] {
|
||||
&self.removed_snapshots
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-5
|
||||
/// Name the state the photograph is in, and keep it. Returns the id.
|
||||
///
|
||||
/// Not a history step: taking a snapshot changes nothing about the edit,
|
||||
/// and an undo that removed one would be undoing a decision to remember
|
||||
/// rather than a change to the photograph. Deleting one is the same.
|
||||
///
|
||||
/// The id is stamped with the second and a per-process random word
|
||||
/// rather than counted, because two devices can each take a snapshot of
|
||||
/// the same photograph and both have to survive the merge — which keys
|
||||
/// on this id, and would fold two `snap-3`s into one.
|
||||
pub fn take_snapshot(&mut self, name: &str) -> String {
|
||||
use std::hash::{BuildHasher, Hasher};
|
||||
let now = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map(|d| d.as_secs() as i64)
|
||||
.unwrap_or(0);
|
||||
let salt = std::collections::hash_map::RandomState::new()
|
||||
.build_hasher()
|
||||
.finish();
|
||||
let id = format!("snap-{now}-{:08x}", salt as u32);
|
||||
|
||||
let name = name.trim();
|
||||
let name = if name.is_empty() {
|
||||
format!("Snapshot {}", self.snapshots.len() + 1)
|
||||
} else {
|
||||
name.to_string()
|
||||
};
|
||||
let mut version = dr_pipeline::Version::from_graph(id.clone(), name, &self.graph);
|
||||
// The stack with the model's coverage folded in, for the reason the
|
||||
// save uses it: a subject layer stored by identity alone renders as
|
||||
// nothing until a model is run, and a snapshot restored on the other
|
||||
// device, or in a batch export, never gets one.
|
||||
version.masks = self.masks_for_storage();
|
||||
version.modified = now;
|
||||
self.snapshots.push(version);
|
||||
id
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-5
|
||||
/// Put the photograph back the way a snapshot has it. One history step,
|
||||
/// so it is undoable as a whole, exactly as a paste is.
|
||||
pub fn restore_snapshot(&mut self, id: &str) -> bool {
|
||||
let Some(version) = self.snapshots.iter().find(|v| v.uuid == id).cloned() else {
|
||||
return false;
|
||||
};
|
||||
let rebake = version.apply(&mut self.graph);
|
||||
self.pay_film_debt(&rebake);
|
||||
self.history
|
||||
.record(&self.graph, Edit::Action(labels::step::SNAPSHOT_RESTORED));
|
||||
true
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-5
|
||||
pub fn rename_snapshot(&mut self, id: &str, name: &str) {
|
||||
let name = name.trim();
|
||||
if name.is_empty() {
|
||||
return;
|
||||
}
|
||||
if let Some(v) = self.snapshots.iter_mut().find(|v| v.uuid == id) {
|
||||
v.name = name.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-5
|
||||
/// Forget a snapshot. Remembered as a deletion so the save takes it out
|
||||
/// of the file rather than merely not putting it back.
|
||||
pub fn delete_snapshot(&mut self, id: &str) {
|
||||
let before = self.snapshots.len();
|
||||
self.snapshots.retain(|v| v.uuid != id);
|
||||
if self.snapshots.len() != before {
|
||||
self.removed_snapshots.push(id.to_string());
|
||||
}
|
||||
if self.compared_snapshot.as_deref() == Some(id) {
|
||||
self.compared_snapshot = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-7
|
||||
/// Hold a comparison against a snapshot, or let it go. Returns whether
|
||||
/// anything changed, so a repeat costs no render.
|
||||
pub fn compare_snapshot(&mut self, id: Option<&str>) -> bool {
|
||||
let id = id.filter(|id| self.snapshots.iter().any(|v| v.uuid == *id));
|
||||
if self.compared_snapshot.as_deref() == id {
|
||||
return false;
|
||||
}
|
||||
self.compared_snapshot = id.map(str::to_string);
|
||||
true
|
||||
}
|
||||
|
||||
/// The snapshot being held against the edit, if one is.
|
||||
pub fn compared_snapshot(&self) -> Option<&str> {
|
||||
self.compared_snapshot.as_deref()
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-7
|
||||
/// Render the photograph as a snapshot has it, without becoming it.
|
||||
///
|
||||
/// The same suspension [`Self::render_original`] uses — borrow the graph
|
||||
/// for one render and hand it back — because it is the same question
|
||||
/// about a different reference point: "the version I liked twenty
|
||||
/// minutes ago" instead of the file. Nothing is recorded and nothing is
|
||||
/// marked modified. A held comparison against a snapshot that has since
|
||||
/// been deleted falls back to the edit itself, which is what is on
|
||||
/// screen anyway.
|
||||
pub fn render_compared(&mut self, width: u32, height: u32) -> Result<slint::Image, String> {
|
||||
let Some(version) = self
|
||||
.compared_snapshot
|
||||
.as_deref()
|
||||
.and_then(|id| self.snapshots.iter().find(|v| v.uuid == id))
|
||||
.cloned()
|
||||
else {
|
||||
return self.render(width, height);
|
||||
};
|
||||
let saved = self.graph.state();
|
||||
let debt = version.apply(&mut self.graph);
|
||||
self.pay_film_debt(&debt);
|
||||
let rendered = self.render(width, height);
|
||||
let debt = self.graph.set_state(&saved);
|
||||
self.pay_film_debt(&debt);
|
||||
rendered
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-5
|
||||
/// The snapshot list as the panel draws it, oldest first.
|
||||
pub fn snapshot_rows(&self) -> Vec<crate::SnapshotRow> {
|
||||
self.snapshots
|
||||
.iter()
|
||||
.map(|v| crate::SnapshotRow {
|
||||
id: v.uuid.as_str().into(),
|
||||
name: v.name.as_str().into(),
|
||||
comparing: self.compared_snapshot.as_deref() == Some(v.uuid.as_str()),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3f | FR-DEV-5
|
||||
/// Pay what a restored edit owes the picture.
|
||||
///
|
||||
@@ -6538,6 +6718,109 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-5
|
||||
/// A snapshot is a state the photographer named: taking one changes
|
||||
/// nothing, going back to it is one step, and undo takes the whole of
|
||||
/// that step back.
|
||||
#[test]
|
||||
fn a_snapshot_is_restored_as_one_step_and_undone_as_one() {
|
||||
let Some(ctx) = headless() else { return };
|
||||
let (mut session, _) = grey_session(&ctx);
|
||||
|
||||
let rows = session.rows();
|
||||
let row = rows
|
||||
.iter()
|
||||
.find(|row| {
|
||||
session.set_param(row.op_index, row.param_index, row.maximum);
|
||||
!session.is_neutral()
|
||||
})
|
||||
.expect("some control in the panel moves the picture")
|
||||
.clone();
|
||||
let liked = session.copy_settings();
|
||||
let steps_before = session.history_rows().len();
|
||||
|
||||
let id = session.take_snapshot("Liked this");
|
||||
assert_eq!(session.snapshots().len(), 1);
|
||||
assert_eq!(session.snapshots()[0].name, "Liked this");
|
||||
assert_eq!(
|
||||
session.history_rows().len(),
|
||||
steps_before,
|
||||
"naming a state is not a change to the photograph"
|
||||
);
|
||||
|
||||
// Move on, then go back.
|
||||
session.set_param(row.op_index, row.param_index, row.minimum);
|
||||
let moved_on = session.copy_settings();
|
||||
assert_ne!(moved_on, liked, "the premise: the edit has moved");
|
||||
let steps_moved = session.history_rows().len();
|
||||
|
||||
assert!(session.restore_snapshot(&id));
|
||||
assert_eq!(session.copy_settings(), liked, "back to the named state");
|
||||
assert_eq!(
|
||||
session.history_rows().len(),
|
||||
steps_moved + 1,
|
||||
"restoring is one step"
|
||||
);
|
||||
|
||||
assert!(session.undo());
|
||||
assert_eq!(
|
||||
session.copy_settings(),
|
||||
moved_on,
|
||||
"and undo takes the whole restore back"
|
||||
);
|
||||
|
||||
// A name nobody typed is numbered rather than blank.
|
||||
session.take_snapshot(" ");
|
||||
assert_eq!(session.snapshots()[1].name, "Snapshot 2");
|
||||
|
||||
session.delete_snapshot(&id);
|
||||
assert_eq!(session.snapshots().len(), 1);
|
||||
assert_eq!(session.removed_snapshots(), [id.as_str()]);
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-7 | FR-DEV-5
|
||||
/// Holding a snapshot against the edit is the same bargain as holding
|
||||
/// the original: the picture changes, and nothing else does.
|
||||
#[test]
|
||||
fn comparing_against_a_snapshot_leaves_the_edit_exactly_as_it_was() {
|
||||
let Some(ctx) = headless() else { return };
|
||||
let (mut session, _) = grey_session(&ctx);
|
||||
|
||||
let rows = session.rows();
|
||||
let row = rows
|
||||
.iter()
|
||||
.find(|row| {
|
||||
session.set_param(row.op_index, row.param_index, row.maximum);
|
||||
!session.is_neutral()
|
||||
})
|
||||
.expect("some control in the panel moves the picture")
|
||||
.clone();
|
||||
let id = session.take_snapshot("Bright");
|
||||
session.set_param(row.op_index, row.param_index, row.minimum);
|
||||
let edit = session.copy_settings();
|
||||
let steps = session.history_rows().len();
|
||||
|
||||
assert!(session.compare_snapshot(Some(&id)), "the hold began");
|
||||
assert!(
|
||||
!session.compare_snapshot(Some(&id)),
|
||||
"a repeat of the same hold is not a change"
|
||||
);
|
||||
assert_eq!(session.compared_snapshot(), Some(id.as_str()));
|
||||
session
|
||||
.render_compared(64, 64)
|
||||
.expect("render the snapshot");
|
||||
|
||||
assert_eq!(session.copy_settings(), edit, "every parameter comes back");
|
||||
assert_eq!(session.history_rows().len(), steps, "looking is not a step");
|
||||
|
||||
assert!(session.compare_snapshot(None), "and letting go is one");
|
||||
assert!(session.compared_snapshot().is_none());
|
||||
assert!(
|
||||
!session.compare_snapshot(Some("nothing-by-this-name")),
|
||||
"a snapshot that does not exist cannot be held"
|
||||
);
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3 | FR-CAT-8
|
||||
/// Reopening an edited photograph renders its subject mask, with no model.
|
||||
///
|
||||
|
||||
@@ -113,6 +113,20 @@ pub const GESTURES: &[Gesture] = &[
|
||||
pointer: "Double-click its track, or right-click it",
|
||||
keys: "R, for the control last moved",
|
||||
},
|
||||
Gesture {
|
||||
title: "See the photograph as a snapshot had it",
|
||||
section: "Develop",
|
||||
touch: "Press and hold the eye beside the snapshot",
|
||||
pointer: "Press and hold the eye beside the snapshot",
|
||||
keys: "",
|
||||
},
|
||||
Gesture {
|
||||
title: "Keep the photograph as it is now, under a name",
|
||||
section: "Develop",
|
||||
touch: "Type a name in the History panel and press Snapshot",
|
||||
pointer: "Type a name in the History panel and press Snapshot",
|
||||
keys: "",
|
||||
},
|
||||
Gesture {
|
||||
title: "Show or hide one mask layer",
|
||||
section: "Develop",
|
||||
|
||||
@@ -28,6 +28,9 @@ pub mod step {
|
||||
|
||||
pub const PASTE: LocalizedKey = LocalizedKey("history.paste");
|
||||
pub const FILM: LocalizedKey = LocalizedKey("history.film");
|
||||
/// TRACES: FR-DEV-5
|
||||
/// The photograph put back to a named snapshot, as one step.
|
||||
pub const SNAPSHOT_RESTORED: LocalizedKey = LocalizedKey("history.snapshot_restored");
|
||||
|
||||
/// TRACES: FR-DEV-3
|
||||
/// A neutral was picked off the photograph, setting the white balance.
|
||||
@@ -97,6 +100,7 @@ pub mod step {
|
||||
dr_pipeline::history::OPENED,
|
||||
dr_pipeline::history::UNNAMED,
|
||||
PASTE,
|
||||
SNAPSHOT_RESTORED,
|
||||
FILM,
|
||||
SAMPLED_NEUTRAL,
|
||||
RESET_ALL,
|
||||
@@ -289,6 +293,7 @@ fn catalogued(key: &str) -> Option<&'static str> {
|
||||
"history.opened" => "Opened",
|
||||
"history.edit" => "Edit",
|
||||
"history.paste" => "Paste Settings",
|
||||
"history.snapshot_restored" => "Restore A Snapshot",
|
||||
"history.film" => "Film Stock",
|
||||
"history.sampled_neutral" => "Sample Neutral",
|
||||
|
||||
|
||||
@@ -1838,6 +1838,11 @@ pub fn run(paths: Vec<PathBuf>) -> Result<()> {
|
||||
// the list is rebuilt when it would read differently, not when the picture
|
||||
// is redrawn, and those are very different rates.
|
||||
let drawn_history: Rc<Cell<Option<u64>>> = Rc::new(Cell::new(None));
|
||||
// TRACES: FR-DEV-5
|
||||
// And the snapshot list, compared by value rather than by a revision: it
|
||||
// is a handful of rows, and a held comparison changes one of them
|
||||
// without a step being taken.
|
||||
let drawn_snapshots: Rc<RefCell<Option<Vec<SnapshotRow>>>> = Rc::new(RefCell::new(None));
|
||||
|
||||
// TRACES: FR-CULL-3
|
||||
// How the photographer wants focus peaking drawn, or `None` for off.
|
||||
@@ -1874,6 +1879,7 @@ pub fn run(paths: Vec<PathBuf>) -> Result<()> {
|
||||
let session = session.clone();
|
||||
let viewport = viewport.clone();
|
||||
let drawn_history = drawn_history.clone();
|
||||
let drawn_snapshots = drawn_snapshots.clone();
|
||||
let display = display.clone();
|
||||
let chosen_peaking = chosen_peaking.clone();
|
||||
Rc::new(move |window: &AppWindow, draft: bool| {
|
||||
@@ -1916,6 +1922,16 @@ pub fn run(paths: Vec<PathBuf>) -> Result<()> {
|
||||
steps.set_rows(slint::ModelRc::new(slint::VecModel::from(s.history_rows())));
|
||||
steps.set_undo_label(s.undo_label().into());
|
||||
}
|
||||
// TRACES: FR-DEV-5
|
||||
// The snapshots, on the same path. Rebuilt only when the list
|
||||
// would read differently, for the reason the steps are: a held
|
||||
// comparison redraws, and it is the one thing here that changes
|
||||
// a row without changing the history.
|
||||
let snapshots = s.snapshot_rows();
|
||||
if drawn_snapshots.borrow().as_ref() != Some(&snapshots) {
|
||||
*drawn_snapshots.borrow_mut() = Some(snapshots.clone());
|
||||
steps.set_snapshots(slint::ModelRc::new(slint::VecModel::from(snapshots)));
|
||||
}
|
||||
|
||||
// TRACES: FR-DEV-3
|
||||
// Which part of the region overlay the view is showing. Here
|
||||
@@ -1979,6 +1995,10 @@ pub fn run(paths: Vec<PathBuf>) -> Result<()> {
|
||||
s.render_uncropped(w, h).map(|(image, _, _)| image)
|
||||
} else if window.get_showing_original() {
|
||||
s.render_original(w, h)
|
||||
} else if s.compared_snapshot().is_some() {
|
||||
// TRACES: FR-DEV-7
|
||||
// The same hold, against a snapshot rather than the file.
|
||||
s.render_compared(w, h)
|
||||
} else {
|
||||
s.render(w, h)
|
||||
};
|
||||
@@ -3043,6 +3063,80 @@ pub fn run(paths: Vec<PathBuf>) -> Result<()> {
|
||||
}
|
||||
});
|
||||
}
|
||||
// TRACES: FR-DEV-5
|
||||
// Named snapshots. Taking and deleting one change the list and nothing
|
||||
// else — no rows, no history — so they redraw only to push the list,
|
||||
// through the same path everything else pushes it on. Restoring one is
|
||||
// the paste's shape: the whole edit moves, so the rows resync and the
|
||||
// picture is redrawn.
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let session = session.clone();
|
||||
let redraw = redraw.clone();
|
||||
window.global::<Steps>().on_snapshot_taken(move |name| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
if let Some(s) = session.borrow_mut().as_mut() {
|
||||
s.take_snapshot(&name);
|
||||
}
|
||||
redraw(&w);
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let session = session.clone();
|
||||
let redraw = redraw.clone();
|
||||
let rows = rows.clone();
|
||||
window.global::<Steps>().on_snapshot_restored(move |id| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let restored = session
|
||||
.borrow_mut()
|
||||
.as_mut()
|
||||
.is_some_and(|s| s.restore_snapshot(&id));
|
||||
if restored {
|
||||
sync_rows(&w, &rows, &session);
|
||||
// The mask panel too: a snapshot carries its layers, and
|
||||
// the redraw syncs the repairs and the overlay but not the
|
||||
// rows the layers are listed in.
|
||||
masks_ui::sync(&w, &session);
|
||||
redraw(&w);
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let session = session.clone();
|
||||
let redraw = redraw.clone();
|
||||
window.global::<Steps>().on_snapshot_removed(move |id| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
if let Some(s) = session.borrow_mut().as_mut() {
|
||||
s.delete_snapshot(&id);
|
||||
}
|
||||
redraw(&w);
|
||||
});
|
||||
}
|
||||
{
|
||||
// TRACES: FR-DEV-7
|
||||
// Holding a snapshot against the edit, and letting it go — the
|
||||
// Before button's shape, and its rule: no rows are synced and no
|
||||
// history is touched. A full frame rather than a draft, for the
|
||||
// reason the original is: a soft comparison shows a difference the
|
||||
// edit does not have.
|
||||
let weak = window.as_weak();
|
||||
let session = session.clone();
|
||||
let render_now = render_now.clone();
|
||||
window
|
||||
.global::<Steps>()
|
||||
.on_snapshot_compared(move |id, down| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let changed = session
|
||||
.borrow_mut()
|
||||
.as_mut()
|
||||
.is_some_and(|s| s.compare_snapshot(down.then_some(id.as_str())));
|
||||
if changed {
|
||||
render_now(&w, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ---- zoom, pan and crop ---------------------------------------------
|
||||
//
|
||||
|
||||
@@ -544,6 +544,11 @@ pub enum Amendment {
|
||||
/// `Some(None)` is a real edit: "develop this normally again". Without
|
||||
/// the distinction, clearing a film could never be saved.
|
||||
film: Option<Option<dr_pipeline::sidecar::FilmRef>>,
|
||||
/// TRACES: FR-DEV-5
|
||||
/// The named snapshots, when this is an image's own edit being
|
||||
/// written back: the ones the session holds, and the ids it deleted.
|
||||
/// A paste carries none — a snapshot is a state of one photograph.
|
||||
snapshots: Option<(Vec<dr_pipeline::Version>, Vec<String>)>,
|
||||
/// TRACES: FR-DEV-3 | FR-CAT-8
|
||||
/// The local adjustments, when this is an image's own edit being
|
||||
/// written back rather than a paste onto someone else's.
|
||||
@@ -795,6 +800,7 @@ fn amend(base: dr_pipeline::Sidecar, w: &SidecarWrite) -> dr_pipeline::Sidecar {
|
||||
scope,
|
||||
masks,
|
||||
film,
|
||||
..
|
||||
} => {
|
||||
preset.amend(&mut version.params, *scope);
|
||||
// TRACES: FR-DEV-3f
|
||||
@@ -823,6 +829,17 @@ fn amend(base: dr_pipeline::Sidecar, w: &SidecarWrite) -> dr_pipeline::Sidecar {
|
||||
version.modified = now_secs();
|
||||
|
||||
sidecar.put(version);
|
||||
// TRACES: FR-DEV-5 | FR-NC-9
|
||||
// After the version, and against the uuid the fuse settled on: a
|
||||
// snapshot points at its edit by uuid, and the edit may have just been
|
||||
// renamed onto the canonical one.
|
||||
if let Amendment::Settings {
|
||||
snapshots: Some((kept, removed)),
|
||||
..
|
||||
} = &w.amendment
|
||||
{
|
||||
sidecar.replace_snapshots(&w.version_uuid, kept.clone(), removed);
|
||||
}
|
||||
sidecar
|
||||
}
|
||||
|
||||
|
||||
@@ -3321,6 +3321,9 @@ fn collect_settings_writes(
|
||||
// not a parameter. Pasting one would be pasting a choice the
|
||||
// clipboard never captured.
|
||||
film: None,
|
||||
// Nor snapshots: they are states of the photograph they were
|
||||
// taken on, and mean nothing on another.
|
||||
snapshots: None,
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
+96
-4
@@ -315,6 +315,7 @@ pub fn save_local(
|
||||
preset: &Preset,
|
||||
scope: Scope,
|
||||
masks: Option<&dr_pipeline::mask::MaskStack>,
|
||||
snapshots: Option<(&[dr_pipeline::Version], &[String])>,
|
||||
) -> Result<(), String> {
|
||||
let path = local_sidecar_path(image);
|
||||
|
||||
@@ -369,6 +370,10 @@ pub fn save_local(
|
||||
version.revision = version.revision.saturating_add(1);
|
||||
version.modified = now_secs();
|
||||
sidecar.put(version);
|
||||
// TRACES: FR-DEV-5
|
||||
if let Some((kept, removed)) = snapshots {
|
||||
sidecar.replace_snapshots(&uuid, kept.to_vec(), removed);
|
||||
}
|
||||
|
||||
let text = sidecar.to_text();
|
||||
|
||||
@@ -401,9 +406,9 @@ pub fn save_open_edit(
|
||||
session: &Rc<RefCell<Option<DevelopSession>>>,
|
||||
library: &Rc<library_ui::LibraryController>,
|
||||
) {
|
||||
// Both taken in one borrow: they are one edit, and a mask stack captured
|
||||
// All taken in one borrow: they are one edit, and a mask stack captured
|
||||
// from a session that had already moved on would be a different image's.
|
||||
let Some((preset, masks, film)) = session.borrow().as_ref().map(|s| {
|
||||
let Some((preset, masks, film, snapshots, removed)) = session.borrow().as_ref().map(|s| {
|
||||
(
|
||||
s.copy_settings(),
|
||||
// TRACES: FR-DEV-3
|
||||
@@ -429,6 +434,12 @@ pub fn save_open_edit(
|
||||
.unwrap_or_default()
|
||||
}),
|
||||
}),
|
||||
// TRACES: FR-DEV-5
|
||||
// The snapshots as they stand and the ids deleted this sitting,
|
||||
// so the file gains what was taken and loses what was removed —
|
||||
// and keeps what another device added meanwhile.
|
||||
s.snapshots().to_vec(),
|
||||
s.removed_snapshots().to_vec(),
|
||||
)
|
||||
}) else {
|
||||
return;
|
||||
@@ -443,7 +454,13 @@ pub fn save_open_edit(
|
||||
// `Everything`: this is the image's *own* edit being written back,
|
||||
// not a paste onto someone else's. Excluding framing here would
|
||||
// make a crop the one adjustment that never survived a restart.
|
||||
if let Err(e) = save_local(path, &preset, Scope::everything(), Some(&masks)) {
|
||||
if let Err(e) = save_local(
|
||||
path,
|
||||
&preset,
|
||||
Scope::everything(),
|
||||
Some(&masks),
|
||||
Some((&snapshots, &removed)),
|
||||
) {
|
||||
log::warn!("saving {}: {e}", path.display());
|
||||
}
|
||||
}
|
||||
@@ -461,6 +478,7 @@ pub fn save_open_edit(
|
||||
// sliders were written and every mask was dropped.
|
||||
masks: Some(masks),
|
||||
film: Some(film),
|
||||
snapshots: Some((snapshots, removed)),
|
||||
},
|
||||
};
|
||||
library_ui::start_sidecar_writes(window, library, vec![write]);
|
||||
@@ -536,6 +554,15 @@ pub fn apply_stored_edit(
|
||||
let mut slot = session.borrow_mut();
|
||||
let Some(s) = slot.as_mut() else { return false };
|
||||
s.apply_version(version);
|
||||
// TRACES: FR-DEV-5
|
||||
// And the snapshots taken of it, on this device or another.
|
||||
s.set_snapshots(
|
||||
sidecar
|
||||
.snapshots_of(&version.uuid)
|
||||
.into_iter()
|
||||
.cloned()
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
|
||||
crate::sync_rows(window, rows, session);
|
||||
@@ -1162,6 +1189,7 @@ mod tests {
|
||||
&Preset::capture(&graph),
|
||||
Scope::everything(),
|
||||
Some(graph.masks()),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1209,6 +1237,7 @@ mod tests {
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1242,6 +1271,7 @@ mod tests {
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
save_local(
|
||||
@@ -1249,6 +1279,7 @@ mod tests {
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1267,6 +1298,7 @@ mod tests {
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let first = load_local(&image)
|
||||
@@ -1279,6 +1311,7 @@ mod tests {
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let second = load_local(&image)
|
||||
@@ -1313,6 +1346,7 @@ mod tests {
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1335,7 +1369,8 @@ mod tests {
|
||||
&image,
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.is_err());
|
||||
assert_eq!(
|
||||
@@ -1353,6 +1388,7 @@ mod tests {
|
||||
&Preset::capture(&edited()),
|
||||
Scope::everything(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1638,4 +1674,60 @@ mod tests {
|
||||
"the failed overwrite kept the new value"
|
||||
);
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-5
|
||||
/// A snapshot goes into the file beside the edit and comes back out as a
|
||||
/// snapshot of it; deleting one takes it out of the file; and neither
|
||||
/// touches the edit the photograph opens at.
|
||||
#[test]
|
||||
fn snapshots_survive_the_local_sidecar_and_leave_it_when_deleted() {
|
||||
let dir = tempdir("snapshots");
|
||||
let image = dir.join("IMG_0001.CR3");
|
||||
std::fs::write(&image, b"").unwrap();
|
||||
|
||||
let graph = edited();
|
||||
let mut liked = EditGraph::default_chain();
|
||||
liked.set_param(
|
||||
dr_pipeline::ops::exposure::ID,
|
||||
dr_pipeline::ops::exposure::EXPOSURE,
|
||||
1.5,
|
||||
);
|
||||
let snapshot = dr_pipeline::Version::from_graph("snap-1", "Brighter", &liked);
|
||||
|
||||
save_local(
|
||||
&image,
|
||||
&Preset::capture(&graph),
|
||||
Scope::everything(),
|
||||
None,
|
||||
Some((&[snapshot], &[])),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let text = std::fs::read_to_string(local_sidecar_path(&image)).unwrap();
|
||||
let sidecar = Sidecar::parse(&text).unwrap();
|
||||
let edit = sidecar.default_version().expect("the edit");
|
||||
assert!(!edit.is_snapshot(), "the photograph opens at its edit");
|
||||
let back = sidecar.snapshots_of(&edit.uuid);
|
||||
assert_eq!(back.len(), 1);
|
||||
assert_eq!(back[0].name, "Brighter");
|
||||
assert_eq!(
|
||||
back[0]
|
||||
.params
|
||||
.get(&("exposure".to_string(), "exposure".to_string())),
|
||||
Some(&1.5)
|
||||
);
|
||||
|
||||
save_local(
|
||||
&image,
|
||||
&Preset::capture(&graph),
|
||||
Scope::everything(),
|
||||
None,
|
||||
Some((&[], &["snap-1".to_string()])),
|
||||
)
|
||||
.unwrap();
|
||||
let text = std::fs::read_to_string(local_sidecar_path(&image)).unwrap();
|
||||
let sidecar = Sidecar::parse(&text).unwrap();
|
||||
let edit = sidecar.default_version().expect("the edit is still there");
|
||||
assert!(sidecar.snapshots_of(&edit.uuid).is_empty(), "{text}");
|
||||
}
|
||||
}
|
||||
|
||||
+152
-1
@@ -19,7 +19,7 @@
|
||||
|
||||
import { Theme } from "theme.slint";
|
||||
import { Develop } from "session.slint";
|
||||
import { PanelHeading, Caption, Label, Value, Button } from "widgets.slint";
|
||||
import { PanelHeading, Caption, Label, Value, Button, Field } from "widgets.slint";
|
||||
|
||||
// One step, flattened for Slint's model system.
|
||||
export struct HistoryRow {
|
||||
@@ -40,6 +40,105 @@ export struct HistoryRow {
|
||||
undone: bool,
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-5
|
||||
/// One named snapshot of the open edit.
|
||||
export struct SnapshotRow {
|
||||
/// Routing back to the core. Opaque to this file.
|
||||
id: string,
|
||||
name: string,
|
||||
/// The canvas is showing this one instead of the edit, while held.
|
||||
comparing: bool,
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-5 | FR-DEV-7
|
||||
/// A snapshot: press it to go back to it, hold the eye beside it to look.
|
||||
component SnapshotItem inherits Rectangle {
|
||||
in property <SnapshotRow> data;
|
||||
in property <bool> enabled: true;
|
||||
callback restored();
|
||||
/// Both edges, like "Before": down shows the snapshot, up shows the edit.
|
||||
callback compared(bool);
|
||||
callback removed();
|
||||
|
||||
height: Theme.row-height;
|
||||
background: root.data.comparing
|
||||
? Theme.selected
|
||||
: (touch.has-hover ? Theme.hover : transparent);
|
||||
|
||||
// Behind the two buttons, so a press on either does its own job and a
|
||||
// press anywhere else on the row is the restore.
|
||||
touch := TouchArea {
|
||||
width: 100%;
|
||||
height: max(parent.height, Theme.touch-target);
|
||||
y: (parent.height - self.height) / 2;
|
||||
enabled: root.enabled;
|
||||
mouse-cursor: root.enabled ? MouseCursor.pointer : MouseCursor.default;
|
||||
clicked => { root.restored(); }
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.gap-sm;
|
||||
padding-right: Theme.gap-sm;
|
||||
spacing: Theme.gap-sm;
|
||||
|
||||
Label {
|
||||
text: root.data.name;
|
||||
emphasised: root.data.comparing || touch.has-hover;
|
||||
horizontal-stretch: 1;
|
||||
overflow: elide;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
|
||||
// GESTURE: See the photograph as a snapshot had it
|
||||
// where: Develop
|
||||
// touch: Press and hold the eye beside the snapshot
|
||||
// pointer: Press and hold the eye beside the snapshot
|
||||
// why: The same hold as "Before", against a point the
|
||||
// photographer chose rather than the file: "the version
|
||||
// I liked twenty minutes ago" is how a choice between two
|
||||
// treatments is actually made. It takes no history step
|
||||
// and changes nothing; letting go puts the edit back.
|
||||
//
|
||||
// TRACES: FR-DEV-7
|
||||
eye := TouchArea {
|
||||
width: Theme.touch-target;
|
||||
mouse-cursor: pointer;
|
||||
enabled: root.enabled;
|
||||
pointer-event(event) => {
|
||||
if event.kind == PointerEventKind.down
|
||||
&& event.button == PointerEventButton.left {
|
||||
root.compared(true);
|
||||
}
|
||||
if event.kind == PointerEventKind.up
|
||||
|| event.kind == PointerEventKind.cancel {
|
||||
root.compared(false);
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
text: "◐";
|
||||
emphasised: eye.has-hover || root.data.comparing;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
|
||||
cut := TouchArea {
|
||||
width: Theme.touch-target;
|
||||
mouse-cursor: pointer;
|
||||
enabled: root.enabled;
|
||||
clicked => { root.removed(); }
|
||||
|
||||
Label {
|
||||
text: "×";
|
||||
emphasised: cut.has-hover;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component StepRow inherits Rectangle {
|
||||
in property <HistoryRow> data;
|
||||
in property <bool> enabled: true;
|
||||
@@ -115,6 +214,18 @@ export global Steps {
|
||||
callback redo();
|
||||
/// A row's own `index`, not its position in `rows`.
|
||||
callback picked(int);
|
||||
|
||||
/// TRACES: FR-DEV-5
|
||||
/// The named snapshots of the open edit, oldest first. Rust owns the
|
||||
/// list; the panel only names, restores, deletes and holds them.
|
||||
in property <[SnapshotRow]> snapshots;
|
||||
/// The name typed for the next one. Empty is allowed: Rust numbers it.
|
||||
callback snapshot-taken(string);
|
||||
callback snapshot-restored(string);
|
||||
callback snapshot-removed(string);
|
||||
/// TRACES: FR-DEV-7
|
||||
/// `true` on the way down, `false` on the way up.
|
||||
callback snapshot-compared(string, bool);
|
||||
}
|
||||
|
||||
export component HistoryPanel inherits Rectangle {
|
||||
@@ -189,6 +300,46 @@ export component HistoryPanel inherits Rectangle {
|
||||
overflow: elide;
|
||||
}
|
||||
|
||||
// TRACES: FR-DEV-5
|
||||
// Snapshots above the steps: a snapshot is the state worth keeping
|
||||
// out of a run of steps, so it sits where the steps lead to.
|
||||
//
|
||||
// GESTURE: Keep the photograph as it is now, under a name
|
||||
// where: Develop
|
||||
// touch: Type a name in the History panel and press Snapshot
|
||||
// pointer: Type a name in the History panel and press Snapshot
|
||||
// why: The history is forgotten with the sitting, on purpose;
|
||||
// a snapshot is the photographer saying this one should
|
||||
// not be. It is written into the sidecar as a version
|
||||
// of the edit, so it survives a restart and reaches the
|
||||
// other device. Pressing a snapshot puts the photograph
|
||||
// back to it, as one step that undo takes back whole.
|
||||
if Develop.enabled: HorizontalLayout {
|
||||
spacing: Theme.gap-sm;
|
||||
|
||||
name := Field {
|
||||
label: "Snapshot name";
|
||||
placeholder: "Name this state";
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Snapshot";
|
||||
clicked => {
|
||||
Steps.snapshot-taken(name.text);
|
||||
name.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for snapshot in Steps.snapshots: SnapshotItem {
|
||||
data: snapshot;
|
||||
enabled: Develop.enabled;
|
||||
restored => { Steps.snapshot-restored(snapshot.id); }
|
||||
compared(down) => { Steps.snapshot-compared(snapshot.id, down); }
|
||||
removed => { Steps.snapshot-removed(snapshot.id); }
|
||||
}
|
||||
|
||||
if Develop.enabled && Steps.rows.length > 0: Rectangle {
|
||||
height: 1px;
|
||||
background: Theme.rule;
|
||||
|
||||
Reference in New Issue
Block a user