コード例 #1
0
  private void processKeyEvent(KeyEvent e) {
    if (e.isAltDown()) return;
    if (mySearchPopup != null) {
      mySearchPopup.processKeyEvent(e);
      return;
    }
    if (!isSpeedSearchEnabled()) return;
    if (e.getID() == KeyEvent.KEY_TYPED) {
      if (!UIUtil.isReallyTypedEvent(e)) return;

      char c = e.getKeyChar();
      if (Character.isLetterOrDigit(c) || c == '_' || c == '*' || c == '/' || c == ':') {
        manageSearchPopup(new SearchPopup(String.valueOf(c)));
        e.consume();
      }
    }
  }
コード例 #2
0
 @Override
 public boolean isPopupActive() {
   return mySearchPopup != null && mySearchPopup.isVisible();
 }
コード例 #3
0
  private void manageSearchPopup(@Nullable SearchPopup searchPopup) {
    final Project project;
    if (ApplicationManager.getApplication() != null
        && !ApplicationManager.getApplication().isDisposed()) {
      project =
          PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myComponent));
    } else {
      project = null;
    }

    if (mySearchPopup != null) {
      myPopupLayeredPane.remove(mySearchPopup);
      myPopupLayeredPane.validate();
      myPopupLayeredPane.repaint();
      myPopupLayeredPane = null;

      if (project != null) {
        ((ToolWindowManagerEx) ToolWindowManager.getInstance(project))
            .removeToolWindowManagerListener(myWindowManagerListener);
      }
    } else if (searchPopup != null) {
      FeatureUsageTracker.getInstance().triggerFeatureUsed("ui.tree.speedsearch");
    }

    if (!myComponent.isShowing()) {
      mySearchPopup = null;
    } else {
      mySearchPopup = searchPopup;
    }

    fireStateChanged();

    if (mySearchPopup == null || !myComponent.isDisplayable()) return;

    if (project != null) {
      ((ToolWindowManagerEx) ToolWindowManager.getInstance(project))
          .addToolWindowManagerListener(myWindowManagerListener);
    }
    JRootPane rootPane = myComponent.getRootPane();
    if (rootPane != null) {
      myPopupLayeredPane = rootPane.getLayeredPane();
    } else {
      myPopupLayeredPane = null;
    }
    if (myPopupLayeredPane == null) {
      LOG.error(toString() + " in " + String.valueOf(myComponent));
      return;
    }
    myPopupLayeredPane.add(mySearchPopup, JLayeredPane.POPUP_LAYER);
    if (myPopupLayeredPane == null) return; // See # 27482. Somewho it does happen...
    Point lPaneP = myPopupLayeredPane.getLocationOnScreen();
    Point componentP = getComponentLocationOnScreen();
    Rectangle r = getComponentVisibleRect();
    Dimension prefSize = mySearchPopup.getPreferredSize();
    Window window = (Window) SwingUtilities.getAncestorOfClass(Window.class, myComponent);
    Point windowP;
    if (window instanceof JDialog) {
      windowP = ((JDialog) window).getContentPane().getLocationOnScreen();
    } else if (window instanceof JFrame) {
      windowP = ((JFrame) window).getContentPane().getLocationOnScreen();
    } else {
      windowP = window.getLocationOnScreen();
    }
    int y = r.y + componentP.y - lPaneP.y - prefSize.height;
    y = Math.max(y, windowP.y - lPaneP.y);
    mySearchPopup.setLocation(componentP.x - lPaneP.x + r.x, y);
    mySearchPopup.setSize(prefSize);
    mySearchPopup.setVisible(true);
    mySearchPopup.validate();
  }
コード例 #4
0
 public void refreshSelection() {
   if (mySearchPopup != null) mySearchPopup.refreshSelection();
 }