From b65f1696b2bc8d11927897e1edf333316eaf469b Mon Sep 17 00:00:00 2001 From: jyviko <2501648+jyviko@users.noreply.github.com> Date: Thu, 15 Oct 2026 08:28:30 -0400 Subject: [PATCH] ui: name a sample's document after it until saved (#334); "Solve cancelled" Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UhhZMBTviDQxZvwnyP89fo --- crates/engine/src/cmd/file.rs | 1 + crates/engine/src/lib.rs | 3 +++ crates/ui-egui/src/files.rs | 11 ++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs index bd24adc..a0e5a1f 100644 --- a/crates/engine/src/cmd/file.rs +++ b/crates/engine/src/cmd/file.rs @@ -106,6 +106,7 @@ fn open_sample(s: &mut Session, p: &Value) -> Result { // A sample just opened has nothing to save: it opens again the same way. opened.saved_revision = Some(opened.revision); opened.saved_view = opened.view.clone(); + opened.sample = Some(sample.label); s.replace_with(opened); let mut reply = summary(s, &[]); reply["sample"] = json!(sample.name); diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 69523e0..47c8f4b 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -224,6 +224,9 @@ pub struct Session { pub journal: Vec<(String, Value)>, /// The `.fieldcraft` file the session was opened from or last saved to. pub path: Option, + /// The sample the session was opened as (`file.sample`), by its label; the document is named + /// after it until it is saved under a name of its own. + pub sample: Option<&'static str>, history: History, /// Identifies the current state: it changes with every edit, undo and redo, and comes back /// when an undo returns to an earlier state. diff --git a/crates/ui-egui/src/files.rs b/crates/ui-egui/src/files.rs index 39ee0db..12ea017 100644 --- a/crates/ui-egui/src/files.rs +++ b/crates/ui-egui/src/files.rs @@ -352,8 +352,12 @@ pub enum Answer { } /// The file name a model is saved under by default. +/// The document's name: its file's, else the sample it was opened as ("Cantilever (sample)"). fn model_name(session: &Session) -> String { - session.path.as_deref().and_then(|p| Path::new(p).file_stem()).and_then(|s| s.to_str()).map_or_else(|| "Untitled".to_string(), str::to_string) + match session.path.as_deref().and_then(|p| Path::new(p).file_stem()).and_then(|s| s.to_str()) { + Some(stem) => stem.to_string(), + None => session.sample.map_or_else(|| "Untitled".to_string(), |label| format!("{label} (sample)")), + } } /// `path` with `ext` added when it has no extension of that name (some pickers leave it off). @@ -406,7 +410,7 @@ fn spawn(session: Session, command: &'static str, params: Value) -> (Receiver<(B } impl ModelApp { - /// The model's name: its file's stem, or "Untitled". + /// The model's name: its file's stem, the sample it was opened as, or "Untitled". pub fn model_name(&self) -> String { model_name(&self.session) } @@ -579,7 +583,8 @@ impl ModelApp { pub fn cancel_loading(&mut self) { if let Some(l) = self.loading.take() { self.queued.clear(); - self.set_status(format!("Cancelled: {}", l.title), false); + let line = if l.title == "Solving" { "Solve cancelled".to_string() } else { format!("{} cancelled", l.title) }; + self.set_status(line, false); } }