Skip to content

Commit

Permalink
feat(terminal): add compatibility support for 222 and 233 versions
Browse files Browse the repository at this point in the history
This commit introduces compatibility with both version 222 and 233 of the terminal extension. It includes a new ShellCommandSuggestionAction class that leverages the newly added TerminalUtil class to get the current terminal widget more efficiently. The TerminalUtil class has been split into two separate files, one for each version, to ensure compatibility and avoid breaking changes.
  • Loading branch information
phodal committed Apr 4, 2024
1 parent 0c9a04b commit 85175f8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
@@ -0,0 +1,17 @@
package cc.unitmesh.terminal

import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.terminal.JBTerminalWidget
import org.jetbrains.plugins.terminal.TerminalToolWindowFactory
import org.jetbrains.plugins.terminal.TerminalView

object TerminalUtil {
fun getCurrentTerminalWidget(project: Project): JBTerminalWidget? {
val toolWindow = ToolWindowManager.getInstance(project)
.getToolWindow(TerminalToolWindowFactory.TOOL_WINDOW_ID) ?: return null
val content = toolWindow.contentManager.selectedContent ?: return null
val widget = TerminalView.getWidgetByContent(content) ?: return null
return widget
}
}
@@ -0,0 +1,17 @@
package cc.unitmesh.terminal

import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.terminal.JBTerminalWidget
import org.jetbrains.plugins.terminal.TerminalToolWindowFactory
import org.jetbrains.plugins.terminal.TerminalToolWindowManager

object TerminalUtil {
fun getCurrentTerminalWidget(project: Project): JBTerminalWidget? {
val toolWindow = ToolWindowManager.getInstance(project)
.getToolWindow(TerminalToolWindowFactory.TOOL_WINDOW_ID) ?: return null
val content = toolWindow.contentManager.selectedContent ?: return null
val widget = TerminalToolWindowManager.getWidgetByContent(content) ?: return null
return widget
}
}
Expand Up @@ -18,7 +18,6 @@ import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.ui.popup.JBPopupListener
import com.intellij.openapi.ui.popup.LightweightWindowEvent
import com.intellij.openapi.wm.IdeFocusManager
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.terminal.JBTerminalWidget
import com.intellij.ui.DocumentAdapter
import com.intellij.ui.awt.RelativePoint
Expand All @@ -28,8 +27,6 @@ import com.intellij.util.ui.SwingHelper
import com.intellij.util.ui.UIUtil
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import org.jetbrains.plugins.terminal.TerminalToolWindowFactory
import org.jetbrains.plugins.terminal.TerminalView
import java.awt.Component
import java.awt.Font
import java.awt.Point
Expand All @@ -51,7 +48,7 @@ class ShellCommandSuggestionAction : AnAction() {
val contextComponent = e.getData(PlatformCoreDataKeys.CONTEXT_COMPONENT) ?: return

showContentRenamePopup(contextComponent, popupPoint) { data ->
val widget = getCurrentTerminalWidget(project) ?: return@showContentRenamePopup
val widget = TerminalUtil.getCurrentTerminalWidget(project) ?: return@showContentRenamePopup
suggestCommand(widget, data, project)
}
}
Expand Down Expand Up @@ -154,15 +151,5 @@ class ShellCommandSuggestionAction : AnAction() {
}
})
}
}

companion object {
// TODO: spike for multiple version support
fun getCurrentTerminalWidget(project: Project): JBTerminalWidget? {
val toolWindow = ToolWindowManager.getInstance(project)
.getToolWindow(TerminalToolWindowFactory.TOOL_WINDOW_ID) ?: return null
val content = toolWindow.contentManager.selectedContent ?: return null
val widget = TerminalView.getWidgetByContent(content) ?: return null
return widget
}
}
}

0 comments on commit 85175f8

Please sign in to comment.