Improved error handling
This commit is contained in:
25
src/app.rs
25
src/app.rs
@@ -6,13 +6,12 @@ use crate::template::{self, Template};
|
|||||||
pub struct MyEguiApp {
|
pub struct MyEguiApp {
|
||||||
templates: Vec<Template>,
|
templates: Vec<Template>,
|
||||||
selected_template: Option<usize>,
|
selected_template: Option<usize>,
|
||||||
error_modal: bool,
|
|
||||||
error_value: Option<anyhow_serde::Error>,
|
error_value: Option<anyhow_serde::Error>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MyEguiApp {
|
impl MyEguiApp {
|
||||||
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
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| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
ui.heading("Hello, World!");
|
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() {
|
if ui.button("Add Template").clicked() {
|
||||||
let file = FileDialog::new().add_filter("text", &["txt"]).set_directory("/").pick_file();
|
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),
|
Ok(templ) => self.templates.push(templ),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.error_value = Some(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 {
|
let combo_text = match self.selected_template {
|
||||||
Some(num) => {&self.templates[num].get_label()}
|
Some(num) => {&self.templates[num].get_label()}
|
||||||
None => "Select a template"
|
None => "Select a template"
|
||||||
|
|||||||
Reference in New Issue
Block a user