Browse Source

Move intellijPlugin to 1.0.0-alpha1-rc1

pull/966/head
Nikolay Igotti 3 years ago
parent
commit
88c4e27d6e
  1. 9
      examples/intelliJPlugin/build.gradle.kts
  2. 17
      examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/ComposeDemoAction.kt
  3. 45
      examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/ComposeSizeAdjustmentWrapper.kt

9
examples/intelliJPlugin/build.gradle.kts

@ -3,9 +3,9 @@ import org.jetbrains.compose.compose
plugins { plugins {
id("org.jetbrains.intellij") version "0.6.5" id("org.jetbrains.intellij") version "0.6.5"
java java
kotlin("jvm") version "1.5.10" kotlin("jvm") version "1.5.21"
// __LATEST_COMPOSE_RELEASE_VERSION__ // __LATEST_COMPOSE_RELEASE_VERSION__
id("org.jetbrains.compose") version "0.4.0" id("org.jetbrains.compose") version "1.0.0-alpha1-rc1"
} }
group = "org.example" group = "org.example"
@ -13,19 +13,18 @@ version = "1.0-SNAPSHOT"
repositories { repositories {
mavenCentral() mavenCentral()
google()
maven { url = uri("https://maven.pkg.jetbrains.space/public/p/compose/dev") } maven { url = uri("https://maven.pkg.jetbrains.space/public/p/compose/dev") }
} }
dependencies { dependencies {
implementation(kotlin("stdlib"))
implementation("org.jetbrains.compose.material:material:")
implementation(compose.desktop.currentOs) implementation(compose.desktop.currentOs)
testCompile("junit", "junit", "4.12") testCompile("junit", "junit", "4.12")
} }
// See https://github.com/JetBrains/gradle-intellij-plugin/ // See https://github.com/JetBrains/gradle-intellij-plugin/
intellij { intellij {
version = "2021.1" version = "2021.2"
} }
tasks.getByName<org.jetbrains.intellij.tasks.PatchPluginXmlTask>("patchPluginXml") { tasks.getByName<org.jetbrains.intellij.tasks.PatchPluginXmlTask>("patchPluginXml") {
changeNotes(""" changeNotes("""

17
examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/ComposeDemoAction.kt

@ -1,6 +1,5 @@
package com.jetbrains.compose package com.jetbrains.compose
import androidx.compose.desktop.ComposePanel
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@ -8,12 +7,14 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Surface import androidx.compose.material.Surface
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.IntSize import androidx.compose.ui.awt.ComposePanel
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.MeasurePolicy
import androidx.compose.ui.layout.onGloballyPositioned
import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.DumbAwareAction import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogWrapper import com.intellij.openapi.ui.DialogWrapper
import com.intellij.ui.layout.panel
import com.jetbrains.compose.theme.WidgetTheme import com.jetbrains.compose.theme.WidgetTheme
import com.jetbrains.compose.widgets.Buttons import com.jetbrains.compose.widgets.Buttons
import com.jetbrains.compose.widgets.LazyScrollable import com.jetbrains.compose.widgets.LazyScrollable
@ -22,6 +23,7 @@ import com.jetbrains.compose.widgets.TextInputs
import com.jetbrains.compose.widgets.Toggles import com.jetbrains.compose.widgets.Toggles
import java.awt.Dimension import java.awt.Dimension
import javax.swing.JComponent import javax.swing.JComponent
import javax.swing.SwingUtilities
/** /**
@ -39,15 +41,9 @@ class ComposeDemoAction : DumbAwareAction() {
} }
override fun createCenterPanel(): JComponent { override fun createCenterPanel(): JComponent {
val dialog = this
return ComposePanel().apply { return ComposePanel().apply {
preferredSize = Dimension(800, 600) setBounds(0, 0, 800, 600)
setContent { setContent {
ComposeSizeAdjustmentWrapper(
window = dialog,
panel = this,
preferredSize = IntSize(800, 600)
) {
WidgetTheme(darkTheme = true) { WidgetTheme(darkTheme = true) {
Surface(modifier = Modifier.fillMaxSize()) { Surface(modifier = Modifier.fillMaxSize()) {
Row { Row {
@ -72,4 +68,3 @@ class ComposeDemoAction : DumbAwareAction() {
} }
} }
} }
}

45
examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/ComposeSizeAdjustmentWrapper.kt

@ -1,45 +0,0 @@
package com.jetbrains.compose
import androidx.compose.desktop.ComposePanel
import androidx.compose.foundation.layout.Box
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.unit.IntSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import com.intellij.openapi.ui.DialogWrapper
import java.awt.Dimension
import java.awt.Window
import javax.swing.JComponent
@Composable
fun ComposeSizeAdjustmentWrapper(
window: DialogWrapper,
panel: ComposePanel,
preferredSize: IntSize,
content: @Composable () -> Unit
) {
var packed = false
Box {
content()
Layout(
content = {},
modifier = Modifier.onGloballyPositioned { childCoordinates ->
// adjust size of the dialog
if (!packed) {
val contentSize = childCoordinates.parentCoordinates!!.size
panel.preferredSize = Dimension(
if (contentSize.width < preferredSize.width) preferredSize.width else contentSize.width,
if (contentSize.height < preferredSize.height) preferredSize.height else contentSize.height,
)
window.pack()
packed = true
}
},
measurePolicy = { _, _ ->
layout(0, 0) {}
}
)
}
}
Loading…
Cancel
Save