mirror of https://codeberg.org/topola/topola.git
egui: Implement saving command file
This commit is contained in:
parent
fb501ac072
commit
02bfe1105b
|
|
@ -26,6 +26,7 @@ geo = "0.25.1"
|
|||
rstar = "0.11.0"
|
||||
petgraph = "0.6.3"
|
||||
spade = "2.2.0"
|
||||
serde_json = "1.0.117"
|
||||
enum_dispatch = "0.3.12"
|
||||
itertools = "0.8.2"
|
||||
contracts = "0.6.3"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::autorouter::invoker::Command;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct History {
|
||||
done: Vec<Command>,
|
||||
undone: Vec<Command>,
|
||||
|
|
|
|||
|
|
@ -62,10 +62,9 @@ impl<R: RulesTrait> Invoker<R> {
|
|||
|
||||
pub fn undo(&mut self) {
|
||||
let command = self.history.done().last().unwrap();
|
||||
let mut execute = self.dispatch_command(command);
|
||||
|
||||
while execute.next(self, &mut EmptyRouterObserver) {
|
||||
//
|
||||
match command {
|
||||
Command::Autoroute(ref selection) => self.autorouter.undo_autoroute(selection),
|
||||
}
|
||||
|
||||
self.history.undo();
|
||||
|
|
@ -85,4 +84,8 @@ impl<R: RulesTrait> Invoker<R> {
|
|||
pub fn autorouter(&self) -> &Autorouter<R> {
|
||||
&self.autorouter
|
||||
}
|
||||
|
||||
pub fn history(&self) -> &History {
|
||||
&self.history
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use futures::executor;
|
|||
use geo::point;
|
||||
use petgraph::visit::{EdgeRef, IntoEdgeReferences};
|
||||
use std::{
|
||||
fs::File,
|
||||
future::Future,
|
||||
sync::{
|
||||
mpsc::{channel, Receiver, Sender},
|
||||
|
|
@ -187,15 +188,34 @@ impl eframe::App for App {
|
|||
let task = rfd::AsyncFileDialog::new().pick_file();
|
||||
|
||||
execute(async move {
|
||||
let maybe_file_handle = task.await;
|
||||
|
||||
if let Some(file_handle) = maybe_file_handle {
|
||||
let _ = sender.send(channel_text(file_handle).await);
|
||||
if let Some(file_handle) = task.await {
|
||||
sender.send(channel_text(file_handle).await);
|
||||
ctx.request_repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
if ui.button("Save history").clicked() {
|
||||
if let Some(invoker_arc_mutex) = &self.invoker {
|
||||
let invoker_arc_mutex = invoker_arc_mutex.clone();
|
||||
let ctx = ui.ctx().clone();
|
||||
let task = rfd::AsyncFileDialog::new().save_file();
|
||||
|
||||
execute(async move {
|
||||
if let Some(file_handle) = task.await {
|
||||
let path = file_handle.path();
|
||||
let mut file = File::create(path).unwrap();
|
||||
let mut invoker = invoker_arc_mutex.lock().unwrap();
|
||||
serde_json::to_writer(file, invoker.history());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
// "Quit" button wouldn't work on a Web page.
|
||||
if !cfg!(target_arch = "wasm32") {
|
||||
if ui.button("Quit").clicked() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue