From bb1ea6643959fb7ff1e8fd5b286cc225913e5b65 Mon Sep 17 00:00:00 2001 From: Konstantin Aksenov Date: Mon, 4 Mar 2024 13:57:52 +1000 Subject: [PATCH] feat(debt): migrate to new terminal --- README.md | 3 ++- build.gradle.kts | 8 +++--- .../cliactions/CliActionsToolWindowFactory.kt | 2 +- .../github/vacxe/cliactions/model/Command.kt | 3 ++- .../terminal/IntellijIDETerminal.kt | 27 ++++++++++++++++--- .../vacxe/cliactions/terminal/Terminal.kt | 4 ++- .../cliactions/ui/CliActionsTablePanel.kt | 14 +++++++--- 7 files changed, 46 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 5f03a8a..a0485b6 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,8 @@ groups: commands: - name: Command Name command: your-terminal-command - prompt: true/false + prompt: true/false (default false) + forceNewTab: true/false (default false) ``` ## Troubleshooting diff --git a/build.gradle.kts b/build.gradle.kts index b352e0a..8542084 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,14 +8,14 @@ plugins { } group = "io.github.vacxe" -version = "1.0.5" +version = "1.0.6" repositories { mavenCentral() } intellij { - version.set("2022.2.1") + version.set("2023.2.2") pluginName.set("CLI Actions") plugins.set(listOf("org.jetbrains.plugins.terminal")) } @@ -30,10 +30,10 @@ tasks { } patchPluginXml { - sinceBuild.set("222") + sinceBuild.set("232") untilBuild.set("") changeNotes.set(""" - Added autorefresh for configurations on case of yaml change. No more IDE restart for update! Yay! + Migrate from deprecated Terminal View. Tab names support and reuse tabs. """) } diff --git a/src/main/kotlin/io/github/vacxe/cliactions/CliActionsToolWindowFactory.kt b/src/main/kotlin/io/github/vacxe/cliactions/CliActionsToolWindowFactory.kt index 65f1f4f..b811319 100644 --- a/src/main/kotlin/io/github/vacxe/cliactions/CliActionsToolWindowFactory.kt +++ b/src/main/kotlin/io/github/vacxe/cliactions/CliActionsToolWindowFactory.kt @@ -17,7 +17,7 @@ class CliActionsToolWindowFactory : DumbAware, ToolWindowFactory { val cmdPanel = CliActionsTablePanel( configurationFinder = configurationFinder, - runTerminalCommand = { name, command -> terminalProvider.run(name, command) } + runTerminalCommand = { name, command, forceNewTab -> terminalProvider.run(name, command, forceNewTab) } ) val content: Content = ContentFactory.getInstance().createContent(cmdPanel, null, true) content.setDisposer(cmdPanel::dispose) diff --git a/src/main/kotlin/io/github/vacxe/cliactions/model/Command.kt b/src/main/kotlin/io/github/vacxe/cliactions/model/Command.kt index 52a3f58..2161de8 100644 --- a/src/main/kotlin/io/github/vacxe/cliactions/model/Command.kt +++ b/src/main/kotlin/io/github/vacxe/cliactions/model/Command.kt @@ -6,5 +6,6 @@ import kotlinx.serialization.Serializable data class Command( val name: String, val command: String, - val prompt: Boolean = false + val prompt: Boolean = false, + val forceNewTab: Boolean = false ) \ No newline at end of file diff --git a/src/main/kotlin/io/github/vacxe/cliactions/terminal/IntellijIDETerminal.kt b/src/main/kotlin/io/github/vacxe/cliactions/terminal/IntellijIDETerminal.kt index cab4e3a..164b654 100644 --- a/src/main/kotlin/io/github/vacxe/cliactions/terminal/IntellijIDETerminal.kt +++ b/src/main/kotlin/io/github/vacxe/cliactions/terminal/IntellijIDETerminal.kt @@ -1,14 +1,33 @@ package io.github.vacxe.cliactions.terminal import com.intellij.openapi.project.Project -import org.jetbrains.plugins.terminal.TerminalView +import com.intellij.openapi.wm.ToolWindowManager +import org.jetbrains.plugins.terminal.ShellTerminalWidget +import org.jetbrains.plugins.terminal.TerminalToolWindowFactory +import org.jetbrains.plugins.terminal.TerminalToolWindowManager import java.io.IOException class IntellijIDETerminal(private val project: Project) : Terminal { - override fun run(name: String, command: String) { - val terminalView: TerminalView = TerminalView.getInstance(project) + override fun run( + name: String, + command: String, + forceNewTab: Boolean + ) { try { - terminalView.createLocalShellWidget(project.basePath, name).executeCommand(command) + val terminalView = TerminalToolWindowManager.getInstance(project) + val window = ToolWindowManager.getInstance(project).getToolWindow(TerminalToolWindowFactory.TOOL_WINDOW_ID) + val contentManager = window?.contentManager + + val widget = if (forceNewTab) { + terminalView.createLocalShellWidget(project.basePath, name) + } else { + when (val content = contentManager?.findContent(name)) { + null -> terminalView.createLocalShellWidget(project.basePath, name) + else -> TerminalToolWindowManager.getWidgetByContent(content) as ShellTerminalWidget + } + } + + widget.executeCommand(command) } catch (err: IOException) { err.printStackTrace() } diff --git a/src/main/kotlin/io/github/vacxe/cliactions/terminal/Terminal.kt b/src/main/kotlin/io/github/vacxe/cliactions/terminal/Terminal.kt index 6adfd3a..1c665ad 100644 --- a/src/main/kotlin/io/github/vacxe/cliactions/terminal/Terminal.kt +++ b/src/main/kotlin/io/github/vacxe/cliactions/terminal/Terminal.kt @@ -1,5 +1,7 @@ package io.github.vacxe.cliactions.terminal interface Terminal { - fun run(name: String, command: String) + fun run(name: String, + command: String, + forceNewTab: Boolean = false) } \ No newline at end of file diff --git a/src/main/kotlin/io/github/vacxe/cliactions/ui/CliActionsTablePanel.kt b/src/main/kotlin/io/github/vacxe/cliactions/ui/CliActionsTablePanel.kt index 537b9c2..3181b8a 100644 --- a/src/main/kotlin/io/github/vacxe/cliactions/ui/CliActionsTablePanel.kt +++ b/src/main/kotlin/io/github/vacxe/cliactions/ui/CliActionsTablePanel.kt @@ -15,7 +15,7 @@ import java.io.File import javax.swing.* class CliActionsTablePanel( - private val configurationFinder: ConfigurationProvider, private val runTerminalCommand: (String, String) -> Unit + private val configurationFinder: ConfigurationProvider, private val runTerminalCommand: (String, String, Boolean) -> Unit ) : JPanel() { private val configsUpdate: (Sequence) -> Unit = { configFiles -> @@ -80,10 +80,18 @@ class CliActionsTablePanel( null, "Run: ${iCmdCommand.name} ?", "Confirm Action", JOptionPane.YES_NO_OPTION ) == 0 ) { - runTerminalCommand.invoke(iCmdCommand.name, iCmdCommand.command) + runTerminalCommand.invoke( + iCmdCommand.name, + iCmdCommand.command, + iCmdCommand.forceNewTab + ) } } else { - runTerminalCommand.invoke(iCmdCommand.name, iCmdCommand.command) + runTerminalCommand.invoke( + iCmdCommand.name, + iCmdCommand.command, + iCmdCommand.forceNewTab + ) } } panel.add(button)