Skip to content

Commit

Permalink
fix: don't double-activate tools unnecessarily
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhulbert committed Aug 14, 2024
1 parent 2d77497 commit c16570c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ import org.janelia.saalfeldlab.fx.util.InvokeOnJavaFXApplicationThread
import org.janelia.saalfeldlab.paintera.PainteraBaseKeys
import org.janelia.saalfeldlab.paintera.config.input.KeyAndMouseBindings
import org.janelia.saalfeldlab.paintera.control.actions.AllowedActions
import org.janelia.saalfeldlab.paintera.control.modes.NavigationTool.activeViewer
import org.janelia.saalfeldlab.paintera.control.modes.NavigationTool.mode
import org.janelia.saalfeldlab.paintera.control.modes.NavigationTool.removeFrom
import org.janelia.saalfeldlab.paintera.control.tools.REQUIRES_ACTIVE_VIEWER
import org.janelia.saalfeldlab.paintera.control.tools.Tool
import org.janelia.saalfeldlab.paintera.control.tools.ToolBarItem
Expand Down Expand Up @@ -86,14 +83,15 @@ interface ToolMode : SourceMode {
}
}

fun switchTool(tool: Tool?) : Job? {
fun switchTool(tool: Tool?): Job? {
if (activeTool == tool)
return null

LOG.debug { "Switch from $activeTool to $tool" }

/* Deactivate off the main thread */
val deactivateJob = CoroutineScope(Dispatchers.Default).launch {
LOG.trace {"Deactivated $activeTool"}
LOG.trace { "Deactivated $activeTool" }
activeTool?.deactivate()
}

Expand All @@ -105,15 +103,15 @@ interface ToolMode : SourceMode {
showToolBars()
tool?.activate()
activeTool = tool
LOG.trace {"Activated $activeTool"}
LOG.trace { "Activated $activeTool" }
}

deactivateJob.invokeOnCompletion {
/* If the mode was changed before we can activate, don't activate anymore */
if (paintera.baseView.activeModeProperty.value == this@ToolMode)
activateJob.start()
}
return activateJob
return activateJob
}

private fun showToolBars(show: Boolean = true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ object NavigationControlMode : AbstractToolMode() {

override val tools: ObservableList<Tool> = FXCollections.observableArrayList(NavigationTool)

override fun enter() {
super.enter()
switchTool(NavigationTool)
}
}

object NavigationTool : ViewerTool() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,6 @@ object RawSourceMode : AbstractToolMode() {
old?.viewer()?.removeActionSet(actionSet)
new?.viewer()?.installActionSet(actionSet)
}

/* set the currently activeTool for this viewer */
switchTool(activeTool ?: NavigationTool)
}

override fun enter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ object ViewLabelMode : AbstractToolMode() {
old?.viewer()?.removeActionSet(actionSet)
new?.viewer()?.installActionSet(actionSet)
}

/* set the currently activeTool for this viewer */
switchTool(activeTool ?: NavigationTool)
}

override fun enter() {
Expand Down

0 comments on commit c16570c

Please sign in to comment.