Use window::run in editor example
This commit is contained in:
parent
bbba0942f8
commit
c9830b4a9b
4 changed files with 315 additions and 470 deletions
757
Cargo.lock
generated
757
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -12,4 +12,4 @@ iced.features = ["highlighter", "tokio", "debug"]
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
tokio.features = ["fs"]
|
tokio.features = ["fs"]
|
||||||
|
|
||||||
rfd = "0.13"
|
rfd.workspace = true
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ use iced::widget::{
|
||||||
button, center_x, column, container, operation, pick_list, row, space,
|
button, center_x, column, container, operation, pick_list, row, space,
|
||||||
text, text_editor, toggler, tooltip,
|
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::ffi;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
@ -97,7 +98,10 @@ impl Editor {
|
||||||
} else {
|
} else {
|
||||||
self.is_loading = true;
|
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) => {
|
Message::FileOpened(result) => {
|
||||||
|
|
@ -246,14 +250,19 @@ pub enum Error {
|
||||||
IoError(io::ErrorKind),
|
IoError(io::ErrorKind),
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn open_file() -> Result<(PathBuf, Arc<String>), Error> {
|
fn open_file(
|
||||||
let picked_file = rfd::AsyncFileDialog::new()
|
window: &dyn Window,
|
||||||
|
) -> impl Future<Output = Result<(PathBuf, Arc<String>), Error>> + use<> {
|
||||||
|
let dialog = rfd::AsyncFileDialog::new()
|
||||||
.set_title("Open a text file...")
|
.set_title("Open a text file...")
|
||||||
.pick_file()
|
.set_parent(&window);
|
||||||
.await
|
|
||||||
.ok_or(Error::DialogClosed)?;
|
|
||||||
|
|
||||||
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(
|
async fn load_file(
|
||||||
|
|
|
||||||
|
|
@ -647,6 +647,7 @@ pub use font::Font;
|
||||||
pub use program::Program;
|
pub use program::Program;
|
||||||
pub use renderer::Renderer;
|
pub use renderer::Renderer;
|
||||||
pub use task::Task;
|
pub use task::Task;
|
||||||
|
pub use window::Window;
|
||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use application::application;
|
pub use application::application;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue