Skip to content

Commit

Permalink
Merge pull request #9 from Vacxe/migrate-new-terminal
Browse files Browse the repository at this point in the history
feat(debt): migrate to new terminal
  • Loading branch information
Vacxe authored Mar 4, 2024
2 parents 93301dc + bb1ea66 commit 47a72e1
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 15 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand All @@ -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.
""")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/io/github/vacxe/cliactions/model/Command.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
@@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<File>) -> Unit = { configFiles ->
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 47a72e1

Please sign in to comment.