Skip to content

Commit

Permalink
Some code polishing and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
elmot committed Apr 2, 2024
1 parent 530e9b2 commit dbdc634
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ import com.intellij.terminal.TerminalExecutionConsole
import com.intellij.ui.content.ContentFactory
import com.jetbrains.micropython.repl.MicroPythonReplManager
import com.jetbrains.micropython.settings.MicroPythonFacet
import com.jetbrains.micropython.settings.MicroPythonFacetType
import com.jetbrains.micropython.settings.firstMicroPythonFacet

private val COMMAND_KEY = com.intellij.openapi.util.Key<Boolean>("MicroPythonCommand")

class RemoveAllFilesFromDeviceAction : MicroPythonAction() {

override fun actionPerformed(e: AnActionEvent) {
Expand All @@ -50,26 +53,28 @@ class RemoveAllFilesFromDeviceAction : MicroPythonAction() {
Disposer.register(facet, console)

osProcessHandler.addProcessListener(
object: ProcessListener{
object : ProcessListener {
override fun processTerminated(event: ProcessEvent) {
with(console.terminalWidget.terminal){
with(console.terminalWidget.terminal) {
nextLine()
writeCharacters("==== Finished with exit code ${event.exitCode} ====")
}
}
}
)

val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("MicroPython") ?: return
val toolWindow =
ToolWindowManager.getInstance(project).getToolWindow(MicroPythonFacetType.PRESENTABLE_NAME) ?: return
toolWindow.show()
val contentManager = toolWindow.contentManager
var content = contentManager.findContent("Command")
var content = contentManager.contents.firstOrNull { it.getUserData(COMMAND_KEY) ?: false }
if (content == null) {
content = ContentFactory.getInstance().createContent(null, "Command", true)
content = ContentFactory.getInstance().createContent(console.component, "Command", true)
content.putUserData(COMMAND_KEY, true)
content.isCloseable = true
contentManager.addContent(content)
}

content.component = console.component
toolWindow.activate(null)
contentManager.setSelectedContent(content)
osProcessHandler.startNotify()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.StandardFileSystems
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.util.PathUtil
import com.intellij.util.PlatformUtils
import com.jetbrains.micropython.repl.MicroPythonReplManager
Expand Down Expand Up @@ -88,7 +87,6 @@ class MicroPythonRunConfiguration(project: Project, factory: ConfigurationFactor
return RunStateWrapper(state) {
ApplicationManager.getApplication().invokeLater {
project.service<MicroPythonReplManager>().startOrRestartRepl()
ToolWindowManager.getInstance(project).getToolWindow("MicroPython")?.show()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ToolWindowFactory
import com.intellij.ui.content.ContentFactory
import com.jetbrains.micropython.repl.MICROPYTHON_REPL_CONTROL
import com.jetbrains.micropython.repl.MicroPythonReplControl
import com.jetbrains.micropython.repl.MicroPythonReplManager
import com.jetbrains.micropython.repl.ToolWindowReplTab
import com.jetbrains.micropython.settings.firstMicroPythonFacet
Expand All @@ -19,6 +21,15 @@ class MicroPythonToolWindowFactory : ToolWindowFactory, DumbAware {
terminalContent.component = ToolWindowReplTab(it.module, terminalContent).createUI()
toolWindow.contentManager.addContent(terminalContent)
project.service<MicroPythonReplManager>().startOrRestartRepl()
project.messageBus.connect().subscribe(MICROPYTHON_REPL_CONTROL,
object : MicroPythonReplControl {
override fun stopRepl() {}
override fun startOrRestartRepl() {
toolWindow.contentManager.setSelectedContent(terminalContent)
toolWindow.show()
}
}
)
}
}

Expand Down

0 comments on commit dbdc634

Please sign in to comment.