Design tabs: the tooltip says where the file is saved (#5868) (#5974)

* claim: #5868

* Design tabs: the tooltip says where the file is saved (#5868)

Hovering a design tab showed the design's name, the same text as the tab.
The tooltip now says where the file is saved, with a path in the home
folder shortened to ~/ (home::friendly_path, as the start page does), or
"Not saved yet" for a design never saved. When the tab is too narrow for
its name, the full name comes first, then the place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DuBearte
2026-10-25 01:25:36 +00:00
committed by GitHub
parent d366b8922a
commit 443baa41f0
5 changed files with 36 additions and 2 deletions
+1
View File
@@ -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",
+1
View File
@@ -333,6 +333,7 @@
"Nominal diameter": "呼び径",
"None": "なし",
"Not available yet": "まだ利用できません",
"Not saved yet": "まだ保存されていません",
"Notch": "ノッチ",
"OUTPUT": "出力",
"Of": "の値",
+1
View File
@@ -333,6 +333,7 @@
"Nominal diameter": "公称直径",
"None": "无",
"Not available yet": "暂不可用",
"Not saved yet": "尚未保存",
"Notch": "缺口",
"OUTPUT": "输出",
"Of": "的值",
+32 -1
View File
@@ -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())
}
+1 -1
View File
@@ -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))
}