Java Code Examples for com.intellij.ui.content.ContentManager#getSelectedContent()

The following examples show how to use com.intellij.ui.content.ContentManager#getSelectedContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CloseActiveTabAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
  ContentManager contentManager = ContentManagerUtil.getContentManagerFromContext(e.getDataContext(), true);
  boolean processed = false;
  if (contentManager != null && contentManager.canCloseContents()) {
    final Content selectedContent = contentManager.getSelectedContent();
    if (selectedContent != null && selectedContent.isCloseable()) {
      contentManager.removeContent(selectedContent, true);
      processed = true;
    }
  }

  if (!processed && contentManager != null) {
    final DataContext context = DataManager.getInstance().getDataContext(contentManager.getComponent());
    final ToolWindow tw = context.getData(PlatformDataKeys.TOOL_WINDOW);
    if (tw != null) {
      tw.hide(null);
    }
  }
}
 
Example 2
Source File: PredefinedSearchScopeProviderImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void addHierarchyScope(@Nonnull Project project, Collection<SearchScope> result) {
  final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.HIERARCHY);
  if (toolWindow == null) {
    return;
  }
  final ContentManager contentManager = toolWindow.getContentManager();
  final Content content = contentManager.getSelectedContent();
  if (content == null) {
    return;
  }
  final String name = content.getDisplayName();
  final JComponent component = content.getComponent();
  if (!(component instanceof HierarchyBrowserBase)) {
    return;
  }
  final HierarchyBrowserBase hierarchyBrowserBase = (HierarchyBrowserBase)component;
  final PsiElement[] elements = hierarchyBrowserBase.getAvailableElements();
  if (elements.length > 0) {
    result.add(new LocalSearchScope(elements, "Hierarchy '" + name + "' (visible nodes only)"));
  }
}
 
Example 3
Source File: ShTerminalRunner.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
private static Pair<Content, Process> getSuitableProcess(@NotNull ContentManager contentManager, @NotNull String workingDirectory) {
  Content selectedContent = contentManager.getSelectedContent();
  if (selectedContent != null) {
    Pair<Content, Process> pair = getSuitableProcess(selectedContent, workingDirectory);
    if (pair != null) return pair;
  }

  return Arrays.stream(contentManager.getContents())
    .map(content -> getSuitableProcess(content, workingDirectory))
    .filter(Objects::nonNull)
    .findFirst()
    .orElse(null);
}
 
Example 4
Source File: CloseLogTabAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static Content getTabbedContent(@Nonnull ContentManager contentManager) {
  Content content = contentManager.getSelectedContent();
  if (content != null) {
    if (ContentUtilEx.isContentTab(content, VcsLogContentProvider.TAB_NAME)) return content;
  }
  return null;
}
 
Example 5
Source File: PinToolwindowTabAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static Content getContextContent(@Nonnull AnActionEvent event) {
  final ToolWindow window = event.getData(PlatformDataKeys.TOOL_WINDOW);
  if (window != null) {
    final ContentManager contentManager = window.getContentManager();
    if (contentManager != null) {
      return contentManager.getSelectedContent();
    }
  }

  return null;
}
 
Example 6
Source File: OccurenceNavigatorActionBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
protected OccurenceNavigator getNavigator(DataContext dataContext) {
  ContentManager contentManager = ContentManagerUtil.getContentManagerFromContext(dataContext, false);
  if (contentManager != null) {
    Content content = contentManager.getSelectedContent();
    if (content == null) return null;
    JComponent component = content.getComponent();
    return findNavigator(component);
  }

  return (OccurenceNavigator)getOccurenceNavigatorFromContext(dataContext);
}
 
Example 7
Source File: ToggleToolbarAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
  ContentManager contentManager = myToolWindow.getContentManager();
  Content selectedContent = contentManager.getSelectedContent();
  JComponent contentComponent = selectedContent != null ? selectedContent.getComponent() : null;
  if (contentComponent == null) return EMPTY_ARRAY;
  List<AnAction> result = ContainerUtil.newSmartList();
  for (final ActionToolbar toolbar : iterateToolbars(contentComponent)) {
    JComponent c = toolbar.getComponent();
    if (c.isVisible() || !c.isValid()) continue;
    if (!result.isEmpty() && !(ContainerUtil.getLastItem(result) instanceof AnSeparator)) {
      result.add(AnSeparator.getInstance());
    }

    List<AnAction> actions = toolbar.getActions();
    for (AnAction action : actions) {
      if (action instanceof ToggleAction && !result.contains(action)) {
        result.add(action);
      }
      else if (action instanceof AnSeparator) {
        if (!result.isEmpty() && !(ContainerUtil.getLastItem(result) instanceof AnSeparator)) {
          result.add(AnSeparator.getInstance());
        }
      }
    }
  }
  boolean popup = result.size() > 3;
  setPopup(popup);
  if (!popup && !result.isEmpty()) result.add(AnSeparator.getInstance());
  return result.toArray(new AnAction[result.size()]);
}
 
Example 8
Source File: PinActiveTabAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static Content getNonToolWindowContent(@Nonnull AnActionEvent e) {
  Content result = null;
  Content[] contents = e.getData(ViewContext.CONTENT_KEY);
  if (contents != null && contents.length == 1) result = contents[0];
  if (result != null && result.isPinnable()) return result;

  ContentManager contentManager = ContentManagerUtil.getContentManagerFromContext(e.getDataContext(), true);
  result = contentManager != null? contentManager.getSelectedContent() : null;
  if (result != null && result.isPinnable()) return result;
  return null;
}
 
Example 9
Source File: BrowseHierarchyActionBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static HierarchyBrowser createAndAddToPanel(@Nonnull Project project, @Nonnull final HierarchyProvider provider, @Nonnull PsiElement target) {
  final HierarchyBrowser hierarchyBrowser = provider.createHierarchyBrowser(target);

  final Content content;

  final HierarchyBrowserManager hierarchyBrowserManager = HierarchyBrowserManager.getInstance(project);

  final ContentManager contentManager = hierarchyBrowserManager.getContentManager();
  final Content selectedContent = contentManager.getSelectedContent();
  if (selectedContent != null && !selectedContent.isPinned()) {
    content = selectedContent;
    final Component component = content.getComponent();
    if (component instanceof Disposable) {
      Disposer.dispose((Disposable)component);
    }
    content.setComponent(hierarchyBrowser.getComponent());
  }
  else {
    content = ContentFactory.getInstance().createContent(hierarchyBrowser.getComponent(), null, true);
    contentManager.addContent(content);
  }
  contentManager.setSelectedContent(content);
  hierarchyBrowser.setContent(content);

  final Runnable runnable = new Runnable() {
    @Override
    public void run() {
      provider.browserActivated(hierarchyBrowser);
    }
  };
  ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.HIERARCHY).activate(runnable);
  return hierarchyBrowser;
}