mirror of https://codeberg.org/topola/topola.git
refactor(egui): wrap `Invoker<...>` inside new `ActivityContext`
This commit is contained in:
parent
8b9d4074e4
commit
a9b72334f7
|
|
@ -15,18 +15,16 @@ use topola::{
|
|||
stepper::{Abort, Step},
|
||||
};
|
||||
|
||||
pub struct ActivityContext<'a> {
|
||||
pub invoker: &'a mut Invoker<SpecctraMesadata>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ActivityStatus {
|
||||
Running,
|
||||
Finished(String),
|
||||
}
|
||||
|
||||
#[derive(Error, Debug, Clone)]
|
||||
pub enum ActivityError {
|
||||
#[error(transparent)]
|
||||
Invoker(#[from] InvokerError),
|
||||
}
|
||||
|
||||
impl From<InvokerStatus> for ActivityStatus {
|
||||
fn from(status: InvokerStatus) -> Self {
|
||||
match status {
|
||||
|
|
@ -46,26 +44,29 @@ impl TryInto<()> for ActivityStatus {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Error, Debug, Clone)]
|
||||
pub enum ActivityError {
|
||||
#[error(transparent)]
|
||||
Invoker(#[from] InvokerError),
|
||||
}
|
||||
|
||||
pub enum ActivityStepper {
|
||||
// There will be another variant for interactive activities here soon. (TODO)
|
||||
Execution(ExecutionStepper),
|
||||
}
|
||||
|
||||
impl Step<Invoker<SpecctraMesadata>, ActivityStatus, ActivityError, ()> for ActivityStepper {
|
||||
fn step(
|
||||
&mut self,
|
||||
invoker: &mut Invoker<SpecctraMesadata>,
|
||||
) -> Result<ActivityStatus, ActivityError> {
|
||||
impl Step<ActivityContext<'_>, ActivityStatus, ActivityError, ()> for ActivityStepper {
|
||||
fn step(&mut self, context: &mut ActivityContext) -> Result<ActivityStatus, ActivityError> {
|
||||
match self {
|
||||
ActivityStepper::Execution(execution) => Ok(execution.step(invoker)?.into()),
|
||||
ActivityStepper::Execution(execution) => Ok(execution.step(context.invoker)?.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Abort<Invoker<SpecctraMesadata>> for ActivityStepper {
|
||||
fn abort(&mut self, invoker: &mut Invoker<SpecctraMesadata>) {
|
||||
impl Abort<ActivityContext<'_>> for ActivityStepper {
|
||||
fn abort(&mut self, context: &mut ActivityContext) {
|
||||
match self {
|
||||
ActivityStepper::Execution(execution) => execution.finish(invoker), // TODO.
|
||||
ActivityStepper::Execution(execution) => execution.finish(context.invoker), // TODO.
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -124,23 +125,18 @@ impl ActivityStepperWithStatus {
|
|||
}
|
||||
}
|
||||
|
||||
impl Step<Invoker<SpecctraMesadata>, ActivityStatus, ActivityError, ()>
|
||||
for ActivityStepperWithStatus
|
||||
{
|
||||
fn step(
|
||||
&mut self,
|
||||
invoker: &mut Invoker<SpecctraMesadata>,
|
||||
) -> Result<ActivityStatus, ActivityError> {
|
||||
let status = self.activity.step(invoker)?;
|
||||
impl Step<ActivityContext<'_>, ActivityStatus, ActivityError, ()> for ActivityStepperWithStatus {
|
||||
fn step(&mut self, context: &mut ActivityContext) -> Result<ActivityStatus, ActivityError> {
|
||||
let status = self.activity.step(context)?;
|
||||
self.maybe_status = Some(status.clone());
|
||||
Ok(status.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Abort<Invoker<SpecctraMesadata>> for ActivityStepperWithStatus {
|
||||
fn abort(&mut self, invoker: &mut Invoker<SpecctraMesadata>) {
|
||||
impl Abort<ActivityContext<'_>> for ActivityStepperWithStatus {
|
||||
fn abort(&mut self, context: &mut ActivityContext) {
|
||||
self.maybe_status = Some(ActivityStatus::Finished(String::from("aborted")));
|
||||
self.activity.abort(invoker);
|
||||
self.activity.abort(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use topola::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
activity::{ActivityStatus, ActivityStepperWithStatus},
|
||||
activity::{ActivityContext, ActivityStatus, ActivityStepperWithStatus},
|
||||
config::Config,
|
||||
error_dialog::ErrorDialog,
|
||||
layers::Layers,
|
||||
|
|
@ -170,7 +170,7 @@ impl App {
|
|||
}
|
||||
|
||||
if let Some(ref mut activity) = self.maybe_activity {
|
||||
return match activity.step(invoker) {
|
||||
return match activity.step(&mut ActivityContext { invoker }) {
|
||||
Ok(ActivityStatus::Running) => true,
|
||||
Ok(ActivityStatus::Finished(..)) => false,
|
||||
Err(err) => {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ use topola::{
|
|||
|
||||
use crate::{
|
||||
action::{Action, Switch, Trigger},
|
||||
activity::{ActivityStatus, ActivityStepperWithStatus},
|
||||
activity::{ActivityContext, ActivityStatus, ActivityStepperWithStatus},
|
||||
app::{execute, handle_file},
|
||||
overlay::Overlay,
|
||||
translator::Translator,
|
||||
|
|
@ -331,7 +331,7 @@ impl MenuBar {
|
|||
} else if abort.consume_key_triggered(ctx, ui) {
|
||||
if let Some(activity) = maybe_activity {
|
||||
if let Some(invoker) = arc_mutex_maybe_invoker.lock().unwrap().as_mut() {
|
||||
activity.abort(invoker);
|
||||
activity.abort(&mut ActivityContext { invoker });
|
||||
}
|
||||
}
|
||||
} else if remove_bands.consume_key_triggered(ctx, ui) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue