mirror of https://codeberg.org/topola/topola.git
egui/MenuBar: reduce code duplication for Workspace Activities
This commit is contained in:
parent
d03e5c63a0
commit
49f4063ac4
|
|
@ -1,7 +1,9 @@
|
||||||
use std::{path::Path, sync::mpsc::Sender};
|
use std::{path::Path, sync::mpsc::Sender};
|
||||||
|
|
||||||
use topola::{
|
use topola::{
|
||||||
autorouter::{execution::Command, invoker::InvokerError, AutorouterOptions},
|
autorouter::{
|
||||||
|
execution::Command, invoker::InvokerError, selection::Selection, AutorouterOptions,
|
||||||
|
},
|
||||||
router::RouterOptions,
|
router::RouterOptions,
|
||||||
specctra::design::{LoadingError as SpecctraLoadingError, SpecctraDesign},
|
specctra::design::{LoadingError as SpecctraLoadingError, SpecctraDesign},
|
||||||
stepper::Abort,
|
stepper::Abort,
|
||||||
|
|
@ -314,56 +316,36 @@ impl MenuBar {
|
||||||
invoker: &mut workspace.invoker,
|
invoker: &mut workspace.invoker,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if remove_bands.consume_key_triggered(ctx, ui) {
|
|
||||||
if workspace.maybe_activity.as_mut().map_or(true, |activity| {
|
|
||||||
matches!(activity.maybe_status(), Some(ActivityStatus::Finished(..)))
|
|
||||||
}) {
|
|
||||||
let selection = workspace.overlay.take_selection();
|
|
||||||
workspace.maybe_activity =
|
|
||||||
Some(ActivityStepperWithStatus::new_execution(
|
|
||||||
workspace.invoker.execute_stepper(Command::RemoveBands(
|
|
||||||
selection.band_selection,
|
|
||||||
))?,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} else if place_via.consume_key_enabled(ctx, ui, &mut self.is_placing_via) {
|
} else if place_via.consume_key_enabled(ctx, ui, &mut self.is_placing_via) {
|
||||||
|
} else if workspace.maybe_activity.as_mut().map_or(true, |activity| {
|
||||||
|
matches!(activity.maybe_status(), Some(ActivityStatus::Finished(..)))
|
||||||
|
}) {
|
||||||
|
let mut schedule = |op: fn(Selection, AutorouterOptions) -> Command| {
|
||||||
|
let selection = workspace.overlay.take_selection();
|
||||||
|
workspace.maybe_activity =
|
||||||
|
Some(ActivityStepperWithStatus::new_execution(
|
||||||
|
workspace
|
||||||
|
.invoker
|
||||||
|
.execute_stepper(op(selection, self.autorouter_options))?,
|
||||||
|
));
|
||||||
|
Ok::<(), InvokerError>(())
|
||||||
|
};
|
||||||
|
if remove_bands.consume_key_triggered(ctx, ui) {
|
||||||
|
schedule(|selection, _| {
|
||||||
|
Command::RemoveBands(selection.band_selection)
|
||||||
|
})?;
|
||||||
} else if autoroute.consume_key_triggered(ctx, ui) {
|
} else if autoroute.consume_key_triggered(ctx, ui) {
|
||||||
if workspace.maybe_activity.as_mut().map_or(true, |activity| {
|
schedule(|selection, opts| {
|
||||||
matches!(activity.maybe_status(), Some(ActivityStatus::Finished(..)))
|
Command::Autoroute(selection.pin_selection, opts)
|
||||||
}) {
|
})?;
|
||||||
let selection = workspace.overlay.take_selection();
|
|
||||||
workspace.maybe_activity =
|
|
||||||
Some(ActivityStepperWithStatus::new_execution(
|
|
||||||
workspace.invoker.execute_stepper(Command::Autoroute(
|
|
||||||
selection.pin_selection,
|
|
||||||
self.autorouter_options,
|
|
||||||
))?,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} else if compare_detours.consume_key_triggered(ctx, ui) {
|
} else if compare_detours.consume_key_triggered(ctx, ui) {
|
||||||
if workspace.maybe_activity.as_mut().map_or(true, |activity| {
|
schedule(|selection, opts| {
|
||||||
matches!(activity.maybe_status(), Some(ActivityStatus::Finished(..)))
|
Command::CompareDetours(selection.pin_selection, opts)
|
||||||
}) {
|
})?;
|
||||||
let selection = workspace.overlay.take_selection();
|
|
||||||
workspace.maybe_activity =
|
|
||||||
Some(ActivityStepperWithStatus::new_execution(
|
|
||||||
workspace.invoker.execute_stepper(Command::CompareDetours(
|
|
||||||
selection.pin_selection,
|
|
||||||
self.autorouter_options,
|
|
||||||
))?,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} else if measure_length.consume_key_triggered(ctx, ui) {
|
} else if measure_length.consume_key_triggered(ctx, ui) {
|
||||||
if workspace.maybe_activity.as_mut().map_or(true, |activity| {
|
schedule(|selection, _| {
|
||||||
matches!(activity.maybe_status(), Some(ActivityStatus::Finished(..)))
|
Command::MeasureLength(selection.band_selection)
|
||||||
}) {
|
})?;
|
||||||
let selection = workspace.overlay.take_selection();
|
|
||||||
workspace.maybe_activity =
|
|
||||||
Some(ActivityStepperWithStatus::new_execution(
|
|
||||||
workspace.invoker.execute_stepper(Command::MeasureLength(
|
|
||||||
selection.band_selection,
|
|
||||||
))?,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue