#3535: Export refusals show on the Export page; a typed document extension gives way to the chosen type's

A refused or failed export is said on the Export page (Backstage hides the status bar), as Save As does. A known document extension on the typed name is replaced by the chosen Export type's, and any other is kept with the extension added.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Martin Ball
2026-11-15 22:32:48 +00:00
co-authored by Claude Sonnet 5.5
parent 06b4d911cc
commit 67064e2f5e
8 changed files with 123 additions and 30 deletions
+1 -1
View File
@@ -154,7 +154,7 @@ Ranked, to beta (detail and remaining milestones in [docs/roadmap.md](docs/roadm
fix/6146-touchpad-scroll-speed
- 2026-11-09: Touchpad and mouse-wheel scroll speed settings (#6146): scales Wayland touchpad point input by default (4×) so two-finger scrolling matches desktop speed rather than crawling 1:1, and scales mouse wheel line distance; File › Options › Advanced › Scrolling; commands ui.scrollSpeed and ui.touchpadScrollSpeed.
- 2026-11-14: Save As and Export (also the formats on the Print page) offer Browse in WordCraft… on Linux and the BSDs, as File › Open does, for when the system file dialog doesn't appear (#3535, from VoiceLessQ's #3801). Exporting in the built-in browser lists Export's formats as the types; the chosen type is the format and its extension. Readiness estimates unchanged.
- 2026-11-14: Save As and Export (also the formats on the Print page) offer Browse in WordCraft… on Linux and the BSDs, as File › Open does, for when the system file dialog doesn't appear (#3535, from VoiceLessQ's #3801). Exporting in the built-in browser lists Export's formats as the types; the chosen type is the format and its extension, which replaces a known document extension on a typed name (`notes.docx` as plain text is `notes.txt`). An export the system dialog's name makes impossible (Word XML over an existing `.xml`) is refused on the Export page itself, not only the hidden status bar. Readiness estimates unchanged.
- 2026-11-12: DOCX: `w:lnNumType` without a positive `w:countBy` leaves line numbering off, as Word does, instead of numbering every line on screen, in PDF export and on re-save (#6209). Readiness estimates unchanged.
main
- 2026-11-04: Three behaviours lost in the #4501 refactor are back (#4683). From the second section on, headers, footers and note separators are measured with their own section's document grid and SECTION/SECTIONPAGES values, not the previous section's. An ODT paragraph default style that names no font no longer clears the document's default font. A press the canvas handles itself (Ctrl+click on a link, switching into a header or footer, equation entry) no longer also shows the link tooltip in that frame. Readiness unchanged.
+1
View File
@@ -497,6 +497,7 @@ impl WordApp {
if !self.ui.backstage {
backstage::forget_open_error(&ctx);
backstage::forget_save_as_error(&ctx);
backstage::forget_export_error(&ctx);
}
self.paint_window(ui, &ctx, t);
if !moved(self) {
+16
View File
@@ -719,6 +719,17 @@ pub(crate) fn forget_save_as_error(ctx: &egui::Context) {
ctx.data_mut(|d| d.remove::<String>(save_as_error_id()));
}
/// The Export page's refusal or write-failure message ([`WordApp::fail_export`]), shown on the
/// page for the same reason as the Save As one: Backstage hides the status bar.
pub(crate) fn export_error_id() -> egui::Id {
egui::Id::unique("backstage_export_error")
}
/// Drop the Export page's error once File is closed or a later export succeeds.
pub(crate) fn forget_export_error(ctx: &egui::Context) {
ctx.data_mut(|d| d.remove::<String>(export_error_id()));
}
/// Open a file from the Recent list. A file that can't be opened (deleted, moved, unreadable)
/// leaves File open so the list can say why, rather than closing it on a greyed-out window.
pub(crate) fn open_recent(app: &mut WordApp, path: &str) -> Result<(), String> {
@@ -902,6 +913,11 @@ fn export_page(app: &mut WordApp, ui: &mut Ui) {
return;
}
heading(ui, "Export");
let error = ui.ctx().data(|d| d.get_temp::<String>(export_error_id())).unwrap_or_default();
if !error.is_empty() {
ui.label(egui::RichText::new(&error).color(ui.visuals().error_fg_color));
ui.add_space(6.0);
}
ui.label(tl!("Save a copy in another format. Printing goes through a PDF you can print from any viewer."));
ui.add_space(12.0);
crate::print_page::export_formats(app, ui);
+30
View File
@@ -1363,3 +1363,33 @@ fn rtl_template_titles_are_right_aligned() {
wide_text_right,
);
}
/// A refused Word XML export (the typed name's `.xml` twin already exists) is said on the Export
/// page itself: Backstage hides the status bar, so the person would otherwise see nothing.
#[test]
fn export_refusal_shows_on_the_export_page() {
let dir = std::env::temp_dir().join(format!("wordcraft-backstage-export-error-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(dir.join("letter.xml"), "taken").unwrap();
let bare = dir.join("letter").to_string_lossy().into_owned();
let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Services::default());
a.run("text.insert", json!({"text": "Dear reader"})).unwrap();
a.run("ui.backstage", json!({"value": true, "page": "export"})).unwrap();
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
app.ui(ui);
},
a,
);
h.run_steps(4);
let err = h.state_mut().finish_pick(crate::file_dialogs::AfterPick::Export { ext: "xml".into() }, Some(bare)).unwrap_err();
h.run_steps(4);
assert!(h.state().ui.backstage, "still on the Export page");
assert!(err.contains("letter.xml already exists"), "{err}");
h.get_by_label(err.as_str());
assert_eq!(std::fs::read_to_string(dir.join("letter.xml")).unwrap(), "taken", "nothing replaced");
let _ = std::fs::remove_dir_all(&dir);
}
+24 -19
View File
@@ -12,7 +12,7 @@ use std::path::{Path, PathBuf};
use egui::{Align2, Rect, Sense, Ui, pos2, vec2};
use crate::file_dialogs::{AfterPick, FileDialogRequest, open_filters};
use crate::print_page::{EXPORT_FORMATS, export_file_ext};
use crate::print_page::{EXPORT_FORMATS, export_file_ext, export_name, is_document_ext};
use crate::theme::{Tokens, regular};
use crate::{WordApp, icons};
@@ -205,11 +205,9 @@ impl FileBrowser {
/// A type was chosen: when exporting it is the format, and the name's export extension follows it.
fn type_changed(&mut self) {
let Some(format) = self.exports.get(self.filter).cloned() else { return };
let name = Path::new(&self.name);
let known =
name.extension().and_then(|e| e.to_str()).is_some_and(|e| self.exports.iter().any(|f| export_file_ext(f).eq_ignore_ascii_case(e)));
if known {
self.name = name.with_extension(export_file_ext(&format)).to_string_lossy().into_owned();
// Only a known document extension is replaced; `notes.v2` keeps its `.v2`.
if Path::new(&self.name).extension().and_then(|e| e.to_str()).is_some_and(is_document_ext) {
self.name = export_name(&self.name, &format);
}
self.after = AfterPick::Export { ext: format };
}
@@ -221,8 +219,8 @@ impl FileBrowser {
}
/// OK: a highlighted folder, or a typed folder, is opened; otherwise the typed name is the
/// pick. Save adds the chosen type's extension to a name without one (an export, to a name
/// without the export's) and asks once more before replacing a file; Open wants a file that exists.
/// pick. Save adds the chosen type's extension to a name without one (an export replaces a
/// known document extension with the type's) and asks once more before replacing a file; Open wants a file that exists.
pub(crate) fn accept(&mut self) -> Step {
if let Some(dir) = self.selected.take().filter(|p| p.is_dir()) {
self.navigate(dir);
@@ -244,11 +242,9 @@ impl FileBrowser {
}
FileDialogRequest::Save { .. } => {
if let AfterPick::Export { ext } = &self.after {
// The chosen type is the format, so its extension goes on any name without it.
let want = export_file_ext(ext);
if !path.extension().and_then(|e| e.to_str()).is_some_and(|e| e.eq_ignore_ascii_case(want)) {
path.as_mut_os_string().push(format!(".{want}"));
}
// The chosen type is the format: its extension replaces a known document
// extension on the name, and is added to any other.
path = PathBuf::from(export_name(&path.to_string_lossy(), ext));
} else if path.extension().is_none()
&& let Some(ext) = self.exts().first().filter(|e| e.as_str() != "*")
{
@@ -786,10 +782,17 @@ mod tests {
assert!(b.name.ends_with(".txt"), "{}", b.name);
assert!(matches!(&b.after, AfterPick::Export { ext } if ext == "txt"));
b.navigate(dir.clone());
// A name typed afterwards with another extension still gets the chosen format's.
// A name typed afterwards with another document extension gets the chosen format's instead,
// and a name with an unknown one keeps it.
b.name = "notes.v2".into();
let Step::Pick(v2) = b.accept() else { panic!("picked") };
assert_eq!(v2.file_name().unwrap(), "notes.v2.txt");
b.name = "notes.docx".into();
let Step::Pick(path) = b.accept() else { panic!("picked") };
assert_eq!(path.file_name().unwrap(), "notes.docx.txt");
assert_eq!(path.file_name().unwrap(), "notes.txt");
for (typed, want) in [("a.PDF", "a.txt"), ("a.htm", "a.txt"), ("a", "a.txt"), ("a.TXT", "a.TXT"), ("sub/a.rtf", "sub/a.txt")] {
assert_eq!(crate::print_page::export_name(typed, "txt"), want);
}
a.close_file_browser(Some(path.clone()));
assert!(std::fs::read_to_string(&path).unwrap().contains("Exported in WordCraft"));
// Word 2003 XML starts on its own type, though Word XML writes .xml too.
@@ -872,14 +875,16 @@ mod tests {
a.finish_pick(AfterPick::Export { ext: "xml".into() }, Some(bare)).unwrap();
let xml = std::fs::read_to_string(dir.join("letter.xml")).unwrap();
assert!(xml.contains("pkg:package"), "Word XML written at letter.xml");
// A known document extension gives way to .xml; an unknown one stays.
let docx = dir.join("notes.docx").to_string_lossy().into_owned();
a.finish_pick(AfterPick::Export { ext: "xml".into() }, Some(docx)).unwrap();
assert!(dir.join("notes.docx.xml").is_file());
// The appended name already exists: the system dialog never confirmed it, so refuse.
assert!(dir.join("notes.xml").is_file());
let v2 = dir.join("notes.v2").to_string_lossy().into_owned();
a.finish_pick(AfterPick::Export { ext: "xml".into() }, Some(v2)).unwrap();
assert!(dir.join("notes.v2.xml").is_file());
// The resulting name already exists: the system dialog never confirmed it, so refuse.
let bare = dir.join("letter").to_string_lossy().into_owned();
assert!(a.finish_pick(AfterPick::Export { ext: "xml".into() }, Some(bare)).is_err());
let said = a.status_msg.as_ref().map(|(m, _)| m.clone()).unwrap_or_default();
assert!(said.contains("letter.xml already exists"), "the refusal is on the status bar: {said:?}");
let _ = std::fs::remove_dir_all(&dir);
}
+31 -9
View File
@@ -304,16 +304,15 @@ impl WordApp {
self.run("file.saveAs", json!({"path": path, "format": ext}))
} else if ext == "xml" {
// The engine takes an explicit format only for an .xml path, and a system Save
// dialog lets the user type any name: add the extension, as the built-in
// browser does (`notes.docx` becomes `notes.docx.xml`).
if !std::path::Path::new(&path).extension().and_then(|e| e.to_str()).is_some_and(|e| e.eq_ignore_ascii_case("xml")) {
path.push_str(".xml");
// dialog lets the user type any name: give it the extension, as the built-in
// browser does (`notes.docx` becomes `notes.xml`, `notes.v2` `notes.v2.xml`).
let named = crate::print_page::export_name(&path, "xml");
if named != path {
path = named;
// The dialog only confirmed the name it was given, not this one.
if std::path::Path::new(&path).exists() {
// Callers drop the result, so say it where the person sees it.
let msg = format!("{path} already exists; choose another name");
self.status(msg.clone());
return Err(msg);
return Err(self.fail_export(format!("{path} already exists; choose another name")));
}
}
// Word XML even over a Word 2003 XML file, which a save by path would keep.
@@ -321,8 +320,14 @@ impl WordApp {
} else {
self.run("file.saveAs", json!({"path": path}))
};
if r.is_ok() {
self.status(crate::i18n::fmt(tl!("Exported {path}"), &[("path", &crate::i18n::isolate_path(&path))]));
match &r {
Ok(_) => {
self.clear_export_error();
self.status(crate::i18n::fmt(tl!("Exported {path}"), &[("path", &crate::i18n::isolate_path(&path))]));
}
Err(e) => {
self.fail_export(e.clone());
}
}
r
}
@@ -401,6 +406,22 @@ impl WordApp {
}
}
/// An export failed or was refused: say so on the status bar and, for the Export page,
/// there too, since Backstage's render loop skips the status bar (callers drop the result).
fn fail_export(&mut self, error: String) -> String {
self.status(error.clone());
if let Some(ctx) = self.ctx.clone() {
ctx.data_mut(|d| d.insert_temp(crate::backstage::export_error_id(), error.clone()));
}
error
}
fn clear_export_error(&mut self) {
if let Some(ctx) = self.ctx.clone() {
crate::backstage::forget_export_error(&ctx);
}
}
/// Drop a Save As page error once a later attempt has actually saved.
fn clear_save_as_error(&mut self) {
if let Some(ctx) = self.ctx.clone() {
@@ -455,6 +476,7 @@ impl WordApp {
/// File › Export: ask where to save a copy in this format, then write it.
pub(crate) fn export_dialog(&mut self, ext: &str) {
let name = format!("{}.{}", self.title_stem(), crate::print_page::export_file_ext(ext));
// A refusal or failure is reported by `finish_pick` itself (Export page and status bar).
let _ = self.ask_file(FileDialogRequest::Save { name, dir: None }, AfterPick::Export { ext: ext.to_string() });
}
+19
View File
@@ -476,6 +476,25 @@ pub(crate) fn export_file_ext(format: &str) -> &str {
if format == EXPORT_WORD_2003 { "xml" } else { format }
}
/// Is `ext` an extension of a document or export type (the Export types, plus the older `.doc`
/// and `.htm`)? Such an extension on a typed name gives way to the chosen type's; any other
/// (`notes.v2`) is part of the name.
pub(crate) fn is_document_ext(ext: &str) -> bool {
["doc", "htm"].iter().any(|e| e.eq_ignore_ascii_case(ext)) || EXPORT_FORMATS.iter().any(|&(_, f)| export_file_ext(f).eq_ignore_ascii_case(ext))
}
/// The name an export to `format` is saved under: the chosen type's extension replaces a known
/// document extension (`notes.docx` as plain text is `notes.txt`) and is added to any other name.
pub(crate) fn export_name(name: &str, format: &str) -> String {
let want = export_file_ext(format);
let path = std::path::Path::new(name);
match path.extension().and_then(|e| e.to_str()) {
Some(e) if e.eq_ignore_ascii_case(want) => name.to_string(),
Some(e) if is_document_ext(e) => path.with_extension(want).to_string_lossy().into_owned(),
_ => format!("{name}.{want}"),
}
}
/// The "save a copy" formats (File › Export, and below the settings on the Print page).
pub fn export_formats(app: &mut WordApp, ui: &mut Ui) {
for &(label, ext) in EXPORT_FORMATS {
+1 -1
View File
@@ -128,7 +128,7 @@ Page Setup's margin, paper-size and document-grid number boxes scroll long text
| Date | Change | Summary |
|---|---|---|
| 2026-11-14 | trivial | Save As and Export (also the formats on the Print page) offer Browse in WordCraft… on Linux/BSD, as Open does; exporting there lists Export's formats as the types (#3535) |
| 2026-11-14 | trivial | Save As and Export (also the formats on the Print page) offer Browse in WordCraft… on Linux/BSD, as Open does; exporting there lists Export's formats as the types, whose extension replaces a known document extension on the name; an export refusal or failure shows on the Export page, as Save As's does (#3535) |
| 2026-11-12 | trivial | Clipboard: a copied picture is published as PNG (and HTML where the host writes it); WordCraft's own paste still keeps the original fragment, and a copy of only shapes carries no HTML or RTF (#6205). Native external-app paste remains untested. |
| 2026-11-07 | trivial | Vertical scrollbar track: clicking above the elevator moves one screen up and clicking below it moves one screen down, as in Word, instead of jumping to that position in the document (#5853) |
| 2026-11-04 | trivial | Canvas: a press the canvas handles itself (Ctrl+click on a link, switching into a header or footer, equation entry) skips the link tooltip that frame; hovering shows it again; a regression from the #4501 refactor (#4683) |