ui: name a sample's document after it until saved (#334); "Solve cancelled"

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UhhZMBTviDQxZvwnyP89fo
This commit is contained in:
jyvikoandClaude Opus 5.5 authored and Irakli Kourtis committed 2026-10-15 08:55:25 -04:00
1 parent 8819ff787c
commit b65f1696b2
3 files changed
+12 -3

No files matched your search

+1
View File
@@ -106,6 +106,7 @@ fn open_sample(s: &mut Session, p: &Value) -> Result<Value> {
// 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);
+3
View File
@@ -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<String>,
/// 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.
+8 -3
View File
@@ -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);
}
}