Skip to content

Commit

Permalink
feat: update name while typing; respect manual user changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhulbert committed Dec 15, 2023
1 parent e4255b1 commit be3f486
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import org.controlsfx.validation.ValidationSupport
import org.controlsfx.validation.Validator
import org.controlsfx.validation.decoration.GraphicValidationDecoration
import org.janelia.saalfeldlab.fx.SaalFxStyle
import org.janelia.saalfeldlab.fx.extensions.invoke
import org.janelia.saalfeldlab.fx.ui.DirectoryField
import org.janelia.saalfeldlab.fx.ui.Exceptions.Companion.exceptionAlert
import org.janelia.saalfeldlab.fx.ui.NamedNode.Companion.bufferNode
Expand Down Expand Up @@ -93,7 +92,7 @@ class CreateDataset(private val currentSource: Source<*>?, vararg allSources: So
private val setFromButton = MenuButton("_Populate", null, populateFromSource, populateFromCurrentSource)
private val setFromCurrentBox = HBox(bufferNode(), setFromButton).apply { HBox.setHgrow(children[0], Priority.ALWAYS) }

private val name = object: TextField() {
private val nameField = object: TextField() {
var manuallyNamed = false
override fun paste() {
super.paste()
Expand All @@ -116,8 +115,8 @@ class CreateDataset(private val currentSource: Source<*>?, vararg allSources: So
private val n5Container: DirectoryField = DirectoryField(System.getProperty("user.home"), FIELD_WIDTH)
private val dataset = stringField("", *SubmitOn.values()).apply {
textField.textProperty().addListener { _, _, newv: String? ->
if (!name.manuallyNamed && newv != null) {
name.text = newv.split("/").toTypedArray().last()
if (!nameField.manuallyNamed && newv != null) {
nameField.text = newv.split("/").toTypedArray().last()
}
}
}
Expand All @@ -129,7 +128,7 @@ class CreateDataset(private val currentSource: Source<*>?, vararg allSources: So
private val offset = SpatialField.doubleField(0.0, { true }, FIELD_WIDTH, *SubmitOn.values())
private val scaleLevels = TitledPane("Scale Levels", mipmapLevelsNode)
private val pane = VBox(
nameIt("Name", NAME_WIDTH, true, name),
nameIt("Name", NAME_WIDTH, true, nameField),
nameIt("N5", NAME_WIDTH, true, n5Container.asNode()),
nameIt("Dataset", NAME_WIDTH, true, dataset.textField),
nameIt("Dimensions", NAME_WIDTH, false, bufferNode(), dimensions.node),
Expand Down Expand Up @@ -248,7 +247,7 @@ class CreateDataset(private val currentSource: Source<*>?, vararg allSources: So
dialogPane.lookupButton(ButtonType.OK).addEventFilter(ActionEvent.ACTION) { e: ActionEvent ->
val container = n5Container.directoryProperty().value!!.absolutePath
val dataset = dataset.value
val name = name.text
val name = nameField.text
try {
LOG.debug("Trying to create empty label dataset `{}' in container `{}'", dataset, container)
if (dataset.isNullOrEmpty()) throw IOException("Dataset not specified!")
Expand Down Expand Up @@ -289,7 +288,7 @@ class CreateDataset(private val currentSource: Source<*>?, vararg allSources: So
}
}
}.showAndWait()
val name = name.text
val name = nameField.text
return Optional.ofNullable(metadataStateProp.get()).map { metadataState: MetadataState -> Pair(metadataState, name) }
}

Expand Down

0 comments on commit be3f486

Please sign in to comment.