mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-11 21:14:18 +00:00
Merge pull request #5671 from dotCooCoo/fix/package-status-fonts-background
Package: name every font left out when no dialog is shown
This commit is contained in:
@@ -164,8 +164,12 @@ fn packaged(app: &mut VectorcraftApp, r: Result<Value, String>, web: bool, later
|
||||
return Ok(r);
|
||||
}
|
||||
let folder = r["folder"].as_str().unwrap_or_default().to_string();
|
||||
// The dialog names every font left out, so the status line may cut the list short.
|
||||
app.status(package_status(n, Some(&folder), &package_status_note(missing, &status_fonts(&fonts))));
|
||||
// A dialog open now (another one, after a package written in the background) stays, and no
|
||||
// dialog names the fonts left out, so the status line names every one of them. Otherwise the
|
||||
// dialog names them all, and the status line may cut the list short.
|
||||
let asks = app.ui.dialog.is_none();
|
||||
let listed = if asks { status_fonts(&fonts) } else { fonts.clone() };
|
||||
app.status(package_status(n, Some(&folder), &package_status_note(missing, &listed)));
|
||||
let shown_note = package_dialog_note(missing, &fonts);
|
||||
let detail = if shown_note.is_empty() {
|
||||
crate::i18n::fmt(
|
||||
@@ -178,7 +182,7 @@ fn packaged(app: &mut VectorcraftApp, r: Result<Value, String>, web: bool, later
|
||||
&[("folder", &folder), ("note", &shown_note)],
|
||||
)
|
||||
};
|
||||
if app.ui.dialog.is_none() {
|
||||
if asks {
|
||||
ask(app, tl!("Package created"), &detail, "file.showPackage", json!({ "folder": folder }));
|
||||
}
|
||||
Ok(r)
|
||||
@@ -212,9 +216,9 @@ pub(super) fn package_status_note(missing: usize, fonts: &str) -> String {
|
||||
/// The most bytes of font names a package status lists next to the dialog that names them all.
|
||||
const STATUS_FONTS: usize = 500;
|
||||
|
||||
/// `fonts` (names joined with `, `) as the desktop's status line lists them: whole, or the names
|
||||
/// that fit in [`STATUS_FONTS`] bytes followed by `, …`, so the line stays short enough for the
|
||||
/// status bar to translate it.
|
||||
/// `fonts` (names joined with `, `) as the desktop's status line lists them while the Package
|
||||
/// created dialog names them all: whole, or the names that fit in [`STATUS_FONTS`] bytes followed
|
||||
/// by `, …`, so the line stays short enough for the status bar to translate it.
|
||||
pub(super) fn status_fonts(fonts: &str) -> String {
|
||||
if fonts.len() <= STATUS_FONTS {
|
||||
return fonts.to_string();
|
||||
|
||||
@@ -342,6 +342,27 @@ fn a_long_list_of_fonts_left_out_is_cut_short_in_the_status() {
|
||||
assert!(package::package_dialog_note(0, &fonts).contains("Family 199 Regular"));
|
||||
}
|
||||
|
||||
/// A package written in the background while another dialog is open shows no dialog, so its
|
||||
/// status line names every font left out, however long the list.
|
||||
#[test]
|
||||
fn a_background_package_behind_another_dialog_names_every_font_in_the_status() {
|
||||
let dir = Folder::new("fonts-behind");
|
||||
let gate = Gate::default();
|
||||
let (mut app, _files) = saved_with_worker(&dir, &gate);
|
||||
for i in 0..30 {
|
||||
app.run("text.create", json!({"x": 10, "y": 40 + i, "text": "Gone", "font": format!("No Such Font Family {i}")})).unwrap();
|
||||
}
|
||||
package_dialog(&mut app, &dir.path("out"));
|
||||
assert_eq!(confirm(&mut app).unwrap()["background"], true);
|
||||
app.run("ui.packageDialog", json!({})).unwrap();
|
||||
gate.open();
|
||||
background::wait_all(&mut app);
|
||||
assert_eq!(app.ui.dialog.as_ref().map(|d| d.kind.as_str()), Some("package"), "the other dialog stays");
|
||||
let status = &app.ui.status;
|
||||
assert!(status.contains("No Such Font Family 0 Regular") && status.contains("No Such Font Family 29 Regular"), "{status}");
|
||||
assert!(!status.contains('…'), "{status}");
|
||||
}
|
||||
|
||||
/// A package status written in English, for one file or several, with or without a folder and a
|
||||
/// note, is translated by every catalog when the status bar shows it after a language switch, in
|
||||
/// the form the language's plural rule picks for the count, and a folder whose name has a space or
|
||||
|
||||
Reference in New Issue
Block a user