[terminal] IDEA-330183 Refactor: rename UI classes to View

GitOrigin-RevId: 27ca0ac28003e5e37cb94feeeb4e6eb5f6b0bfb8
This commit is contained in:
Konstantin Hudyakov
2023-08-22 13:36:32 +03:00
committed by intellij-monorepo-bot
parent 1707b7d836
commit 65be4df856
10 changed files with 80 additions and 78 deletions

View File

@@ -20,24 +20,24 @@ import javax.swing.JPanel
import kotlin.math.max
import kotlin.math.min
class BlockTerminalPanel(
class BlockTerminalView(
private val project: Project,
private val session: TerminalSession,
private val settings: JBTerminalSystemSettingsProviderBase
) : JPanel(), TerminalContentController, TerminalCommandExecutor {
) : JPanel(), TerminalContentView, TerminalCommandExecutor {
private val controller: BlockTerminalController
private val outputPanel: TerminalOutputPanel
private val promptPanel: TerminalPromptPanel
private var alternateBufferPanel: TerminalPanel? = null
private val outputView: TerminalOutputView
private val promptView: TerminalPromptView
private var alternateBufferView: SimpleTerminalView? = null
init {
outputPanel = TerminalOutputPanel(project, session, settings)
promptPanel = TerminalPromptPanel(project, settings, session, this)
outputView = TerminalOutputView(project, session, settings)
promptView = TerminalPromptView(project, settings, session, this)
promptPanel.controller.addListener(object : PromptStateListener {
promptView.controller.addListener(object : PromptStateListener {
override fun promptVisibilityChanged(visible: Boolean) {
promptPanel.component.isVisible = visible
promptView.component.isVisible = visible
revalidate()
invokeLater {
IdeFocusManager.getInstance(project).requestFocus(preferredFocusableComponent, true)
@@ -45,24 +45,24 @@ class BlockTerminalPanel(
}
})
promptPanel.controller.addDocumentListener(object : DocumentListener {
promptView.controller.addDocumentListener(object : DocumentListener {
override fun documentChanged(event: DocumentEvent) {
if (promptPanel.component.preferredHeight != promptPanel.component.height) {
if (promptView.component.preferredHeight != promptView.component.height) {
revalidate()
}
}
})
outputPanel.controller.addDocumentListener(object : DocumentListener {
outputView.controller.addDocumentListener(object : DocumentListener {
override fun documentChanged(event: DocumentEvent) {
if (outputPanel.component.height < this@BlockTerminalPanel.height // do not revalidate if output already occupied all height
&& outputPanel.component.preferredHeight > outputPanel.component.height) { // revalidate if output no more fit in current bounds
if (outputView.component.height < this@BlockTerminalView.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()
}
}
})
controller = BlockTerminalController(session, outputPanel.controller, promptPanel.controller)
controller = BlockTerminalController(session, outputView.controller, promptView.controller)
addComponentListener(object : ComponentAdapter() {
override fun componentResized(e: ComponentEvent?) {
@@ -86,8 +86,8 @@ class BlockTerminalPanel(
installAlternateBufferPanel()
}
else {
alternateBufferPanel?.let { Disposer.dispose(it) }
alternateBufferPanel = null
alternateBufferView?.let { Disposer.dispose(it) }
alternateBufferView = null
installPromptAndOutput()
}
IdeFocusManager.getInstance(project).requestFocus(preferredFocusableComponent, true)
@@ -98,21 +98,21 @@ class BlockTerminalPanel(
private fun installAlternateBufferPanel() {
val eventsHandler = TerminalEventsHandler(session, settings)
val panel = TerminalPanel(project, settings, session, eventsHandler, withVerticalScroll = false)
Disposer.register(this, panel)
alternateBufferPanel = panel
val view = SimpleTerminalView(project, settings, session, eventsHandler, withVerticalScroll = false)
Disposer.register(this, view)
alternateBufferView = view
removeAll()
layout = BorderLayout()
add(panel.component, BorderLayout.CENTER)
add(view.component, BorderLayout.CENTER)
revalidate()
}
private fun installPromptAndOutput() {
removeAll()
layout = BlockTerminalLayout()
add(outputPanel.component, BlockTerminalLayout.TOP)
add(promptPanel.component, BlockTerminalLayout.BOTTOM)
add(outputView.component, BlockTerminalLayout.TOP)
add(promptView.component, BlockTerminalLayout.BOTTOM)
revalidate()
}
@@ -130,10 +130,10 @@ class BlockTerminalPanel(
}
override fun getTerminalSize(): TermSize? {
val (width, charSize) = if (alternateBufferPanel != null) {
alternateBufferPanel!!.let { it.terminalWidth to it.charSize }
val (width, charSize) = if (alternateBufferView != null) {
alternateBufferView!!.let { it.terminalWidth to it.charSize }
}
else outputPanel.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)
}
@@ -141,21 +141,21 @@ class BlockTerminalPanel(
}
override fun isFocused(): Boolean {
return outputPanel.component.hasFocus() || promptPanel.component.hasFocus()
return outputView.component.hasFocus() || promptView.component.hasFocus()
}
override fun dispose() {
Disposer.dispose(outputPanel)
Disposer.dispose(promptPanel)
Disposer.dispose(outputView)
Disposer.dispose(promptView)
}
override fun getComponent(): JComponent = this
override fun getPreferredFocusableComponent(): JComponent {
return when {
alternateBufferPanel != null -> alternateBufferPanel!!.preferredFocusableComponent
promptPanel.component.isVisible -> promptPanel.preferredFocusableComponent
else -> outputPanel.preferredFocusableComponent
alternateBufferView != null -> alternateBufferView!!.preferredFocusableComponent
promptView.component.isVisible -> promptView.preferredFocusableComponent
else -> outputView.preferredFocusableComponent
}
}

View File

@@ -11,41 +11,41 @@ import java.awt.event.ComponentAdapter
import java.awt.event.ComponentEvent
import javax.swing.JComponent
class PlainTerminalController(
class PlainTerminalView(
project: Project,
private val session: TerminalSession,
settings: JBTerminalSystemSettingsProviderBase
) : TerminalContentController {
private val panel: TerminalPanel
) : TerminalContentView {
private val view: SimpleTerminalView
init {
val eventsHandler = TerminalEventsHandler(session, settings)
panel = TerminalPanel(project, settings, session, eventsHandler)
panel.border = JBUI.Borders.empty()
panel.addComponentListener(object : ComponentAdapter() {
view = SimpleTerminalView(project, settings, session, eventsHandler)
view.border = JBUI.Borders.empty()
view.addComponentListener(object : ComponentAdapter() {
override fun componentResized(e: ComponentEvent?) {
val newSize = getTerminalSize() ?: return
session.postResize(newSize)
}
})
Disposer.register(this, panel)
Disposer.register(this, view)
}
// return preferred size of the terminal calculated from the component size
override fun getTerminalSize(): TermSize? {
if (panel.bounds.isEmpty) return null
val contentSize = Dimension(panel.terminalWidth, panel.height)
return TerminalUiUtils.calculateTerminalSize(contentSize, panel.charSize)
if (view.bounds.isEmpty) return null
val contentSize = Dimension(view.terminalWidth, view.height)
return TerminalUiUtils.calculateTerminalSize(contentSize, view.charSize)
}
override fun isFocused(): Boolean {
return panel.isFocused()
return view.isFocused()
}
override fun getComponent(): JComponent = panel
override fun getComponent(): JComponent = view
override fun getPreferredFocusableComponent(): JComponent = panel.preferredFocusableComponent
override fun getPreferredFocusableComponent(): JComponent = view.preferredFocusableComponent
override fun dispose() {
}

View File

@@ -20,10 +20,12 @@ import com.jediterm.terminal.ui.AwtTransformers
import java.awt.Color
import java.awt.Font
class TerminalPanelController(private val settings: JBTerminalSystemSettingsProviderBase,
private val session: TerminalSession,
private val editor: EditorEx,
eventsHandler: TerminalEventsHandler) : Disposable {
class SimpleTerminalController(
private val settings: JBTerminalSystemSettingsProviderBase,
private val session: TerminalSession,
private val editor: EditorEx,
eventsHandler: TerminalEventsHandler
) : Disposable {
val document: Document
get() = editor.document
private val palette: ColorPalette

View File

@@ -18,13 +18,15 @@ import javax.swing.JComponent
import javax.swing.JPanel
import javax.swing.JScrollPane
class TerminalPanel(private val project: Project,
private val settings: JBTerminalSystemSettingsProviderBase,
session: TerminalSession,
eventsHandler: TerminalEventsHandler,
private val withVerticalScroll: Boolean = true) : JPanel(), ComponentContainer {
class SimpleTerminalView(
private val project: Project,
private val settings: JBTerminalSystemSettingsProviderBase,
session: TerminalSession,
eventsHandler: TerminalEventsHandler,
private val withVerticalScroll: Boolean = true
) : JPanel(), ComponentContainer {
private val editor: EditorImpl
private val controller: TerminalPanelController
private val controller: SimpleTerminalController
val terminalWidth: Int
get() {
@@ -38,7 +40,7 @@ class TerminalPanel(private val project: Project,
init {
editor = createEditor()
controller = TerminalPanelController(settings, session, editor, eventsHandler)
controller = SimpleTerminalController(settings, session, editor, eventsHandler)
editor.addFocusListener(object : FocusChangeListener {
override fun focusGained(editor: Editor) {
controller.isFocused = true

View File

@@ -4,7 +4,7 @@ package org.jetbrains.plugins.terminal.exp
import com.intellij.openapi.ui.ComponentContainer
import com.jediterm.core.util.TermSize
interface TerminalContentController : ComponentContainer {
interface TerminalContentView : ComponentContainer {
fun getTerminalSize(): TermSize?
fun isFocused(): Boolean

View File

@@ -26,8 +26,7 @@ import kotlin.math.min
/**
* Mostly duplicates the logic of [com.jediterm.terminal.model.JediTerminal],
* but do not modify the view directly. All changes are reflected on [TerminalModel]
* and propagated to the [TerminalPanel].
* but do not modify the view directly.
*/
class TerminalController(private val model: TerminalModel,
private val settings: JBTerminalSystemSettingsProviderBase) : Terminal {

View File

@@ -18,7 +18,7 @@ import java.nio.charset.Charset
import javax.swing.SwingUtilities
/**
* Logic of key events handling is copied from [org.jetbrains.plugins.terminal.exp.TerminalPanel]
* Logic of key events handling is copied from [com.jediterm.terminal.ui.TerminalPanel]
* Logic of mouse event handling is copied from [com.jediterm.terminal.model.JediTerminal]
*/
class TerminalEventsHandler(private val session: TerminalSession,

View File

@@ -12,7 +12,7 @@ import com.intellij.terminal.JBTerminalSystemSettingsProviderBase
import java.awt.Dimension
import javax.swing.JComponent
class TerminalOutputPanel(
class TerminalOutputView(
private val project: Project,
session: TerminalSession,
settings: JBTerminalSystemSettingsProviderBase

View File

@@ -20,7 +20,7 @@ import javax.swing.JComponent
import javax.swing.JLabel
import javax.swing.JPanel
class TerminalPromptPanel(
class TerminalPromptView(
private val project: Project,
private val settings: JBTerminalSystemSettingsProviderBase,
session: TerminalSession,

View File

@@ -11,7 +11,6 @@ import com.intellij.terminal.ui.TerminalWidget
import com.intellij.terminal.ui.TtyConnectorAccessor
import com.intellij.ui.components.panels.Wrapper
import com.intellij.util.concurrency.annotations.RequiresEdt
import com.intellij.util.ui.UIUtil
import com.jediterm.core.util.TermSize
import com.jediterm.terminal.RequestOrigin
import com.jediterm.terminal.TtyConnector
@@ -29,18 +28,18 @@ class TerminalWidgetImpl(private val project: Project,
override val terminalTitle: TerminalTitle = TerminalTitle()
override val termSize: TermSize?
get() = controller.getTerminalSize()
get() = view.getTerminalSize()
override val ttyConnectorAccessor: TtyConnectorAccessor = TtyConnectorAccessor()
private val session: TerminalSession = TerminalSession(terminalSettings)
private var controller: TerminalContentController = TerminalPlaceholder()
private var view: TerminalContentView = TerminalPlaceholder()
init {
wrapper.setContent(controller.component)
wrapper.setContent(view.component)
Disposer.register(parent, this)
Disposer.register(this, session)
Disposer.register(this, controller)
Disposer.register(this, view)
}
override fun connectToTty(ttyConnector: TtyConnector, initialTermSize: TermSize) {
@@ -52,18 +51,18 @@ class TerminalWidgetImpl(private val project: Project,
@RequiresEdt(generateAssertion = false)
fun initialize(options: ShellStartupOptions): CompletableFuture<TermSize> {
session.shellIntegration = options.shellIntegration
Disposer.dispose(controller)
controller = if (options.shellIntegration?.withCommandBlocks == true) {
BlockTerminalPanel(project, session, terminalSettings)
Disposer.dispose(view)
view = if (options.shellIntegration?.withCommandBlocks == true) {
BlockTerminalView(project, session, terminalSettings)
}
else PlainTerminalController(project, session, terminalSettings)
Disposer.register(this, controller)
else PlainTerminalView(project, session, terminalSettings)
Disposer.register(this, view)
val component = controller.component
val component = view.component
wrapper.setContent(component)
return TerminalUiUtils.awaitComponentLayout(component, controller).thenApply {
controller.getTerminalSize()
return TerminalUiUtils.awaitComponentLayout(component, view).thenApply {
view.getTerminalSize()
}
}
@@ -76,7 +75,7 @@ class TerminalWidgetImpl(private val project: Project,
}
override fun hasFocus(): Boolean {
return controller.isFocused()
return view.isFocused()
}
override fun requestFocus() {
@@ -97,9 +96,9 @@ class TerminalWidgetImpl(private val project: Project,
override fun getComponent(): JComponent = wrapper
override fun getPreferredFocusableComponent(): JComponent = controller.preferredFocusableComponent
override fun getPreferredFocusableComponent(): JComponent = view.preferredFocusableComponent
private class TerminalPlaceholder : TerminalContentController {
private class TerminalPlaceholder : TerminalContentView {
private val panel: JPanel = object : JPanel() {
override fun getBackground(): Color {
return TerminalUI.terminalBackground