From 9bfbfc9c39db6f3581deaacb1df7f52949d519cb Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 23 Dec 2019 17:53:44 +0100 Subject: [PATCH] don't call createContentIfNeeded inside content manager initialization GitOrigin-RevId: 9c66858945296fb82bc0e41bf7cf4bad131887c1 --- .../openapi/wm/impl/ToolWindowImpl.kt | 57 ++++++++++--------- .../vcs/log/impl/VcsLogContentUtil.java | 22 +++++-- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.kt index 75e02b0d7b9e..22c2bab668d5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.kt @@ -103,31 +103,10 @@ class ToolWindowImpl internal constructor(val toolWindowManager: ToolWindowManag private fun createContentManager(): ContentManagerImpl { val contentUi = ToolWindowContentUi(this, windowInfo.contentUiType) + this.contentUi = contentUi val contentManager = ContentManagerImpl(contentUi, canCloseContent, toolWindowManager.project, parentDisposable) - UIUtil.putClientProperty(contentUi.component, UIUtil.NOT_IN_HIERARCHY_COMPONENTS, object : Iterable { - override fun iterator(): Iterator { - if (contentManager.contentCount == 0) { - return Collections.emptyIterator() - } - - return contentManager.contents - .asSequence() - .mapNotNull { content: Content -> - var last: JComponent? = null - var parent: Component? = content.component - while (parent != null) { - if (parent === contentUi.component || parent !is JComponent) { - return@mapNotNull null - } - last = parent - parent = parent.getParent() - } - last - } - .iterator() - } - }) + addContentNotInHierarchyComponents(contentUi) val contentComponent = contentManager.component InternalDecorator.installFocusTraversalPolicy(contentComponent, LayoutFocusTraversalPolicy()) @@ -154,10 +133,6 @@ class ToolWindowImpl internal constructor(val toolWindowManager: ToolWindowManag toolWindowFocusWatcher = ToolWindowManagerImpl.ToolWindowFocusWatcher(this, contentComponent) - if (windowInfo.isVisible) { - createContentIfNeeded() - } - // after init, as it was before contentManager creation was changed to be lazy pendingContentManagerListeners?.let { list -> pendingContentManagerListeners = null @@ -460,7 +435,6 @@ class ToolWindowImpl internal constructor(val toolWindowManager: ToolWindowManag contentManager.value } - // if content manager due to some incorrect call was already initialized, content will be not created internal fun scheduleContentInitializationIfNeeded() { if (contentFactory != null) { // todo use lazy loading (e.g. JBLoadingPanel) @@ -655,4 +629,31 @@ private fun addSorted(main: DefaultActionGroup, group: ActionGroup) { if (children.isNotEmpty() && !separatorText.isNullOrEmpty()) { main.addAction(Separator(separatorText), Constraints.FIRST) } +} + +private fun addContentNotInHierarchyComponents(contentUi: ToolWindowContentUi) { + UIUtil.putClientProperty(contentUi.component, UIUtil.NOT_IN_HIERARCHY_COMPONENTS, object : Iterable { + override fun iterator(): Iterator { + val contentManager = contentUi.contentManager ?: return Collections.emptyIterator() + if (contentManager.contentCount == 0) { + return Collections.emptyIterator() + } + + return contentManager.contents + .asSequence() + .mapNotNull { content: Content -> + var last: JComponent? = null + var parent: Component? = content.component + while (parent != null) { + if (parent === contentUi.component || parent !is JComponent) { + return@mapNotNull null + } + last = parent + parent = parent.getParent() + } + last + } + .iterator() + } + }) } \ No newline at end of file diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogContentUtil.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogContentUtil.java index 65e8d82d73e4..eaeaace506d3 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogContentUtil.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogContentUtil.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.vcs.log.impl; import com.intellij.openapi.project.Project; @@ -76,7 +76,9 @@ public class VcsLogContentUtil { @NotNull Class clazz, boolean select, @NotNull Condition condition) { ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.VCS); - if (toolWindow == null) return null; + if (toolWindow == null) { + return null; + } ContentManager manager = toolWindow.getContentManager(); JComponent component = ContentUtilEx.findContentComponent(manager, c -> { @@ -87,11 +89,17 @@ public class VcsLogContentUtil { } return false; }); - if (component == null) return null; + if (component == null) { + return null; + } if (select) { - if (!toolWindow.isVisible()) toolWindow.activate(null); - if (!ContentUtilEx.selectContent(manager, component, true)) return null; + if (!toolWindow.isVisible()) { + toolWindow.activate(null); + } + if (!ContentUtilEx.selectContent(manager, component, true)) { + return null; + } } //noinspection unchecked return (U)getLogUi(component); @@ -135,7 +143,9 @@ public class VcsLogContentUtil { ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.VCS); ContentUtilEx.addTabbedContent(toolWindow.getContentManager(), new VcsLogPanel(logManager, logUi), tabGroupName, shortName, focus, logUi); - if (focus) toolWindow.activate(null); + if (focus) { + toolWindow.activate(null); + } logManager.scheduleInitialization(); return logUi; }