[terminal] IDEA-330183 Refactor: do not use ComponentContainer interface

It makes FindUsages much harder to use, because there are a lot of `ComponentContainer` implementations. Also, our components are never referenced as `ComponentContainer`, so it can be just removed.

GitOrigin-RevId: 12b07ca2a5648d544164e2a4dca2cfddef1233df
This commit is contained in:
Konstantin Hudyakov
2023-08-22 14:09:57 +03:00
committed by intellij-monorepo-bot
parent b632e93ca8
commit 8a82485f6b
7 changed files with 42 additions and 39 deletions

View File

@@ -31,6 +31,15 @@ class BlockTerminalView(
private val promptView: TerminalPromptView = TerminalPromptView(project, settings, session, this)
private var alternateBufferView: SimpleTerminalView? = null
override val component: JComponent = this
override val preferredFocusableComponent: JComponent
get() = when {
alternateBufferView != null -> alternateBufferView!!.preferredFocusableComponent
promptView.component.isVisible -> promptView.preferredFocusableComponent
else -> outputView.preferredFocusableComponent
}
init {
Disposer.register(this, outputView)
Disposer.register(this, promptView)
@@ -146,16 +155,6 @@ class BlockTerminalView(
override fun dispose() {}
override fun getComponent(): JComponent = this
override fun getPreferredFocusableComponent(): JComponent {
return when {
alternateBufferView != null -> alternateBufferView!!.preferredFocusableComponent
promptView.component.isVisible -> promptView.preferredFocusableComponent
else -> outputView.preferredFocusableComponent
}
}
/**
* This layout is needed to place [TOP] component (command blocks) over the [BOTTOM] component (prompt).
* The height of the [TOP] component is limited by the container size minus preferred height of the [BOTTOM].

View File

@@ -16,6 +16,11 @@ class PlainTerminalView(
private val session: TerminalSession,
settings: JBTerminalSystemSettingsProviderBase
) : TerminalContentView {
override val component: JComponent
get() = view.component
override val preferredFocusableComponent: JComponent
get() = view.preferredFocusableComponent
private val view: SimpleTerminalView
init {
@@ -43,10 +48,6 @@ class PlainTerminalView(
return view.isFocused()
}
override fun getComponent(): JComponent = view
override fun getPreferredFocusableComponent(): JComponent = view.preferredFocusableComponent
override fun dispose() {
}
}

View File

@@ -1,13 +1,13 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.plugins.terminal.exp
import com.intellij.openapi.Disposable
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.EditorFactory
import com.intellij.openapi.editor.ex.FocusChangeListener
import com.intellij.openapi.editor.impl.DocumentImpl
import com.intellij.openapi.editor.impl.EditorImpl
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.ComponentContainer
import com.intellij.openapi.util.Disposer
import com.intellij.terminal.JBTerminalSystemSettingsProviderBase
import com.intellij.util.ui.JBUI
@@ -24,10 +24,14 @@ class SimpleTerminalView(
session: TerminalSession,
eventsHandler: TerminalEventsHandler,
private val withVerticalScroll: Boolean = true
) : JPanel(), ComponentContainer {
) : JPanel(), Disposable {
private val editor: EditorImpl
private val controller: SimpleTerminalController
val component: JComponent = this
val preferredFocusableComponent: JComponent
get() = editor.contentComponent
val terminalWidth: Int
get() {
val visibleArea = editor.scrollingModel.visibleArea
@@ -73,10 +77,6 @@ class SimpleTerminalView(
return TerminalUI.terminalBackground
}
override fun getComponent(): JComponent = this
override fun getPreferredFocusableComponent(): JComponent = editor.contentComponent
override fun dispose() {
EditorFactory.getInstance().releaseEditor(editor)
Disposer.dispose(controller)

View File

@@ -1,10 +1,15 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.plugins.terminal.exp
import com.intellij.openapi.ui.ComponentContainer
import com.intellij.openapi.Disposable
import com.jediterm.core.util.TermSize
import javax.swing.JComponent
interface TerminalContentView : Disposable {
val component: JComponent
val preferredFocusableComponent: JComponent
interface TerminalContentView : ComponentContainer {
fun getTerminalSize(): TermSize?
fun isFocused(): Boolean

View File

@@ -1,13 +1,13 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.plugins.terminal.exp
import com.intellij.openapi.Disposable
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.EditorFactory
import com.intellij.openapi.editor.ex.FocusChangeListener
import com.intellij.openapi.editor.impl.DocumentImpl
import com.intellij.openapi.editor.impl.EditorImpl
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.ComponentContainer
import com.intellij.terminal.JBTerminalSystemSettingsProviderBase
import java.awt.Dimension
import javax.swing.JComponent
@@ -16,8 +16,12 @@ class TerminalOutputView(
private val project: Project,
session: TerminalSession,
settings: JBTerminalSystemSettingsProviderBase
) : ComponentContainer {
) : Disposable {
val controller: TerminalOutputController
val component: JComponent
get() = editor.component
val preferredFocusableComponent: JComponent
get() = editor.contentComponent
private val editor: EditorImpl
@@ -56,8 +60,4 @@ class TerminalOutputView(
override fun dispose() {
EditorFactory.getInstance().releaseEditor(editor)
}
override fun getComponent(): JComponent = editor.component
override fun getPreferredFocusableComponent(): JComponent = editor.contentComponent
}

View File

@@ -1,12 +1,12 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.plugins.terminal.exp
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.editor.ex.util.EditorUtil
import com.intellij.openapi.editor.impl.EditorImpl
import com.intellij.openapi.fileTypes.PlainTextLanguage
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.ComponentContainer
import com.intellij.openapi.util.NlsSafe
import com.intellij.terminal.JBTerminalSystemSettingsProviderBase
import com.intellij.ui.LanguageTextField
@@ -25,9 +25,13 @@ class TerminalPromptView(
private val settings: JBTerminalSystemSettingsProviderBase,
session: TerminalSession,
commandExecutor: TerminalCommandExecutor
) : JPanel(), ComponentContainer, PromptStateListener {
) : JPanel(), PromptStateListener, Disposable {
val controller: TerminalPromptController
val component: JComponent = this
val preferredFocusableComponent: JComponent
get() = editor.contentComponent
private val editor: EditorImpl
private val promptLabel: JLabel
private val commandHistoryPresenter: CommandHistoryPresenter
@@ -118,9 +122,5 @@ class TerminalPromptView(
override fun getBackground(): Color = TerminalUI.terminalBackground
override fun getComponent(): JComponent = this
override fun getPreferredFocusableComponent(): JComponent = editor.contentComponent
override fun dispose() {}
}

View File

@@ -99,20 +99,18 @@ class TerminalWidgetImpl(private val project: Project,
override fun getPreferredFocusableComponent(): JComponent = view.preferredFocusableComponent
private class TerminalPlaceholder : TerminalContentView {
private val panel: JPanel = object : JPanel() {
override val component: JComponent = object : JPanel() {
override fun getBackground(): Color {
return TerminalUI.terminalBackground
}
}
override val preferredFocusableComponent: JComponent = component
override fun getTerminalSize(): TermSize? = null
override fun isFocused(): Boolean = false
override fun getComponent(): JComponent = panel
override fun getPreferredFocusableComponent(): JComponent = panel
override fun dispose() {
}
}