예제 #1
0
  private static void copyClassesImpl(
      final String copyClassName,
      final Project project,
      final Map<PsiFile, PsiClass[]> classes,
      final HashMap<PsiFile, String> map,
      final Object targetDirectory,
      final PsiDirectory defaultTargetDirectory,
      final String commandName,
      final boolean selectInActivePanel,
      final boolean openInEditor) {
    final boolean[] result = new boolean[] {false};
    Runnable command =
        () -> {
          final Runnable action =
              () -> {
                try {
                  PsiDirectory target;
                  if (targetDirectory instanceof PsiDirectory) {
                    target = (PsiDirectory) targetDirectory;
                  } else {
                    target =
                        ((MoveDestination) targetDirectory)
                            .getTargetDirectory(defaultTargetDirectory);
                  }
                  Collection<PsiFile> files =
                      doCopyClasses(classes, map, copyClassName, target, project);
                  if (files != null) {
                    if (openInEditor) {
                      for (PsiFile file : files) {
                        CopyHandler.updateSelectionInActiveProjectView(
                            file, project, selectInActivePanel);
                      }
                      EditorHelper.openFilesInEditor(files.toArray(new PsiFile[files.size()]));
                    }

                    result[0] = true;
                  }
                } catch (final IncorrectOperationException ex) {
                  ApplicationManager.getApplication()
                      .invokeLater(
                          () ->
                              Messages.showMessageDialog(
                                  project,
                                  ex.getMessage(),
                                  RefactoringBundle.message("error.title"),
                                  Messages.getErrorIcon()));
                }
              };
          ApplicationManager.getApplication().runWriteAction(action);
        };
    CommandProcessor processor = CommandProcessor.getInstance();
    processor.executeCommand(project, command, commandName, null);

    if (result[0]) {
      ToolWindowManager.getInstance(project)
          .invokeLater(() -> ToolWindowManager.getInstance(project).activateEditorComponent());
    }
  }
예제 #2
0
 public static void updateStudyToolWindow(Project project) {
   ToolWindowManager.getInstance(project)
       .getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW)
       .getContentManager()
       .removeAllContents(false);
   StudyToolWindowFactory factory = new StudyToolWindowFactory();
   factory.createToolWindowContent(
       project,
       ToolWindowManager.getInstance(project)
           .getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW));
 }
 @Override
 public Insets getBorderInsets(final Component c) {
   if (myProject == null) return new Insets(0, 0, 0, 0);
   ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
   if (!(toolWindowManager instanceof ToolWindowManagerImpl)
       || !((ToolWindowManagerImpl) toolWindowManager).isToolWindowRegistered(myInfo.getId())
       || myWindow.getType() == ToolWindowType.FLOATING) {
     return new Insets(0, 0, 0, 0);
   }
   ToolWindowAnchor anchor = myWindow.getAnchor();
   Component component = myWindow.getComponent();
   Container parent = component.getParent();
   while (parent != null) {
     if (parent instanceof Splitter) {
       Splitter splitter = (Splitter) parent;
       boolean isFirst = splitter.getFirstComponent() == component;
       boolean isVertical = splitter.isVertical();
       return new Insets(
           0,
           anchor == ToolWindowAnchor.RIGHT || (!isVertical && !isFirst) ? 1 : 0,
           (isVertical && isFirst) ? 1 : 0,
           anchor == ToolWindowAnchor.LEFT || (!isVertical && isFirst) ? 1 : 0);
     }
     component = parent;
     parent = component.getParent();
   }
   return new Insets(
       0,
       anchor == ToolWindowAnchor.RIGHT ? 1 : 0,
       anchor == ToolWindowAnchor.TOP ? 1 : 0,
       anchor == ToolWindowAnchor.LEFT ? 1 : 0);
 }
예제 #4
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;
  }
  private synchronized void unregisterToolWindow() {
    if (myToolWindow == null) return;

    ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
    toolWindowManager.unregisterToolWindow(TOOL_WINDOW_ID);
    myToolWindow = null;
  }
  @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;
  }
 @Override
 protected void previewRefactoring(final UsageInfo[] usages) {
   MigrationPanel panel = new MigrationPanel(myRoot[0], myLabeler, myProject, isPreviewUsages());
   String text;
   if (myRoot[0] instanceof PsiField) {
     text = "field \'" + ((PsiField) myRoot[0]).getName() + "\'";
   } else if (myRoot[0] instanceof PsiParameter) {
     text = "parameter \'" + ((PsiParameter) myRoot[0]).getName() + "\'";
   } else if (myRoot[0] instanceof PsiLocalVariable) {
     text = "variable \'" + ((PsiLocalVariable) myRoot[0]).getName() + "\'";
   } else if (myRoot[0] instanceof PsiMethod) {
     text = "method \'" + ((PsiMethod) myRoot[0]).getName() + "\' return";
   } else {
     text = Arrays.toString(myRoot);
   }
   Content content =
       UsageViewManager.getInstance(myProject)
           .addContent(
               "Migrate Type of "
                   + text
                   + " from \'"
                   + TypeMigrationLabeler.getElementType(myRoot[0]).getPresentableText()
                   + "\' to \'"
                   + myRules.getMigrationRootType().getPresentableText()
                   + "\'",
               false,
               panel,
               true,
               true);
   panel.setContent(content);
   ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.FIND).activate(null);
 }
  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 doSelectModuleOrGroup(final Object toSelect, final boolean requestFocus) {
   ToolWindowManager windowManager = ToolWindowManager.getInstance(myProject);
   final Runnable runnable =
       new Runnable() {
         @Override
         public void run() {
           ProjectView projectView = ProjectView.getInstance(myProject);
           if (requestFocus) {
             projectView.changeView(getId(), getSubId());
           }
           ((BaseProjectTreeBuilder) getTreeBuilder())
               .selectInWidth(
                   toSelect,
                   requestFocus,
                   new Condition<AbstractTreeNode>() {
                     @Override
                     public boolean value(final AbstractTreeNode node) {
                       return node instanceof AbstractModuleNode
                           || node instanceof ModuleGroupNode
                           || node instanceof AbstractProjectNode;
                     }
                   });
         }
       };
   if (requestFocus) {
     windowManager.getToolWindow(ToolWindowId.PROJECT_VIEW).activate(runnable);
   } else {
     runnable.run();
   }
 }
  private void initialize() {
    if (myIsInitialized) {
      return;
    }

    myIsInitialized = true;
    myIsDisposed = false;

    myContentManager = ContentFactory.SERVICE.getInstance().createContentManager(true, myProject);
    myContentManager.addContentManagerListener(
        new ContentManagerAdapter() {
          public void contentRemoved(ContentManagerEvent event) {
            JComponent component = event.getContent().getComponent();
            JComponent removedComponent =
                component instanceof CvsTabbedWindowComponent
                    ? ((CvsTabbedWindowComponent) component).getComponent()
                    : component;
            if (removedComponent == myErrorsView) {
              myErrorsView.dispose();
              myErrorsView = null;
            } else if (myOutput != null && removedComponent == myOutput.getComponent()) {
              EditorFactory.getInstance().releaseEditor(myOutput);
              myOutput = null;
            }
          }
        });

    ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
    ToolWindow toolWindow =
        toolWindowManager.registerToolWindow(
            ToolWindowId.CVS, myContentManager.getComponent(), ToolWindowAnchor.BOTTOM);
    toolWindow.setIcon(AllIcons.Providers.Cvs);
    toolWindow.installWatcher(myContentManager);
  }
예제 #11
0
 @Override
 protected void previewRefactoring(@NotNull final UsageInfo[] usages) {
   MigrationPanel panel = new MigrationPanel(myRoot, myLabeler, myProject, isPreviewUsages());
   String name;
   if (myRoot.length == 1) {
     String fromType =
         assertNotNull(TypeMigrationLabeler.getElementType(myRoot[0])).getPresentableText();
     String toType = myRootTypes.fun(myRoot[0]).getPresentableText();
     String text;
     text = getPresentation(myRoot[0]);
     name = "Migrate Type of " + text + " from \'" + fromType + "\' to \'" + toType + "\'";
   } else {
     final int rootsInPresentationCount =
         myRoot.length > MAX_ROOT_IN_PREVIEW_PRESENTATION
             ? MAX_ROOT_IN_PREVIEW_PRESENTATION
             : myRoot.length;
     String[] rootsPresentation = new String[rootsInPresentationCount];
     for (int i = 0; i < rootsInPresentationCount; i++) {
       final PsiElement root = myRoot[i];
       rootsPresentation[i] =
           root instanceof PsiNamedElement ? ((PsiNamedElement) root).getName() : root.getText();
     }
     rootsPresentation = StringUtil.surround(rootsPresentation, "\'", "\'");
     name = "Migrate Type of " + StringUtil.join(rootsPresentation, ", ");
     if (myRoot.length > MAX_ROOT_IN_PREVIEW_PRESENTATION) {
       name += "...";
     }
   }
   Content content =
       UsageViewManager.getInstance(myProject).addContent(name, false, panel, true, true);
   panel.setContent(content);
   ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.FIND).activate(null);
 }
    public BookmarkInContextInfo invoke() {
      myBookmarkAtPlace = null;
      myFile = null;
      myLine = -1;

      BookmarkManager bookmarkManager = BookmarkManager.getInstance(myProject);
      if (ToolWindowManager.getInstance(myProject).isEditorComponentActive()) {
        Editor editor = CommonDataKeys.EDITOR.getData(myDataContext);
        if (editor != null) {
          Document document = editor.getDocument();
          myLine = editor.getCaretModel().getLogicalPosition().line;
          myFile = FileDocumentManager.getInstance().getFile(document);
          myBookmarkAtPlace = bookmarkManager.findEditorBookmark(document, myLine);
        }
      }

      if (myFile == null) {
        myFile = CommonDataKeys.VIRTUAL_FILE.getData(myDataContext);
        myLine = -1;

        if (myBookmarkAtPlace == null && myFile != null) {
          myBookmarkAtPlace = bookmarkManager.findFileBookmark(myFile);
        }
      }
      return this;
    }
 @Override
 public UpdateInfoTree showUpdateProjectInfo(
     UpdatedFiles updatedFiles,
     String displayActionName,
     ActionInfo actionInfo,
     boolean canceled) {
   if (!myProject.isOpen() || myProject.isDisposed()) return null;
   ContentManager contentManager = getContentManager();
   if (contentManager == null) {
     return null; // content manager is made null during dispose; flag is set later
   }
   final UpdateInfoTree updateInfoTree =
       new UpdateInfoTree(contentManager, myProject, updatedFiles, displayActionName, actionInfo);
   Content content =
       ContentFactory.SERVICE
           .getInstance()
           .createContent(
               updateInfoTree,
               canceled
                   ? VcsBundle.message(
                       "toolwindow.title.update.action.canceled.info", displayActionName)
                   : VcsBundle.message("toolwindow.title.update.action.info", displayActionName),
               true);
   Disposer.register(content, updateInfoTree);
   ContentsUtil.addContent(contentManager, content, true);
   ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.VCS).activate(null);
   updateInfoTree.expandRootChildren();
   return updateInfoTree;
 }
예제 #14
0
 private void showToolWindow(boolean activateWindow) {
   ToolWindow toolWindow =
       ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.FIND);
   toolWindow.show(null);
   if (activateWindow && !toolWindow.isActive()) {
     toolWindow.activate(null);
   }
 }
 public ToolWindow getToolWindow() {
   if (myToolWindow == null) {
     myToolWindow =
         ToolWindowManager.getInstance(getProject())
             .getToolWindow(PythonConsoleToolWindowFactory.ID);
   }
   return myToolWindow;
 }
예제 #16
0
 public void projectClosed() {
   if (myPaletteWindow != null) {
     myPaletteWindow.dispose();
     ToolWindowManager.getInstance(myProject)
         .unregisterToolWindow(IdeBundle.message("toolwindow.palette"));
     myPaletteWindow = null;
   }
 }
  private QueryResultPanel getSelectedResultPanel() {
    ToolWindow wm = ToolWindowManager.getInstance(project).getToolWindow(QUERY_RESULT_PANE);
    Content selected = wm.getContentManager().getSelectedContent();
    if (selected != null) {
      return getSelectedTab(selected);
    }

    return null;
  }
 @Override
 public ContentManager getContentManager() {
   if (myContentManager == null && Registry.is("vcs.merge.toolwindows")) {
     final ToolWindow changes =
         ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.VCS);
     myContentManager = changes == null ? null : changes.getContentManager();
   }
   return myContentManager;
 }
  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 registerToolwindow(@NotNull final Executor executor) {
    final String toolWindowId = executor.getToolWindowId();
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
    if (toolWindowManager == null) return; // headless environment
    if (toolWindowManager.getToolWindow(toolWindowId) != null) {
      return;
    }

    final ToolWindow toolWindow =
        toolWindowManager.registerToolWindow(
            toolWindowId, true, ToolWindowAnchor.BOTTOM, this, true);

    final ContentManager contentManager = toolWindow.getContentManager();
    class MyDataProvider implements DataProvider {
      private int myInsideGetData = 0;

      public Object getData(String dataId) {
        myInsideGetData++;
        try {
          if (PlatformDataKeys.HELP_ID.is(dataId)) {
            return executor.getHelpId();
          } else {
            return myInsideGetData == 1
                ? DataManager.getInstance()
                    .getDataContext(contentManager.getComponent())
                    .getData(dataId)
                : null;
          }
        } finally {
          myInsideGetData--;
        }
      }
    }
    contentManager.addDataProvider(new MyDataProvider());

    toolWindow.setIcon(executor.getToolWindowIcon());
    new ContentManagerWatcher(toolWindow, contentManager);
    contentManager.addContentManagerListener(
        new ContentManagerAdapter() {
          public void selectionChanged(final ContentManagerEvent event) {
            final Content content = event.getContent();
            final RunContentDescriptor descriptor =
                content != null ? getRunContentDescriptorByContent(content) : null;
            getSyncPublisher().contentSelected(descriptor, executor);
          }
        });
    myToolwindowIdToContentManagerMap.put(toolWindowId, contentManager);
    Disposer.register(
        contentManager,
        new Disposable() {
          public void dispose() {
            unregisterToolwindow(toolWindowId);
          }
        });
    myToolwindowIdZbuffer.addLast(toolWindowId);
  }
 public void ensureVisible(Project project) {
   if (project == null) return;
   ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
   if (toolWindowManager != null) {
     ToolWindow toolWindow = toolWindowManager.getToolWindow(ToolWindowId.CVS);
     if (toolWindow != null) {
       toolWindow.activate(null, false);
     }
   }
 }
 @Override
 @Nullable
 public ToolWindow getToolWindowByDescriptor(@NotNull final RunContentDescriptor descriptor) {
   for (Map.Entry<String, ContentManager> entry : myToolwindowIdToContentManagerMap.entrySet()) {
     if (getRunContentByDescriptor(entry.getValue(), descriptor) != null) {
       return ToolWindowManager.getInstance(myProject).getToolWindow(entry.getKey());
     }
   }
   return null;
 }
예제 #23
0
 private void activateMessageView() {
   synchronized (myMessageViewLock) {
     if (myErrorTreeView != null) {
       final ToolWindow tw =
           ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.MESSAGES_WINDOW);
       if (tw != null) {
         tw.activate(null, false);
       }
     }
   }
 }
예제 #24
0
    public PostponeableLogRefresher(
        @NotNull Project project, @NotNull VcsLogDataHolder dataHolder) {
      myDataHolder = dataHolder;
      myToolWindowManager = (ToolWindowManagerImpl) ToolWindowManager.getInstance(project);
      myToolWindow = (ToolWindowImpl) myToolWindowManager.getToolWindow(TOOLWINDOW_ID);

      Disposer.register(myToolWindow.getContentManager(), this);

      myPostponedEventsListener = new MyRefreshPostponedEventsListener();
      myToolWindow.getContentManager().addContentManagerListener(myPostponedEventsListener);
      myToolWindowManager.addToolWindowManagerListener(myPostponedEventsListener);
    }
 public void ensureVisible(Project project) {
   if (project == null) {
     return;
   }
   ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
   if (toolWindowManager != null) {
     ToolWindow toolWindow = toolWindowManager.getToolWindow(COMMIT_LOGS_TOOLWINDOW_ID);
     if (toolWindow != null) {
       toolWindow.activate(null);
     }
   }
 }
  @Override
  public void disposeComponent() {
    releaseEditor();
    myMappings.disposeMe();
    myConnect.disconnect();
    Disposer.dispose(myAnnotationLocalChangesListener);
    myContentManager = null;

    ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
    if (toolWindowManager != null && toolWindowManager.getToolWindow(ToolWindowId.VCS) != null) {
      toolWindowManager.unregisterToolWindow(ToolWindowId.VCS);
    }
  }
예제 #27
0
 @Override
 protected void notifyByBalloon(
     JUnitRunningModel model, boolean started, final JUnitConsoleProperties consoleProperties) {
   if (myFoundTests) {
     super.notifyByBalloon(model, started, consoleProperties);
   } else {
     final String packageName = myConfiguration.getPackage();
     if (packageName == null) return;
     final Project project = myConfiguration.getProject();
     final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(packageName);
     if (aPackage == null) return;
     final Module module = myConfiguration.getConfigurationModule().getModule();
     if (module == null) return;
     final Set<Module> modulesWithPackage = new HashSet<Module>();
     final PsiDirectory[] directories = aPackage.getDirectories();
     for (PsiDirectory directory : directories) {
       final Module currentModule =
           ModuleUtil.findModuleForFile(directory.getVirtualFile(), project);
       if (module != currentModule && currentModule != null) {
         modulesWithPackage.add(currentModule);
       }
     }
     if (!modulesWithPackage.isEmpty()) {
       final String testRunDebugId =
           consoleProperties.isDebug() ? ToolWindowId.DEBUG : ToolWindowId.RUN;
       final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
       final Function<Module, String> moduleNameRef =
           new Function<Module, String>() {
             @Override
             public String fun(Module module) {
               final String moduleName = module.getName();
               return "<a href=\"" + moduleName + "\">" + moduleName + "</a>";
             }
           };
       String message = "Tests were not found in module \"" + module.getName() + "\".\n" + "Use ";
       if (modulesWithPackage.size() == 1) {
         message += "module \"" + moduleNameRef.fun(modulesWithPackage.iterator().next()) + "\" ";
       } else {
         message += "one of\n" + StringUtil.join(modulesWithPackage, moduleNameRef, "\n") + "\n";
       }
       message += "instead";
       toolWindowManager.notifyByBalloon(
           testRunDebugId,
           MessageType.WARNING,
           message,
           null,
           new ResetConfigurationModuleAdapter(
               project, consoleProperties, toolWindowManager, testRunDebugId));
     }
   }
 }
 public void focusGained(final FocusEvent e) {
   if (e.getOppositeComponent() == null && shouldFocusEditor) {
     shouldFocusEditor = false;
     ToolWindowManager.getInstance(myPanel.getProject()).activateEditorComponent();
     return;
   }
   myPanel.updateItems();
   final List<NavBarItem> items = myPanel.getItems();
   if (!myPanel.isInFloatingMode() && items.size() > 0) {
     myPanel.setContextComponent(items.get(items.size() - 1));
   } else {
     myPanel.setContextComponent(null);
   }
 }
  private boolean isProjectViewVisible() {
    final Window frame = SwingUtilities.getWindowAncestor(this);
    if (frame instanceof IdeFrameImpl) {
      final Project project = ((IdeFrameImpl) frame).getProject();
      if (project != null) {
        if (!project.isInitialized()) return true;
        ToolWindow toolWindow =
            ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.PROJECT_VIEW);
        return toolWindow != null && toolWindow.isVisible();
      }
    }

    return false;
  }
예제 #30
0
  public void initTerminal(final ToolWindow toolWindow) {
    LocalTerminalDirectRunner terminalRunner =
        LocalTerminalDirectRunner.createTerminalRunner(myProject);

    toolWindow.setToHideOnEmptyContent(true);

    Content content = createTerminalInContentPanel(terminalRunner, toolWindow);

    toolWindow.getContentManager().addContent(content);

    ((ToolWindowManagerEx) ToolWindowManager.getInstance(myProject))
        .addToolWindowManagerListener(
            new ToolWindowManagerListener() {
              @Override
              public void toolWindowRegistered(@NotNull String id) {}

              @Override
              public void stateChanged() {
                ToolWindow window =
                    ToolWindowManager.getInstance(myProject)
                        .getToolWindow(TerminalToolWindowFactory.TOOL_WINDOW_ID);
                if (window != null) {
                  boolean visible = window.isVisible();
                  if (visible && toolWindow.getContentManager().getContentCount() == 0) {
                    initTerminal(window);
                  }
                }
              }
            });

    Disposer.register(
        myProject,
        new Disposable() {
          @Override
          public void dispose() {
            if (myTerminalWidget != null) {
              myTerminalWidget.dispose();
              myTerminalWidget = null;
            }
          }
        });

    if (myDockContainer == null) {
      myDockContainer = new TerminalDockContainer(toolWindow);

      Disposer.register(myProject, myDockContainer);
      DockManager.getInstance(myProject).register(myDockContainer);
    }
  }