diff --git a/crates/imaging/src/ui/fill/mod.rs b/crates/imaging/src/ui/fill/mod.rs index 3311ebfed..973d1658f 100644 --- a/crates/imaging/src/ui/fill/mod.rs +++ b/crates/imaging/src/ui/fill/mod.rs @@ -432,7 +432,7 @@ impl ContentAwareFillWorkspace { (shown.output.result(|| work.command()), None) }; let events = std::mem::take(&mut work.events); - WorkspacePass::new(shown.output.response, events).held(held).result(result) + WorkspacePass::new(shown.output.response, events).held(held).result(result).canvas(work.canvas_id) } /// The app's colour picker answered a [`FillEvent::PickColor`] request. A key this workspace diff --git a/crates/imaging/src/ui/filter_gallery/mod.rs b/crates/imaging/src/ui/filter_gallery/mod.rs index 3cb77eea5..1452e91ed 100644 --- a/crates/imaging/src/ui/filter_gallery/mod.rs +++ b/crates/imaging/src/ui/filter_gallery/mod.rs @@ -412,11 +412,13 @@ impl FullWindowWorkspace for FilterGalleryWorkspace { if let Some(checker) = checkerboard { canvas = canvas.checkerboard(checker); } - canvas.show(ui); - (view, status) + let canvas = canvas.show(ui).response.id; + (view, status, canvas) }); // Once per pass, after the real run: the view it settled and the render status are stored. - dialog.settle(|_, (view, status)| { + let mut canvas = None; + dialog.settle(|_, (view, status, shown_canvas)| { + canvas = Some(*shown_canvas); let view = std::mem::take(view); let mut workspace = shared.borrow_mut(); workspace.status = status.clone(); @@ -433,7 +435,7 @@ impl FullWindowWorkspace for FilterGalleryWorkspace { events.push(FilterGalleryEvent::Select(workspace.selected)); } let result = dialog.output.result(|| workspace.session.clone()); - WorkspacePass::new(dialog.output.response, events).result(result) + WorkspacePass::new(dialog.output.response, events).result(result).canvas(canvas) } fn json_fields(&self, _source: &Self::Source) -> Option { diff --git a/crates/imaging/src/ui/liquify/mod.rs b/crates/imaging/src/ui/liquify/mod.rs index e8a6225b4..e6df51b2d 100644 --- a/crates/imaging/src/ui/liquify/mod.rs +++ b/crates/imaging/src/ui/liquify/mod.rs @@ -604,7 +604,7 @@ impl LiquifyWorkspace { } let result = shown.output.result(|| this.done()); let events = std::mem::take(&mut this.edit.events); - WorkspacePass::new(shown.output.response, events).result(result) + WorkspacePass::new(shown.output.response, events).result(result).canvas(this.view.canvas_id) } /// What OK applies. diff --git a/crates/imaging/src/ui/raw_develop/mod.rs b/crates/imaging/src/ui/raw_develop/mod.rs index 468e397a6..b22b00d4e 100644 --- a/crates/imaging/src/ui/raw_develop/mod.rs +++ b/crates/imaging/src/ui/raw_develop/mod.rs @@ -814,7 +814,7 @@ impl FullWindowWorkspace for RawDevelopWorkspace { (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).held(held).result(result) + WorkspacePass::new(output.response, events).held(held).result(result).canvas(self.canvas) } fn json_fields(&self, source: &Self::Source) -> Option { diff --git a/crates/imaging/src/ui/select_mask/mod.rs b/crates/imaging/src/ui/select_mask/mod.rs index d53267345..2a9dfbb9c 100644 --- a/crates/imaging/src/ui/select_mask/mod.rs +++ b/crates/imaging/src/ui/select_mask/mod.rs @@ -660,7 +660,7 @@ impl SelectMaskWorkspace { this.done(&ctx) }); let events = std::mem::take(&mut this.events); - WorkspacePass::new(shown.output.response, events).result(result) + WorkspacePass::new(shown.output.response, events).result(result).canvas(this.canvas_id) } /// The start of a pass: the first pass reads the stored settings, a change the app made to the settings since the diff --git a/crates/imaging/src/ui/vanishing_point/mod.rs b/crates/imaging/src/ui/vanishing_point/mod.rs index 56711c5f9..2d9cecc1f 100644 --- a/crates/imaging/src/ui/vanishing_point/mod.rs +++ b/crates/imaging/src/ui/vanishing_point/mod.rs @@ -371,6 +371,7 @@ impl FullWindowWorkspace for VanishingPointWorkspace { let slots = slots(); let status: RefCell>> = RefCell::new(None); let events = RefCell::new(Vec::::new()); + let shown_canvas = std::cell::Cell::new(None); let this = RefCell::new(&mut *self); let shown = FullWindowDialog::new(title) @@ -495,6 +496,7 @@ impl FullWindowWorkspace for VanishingPointWorkspace { } } state.canvas = shown.as_ref().map(|canvas| canvas.response.id); + shown_canvas.set(state.canvas); work.zoom_percent = state.view.zoom_percent(); out.extend(work.editor.take_events()); events.borrow_mut().extend(out); @@ -511,7 +513,7 @@ impl FullWindowWorkspace for VanishingPointWorkspace { } events.extend(this.editor.take_status().map(VanishingPointEvent::Refused)); let result = shown.output.result(|| this.command(source.paste().is_some())); - WorkspacePass::new(shown.output.response.clone(), events).result(result) + WorkspacePass::new(shown.output.response.clone(), events).result(result).canvas(shown_canvas.get()) } fn json_fields(&self, _source: &Self::Source) -> Option { diff --git a/crates/imaging/src/ui/wide_angle/mod.rs b/crates/imaging/src/ui/wide_angle/mod.rs index a9ac5220a..9f9ac4767 100644 --- a/crates/imaging/src/ui/wide_angle/mod.rs +++ b/crates/imaging/src/ui/wide_angle/mod.rs @@ -309,6 +309,7 @@ impl FullWindowWorkspace for WideAngleWorkspace { let preview_on = Cell::new(self.preview_on); let actions = RefCell::new(Vec::::new()); let zoom_percent = Cell::new(self.zoom_percent); + let shown_canvas = Cell::new(None); let add = Cell::new(self.add_requested); let common = env.words::(); let ctx = ui.ctx().clone(); @@ -406,6 +407,7 @@ impl FullWindowWorkspace for WideAngleWorkspace { let out = canvas.show(ui); zoom_percent.set(view.zoom_percent()); body.canvas = Some(out.response.id); + shown_canvas.set(body.canvas); let mut queued = actions.borrow_mut(); queued.extend(body.constraint.take_edits().into_iter().map(Action::Constraint)); @@ -504,7 +506,7 @@ impl FullWindowWorkspace for WideAngleWorkspace { } } let result = shown.output.result(|| self.session.clone()); - WorkspacePass::new(shown.output.response.clone(), events).result(result) + WorkspacePass::new(shown.output.response.clone(), events).result(result).canvas(shown_canvas.get()) } fn json_fields(&self, _source: &Self::Source) -> Option { diff --git a/crates/ui-canvas/src/canvas/full_window/hosted.rs b/crates/ui-canvas/src/canvas/full_window/hosted.rs index bbcc33b31..54bd5d747 100644 --- a/crates/ui-canvas/src/canvas/full_window/hosted.rs +++ b/crates/ui-canvas/src/canvas/full_window/hosted.rs @@ -109,12 +109,15 @@ pub struct WorkspacePass { /// The result OK would give, reported in the pass the Accept button is picked under `cx.hold_ok`; `result` /// stays `None` then. pub held: Option, + /// The canvas the workspace showed its image on this pass (the id of its `FullWindowCanvas`'s response, which + /// keys the canvas's tool host): where the app's tool input in document points goes while the workspace is open. + pub canvas: Option, } impl WorkspacePass { /// A pass with `events` that leaves the workspace open. pub fn new(response: Response, events: Vec) -> Self { - WorkspacePass { response, events, result: None, held: None } + WorkspacePass { response, events, result: None, held: None, canvas: None } } /// The result a held OK gives this pass. @@ -130,6 +133,13 @@ impl WorkspacePass { self.result = result; self } + + /// The canvas the workspace showed its image on this pass; `None` for a pass that showed none (a measuring run). + #[must_use] + pub fn canvas(mut self, canvas: Option) -> Self { + self.canvas = canvas; + self + } } /// A [`FullWindowWorkspace`] the [`DialogHost`](crate::dialog::DialogHost) owns, with the app's source. It keeps the @@ -172,6 +182,8 @@ pub struct HostedWorkspace { /// The held OK's answer until the app answers it (the workspace disables its OK meanwhile), and why the app /// refused the last one, until OK files again. held: HeldAnswer, + /// The canvas the workspace shows its image on, as its latest pass that showed one reported it. + canvas: Option, #[cfg(feature = "testing")] facts: crate::testing::StoryOutput, } @@ -188,6 +200,7 @@ impl HostedWorkspace { revision: 0, hold_ok: false, held: HeldAnswer::new(), + canvas: None, #[cfg(feature = "testing")] facts: crate::testing::StoryOutput::default(), } @@ -273,6 +286,9 @@ impl StackDialog for HostedWorkspace { ok_waits: self.held.is_waiting(), }; let pass = self.workspace.show(ui, cx); + if pass.canvas.is_some() { + self.canvas = pass.canvas; + } #[cfg(feature = "testing")] { self.facts = crate::contract::Outcome::story_facts(&pass.response); @@ -293,6 +309,10 @@ impl StackDialog for HostedWorkspace { Some(W::KEY) } + fn canvas(&self) -> Option { + self.canvas + } + /// OK as the Accept button: a held workspace files the result and answers none, and answers the held result once /// the app accepted it. fn confirm(&mut self, ctx: &Context) -> Option { diff --git a/crates/ui-panels/src/dialog/host.rs b/crates/ui-panels/src/dialog/host.rs index 63f24e63b..f3aaba9e0 100644 --- a/crates/ui-panels/src/dialog/host.rs +++ b/crates/ui-panels/src/dialog/host.rs @@ -82,6 +82,12 @@ pub trait StackDialog: Any + Send { None } + /// The canvas the dialog shows the document on, which takes the app's tool input in document points while the + /// dialog is open: a full-window workspace's. `None` (the default) for a dialog without one. + fn canvas(&self) -> Option { + None + } + /// The dialog's values as a JSON object, keyed as [`set_json_field`](StackDialog::set_json_field) takes them: /// what automation lists for the open dialog (`ui.inspect`). `None` (the default) for a dialog without values. fn json_fields(&self) -> Option { @@ -183,6 +189,7 @@ trait AnyStackDialog: Send { fn instance(&self) -> Option; fn confirm_erased(&mut self, ctx: &Context) -> Option>; fn held_state(&self) -> Option; + fn canvas(&self) -> Option; fn json_fields(&self) -> Option; fn set_json_field(&mut self, ctx: &Context, field: &str, value: Value) -> Result<(), String>; fn show_erased(&mut self, ui: &mut Ui, stack: &DialogStack) -> Option>; @@ -220,6 +227,10 @@ impl AnyStackDialog for D { StackDialog::held_state(self) } + fn canvas(&self) -> Option { + StackDialog::canvas(self) + } + fn json_fields(&self) -> Option { StackDialog::json_fields(self) } @@ -471,6 +482,12 @@ impl DialogHost { self.open.iter().find(|dialog| dialog.id() == id)?.held_state() } + /// The canvas of the most recently opened dialog that shows the document on one ([`StackDialog::canvas`]): where + /// the app's tool input in document points goes while it is open. `None` when no open dialog has one. + pub fn canvas(&self) -> Option { + self.open.iter().rev().find_map(|dialog| dialog.canvas()) + } + /// [`confirm`](DialogHost::confirm) for the open dialog `id` names, whatever its type. pub fn confirm_by_id(&mut self, ctx: &Context, id: DialogId) -> bool { match self.position_by_id(id) {