Use window::run in editor example
This commit is contained in:
parent
bbba0942f8
commit
c9830b4a9b
4 changed files with 315 additions and 470 deletions
|
|
@ -4,7 +4,8 @@ use iced::widget::{
|
|||
button, center_x, column, container, operation, pick_list, row, space,
|
||||
text, text_editor, toggler, tooltip,
|
||||
};
|
||||
use iced::{Center, Element, Fill, Font, Task, Theme};
|
||||
use iced::window;
|
||||
use iced::{Center, Element, Fill, Font, Task, Theme, Window};
|
||||
|
||||
use std::ffi;
|
||||
use std::io;
|
||||
|
|
@ -97,7 +98,10 @@ impl Editor {
|
|||
} else {
|
||||
self.is_loading = true;
|
||||
|
||||
Task::perform(open_file(), Message::FileOpened)
|
||||
window::oldest()
|
||||
.and_then(|id| window::run(id, open_file))
|
||||
.then(Task::future)
|
||||
.map(Message::FileOpened)
|
||||
}
|
||||
}
|
||||
Message::FileOpened(result) => {
|
||||
|
|
@ -246,14 +250,19 @@ pub enum Error {
|
|||
IoError(io::ErrorKind),
|
||||
}
|
||||
|
||||
async fn open_file() -> Result<(PathBuf, Arc<String>), Error> {
|
||||
let picked_file = rfd::AsyncFileDialog::new()
|
||||
fn open_file(
|
||||
window: &dyn Window,
|
||||
) -> impl Future<Output = Result<(PathBuf, Arc<String>), Error>> + use<> {
|
||||
let dialog = rfd::AsyncFileDialog::new()
|
||||
.set_title("Open a text file...")
|
||||
.pick_file()
|
||||
.await
|
||||
.ok_or(Error::DialogClosed)?;
|
||||
.set_parent(&window);
|
||||
|
||||
load_file(picked_file).await
|
||||
async move {
|
||||
let picked_file =
|
||||
dialog.pick_file().await.ok_or(Error::DialogClosed)?;
|
||||
|
||||
load_file(picked_file).await
|
||||
}
|
||||
}
|
||||
|
||||
async fn load_file(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue