diff --git a/crates/imaging/src/ui/fill/mod.rs b/crates/imaging/src/ui/fill/mod.rs index a2582c524..878cf50f3 100644 --- a/crates/imaging/src/ui/fill/mod.rs +++ b/crates/imaging/src/ui/fill/mod.rs @@ -916,7 +916,7 @@ impl FullWindowWorkspace for ContentAwareFillWorkspace { /// The settings, and the bar's `tool`, `brushSize`, `brushMode` (`"add"`, `"subtract"`), `lassoMode` (`"new"`, /// `"add"`, `"subtract"`, `"intersect"`) and `expandBy`. - fn json_fields(&self) -> Option { + fn json_fields(&self, _source: &Self::Source) -> Option { let mut fields = serde_fields(&self.settings)?; let bar = fields.as_object_mut()?; let brush_mode = if self.options.brush_add { "add" } else { "subtract" }; diff --git a/crates/imaging/src/ui/filter_gallery/mod.rs b/crates/imaging/src/ui/filter_gallery/mod.rs index 4ad13d448..3cb77eea5 100644 --- a/crates/imaging/src/ui/filter_gallery/mod.rs +++ b/crates/imaging/src/ui/filter_gallery/mod.rs @@ -436,7 +436,7 @@ impl FullWindowWorkspace for FilterGalleryWorkspace { WorkspacePass::new(dialog.output.response, events).result(result) } - fn json_fields(&self) -> Option { + fn json_fields(&self, _source: &Self::Source) -> Option { let zoom = if self.view.is_fit() { json!("fit") } else { json!(self.view.device_zoom()) }; let effects = serde_json::to_value(&self.session.effects).unwrap_or_default(); Some(json!({ "effects": effects, "select": self.clamped_selection(), "zoom": zoom })) diff --git a/crates/imaging/src/ui/liquify/mod.rs b/crates/imaging/src/ui/liquify/mod.rs index 1200701a5..e8a6225b4 100644 --- a/crates/imaging/src/ui/liquify/mod.rs +++ b/crates/imaging/src/ui/liquify/mod.rs @@ -737,7 +737,7 @@ impl FullWindowWorkspace for LiquifyWorkspace { } /// The settings (the brush keys at the top level) and `preview`. - fn json_fields(&self) -> Option { + fn json_fields(&self, _source: &Self::Source) -> Option { let mut fields = serde_fields(&self.edit.settings)?; fields.as_object_mut()?.insert("preview".to_owned(), serde_json::Value::Bool(self.preview)); Some(fields) diff --git a/crates/imaging/src/ui/raw_develop/mod.rs b/crates/imaging/src/ui/raw_develop/mod.rs index a935ed8c6..f002deed1 100644 --- a/crates/imaging/src/ui/raw_develop/mod.rs +++ b/crates/imaging/src/ui/raw_develop/mod.rs @@ -519,7 +519,7 @@ impl FullWindowWorkspace for RawDevelopWorkspace { const KEY: &'static str = "filter.cameraRaw"; fn show(&mut self, ui: &mut Ui, cx: WorkspaceCx<'_, Self::Source>) -> WorkspacePass { - let WorkspaceCx { source, revision, open, .. } = cx; + let WorkspaceCx { source, revision, open, hold_ok, ok_waits, .. } = cx; let env = Env::of(ui); let words = env.words::(); let common = env.words::(); @@ -529,9 +529,11 @@ impl FullWindowWorkspace for RawDevelopWorkspace { let name = if self.target == RawTarget::OpenRaw { words.name.clone() } else { words.name_filter.clone() }; let title: Label = FullWindowTitle::new(name).subject(self.subject.clone()).zoom(self.view.zoom_percent()).label(&env); - let mut plan = vec![(Footer::Finish(self.target.accept()), FooterButton::new(self.target_label(&words, &common), DialogRole::Accept))]; + // A held OK files its answer for the app and keeps the workspace open until the app answers; the buttons that finish wait meanwhile. + let finishing = |button: FooterButton| button.stays_open(hold_ok).enabled(!ok_waits); + let mut plan = vec![(Footer::Finish(self.target.accept()), finishing(FooterButton::new(self.target_label(&words, &common), DialogRole::Accept)))]; if self.target == RawTarget::OpenRaw { - plan.push((Footer::Finish(RawFinish::Done), FooterButton::new(words.done.clone(), DialogRole::Other))); + plan.push((Footer::Finish(RawFinish::Done), finishing(FooterButton::new(words.done.clone(), DialogRole::Other)))); } plan.push((Footer::Save, FooterButton::new(words.save_settings.clone(), DialogRole::Other).stays_open(true))); plan.push((Footer::Load, FooterButton::new(words.load_settings.clone(), DialogRole::Other).stays_open(true))); @@ -804,14 +806,17 @@ impl FullWindowWorkspace for RawDevelopWorkspace { Some(Footer::Finish(finish)) => finish, _ => self.target.accept(), }; - let result = match self.requested.take() { - Some(finish) => Some(DialogResult::Ok(self.result(finish))), - None => output.result(|| self.result(finish)), + let (result, held) = match (self.requested.take(), hold_ok) { + (Some(finish), true) => (None, Some(self.result(finish))), + (Some(finish), false) => (Some(DialogResult::Ok(self.result(finish))), None), + // Esc and Cancel close the workspace either way. + (None, true) => (output.closed.map(|_| DialogResult::Cancel), matches!(footer, Some(Footer::Finish(_))).then(|| self.result(finish))), + (None, false) => (output.result(|| self.result(finish)), None), }; - WorkspacePass::new(output.response, events).result(result) + WorkspacePass::new(output.response, events).held(held).result(result) } - fn json_fields(&self) -> Option { + fn json_fields(&self, source: &Self::Source) -> Option { let mut fields = serde_fields(&self.settings)?; if let serde_json::Value::Object(map) = &mut fields { map.insert("before".to_owned(), serde_json::Value::Bool(self.before)); @@ -819,7 +824,11 @@ impl FullWindowWorkspace for RawDevelopWorkspace { let view = if self.view.is_fit() { serde_json::Value::from("fit") } else { serde_json::Value::from(self.view.zoom_percent()) }; map.insert("view".to_owned(), view); let scope = self.scope.as_ref().map(|state| state.settings.clone()).unwrap_or_default(); + let lab = scope.lab_readouts; map.insert("scope".to_owned(), serde_json::to_value(scope).unwrap_or(serde_json::Value::Null)); + let read = |at: [f64; 2]| preview::readout_json(source, at, self.before, lab); + map.insert("pointerReadout".to_owned(), self.hover.map_or(serde_json::Value::Null, read)); + map.insert("samplerReadouts".to_owned(), self.samplers.points().iter().copied().map(read).collect()); } Some(fields) } diff --git a/crates/imaging/src/ui/raw_develop/preview.rs b/crates/imaging/src/ui/raw_develop/preview.rs index 6adde51c2..5e6e5a9ff 100644 --- a/crates/imaging/src/ui/raw_develop/preview.rs +++ b/crates/imaging/src/ui/raw_develop/preview.rs @@ -12,8 +12,8 @@ use super::source::RawDevelopSource; use crate::scopes::ClippingMask; use crate::ui::scopes::{ClippingMode, ClippingOverlay, ScopeReadout}; -/// The readouts of `samplers` over the picture `before` or after, from `cache` while `revision` and the points are -/// unchanged. The samplers ask in RGB; with `lab` (Show Lab Color Readouts) each readout also carries its Lab value, +/// The readouts of `samplers` over the picture `before` or after, from `cache` while `revision`, the picture shown and the +/// points are unchanged. The samplers ask in RGB; with `lab` (Show Lab Color Readouts) each readout also carries its Lab value, /// asked of the source again for the few points. pub(super) fn sampler_readouts( samplers: &ColorSamplers, @@ -27,7 +27,7 @@ pub(super) fn sampler_readouts( Some(ScopeReadout::Rgb([r, g, b])) => Srgba { r, g, b, a: 1.0 }, _ => Srgba { r: 0.0, g: 0.0, b: 0.0, a: 0.0 }, }; - let readouts = SamplerReadouts::new(samplers, read).revision(revision).get(cache); + let readouts = SamplerReadouts::new(samplers, read).revision(revision).document(before).get(cache); if !lab { return readouts; } @@ -44,6 +44,17 @@ pub(super) fn sampler_readouts( Arc::new(with_lab) } +/// The readout under `at` as the automation surface lists it: its `position`, `space` (`rgb` in 0..=255, or `lab` +/// when `lab` asks for the Lab value) and `values`; `null` where the source reads no pixel. +pub(super) fn readout_json(source: &dyn RawDevelopSource, at: [f64; 2], before: bool, lab: bool) -> serde_json::Value { + let (space, values) = match source.sample(at, before, lab) { + Some(ScopeReadout::Rgb(rgb)) => ("rgb", rgb.map(|v| v * 255.0)), + Some(ScopeReadout::Lab(lab)) => ("lab", lab), + _ => return serde_json::Value::Null, + }; + serde_json::json!({ "position": at, "space": space, "values": values }) +} + /// The source's clipping mask and its revision while a warning is on; nothing when `mode` shows none. pub(super) fn clipping_state(source: &dyn RawDevelopSource, mode: ClippingMode) -> Option<(Arc, Revision)> { if matches!(mode, ClippingMode::None) { None } else { source.clipping() } diff --git a/crates/imaging/src/ui/select_mask/mod.rs b/crates/imaging/src/ui/select_mask/mod.rs index b2079f213..d53267345 100644 --- a/crates/imaging/src/ui/select_mask/mod.rs +++ b/crates/imaging/src/ui/select_mask/mod.rs @@ -915,7 +915,7 @@ impl FullWindowWorkspace for SelectMaskWorkspace { /// The settings, and the bar's `tool`, `mode` (`"add"`, `"subtract"`), `size` (of the current tool), `hardness`, /// `sampleAllLayers`, and `hideView`. - fn json_fields(&self) -> Option { + fn json_fields(&self, _source: &Self::Source) -> Option { let mut fields = serde_fields(&self.settings)?; let bar = fields.as_object_mut()?; let mode = if self.options.add { "add" } else { "subtract" }; diff --git a/crates/imaging/src/ui/vanishing_point/mod.rs b/crates/imaging/src/ui/vanishing_point/mod.rs index 54b75e361..56711c5f9 100644 --- a/crates/imaging/src/ui/vanishing_point/mod.rs +++ b/crates/imaging/src/ui/vanishing_point/mod.rs @@ -514,7 +514,7 @@ impl FullWindowWorkspace for VanishingPointWorkspace { WorkspacePass::new(shown.output.response.clone(), events).result(result) } - fn json_fields(&self) -> Option { + fn json_fields(&self, _source: &Self::Source) -> Option { let mut fields = serde_fields(&self.settings)?; let map = fields.as_object_mut()?; let selected = self.editor.selected().map_or(Value::Null, Value::from); diff --git a/crates/imaging/src/ui/wide_angle/mod.rs b/crates/imaging/src/ui/wide_angle/mod.rs index 5995509e9..a9ac5220a 100644 --- a/crates/imaging/src/ui/wide_angle/mod.rs +++ b/crates/imaging/src/ui/wide_angle/mod.rs @@ -507,7 +507,7 @@ impl FullWindowWorkspace for WideAngleWorkspace { WorkspacePass::new(shown.output.response.clone(), events).result(result) } - fn json_fields(&self) -> Option { + fn json_fields(&self, _source: &Self::Source) -> Option { let mut fields = serde_fields(&self.session)?; fields.as_object_mut()?.insert("preview".to_owned(), Value::Bool(self.preview_on)); Some(fields) diff --git a/crates/imaging/tests/it/raw_develop.rs b/crates/imaging/tests/it/raw_develop.rs index cd732da5c..35ff3d2b0 100644 --- a/crates/imaging/tests/it/raw_develop.rs +++ b/crates/imaging/tests/it/raw_develop.rs @@ -218,6 +218,22 @@ fn raw_develop_switches_raws_and_finishes_with_each_footer_button() { assert_eq!(finish(&host), Some(RawFinish::Ok)); } +#[trial] +fn a_held_ok_files_its_answer_and_keeps_the_workspace_open_until_the_app_answers() { + let host = Rc::new(RefCell::new(DialogHost::new())); + let mut fixture = fixture(&host, &Rc::new(Cell::new(false))); + host.borrow_mut().open(HostedWorkspace::new(RawDevelopWorkspace::new(open(RawTarget::OpenRaw)), Source::new()).held_ok()); + fixture.idle(10); + let done = fixture.by_label("Done").expect("Done"); + fixture.click(&done).idle(4); + let held = host.borrow_mut().get_mut::().expect("Done keeps the workspace open").take_ok(); + assert_eq!(held.map(|result| result.finish), Some(RawFinish::Done), "Done files its answer for the app"); + + host.borrow_mut().get_mut::().expect("open").answer_ok(Ok(())); + fixture.idle(4); + assert_eq!(finish(&host), Some(RawFinish::Done), "the app's answer closes the workspace with the filed result"); +} + /// The key `key` going down or up, as a keyboard reports it. fn key_event(key: Key, pressed: bool) -> Event { Event::Key { key, physical_key: Some(key), pressed, repeat: false, modifiers: Modifiers::NONE } @@ -284,7 +300,7 @@ fn readout_shown(fixture: &Fixture) -> bool { } fn scope_json(host: &Rc>) -> serde_json::Value { - let fields = host.borrow_mut().get_mut::().and_then(|hosted| hosted.workspace().json_fields()); + let fields = host.borrow_mut().get_mut::().and_then(|hosted| hosted.workspace().json_fields(&**hosted.source())); fields.and_then(|fields| fields.get("scope").cloned()).unwrap_or_default() } diff --git a/crates/ui-canvas/src/canvas/full_window/hosted.rs b/crates/ui-canvas/src/canvas/full_window/hosted.rs index 6c9a6428f..bbcc33b31 100644 --- a/crates/ui-canvas/src/canvas/full_window/hosted.rs +++ b/crates/ui-canvas/src/canvas/full_window/hosted.rs @@ -39,8 +39,10 @@ pub trait FullWindowWorkspace: Send + 'static { /// it binds to `open` ([`opened`](crate::dialog::FullWindowDialog::opened)). fn show(&mut self, ui: &mut Ui, cx: WorkspaceCx<'_, Self::Source>) -> WorkspacePass; - /// The workspace's fields as JSON for the automation surface; `None` when it has none. - fn json_fields(&self) -> Option { + /// The workspace's fields as JSON for the automation surface; `None` when it has none. `source` is what the app + /// shows the workspace, for the fields that read it (the readout under the pointer). + fn json_fields(&self, source: &Self::Source) -> Option { + let _ = source; None } @@ -321,7 +323,7 @@ impl StackDialog for HostedWorkspace { } fn json_fields(&self) -> Option { - self.workspace.json_fields() + self.workspace.json_fields(&*self.source) } fn set_json_field(&mut self, ctx: &Context, field: &str, value: serde_json::Value) -> Result<(), String> { diff --git a/crates/ui-canvas/src/canvas/full_window/stories.rs b/crates/ui-canvas/src/canvas/full_window/stories.rs index 870604803..4c52972af 100644 --- a/crates/ui-canvas/src/canvas/full_window/stories.rs +++ b/crates/ui-canvas/src/canvas/full_window/stories.rs @@ -153,7 +153,7 @@ impl FullWindowWorkspace for BrushWorkspace { WorkspacePass::new(shown.output.response, events).result(result).held(held) } - fn json_fields(&self) -> Option { + fn json_fields(&self, _source: &Self::Source) -> Option { Some(serde_json::json!({ "brush": self.brush })) }