Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Design tabs: double-click a tab to rename the design (#10364)

Matthew Davis48bab1a65a1e
diff --git a/assets/locales/pending/design-tab-rename.json b/assets/locales/pending/design-tab-rename.json
new file mode 100644
index 0000000000..50472334b4
--- /dev/null
+++ b/assets/locales/pending/design-tab-rename.json
@@ -0,0 +1,34 @@
+{
+ "en": {
+ "prefs.tab_double_click_renames": "Double-click a design tab to rename it",
+ "prefs.tab_double_click_renames_note": "Type the new name, then press Enter or click elsewhere to keep it, or Esc to cancel. Off: a double-click on a tab maximizes the window, as on the empty part of the bar."
+ },
+ "ar": {
+ "prefs.tab_double_click_renames": "انقر نقرًا مزدوجًا على تبويب التصميم لإعادة تسميته",
+ "prefs.tab_double_click_renames_note": "اكتب الاسم الجديد، ثم اضغط Enter أو انقر في مكان آخر للاحتفاظ به، أو Esc للإلغاء. عند الإيقاف: يؤدي النقر المزدوج على التبويب إلى تكبير النافذة، كما في الجزء الفارغ من الشريط."
+ },
+ "de": {
+ "prefs.tab_double_click_renames": "Entwurfsregisterkarte per Doppelklick umbenennen",
+ "prefs.tab_double_click_renames_note": "Geben Sie den neuen Namen ein und drücken Sie Enter oder klicken Sie woanders hin, um ihn zu übernehmen, oder Esc zum Abbrechen. Aus: Ein Doppelklick auf eine Registerkarte maximiert das Fenster, wie auf dem leeren Teil der Leiste."
+ },
+ "he": {
+ "prefs.tab_double_click_renames": "לחיצה כפולה על לשונית עיצוב משנה את שמו",
+ "prefs.tab_double_click_renames_note": "הקלידו את השם החדש ואז הקישו Enter או לחצו במקום אחר כדי לשמור אותו, או Esc כדי לבטל. כבוי: לחיצה כפולה על לשונית מגדילה את החלון, כמו בחלק הריק של הסרגל."
+ },
+ "ja": {
+ "prefs.tab_double_click_renames": "デザインのタブをダブルクリックして名前を変更",
+ "prefs.tab_double_click_renames_note": "新しい名前を入力し、Enter キーを押すか別の場所をクリックすると確定し、Esc でキャンセルします。オフ: タブをダブルクリックすると、バーの空いている部分と同じようにウィンドウを最大化します。"
+ },
+ "ko": {
+ "prefs.tab_double_click_renames": "디자인 탭을 두 번 클릭하여 이름 바꾸기",
+ "prefs.tab_double_click_renames_note": "새 이름을 입력한 뒤 Enter 키를 누르거나 다른 곳을 클릭하면 적용되고, Esc 키를 누르면 취소됩니다. 끄면: 탭을 두 번 클릭할 때 막대의 빈 부분처럼 창이 최대화됩니다."
+ },
+ "vi": {
+ "prefs.tab_double_click_renames": "Nhấp đúp vào thẻ thiết kế để đổi tên",
+ "prefs.tab_double_click_renames_note": "Nhập tên mới, rồi nhấn Enter hoặc nhấp ra chỗ khác để giữ, hoặc Esc để hủy. Khi tắt: nhấp đúp vào thẻ sẽ phóng to cửa sổ, như ở phần trống của thanh."
+ },
+ "zh": {
+ "prefs.tab_double_click_renames": "双击设计选项卡以重命名",
+ "prefs.tab_double_click_renames_note": "输入新名称,然后按 Enter 或点击别处即可保留,按 Esc 取消。关闭时:双击选项卡会最大化窗口,与栏的空白处相同。"
+ }
+}
diff --git a/crates/ui-egui/src/documents.rs b/crates/ui-egui/src/documents.rs
index 62a1d3b5f4..cbc67d7746 100644
--- a/crates/ui-egui/src/documents.rs
+++ b/crates/ui-egui/src/documents.rs
@@ -969,10 +969,17 @@ pub fn tabs(app: &mut SolveApp, ui: &mut egui::Ui, r: Rect, x0: f32, x1: f32) {
let mut shut: Option<usize> = None;
// Each tab fits its name (up to MAX_FIT) while all of them fit; otherwise they share the room.
const MAX_FIT: f32 = 200.0;
+ // The selected tab grows with a name being typed into it.
+ let typed = app.menu.rename.as_ref().filter(|_| renaming_tab(app)).map(|r| r.text.clone());
+ let selected = if app.docs.slots.is_empty() { 0 } else { app.docs.active };
let natural: Vec<f32> = info
.iter()
- .map(|(name, dirty)| {
- let shown_name = crate::i18n::Locale::for_language(&app.preferences.language).given_name(name);
+ .enumerate()
+ .map(|(i, (name, dirty))| {
+ let shown_name = match &typed {
+ Some(text) if i == selected => text.clone(),
+ _ => crate::i18n::Locale::for_language(&app.preferences.language).given_name(name),
+ };
let label = format!("{shown_name}{}", if *dirty { " •" } else { "" });
let text = ui.painter().layout_no_wrap(label, crate::fonts::semibold(crate::theme::Tokens::get().font_button), t.app_bar_text).size().x;
(text + 40.0).clamp(72.0, MAX_FIT)
@@ -1027,8 +1034,9 @@ pub fn tabs(app: &mut SolveApp, ui: &mut egui::Ui, r: Rect, x0: f32, x1: f32) {
let resp = ui.interact(tr, ui.scope_id().with(("doc_tab", i)), Sense::click_and_drag());
crate::scenario::publish_target(&format!("tab:design:{i}"), tr);
// Dragging a tab along the strip moves it. The tabs are also part of the title bar:
- // dragging the only tab, or one mostly up or down, moves the window, and a double click
- // maximizes it.
+ // dragging the only tab, or one mostly up or down, moves the window. A double click
+ // renames the design in its tab (the first click selected it), or with the preference
+ // off maximizes the window as the bar's empty space does.
if resp.drag_started_by(egui::PointerButton::Primary) {
let origin = ui.input(|i| i.pointer.press_origin()).unwrap_or(tr.center());
let moved = pointer.unwrap_or(origin) - origin;
@@ -1037,8 +1045,14 @@ pub fn tabs(app: &mut SolveApp, ui: &mut egui::Ui, r: Rect, x0: f32, x1: f32) {
} else if title_bar {
ui.ctx().send_viewport_cmd(egui::ViewportCommand::StartDrag);
}
- } else if title_bar && resp.double_clicked() {
- crate::titlebar::toggle_maximize(ui.ctx());
+ } else if resp.double_clicked() {
+ if app.preferences.tab_double_click_renames {
+ if active {
+ start_tab_rename(app, name, tr);
+ }
+ } else if title_bar {
+ crate::titlebar::toggle_maximize(ui.ctx());
+ }
}
if resp.drag_stopped() && drag.is_some_and(|d| d.from == i) {
// Released over the bar (not dropped somewhere down the window): the tab lands there.
@@ -1063,7 +1077,16 @@ pub fn tabs(app: &mut SolveApp, ui: &mut egui::Ui, r: Rect, x0: f32, x1: f32) {
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, *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);
+ if active && renaming_tab(app) {
+ tab_rename_field(
+ app,
+ ui,
+ Rect::from_min_max(pos2(tr.left() + 6.0, tr.top() + 3.0), pos2(tr.left() + 10.0 + text_w, tr.bottom() - 3.0)),
+ &name_display,
+ );
+ } else {
+ ui.painter().with_clip_rect(clip).galley(pos2(tr.left() + 10.0, tr.center().y - g.size().y / 2.0), g, ink);
+ }
// ×
let xr = Rect::from_center_size(pos2(tr.right() - 13.0, tr.center().y), vec2(16.0, 16.0));
let show_close = active || resp.hovered() || ui.rect_contains_pointer(tr);
@@ -1239,6 +1262,62 @@ fn tab_shape(painter: &egui::Painter, t: &Tokens, r: Rect, active: bool, hovered
painter.rect_filled(r, t.radius_md, fill);
}
+/// The longest name a design takes (as `component.rename` accepts).
+const MAX_DESIGN_NAME: usize = 128;
+
+/// Whether the selected tab's design name is being edited in the tab.
+fn renaming_tab(app: &SolveApp) -> bool {
+ app.menu.rename.as_ref().is_some_and(|r| r.inline && matches!(r.what, crate::context_menu::RenameWhat::Component(0)))
+}
+
+/// Starts editing the selected design's name in its tab, with the name as shown selected.
+fn start_tab_rename(app: &mut SolveApp, name: &str, tab: Rect) {
+ let text = crate::i18n::Locale::for_language(&app.preferences.language).given_name(name);
+ app.menu.rename = Some(crate::context_menu::Rename {
+ what: crate::context_menu::RenameWhat::Component(0),
+ text,
+ at: tab.left_bottom(),
+ focused: false,
+ inline: true,
+ });
+}
+
+/// The selected tab's name field: Enter or leaving the field (a click anywhere else) keeps the
+/// name, Escape keeps the old one. A name left as it was, or left blank, changes nothing.
+fn tab_rename_field(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, shown: &str) {
+ let Some(mut rename) = app.menu.rename.take() else { return };
+ let t = Tokens::get();
+ ui.painter().rect_filled(rect, t.radius_sm, t.field);
+ let id = ui.scope_id().with("doc_tab_rename");
+ let response = crate::ui_kit::inline_name(ui, rect.shrink2(vec2(4.0, 0.0)), id, &mut rename.text);
+ if rename.text.chars().count() > MAX_DESIGN_NAME {
+ rename.text = rename.text.chars().take(MAX_DESIGN_NAME).collect();
+ }
+ crate::scenario::publish_target("tab:rename", rect);
+ let was_focused = rename.focused;
+ if !rename.focused {
+ // The whole name selected, so typing replaces it.
+ if let Some(mut state) = egui::TextEdit::load_state(ui.ctx(), id) {
+ let end = rename.text.chars().count();
+ state.cursor.set_char_range(Some(egui::text::CCursorRange::two(egui::text::CCursor::new(0), egui::text::CCursor::new(end))));
+ state.store(ui.ctx(), id);
+ }
+ response.request_focus();
+ rename.focused = true;
+ }
+ let escape = ui.input(|i| i.key_pressed(egui::Key::Escape));
+ let commit = ui.input(|i| i.key_pressed(egui::Key::Enter)) || (was_focused && response.lost_focus());
+ if escape {
+ // Dropping the edit keeps the old name.
+ } else if commit {
+ if rename.text.trim() != shown.trim() {
+ let _ = crate::context_menu::commit_rename(app, &rename);
+ }
+ } else {
+ app.menu.rename = Some(rename);
+ }
+}
+
/// Which tabs the strip shows in `room` points: (first, how many, tab width). Tabs shrink to
/// `MIN_TAB`; past that a window of tabs around the active one is shown and the rest go in the »
/// list.
@@ -1517,6 +1596,96 @@ mod tests {
use crate::Services;
use egui::Color32;
+ /// A harness with the design open (not the start page).
+ fn design_open() -> crate::scenario::Harness {
+ let mut h = crate::scenario::Harness::new();
+ h.app.home.open = false;
+ h.frames(2);
+ h
+ }
+
+ /// A double-click on design tab `i`, as a person gives it.
+ fn double_click_tab(h: &mut crate::scenario::Harness, i: usize) {
+ h.step(&json!({"click": {"handle": format!("tab:design:{i}")}, "double": true})).unwrap();
+ h.frames(2);
+ }
+
+ #[test]
+ fn double_clicking_the_design_tab_renames_the_design_with_enter() {
+ let mut h = design_open();
+ let before = h.app.session.doc.name.clone();
+ double_click_tab(&mut h, 0);
+ assert!(renaming_tab(&h.app), "the tab's name is being edited");
+ assert!(crate::scenario::rect_of("tab:rename").is_some(), "the field is in the tab");
+ // The whole name is selected, so typing replaces it.
+ h.step(&json!({"text": "Bracket"})).unwrap();
+ h.step(&json!({"key": "Enter"})).unwrap();
+ h.frames(2);
+ assert_eq!(h.app.session.doc.name, "Bracket");
+ assert_eq!(tabs_info(&h.app).first().map(|(name, _)| name.as_str()), Some("Bracket"), "the tab shows it");
+ assert!(!renaming_tab(&h.app) && crate::scenario::rect_of("tab:rename").is_none(), "the field closed");
+ h.app.run("edit.undo", json!({})).unwrap();
+ assert_eq!(h.app.session.doc.name, before, "a rename is undone like any change");
+ }
+
+ #[test]
+ fn clicking_elsewhere_keeps_the_new_name() {
+ let mut h = design_open();
+ double_click_tab(&mut h, 0);
+ let narrow = crate::scenario::rect_of("tab:rename").unwrap().width();
+ h.step(&json!({"text": "Hinge bracket, left"})).unwrap();
+ h.frames(1);
+ let wide = crate::scenario::rect_of("tab:rename").unwrap().width();
+ assert!(wide > narrow, "the tab grows with the name typed: {narrow} then {wide}");
+ h.step(&json!({"click": [800.0, 600.0]})).unwrap();
+ h.frames(2);
+ assert_eq!(h.app.session.doc.name, "Hinge bracket, left");
+ assert!(!renaming_tab(&h.app));
+ }
+
+ #[test]
+ fn escape_a_blank_name_or_the_same_name_change_nothing() {
+ for finish in ["escape", "blank", "same"] {
+ let mut h = design_open();
+ let (before, undo) = (h.app.session.doc.name.clone(), h.app.session.undo.len());
+ double_click_tab(&mut h, 0);
+ match finish {
+ "escape" => {
+ h.step(&json!({"text": "Discarded"})).unwrap();
+ h.step(&json!({"key": "Escape"})).unwrap();
+ }
+ "blank" => {
+ h.step(&json!({"text": " "})).unwrap();
+ h.step(&json!({"key": "Enter"})).unwrap();
+ }
+ _ => h.step(&json!({"key": "Enter"})).unwrap(),
+ }
+ h.frames(2);
+ assert_eq!((h.app.session.doc.name.clone(), h.app.session.undo.len()), (before, undo), "{finish}: unchanged");
+ assert!(!h.app.session.is_dirty(), "{finish}: nothing to save");
+ assert!(!renaming_tab(&h.app), "{finish}: the field closed");
+ }
+ }
+
+ #[test]
+ fn a_name_longer_than_a_design_takes_is_cut_to_fit() {
+ let mut h = design_open();
+ double_click_tab(&mut h, 0);
+ h.step(&json!({"text": "x".repeat(MAX_DESIGN_NAME + 40)})).unwrap();
+ h.step(&json!({"key": "Enter"})).unwrap();
+ h.frames(2);
+ assert_eq!(h.app.session.doc.name, "x".repeat(MAX_DESIGN_NAME), "the command takes it, cut to 128 characters");
+ }
+
+ #[test]
+ fn with_the_preference_off_a_double_click_does_not_rename() {
+ let mut h = design_open();
+ h.call("ui.prefs", json!({"tab_double_click_renames": false}));
+ h.frames(2);
+ double_click_tab(&mut h, 0);
+ assert!(!renaming_tab(&h.app) && crate::scenario::rect_of("tab:rename").is_none());
+ }
+
/// #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. #11408: a saved design with
/// changes not saved yet says so below, since a cut name hides the tab's bullet.
diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs
index ca3f9556ce..4e8b0f8c2b 100644
--- a/crates/ui-egui/src/prefs.rs
+++ b/crates/ui-egui/src/prefs.rs
@@ -1321,6 +1321,9 @@ preference_settings! {
/// click shows its panels over the view until a command starts or the pointer leaves them.
/// Off by default: the whole ribbon shows. `view.ribbon_tabs_only` switches it.
ribbon_tabs_only: bool = false, PAGE_LAYOUT;
+ /// A double-click on a design tab renames the design in the tab; off, it maximizes the window
+ /// as the rest of the title bar does, as before.
+ tab_double_click_renames: bool = true, PAGE_LAYOUT;
/// Where a dialog's OK and Cancel sit: under its inputs (the default) or in its title row (#6708).
dialog_buttons: crate::ui_kit::DialogButtons = Default::default(), PAGE_LAYOUT;
/// Where notices and offers stack: the view's bottom-right corner (the default) or the bottom
@@ -6255,6 +6258,7 @@ mod tests {
("sketch_tab_always", json!(true), PAGE_LAYOUT),
("keep_work_on_tab_switch", json!(true), PAGE_LAYOUT),
("ribbon_reveal", json!(true), PAGE_LAYOUT),
+ ("tab_double_click_renames", json!(false), PAGE_LAYOUT),
("dialog_buttons", json!("top"), PAGE_LAYOUT),
("toast_place", json!("centre"), PAGE_LAYOUT),
("ribbon_icon_grid", json!(true), PAGE_LAYOUT),
diff --git a/crates/ui-egui/src/prefs/interface.rs b/crates/ui-egui/src/prefs/interface.rs
index c3e00d8674..dd8951b4aa 100644
--- a/crates/ui-egui/src/prefs/interface.rs
+++ b/crates/ui-egui/src/prefs/interface.rs
@@ -298,6 +298,13 @@ pub(super) fn layout(app: &mut SolveApp, ui: &mut egui::Ui) {
&mut app.preferences.keep_work_on_tab_switch,
"keep_work_on_tab_switch",
);
+ layout_check(
+ ui,
+ app.tr("prefs.tab_double_click_renames"),
+ app.tr("prefs.tab_double_click_renames_note"),
+ &mut app.preferences.tab_double_click_renames,
+ "tab_double_click_renames",
+ );
});
if let Some(rect) = crate::scenario::rect_of(&format!("dialog:section:{}", app.tr("prefs.layout_page.window"))) {
crate::scenario::publish_target(&format!("dialog:section:{}", app.tr("prefs.layout")), rect);
diff --git a/docs/book/src/guide/ui-tour.md b/docs/book/src/guide/ui-tour.md
index 6e3170091b..924a0a0cd9 100644
--- a/docs/book/src/guide/ui-tour.md
+++ b/docs/book/src/guide/ui-tour.md
@@ -14,8 +14,11 @@ view.
- **Title bar.** On Windows and Linux the application bar is the window's title bar. On the left:
the File menu (New, Open, Save, Save As, Export…), undo and redo, the Home tab (the start page)
and one tab per open design (each with its own undo history, selection and camera; a dot marks
- unsaved changes). On the right: Report a bug, Help (?), Preferences (which hold the theme) and the
- window's buttons. On Linux, to have your desktop's own title bar and window buttons instead, set
+ unsaved changes). Double-click a design's tab to rename the design: type the name, then press
+ Enter or click elsewhere to keep it, or Esc to leave the old one (Preferences › Interface turns
+ this off, for a double-click that maximizes the window instead). On the right: Report a bug,
+ Help (?), Preferences (which hold the theme) and the window's buttons. On Linux, to have your
+ desktop's own title bar and window buttons instead, set
`SOLIDCRAFT_TITLEBAR=system` or put `"titlebar": "system"` in `graphics.json` in the settings
folder (see [Troubleshooting](troubleshooting.md#reset-the-settings)) and restart; `app` (the
default) puts the application bar back.
diff --git a/docs/control-protocol.md b/docs/control-protocol.md
index 9eb26c4b8b..942fc840c9 100644
--- a/docs/control-protocol.md
+++ b/docs/control-protocol.md
@@ -924,6 +924,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own
- `stand_up_unknown` (`note` (default: a file whose header names no program known to save Y up and whose bodies seem to lie on their back (their flat area across Y outweighs their flat area facing down Z) gets a small note over the view, "Did this part open the wrong way up?", with Stand it up and Don't ask again as the handles `stand_up:stand` and `stand_up:never`, and its close (×) as `toast:stand_up:close` (also `stand_up:dismiss`); it goes by itself after 10 seconds and never blocks input), `ask` (the "Stand this part up?" dialog for every file from another program, SolidWorks too, without looking at how it rests, as before #7717), `off` (no offer); otherwise a SolidWorks file gets the dialog, or the note when its bodies clearly stand on Z already)
- `status_bar` (default false: a thin bar along the window's bottom edge, below History, handle `status:bar`: what is being edited (`status:editing`), the open sketch's state in its colour (`status:sketch`) and the design's units (`status:units`, a click opens the Units menu, whose rows run `document.units`); the sketch's state then leaves the view's top-left corner, #7243)
- `step_values` (default false: Up/Down and the wheel step a plain number in a focused value field)
+- `tab_double_click_renames` (default true: a double-click on the selected design's tab edits its name in the tab, handle `tab:rename`; Enter or a click elsewhere keeps the name through `component.rename` with `component: 0`, Esc cancels, and a name left as it was or blank changes nothing; false: a double-click on a tab maximizes the window, as the bar's empty space does, as before)
- `theme` (`dark`, `light`, `system` or a theme file's id: a built-in one such as `gruvbox-dark`, or an imported one; the reply's `theme_ids` lists them)
- `theme_export: true` (the reply's `theme_file` is the active theme, including a followed file; themes with options retain their authored definitions, defaults and overlays, while older themes keep the complete snapshot shape; saved option values are excluded; see [colour themes](book/src/guide/ui-tour.md#colour-themes))
- `theme_follow` (desktop only, default `""`: a `solidcraft-theme/1` file's path to follow as the theme, reloaded within about a second whenever it changes and when the window gains the focus; the file is read at once, and a file that doesn't read keeps the last good theme; `""` stops following, as does setting `theme`; in the browser it is an error; the launch flag `--theme-file PATH` follows a file for one run without saving it; the reply's `theme_followed` is the path followed now or null, and `theme_follow_error` why its last read was not applied, or null)