Insert Design: pick one of the other open designs, or browse for a file (#8570) (#8571)

* claim: #8570

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

* Insert Design: pick one of the other open designs, or browse for a file (#8570)

With other designs open in tabs, Insert Design first lists them under the
button: one click inserts a saved one as a linked component; one with
unsaved changes inserts its saved file and the status line says so; one
never saved is greyed out, as there is no file to link. Browse... opens
the file picker, as the button did before, and it still goes straight
there with no other design open.

Preferences > Design > Linked designs > "Insert Design lists the designs
open in other tabs first" (insert_lists_open_designs) turns the list off.

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

* Insert Design list: sit with the other menus' items, so run_item keeps its doc comment

Review on #8571: insert_design_items had landed between run_item and its comment. The
rebased menu-walk list keeps main's Target::HistoryControls beside Target::InsertDesign.

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:
RyanandClaude Opus 5.5 authored and GitHub committed 2026-10-29 17:11:25 +00:00
1 parent 6ebfe91661
commit d05a114241
9 files changed
+248 -15

No files matched your search

@@ -0,0 +1,58 @@
{
"en": {
"settings.insert_lists_open_designs": "Insert Design lists the designs open in other tabs first",
"ui.insert_design.browse": "Browse…",
"ui.insert_design.open_designs": "Open designs",
"ui.insert_design.saved_file": "{name} has unsaved changes, so its saved file was inserted. Save it, then Update Links to bring the changes in.",
"ui.insert_design.unsaved": "Unsaved changes"
},
"ar": {
"settings.insert_lists_open_designs": "يعرض إدراج تصميم أولًا التصاميم المفتوحة في علامات التبويب الأخرى",
"ui.insert_design.browse": "استعراض…",
"ui.insert_design.open_designs": "التصاميم المفتوحة",
"ui.insert_design.saved_file": "في {name} تغييرات غير محفوظة، لذا أُدرج ملفه المحفوظ. احفظه، ثم استخدم تحديث الروابط لإدخال التغييرات.",
"ui.insert_design.unsaved": "تغييرات غير محفوظة"
},
"de": {
"settings.insert_lists_open_designs": "Konstruktion einfügen zeigt zuerst die in anderen Tabs geöffneten Konstruktionen",
"ui.insert_design.browse": "Durchsuchen…",
"ui.insert_design.open_designs": "Geöffnete Konstruktionen",
"ui.insert_design.saved_file": "{name} hat ungespeicherte Änderungen, daher wurde die gespeicherte Datei eingefügt. Speichern Sie sie und wählen Sie dann Verknüpfungen aktualisieren, um die Änderungen zu übernehmen.",
"ui.insert_design.unsaved": "Ungespeicherte Änderungen"
},
"he": {
"settings.insert_lists_open_designs": "הוספת תכן מציגה קודם את התכנים הפתוחים בלשוניות אחרות",
"ui.insert_design.browse": "עיון…",
"ui.insert_design.open_designs": "תכנים פתוחים",
"ui.insert_design.saved_file": "ב-{name} יש שינויים שלא נשמרו, ולכן נוסף הקובץ השמור שלו. שמרו אותו ואז בחרו עדכון קישורים כדי להכניס את השינויים.",
"ui.insert_design.unsaved": "שינויים שלא נשמרו"
},
"ja": {
"settings.insert_lists_open_designs": "デザインを挿入で、ほかのタブで開いているデザインを先に表示する",
"ui.insert_design.browse": "参照…",
"ui.insert_design.open_designs": "開いているデザイン",
"ui.insert_design.saved_file": "{name} に保存されていない変更があるため、保存済みのファイルを挿入しました。保存してから、リンクを更新で変更を取り込んでください。",
"ui.insert_design.unsaved": "未保存の変更"
},
"ko": {
"settings.insert_lists_open_designs": "설계 삽입에서 다른 탭에 열린 설계를 먼저 표시",
"ui.insert_design.browse": "찾아보기…",
"ui.insert_design.open_designs": "열린 설계",
"ui.insert_design.saved_file": "{name}에 저장되지 않은 변경 사항이 있어 저장된 파일을 삽입했습니다. 저장한 다음 링크 업데이트로 변경 사항을 가져오세요.",
"ui.insert_design.unsaved": "저장되지 않은 변경 사항"
},
"vi": {
"settings.insert_lists_open_designs": "Chèn thiết kế vào cụm liệt kê trước các thiết kế đang mở ở các thẻ khác",
"ui.insert_design.browse": "Duyệt…",
"ui.insert_design.open_designs": "Thiết kế đang mở",
"ui.insert_design.saved_file": "{name} có thay đổi chưa lưu, nên tệp đã lưu của nó đã được chèn. Hãy lưu nó, rồi dùng Cập nhật liên kết để đưa các thay đổi vào.",
"ui.insert_design.unsaved": "Thay đổi chưa lưu"
},
"zh": {
"settings.insert_lists_open_designs": "插入设计时先列出其他标签页中打开的设计",
"ui.insert_design.browse": "浏览…",
"ui.insert_design.open_designs": "已打开的设计",
"ui.insert_design.saved_file": "{name} 有未保存的更改,因此插入的是其已保存的文件。请先保存,再使用“更新链接”导入这些更改。",
"ui.insert_design.unsaved": "未保存的更改"
}
}
+42
View File
@@ -63,6 +63,8 @@ pub enum Target {
Origin,
/// Document Settings › Units.
Units,
/// Insert › Insert Design: the designs open in other tabs, and Browse… (#8570).
InsertDesign,
/// The mouse mappings (Preferences › Navigation), from the status bar (#7023).
Navigation,
/// An assembly joint.
@@ -428,6 +430,7 @@ pub fn items(app: &SolveApp, target: &Target) -> Vec<Item> {
})
.collect(),
Target::NamedView { name } => crate::browser::view_items(app, name),
Target::InsertDesign => insert_design_items(app),
};
if !crate::render_workspace::active(app) {
v.extend(crate::browser::folded_folder_items(app, target));
@@ -1243,6 +1246,30 @@ fn menu_sketch_point(app: &SolveApp, plane: &solidcraft_engine::geom::Plane) ->
Some(plane.to_local(plane.intersect_ray(o, d)?))
}
/// Insert Design's list (#8570): each design open in another tab, inserted with one click (its
/// file name beside it; one not saved yet greyed out, as there is no file to link), then
/// Browse… for a file, as the button did before.
fn insert_design_items(app: &SolveApp) -> Vec<Item> {
let mut v = vec![Item::heading("Open designs")];
for d in crate::documents::other_designs(app) {
let file = d.path.as_deref().map(|p| std::path::Path::new(p).file_name().map_or(p.to_string(), |f| f.to_string_lossy().into_owned()));
let note = match (&file, d.unsaved) {
(None, _) => "Not saved yet".to_string(),
(Some(_), true) => "Unsaved changes".to_string(),
(Some(file), false) => file.clone(),
};
v.push(
act("ui.insertOpenDesign", &d.name, "component")
.key(&note)
.on(d.path.is_some())
.with(json!({"path": d.path, "name": d.name, "unsaved": d.unsaved})),
);
}
v.push(Item::sep());
v.push(act("ui.insertBrowse", "Browse…", "open"));
v
}
// ---------------------------------------------------------------------------------------------
// Running an item
// ---------------------------------------------------------------------------------------------
@@ -1401,6 +1428,21 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) {
crate::design_properties::open_object(app, command, &params, fallback);
}
"ui.designProperties" => app.start("document.metadata"),
"ui.insertOpenDesign" => {
let (Some(path), name) = (p.get("path").and_then(Value::as_str), p.get("name").and_then(Value::as_str).unwrap_or_default()) else {
return;
};
// The design is open here, so its file's place is already the user's choice.
let hosts: Vec<String> = solidcraft_engine::io::vfs::network_host(path).into_iter().collect();
let inserted = solidcraft_engine::io::vfs::allowing_hosts(&hosts, || app.run("component.insert_design", json!({ "path": path })));
if inserted.is_ok() {
app.fit_view();
if p.get("unsaved").and_then(Value::as_bool) == Some(true) {
app.set_status(crate::i18n::format("ui.insert_design.saved_file", &[("name", name)]), false);
}
}
}
"ui.insertBrowse" => app.pick_design_to_insert(),
"ui.export" => {
let name = bodies.first().cloned().unwrap_or_else(|| app.session.doc.name.clone());
app.pick_save_command(&format!("{name}.step"), &["step", "stp", "igs", "stl", "3mf", "obj"], "file.export", json!({"bodies": bodies}));
+20
View File
@@ -618,6 +618,26 @@ pub fn tabs_info(app: &SolveApp) -> Vec<(String, bool)> {
.collect()
}
/// A design open in another tab, as Insert Design offers it (#8570): its name, its file (`None`:
/// not saved yet, so there is nothing to link) and whether it has unsaved changes.
pub(crate) struct OpenDesign {
pub name: String,
pub path: Option<String>,
pub unsaved: bool,
}
/// The designs open in the other tabs, in tab order: none on the shown design's file, and no
/// blank one (an empty new design has nothing to insert).
pub(crate) fn other_designs(app: &SolveApp) -> Vec<OpenDesign> {
let shown = app.session.path.as_deref();
app.docs
.background()
.filter(|s| s.path.is_some() || !s.doc.features.is_empty())
.filter(|s| !s.path.as_deref().zip(shown).is_some_and(|(a, b)| same_path(a, b)))
.map(|s| OpenDesign { name: s.doc.name.clone(), path: s.path.clone(), unsaved: s.is_dirty() })
.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() {
+10 -1
View File
@@ -33,7 +33,16 @@ fn take(app: &SolveApp, out: &mut BTreeSet<String>) {
let components: Vec<u64> = app.session.doc.components.iter().map(|c| c.id).collect();
let groups: Vec<u64> = app.session.doc.browser_groups.iter().map(|g| g.id).collect();
for target in [Target::Viewport, Target::Origin, Target::Units, Target::Toolbar, Target::HistoryControls, Target::Workspace, Target::NamedViews] {
for target in [
Target::Viewport,
Target::Origin,
Target::Units,
Target::Toolbar,
Target::HistoryControls,
Target::Workspace,
Target::NamedViews,
Target::InsertDesign,
] {
take_items(out, &context_menu::items(app, &target));
}
for name in &bodies {
+27 -13
View File
@@ -1375,6 +1375,24 @@ impl SolveApp {
self.start_at(id, None);
}
/// Insert Design's file picker: another design becomes a linked component; a STEP or mesh
/// file picked here is inserted the way Insert STEP or Insert Mesh would (#1240).
pub(crate) fn pick_design_to_insert(&mut self) {
self.pick_open(|app, path| {
let Some(path) = path else { return };
if solidcraft_engine::io::is_design_path(&path) {
// Picked in the file dialog: its server is the user's choice.
let hosts: Vec<String> = solidcraft_engine::io::vfs::network_host(&path).into_iter().collect();
let inserted = solidcraft_engine::io::vfs::allowing_hosts(&hosts, || app.run("component.insert_design", json!({ "path": path })));
if inserted.is_ok() {
app.fit_view();
}
} else {
app.insert_path_async(&path);
}
});
}
/// Start an interactive command with its menu anchored below the invoking button.
pub(crate) fn start_at(&mut self, id: &str, opener: Option<egui::Rect>) {
self.start_with_variant_memory(id, true, opener);
@@ -1589,21 +1607,17 @@ impl SolveApp {
return;
}
if id == "component.insert_design" {
// Another design becomes a linked component; a STEP or mesh file picked here is
// inserted the way Insert STEP or Insert Mesh would (#1240).
self.pick_open(|app, path| {
let Some(path) = path else { return };
if solidcraft_engine::io::is_design_path(&path) {
// Picked in the file dialog: its server is the user's choice.
let hosts: Vec<String> = solidcraft_engine::io::vfs::network_host(&path).into_iter().collect();
let inserted = solidcraft_engine::io::vfs::allowing_hosts(&hosts, || app.run("component.insert_design", json!({ "path": path })));
if inserted.is_ok() {
app.fit_view();
}
// The designs open in other tabs first, each a click away, then Browse… (#8570).
if self.preferences.insert_lists_open_designs && !documents::other_designs(self).is_empty() {
if let Some(rect) = opener {
context_menu::toggle_for(self, rect, rect.left_bottom(), context_menu::Target::InsertDesign);
} else {
app.insert_path_async(&path);
let at = self.viewport.rect.map(|rect| rect.center()).unwrap_or(egui::pos2(300.0, 200.0));
context_menu::open_for(self, at, context_menu::Target::InsertDesign);
}
});
} else {
self.pick_design_to_insert();
}
return;
}
if id == "component.relink" {
+81
View File
@@ -1810,3 +1810,84 @@ mod browser_rows {
assert!(h.app.viewport.context_menu.is_none(), "a click outside the menu closes it");
}
}
/// #8570: Insert Design lists the designs open in other tabs. One click inserts a saved one; one
/// with unsaved changes inserts its saved file and says so; one never saved is greyed out, as there
/// is no file to link. Browse… opens the file picker. Alone, or with the preference off, the
/// button goes straight to the picker, as before.
#[test]
fn insert_design_offers_the_other_open_designs_then_browse() {
let mut h = crate::scenario::Harness::new();
let open = |dir: &std::path::Path, file: &str, size: f64| {
let path = dir.join(file);
let mut s = Session::default();
s.execute("solid.box", &json!({"length": size, "width": size, "height": size})).unwrap();
s.execute("file.save", &json!({"path": path})).unwrap();
let mut opened = Session::default();
opened.execute("doc.open", &json!({"path": path})).unwrap();
opened
};
let linked = |app: &SolveApp, file: &str| app.session.doc.links.values().filter(|l| l.path.ends_with(file)).count();
let menu_open = |app: &SolveApp| app.viewport.context_menu.is_some() && app.menu.target == Target::InsertDesign;
// Alone: the picker, as before.
h.step(&json!({"choose_file": "none.solidcraft"})).unwrap();
h.app.start("component.insert_design");
assert!(!menu_open(&h.app));
h.frames(3);
context_menu::close(&mut h.app);
let dir = h.dir.clone();
crate::documents::open_tab(&mut h.app, open(&dir, "bracket.solidcraft", 10.0)).unwrap();
crate::documents::open_tab(&mut h.app, open(&dir, "plate.solidcraft", 20.0)).unwrap();
h.app.run("solid.box", json!({"length": 5, "width": 5, "height": 5, "corner": [40, 0, 0]})).unwrap();
crate::documents::open_tab(&mut h.app, Session::default()).unwrap();
h.app.run("solid.box", json!({"length": 5, "width": 5, "height": 5})).unwrap();
crate::documents::open_tab(&mut h.app, Session::default()).unwrap();
crate::documents::switch(&mut h.app, 0);
h.app.run("solid.box", json!({"length": 1, "width": 1, "height": 1, "body_name": "Base"})).unwrap();
h.app.start("component.insert_design");
assert!(menu_open(&h.app));
let items = context_menu::items(&h.app, &Target::InsertDesign);
let rows: Vec<(&str, &str, bool)> = items.iter().map(|i| (i.label.as_str(), i.shortcut.as_str(), i.enabled)).collect();
let names: Vec<String> = h.app.docs.background().map(|s| s.doc.name.clone()).collect();
assert_eq!(
rows,
[
("Open designs", "", false),
(names[0].as_str(), "bracket.solidcraft", true),
(names[1].as_str(), "Unsaved changes", true),
(names[2].as_str(), "Not saved yet", false),
("", "", false),
("Browse…", "", true),
],
"a saved design, one with unsaved changes, one never saved; not the blank new tab"
);
act(&mut h.app, &Target::InsertDesign, &names[0]);
assert_eq!(linked(&h.app, "bracket.solidcraft"), 1);
assert!(h.app.status.as_ref().is_none_or(|(s, _, _)| !s.contains("unsaved")), "{:?}", h.app.status);
act(&mut h.app, &Target::InsertDesign, &names[1]);
assert_eq!(linked(&h.app, "plate.solidcraft"), 1);
assert!(
h.app.status.as_ref().is_some_and(|(s, _, error)| !*error && s.contains("unsaved changes") && s.contains("Update Links")),
"{:?}",
h.app.status
);
// Browse…: the picker, for any file on disk.
h.step(&json!({"choose_file": "bracket.solidcraft"})).unwrap();
act(&mut h.app, &Target::InsertDesign, "Browse…");
h.frames(3);
assert_eq!(linked(&h.app, "bracket.solidcraft"), 2);
// The preference off: straight to the picker.
h.app.preferences.insert_lists_open_designs = false;
context_menu::close(&mut h.app);
h.step(&json!({"choose_file": "plate.solidcraft"})).unwrap();
h.app.start("component.insert_design");
assert!(!menu_open(&h.app));
h.frames(3);
assert_eq!(linked(&h.app, "plate.solidcraft"), 2);
}
+3
View File
@@ -973,6 +973,9 @@ preference_settings! {
/// a double-click in the browser activates every component and one in the view does nothing,
/// as before.
double_click_components: bool = true, PAGE_DESIGN => check_id("settings.double_click_components");
/// Insert Design lists the designs open in other tabs, each inserted with one click, then
/// Browse… for a file (#8570). Off: it opens the file picker at once, as before.
insert_lists_open_designs: bool = true, PAGE_DESIGN => check_id("settings.insert_lists_open_designs");
/// Reopen the saved designs that were open when the app was last closed (#5542).
reopen_designs: bool = true, PAGE_GENERAL;
/// Those designs' files, in tab order, as the last quit left them.
+1
View File
@@ -119,6 +119,7 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
ui_kit::settings_section(ui, "linked_designs", app.tr("prefs.linked_designs"), |ui| {
setting::update_changed_links(app, ui);
setting::double_click_components(app, ui);
setting::insert_lists_open_designs(app, ui);
});
// Where the files a design names may be: never a network location the user hasn't allowed.
ui_kit::settings_section(ui, "network_locations", app.tr("prefs.network_locations_section"), |ui| {
+6 -1
View File
@@ -373,7 +373,12 @@ leaves the design as it was unless `apply` is true.
**Insert Design** (`component.insert_design {path, translate?}`, on the **ASSEMBLE** panel and
in the **File** menu) adds a component linked to another saved design, so each part can live in
its own document. A STEP or mesh file picked there is inserted as **Insert STEP** or **Insert
its own document. When other designs are open in tabs, the button first lists them under
**Open designs**. One click inserts that design; a design not saved yet is greyed out, as it has no
file to link; one with unsaved changes inserts its saved file, and the status line says so.
**Browse…** at the end opens the file picker, as the button does when no other design is open.
Preferences › Design › **Insert Design lists the designs open in other tabs first** turns the list
off. A STEP or mesh file picked there is inserted as **Insert STEP** or **Insert
Mesh** would. The part's solid bodies come
in as they sit in that design, and they are kept in the assembly, so it opens even without the
part file. The link is stored relative to the assembly's folder once the assembly is saved.