Skip to content
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 @@ -2,16 +2,19 @@ package com.github.continuedev.continueintellijextension.actions

import com.github.continuedev.continueintellijextension.HighlightedCodePayload
import com.github.continuedev.continueintellijextension.RangeInFileWithContents
import com.github.continuedev.continueintellijextension.browser.ContinueBrowserService
import com.github.continuedev.continueintellijextension.browser.ContinueBrowserService.Companion.getBrowser
import com.github.continuedev.continueintellijextension.editor.DiffStreamService
import com.github.continuedev.continueintellijextension.editor.EditorUtils
import com.github.continuedev.continueintellijextension.services.ContinuePluginService
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.PlatformDataKeys
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.service
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindowManager
import java.io.File

class RestartContinueProcess : AnAction() {
Expand Down Expand Up @@ -89,6 +92,39 @@ class OpenConfigAction : ContinueToolbarAction() {
}
}

class ReloadBrowserAction: ContinueToolbarAction() {
override fun toolbarActionPerformed(project: Project) {
val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("Continue")
?: return
val browserService = project.service<ContinueBrowserService>()

// Perform the reload and UI update on the Event Dispatch Thread
ApplicationManager.getApplication().invokeLater {
// Reload the browser service to get a new browser instance
browserService.reload()

val newBrowser = project.getBrowser() ?: return@invokeLater
val newBrowserComponent = newBrowser.getComponent()

val contentManager = toolWindow.contentManager
contentManager.removeAllContents(true)

val newContent = contentManager.factory.createContent(
newBrowserComponent,
null,
false
)
contentManager.addContent(newContent)
contentManager.setSelectedContent(newContent, true) // Request focus

toolWindow.activate({
// After activation, ensure the browser's input field gets focus
newBrowser.focusOnInput()
}, true)
}
}
}

class OpenLogsAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,59 @@
package com.github.continuedev.continueintellijextension.browser

import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import com.intellij.ui.jcef.JBCefApp

@Service(Service.Level.PROJECT)
class ContinueBrowserService(project: Project): Disposable {
class ContinueBrowserService(val project: Project): Disposable {

private val browser: ContinueBrowser? =
if (JBCefApp.isSupported())
ContinueBrowser(project)
else null
private var browser: ContinueBrowser? = null

init {
load()
}

override fun dispose() {
if (browser != null)
Disposer.dispose(browser)
browser?.let { Disposer.dispose(it) }
browser = null
}

private fun load(): ContinueBrowser? {
if (browser != null) {
return browser
}
if (!JBCefApp.isSupported()) {
return null
}
val newBrowser = ContinueBrowser(project)
Disposer.register(this, newBrowser)

this.browser = newBrowser
return this.browser
}

/**
* Reloads the browser by disposing the current one and creating a new one.
* This method is intended for use when browser is frozen (unresponsive).
*/
fun reload() {
// Store the old browser instance to be disposed later
val oldBrowser = browser
browser = null

// Dispose the old browser after the new one is loaded and UI is updated.
// This avoids race conditions. We can do this on a background thread.
oldBrowser?.let {
ApplicationManager.getApplication().invokeLater {
Disposer.dispose(it)
}
}

load()
}

companion object {
Expand Down
9 changes: 9 additions & 0 deletions extensions/intellij/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@
<override-text place="GoToAction" text="Settings"/>
</action>

<action id="continue.reloadPage"
class="com.github.continuedev.continueintellijextension.actions.ReloadBrowserAction"
icon="AllIcons.Actions.Refresh"
text="Reload Continue Browser"
description="Reload Continue Browser">
<override-text place="GoToAction" text="Reload Continue Browser"/>
</action>

<action id="continue.openLogs"
class="com.github.continuedev.continueintellijextension.actions.OpenLogsAction"
icon="AllIcons.General.ShowInfos"
Expand All @@ -167,6 +175,7 @@
<reference ref="continue.newContinueSession"/>
<reference ref="continue.viewHistory"/>
<reference ref="continue.openConfigPage"/>
<reference ref="continue.reloadPage" />
</group>

<action id="continue.focusContinueInput"
Expand Down
Loading