Skip to content

Commit 53f5aad

Browse files
committed
feat: add JCEF reload action
1 parent 72db8f0 commit 53f5aad

File tree

3 files changed

+72
-7
lines changed

3 files changed

+72
-7
lines changed

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/ContinuePluginActions.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.github.continuedev.continueintellijextension.actions
22

33
import com.github.continuedev.continueintellijextension.HighlightedCodePayload
44
import com.github.continuedev.continueintellijextension.RangeInFileWithContents
5+
import com.github.continuedev.continueintellijextension.browser.ContinueBrowserService
56
import com.github.continuedev.continueintellijextension.browser.ContinueBrowserService.Companion.getBrowser
67
import com.github.continuedev.continueintellijextension.editor.DiffStreamService
78
import com.github.continuedev.continueintellijextension.editor.EditorUtils
@@ -12,6 +13,7 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys
1213
import com.intellij.openapi.components.service
1314
import com.intellij.openapi.fileEditor.FileEditorManager
1415
import com.intellij.openapi.project.Project
16+
import com.intellij.openapi.wm.ToolWindowManager
1517
import java.io.File
1618

1719
class RestartContinueProcess : AnAction() {
@@ -89,6 +91,32 @@ class OpenConfigAction : ContinueToolbarAction() {
8991
}
9092
}
9193

94+
class ReloadBrowserAction: ContinueToolbarAction() {
95+
override fun toolbarActionPerformed(project: Project) {
96+
val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("Continue")
97+
?: return
98+
val contentManager = toolWindow.contentManager
99+
val browserService = project.service<ContinueBrowserService>()
100+
browserService.reload()
101+
102+
val newBrowser = project.getBrowser() ?: return
103+
val newBrowserComponent = newBrowser.getComponent()
104+
105+
contentManager.removeAllContents(true)
106+
val newContent = contentManager.factory.createContent(
107+
newBrowserComponent,
108+
null,
109+
false
110+
)
111+
112+
contentManager.addContent(newContent)
113+
114+
contentManager.setSelectedContent(newContent)
115+
116+
toolWindow.activate(null)
117+
}
118+
}
119+
92120
class OpenLogsAction : AnAction() {
93121
override fun actionPerformed(e: AnActionEvent) {
94122
val project = e.project ?: return

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/browser/ContinueBrowserService.kt

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,44 @@ import com.intellij.openapi.util.Disposer
88
import com.intellij.ui.jcef.JBCefApp
99

1010
@Service(Service.Level.PROJECT)
11-
class ContinueBrowserService(project: Project): Disposable {
11+
class ContinueBrowserService(val project: Project): Disposable {
1212

13-
private val browser: ContinueBrowser? =
14-
if (JBCefApp.isSupported())
15-
ContinueBrowser(project)
16-
else null
13+
private var browser: ContinueBrowser? = null
14+
15+
init {
16+
load()
17+
}
1718

1819
override fun dispose() {
19-
if (browser != null)
20-
Disposer.dispose(browser)
20+
browser?.let { Disposer.dispose(it) }
21+
browser = null
22+
}
23+
24+
private fun load(): ContinueBrowser? {
25+
if (browser != null) {
26+
return browser
27+
}
28+
if (!JBCefApp.isSupported()) {
29+
return null
30+
}
31+
val newBrowser = ContinueBrowser(project)
32+
Disposer.register(this, newBrowser)
33+
34+
this.browser = newBrowser
35+
return this.browser
36+
}
37+
38+
/**
39+
* Reloads the browser by disposing the current one and creating a new one.
40+
* This method is intended for use when browser is frozen (unresponsive).
41+
*/
42+
fun reload() {
43+
browser?.let {
44+
Disposer.dispose(it)
45+
}
46+
browser = null
47+
48+
load()
2149
}
2250

2351
companion object {

extensions/intellij/src/main/resources/META-INF/plugin.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@
156156
<override-text place="GoToAction" text="Settings"/>
157157
</action>
158158

159+
<action id="continue.reloadPage"
160+
class="com.github.continuedev.continueintellijextension.actions.ReloadBrowserAction"
161+
icon="AllIcons.Actions.Refresh"
162+
text="Reload Continue Browser"
163+
description="Reload Continue Browser">
164+
<override-text place="GoToAction" text="Reload Continue Browser"/>
165+
</action>
166+
159167
<action id="continue.openLogs"
160168
class="com.github.continuedev.continueintellijextension.actions.OpenLogsAction"
161169
icon="AllIcons.General.ShowInfos"
@@ -168,6 +176,7 @@
168176
<reference ref="continue.newContinueSession"/>
169177
<reference ref="continue.viewHistory"/>
170178
<reference ref="continue.openConfigPage"/>
179+
<reference ref="continue.reloadPage" />
171180
</group>
172181

173182
<action id="continue.focusContinueInput"

0 commit comments

Comments
 (0)