Start: tell same-named recent designs apart (#9081) (#9174)

* claim: #9081

Co-authored-by: Cursor <cursoragent@cursor.com>

* Tell same-named recent designs apart (#9081)

Show the file name with extension, ellipsize long paths in the middle so the end stays visible, and label imports by kind (STEP, STL, …) instead of always Design.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Start: Recent paths take their ink from the theme, and the middle-ellipsis helper is exported for tests only

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

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SilentWolf75
2026-10-30 16:21:26 +00:00
committed by GitHub
parent 0396b2d00a
commit df18823d0a
4 changed files with 112 additions and 7 deletions
+53 -2
View File
@@ -860,7 +860,8 @@ fn start_content(app: &mut SolveApp, ui: &mut egui::Ui, action: &mut Option<File
if !app.home.recent.is_empty() {
FileView::recent_list(ui, |ui| {
for (index, path) in app.home.recent.clone().iter().enumerate() {
let name = std::path::Path::new(path).file_stem().map(|name| name.to_string_lossy()).unwrap_or_else(|| path.as_str().into());
// Keep the extension so plate.step and plate.stl are not both "plate" (#9081).
let name = std::path::Path::new(path).file_name().map(|name| name.to_string_lossy()).unwrap_or_else(|| path.as_str().into());
let missing = !available(app, path);
let when = if app.session.path.as_ref() == Some(path) { app.tr("home.open_now").to_string() } else { recent_time(app, path) };
let shown_path = if missing {
@@ -872,6 +873,7 @@ fn start_content(app: &mut SolveApp, ui: &mut egui::Ui, action: &mut Option<File
} else {
friendly_path(path)
};
let kind = recent_kind(app, path);
let response = FileView::recent_row(
ui,
&format!("home:recent:{index}"),
@@ -879,7 +881,7 @@ fn start_content(app: &mut SolveApp, ui: &mut egui::Ui, action: &mut Option<File
title: &name,
path: &shown_path,
when: &when,
workspace: app.tr("home.design_workspace"),
workspace: &kind,
thumbnail: texture(app.home.thumbs.get(path).and_then(Option::as_ref)),
// A design whose picture could not be made shows a dimmed placeholder,
// distinct from the one shown while a picture is still loading (#4655).
@@ -948,6 +950,30 @@ fn abbreviated_path(path: &str, home: Option<&std::path::Path>) -> String {
}
}
/// Kind column for a recent file: Design for `.sc`/legacy, else STEP, STL, … (#9081).
fn recent_kind(app: &SolveApp, path: &str) -> String {
let ext = std::path::Path::new(path).extension().and_then(|e| e.to_str()).unwrap_or("");
if solidcraft_engine::io::is_design_ext(ext) || ext.eq_ignore_ascii_case("json") {
return app.tr("home.design_workspace").to_string();
}
if solidcraft_engine::io::is_drawing_path(path) {
return app.tr_label("Drawing").to_string();
}
let label = match ext.to_ascii_lowercase().as_str() {
"step" | "stp" => "STEP",
"igs" | "iges" => "IGES",
"stl" => "STL",
"3mf" => "3MF",
"obj" => "OBJ",
"glb" | "gltf" => "glTF",
"fcstd" => "FreeCAD",
"3dm" => "Rhino",
other if !other.is_empty() => return other.to_ascii_uppercase(),
_ => return app.tr("home.design_workspace").to_string(),
};
label.to_string()
}
fn recent_time(app: &SolveApp, path: &str) -> String {
let Some(time) = app.home.opened_at.get(path) else { return String::new() };
let now = web_time::SystemTime::now().duration_since(web_time::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(*time);
@@ -1112,6 +1138,31 @@ mod tests {
assert_eq!(abbreviated_path("/disk/design.solidcraft", None), "/disk/design.solidcraft");
}
#[test]
fn recent_kind_names_imports_by_extension() {
let app = crate::test_support::sample_app();
assert_eq!(recent_kind(&app, "/tmp/plate.sc"), "Design");
assert_eq!(recent_kind(&app, "/tmp/plate.solidcraft"), "Design");
assert_eq!(recent_kind(&app, "/tmp/plate.step"), "STEP");
assert_eq!(recent_kind(&app, "/tmp/plate.STL"), "STL");
assert_eq!(recent_kind(&app, "/tmp/plate.3mf"), "3MF");
assert_eq!(recent_kind(&app, "/tmp/plate.obj"), "OBJ");
}
#[test]
fn middle_ellipsis_keeps_both_ends_of_a_path() {
let ctx = crate::fonts::test_context();
let mut shown = String::new();
crate::test_support::frame(&ctx, egui::RawInput::default(), |ui| {
let font = egui::FontId::monospace(12.0);
let full = "~/Projects/exports/out/plate.step";
shown = crate::ui_kit::ellipsize_middle(ui, full, font, 80.0);
});
assert!(shown.contains('…'), "{shown}");
assert!(shown.ends_with("plate.step") || shown.ends_with(".step"), "{shown}");
assert!(shown.starts_with('~') || shown.starts_with("~/P"), "{shown}");
}
#[test]
fn recent_times_use_compact_labels_and_calendar_dates() {
let app = crate::test_support::sample_app();
+15 -3
View File
@@ -1,5 +1,8 @@
//! File/start presentation; callers retain commands, caches and recovery ownership.
use super::{metrics::dimension, text::paint_text};
use super::{
metrics::dimension,
text::{paint_text, paint_text_aligned},
};
use crate::theme::Tokens;
use egui::{Align2, FontId, InnerResponse, Rect, Response, Sense, Stroke, TextureId, Ui, Vec2, pos2, vec2};
@@ -301,7 +304,15 @@ impl FileView {
t.form_ink,
false,
);
paint_text(ui, Rect::from_min_max(pos2(left, half), content.max), row.path, FontId::monospace(t.font_body), t.file_dim, false);
paint_text_aligned(
ui,
Rect::from_min_max(pos2(left, half), content.max),
row.path,
FontId::monospace(t.font_body),
t.file_dim,
false,
true,
);
} else {
let when_width = t.space_24 * 5.0;
let workspace_width = t.form_label_width * 2.0;
@@ -318,13 +329,14 @@ impl FileView {
t.form_ink,
false,
);
paint_text(
paint_text_aligned(
ui,
Rect::from_min_max(pos2(path_left, content.top()), pos2((when_left - t.space_14).max(path_left), content.bottom())),
row.path,
FontId::monospace(t.font_body),
t.file_dim,
false,
true,
);
paint_text(
ui,
+2
View File
@@ -94,6 +94,8 @@ pub(crate) use sphere::{SphereTile, sphere_cursor, sphere_grid, sphere_grid_drag
pub(crate) use stages::{StageAction, StageBar};
pub(crate) use status::*;
pub(crate) use table::*;
#[cfg(test)]
pub(crate) use text::ellipsize_middle;
pub(crate) use text_menu::menu_open as text_menu_open;
pub(crate) use tree::*;
pub(crate) use value_focus::*;
+42 -2
View File
@@ -2,15 +2,55 @@
use crate::theme::Tokens;
use egui::Ui;
/// Shorten `text` with an ellipsis in the middle so both ends stay visible (#9081).
pub(crate) fn ellipsize_middle(ui: &Ui, text: &str, font: egui::FontId, max_width: f32) -> String {
if !(max_width.is_finite() && max_width > 0.0) {
return String::new();
}
let width = |s: &str| ui.fonts_mut(|fonts| fonts.layout_no_wrap(s.to_owned(), font.clone(), ui.visuals().text_color()).size().x);
if width(text) <= max_width + 0.5 {
return text.to_owned();
}
let chars: Vec<char> = text.chars().collect();
if chars.len() < 4 {
return "…".into();
}
let mut best = "…".to_string();
let mut lo = 1usize;
let mut hi = chars.len() / 2;
while lo <= hi {
let keep = (lo + hi) / 2;
let left: String = chars.iter().take(keep).collect();
let right: String = chars.iter().skip(chars.len() - keep).collect();
let candidate = format!("{left}…{right}");
if width(&candidate) <= max_width + 0.5 {
best = candidate;
lo = keep + 1;
} else if keep == 0 {
break;
} else {
hi = keep - 1;
}
}
best
}
/// Paint one pixel-aligned text run with the requested interface weight.
/// Clipped, device-pixel-snapped weighted text. Tokens: `font_section_tracking; caller supplies font/ink tokens`.
pub(super) fn paint_text(ui: &Ui, rect: egui::Rect, text: &str, font: egui::FontId, ink: egui::Color32, spaced: bool) {
paint_text_aligned(ui, rect, text, font, ink, spaced, false);
}
/// Like [`paint_text`], but with `middle` an ellipsis sits in the middle so a path's file name
/// stays visible (#9081).
pub(super) fn paint_text_aligned(ui: &Ui, rect: egui::Rect, text: &str, font: egui::FontId, ink: egui::Color32, spaced: bool, middle: bool) {
let size = font.size;
let mut format = egui::TextFormat::simple(font, ink);
let mut format = egui::TextFormat::simple(font.clone(), ink);
if spaced {
format.extra_letter_spacing = size * Tokens::get().font_section_tracking;
}
let mut job = egui::text::LayoutJob::single_section(text.to_string(), format);
let shown = if middle { ellipsize_middle(ui, text, font, rect.width().max(0.0)) } else { text.to_owned() };
let mut job = egui::text::LayoutJob::single_section(shown, format);
job.wrap.max_width = rect.width().max(0.0);
job.wrap.max_rows = 1;
let galley = ui.fonts_mut(|fonts| fonts.layout_job(job));