ToggleToolbarAction (@NotNull ToolWindow toolWindow, @NotNull PropertiesComponent properties) { updateToolbarsVisibility(toolWindow, properties); toolWindow.addContentManagerListener(new ContentManagerListener() { @Override public void contentAdded(@NotNull ContentManagerEvent event) { JComponent component = event.getContent().getComponent(); setToolbarVisible(Collections.singletonList(component), isToolbarVisible(toolWindow, properties)); // support nested content managers, e.g. RunnerLayoutUi as content component ContentManager contentManager = component instanceof DataProvider ? PlatformDataKeys.CONTENT_MANAGER.getData((DataProvider)component) : null; if (contentManager != null) { contentManager.addContentManagerListener(this); } } @Override public void selectionChanged(@NotNull ContentManagerEvent event) { if (event.getOperation() != ContentManagerEvent.ContentOperation.remove) { updateToolbarsVisibility(toolWindow, properties); } } }); return new ToggleToolbarAction(properties, getShowToolbarProperty(toolWindow), () -> { ContentManager manager = toolWindow.getContentManagerIfCreated(); return ContainerUtil.createMaybeSingletonList(manager == null ? null : manager.getComponent()); }); }