Store file io error in app state

This commit is contained in:
Jarrod Doyle 2024-01-21 18:58:45 +00:00
parent b36d3fafc6
commit 98e706af4a
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 6 additions and 5 deletions

View File

@ -14,6 +14,7 @@ enum Message {
struct BookManagerApp { struct BookManagerApp {
book_content: text_editor::Content, book_content: text_editor::Content,
io_error: Option<io::ErrorKind>,
} }
impl Application for BookManagerApp { impl Application for BookManagerApp {
@ -26,6 +27,7 @@ impl Application for BookManagerApp {
( (
Self { Self {
book_content: text_editor::Content::new(), book_content: text_editor::Content::new(),
io_error: None,
}, },
Command::perform( Command::perform(
load_file(format!("{}/src/main.rs", env!("CARGO_MANIFEST_DIR"))), load_file(format!("{}/src/main.rs", env!("CARGO_MANIFEST_DIR"))),
@ -41,11 +43,10 @@ impl Application for BookManagerApp {
fn update(&mut self, message: Self::Message) -> Command<Self::Message> { fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
match message { match message {
Message::Edit(action) => self.book_content.perform(action), Message::Edit(action) => self.book_content.perform(action),
Message::FileOpened(result) => { Message::FileOpened(result) => match result {
if let Ok(content) = result { Ok(content) => self.book_content = text_editor::Content::with_text(&content),
self.book_content = text_editor::Content::with_text(&content); Err(error) => self.io_error = Some(error),
} },
}
} }
Command::none() Command::none()