diff --git a/platform/xdebugger-api/resources/messages/XDebuggerBundle.properties b/platform/xdebugger-api/resources/messages/XDebuggerBundle.properties index ba15215a0b59..75e3c0cc5cf4 100644 --- a/platform/xdebugger-api/resources/messages/XDebuggerBundle.properties +++ b/platform/xdebugger-api/resources/messages/XDebuggerBundle.properties @@ -338,3 +338,5 @@ notification.group.debugger.hotswap.messages=Hotswap failed xdebugger.hotswap.status.success=Code has been reloaded xdebugger.hotswap.tooltip.apply=Apply hot swap xdebugger.hotswap.tooltip.description=You changed code during a debug session. Code in runtime differs from code in editor. You can apply changes manually. +action.XDebugger.Hotswap.Modified.Files.text=Compile And Reload Modified Files +action.XDebugger.Hotswap.Modified.Files.description=Recompile files modified during a debugger session and perform hot swap diff --git a/platform/xdebugger-impl/resources/META-INF/xdebugger.xml b/platform/xdebugger-impl/resources/META-INF/xdebugger.xml index 7a228bffaa0f..ae293ba07e96 100644 --- a/platform/xdebugger-impl/resources/META-INF/xdebugger.xml +++ b/platform/xdebugger-impl/resources/META-INF/xdebugger.xml @@ -198,6 +198,10 @@ + + + + diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/hotswap/HotSwapFloatingToolbarProvider.kt b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/hotswap/HotSwapFloatingToolbarProvider.kt index ee2c66337301..5acacb82b778 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/hotswap/HotSwapFloatingToolbarProvider.kt +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/hotswap/HotSwapFloatingToolbarProvider.kt @@ -10,6 +10,7 @@ import com.intellij.openapi.application.EDT import com.intellij.openapi.editor.toolbar.floating.FloatingToolbarComponent import com.intellij.openapi.editor.toolbar.floating.FloatingToolbarProvider import com.intellij.openapi.editor.toolbar.floating.isInsideMainEditor +import com.intellij.openapi.project.Project import com.intellij.openapi.util.registry.Registry import com.intellij.ui.AnimatedIcon import com.intellij.ui.components.JBLabel @@ -24,17 +25,35 @@ import java.awt.FlowLayout import javax.swing.JComponent import javax.swing.JPanel +internal class HotSwapModifiedFilesAction : AnAction(XDebuggerBundle.messagePointer("action.XDebugger.Hotswap.Modified.Files.text"), + XDebuggerBundle.messagePointer("action.XDebugger.Hotswap.Modified.Files.description"), + PlatformDebuggerImplIcons.Actions.Hot_swap) { + override fun actionPerformed(e: AnActionEvent) { + val session = findSessionIfReady(e.project) ?: return + HotSwapWithRebuildAction.performHotSwap(e.dataContext, session) + } + + override fun update(e: AnActionEvent) { + e.presentation.isEnabledAndVisible = findSessionIfReady(e.project) != null + } + + private fun findSessionIfReady(project: Project?): HotSwapSession<*>? { + if (project == null) return null + val session = HotSwapSessionManager.getInstance(project).currentSession ?: return null + if (session.currentStatus != HotSwapVisibleStatus.CHANGES_READY) return null + return session + } + + override fun getActionUpdateThread() = ActionUpdateThread.BGT +} + private class HotSwapWithRebuildAction : AnAction(), CustomComponentAction { var inProgress = false var session: HotSwapSession<*>? = null override fun actionPerformed(e: AnActionEvent) { val session = session ?: return - callWithTemplate(e.dataContext, session) - } - - private fun callWithTemplate(context: DataContext, session: HotSwapSession) { - session.provider.performHotSwap(context, session) + performHotSwap(e.dataContext, session) } override fun getActionUpdateThread() = ActionUpdateThread.EDT @@ -46,6 +65,12 @@ private class HotSwapWithRebuildAction : AnAction(), CustomComponentAction { override fun updateCustomComponent(component: JComponent, presentation: Presentation) { (component as HotSwapToolbarComponent).update(inProgress, presentation) } + + companion object { + internal fun performHotSwap(context: DataContext, session: HotSwapSession) { + session.provider.performHotSwap(context, session) + } + } } private class HotSwapToolbarComponent(action: AnAction, presentation: Presentation, place: String) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/hotswap/HotSwapSessionManager.kt b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/hotswap/HotSwapSessionManager.kt index 7817488d540d..5c1010cd8358 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/hotswap/HotSwapSessionManager.kt +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/hotswap/HotSwapSessionManager.kt @@ -27,9 +27,11 @@ class HotSwapSessionManager(private val project: Project, private val parentScop return hotSwapSession } + internal val currentSession: HotSwapSession<*>? get() = sessions.lastOrNull() + internal fun addListener(listener: HotSwapChangesListener, disposable: Disposable) { listeners.add(listener, disposable) - val currentSession = sessions.lastOrNull() ?: return + val currentSession = currentSession ?: return listener.onStatusChanged(currentSession, currentSession.currentStatus) }