SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Design tabs: the tooltip says when a saved design has unsaved changes (#11408) (#11590)
semmelrinde4afd24d29fcb
diff --git a/assets/locales/pending/tab-unsaved-changes.json b/assets/locales/pending/tab-unsaved-changes.jsonnew file mode 100644index 0000000000..6d9269f505--- /dev/null+++ b/assets/locales/pending/tab-unsaved-changes.json@@ -0,0 +1,15 @@+{+ "en": { "document.tab_unsaved_changes": "Unsaved changes" },+ "ar": { "document.tab_unsaved_changes": "تغييرات غير محفوظة" },+ "de": { "document.tab_unsaved_changes": "Ungespeicherte Änderungen" },+ "es": { "document.tab_unsaved_changes": "Cambios sin guardar" },+ "fr": { "document.tab_unsaved_changes": "Modifications non enregistrées" },+ "he": { "document.tab_unsaved_changes": "שינויים שלא נשמרו" },+ "it": { "document.tab_unsaved_changes": "Modifiche non salvate" },+ "ja": { "document.tab_unsaved_changes": "未保存の変更" },+ "nl": { "document.tab_unsaved_changes": "Niet-opgeslagen wijzigingen" },+ "pl": { "document.tab_unsaved_changes": "Niezapisane zmiany" },+ "sv": { "document.tab_unsaved_changes": "Osparade ändringar" },+ "vi": { "document.tab_unsaved_changes": "Thay đổi chưa lưu" },+ "zh": { "document.tab_unsaved_changes": "未保存的更改" }+}diff --git a/crates/ui-egui/src/documents.rs b/crates/ui-egui/src/documents.rsindex 692dd45078..0e48f34d79 100644--- a/crates/ui-egui/src/documents.rs+++ b/crates/ui-egui/src/documents.rs@@ -741,9 +741,11 @@ fn tab_paths(app: &SolveApp) -> Vec<Option<String>> {}/// A tab's tooltip: where its design is saved (home shortened to `~`), or that it isn't yet; with-/// the full name above when the tab cut it short (#5868).-fn tab_tooltip(name: &str, path: Option<&str>, cut: bool) -> String {+/// the full name above when the tab cut it short (#5868), and below, that a saved design has+/// changes not saved yet (`dirty`), which the bullet after a cut name no longer shows (#11408).+fn tab_tooltip(name: &str, path: Option<&str>, cut: bool, dirty: bool) -> String {let place = path.map_or_else(|| crate::i18n::tr_label("Not saved yet").to_string(), crate::home::friendly_path);+ let place = if dirty && path.is_some() { format!("{place}\n{}", crate::i18n::tr("document.tab_unsaved_changes")) } else { place };if cut { format!("{name}\n{place}") } else { place }}@@ -926,7 +928,7 @@ pub fn tabs(app: &mut SolveApp, ui: &mut egui::Ui, r: Rect, x0: f32, x1: f32) {};let g = ui.painter().layout_no_wrap(label, font, ink);let text_w = (tr.width() - 30.0).max(10.0);- let tip = tab_tooltip(&name_display, paths.get(i).cloned().flatten().as_deref(), g.size().x > text_w);+ let tip = tab_tooltip(&name_display, paths.get(i).cloned().flatten().as_deref(), g.size().x > text_w, *dirty);let clip = Rect::from_min_size(tr.min, vec2(text_w + 10.0, tr.height()));ui.painter().with_clip_rect(clip).galley(pos2(tr.left() + 10.0, tr.center().y - g.size().y / 2.0), g, ink);// ×@@ -1351,18 +1353,26 @@ mod tests {use egui::Color32;/// #5868: a tab's tooltip says where its design is saved (home as `~`), or that it isn't- /// yet, with the full name above when the tab cut the name short.+ /// yet, with the full name above when the tab cut the name short. #11408: a saved design with+ /// changes not saved yet says so below, since a cut name hides the tab's bullet.#[test]fn tab_tooltip_says_where_the_design_is_saved() {- assert_eq!(tab_tooltip("plate", Some("/srv/designs/plate.solidcraft"), false), "/srv/designs/plate.solidcraft");- assert_eq!(tab_tooltip("a-long-name", Some("/srv/a-long-name.solidcraft"), true), "a-long-name\n/srv/a-long-name.solidcraft");- assert_eq!(tab_tooltip("Untitled", None, false), "Not saved yet");- assert_eq!(tab_tooltip("Untitled", None, true), "Untitled\nNot saved yet");+ assert_eq!(tab_tooltip("plate", Some("/srv/designs/plate.solidcraft"), false, false), "/srv/designs/plate.solidcraft");+ assert_eq!(tab_tooltip("a-long-name", Some("/srv/a-long-name.solidcraft"), true, false), "a-long-name\n/srv/a-long-name.solidcraft");+ assert_eq!(tab_tooltip("Untitled", None, false, false), "Not saved yet");+ assert_eq!(tab_tooltip("Untitled", None, true, false), "Untitled\nNot saved yet");+ assert_eq!(tab_tooltip("plate", Some("/srv/designs/plate.solidcraft"), false, true), "/srv/designs/plate.solidcraft\nUnsaved changes");+ assert_eq!(+ tab_tooltip("a-long-name", Some("/srv/a-long-name.solidcraft"), true, true),+ "a-long-name\n/srv/a-long-name.solidcraft\nUnsaved changes"+ );+ // A design never saved says so already, changed or not.+ assert_eq!(tab_tooltip("Untitled", None, true, true), "Untitled\nNot saved yet");if let Some(home) = std::env::var_os("HOME").or_else(|| std::env::var_os("USERPROFILE")).filter(|h| !h.is_empty()) {// The abbreviation keeps the relative path's native separators after `~/`.let relative = std::path::Path::new("Designs").join("bracket.solidcraft");let path = std::path::Path::new(&home).join(&relative);- assert_eq!(tab_tooltip("bracket", path.to_str(), false), format!("~/{}", relative.display()));+ assert_eq!(tab_tooltip("bracket", path.to_str(), false, false), format!("~/{}", relative.display()));}}