Skip to content

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

Status line: say which design an Open or Insert brought in (#7858) (#7869)

Christian Hammacher020e3bebe391
diff --git a/assets/locales/pending/opened-status.json b/assets/locales/pending/opened-status.json
new file mode 100644
index 0000000000..861d98eb7d
--- /dev/null
+++ b/assets/locales/pending/opened-status.json
@@ -0,0 +1,42 @@
+{
+ "en": {
+ "file_load.inserted": "Inserted {name}",
+ "file_load.opened": "Opened {name}",
+ "file_load.opened_in_tab": "Opened {name} in a new tab"
+ },
+ "ar": {
+ "file_load.inserted": "تم إدراج {name}",
+ "file_load.opened": "تم فتح {name}",
+ "file_load.opened_in_tab": "تم فتح {name} في علامة تبويب جديدة"
+ },
+ "de": {
+ "file_load.inserted": "{name} eingefügt",
+ "file_load.opened": "{name} geöffnet",
+ "file_load.opened_in_tab": "{name} in neuem Tab geöffnet"
+ },
+ "he": {
+ "file_load.inserted": "{name} הוכנס",
+ "file_load.opened": "{name} נפתח",
+ "file_load.opened_in_tab": "{name} נפתח בלשונית חדשה"
+ },
+ "ja": {
+ "file_load.inserted": "{name} を挿入しました",
+ "file_load.opened": "{name} を開きました",
+ "file_load.opened_in_tab": "{name} を新しいタブで開きました"
+ },
+ "ko": {
+ "file_load.inserted": "{name}을(를) 삽입했습니다",
+ "file_load.opened": "{name}을(를) 열었습니다",
+ "file_load.opened_in_tab": "{name}을(를) 새 탭에서 열었습니다"
+ },
+ "vi": {
+ "file_load.inserted": "Đã chèn {name}",
+ "file_load.opened": "Đã mở {name}",
+ "file_load.opened_in_tab": "Đã mở {name} trong thẻ mới"
+ },
+ "zh": {
+ "file_load.inserted": "已插入 {name}",
+ "file_load.opened": "已打开 {name}",
+ "file_load.opened_in_tab": "已在新标签页中打开 {name}"
+ }
+}
diff --git a/crates/ui-egui/src/documents.rs b/crates/ui-egui/src/documents.rs
index e6b4df799f..ed7c19478b 100644
--- a/crates/ui-egui/src/documents.rs
+++ b/crates/ui-egui/src/documents.rs
@@ -461,8 +461,8 @@ pub fn active_is_blank(app: &SolveApp) -> bool {
}
/// Show `session` (a design built or read elsewhere): in place of a blank active design,
-/// otherwise in a new tab.
-pub fn adopt(app: &mut SolveApp, session: Session) {
+/// otherwise in a new tab. Whether it is shown (no tab left for it: the status says so).
+pub fn adopt(app: &mut SolveApp, session: Session) -> bool {
if active_is_blank(app) {
let rev = app.session.revision;
crate::browser::discard_reveals(app);
@@ -482,8 +482,12 @@ pub fn adopt(app: &mut SolveApp, session: Session) {
// The linked designs that changed while it was closed are read again (#9739): last, as a
// read is taken up only by the design revision it started from.
crate::linked_source::update_changed(app);
+ true
} else if let Err(e) = open_tab(app, session) {
app.set_status(e, true);
+ false
+ } else {
+ true
}
}
diff --git a/crates/ui-egui/src/file_load.rs b/crates/ui-egui/src/file_load.rs
index 5b5468a5e0..efc53d4fb5 100644
--- a/crates/ui-egui/src/file_load.rs
+++ b/crates/ui-egui/src/file_load.rs
@@ -464,6 +464,9 @@ fn start(app: &mut SolveApp) {
{
let e = "too many open designs; close a tab before opening another";
app.set_status(e, true);
+ if let Kind::Recover { id, dir } = &request.kind {
+ reoffer(app, id, dir.as_deref());
+ }
request.answer(Err(e.into()));
return;
}
@@ -1066,15 +1069,25 @@ pub fn tick(app: &mut SolveApp, ctx: &egui::Context) {
request.answer(r);
}
Ok(_) if reuse_open(app, request) => {}
- Ok(made) if running.matches(&app.session) => {
+ Ok(made) if running.matches(&app.session) => 'open: {
// Not meshed yet: framing it while it goes in must not mesh it here.
app.open_meshing_next = true;
crate::frame_watch::step(app, "before the open");
+ let tabs = app.docs.count();
if request.insert() {
app.session.accept_computed(made.session);
app.big_operation = true;
} else {
- crate::agent_chat::with_tool_request(app, request.chat_turn.as_ref(), |app| crate::documents::adopt(app, made.session));
+ // No tab left for it: `adopt` said why, and nothing else of the open happens.
+ if !crate::agent_chat::with_tool_request(app, request.chat_turn.as_ref(), |app| crate::documents::adopt(app, made.session)) {
+ app.open_meshing_next = false;
+ // A design to recover stays offered, as when its read fails.
+ if let Kind::Recover { id, dir } = &request.kind {
+ reoffer(app, id, dir.as_deref());
+ }
+ request.answer(Err(app.status.as_ref().map_or_else(String::new, |s| s.0.clone())));
+ break 'open;
+ }
if request.kind == Kind::Open {
app.home.add_recent(&request.path);
}
@@ -1102,7 +1115,29 @@ pub fn tick(app: &mut SolveApp, ctx: &egui::Context) {
} else if let Some(w) = warnings.filter(|w| !w.is_empty()) {
format!("imported with {} warning(s): {}", w.len(), w.first().and_then(Value::as_str).unwrap_or(""))
} else {
- format!("{} done", if request.insert() { "Insert" } else { "Open" })
+ // Built here, outside the window's language scope: in the language
+ // chosen, as the other statuses of this file are.
+ let language = crate::i18n::Locale::for_language(&app.preferences.language);
+ // An opened design is named as its tab names it, an inserted one as
+ // its component is named.
+ let name = if request.insert() {
+ made.result.get("component_name").and_then(Value::as_str).map(str::to_string).unwrap_or_else(|| {
+ std::path::Path::new(&request.path)
+ .file_stem()
+ .map_or_else(|| request.path.clone(), |n| n.to_string_lossy().into_owned())
+ })
+ } else {
+ language.given_name(&app.session.doc.name)
+ };
+ // A blank design is replaced in place; anything else gets a tab of its own.
+ let key = if request.insert() {
+ "file_load.inserted"
+ } else if app.docs.count() > tabs {
+ "file_load.opened_in_tab"
+ } else {
+ "file_load.opened"
+ };
+ language.format(key, &[("name", &name)])
},
false,
);
@@ -1380,6 +1415,45 @@ mod tests {
});
}
+ /// An Open says which design it brought in, by the name its tab shows, and whether it took
+ /// a tab of its own or replaced the blank design.
+ #[test]
+ fn an_open_names_the_design_and_says_when_it_got_a_new_tab() {
+ let ctx = egui::Context::default();
+ let mut app = SolveApp::new(Session::default(), Default::default());
+ let open = |app: &mut SolveApp, name: &str| {
+ let mut part = Session::default();
+ part.execute("solid.box", &json!({"length": 10, "width": 10, "height": 10})).unwrap();
+ Arc::make_mut(&mut part.doc).name = name.into();
+ part.path = Some(format!("{name}.solidcraft"));
+ completed_open(app, Request::new(&format!("{name}.solidcraft"), Kind::Open), part);
+ tick(app, &ctx);
+ app.status.clone().map(|s| (s.0, s.2)).unwrap_or_default()
+ };
+ assert_eq!(open(&mut app, "plate"), ("Opened plate".into(), false), "the blank design is replaced in its tab");
+ assert_eq!(app.docs.count(), 1);
+ assert_eq!(open(&mut app, "post"), ("Opened post in a new tab".into(), false));
+ assert_eq!(app.docs.count(), 2);
+ // In the language chosen, though the status is set outside the window's language scope
+ app.preferences.language = "de".into();
+ assert_eq!(open(&mut app, "knob"), ("knob in neuem Tab geöffnet".into(), false));
+ // No tab left (and no blank design to take): the open says so, and names nothing it did not open
+ while app.docs.count() < crate::documents::MAX_OPEN {
+ let mut saved = Session::default();
+ saved.path = Some(format!("tab{}.solidcraft", app.docs.count()));
+ crate::documents::open_tab(&mut app, saved).unwrap();
+ }
+ let mut request = Request::new("full.solidcraft", Kind::Open);
+ let (tx, reply) = std::sync::mpsc::channel();
+ request.reply = Some(tx);
+ completed_open(&mut app, request, Session::default());
+ tick(&mut app, &ctx);
+ let (status, _, error) = app.status.clone().unwrap_or_default();
+ assert!(error && status.contains(&crate::documents::MAX_OPEN.to_string()), "{status}");
+ assert_eq!(app.docs.count(), crate::documents::MAX_OPEN);
+ assert!(reply.try_recv().is_ok_and(|r| r["ok"] == json!(false)), "the caller hears it failed");
+ }
+
#[test]
fn repeated_queued_opens_reply_once_and_keep_one_session() {
let mut app = SolveApp::new(Session::default(), Default::default());
@@ -1775,7 +1849,7 @@ mod tests {
frames += 1;
}
assert_eq!(bodies(&app), 6, "{:?}", app.status);
- assert!(app.status.as_ref().is_some_and(|s| s.0.contains("Insert done")), "{:?}", app.status);
+ assert_eq!(app.status.as_ref().map(|s| s.0.as_str()), Some("Inserted boxes"), "named as its component is");
// Cancelled after the parse: nothing is inserted, and nothing waits.
let before = app.session.doc.clone();
app.file_load.queued.push_back(Request::new(&path, Kind::Insert));
@@ -1838,7 +1912,7 @@ mod tests {
tick(&mut app, &ctx);
frames += 1;
}
- assert!(app.status.as_ref().is_some_and(|s| s.0.contains("Open done")), "{:?}", app.status);
+ assert_eq!(app.status.as_ref().map(|s| s.0.as_str()), Some("Opened staged"), "named as its tab is");
assert_eq!(app.session.path.as_deref(), Some(path.as_str()));
assert_eq!(app.session.doc, whole.doc);
assert_eq!(names(&app.session), names(&whole));