Compare commits

..

2 commits

Author SHA1 Message Date
Florent DENEF
542923ccef Saving file and dealing with all errors. 2022-11-30 13:32:44 +01:00
Florent DENEF
9ed44a9a68 Removing a blank line. 2022-11-30 13:32:18 +01:00
2 changed files with 14 additions and 10 deletions

View file

@ -1,4 +1,5 @@
use eframe::egui; use eframe::egui;
use std::io::Write as _;
use billy_sheet::gui::SheetGui; use billy_sheet::gui::SheetGui;
@ -40,16 +41,20 @@ impl eframe::App for Gui {
_frame.close(); _frame.close();
} }
if ui.button("Save in json").clicked() { if ui.button("Save in json").clicked() {
let sheet_str = serde_json::to_string(&self.sheet); let result = serde_json::to_string_pretty(&self.sheet);
match result {
Ok(sheet_str) => {
let path = std::path::Path::new("./sheet.json"); let path = std::path::Path::new("./sheet.json");
if path.exists() { match std::fs::File::create(path) {
if let Err(a) = std::fs::remove_file(path) { Ok(mut file) => {
println!("{a}"); if let Err(err) = write!(file, "{}", sheet_str) {
} else { println!("{err}");
} }
} else { }
Err(error) => println!("{error}"),
}
}
Err(error) => println!("{error}"),
} }
} }
}); });

View file

@ -2,7 +2,6 @@ use eframe::egui::widgets::DragValue;
use eframe::egui::Ui; use eframe::egui::Ui;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::gui::SheetGui; use crate::gui::SheetGui;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]