Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate PlatformsForm.kt to Kotlin UI DSL Version 2 #7310

Open
jwren opened this issue Apr 2, 2024 · 2 comments
Open

Migrate PlatformsForm.kt to Kotlin UI DSL Version 2 #7310

jwren opened this issue Apr 2, 2024 · 2 comments
Milestone

Comments

@jwren
Copy link
Contributor

jwren commented Apr 2, 2024

com.intellij.ui.layout.Cell deprecation, see https://plugins.jetbrains.com/docs/intellij/kotlin-ui-dsl-version-2.html

File in the Flutter IJ plugin: io/flutter/module/settings/PlatformsForm.kt.

@jwren jwren added this to the M80 milestone Apr 2, 2024
@beansoft
Copy link

Dear Google team, as I maintained a fork for WebStorm(the Flutter Storm plugin), please try the following in DSL 2(please make sure to check may be something different or potential bugs):

import com.intellij.openapi.ui.DialogPanel
import com.intellij.ui.dsl.builder.*
import com.intellij.ui.layout.ComponentPredicate
import io.flutter.FlutterBundle
import io.flutter.sdk.FlutterCreateAdditionalSettings

class PlatformsForm {

  var channel: FlutterSdkChannel? = null
  private var configAndroid: Boolean = true
  private var configIos: Boolean = true
  private var configLinux: Boolean = true
  private var configMacos: Boolean = true
  private var configWeb: Boolean = true
  private var configWindows: Boolean = true
  var component: DialogPanel? = null

  fun panel(settings: FlutterCreateAdditionalSettings) =
    panel {
      row {
          makeCheckBox( FlutterBundle.message("npw_platform_android"), settings.platformAndroidProperty, configAndroid)
          makeCheckBox( FlutterBundle.message("npw_platform_ios"), settings.platformIosProperty, configIos)
          makeCheckBox( FlutterBundle.message("npw_platform_linux"), settings.platformLinuxProperty, configLinux)
          makeCheckBox( FlutterBundle.message("npw_platform_macos"), settings.platformMacosProperty, configMacos)
          makeCheckBox( FlutterBundle.message("npw_platform_web"), settings.platformWebProperty, configWeb)
          makeCheckBox( FlutterBundle.message("npw_platform_windows"), settings.platformWindowsProperty, configWindows)
      }

      row {
        label(FlutterBundle.message("npw_platform_selection_help"))
      }
    }.apply { component = this }


  private fun Row.makeCheckBox(name: String, property: InitializeOnceBoolValueProperty,
                           config: Boolean?) {

    val wasSelected = config == true
    property.initialize(wasSelected)

    val names: List<String> = listOfNotNull(
        FlutterBundle.message("npw_platform_android"),
        FlutterBundle.message("npw_platform_ios"),
        FlutterBundle.message("npw_platform_web"),
        FlutterBundle.message("npw_platform_windows"),
        FlutterBundle.message("npw_platform_linux"),
        FlutterBundle.message("npw_platform_macos"),
    )
    checkBox(name)
        .actionListener { _, button -> property.set(button.isSelected) }.selected(property.get())
        .enabledIf( ComponentPredicate.fromValue( names.contains(name) || wasSelected ) )
  }
}

@jwren
Copy link
Contributor Author

jwren commented Apr 27, 2024

@beansoft thank you for the prompt here. Consider creating a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants