IDEA-229436 NPE at ContentManagerImpl.getComponent() through JSLanguageServiceToolWindowManager.resetToolWindow() on closing Kotlin/JS project

GitOrigin-RevId: 918a48c40063e55a96a9298d2ef6124cf80bb1b1
This commit is contained in:
Vladimir Krivosheev
2019-12-19 17:35:54 +00:00
committed by intellij-monorepo-bot
parent ef9fd04f37
commit 4cc56ef3cf
3 changed files with 18 additions and 9 deletions
@@ -95,15 +95,20 @@ public final class InternalDecorator extends JPanel implements Queryable, DataPr
return toolWindow.getId();
}
public boolean isFocused() {
public boolean isFocused(@NotNull IdeFrame ideFrame) {
IdeFocusManager focusManager = toolWindow.getToolWindowManager().getFocusManager();
Component component = focusManager.getFocusedDescendantFor(toolWindow.getComponent());
JComponent toolWindowComponent = toolWindow.getComponentIfInitialized();
if (toolWindowComponent == null) {
return false;
}
Component component = focusManager.getFocusedDescendantFor(toolWindowComponent);
if (component != null) {
return true;
}
Component owner = focusManager.getLastFocusedFor(WindowManager.getInstance().getIdeFrame(toolWindow.getToolWindowManager().getProject()));
return owner != null && SwingUtilities.isDescendingFrom(owner, toolWindow.getComponent());
Component owner = focusManager.getLastFocusedFor(ideFrame);
return owner != null && SwingUtilities.isDescendingFrom(owner, toolWindowComponent);
}
void applyWindowInfo(@NotNull WindowInfo info) {
@@ -19,7 +19,6 @@ import com.intellij.openapi.util.BusyObject
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.wm.*
import com.intellij.openapi.wm.ex.ToolWindowEx
import com.intellij.openapi.wm.ex.WindowManagerEx
import com.intellij.openapi.wm.impl.content.ToolWindowContentUi
import com.intellij.ui.LayeredIcon
import com.intellij.ui.UIBundle
@@ -169,8 +168,9 @@ class ToolWindowImpl internal constructor(val toolWindowManager: ToolWindowManag
override fun isActive(): Boolean {
ApplicationManager.getApplication().assertIsDispatchThread()
val frame = WindowManagerEx.getInstanceEx().getFrame(toolWindowManager.project)
if (frame == null || !frame.isActive || toolWindowManager.isEditorComponentActive) {
val frameHelper = toolWindowManager.getFrame() ?: return false
val frame = frameHelper.frame
if (!frame.isActive || toolWindowManager.isEditorComponentActive) {
return false
}
@@ -179,7 +179,7 @@ class ToolWindowImpl internal constructor(val toolWindowManager: ToolWindowManag
return false
}
else {
return windowInfo.isActive || (decorator?.isFocused ?: false)
return windowInfo.isActive || (windowInfo.isVisible && (decorator?.isFocused(frameHelper) ?: false))
}
}
@@ -267,7 +267,9 @@ class ToolWindowImpl internal constructor(val toolWindowManager: ToolWindowManag
override fun getDecorator() = decorator!!
val isFocused: Boolean
get() = decorator?.isFocused ?: false
get() {
return decorator?.isFocused(toolWindowManager.getFrame() ?: return false) ?: false
}
override fun setAdditionalGearActions(value: ActionGroup?) {
additionalGearActions = value
@@ -124,6 +124,8 @@ open class ToolWindowManagerImpl(val project: Project) : ToolWindowManagerEx(),
}
}
internal fun getFrame() = frame
@Service
private class ToolWindowManagerAppLevelHelper {
private var awtFocusListener: AWTEventListener? = null