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

Refresh desktop preview (#2921) #4977

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<PreviewStateService>().lastPreviewLocation ?: return
buildPreviewViaGradle(project, previewLocation)
}
}

internal const val PREVIEW_EDITOR_TOOLBAR_GROUP_ID = "Compose.Desktop.Preview.Editor.Toolbar"

class RefreshOrRunPreviewAction : AnAction(PreviewIcons.COMPOSE) {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions idea-plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
</extensions>

<actions>
<group id="Compose.Desktop.Preview">
<action class="org.jetbrains.compose.desktop.ide.preview.RefreshShownPreviewAction"/>
</group>
<group id="Compose.Desktop.Preview.Editor.Toolbar">
<action class="org.jetbrains.compose.desktop.ide.preview.RefreshOrRunPreviewAction"/>
</group>
Expand Down