analysis Name From File Stem
Once-at-default auto-fill helper for markSaved paths in configuration-shaped apps: derive a fresh analysis name from a just-saved file's stem, but only when the current analysisName is still at its default sentinel.
Pre-decomposition, Scenario / Experiment / Simopt each carried a near-identical 6-line block inside markSaved:
if (myOutputConfig.value.analysisName == "Untitled") {
val stem = path.fileName.toString().substringBeforeLast('.')
if (stem.isNotBlank()) {
myOutputConfig.value =
myOutputConfig.value.copy(analysisName = stem)
}
}Simopt additionally piped the stem through sanitizeAnalysisName. This helper captures the shared shape so each host's markSaved collapses to a single call. Returns the new name to apply, or null when no change is warranted — caller is responsible for the copy(analysisName = …) mutation.
Semantics:
Returns
nullwhen currentName is not sentinel. Once the user has set a non-default name, save-as to a different file must NOT silently rename their analysis.Returns
nullwhen the file's stem (the name without the final.ext) is blank — happens for hidden files like.configor paths whose final segment has no characters before the dot.Otherwise returns sanitizer applied to the stem. The default sanitizer is the identity function, so Scenario / Experiment get the raw stem; Simopt passes sanitizeAnalysisName to coerce the stem into the same shape used elsewhere in the Simopt pipeline.
Return
the new name to assign, or null to leave the current name alone
Parameters
the file the document was just persisted to — only path.fileName is read; the parent path is ignored
the document's current analysisName
the "still at default" marker; "Untitled" by default
applied to the file stem before returning; identity by default