diff --git a/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewActions.kt b/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewActions.kt index 93851ff38c7..4ee7ba1060a 100644 --- a/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewActions.kt +++ b/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewActions.kt @@ -6,6 +6,7 @@ package org.jetbrains.compose.desktop.ide.preview import com.intellij.execution.executors.DefaultRunExecutor +import com.intellij.icons.AllIcons import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys @@ -31,6 +32,14 @@ class RunPreviewAction( } } +class RefreshShownPreviewAction : AnAction({ "Refresh last preview" }, AllIcons.Actions.Refresh) { + override fun actionPerformed(e: AnActionEvent) { + val project = e.project ?: return + val previewLocation = project.service().lastPreviewLocation ?: return + buildPreviewViaGradle(project, previewLocation) + } +} + internal const val PREVIEW_EDITOR_TOOLBAR_GROUP_ID = "Compose.Desktop.Preview.Editor.Toolbar" class RefreshOrRunPreviewAction : AnAction(PreviewIcons.COMPOSE) { @@ -79,10 +88,10 @@ private fun buildPreviewViaGradle(project: Project, previewLocation: PreviewLoca GradleConstants.SYSTEM_ID, object : TaskCallback { override fun onSuccess() { - previewService.buildFinished(success = true) + previewService.buildFinished(previewLocation, success = true) } override fun onFailure() { - previewService.buildFinished(success = false) + previewService.buildFinished(previewLocation, success = false) } }, ProgressExecutionMode.IN_BACKGROUND_ASYNC, diff --git a/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewStateService.kt b/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewStateService.kt index 74a6d248ca0..45277245c4f 100644 --- a/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewStateService.kt +++ b/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewStateService.kt @@ -32,6 +32,9 @@ class PreviewStateService(private val myProject: Project) : Disposable { private val configurePreviewTaskNameCache = ConfigurePreviewTaskNameCache(ConfigurePreviewTaskNameProviderImpl()) + var lastPreviewLocation: PreviewLocation? = null + private set + init { val projectRefreshListener = ConfigurePreviewTaskNameCacheInvalidator(configurePreviewTaskNameCache) ExternalSystemProgressNotificationManager.getInstance() @@ -63,7 +66,8 @@ class PreviewStateService(private val myProject: Project) : Disposable { previewListener.onNewBuildRequest() } - internal fun buildFinished(success: Boolean) { + internal fun buildFinished(previewLocation: PreviewLocation, success: Boolean) { + lastPreviewLocation = previewLocation previewListener.onFinishedBuild(success) } } diff --git a/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewToolWindow.kt b/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewToolWindow.kt index c3a10cd4493..7587e02d224 100644 --- a/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewToolWindow.kt +++ b/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewToolWindow.kt @@ -25,6 +25,7 @@ class PreviewToolWindow : ToolWindowFactory, DumbAware { } override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { + toolWindow.setTitleActions(listOf(RefreshShownPreviewAction())) toolWindow.contentManager.let { content -> val panel = PreviewPanel(project) val loadingPanel = JBLoadingPanel(BorderLayout(), project) diff --git a/idea-plugin/src/main/resources/META-INF/plugin.xml b/idea-plugin/src/main/resources/META-INF/plugin.xml index 947d927ea36..86b1bac1c1a 100644 --- a/idea-plugin/src/main/resources/META-INF/plugin.xml +++ b/idea-plugin/src/main/resources/META-INF/plugin.xml @@ -48,6 +48,9 @@ + + +