mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[terminal] IJPL-212254 Remove DetachedTabs
They stay on the way of refactoring. It is a breaking change, but its original goal is going to be addressed in the further refactoring. (cherry picked from commit fc348bda19a625ba0c2ea9f3a189b7f4f2ced0f4) IJ-CR-214214 GitOrigin-RevId: a05803183f500c5174457c67eb4c5d8e849bde17
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5ee7d9e3b8
commit
ab59bf69f2
+1
-10
@@ -37,7 +37,6 @@ internal class TerminalTabsManager(private val project: Project, private val cor
|
||||
private val tabsMap: MutableMap<Int, TerminalSessionTab> = LinkedHashMap()
|
||||
private val tabsLock = Mutex()
|
||||
private val tabIdCounter = AtomicInteger(0)
|
||||
private val detachedTabs: MutableSet<Int> = HashSet()
|
||||
|
||||
init {
|
||||
val storedTabs = TerminalTabsStorage.getInstance(project).getStoredTabs()
|
||||
@@ -55,7 +54,7 @@ internal class TerminalTabsManager(private val project: Project, private val cor
|
||||
|
||||
/** Caller must hold [tabsLock] */
|
||||
private fun getTerminalTabsNoLock(): List<TerminalSessionTab> {
|
||||
return tabsMap.values.filter { it.id !in detachedTabs }
|
||||
return tabsMap.values.toList()
|
||||
}
|
||||
|
||||
suspend fun createNewTerminalTab(): TerminalSessionTab {
|
||||
@@ -108,7 +107,6 @@ internal class TerminalTabsManager(private val project: Project, private val cor
|
||||
scope.awaitCancellationAndInvoke {
|
||||
updateTabsAndStore { tabs ->
|
||||
tabs.remove(tabId)
|
||||
detachedTabs -= tabId
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +138,6 @@ internal class TerminalTabsManager(private val project: Project, private val cor
|
||||
else {
|
||||
// The session was not started - just remove the tab.
|
||||
tabs.remove(tabId)
|
||||
detachedTabs -= tabId
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -241,12 +238,6 @@ internal class TerminalTabsManager(private val project: Project, private val cor
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun detachTerminalTab(tabId: Int) {
|
||||
updateTabsAndStore {
|
||||
detachedTabs += tabId
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getInstance(project: Project): TerminalTabsManager {
|
||||
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
package com.intellij.terminal.frontend.toolwindow.impl
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.terminal.frontend.session.TerminalTabsManager
|
||||
import com.intellij.terminal.frontend.toolwindow.TerminalTabsManagerListener
|
||||
import com.intellij.terminal.frontend.toolwindow.TerminalToolWindowTab
|
||||
import com.intellij.terminal.frontend.view.TerminalView
|
||||
import com.intellij.util.AwaitCancellationAndInvoke
|
||||
import com.intellij.util.awaitCancellationAndInvoke
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.Collections
|
||||
import java.util.IdentityHashMap
|
||||
|
||||
/**
|
||||
* Notifies [TerminalTabsManager] when a terminal tab is detached,
|
||||
* so it isn't restored on the next IDE start.
|
||||
*/
|
||||
internal class DetachedTabs(
|
||||
private val project: Project,
|
||||
private val coroutineScope: CoroutineScope,
|
||||
) {
|
||||
|
||||
private val lock = Any()
|
||||
private val detachedViews: MutableSet<TerminalView> = Collections.newSetFromMap(IdentityHashMap())
|
||||
private val viewsWithIds: MutableMap<TerminalView, Int> = IdentityHashMap()
|
||||
|
||||
init {
|
||||
project.messageBus.connect(coroutineScope).subscribe(TerminalTabsManagerListener.TOPIC, object : TerminalTabsManagerListener {
|
||||
override fun tabDetached(tab: TerminalToolWindowTab) {
|
||||
onTabDetached(tab.view)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun onTabDetached(detachedView: TerminalView) {
|
||||
synchronized(lock) {
|
||||
detachedViews.add(detachedView)
|
||||
}
|
||||
tryMatchAndDetach(detachedView)
|
||||
}
|
||||
|
||||
/** May be called before or after [onTabDetached]. */
|
||||
@OptIn(AwaitCancellationAndInvoke::class)
|
||||
fun onTabCreated(terminalView: TerminalView, tabId: Int) {
|
||||
synchronized(lock) {
|
||||
viewsWithIds[terminalView] = tabId
|
||||
}
|
||||
tryMatchAndDetach(terminalView)
|
||||
terminalView.coroutineScope.awaitCancellationAndInvoke {
|
||||
synchronized(lock) {
|
||||
viewsWithIds.remove(terminalView)
|
||||
detachedViews.remove(terminalView)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun tryMatchAndDetach(view: TerminalView) {
|
||||
val tabId = synchronized(lock) {
|
||||
if (view in detachedViews && view in viewsWithIds) {
|
||||
detachedViews.remove(view)
|
||||
viewsWithIds.remove(view)
|
||||
}
|
||||
else {
|
||||
null
|
||||
}
|
||||
}
|
||||
if (tabId != null) {
|
||||
coroutineScope.launch {
|
||||
TerminalTabsManager.getInstance(project).detachTerminalTab(tabId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-4
@@ -79,8 +79,6 @@ internal class TerminalToolWindowTabsManagerImpl(
|
||||
|
||||
private var tabsRestoredDeferred: Deferred<Unit> = CompletableDeferred(Unit)
|
||||
|
||||
private val detachedTabs = DetachedTabs(project, coroutineScope)
|
||||
|
||||
init {
|
||||
project.messageBus.connect(coroutineScope).subscribe(ToolWindowManagerListener.TOPIC, object : ToolWindowManagerListener {
|
||||
override fun toolWindowShown(toolWindow: ToolWindow) {
|
||||
@@ -292,8 +290,6 @@ internal class TerminalToolWindowTabsManagerImpl(
|
||||
) = terminal.coroutineScope.launch {
|
||||
val backendTabId = existingBackendTabId ?: TerminalTabsManager.getInstance(project).createNewTerminalTab().id
|
||||
|
||||
detachedTabs.onTabCreated(terminal, backendTabId)
|
||||
|
||||
terminal.coroutineScope.awaitCancellationAndInvoke(Dispatchers.EDT) {
|
||||
// Backend terminal session tab lifecycle is not directly bound to the terminal frontend lifecycle.
|
||||
// We need to close the backend session when the terminal is closed explicitly.
|
||||
|
||||
Reference in New Issue
Block a user