From c16570c9771f317b6949cb647a2b801c4200216b Mon Sep 17 00:00:00 2001 From: Caleb Hulbert Date: Wed, 14 Aug 2024 13:13:10 -0400 Subject: [PATCH] fix: don't double-activate tools unnecessarily --- .../saalfeldlab/paintera/control/modes/Modes.kt | 12 +++++------- .../paintera/control/modes/NavigationControlMode.kt | 4 ---- .../paintera/control/modes/RawSourceMode.kt | 3 --- .../paintera/control/modes/ViewLabelMode.kt | 3 --- 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/Modes.kt b/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/Modes.kt index fcc81a6c4..84a804cdb 100644 --- a/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/Modes.kt +++ b/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/Modes.kt @@ -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 @@ -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() } @@ -105,7 +103,7 @@ interface ToolMode : SourceMode { showToolBars() tool?.activate() activeTool = tool - LOG.trace {"Activated $activeTool"} + LOG.trace { "Activated $activeTool" } } deactivateJob.invokeOnCompletion { @@ -113,7 +111,7 @@ interface ToolMode : SourceMode { if (paintera.baseView.activeModeProperty.value == this@ToolMode) activateJob.start() } - return activateJob + return activateJob } private fun showToolBars(show: Boolean = true) { diff --git a/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/NavigationControlMode.kt b/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/NavigationControlMode.kt index 9a31fa60e..cce6bc7cf 100644 --- a/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/NavigationControlMode.kt +++ b/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/NavigationControlMode.kt @@ -71,10 +71,6 @@ object NavigationControlMode : AbstractToolMode() { override val tools: ObservableList = FXCollections.observableArrayList(NavigationTool) - override fun enter() { - super.enter() - switchTool(NavigationTool) - } } object NavigationTool : ViewerTool() { diff --git a/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/RawSourceMode.kt b/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/RawSourceMode.kt index da012eb3c..52a11ab2a 100644 --- a/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/RawSourceMode.kt +++ b/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/RawSourceMode.kt @@ -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() { diff --git a/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/ViewLabelMode.kt b/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/ViewLabelMode.kt index d19707ca1..122b46d20 100644 --- a/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/ViewLabelMode.kt +++ b/src/main/kotlin/org/janelia/saalfeldlab/paintera/control/modes/ViewLabelMode.kt @@ -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() {