dialogs: the chooser's Save answers Answer::Saved with the type picked, and a browser save answers Picked::Saved, so name settling and records_file follow upstream's save path

This commit is contained in:
bflatastic committed 2026-11-22 01:33:35 +07:00
1 parent b2b9a7e104
commit cfb9ec9c6e
3 files changed
+21 -10

No files matched your search

+10 -4
View File
@@ -175,7 +175,8 @@ struct Seen {
/// again when it is entered and when the window regains focus.
/// - OK, Enter and a double click on a file accept: a folder is entered, a file is opened, a Save to a listed file
/// asks Replace once, a typed path elsewhere is listed first and accepted there. The result is
/// `Ok(Answer::Paths(..))`; Cancel, Escape and the close action give `Cancel`.
/// `Ok(Answer::Paths(..))` for Open and Folder, `Ok(Answer::Saved { .. })` with the type picked for Save; Cancel,
/// Escape and the close action give `Cancel`.
/// - Automation fields: `folder`, `name` and `selection` (names in the shown folder); `listed` (read only) says the
/// listing is ready, and `replace` (read only) names the file the open Replace question is about. The question is a
/// child prompt: it is answered as every prompt is.
@@ -254,6 +255,11 @@ impl FileChooser {
}
/// Whether the type selector shows: a Save with types, or an Open with a choice of them.
/// A Save's answer for `path`, with the file type picked when the request offers types.
fn saved(&self, path: PathBuf) -> Answer {
Answer::Saved { path, filter: (!self.request.filters.is_empty()).then_some(self.filter) }
}
fn offers_types(&self) -> bool {
!self.request.filters.is_empty() && (self.request.kind == PickKind::Save || self.request.filters.len() > 1)
}
@@ -292,7 +298,7 @@ impl FileChooser {
let picked_folder = matches!(selected.as_slice(), [one] if one.folder);
match accept(&self.request, &typed, &folder, &rows, &selected, home.flatten().as_deref()) {
Accept::Open(paths) => return Some(DialogResult::Ok(Answer::Paths(paths))),
Accept::Save(path) => return Some(DialogResult::Ok(Answer::Paths(vec![path]))),
Accept::Save(path) => return Some(DialogResult::Ok(self.saved(path))),
Accept::Replace(path) => {
self.asks += 1;
let name = path.file_name().map_or_else(|| path.to_string_lossy(), |n| n.to_string_lossy()).into_owned();
@@ -449,7 +455,7 @@ impl FileChooser {
.events;
for event in events {
match event {
CollectionEvent::Selection(change) => seen.selection.push(change),
CollectionEvent::Selection { change, .. } => seen.selection.push(change),
CollectionEvent::Activate(path) => seen.activated = Some(path),
_ => {}
}
@@ -482,7 +488,7 @@ impl FileChooser {
if let Some(choice) = given {
self.replacing = None;
if choice == PromptChoice::Proceed {
return Some(DialogResult::Ok(Answer::Paths(vec![path])));
return Some(DialogResult::Ok(self.saved(path)));
}
}
return None;
+10 -5
View File
@@ -108,6 +108,11 @@ fn picked(path: impl AsRef<Path>) -> Option<DialogResult<Answer>> {
Some(DialogResult::Ok(Answer::Paths(vec![path.as_ref().to_path_buf()])))
}
/// A Save's answer of `path`, from a request that offers no file types.
fn saved(path: impl AsRef<Path>) -> Option<DialogResult<Answer>> {
Some(DialogResult::Ok(Answer::Saved { path: path.as_ref().to_path_buf(), filter: None }))
}
// WordCraft's `save_adds_the_extension_and_asks_before_replacing`, `selecting_a_file_preserves_leading_spaces`,
// `a_selected_folder_never_replaces_the_typed_save_name` and `a_removed_selected_file_keeps_its_exact_save_path`, with
// `~` and "not found". The extension is the service's policy now, so the chooser answers the name as typed.
@@ -120,7 +125,7 @@ fn the_chooser_lists_and_accepts_like_a_file_panel() {
assert_eq!((save.field("folder"), save.field("name")), (Value::from(shown("/d", "drafts")), Value::from("")), "the typed folder opens");
save.type_name("chapter");
save.click("Save");
assert_eq!(save.answer(), picked("/d/drafts/chapter"), "a new name is saved to as typed");
assert_eq!(save.answer(), saved("/d/drafts/chapter"), "a new name is saved to as typed");
// A listed file is replaced only after the question, asked once.
let mut replace = Chooser::open(PickRequest::save("document").directory("/d/drafts"));
@@ -128,7 +133,7 @@ fn the_chooser_lists_and_accepts_like_a_file_panel() {
replace.click("Save");
assert_eq!(replace.answer(), None, "the chooser asks before replacing");
replace.click("Replace");
assert_eq!(replace.answer(), picked("/d/drafts/old.docx"));
assert_eq!(replace.answer(), saved("/d/drafts/old.docx"));
// A selected file keeps its exact name, leading space and all, for Open and for Save's question.
let mut open = Chooser::open(PickRequest::open("document").directory("/d"));
@@ -141,7 +146,7 @@ fn the_chooser_lists_and_accepts_like_a_file_panel() {
save.click("Save");
assert_eq!(save.answer(), None, "Save asks before replacing the selected file");
save.click("Replace");
assert_eq!(save.answer(), picked("/d/ report.docx"));
assert_eq!(save.answer(), saved("/d/ report.docx"));
// A selected file removed meanwhile still names the exact path, and nothing is asked.
let mut removed = Chooser::open(PickRequest::save("document").file_name("Draft.docx").directory("/d"));
@@ -149,7 +154,7 @@ fn the_chooser_lists_and_accepts_like_a_file_panel() {
removed.fake.remove_file("/d/ report.docx");
removed.refocus();
removed.click("Save");
assert_eq!(removed.answer(), picked("/d/ report.docx"), "the removed selection keeps its path, not `report.docx`");
assert_eq!(removed.answer(), saved("/d/ report.docx"), "the removed selection keeps its path, not `report.docx`");
// A selected folder is entered and never becomes the save name; once it is gone, the typed name is saved to.
let mut folder = Chooser::open(PickRequest::save("document").file_name("chapter.docx").directory("/d"));
@@ -162,7 +167,7 @@ fn the_chooser_lists_and_accepts_like_a_file_panel() {
gone.fake.remove_folder("/d/Chapters");
gone.refocus();
gone.click("Save");
assert_eq!(gone.answer(), picked("/d/chapter.docx"), "the removed folder is not saved over as `Chapters.docx`");
assert_eq!(gone.answer(), saved("/d/chapter.docx"), "the removed folder is not saved over as `Chapters.docx`");
// `~` is the Home root; a typed path elsewhere is listed, then opened.
let mut home = Chooser::open(PickRequest::open("document").directory("/d"));
+1 -1
View File
@@ -329,7 +329,7 @@ impl Files for BrowserFiles {
let picked = match JsFuture::from(promise).await {
// A failed write or close is the save's failure; it never downloads.
Ok(handle) => match write_handle(&handle, &bytes).await {
Ok(()) => Picked::Paths(vec![PathBuf::from(&name)]),
Ok(()) => Picked::Saved { path: PathBuf::from(&name), file_type: None },
Err(error) => Picked::Failed(error),
},
Err(error) => rejected(&error_name(&error), &name, || download(&name, mime, &bytes)),