Browse Source

Preview toolwindow improvements (#854)

* Activate preview toolwindow on receiving preview configuration

* Don't show preview toolwindow until a preview is requested

* Add icon to preview toolwindow
pull/860/head v0.5.0-build235
Alexey Tsvetkov 3 years ago committed by GitHub
parent
commit
6a3b834958
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewToolWindow.kt
  2. 12
      idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/RunPreviewAction.kt

8
idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewToolWindow.kt

@ -16,6 +16,10 @@ class PreviewToolWindow : ToolWindowFactory, DumbAware {
return true
}
override fun init(toolWindow: ToolWindow) {
toolWindow.setIcon(PreviewIcons.COMPOSE)
}
override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
toolWindow.contentManager.let { content ->
val panel = PreviewPanel()
@ -23,4 +27,8 @@ class PreviewToolWindow : ToolWindowFactory, DumbAware {
project.service<PreviewStateService>().registerPreviewPanel(panel)
}
}
// don't show the toolwindow until a preview is requested
override fun shouldBeAvailable(project: Project): Boolean =
false
}

12
idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/RunPreviewAction.kt

@ -14,9 +14,10 @@ import com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMo
import com.intellij.openapi.externalSystem.task.TaskCallback
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil.runTask
import com.intellij.openapi.util.UserDataHolderBase
import com.intellij.openapi.wm.ToolWindowManager
import org.jetbrains.plugins.gradle.settings.GradleSettings
import org.jetbrains.plugins.gradle.util.GradleConstants
import java.util.concurrent.CompletableFuture
import javax.swing.SwingUtilities
class RunPreviewAction(
private val fqName: String,
@ -24,6 +25,9 @@ class RunPreviewAction(
) : AnAction({ "Show non-interactive preview" }, PreviewIcons.RUN_PREVIEW) {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project!!
val previewToolWindow = ToolWindowManager.getInstance(project).getToolWindow("Desktop Preview")
previewToolWindow?.setAvailable(true)
val gradleVmOptions = GradleSettings.getInstance(project).gradleVmOptions
val settings = ExternalSystemTaskExecutionSettings()
settings.executionName = "Preview: $fqName"
@ -37,7 +41,6 @@ class RunPreviewAction(
"-Pcompose.desktop.preview.target=$fqName",
"-Pcompose.desktop.preview.ide.port=$gradleCallbackPort"
).joinToString(" ")
val future = CompletableFuture<Nothing>()
runTask(
settings,
DefaultRunExecutor.EXECUTOR_ID,
@ -45,10 +48,11 @@ class RunPreviewAction(
GradleConstants.SYSTEM_ID,
object : TaskCallback {
override fun onSuccess() {
future.complete(null)
SwingUtilities.invokeLater {
ToolWindowManager.getInstance(project).getToolWindow("Desktop Preview")?.activate { }
}
}
override fun onFailure() {
future.completeExceptionally(RuntimeException("Preview for $fqName failed"))
}
},
ProgressExecutionMode.IN_BACKGROUND_ASYNC,

Loading…
Cancel
Save