From 3766ade270e79e024289a7be2cbd7016cd89d5de Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Fri, 11 Oct 2024 03:20:36 +0200 Subject: [PATCH] refactor(egui): report invoker error one outside of `Interactor` --- src/bin/topola-egui/interactor.rs | 11 +++++------ src/bin/topola-egui/workspace.rs | 9 ++++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/bin/topola-egui/interactor.rs b/src/bin/topola-egui/interactor.rs index 1df9c38..25f41df 100644 --- a/src/bin/topola-egui/interactor.rs +++ b/src/bin/topola-egui/interactor.rs @@ -13,7 +13,7 @@ use topola::{ }; use crate::{ - activity::{ActivityContext, ActivityStatus, ActivityStepperWithStatus}, + activity::{ActivityContext, ActivityError, ActivityStatus, ActivityStepperWithStatus}, interaction::InteractionContext, }; @@ -62,22 +62,21 @@ impl Interactor { self.invoker.replay(history); } - pub fn update(&mut self) -> ControlFlow<()> { + pub fn update(&mut self) -> ControlFlow> { if let Some(ref mut activity) = self.activity { return match activity.step(&mut ActivityContext { interaction: InteractionContext {}, invoker: &mut self.invoker, }) { Ok(ActivityStatus::Running) => ControlFlow::Continue(()), - Ok(ActivityStatus::Finished(..)) => ControlFlow::Break(()), + Ok(ActivityStatus::Finished(..)) => ControlFlow::Break(Ok(())), Err(err) => { - //error_dialog.push_error("tr-module-invoker", format!("{}", err)); self.activity = None; - ControlFlow::Break(()) + ControlFlow::Break(Err(err)) } }; } - ControlFlow::Break(()) + ControlFlow::Break(Ok(())) } pub fn invoker(&self) -> &Invoker { diff --git a/src/bin/topola-egui/workspace.rs b/src/bin/topola-egui/workspace.rs index 3ac16ed..b0b5fe6 100644 --- a/src/bin/topola-egui/workspace.rs +++ b/src/bin/topola-egui/workspace.rs @@ -87,7 +87,14 @@ impl Workspace { } } - self.interactor.update() + match self.interactor.update() { + ControlFlow::Continue(()) => ControlFlow::Continue(()), + ControlFlow::Break(Ok(())) => ControlFlow::Break(()), + ControlFlow::Break(Err(err)) => { + error_dialog.push_error("tr-module-invoker", format!("{}", err)); + ControlFlow::Break(()) + } + } } pub fn update_layers(&mut self, ctx: &egui::Context) {