From 6aafc698744b98566cd804e879c3a941bc66ae9c Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Thu, 28 Nov 2024 15:23:13 +0100 Subject: [PATCH] correctly register disposables in MovefmtConfigurable --- .../externalFormatter/MovefmtConfigurable.kt | 40 +++++++++---------- .../cli/settings/aptos/ChooseAptosCliPanel.kt | 2 +- src/main/kotlin/org/move/openapiext/ui.kt | 9 +---- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/main/kotlin/org/move/cli/externalFormatter/MovefmtConfigurable.kt b/src/main/kotlin/org/move/cli/externalFormatter/MovefmtConfigurable.kt index cd3b4c96..0e0faf13 100644 --- a/src/main/kotlin/org/move/cli/externalFormatter/MovefmtConfigurable.kt +++ b/src/main/kotlin/org/move/cli/externalFormatter/MovefmtConfigurable.kt @@ -17,31 +17,29 @@ import org.move.cli.settings.VersionLabel import org.move.openapiext.pathField class MovefmtConfigurable(val project: Project): BoundConfigurable("Movefmt") { - private val innerDisposable = - Disposer.newCheckedDisposable("Internal checked disposable for MovefmtConfigurable") - - private val movefmtPathField = - pathField( - FileChooserDescriptorFactory.createSingleFileOrExecutableAppDescriptor(), - innerDisposable, - "Movefmt location", - onTextChanged = { it -> - val path = it.toNioPathOrNull() ?: return@pathField - versionLabel.update(path) - }) - private val versionLabel = VersionLabel( - innerDisposable, - envs = EnvironmentVariablesData.create(mapOf("MOVEFMT_LOG" to "error"), true) - ) - - private val additionalArguments: RawCommandLineEditor = RawCommandLineEditor() - private val environmentVariables: EnvironmentVariablesComponent = EnvironmentVariablesComponent() - - override fun createPanel(): DialogPanel { + val innerDisposable = + Disposer.newCheckedDisposable("MovefmtConfigurable.innerDisposable") this.disposable?.let { Disposer.register(it, innerDisposable) } + + val versionLabel = VersionLabel( + innerDisposable, + envs = EnvironmentVariablesData.create(mapOf("MOVEFMT_LOG" to "error"), true) + ) + val movefmtPathField = + pathField( + FileChooserDescriptorFactory.createSingleFileOrExecutableAppDescriptor(), + innerDisposable, + "Movefmt location", + onTextChanged = { it -> + val path = it.toNioPathOrNull() ?: return@pathField + versionLabel.update(path) + }) + val additionalArguments: RawCommandLineEditor = RawCommandLineEditor() + val environmentVariables: EnvironmentVariablesComponent = EnvironmentVariablesComponent() + return panel { val settings = project.movefmtSettings val state = settings.state.copy() diff --git a/src/main/kotlin/org/move/cli/settings/aptos/ChooseAptosCliPanel.kt b/src/main/kotlin/org/move/cli/settings/aptos/ChooseAptosCliPanel.kt index eae31fe8..af0dba5d 100644 --- a/src/main/kotlin/org/move/cli/settings/aptos/ChooseAptosCliPanel.kt +++ b/src/main/kotlin/org/move/cli/settings/aptos/ChooseAptosCliPanel.kt @@ -63,7 +63,7 @@ enum class AptosExecType { class ChooseAptosCliPanel(versionUpdateListener: (() -> Unit)?): Disposable { private val innerDisposable = - Disposer.newCheckedDisposable("Internal checked disposable for ChooseAptosCliPanel") + Disposer.newCheckedDisposable("ChooseAptosCliPanel.innerDisposable") init { Disposer.register(this, innerDisposable) diff --git a/src/main/kotlin/org/move/openapiext/ui.kt b/src/main/kotlin/org/move/openapiext/ui.kt index 4b9f9747..c0ef00d4 100644 --- a/src/main/kotlin/org/move/openapiext/ui.kt +++ b/src/main/kotlin/org/move/openapiext/ui.kt @@ -3,21 +3,16 @@ package org.move.openapiext import com.intellij.openapi.Disposable import com.intellij.openapi.application.ModalityState import com.intellij.openapi.application.invokeLater -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.editor.ScrollType import com.intellij.openapi.fileChooser.FileChooserDescriptor import com.intellij.openapi.ui.TextComponentAccessor import com.intellij.openapi.ui.TextFieldWithBrowseButton import com.intellij.openapi.util.CheckedDisposable -import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.NlsContexts.DialogTitle import com.intellij.ui.DocumentAdapter -import com.intellij.ui.components.JBTextField import com.intellij.ui.dsl.builder.AlignX import com.intellij.ui.dsl.builder.Cell import com.intellij.ui.dsl.builder.Row import com.intellij.util.Alarm -import org.move.lang.core.psi.MvElement import javax.swing.JComponent import javax.swing.JTextField import javax.swing.event.DocumentEvent @@ -48,11 +43,11 @@ class UiDebouncer( fun pathField( fileChooserDescriptor: FileChooserDescriptor, - disposable: Disposable, + parentDisposable: Disposable, @DialogTitle dialogTitle: String, onTextChanged: (String) -> Unit = {} ): TextFieldWithBrowseButton { - val component = TextFieldWithBrowseButton(null, disposable) + val component = TextFieldWithBrowseButton(null, parentDisposable) component.addBrowseFolderListener( dialogTitle, null, null, fileChooserDescriptor,