Improved error handling

This commit is contained in:
2025-12-28 14:38:26 -06:00
parent a48220d3d7
commit f9cb5ded06

View File

@@ -6,13 +6,12 @@ use crate::template::{self, Template};
pub struct MyEguiApp {
templates: Vec<Template>,
selected_template: Option<usize>,
error_modal: bool,
error_value: Option<anyhow_serde::Error>,
}
impl MyEguiApp {
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
MyEguiApp { templates: Vec::new(), selected_template: None, error_modal: false, error_value: None}
MyEguiApp { templates: Vec::new(), selected_template: None, error_value: None}
}
}
@@ -21,6 +20,16 @@ impl eframe::App for MyEguiApp {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("Hello, World!");
if self.error_value.is_some() {
egui::Modal::new(Id::new("Error Box")).show(ui.ctx(), |ui| {
ui.heading("An Error Has Occurred");
ui.label(format!("{:?}", self.error_value));
if ui.button("Okay").clicked() {
self.error_value = None;
}
});
}
if ui.button("Add Template").clicked() {
let file = FileDialog::new().add_filter("text", &["txt"]).set_directory("/").pick_file();
@@ -29,24 +38,12 @@ impl eframe::App for MyEguiApp {
Ok(templ) => self.templates.push(templ),
Err(e) => {
self.error_value = Some(e);
self.error_modal = true;
}
}
};
};
if self.error_modal {
egui::Modal::new(Id::new("Error Box")).show(ui.ctx(), |ui| {
ui.heading("An Error Has Occurred");
ui.label(format!("{:?}", self.error_value));
if ui.button("Okay").clicked() {
self.error_modal = false;
self.error_value = None;
}
});
}
let combo_text = match self.selected_template {
Some(num) => {&self.templates[num].get_label()}
None => "Select a template"