Java Code Examples for com.intellij.ui.content.Content#isPinned()

The following examples show how to use com.intellij.ui.content.Content#isPinned() . 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: ContentsUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void addOrReplaceContent(ContentManager manager, Content content, boolean select) {
  final String contentName = content.getDisplayName();

  Content[] contents = manager.getContents();
  Content oldContentFound = null;
  for(Content oldContent: contents) {
    if (!oldContent.isPinned() && oldContent.getDisplayName().equals(contentName)) {
      oldContentFound = oldContent;
      break;
    }
  }

  manager.addContent(content);
  if (oldContentFound != null) {
    manager.removeContent(oldContentFound, true);
  }
  if (select) {
    manager.setSelectedContent(content);
  }
}
 
Example 2
Source File: AbstractVcsHelperImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void removeContents(Content notToRemove, final String tabDisplayName) {
  MessageView messageView = MessageView.SERVICE.getInstance(myProject);
  Content[] contents = messageView.getContentManager().getContents();
  for (Content content : contents) {
    LOG.assertTrue(content != null);
    if (content.isPinned()) continue;
    if (tabDisplayName.equals(content.getDisplayName()) && content != notToRemove) {
      ErrorTreeView listErrorView = (ErrorTreeView)content.getComponent();
      if (listErrorView != null) {
        if (messageView.getContentManager().removeContent(content, true)) {
          content.release();
        }
      }
    }
  }
}
 
Example 3
Source File: ExecutionHelper.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void removeContents(@Nullable final Content notToRemove, @Nonnull final Project myProject, @Nonnull final String tabDisplayName) {
  MessageView messageView = ServiceManager.getService(myProject, MessageView.class);
  Content[] contents = messageView.getContentManager().getContents();
  for (Content content : contents) {
    LOG.assertTrue(content != null);
    if (content.isPinned()) continue;
    if (tabDisplayName.equals(content.getDisplayName()) && content != notToRemove) {
      ErrorTreeView listErrorView = (ErrorTreeView)content.getComponent();
      if (listErrorView != null) {
        if (messageView.getContentManager().removeContent(content, true)) {
          content.release();
        }
      }
    }
  }
}
 
Example 4
Source File: VcsDockedComponent.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public void removeFromVcsTab(@NotNull @NonNls String title) {
    final ToolWindow toolW = getToolWindow();
    if (toolW == null) {
        // cannot do anything
        return;
    }
    final ContentManager contentManager = getToolWindow().getContentManager();
    final Content existingContent = contentManager.findContent(title);
    if (existingContent != null) {
        if (!existingContent.isPinned()) {
            contentManager.removeContent(existingContent, true);
            existingContent.release();
        }
    }
}
 
Example 5
Source File: VcsDockedComponent.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public boolean addVcsTab(@NotNull @NonNls String title,
        @NotNull JComponent component,
        boolean showTab,
        boolean replaceExistingComponent) {
    if (component instanceof Disposable) {
        Disposer.register(this, (Disposable) component);
    }
    final ToolWindow toolW = getToolWindow();
    if (toolW == null) {
        // cannot do anything
        return false;
    }
    final ContentManager contentManager = getToolWindow().getContentManager();
    final Content existingContent = contentManager.findContent(title);
    if (existingContent != null) {
        if (!replaceExistingComponent) {
            contentManager.setSelectedContent(existingContent);
            return true;
        }
        else if (!existingContent.isPinned()) {
            contentManager.removeContent(existingContent, true);
            existingContent.release();
        }
    }

    final Content content = contentManager.getFactory().createContent(component, title, false);
    contentManager.addContent(content);
    if (showTab) {
        getToolWindow().activate(null, false);
    }

    return true;
}
 
Example 6
Source File: ExternalSystemNotificationManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private Content findContent(@Nonnull Pair<NotificationSource, ProjectSystemId> contentIdPair, @Nonnull String contentDisplayName) {
  Content targetContent = null;
  final MessageView messageView = ServiceManager.getService(myProject, MessageView.class);
  for (Content content : messageView.getContentManager().getContents()) {
    if (contentIdPair.equals(content.getUserData(CONTENT_ID_KEY))
        && StringUtil.equals(content.getDisplayName(), contentDisplayName) && !content.isPinned()) {
      targetContent = content;
    }
  }
  return targetContent;
}
 
Example 7
Source File: PinActiveTabAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Handler createHandler(final Content content) {
  return new Handler(content.isPinned(), content.getManager().getSelectedContent() == content) {
    @Override
    void setPinned(boolean value) {
      content.setPinned(value);
    }
  };
}
 
Example 8
Source File: ReplaceInProjectManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @param model would be used for replacing if not null, otherwise shared (project-level) model would be used
 */
public void replaceInProject(@Nonnull DataContext dataContext, @Nullable FindModel model) {
  final FindManager findManager = FindManager.getInstance(myProject);
  final FindModel findModel;

  final boolean isOpenInNewTabEnabled;
  final boolean toOpenInNewTab;
  final Content selectedContent = UsageViewContentManager.getInstance(myProject).getSelectedContent(true);
  if (selectedContent != null && selectedContent.isPinned()) {
    toOpenInNewTab = true;
    isOpenInNewTabEnabled = false;
  }
  else {
    toOpenInNewTab = FindSettings.getInstance().isShowResultsInSeparateView();
    isOpenInNewTabEnabled = UsageViewContentManager.getInstance(myProject).getReusableContentsCount() > 0;
  }
  if (model == null) {

    findModel = findManager.getFindInProjectModel().clone();
    findModel.setReplaceState(true);
    findModel.setOpenInNewTabEnabled(isOpenInNewTabEnabled);
    findModel.setOpenInNewTab(toOpenInNewTab);
    FindInProjectUtil.setDirectoryName(findModel, dataContext);
    FindInProjectUtil.initStringToFindFromDataContext(findModel, dataContext);
  }
  else {
    findModel = model;
    findModel.setOpenInNewTabEnabled(isOpenInNewTabEnabled);
  }

  findManager.showFindDialog(findModel, () -> {
    if (findModel.isReplaceState()) {
      replaceInPath(findModel);
    }
    else {
      FindInProjectManager.getInstance(myProject).findInPath(findModel);
    }
  });
}
 
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;
}
 
Example 10
Source File: PinToolwindowTabAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isSelected(AnActionEvent event) {
  final Content content = getContextContent(event);
  return content != null && content.isPinned();
}
 
Example 11
Source File: FindUsagesManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
private boolean mustOpenInNewTab() {
  Content selectedContent = UsageViewContentManager.getInstance(myProject).getSelectedContent(true);
  return selectedContent != null && selectedContent.isPinned();
}