mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Merge pull request #10269 from dotCooCoo/fix/issue-6160
Open: say when a file dialog is already open instead of waiting silently
This commit is contained in:
4 files changed
+63
-6
No files matched your search
@@ -73,15 +73,20 @@ pub(super) fn home(app: &mut VectorcraftApp, ui: &mut Ui, rect: egui::Rect) {
|
||||
}
|
||||
}
|
||||
|
||||
/// What the start screen's user did.
|
||||
/// What the start screen's user did. A command that fails says why in the status bar (#6160).
|
||||
fn run_action(app: &mut VectorcraftApp, action: StartAction) {
|
||||
fn run(app: &mut VectorcraftApp, id: &str, params: serde_json::Value) {
|
||||
if let Err(e) = app.run(id, params) {
|
||||
app.status(e);
|
||||
}
|
||||
}
|
||||
match action {
|
||||
StartAction::New => drop(app.run("file.newDialog", json!({}))),
|
||||
StartAction::Open => drop(app.run("file.open", json!({}))),
|
||||
StartAction::New => run(app, "file.newDialog", json!({})),
|
||||
StartAction::Open => run(app, "file.open", json!({})),
|
||||
// A failure is reported to the user there.
|
||||
StartAction::OpenRecent(path) => drop(crate::io::open_reporting(app, &path.to_string_lossy())),
|
||||
StartAction::UseTemplate(name) => drop(app.run("file.new", json!({ "preset": name }))),
|
||||
StartAction::ClearRecent => drop(app.run("file.clearRecent", json!({}))),
|
||||
StartAction::UseTemplate(name) => run(app, "file.new", json!({ "preset": name })),
|
||||
StartAction::ClearRecent => run(app, "file.clearRecent", json!({})),
|
||||
StartAction::RemoveRecent(path) => app.ui.recent_files.retain(|recent| std::path::Path::new(recent) != path),
|
||||
StartAction::RevealRecent(path) => {
|
||||
// PLAN: `io::export` is a private module of `io`; `reveal_path` needs a re-export from io.rs (unowned).
|
||||
|
||||
@@ -233,13 +233,19 @@ fn open_request<'a>(purpose: &str, folder: Option<String>, filters: impl IntoIte
|
||||
|
||||
/// Asks for a file to open with `request`; `then` gets its path. The web answers with the file's
|
||||
/// bytes, which open as File › Open opens them (the extension decides). A cancelled picker runs
|
||||
/// nothing. While it is open the reply is `{pending: "fileDialog"}`.
|
||||
/// nothing, and a picker that failed (the browser could not read the file) reports why. While it is
|
||||
/// open the reply is `{pending: "fileDialog"}`. While another file dialog is still open, which can
|
||||
/// be a window the system placed out of sight, the reply is an error saying so (#6160): a second
|
||||
/// picker would only wait behind the first.
|
||||
fn ask_open(
|
||||
app: &mut VectorcraftApp,
|
||||
request: PickRequest,
|
||||
owner: Owner,
|
||||
then: impl FnOnce(&mut VectorcraftApp, String) -> Result<Value, String> + 'static,
|
||||
) -> Result<Value, String> {
|
||||
if app.file_dialog_open() {
|
||||
return Err(file_asks::busy().into());
|
||||
}
|
||||
Ok(file_asks::ask(app, request, owner, move |app, picked| match picked {
|
||||
Picked::Contents(files) => {
|
||||
for (name, bytes) in &files {
|
||||
@@ -247,6 +253,7 @@ fn ask_open(
|
||||
}
|
||||
Ok(Value::Null)
|
||||
}
|
||||
Picked::Failed(error) => Err(error),
|
||||
picked => match picked.first_path() {
|
||||
Some(path) => then(app, path.to_string_lossy().into_owned()),
|
||||
None => Err("cancelled".into()),
|
||||
|
||||
@@ -125,6 +125,26 @@ fn home_screen(app: VectorcraftApp) -> Panel {
|
||||
home
|
||||
}
|
||||
|
||||
/// Home's Open while a file dialog is still open (a window the system may have placed out of sight)
|
||||
/// says so in the status bar and asks for no second picker; once the first answers, Open asks again
|
||||
/// (#6160).
|
||||
#[test]
|
||||
fn home_open_while_a_file_dialog_is_open_says_so() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
|
||||
let picker = crate::tests::picks::scripted(&mut app);
|
||||
let mut home = home_screen(app);
|
||||
home.click("Open");
|
||||
assert_eq!(picker.requests().len(), 1);
|
||||
assert!(home.app().ui.status.is_empty());
|
||||
home.click("Open");
|
||||
assert_eq!(picker.requests().len(), 1, "no second picker waits behind the first");
|
||||
assert_eq!(home.app().ui.status, crate::file_asks::busy());
|
||||
picker.cancel();
|
||||
crate::file_asks::poll(&mut home.app());
|
||||
home.click("Open");
|
||||
assert_eq!(picker.requests().len(), 2, "Open asks again once the first dialog answered");
|
||||
}
|
||||
|
||||
/// The Home screen lists the first recent files (#663); opening one that can't be opened says so.
|
||||
#[test]
|
||||
fn home_lists_recent_files_and_a_click_opens_one() {
|
||||
|
||||
@@ -49,6 +49,10 @@ impl Picker {
|
||||
pub(crate) fn cancel(&self) {
|
||||
self.files.answer(Picked::Cancelled);
|
||||
}
|
||||
/// The newest open pick fails with `why`, as the browser's picker does when it cannot read the file.
|
||||
pub(crate) fn fail(&self, why: &str) {
|
||||
self.files.answer(Picked::Failed(why.into()));
|
||||
}
|
||||
/// The bytes a save through the service (`Files::save`) wrote to `path`.
|
||||
pub(crate) fn file(&self, path: &str) -> Option<Vec<u8>> {
|
||||
self.files.file(std::path::Path::new(path))
|
||||
@@ -197,6 +201,27 @@ fn app() -> VectorcraftApp {
|
||||
VectorcraftApp::new(Session::new(), Services::default())
|
||||
}
|
||||
|
||||
/// File › Open and Install Plug-in ask for no second picker while a file dialog is still open, and
|
||||
/// say so; an open picker that fails says why, and opens nothing (#6160).
|
||||
#[test]
|
||||
fn an_open_picker_is_refused_while_a_dialog_is_open_and_a_failed_one_says_why() {
|
||||
for command in ["file.open", "ui.installPlugin"] {
|
||||
let mut app = app();
|
||||
let picker = scripted(&mut app);
|
||||
asks(&mut app, command);
|
||||
for again in ["file.open", "ui.installPlugin"] {
|
||||
assert_eq!(app.run(again, json!({})), Err(file_asks::busy().to_string()), "{again} after {command}");
|
||||
}
|
||||
assert_eq!(picker.requests().len(), 1, "no second picker waits behind the first after {command}");
|
||||
picker.fail("the file could not be read");
|
||||
settle(&mut app);
|
||||
assert_eq!(app.ui.status, "the file could not be read", "{command}");
|
||||
assert!(app.session.documents().is_empty(), "{command}");
|
||||
asks(&mut app, command);
|
||||
assert_eq!(picker.requests().len(), 2, "{command} asks again once the first answered");
|
||||
}
|
||||
}
|
||||
|
||||
/// The picks' answers, then the rest of a frame's pumps (Save Changes goes on once its save is written).
|
||||
fn settle(app: &mut VectorcraftApp) {
|
||||
let ctx = app.ui_ctx.clone().unwrap_or_default();
|
||||
|
||||
Reference in new issue
Block a user