Compare commits

..
4 changed files with 53 additions and 49 deletions
+2 -7
View File
@@ -237,15 +237,10 @@ pub fn is_word_template(path: &str) -> bool {
/// The name an open document goes by in the window: the engine's title, with an untitled
/// document's `Document2` in the interface language.
pub fn display_title(d: &DocInfo) -> String {
// NUL cannot go into an X11 window title (C string); a title of only NUL reads as untitled (#3634).
let title: String = d.title.chars().filter(|&c| c != '\0').collect();
if title.is_empty() && !d.title.is_empty() {
return tl!("Document1").into();
}
if d.path.is_none() {
return untitled_title(&title).unwrap_or(title);
return untitled_title(&d.title).unwrap_or_else(|| d.title.clone());
}
title
d.title.clone()
}
/// `Document2` (the engine's English name for an untitled document) in the interface language,
+20 -12
View File
@@ -14,12 +14,14 @@ use craft::behavior::IconId;
use craft::theme::Variant;
use craft::ui::buttons::Button;
use craft::ui::choice::Checkbox;
use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _, clicked};
use craft::ui::contract::{Bind, Pad, Props as _, Show as _, ShowContainer as _, clicked};
use craft::ui::dialog::{Dialog, DialogId, DialogResult, DialogStack, StackDialog, dialog_id};
use craft::ui::display::{Badge, Icon, Shade, Text};
use craft::ui::layout_components::Row as Line;
use craft::ui::layout::RowAlign;
use craft::ui::layout_components::{Row as Line, Stack};
use craft::ui::primitives::IconSpec;
use craft::ui::sections::{DialogRole, FooterButton, GroupBox};
use craft::ui::sections::{DialogRole, FooterButton};
use craft::ui::style::{SurfaceKind, TypeRole};
use egui::Ui;
use serde::Serialize;
@@ -272,15 +274,21 @@ impl StackDialog for FontBox {
.shade(Shade::Faint)
.show(ui);
for (at, g) in groups(fonts).into_iter().enumerate() {
// The names are the document's own words, not interface text.
GroupBox::new(g.fonts.join(", "), None).id_salt(("download", at)).show(ui, |ui, _| {
let shown_as =
crate::i18n::fmt(tl!("Shown as {fonts} · {publisher}"), &[("fonts", &g.shown_as.join(", ")), ("publisher", g.publisher)]);
Text::new(shown_as).shade(Shade::Faint).show(ui);
if g.restricted {
Text::new(tl!("Its licence limits who may use it: read the terms first.")).shade(Shade::Faint).show(ui);
}
Line::new().show(ui, |ui, _| {
// One row per download, as before the craft port: the names, what they are shown as and the licence
// note stacked at the start edge, the button at the end. The names are the document's own words.
Stack::new().surface(SurfaceKind::Frame).pad(Pad::Regular).fill_width().id_salt(("download_group", at)).show(ui, |ui, _| {
Line::new().fill_width().align(RowAlign::SpaceBetween).id_salt(("download", at)).show(ui, |ui, _| {
Stack::new().show(ui, |ui, _| {
Text::new(g.fonts.join(", ")).role(TypeRole::BodyStrong).show(ui);
let shown_as = crate::i18n::fmt(
tl!("Shown as {fonts} · {publisher}"),
&[("fonts", &g.shown_as.join(", ")), ("publisher", g.publisher)],
);
Text::new(shown_as).shade(Shade::Faint).show(ui);
if g.restricted {
Text::new(tl!("Its licence limits who may use it: read the terms first.")).shade(Shade::Faint).show(ui);
}
});
if clicked(&Button::new(tl!("Download")).variant(Variant::PRIMARY).id_salt(("download_button", at)).show(ui)) {
asks.push(Ask::Download(g.url.to_string()));
}
+30
View File
@@ -233,3 +233,33 @@ fn only_so_many_documents_are_remembered() {
assert_eq!(a.font_notice_seen.len(), REMEMBERED);
assert_eq!(a.font_notice_seen.last(), Some(&(REMEMBERED as u64 + 49)));
}
/// Each missing font's names, substitute and Download button sit in one compact row, not one under another, and a
/// narrow window keeps them inside the box.
#[test]
fn each_download_is_one_row() {
let row = |font: &str, shown: &str, url: &str| Row {
font: font.into(),
shown_as: vec![shown.into()],
download: font.into(),
publisher: "Microsoft".into(),
url: url.into(),
restricted: false,
};
for width in [1440.0, 520.0] {
let mut a = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
let fonts = vec![row("Aptos", "Carlito", "https://a"), row("Cascadia Code", "Liberation Mono", "https://c")];
open_with(&mut a, None, FontBox::new(fonts, false), DialogHooks { prepare: None, settle });
let h = harness_sized(a, egui::vec2(width, 900.0));
let buttons: Vec<_> = h.query_all_by_role_and_label(egui::accesskit::Role::Button, "Download").collect();
assert_eq!(buttons.len(), 2);
for (button, shown) in buttons.iter().zip(["Shown as Carlito · Microsoft", "Shown as Liberation Mono · Microsoft"]) {
let shown = h.get_by_label(shown).rect();
let button = button.rect();
// The button is beside the text block, level with it, not under it.
assert!(button.min.x >= shown.max.x, "{width}: {button:?} {shown:?}");
assert!(button.center().y < shown.max.y, "{width}: button under the text: {button:?} {shown:?}");
assert!(button.max.x <= width, "{width}: clipped {button:?}");
}
}
}
+1 -30
View File
@@ -23,13 +23,11 @@ struct Rig {
commands: Vec<(ViewportId, ViewportCommand)>,
/// The viewports that drew in the last frame, in order.
drawn: Vec<ViewportId>,
/// How the viewports asked to open their windows in every frame so far.
builders: Vec<egui::ViewportBuilder>,
}
impl Rig {
fn new() -> Rig {
Rig { kit: Kit::new(), focused: None, closing: Vec::new(), commands: Vec::new(), drawn: Vec::new(), builders: Vec::new() }
Rig { kit: Kit::new(), focused: None, closing: Vec::new(), commands: Vec::new(), drawn: Vec::new() }
}
fn ctx(&self) -> egui::Context {
@@ -60,7 +58,6 @@ impl Rig {
craft::ui::shell::embed::logic(ui.ctx(), || a.close_decision());
a.ui(ui);
});
self.builders.extend(out.builders.into_iter().map(|(_, b)| b));
self.commands = out.commands;
self.drawn = out.trees.iter().map(|(v, _)| *v).collect();
self.closing.clear();
@@ -517,29 +514,3 @@ fn every_open_replaces_an_untouched_blank_document_in_its_window() {
}
std::fs::remove_dir_all(second.parent().unwrap()).ok();
}
/// #3634: a NUL in the document title never reaches an OS window title (X11 and Wayland panic on
/// it): not a native window's builder, not a `Title` command, not the window menu. Checks what the
/// frames send, so a new title source that skips `display_title` fails here.
#[test]
fn nul_in_the_document_title_never_reaches_an_os_window_title() {
for raw in ["\u{0}", "a\u{0}b"] {
let mut rig = Rig::new();
let mut a = app("x");
a.run("file.properties", json!({"title": raw})).unwrap();
rig.frames(&mut a, 3);
a.run("view.newWindow", json!({})).unwrap();
assert_eq!(a.window_count(), 2);
let mut sent = Vec::new();
for _ in 0..3 {
rig.frame(&mut a);
sent.extend(rig.commands.iter().filter_map(|(_, c)| if let ViewportCommand::Title(t) = c { Some(t.clone()) } else { None }));
}
sent.extend(rig.builders.iter().filter_map(|b| b.title.clone()));
sent.extend(a.switch_windows_entries().into_iter().map(|e| e.1));
assert!(rig.builders.iter().any(|b| b.title.is_some()), "the new window's builder carries a title");
for t in &sent {
assert!(std::ffi::CString::new(t.as_str()).is_ok(), "an OS window title without NUL ({raw:?}): {t:?}");
}
}
}