Skip to content

Commit

Permalink
correctly register disposables in MovefmtConfigurable
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov committed Nov 28, 2024
1 parent 8fbf117 commit 6aafc69
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 2 additions & 7 deletions src/main/kotlin/org/move/openapiext/ui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6aafc69

Please sign in to comment.