Prompt for paths asynchronously to avoid double borrow

This commit is contained in:
Antonio Scandurra
2021-04-14 16:30:03 +02:00
parent 29d2236ed2
commit cf23b0e4a2
7 changed files with 70 additions and 35 deletions
+17 -1
View File
@@ -5,7 +5,7 @@ use crate::{
platform::{self, WindowOptions},
presenter::Presenter,
util::post_inc,
AssetCache, AssetSource, ClipboardItem, FontCache, TextLayoutCache,
AssetCache, AssetSource, ClipboardItem, FontCache, PathPromptOptions, TextLayoutCache,
};
use anyhow::{anyhow, Result};
use async_std::sync::Condvar;
@@ -570,6 +570,22 @@ impl MutableAppContext {
self.platform.set_menus(menus);
}
pub fn prompt_for_paths<F>(&self, options: PathPromptOptions, done_fn: F)
where
F: 'static + FnOnce(Option<Vec<PathBuf>>, &mut MutableAppContext),
{
let app = self.weak_self.as_ref().unwrap().upgrade().unwrap();
let foreground = self.foreground.clone();
self.platform().prompt_for_paths(
options,
Box::new(move |paths| {
foreground
.spawn(async move { (done_fn)(paths, &mut *app.borrow_mut()) })
.detach();
}),
);
}
pub fn dispatch_action<T: 'static + Any>(
&mut self,
window_id: usize,