Launch a Run/Debug Configuration setting dialog

Answered

Per Creating a Run Configuration from Context, I am trying to launch the settings editor for the appropriate run configuration every time it is created:

    override fun onFirstRun(
        configuration: ConfigurationFromContext,
        context: ConfigurationContext,
        startRunnable: Runnable
    ) {
        (configuration.configuration as PlaybookRunConfiguration).let {
            val editor = it.configurationEditor
            // TODO: Launch editor and apply user input to configuration. 
        }
        super.onFirstRun(configuration, context, startRunnable)
    }

How do I launch a run configuration dialog window for the given editor instance?

 

 

0
3 comments

Hi Michael,

Could you please descibe your use case?

0

I have a plugin that provides run configurations for executing Ansible tasks: https://github.com/mdklatt/idea-ansible-plugin

I want add the ability to create a run configuration by right-clicking on a YAML file in the Project view. Additional information will be required from the user for this, so I want to reuse the existing settings editors for the run configurations. Basically, I want a context menu action that will work just like creating a new configuration from a template: https://www.jetbrains.com/help/idea/run-debug-configuration.html#createExplicitly.

Per https://intellij-support.jetbrains.com/hc/en-us/community/posts/16990298341138-Context-menu-display-name-for-Run-Configuration-Producer?page=1#community_comment_17018411165586, I am pivoting away from using RunConfigurationProducer.onRun() and will be implementing this as part of a custom action. In either case, I think launching the settings editor would work the same way.

 

0

Hi Michael,

I found two approaches (I didn't test it, so adjustments may be required):

1. You can use editor.component in DialogWrapper:

override fun onFirstRun(configuration: ConfigurationFromContext,
                        context: ConfigurationContext,
                        startRunnable: Runnable) {
  val runConfiguration = configuration.configuration as PlaybookRunConfiguration ?: return
  if (!hasMissingData(runConfiguration)) {
    super.onFirstRun(configuration, context, startRunnable)
    return
  }
  
  val project = context.project
  val runManager = RunManager.getInstance(project)
  val settings = configuration.configurationSettings
  val configurationEditor = runConfiguration.configurationEditor

  val dialog = object : DialogWrapper(project) {
    init {
      title = "Dialog Title"
      init()
    }

    override fun createCenterPanel(): JComponent? = configurationEditor.component

    override fun doValidate(): ValidationInfo? {
      configurationEditor.applyTo(settings)
      try {
        runConfiguration.checkConfiguration()
      } catch (e: RuntimeConfigurationError) {
        return ValidationInfo(e.message.orEmpty())
      } catch (e: RuntimeConfigurationWarning) {
        return ValidationInfo(e.message.orEmpty()).asWarning().withOKEnabled()
      }
      return null
    }
  }

  if (dialog.showAndGet()) {
    runConfiguration.name = "generate name"
    configurationEditor.applyTo(settings)
    runManager.setUniqueNameIfNeeded(settings)
    runManager.addConfiguration(settings)
    runManager.selectedConfiguration = settings
    super.onFirstRun(configuration, context, startRunnable)
  }
}

2. Using com.intellij.execution.impl.EditConfigurationsDialog. Please note that this class may be considered as internal API (it is a part of a *-impl module and is located in an impl package):

override fun onFirstRun(configuration: ConfigurationFromContext,
                        context: ConfigurationContext,
                        startRunnable: Runnable) {
  val runConfiguration = configuration.configuration as PlaybookRunConfiguration
  val project = context.project
  var cancelled = false
  if (hasMissingData(runConfiguration)) {
    val runManager = RunManager.getInstance(project)
    val settings = configuration.configurationSettings
    if (!runManager.allSettings.contains(settings)) {
      runManager.addConfiguration(settings)
    }
    runManager.selectedConfiguration = settings
    val dialog = EditConfigurationsDialog(project)
    if (!dialog.showAndGet()) {
      cancelled = true
    }
  }
  if (!cancelled) {
    super.onFirstRun(configuration, context, startRunnable)
  }
}
0

Please sign in to leave a comment.