SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Design tabs: the tooltip says where the file is saved (#5868) (#5974)
DuBearte443baa41f0c8
diff --git a/assets/locales/en.json b/assets/locales/en.jsonindex 67d226a9a7..695489813d 100644--- a/assets/locales/en.json+++ b/assets/locales/en.json@@ -333,6 +333,7 @@"Nominal diameter": "Nominal diameter","None": "None","Not available yet": "Not available yet",+ "Not saved yet": "Not saved yet","Notch": "Notch","OUTPUT": "OUTPUT","Of": "Of",diff --git a/assets/locales/ja.json b/assets/locales/ja.jsonindex 18c30ddc5e..44dd1420f6 100644--- a/assets/locales/ja.json+++ b/assets/locales/ja.json@@ -333,6 +333,7 @@"Nominal diameter": "呼び径","None": "なし","Not available yet": "まだ利用できません",+ "Not saved yet": "まだ保存されていません","Notch": "ノッチ","OUTPUT": "出力","Of": "の値",diff --git a/assets/locales/zh.json b/assets/locales/zh.jsonindex 008ec26429..19946706ec 100644--- a/assets/locales/zh.json+++ b/assets/locales/zh.json@@ -333,6 +333,7 @@"Nominal diameter": "公称直径","None": "无","Not available yet": "暂不可用",+ "Not saved yet": "尚未保存","Notch": "缺口","OUTPUT": "输出","Of": "的值",diff --git a/crates/ui-egui/src/documents.rs b/crates/ui-egui/src/documents.rsindex b59e192412..33b6f5a260 100644--- a/crates/ui-egui/src/documents.rs+++ b/crates/ui-egui/src/documents.rs@@ -413,6 +413,21 @@ pub fn tabs_info(app: &SolveApp) -> Vec<(String, bool)> {.collect()}+/// Where each tab's design is saved, in `tabs_info`'s order (`None`: not saved yet).+fn tab_paths(app: &SolveApp) -> Vec<Option<String>> {+ if app.docs.slots.is_empty() {+ return vec![app.session.path.clone()];+ }+ app.docs.slots.iter().map(|s| s.as_ref().map_or(&app.session, |d| &d.session).path.clone()).collect()+}++/// 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 {+ let place = path.map_or_else(|| crate::i18n::tr_label("Not saved yet").to_string(), crate::home::friendly_path);+ if cut { format!("{name}\n{place}") } else { place }+}+/// The control channel's `ui.documents`: list, `new`, `switch`, `close` (by index; `force`/// closes without asking), `close_others` (all but `index`), `close_all`, `move` (`from`, `to`)/// or `quit`; `answer`: save | dont_save | cancel answers "save changes?".@@ -462,6 +477,7 @@ struct TabDrag {pub fn tabs(app: &mut SolveApp, ui: &mut egui::Ui, r: Rect, x0: f32, x1: f32) {let t = Tokens::get();let info = tabs_info(app);+ let paths = tab_paths(app);let n = info.len();let (first, shown, w) = layout(n, app.docs.active, x1 - x0);let mut pick: Option<usize> = None;@@ -558,6 +574,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 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);// ×@@ -581,7 +598,7 @@ pub fn tabs(app: &mut SolveApp, ui: &mut egui::Ui, r: Rect, x0: f32, x1: f32) {}if xresp.on_hover_text("Close").clicked() {shut = Some(i);- } else if (if held.is_some() { resp } else { resp.on_hover_text(name.as_str()) }).clicked() {+ } else if (if held.is_some() { resp } else { resp.on_hover_text(tip) }).clicked() {pick = Some(i);}}@@ -876,6 +893,20 @@ mod tests {use crate::Services;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.+ #[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");+ if let Some(home) = std::env::var_os("HOME").filter(|h| !h.is_empty()) {+ let path = std::path::Path::new(&home).join("Designs").join("bracket.solidcraft");+ assert_eq!(tab_tooltip("bracket", path.to_str(), false), "~/Designs/bracket.solidcraft");+ }+ }+fn app() -> SolveApp {SolveApp::new(Session::default(), Services::default())}diff --git a/crates/ui-egui/src/home.rs b/crates/ui-egui/src/home.rsindex a1c13f4348..993d250e59 100644--- a/crates/ui-egui/src/home.rs+++ b/crates/ui-egui/src/home.rs@@ -843,7 +843,7 @@ fn texture(texture: Option<&egui::TextureHandle>) -> Option<(egui::TextureId, eg}/// Abbreviate only an actual home-directory ancestor; the source path is kept for actions.-fn friendly_path(path: &str) -> String {+pub(crate) fn friendly_path(path: &str) -> String {let home = std::env::var_os("HOME").or_else(|| std::env::var_os("USERPROFILE"));abbreviated_path(path, home.as_deref().map(std::path::Path::new))}