Store file io error in app state
This commit is contained in:
parent
b36d3fafc6
commit
98e706af4a
11
src/main.rs
11
src/main.rs
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue