@NotNull @Override public RelativePoint guessBestPopupLocation(@NotNull DataContext dataContext) { Component component = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext); JComponent focusOwner = component instanceof JComponent ? (JComponent) component : null; if (focusOwner == null) { Project project = PlatformDataKeys.PROJECT.getData(dataContext); IdeFrameImpl frame = project == null ? null : ((WindowManagerEx) WindowManager.getInstance()).getFrame(project); focusOwner = frame == null ? null : frame.getRootPane(); if (focusOwner == null) { throw new IllegalArgumentException("focusOwner cannot be null"); } } final Point point = PlatformDataKeys.CONTEXT_MENU_POINT.getData(dataContext); if (point != null) { return new RelativePoint(focusOwner, point); } Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); if (editor != null && focusOwner == editor.getContentComponent()) { return guessBestPopupLocation(editor); } else { return guessBestPopupLocation(focusOwner); } }
@Override public void actionPerformed(AnActionEvent e) { DataContext context = e.getDataContext(); Editor editor = PlatformDataKeys.EDITOR.getData(context); PsiFile psiFile = LangDataKeys.PSI_FILE.getData(context); if (psiFile == null) return; List<GotoRelatedItem> items = getItems(psiFile, editor, context); if (items.isEmpty()) return; if (items.size() == 1 && items.get(0).getElement() != null) { items.get(0).navigate(); return; } if (ApplicationManager.getApplication().isUnitTestMode()) { System.out.println(items); } createPopup(items, "Go to Related Files").showInBestPositionFor(context); }