com.intellij.openapi.ui.popup.JBPopup Java Examples

The following examples show how to use com.intellij.openapi.ui.popup.JBPopup. 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: ChangeGoToChangePopupAction.java    From consulo with Apache License 2.0 7 votes vote down vote up
@Nonnull
@Override
protected JBPopup createPopup(@Nonnull AnActionEvent e) {
  Project project = e.getProject();
  if (project == null) project = ProjectManager.getInstance().getDefaultProject();

  Ref<JBPopup> popup = new Ref<JBPopup>();
  ChangesBrowser cb = new MyChangesBrowser(project, getChanges(), getCurrentSelection(), popup);

  popup.set(JBPopupFactory.getInstance()
                    .createComponentPopupBuilder(cb, cb.getPreferredFocusedComponent())
                    .setResizable(true)
                    .setModalContext(false)
                    .setFocusable(true)
                    .setRequestFocus(true)
                    .setCancelOnWindowDeactivation(true)
                    .setCancelOnOtherWindowOpen(true)
                    .setMovable(true)
                    .setCancelKeyEnabled(true)
                    .setCancelOnClickOutside(true)
                    .setDimensionServiceKey(project, "Diff.GoToChangePopup", false)
                    .createPopup());

  return popup.get();
}
 
Example #2
Source File: ComboBoxButtonImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showPopup0() {
  hidePopup0();

  if (myOnClickListener != null) {
    myOnClickListener.run();

    myCurrentPopupCanceler = null;
    return;
  }

  JBPopup popup = createPopup(() -> {
    myCurrentPopupCanceler = null;

    updateSize();
  });
  popup.showUnderneathOf(this);

  myCurrentPopupCanceler = popup::cancel;
}
 
Example #3
Source File: SetShortcutAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  Project project = e.getProject();
  JBPopup seDialog = project == null ? null : project.getUserData(SearchEverywhereManager.SEARCH_EVERYWHERE_POPUP);
  if (seDialog == null) {
    return;
  }

  KeymapManager km = KeymapManager.getInstance();
  Keymap activeKeymap = km != null ? km.getActiveKeymap() : null;
  if (activeKeymap == null) {
    return;
  }

  AnAction action = e.getData(SELECTED_ACTION);
  Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
  if (action == null || component == null) {
    return;
  }

  seDialog.cancel();
  String id = ActionManager.getInstance().getId(action);
  KeymapPanel.addKeyboardShortcut(id, ActionShortcutRestrictions.getInstance().getForActionId(id), activeKeymap, component);
}
 
Example #4
Source File: GotoRelatedFileAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static JBPopup createPopup(final List<? extends GotoRelatedItem> items, final String title) {
  Object[] elements = new Object[items.size()];
  //todo[nik] move presentation logic to GotoRelatedItem class
  final Map<PsiElement, GotoRelatedItem> itemsMap = new HashMap<PsiElement, GotoRelatedItem>();
  for (int i = 0; i < items.size(); i++) {
    GotoRelatedItem item = items.get(i);
    elements[i] = item.getElement() != null ? item.getElement() : item;
    itemsMap.put(item.getElement(), item);
  }

  return getPsiElementPopup(elements, itemsMap, title, new Processor<Object>() {
    @Override
    public boolean process(Object element) {
      if (element instanceof PsiElement) {
        //noinspection SuspiciousMethodCalls
        itemsMap.get(element).navigate();
      }
      else {
        ((GotoRelatedItem)element).navigate();
      }
      return true;
    }
  }
  );
}
 
Example #5
Source File: NavigationUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Returns navigation popup that shows list of related items from {@code items} list
 *
 * @param items
 * @param title
 * @param showContainingModules Whether the popup should show additional information that aligned at the right side of the dialog.<br>
 *                              It's usually a module name or library name of corresponding navigation item.<br>
 *                              {@code false} by default
 * @return
 */
@Nonnull
public static JBPopup getRelatedItemsPopup(final List<? extends GotoRelatedItem> items, String title, boolean showContainingModules) {
  Object[] elements = new Object[items.size()];
  //todo[nik] move presentation logic to GotoRelatedItem class
  final Map<PsiElement, GotoRelatedItem> itemsMap = new HashMap<>();
  for (int i = 0; i < items.size(); i++) {
    GotoRelatedItem item = items.get(i);
    elements[i] = item.getElement() != null ? item.getElement() : item;
    itemsMap.put(item.getElement(), item);
  }

  return getPsiElementPopup(elements, itemsMap, title, showContainingModules, element -> {
    if (element instanceof PsiElement) {
      //noinspection SuspiciousMethodCalls
      itemsMap.get(element).navigate();
    }
    else {
      ((GotoRelatedItem)element).navigate();
    }
    return true;
  });
}
 
Example #6
Source File: PsiElementListNavigator.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void openTargets(MouseEvent e,
                               NavigatablePsiElement[] targets,
                               String title,
                               final String findUsagesTitle,
                               ListCellRenderer listRenderer,
                               @Nullable BackgroundUpdaterTask listUpdaterTask) {
  JBPopup popup = navigateOrCreatePopup(targets, title, findUsagesTitle, listRenderer, listUpdaterTask);
  if (popup != null) {
    RelativePoint point = new RelativePoint(e);
    if (listUpdaterTask != null) {
      runActionAndListUpdaterTask(() -> popup.show(point), listUpdaterTask);
    }
    else {
      popup.show(point);
    }
  }
}
 
Example #7
Source File: SearchUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void showHintPopup(final ConfigurableSearchTextField searchField,
                                 final JBPopup[] activePopup,
                                 final Alarm showHintAlarm,
                                 final Consumer<String> selectConfigurable,
                                 final Project project) {
  for (JBPopup aPopup : activePopup) {
    if (aPopup != null) {
      aPopup.cancel();
    }
  }

  final JBPopup popup = createPopup(searchField, activePopup, showHintAlarm, selectConfigurable, project, 0); //no selection
  if (popup != null) {
    popup.showUnderneathOf(searchField);
    searchField.requestFocusInWindow();
  }

  activePopup[0] = popup;
  activePopup[1] = null;
}
 
Example #8
Source File: RecentLocationsAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void initSearchActions(@Nonnull Project project,
                                      @Nonnull RecentLocationsDataModel data,
                                      @Nonnull ListWithFilter<RecentLocationItem> listWithFilter,
                                      @Nonnull JBList<RecentLocationItem> list,
                                      @Nonnull JBCheckBox checkBox,
                                      @Nonnull JBPopup popup,
                                      @Nonnull Ref<? super Boolean> navigationRef) {
  listWithFilter.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent event) {
      int clickCount = event.getClickCount();
      if (clickCount > 1 && clickCount % 2 == 0) {
        event.consume();
        navigateToSelected(project, list, popup, navigationRef);
      }
    }
  });

  DumbAwareAction.create(e -> navigateToSelected(project, list, popup, navigationRef)).registerCustomShortcutSet(CustomShortcutSet.fromString("ENTER"), listWithFilter, popup);

  DumbAwareAction.create(e -> removePlaces(project, listWithFilter, list, data, checkBox.isSelected()))
          .registerCustomShortcutSet(CustomShortcutSet.fromString("DELETE", "BACK_SPACE"), listWithFilter, popup);
}
 
Example #9
Source File: RunAnythingManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void calcPositionAndShow(Project project, JBPopup balloon) {
  Point savedLocation = WindowStateService.getInstance(myProject).getLocation(LOCATION_SETTINGS_KEY);

  if (project != null) {
    balloon.showCenteredInCurrentWindow(project);
  }
  else {
    balloon.showInFocusCenter();
  }

  //for first show and short mode popup should be shifted to the top screen half
  if (savedLocation == null && myRunAnythingUI.getViewType() == RunAnythingPopupUI.ViewType.SHORT) {
    Point location = balloon.getLocationOnScreen();
    location.y /= 2;
    balloon.setLocation(location);
  }
}
 
Example #10
Source File: QuickDocUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static DocumentationComponent getActiveDocComponent(@Nonnull Project project) {
  DocumentationManager documentationManager = DocumentationManager.getInstance(project);
  DocumentationComponent component;
  JBPopup hint = documentationManager.getDocInfoHint();
  if (hint != null) {
    component = (DocumentationComponent)((AbstractPopup)hint).getComponent();
  }
  else if (documentationManager.hasActiveDockedDocWindow()) {
    ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.DOCUMENTATION);
    Content selectedContent = toolWindow == null ? null : toolWindow.getContentManager().getSelectedContent();
    component = selectedContent == null ? null : (DocumentationComponent)selectedContent.getComponent();
  }
  else {
    component = EditorMouseHoverPopupManager.getInstance().getDocumentationComponent();
  }
  return component;
}
 
Example #11
Source File: DocumentationManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public JBPopup getDocInfoHint() {
  if (myDocInfoHintRef == null) return null;
  JBPopup hint = myDocInfoHintRef.get();
  if (hint == null || !hint.isVisible() && !ApplicationManager.getApplication().isUnitTestMode()) {
    if (hint != null) {
      // hint's window might've been hidden by AWT without notifying us
      // dispose to remove the popup from IDE hierarchy and avoid leaking components
      hint.cancel();
    }
    myDocInfoHintRef = null;
    return null;
  }
  return hint;
}
 
Example #12
Source File: StackingPopupDispatcherImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private JBPopup findPopup() {
  while (true) {
    if (myStack.isEmpty()) break;
    final AbstractPopup each = (AbstractPopup)myStack.peek();
    if (each == null || each.isDisposed()) {
      myStack.pop();
    }
    else {
      return each;
    }
  }

  return null;
}
 
Example #13
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Rectangle getCurrentHintBounds(Editor editor) {
  JBPopup popup = getCurrentHint();
  if (popup == null) return null;
  Dimension size = popup.getSize();
  if (size == null) return null;
  Rectangle result = new Rectangle(popup.getLocationOnScreen(), size);
  int borderTolerance = editor.getLineHeight() / 3;
  result.grow(borderTolerance, borderTolerance);
  return result;
}
 
Example #14
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean showPopupIfNeedTo(@Nonnull JBPopup popup, @Nonnull RelativePoint popupPosition) {
  if (!popup.isDisposed() && !popup.isVisible()) {
    popup.show(popupPosition);
    return true;
  }
  else {
    return false;
  }
}
 
Example #15
Source File: DocumentationComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Component getPopupAnchor() {
  LookupEx lookup = myManager == null ? null : LookupManager.getActiveLookup(myManager.getEditor());

  if (lookup != null && lookup.getCurrentItem() != null && lookup.getComponent().isShowing()) {
    return lookup.getComponent();
  }
  Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
  JBPopup popup = PopupUtil.getPopupContainerFor(focusOwner);
  if (popup != null && popup != myHint && !popup.isDisposed()) {
    return popup.getContent();
  }
  return null;
}
 
Example #16
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private static boolean showPopupIfNeedTo(@NotNull JBPopup popup, @NotNull RelativePoint popupPosition) {
  if (!popup.isDisposed() && !popup.isVisible()) {
    popup.show(popupPosition);
    return true;
  }
  else {
    return false;
  }
}
 
Example #17
Source File: PopupComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
public PopupComponent getPopup(Component owner, Component content, int x, int y, JBPopup jbPopup) {
  final PopupFactory factory = PopupFactory.getSharedInstance();

  final int oldType = PopupUtil.getPopupType(factory);
  PopupUtil.setPopupType(factory, 2);
  final Popup popup = factory.getPopup(owner, content, x, y);
  if (oldType >= 0) PopupUtil.setPopupType(factory, oldType);

  return new AwtPopupWrapper(popup, jbPopup);
}
 
Example #18
Source File: PopupComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void hide(boolean dispose) {
  myDialog.setVisible(false);
  if (dispose) {
    myDialog.dispose();
    myDialog.getRootPane().putClientProperty(JBPopup.KEY, null);
  }
}
 
Example #19
Source File: StackingPopupDispatcherImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void setRestoreFocusSilently() {
  if (myStack.isEmpty()) return;

  for (JBPopup each : myAllPopups) {
    if (each instanceof AbstractPopup) {
      ((AbstractPopup)each).setOk(true);
    }
  }

}
 
Example #20
Source File: PopupComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void show() {
  myPopup.show();
  Window wnd = getWindow();
  if (wnd instanceof JWindow) {
    ((JWindow)wnd).getRootPane().putClientProperty(JBPopup.KEY, myJBPopup);
  }
}
 
Example #21
Source File: RegExHelpPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static LinkLabel createRegExLink(@Nonnull String title, @Nullable final Component owner, @Nullable final Logger logger) {
  return new LinkLabel(title, null, new LinkListener() {
    JBPopup helpPopup;
    @Override
    public void linkSelected(LinkLabel aSource, Object aLinkData) {
      try {
        if (helpPopup != null && !helpPopup.isDisposed() && helpPopup.isVisible()) {
          return;
        }
        helpPopup = createRegExHelpPopup();
        Disposer.register(helpPopup, new Disposable() {
          @Override
          public void dispose() {
            destroyPopup();
          }
        });
        helpPopup.showInCenterOf(owner);
      }
      catch (BadLocationException e) {
        if (logger != null) logger.info(e);
      }
    }

    private void destroyPopup() {
      helpPopup = null;
    }
  });
}
 
Example #22
Source File: SearchUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean cancelPopups(final JBPopup[] activePopup) {
  for (JBPopup popup : activePopup) {
    if (popup != null && popup.isVisible()) {
      popup.cancel();
      return true;
    }
  }
  return false;
}
 
Example #23
Source File: StackingPopupDispatcherImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(final KeyEvent e) {
  final boolean closeRequest = AbstractPopup.isCloseRequest(e);

  JBPopup popup = closeRequest ? findPopup() : getFocusedPopup();
  if (popup == null) return false;

  Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
  if (window instanceof Dialog && ((Dialog)window).isModal()) {
    if (!SwingUtilities.isDescendingFrom(popup.getContent(), window)) return false;
  }

  return popup.dispatchKeyEvent(e);
}
 
Example #24
Source File: QuickDocOnMouseOverManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void closeQuickDocIfPossible() {
  myAlarm.cancelAllRequests();
  DocumentationManager docManager = getDocManager();
  if (docManager != null) {
    JBPopup hint = docManager.getDocInfoHint();
    if (hint != null) hint.cancel();
  }
}
 
Example #25
Source File: BookmarksAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMnemonic(KeyEvent e, Project project, JBPopup popup) {
  char mnemonic = e.getKeyChar();
  final Bookmark bookmark = BookmarkManager.getInstance(project).findBookmarkForMnemonic(mnemonic);
  if (bookmark != null) {
    popup.cancel();
    IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(new Runnable() {
      @Override
      public void run() {
        bookmark.navigate(true);
      }
    });
  }
}
 
Example #26
Source File: StackingPopupDispatcherImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void onPopupHidden(JBPopup popup) {
  boolean wasInStack = myStack.remove(popup);
  myPersistentPopups.remove(popup);

  if (wasInStack && myStack.isEmpty()) {
    if (ApplicationManager.getApplication() != null) {
      IdeEventQueue.getInstance().getPopupManager().remove(this);
    }
  }

  myAllPopups.remove(popup);
}
 
Example #27
Source File: StackingPopupDispatcherImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void onPopupShown(JBPopup popup, boolean inStack) {
  if (inStack) {
    myStack.push(popup);
    if (ApplicationManager.getApplication() != null) {
      IdeEventQueue.getInstance().getPopupManager().push(getInstance());
    }
  }
  else if (popup.isPersistent()) {
    myPersistentPopups.add(popup);
  }

  myAllPopups.add(popup);
}
 
Example #28
Source File: NavigationUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static <T extends PsiElement> JBPopup getPsiElementPopup(@Nonnull T[] elements,
                                                                @Nonnull final PsiElementListCellRenderer<T> renderer,
                                                                final String title,
                                                                @Nonnull final PsiElementProcessor<T> processor) {
  return getPsiElementPopup(elements, renderer, title, processor, null);
}
 
Example #29
Source File: FocusManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Component getFocusedDescendantFor(Component comp) {
  final Component focused = getFocusOwner();
  if (focused == null) return null;

  if (focused == comp || SwingUtilities.isDescendingFrom(focused, comp)) return focused;

  List<JBPopup> popups = AbstractPopup.getChildPopups(comp);
  for (JBPopup each : popups) {
    if (each.isFocused()) return focused;
  }

  return null;
}
 
Example #30
Source File: MultipleValueFilterPopupComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  Project project = e.getProject();
  if (project == null) {
    return;
  }

  Filter filter = myFilterModel.getFilter();
  List<String> values = filter == null
                        ? Collections.emptyList()
                        : myFilterModel.getFilterValues(filter);
  final MultilinePopupBuilder popupBuilder = new MultilinePopupBuilder(project, myVariants,
                                                                       getPopupText(values),
                                                                       supportsNegativeValues());
  JBPopup popup = popupBuilder.createPopup();
  popup.addListener(new JBPopupAdapter() {
    @Override
    public void onClosed(LightweightWindowEvent event) {
      if (event.isOk()) {
        List<String> selectedValues = popupBuilder.getSelectedValues();
        if (selectedValues.isEmpty()) {
          myFilterModel.setFilter(null);
        }
        else {
          myFilterModel.setFilter(myFilterModel.createFilter(selectedValues));
          rememberValuesInSettings(selectedValues);
        }
      }
    }
  });
  popup.showUnderneathOf(MultipleValueFilterPopupComponent.this);
}