mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
[terminal] IDEA-330183 Refactor: do not subclass JPanel
GitOrigin-RevId: e4e72563c72991a5f6f6e43a0cebba9b136ba79f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8a82485f6b
commit
4639926a33
@@ -24,14 +24,14 @@ class BlockTerminalView(
|
||||
private val project: Project,
|
||||
private val session: TerminalSession,
|
||||
private val settings: JBTerminalSystemSettingsProviderBase
|
||||
) : JPanel(), TerminalContentView, TerminalCommandExecutor {
|
||||
) : TerminalContentView, TerminalCommandExecutor {
|
||||
private val controller: BlockTerminalController
|
||||
|
||||
private val outputView: TerminalOutputView = TerminalOutputView(project, session, settings)
|
||||
private val promptView: TerminalPromptView = TerminalPromptView(project, settings, session, this)
|
||||
private var alternateBufferView: SimpleTerminalView? = null
|
||||
|
||||
override val component: JComponent = this
|
||||
override val component: JComponent = JPanel()
|
||||
|
||||
override val preferredFocusableComponent: JComponent
|
||||
get() = when {
|
||||
@@ -47,7 +47,7 @@ class BlockTerminalView(
|
||||
promptView.controller.addListener(object : PromptStateListener {
|
||||
override fun promptVisibilityChanged(visible: Boolean) {
|
||||
promptView.component.isVisible = visible
|
||||
revalidate()
|
||||
component.revalidate()
|
||||
invokeLater {
|
||||
IdeFocusManager.getInstance(project).requestFocus(preferredFocusableComponent, true)
|
||||
}
|
||||
@@ -57,23 +57,23 @@ class BlockTerminalView(
|
||||
promptView.controller.addDocumentListener(object : DocumentListener {
|
||||
override fun documentChanged(event: DocumentEvent) {
|
||||
if (promptView.component.preferredHeight != promptView.component.height) {
|
||||
revalidate()
|
||||
component.revalidate()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
outputView.controller.addDocumentListener(object : DocumentListener {
|
||||
override fun documentChanged(event: DocumentEvent) {
|
||||
if (outputView.component.height < this@BlockTerminalView.height // do not revalidate if output already occupied all height
|
||||
if (outputView.component.height < component.height // do not revalidate if output already occupied all height
|
||||
&& outputView.component.preferredHeight > outputView.component.height) { // revalidate if output no more fit in current bounds
|
||||
revalidate()
|
||||
component.revalidate()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
controller = BlockTerminalController(session, outputView.controller, promptView.controller)
|
||||
|
||||
addComponentListener(object : ComponentAdapter() {
|
||||
component.addComponentListener(object : ComponentAdapter() {
|
||||
override fun componentResized(e: ComponentEvent?) {
|
||||
updateTerminalSize()
|
||||
}
|
||||
@@ -87,6 +87,7 @@ class BlockTerminalView(
|
||||
}
|
||||
})
|
||||
|
||||
component.background = TerminalUI.terminalBackground
|
||||
installPromptAndOutput()
|
||||
}
|
||||
|
||||
@@ -111,28 +112,28 @@ class BlockTerminalView(
|
||||
Disposer.register(this, view)
|
||||
alternateBufferView = view
|
||||
|
||||
removeAll()
|
||||
layout = BorderLayout()
|
||||
add(view.component, BorderLayout.CENTER)
|
||||
revalidate()
|
||||
with(component) {
|
||||
removeAll()
|
||||
layout = BorderLayout()
|
||||
add(view.component, BorderLayout.CENTER)
|
||||
revalidate()
|
||||
}
|
||||
}
|
||||
|
||||
private fun installPromptAndOutput() {
|
||||
removeAll()
|
||||
layout = BlockTerminalLayout()
|
||||
add(outputView.component, BlockTerminalLayout.TOP)
|
||||
add(promptView.component, BlockTerminalLayout.BOTTOM)
|
||||
revalidate()
|
||||
with(component) {
|
||||
removeAll()
|
||||
layout = BlockTerminalLayout()
|
||||
add(outputView.component, BlockTerminalLayout.TOP)
|
||||
add(promptView.component, BlockTerminalLayout.BOTTOM)
|
||||
revalidate()
|
||||
}
|
||||
}
|
||||
|
||||
override fun startCommandExecution(command: String) {
|
||||
controller.startCommandExecution(command)
|
||||
}
|
||||
|
||||
override fun getBackground(): Color {
|
||||
return TerminalUI.terminalBackground
|
||||
}
|
||||
|
||||
private fun updateTerminalSize() {
|
||||
val newSize = getTerminalSize() ?: return
|
||||
controller.resize(newSize)
|
||||
@@ -143,8 +144,8 @@ class BlockTerminalView(
|
||||
alternateBufferView!!.let { it.terminalWidth to it.charSize }
|
||||
}
|
||||
else outputView.let { it.terminalWidth to it.charSize }
|
||||
return if (width > 0 && height > 0) {
|
||||
TerminalUiUtils.calculateTerminalSize(Dimension(width, height), charSize)
|
||||
return if (width > 0 && component.height > 0) {
|
||||
TerminalUiUtils.calculateTerminalSize(Dimension(width, component.height), charSize)
|
||||
}
|
||||
else null
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ package org.jetbrains.plugins.terminal.exp
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.terminal.JBTerminalSystemSettingsProviderBase
|
||||
import com.intellij.util.ui.JBUI
|
||||
import com.jediterm.core.util.TermSize
|
||||
import java.awt.Dimension
|
||||
import java.awt.event.ComponentAdapter
|
||||
@@ -26,8 +25,7 @@ class PlainTerminalView(
|
||||
init {
|
||||
val eventsHandler = TerminalEventsHandler(session, settings)
|
||||
view = SimpleTerminalView(project, settings, session, eventsHandler)
|
||||
view.border = JBUI.Borders.empty()
|
||||
view.addComponentListener(object : ComponentAdapter() {
|
||||
view.component.addComponentListener(object : ComponentAdapter() {
|
||||
override fun componentResized(e: ComponentEvent?) {
|
||||
val newSize = getTerminalSize() ?: return
|
||||
session.postResize(newSize)
|
||||
@@ -39,8 +37,8 @@ class PlainTerminalView(
|
||||
|
||||
// return preferred size of the terminal calculated from the component size
|
||||
override fun getTerminalSize(): TermSize? {
|
||||
if (view.bounds.isEmpty) return null
|
||||
val contentSize = Dimension(view.terminalWidth, view.height)
|
||||
if (view.component.bounds.isEmpty) return null
|
||||
val contentSize = Dimension(view.terminalWidth, view.component.height)
|
||||
return TerminalUiUtils.calculateTerminalSize(contentSize, view.charSize)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.terminal.JBTerminalSystemSettingsProviderBase
|
||||
import com.intellij.util.ui.JBUI
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.Color
|
||||
import java.awt.Dimension
|
||||
import javax.swing.JComponent
|
||||
import javax.swing.JPanel
|
||||
@@ -24,11 +23,11 @@ class SimpleTerminalView(
|
||||
session: TerminalSession,
|
||||
eventsHandler: TerminalEventsHandler,
|
||||
private val withVerticalScroll: Boolean = true
|
||||
) : JPanel(), Disposable {
|
||||
) : Disposable {
|
||||
private val editor: EditorImpl
|
||||
private val controller: SimpleTerminalController
|
||||
|
||||
val component: JComponent = this
|
||||
val component: JComponent = JPanel()
|
||||
val preferredFocusableComponent: JComponent
|
||||
get() = editor.contentComponent
|
||||
|
||||
@@ -55,9 +54,10 @@ class SimpleTerminalView(
|
||||
}
|
||||
})
|
||||
|
||||
border = JBUI.Borders.emptyLeft(TerminalUI.alternateBufferLeftInset)
|
||||
layout = BorderLayout()
|
||||
add(editor.component, BorderLayout.CENTER)
|
||||
component.background = TerminalUI.terminalBackground
|
||||
component.border = JBUI.Borders.emptyLeft(TerminalUI.alternateBufferLeftInset)
|
||||
component.layout = BorderLayout()
|
||||
component.add(editor.component, BorderLayout.CENTER)
|
||||
}
|
||||
|
||||
private fun createEditor(): EditorImpl {
|
||||
@@ -73,10 +73,6 @@ class SimpleTerminalView(
|
||||
|
||||
fun isFocused(): Boolean = editor.contentComponent.hasFocus()
|
||||
|
||||
override fun getBackground(): Color {
|
||||
return TerminalUI.terminalBackground
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
EditorFactory.getInstance().releaseEditor(editor)
|
||||
Disposer.dispose(controller)
|
||||
|
||||
@@ -25,10 +25,10 @@ class TerminalPromptView(
|
||||
private val settings: JBTerminalSystemSettingsProviderBase,
|
||||
session: TerminalSession,
|
||||
commandExecutor: TerminalCommandExecutor
|
||||
) : JPanel(), PromptStateListener, Disposable {
|
||||
) : PromptStateListener, Disposable {
|
||||
val controller: TerminalPromptController
|
||||
val component: JComponent = JPanel()
|
||||
|
||||
val component: JComponent = this
|
||||
val preferredFocusableComponent: JComponent
|
||||
get() = editor.contentComponent
|
||||
|
||||
@@ -52,11 +52,12 @@ class TerminalPromptView(
|
||||
TerminalUI.promptBottomInset,
|
||||
TerminalUI.blockRightInset + TerminalUI.cornerToBlockInset)
|
||||
val outerBorder = JBUI.Borders.customLineTop(JBUI.CurrentTheme.CustomFrameDecorations.separatorForeground())
|
||||
border = JBUI.Borders.compound(outerBorder, innerBorder)
|
||||
component.border = JBUI.Borders.compound(outerBorder, innerBorder)
|
||||
|
||||
layout = ListLayout.vertical(TerminalUI.promptToCommandInset)
|
||||
add(promptLabel)
|
||||
add(editorTextField)
|
||||
component.background = TerminalUI.terminalBackground
|
||||
component.layout = ListLayout.vertical(TerminalUI.promptToCommandInset)
|
||||
component.add(promptLabel)
|
||||
component.add(editorTextField)
|
||||
}
|
||||
|
||||
override fun promptLabelChanged(newText: @NlsSafe String) {
|
||||
@@ -120,7 +121,5 @@ class TerminalPromptView(
|
||||
return label
|
||||
}
|
||||
|
||||
override fun getBackground(): Color = TerminalUI.terminalBackground
|
||||
|
||||
override fun dispose() {}
|
||||
}
|
||||
Reference in New Issue
Block a user