mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use the only AWT listener
GitOrigin-RevId: fa565967fd06832604496481d471f58359fb4a49
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f51d4217f9
commit
c2c551dee7
@@ -133,12 +133,21 @@ open class ToolWindowManagerImpl(val project: Project) : ToolWindowManagerEx(),
|
||||
init {
|
||||
awtFocusListener = AWTEventListener { event ->
|
||||
event as FocusEvent
|
||||
|
||||
handlePinnedWindowFocusEvent(event) { toolWindowId ->
|
||||
process { manager ->
|
||||
val entry = manager.idToEntry.get(toolWindowId) ?: return@process
|
||||
val info = manager.layout.getInfo(toolWindowId) ?: return@process
|
||||
manager.doDeactivateToolWindow(info, entry)
|
||||
}
|
||||
}
|
||||
|
||||
if (event.id != FocusEvent.FOCUS_GAINED) {
|
||||
return@AWTEventListener
|
||||
}
|
||||
|
||||
val component = event.component ?: return@AWTEventListener
|
||||
processOpenedProjects { project ->
|
||||
val component = event.component ?: return@AWTEventListener
|
||||
for (composite in FileEditorManagerEx.getInstanceEx(project).splitters.editorComposites) {
|
||||
if (composite.editors.any { SwingUtilities.isDescendingFrom(component, it.component) }) {
|
||||
(getInstance(project) as ToolWindowManagerImpl).activeStack.clear()
|
||||
@@ -168,15 +177,6 @@ open class ToolWindowManagerImpl(val project: Project) : ToolWindowManagerEx(),
|
||||
}
|
||||
})
|
||||
|
||||
addFocusLostListener(pinnedWindowFocusLostHandler = { toolWindowId ->
|
||||
process { manager ->
|
||||
val entry = manager.idToEntry.get(toolWindowId) ?: return@process
|
||||
val info = manager.layout.getInfo(toolWindowId) ?: return@process
|
||||
manager.doDeactivateToolWindow(info, entry)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
connection.subscribe(KeymapManagerListener.TOPIC, object : KeymapManagerListener {
|
||||
override fun activeKeymapChanged(keymap: Keymap?) {
|
||||
process { manager ->
|
||||
@@ -1907,28 +1907,25 @@ internal enum class ToolWindowProperty {
|
||||
TITLE, ICON, AVAILABLE, STRIPE_TITLE
|
||||
}
|
||||
|
||||
private fun addFocusLostListener(pinnedWindowFocusLostHandler: (String) -> Unit) {
|
||||
val listener = AWTEventListener { event ->
|
||||
val eventId = event.id
|
||||
if (event !is FocusEvent || !(eventId == FocusEvent.FOCUS_LOST || eventId == FocusEvent.FOCUS_LOST || eventId == FocusEvent.FOCUS_GAINED)) {
|
||||
return@AWTEventListener
|
||||
}
|
||||
private fun handlePinnedWindowFocusEvent(event: FocusEvent, pinnedWindowFocusLostHandler: (String) -> Unit) {
|
||||
val eventId = event.id
|
||||
if (!(eventId == FocusEvent.FOCUS_LOST || eventId == FocusEvent.FOCUS_LOST || eventId == FocusEvent.FOCUS_GAINED)) {
|
||||
return
|
||||
}
|
||||
|
||||
val id = ToolWindowManager.getActiveId() ?: return@AWTEventListener
|
||||
val id = ToolWindowManager.getActiveId() ?: return
|
||||
|
||||
// let's check that it is a toolwindow who loses the focus
|
||||
if (event.oppositeComponent != null && isInActiveToolWindow(event.source) && !isInActiveToolWindow(event.oppositeComponent)) {
|
||||
// a toolwindow lost focus
|
||||
val activeToolWindow = getActiveToolWindow()
|
||||
val focusGoesToPopup = JBPopupFactory.getInstance().getParentBalloonFor(event.oppositeComponent) != null
|
||||
if (!event.isTemporary &&
|
||||
!focusGoesToPopup && activeToolWindow != null &&
|
||||
(activeToolWindow.isAutoHide || activeToolWindow.type == ToolWindowType.SLIDING)) {
|
||||
pinnedWindowFocusLostHandler(id)
|
||||
}
|
||||
// let's check that it is a toolwindow who loses the focus
|
||||
if (event.oppositeComponent != null && isInActiveToolWindow(event.source) && !isInActiveToolWindow(event.oppositeComponent)) {
|
||||
// a toolwindow lost focus
|
||||
val activeToolWindow = getActiveToolWindow()
|
||||
val focusGoesToPopup = JBPopupFactory.getInstance().getParentBalloonFor(event.oppositeComponent) != null
|
||||
if (!event.isTemporary &&
|
||||
!focusGoesToPopup && activeToolWindow != null &&
|
||||
(activeToolWindow.isAutoHide || activeToolWindow.type == ToolWindowType.SLIDING)) {
|
||||
pinnedWindowFocusLostHandler(id)
|
||||
}
|
||||
}
|
||||
Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.FOCUS_EVENT_MASK)
|
||||
}
|
||||
|
||||
private fun isInActiveToolWindow(component: Any?): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user