From f6cb12945cdd0aa222249f48bf18c1bc1fcafede Mon Sep 17 00:00:00 2001 From: Vera Petrenkova Date: Mon, 30 Jun 2025 17:22:15 +0200 Subject: [PATCH] [find in files] IJPL-194101 Refactor UsageViewContentManagerImpl init to handle duplicate tool window registrations Fixes an issue where the service would fail to initialize on the frontend because the Find tool window had already been registered via the backend. GitOrigin-RevId: a788870ecb054e732aee7ee1afcd42ef36635480 --- .../impl/UsageViewContentManagerImpl.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/usageView/impl/UsageViewContentManagerImpl.java b/platform/lang-impl/src/com/intellij/usageView/impl/UsageViewContentManagerImpl.java index 783c3d721d0d..7e49d5def962 100644 --- a/platform/lang-impl/src/com/intellij/usageView/impl/UsageViewContentManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/usageView/impl/UsageViewContentManagerImpl.java @@ -50,15 +50,7 @@ public final class UsageViewContentManagerImpl extends UsageViewContentManager { @NonInjectable public UsageViewContentManagerImpl(@NotNull Project project, @NotNull ToolWindowManager toolWindowManager) { - ToolWindow toolWindow = toolWindowManager.registerToolWindow( - ToolWindowId.FIND, - builder -> { - builder.stripeTitle = UIBundle.messagePointer("tool.window.name.find"); - builder.icon = AllIcons.Toolwindows.ToolWindowFind; - builder.shouldBeAvailable = false; - return Unit.INSTANCE; - } - ); + ToolWindow toolWindow = getOrRegisterFindToolWindow(toolWindowManager); toolWindow.setHelpId(UsageViewImpl.HELP_ID); toolWindow.setToHideOnEmptyContent(true); @@ -130,6 +122,24 @@ public final class UsageViewContentManagerImpl extends UsageViewContentManager { }); } + private static @NotNull ToolWindow getOrRegisterFindToolWindow(@NotNull ToolWindowManager toolWindowManager) { + if (toolWindowManager.getToolWindowIdSet().contains(ToolWindowId.FIND)) { + ToolWindow toolWindow = toolWindowManager.getToolWindow(ToolWindowId.FIND); + if (toolWindow != null) return toolWindow; + else //noinspection deprecation + toolWindowManager.unregisterToolWindow(ToolWindowId.FIND); + } + return toolWindowManager.registerToolWindow( + ToolWindowId.FIND, + builder -> { + builder.stripeTitle = UIBundle.messagePointer("tool.window.name.find"); + builder.icon = AllIcons.Toolwindows.ToolWindowFind; + builder.shouldBeAvailable = false; + return Unit.INSTANCE; + } + ); + } + @Override public @NotNull Content addContent(@NotNull String contentName, boolean reusable,