@Nullable
  private static RunContentDescriptor chooseReuseContentForDescriptor(
      final ContentManager contentManager, final RunContentDescriptor descriptor) {
    Content content = null;
    if (descriptor != null) {
      if (descriptor.isContentReuseProhibited()) {
        return null;
      }
      final Content attachedContent = descriptor.getAttachedContent();
      if (attachedContent != null && attachedContent.isValid()) content = attachedContent;
    }
    if (content == null) {
      content = contentManager.getSelectedContent();
      if (content != null && content.isPinned()) content = null;
    }
    if (content == null || !isTerminated(content)) {
      return null;
    }
    final RunContentDescriptor oldDescriptor = getRunContentDescriptorByContent(content);
    if (oldDescriptor != null && !oldDescriptor.isContentReuseProhibited()) {
      return oldDescriptor;
    }

    return null;
  }
  @Nullable
  public RunContentDescriptor getSelectedContent() {
    for (String activeWindow : myToolwindowIdZbuffer) {
      final ContentManager contentManager = myToolwindowIdToContentManagerMap.get(activeWindow);
      if (contentManager == null) {
        continue;
      }

      final Content selectedContent = contentManager.getSelectedContent();
      if (selectedContent == null) {
        if (contentManager.getContentCount() == 0) {
          // continue to the next window if the content manager is empty
          continue;
        } else {
          // stop iteration over windows because there is some content in the window and the window
          // is the last used one
          break;
        }
      }
      // here we have selected content
      return getRunContentDescriptorByContent(selectedContent);
    }

    return null;
  }
  /** @return selected content or <code>null</code> */
  @Nullable
  private static Content getContent(final DataContext context) {
    Content[] contents = ViewContext.CONTENT_KEY.getData(context);
    if (contents != null && contents.length == 1) return contents[0];

    ContentManager contentManager = ContentManagerUtil.getContentManagerFromContext(context, true);
    if (contentManager == null) {
      return null;
    }
    return contentManager.getSelectedContent();
  }
 @Nullable
 public RunContentDescriptor getSelectedContent(final Executor executor) {
   final ContentManager contentManager = getContentManagerForRunner(executor);
   if (contentManager != null) {
     final Content selectedContent = contentManager.getSelectedContent();
     if (selectedContent != null) {
       final RunContentDescriptor runContentDescriptorByContent =
           getRunContentDescriptorByContent(selectedContent);
       if (runContentDescriptorByContent != null) {
         return runContentDescriptorByContent;
       }
     }
   }
   return null;
 }
  @Nullable
  public RunContentDescriptor getSelectedContent() {
    final String activeWindow =
        myToolwindowIdZbuffer.isEmpty() ? null : myToolwindowIdZbuffer.getFirst();

    if (activeWindow != null) {
      final ContentManager contentManager = myToolwindowIdToContentManagerMap.get(activeWindow);
      if (contentManager != null) {
        final Content selectedContent = contentManager.getSelectedContent();
        if (selectedContent != null) {
          final RunContentDescriptor runContentDescriptorByContent =
              getRunContentDescriptorByContent(selectedContent);
          if (runContentDescriptorByContent != null) {
            return runContentDescriptorByContent;
          }
        }
      }
    }
    return null;
  }
예제 #6
0
 private static void addHierarchyScope(@NotNull 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)"));
   }
 }
예제 #7
0
  public Element getState() {
    Element element = new Element("TodoView");
    if (myContentManager != null) { // all panel were constructed
      Content content = myContentManager.getSelectedContent();
      element.setAttribute(
          ATTRIBUTE_SELECTED_INDEX, Integer.toString(myContentManager.getIndexOfContent(content)));
    }

    Element selectedFileElement = new Element(ELEMENT_TODO_PANEL);
    selectedFileElement.setAttribute(ATTRIBUTE_ID, VALUE_SELECTED_FILE);
    myCurrentPanelSettings.writeExternal(selectedFileElement);
    element.addContent(selectedFileElement);

    Element allElement = new Element(ELEMENT_TODO_PANEL);
    allElement.setAttribute(ATTRIBUTE_ID, VALUE_ALL);
    myAllPanelSettings.writeExternal(allElement);
    element.addContent(allElement);

    Element changeListElement = new Element(ELEMENT_TODO_PANEL);
    changeListElement.setAttribute(ATTRIBUTE_ID, VALUE_DEFAULT_CHANGELIST);
    myChangeListTodosPanelSettings.writeExternal(changeListElement);
    element.addContent(changeListElement);
    return element;
  }