private boolean isOurContentPaneShowing() {
   if (myToolWindowManager.isToolWindowRegistered(TOOLWINDOW_ID) && myToolWindow.isVisible()) {
     Content content = myToolWindow.getContentManager().getSelectedContent();
     return content != null && content.getTabName().equals(VcsLogContentProvider.TAB_NAME);
   }
   return false;
 }
  @Nullable
  public static GradleProjectStructureTreeModel getProjectStructureTreeModel(
      @NotNull Project project) {
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    final ToolWindow toolWindow = toolWindowManager.getToolWindow(GradleConstants.TOOL_WINDOW_ID);
    if (toolWindow == null) {
      return null;
    }

    final ContentManager contentManager = toolWindow.getContentManager();
    if (contentManager == null) {
      return null;
    }

    for (Content content : contentManager.getContents()) {
      final JComponent component = content.getComponent();
      if (component instanceof DataProvider) {
        final Object data =
            ((DataProvider) component).getData(GradleDataKeys.SYNC_TREE_MODEL.getName());
        if (data instanceof GradleProjectStructureTreeModel) {
          return (GradleProjectStructureTreeModel) data;
        }
      }
    }
    return null;
  }
示例#3
0
  @SuppressWarnings("unchecked")
  @Nullable
  public static <T> T getToolWindowElement(
      @NotNull Class<T> clazz,
      @NotNull Project project,
      @NotNull DataKey<T> key,
      @NotNull ProjectSystemId externalSystemId) {
    if (project.isDisposed() || !project.isOpen()) {
      return null;
    }
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    if (toolWindowManager == null) {
      return null;
    }
    final ToolWindow toolWindow = ensureToolWindowContentInitialized(project, externalSystemId);
    if (toolWindow == null) {
      return null;
    }

    final ContentManager contentManager = toolWindow.getContentManager();
    if (contentManager == null) {
      return null;
    }

    for (Content content : contentManager.getContents()) {
      final JComponent component = content.getComponent();
      if (component instanceof DataProvider) {
        final Object data = ((DataProvider) component).getData(key.getName());
        if (data != null && clazz.isInstance(data)) {
          return (T) data;
        }
      }
    }
    return null;
  }
 @Override
 public void showSettings() {
   Content selectedContent = UsageViewManager.getInstance(myProject).getSelectedContent(true);
   JComponent component = selectedContent == null ? null : selectedContent.getComponent();
   FindInProjectManager findInProjectManager = FindInProjectManager.getInstance(myProject);
   findInProjectManager.findInProject(DataManager.getInstance().getDataContext(component));
 }
  private Content createTerminalInContentPanel(
      @NotNull AbstractTerminalRunner terminalRunner, final @NotNull ToolWindow toolWindow) {
    SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true);

    final Content content = ContentFactory.SERVICE.getInstance().createContent(panel, "", false);
    content.setCloseable(true);

    myTerminalWidget = terminalRunner.createTerminalWidget(content);
    myTerminalWidget.addTabListener(
        new TabbedTerminalWidget.TabListener() {
          @Override
          public void tabClosed(JediTermWidget terminal) {
            UIUtil.invokeLaterIfNeeded(
                () -> {
                  if (myTerminalWidget != null) {
                    hideIfNoActiveSessions(toolWindow, myTerminalWidget);
                  }
                });
          }
        });

    panel.setContent(myTerminalWidget.getComponent());
    panel.addFocusListener(createFocusListener());

    ActionToolbar toolbar = createToolbar(terminalRunner, myTerminalWidget, toolWindow);
    toolbar.getComponent().addFocusListener(createFocusListener());
    toolbar.setTargetComponent(panel);
    panel.setToolbar(toolbar.getComponent());

    content.setPreferredFocusableComponent(myTerminalWidget.getComponent());

    return content;
  }
  public static void showTestResultsToolWindow(
      @NotNull final Project project, @NotNull final String message, boolean solved) {
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    ToolWindow window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID);
    if (window == null) {
      toolWindowManager.registerToolWindow(
          StudyTestResultsToolWindowFactoryKt.ID, true, ToolWindowAnchor.BOTTOM);
      window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID);
      new StudyTestResultsToolWindowFactory().createToolWindowContent(project, window);
    }

    final Content[] contents = window.getContentManager().getContents();
    for (Content content : contents) {
      final JComponent component = content.getComponent();
      if (component instanceof ConsoleViewImpl) {
        ((ConsoleViewImpl) component).clear();
        if (!solved) {
          ((ConsoleViewImpl) component).print(message, ConsoleViewContentType.ERROR_OUTPUT);
        } else {
          ((ConsoleViewImpl) component).print(message, ConsoleViewContentType.NORMAL_OUTPUT);
        }
        window.setAvailable(true, () -> {});
        window.show(() -> {});
        return;
      }
    }
  }
 private void removeAllContents(Project project, Content notRemove) {
   if (project.isDisposed()) {
     return;
   }
   final MessageView messageView = MessageView.SERVICE.getInstance(project);
   Content[] contents = messageView.getContentManager().getContents();
   for (Content content : contents) {
     if (content.isPinned()) {
       continue;
     }
     if (content == notRemove) {
       continue;
     }
     boolean toRemove = CONTENT_ID_KEY.get(content) == myContentId;
     if (!toRemove) {
       final Object contentSessionId = SESSION_ID_KEY.get(content);
       toRemove =
           contentSessionId != null
               && contentSessionId != mySessionId; // the content was added by previous compilation
     }
     if (toRemove) {
       messageView.getContentManager().removeContent(content, true);
     }
   }
 }
  @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;
  }
  @Override
  public void update(@NotNull AnActionEvent e) {
    super.update(e);

    Presentation presentation = e.getPresentation();
    DataContext context = e.getDataContext();
    EditorWindow window = getEditorWindow(context);
    if (window == null || window.getOwner().isPreview()) {
      presentation.setEnabledAndVisible(false);
    } else {
      if (getFile(context) != null) {
        presentation.setEnabledAndVisible(true);
      } else {
        Content content = getContent(context);
        presentation.setEnabledAndVisible(content != null && content.isPinnable());
      }
    }

    if (ActionPlaces.EDITOR_TAB_POPUP.equals(e.getPlace())
        || ViewContext.CELL_POPUP_PLACE.equals(e.getPlace())) {
      presentation.setText(
          isSelected(e)
              ? IdeBundle.message("action.unpin.tab")
              : IdeBundle.message("action.pin.tab"));
    } else {
      presentation.setText(
          isSelected(e)
              ? IdeBundle.message("action.unpin.active.tab")
              : IdeBundle.message("action.pin.active.tab"));
    }
  }
 private void removeTab(Content[] contents, String s) {
   myMap.remove(s);
   for (Content content : contents) {
     if (s.equals(content.getDisplayName())) {
       myUi.getContentManager().removeContent(content, false);
       break;
     }
   }
 }
示例#11
0
  public UsageView getSelectedUsageView() {
    final Content content =
        com.intellij.usageView.UsageViewManager.getInstance(myProject).getSelectedContent();
    if (content != null) {
      return content.getUserData(USAGE_VIEW_KEY);
    }

    return null;
  }
  @Override
  public void putInfo(@NotNull Map<String, String> info) {
    info.put("toolWindowTitle", myToolWindow.getTitle());

    final Content selection = myToolWindow.getContentManager().getSelectedContent();
    if (selection != null) {
      info.put("toolWindowTab", selection.getTabName());
    }
  }
  public boolean updateGridUI() {
    for (final GridCellImpl cell : myPlaceInGrid2Cell.values()) {
      cell.setHideTabs(myContents.size() == 1);
    }

    final Content onlyContent = myContents.get(0);

    return onlyContent.getSearchComponent() != null;
  }
 private void close() {
   MessageView messageView = MessageView.SERVICE.getInstance(myProject);
   Content[] contents = messageView.getContentManager().getContents();
   for (Content content : contents) {
     if (content.getComponent() == this) {
       messageView.getContentManager().removeContent(content, true);
       return;
     }
   }
 }
  private int getComponentNumNamed(String s) {
    for (int i = 0; i < getContentManager().getContentCount(); i++) {
      final Content content = getContentManager().getContent(i);
      if (content != null && s.equals(content.getDisplayName())) {
        return i;
      }
    }

    return -1;
  }
 @Nullable
 private static Content getRunContentByDescriptor(
     final ContentManager contentManager, final RunContentDescriptor descriptor) {
   final Content[] contents = contentManager.getContents();
   for (final Content content : contents) {
     if (descriptor.equals(content.getUserData(DESCRIPTOR_KEY))) {
       return content;
     }
   }
   return null;
 }
 public void showRunContent(
     @NotNull final Executor info,
     RunContentDescriptor descriptor,
     RunContentDescriptor contentToReuse) {
   if (contentToReuse != null) {
     final Content attachedContent = contentToReuse.getAttachedContent();
     if (attachedContent.getManager() != null) {
       descriptor.setAttachedContent(attachedContent);
     }
   }
   showRunContent(info, descriptor);
 }
 @Override
 public void createToolWindowContent(Project project, ToolWindow toolWindow) {
   DiffManager.getInstance().registerDiffTool(new CommentsDiffTool());
   final ContentManager contentManager = toolWindow.getContentManager();
   final CruciblePanel cruciblePanel = new CruciblePanel(project);
   final Content content =
       ContentFactory.SERVICE
           .getInstance()
           .createContent(cruciblePanel, CrucibleBundle.message("crucible.main.name"), false);
   content.setCloseable(false);
   contentManager.addContent(content);
 }
 @Nullable
 private RunContentDescriptor getDescriptorBy(ProcessHandler handler, Executor runnerInfo) {
   ContentManager contentManager = getContentManagerForRunner(runnerInfo);
   Content[] contents = contentManager.getContents();
   for (Content content : contents) {
     RunContentDescriptor runContentDescriptor = content.getUserData(DESCRIPTOR_KEY);
     if (runContentDescriptor.getProcessHandler() == handler) {
       return runContentDescriptor;
     }
   }
   return null;
 }
示例#20
0
 public void showCompilerContent() {
   synchronized (myMessageViewLock) {
     if (myErrorTreeView != null) {
       final MessageView messageView = MessageView.SERVICE.getInstance(myProject);
       Content[] contents = messageView.getContentManager().getContents();
       for (Content content : contents) {
         if (content.getUserData(myContentIdKey) != null) {
           messageView.getContentManager().setSelectedContent(content);
           return;
         }
       }
     }
   }
 }
 public void contentRemoved(ContentManagerEvent event) {
   if (event.getContent() == myContent) {
     myContentManager.removeContentManagerListener(this);
     AntBuildMessageView buildMessageView = myContent.getUserData(KEY);
     if (!myCloseAllowed) {
       buildMessageView.stopProcess();
     }
     ProjectManager.getInstance().removeProjectManagerListener(myProject, this);
     myContent.release();
     myContent = null;
     buildMessageView.myBuildFile = null;
     buildMessageView.myPlainTextView.dispose();
   }
 }
 private Content createNewContent(
     final ContentManager contentManager,
     final RunContentDescriptor descriptor,
     Executor executor) {
   final String processDisplayName = descriptor.getDisplayName();
   final Content content =
       ContentFactory.SERVICE
           .getInstance()
           .createContent(descriptor.getComponent(), processDisplayName, true);
   content.putUserData(DESCRIPTOR_KEY, descriptor);
   content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE);
   contentManager.addContent(content);
   new CloseListener(content, executor);
   return content;
 }
    /** @return true if content can be closed */
    private boolean closeQuery() {
      if (myContent == null) {
        return true;
      }

      AntBuildMessageView messageView = myContent.getUserData(KEY);

      if (messageView.isStoppedOrTerminateRequested()) {
        return true;
      }

      if (myCloseAllowed) return true;

      int result =
          Messages.showYesNoCancelDialog(
              AntBundle.message("ant.process.is.active.terminate.confirmation.text"),
              AntBundle.message("close.ant.build.messages.dialog.title"),
              Messages.getQuestionIcon());
      if (result == 0) { // yes
        messageView.stopProcess();
        myCloseAllowed = true;
        return true;
      }

      if (result == 1) { // no
        // close content and leave the process running
        myCloseAllowed = true;
        return true;
      }

      return false;
    }
示例#24
0
 private void addContent(UsageViewImpl usageView, UsageViewPresentation presentation) {
   Content content =
       com.intellij
           .usageView
           .UsageViewManager
           .getInstance(myProject)
           .addContent(
               presentation.getTabText(),
               presentation.getTabName(),
               presentation.getToolwindowTitle(),
               true,
               usageView.getComponent(),
               presentation.isOpenInNewTab(),
               true);
   usageView.setContent(content);
   content.putUserData(USAGE_VIEW_KEY, usageView);
 }
  public HerokuToolWindow addAsContent(ContentManager contentManager) {
    final Content content = contentManager.getFactory().createContent(this, null, false);

    setWindowInfo(
        new ContentInfo() {
          public void describe(String title, String icon, String description) {
            content.setIcon(icon(icon));
            content.setDescription(description);
            content.setDisplayName(title);
            content.setTabName(title);
            content.setToolwindowTitle(title);
          }
        });
    content.setCloseable(false);
    contentManager.addContent(content);
    return this;
  }
 public void actionPerformed(AnActionEvent e) {
   if (myContentManager != null) {
     Content content = myContentManager.getContent(PanelWithActionsAndCloseButton.this);
     if (content != null) {
       ContentsUtil.closeContentTab(myContentManager, content);
       if (content instanceof TabbedContent && ((TabbedContent) content).getTabs().size() > 1) {
         final TabbedContent tabbedContent = (TabbedContent) content;
         final JComponent component = content.getComponent();
         tabbedContent.removeContent(component);
         myContentManager.setSelectedContent(
             content, true, true); // we should request focus here
       } else {
         myContentManager.removeContent(content, true);
       }
     }
   }
 }
 public static void updateToolWindows() {
   for (Project project : ProjectManager.getInstance().getOpenProjects()) {
     final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
     for (String id : toolWindowManager.getToolWindowIds()) {
       final ToolWindow toolWindow = toolWindowManager.getToolWindow(id);
       for (Content content : toolWindow.getContentManager().getContents()) {
         final JComponent component = content.getComponent();
         if (component != null) {
           IJSwingUtilities.updateComponentTreeUI(component);
         }
       }
       final JComponent c = toolWindow.getComponent();
       if (c != null) {
         IJSwingUtilities.updateComponentTreeUI(c);
       }
     }
   }
 }
  private void initToolWindow() {
    myToolWindowForm = new AndroidLayoutPreviewToolWindowForm(this);
    final String toolWindowId = AndroidBundle.message("android.layout.preview.tool.window.title");
    myToolWindow =
        ToolWindowManager.getInstance(myProject)
            .registerToolWindow(toolWindowId, false, ToolWindowAnchor.RIGHT, myProject, true);
    myToolWindow.setIcon(AndroidIcons.AndroidPreview);

    ((ToolWindowManagerEx) ToolWindowManager.getInstance(myProject))
        .addToolWindowManagerListener(
            new ToolWindowManagerAdapter() {
              private boolean myVisible = false;

              @Override
              public void stateChanged() {
                if (myProject.isDisposed()) {
                  return;
                }

                final ToolWindow window =
                    ToolWindowManager.getInstance(myProject).getToolWindow(toolWindowId);
                if (window != null && window.isAvailable()) {
                  final boolean visible = window.isVisible();
                  AndroidEditorSettings.getInstance().getGlobalState().setVisible(visible);

                  if (visible && !myVisible) {
                    render();
                  }
                  myVisible = visible;
                }
              }
            });

    final JPanel contentPanel = myToolWindowForm.getContentPanel();
    final ContentManager contentManager = myToolWindow.getContentManager();
    @SuppressWarnings("ConstantConditions")
    final Content content = contentManager.getFactory().createContent(contentPanel, null, false);
    content.setDisposer(myToolWindowForm);
    content.setCloseable(false);
    content.setPreferredFocusableComponent(contentPanel);
    contentManager.addContent(content);
    contentManager.setSelectedContent(content, true);
    myToolWindow.setAvailable(false, null);
  }
    private void dispose() {
      if (myContent == null) return;

      final Content content = myContent;
      try {
        final RunContentDescriptor descriptor = getRunContentDescriptorByContent(content);

        getSyncPublisher().contentRemoved(descriptor, myExecutor);

        descriptor.dispose();
      } finally {
        content.getManager().removeContentManagerListener(this);
        ProjectManager.getInstance().removeProjectManagerListener(this);
        content
            .release(); // don't invoke myContent.release() because myContent becomes null after
                        // destroyProcess()
        myContent = null;
      }
    }
  @Override
  public void setDiffRequest(DiffRequest request) {
    final Map<String, DiffRequest> requestMap = myRequest.discloseRequest(request);
    final HashMap<String, DiffViewer> copy = new HashMap<String, DiffViewer>(myMap);

    for (Map.Entry<String, DiffRequest> entry : requestMap.entrySet()) {
      final String key = entry.getKey();
      final DiffRequest diffRequest = entry.getValue();
      diffRequest.getGenericData().put(PlatformDataKeys.COMPOSITE_DIFF_VIEWER.getName(), this);
      final DiffViewer viewer = copy.remove(key);
      if (viewer != null && viewer.acceptsType(diffRequest.getType())) {
        viewer.setDiffRequest(diffRequest);
      } else {
        if (viewer != null) {
          removeTab(myUi.getContentManager().getContents(), key);
        }
        final DiffViewer newViewer =
            myRequest.viewerForRequest(myWindow, myParentDisposable, key, diffRequest);
        if (newViewer == null) continue;
        myMap.put(key, newViewer);
        final Content content =
            myUi.createContent(
                key, newViewer.getComponent(), key, null, newViewer.getPreferredFocusedComponent());
        content.setCloseable(false);
        content.setPinned(true);
        Disposer.register(
            myParentDisposable,
            new Disposable() {
              @Override
              public void dispose() {
                myMap.remove(key);
                myUi.removeContent(content, true);
              }
            });
        myUi.addContent(content);
      }
    }
    final Content[] contents = myUi.getContentManager().getContents();
    for (String s : copy.keySet()) {
      removeTab(contents, s);
    }

    if (myMap.isEmpty()) {
      final EmptyDiffViewer emptyDiffViewer = new EmptyDiffViewer();
      myMap.put(FICTIVE_KEY, emptyDiffViewer);
      final Content content =
          myUi.createContent(
              FICTIVE_KEY,
              emptyDiffViewer.getComponent(),
              FICTIVE_KEY,
              null,
              emptyDiffViewer.getPreferredFocusedComponent());
      content.setCloseable(false);
      content.setPinned(true);
      content.setDisposer(myParentDisposable);
      myUi.addContent(content);
    }
  }