com.intellij.codeInsight.navigation.NavigationUtil Java Examples

The following examples show how to use com.intellij.codeInsight.navigation.NavigationUtil. 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: AbstractNavigationHandler.java    From NutzCodeInsight with Apache License 2.0 6 votes vote down vote up
@Override
public final void navigate(MouseEvent mouseEvent, PsiElement psiElement) {
    if (canNavigate(psiElement)) {
        final Project project = psiElement.getProject();
        final List<VirtualFile> fileList = findTemplteFileList(psiElement);
        if (fileList.size() == 1) {
            FileEditorManager.getInstance(project).openFile(fileList.get(0), true);
        } else if (fileList.size() > 1) {
            final List<VirtualFile> infos = new ArrayList<>(fileList);
            List<PsiElement> elements = new ArrayList<>();
            PsiManager psiManager = PsiManager.getInstance(psiElement.getProject());
            infos.forEach(virtualFile -> elements.add(psiManager.findFile(virtualFile).getNavigationElement()));
            NavigationUtil.getPsiElementPopup(elements.toArray(new PsiElement[0]), title).show(new RelativePoint(mouseEvent));
        } else {
            if (fileList == null || fileList.size() <= 0) {
                Messages.showErrorDialog("没有找到这个资源文件,请检查!", "错误提示");
            }
        }
    }

}
 
Example #2
Source File: AbstractPsiElementNavigationHandler.java    From NutzCodeInsight with Apache License 2.0 6 votes vote down vote up
@Override
public void navigate(MouseEvent mouseEvent, PsiElement psiElement) {
    if (canNavigate(psiElement)) {
        final Project project = psiElement.getProject();
        final List<PsiElement> psiElements = findReferences(psiElement);
        if (psiElements.size() == 1) {
            FileEditorManager.getInstance(project).openFile(PsiUtil.getVirtualFile(psiElements.get(0)), true);
        } else if (psiElements.size() > 1) {
            NavigationUtil.getPsiElementPopup(psiElements.toArray(new PsiElement[0]), title).show(new RelativePoint(mouseEvent));
        } else {
            if (Objects.isNull(psiElements) || psiElements.size() <= 0) {
                Messages.showErrorDialog("没有找到这个调用的方法,请检查!", "错误提示");
            }
        }
    }
}
 
Example #3
Source File: AbstractGotoSEContributor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean processSelectedItem(@Nonnull Object selected, int modifiers, @Nonnull String searchText) {
  if (selected instanceof PsiElement) {
    if (!((PsiElement)selected).isValid()) {
      LOG.warn("Cannot navigate to invalid PsiElement");
      return true;
    }

    PsiElement psiElement = preparePsi((PsiElement)selected, modifiers, searchText);
    Navigatable extNavigatable = createExtendedNavigatable(psiElement, searchText, modifiers);
    if (extNavigatable != null && extNavigatable.canNavigate()) {
      extNavigatable.navigate(true);
      return true;
    }

    NavigationUtil.activateFileWithPsiElement(psiElement, openInCurrentWindow(modifiers));
  }
  else {
    EditSourceUtil.navigate(((NavigationItem)selected), true, openInCurrentWindow(modifiers));
  }

  return true;
}
 
Example #4
Source File: CoverageListNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void navigate(boolean requestFocus) {
  if (canNavigate()) {
    final PsiNamedElement value = (PsiNamedElement)getValue();
    if (requestFocus) {
      NavigationUtil.activateFileWithPsiElement(value, true);
    }
    else if (value instanceof NavigationItem) {
      ((NavigationItem)value).navigate(requestFocus);
    }
  }
}
 
Example #5
Source File: AbstractPsiBasedNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void navigate(boolean requestFocus, boolean preserveState) {
  if (canNavigate()) {
    if (requestFocus || preserveState) {
      NavigationUtil.openFileWithPsiElement(extractPsiFromValue(), requestFocus, requestFocus);
    }
    else {
      getNavigationItem().navigate(requestFocus);
    }
  }
}
 
Example #6
Source File: GotoClassAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void handleSubMemberNavigation(ChooseByNamePopup popup, Object element) {
  if (element instanceof PsiElement && ((PsiElement)element).isValid()) {
    PsiElement psiElement = getElement(((PsiElement)element), popup);
    psiElement = psiElement.getNavigationElement();
    VirtualFile file = PsiUtilCore.getVirtualFile(psiElement);

    if (file != null && popup.getLinePosition() != -1) {
      OpenFileDescriptor descriptor = new OpenFileDescriptor(psiElement.getProject(), file, popup.getLinePosition(), popup.getColumnPosition());
      Navigatable n = descriptor.setUseCurrentWindow(popup.isOpenInCurrentWindowRequested());
      if (n.canNavigate()) {
        n.navigate(true);
        return;
      }
    }

    if (file != null && popup.getMemberPattern() != null) {
      NavigationUtil.activateFileWithPsiElement(psiElement, !popup.isOpenInCurrentWindowRequested());
      Navigatable member = findMember(popup.getMemberPattern(), popup.getTrimmedText(), psiElement, file);
      if (member != null) {
        member.navigate(true);
      }
    }

    NavigationUtil.activateFileWithPsiElement(psiElement, !popup.isOpenInCurrentWindowRequested());
  }
  else {
    EditSourceUtil.navigate(((NavigationItem)element), true, popup.isOpenInCurrentWindowRequested());
  }
}
 
Example #7
Source File: ClassSearchEverywhereContributor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected Navigatable createExtendedNavigatable(PsiElement psi, String searchText, int modifiers) {
  Navigatable res = super.createExtendedNavigatable(psi, searchText, modifiers);
  if (res != null) {
    return res;
  }

  VirtualFile file = PsiUtilCore.getVirtualFile(psi);
  String memberName = getMemberName(searchText);
  if (file != null && memberName != null) {
    Navigatable delegate = GotoClassAction.findMember(memberName, searchText, psi, file);
    if (delegate != null) {
      return new Navigatable() {
        @Override
        public void navigate(boolean requestFocus) {
          NavigationUtil.activateFileWithPsiElement(psi, openInCurrentWindow(modifiers));
          delegate.navigate(true);

        }

        @Override
        public boolean canNavigate() {
          return delegate.canNavigate();
        }

        @Override
        public boolean canNavigateToSource() {
          return delegate.canNavigateToSource();
        }
      };
    }
  }

  return null;
}
 
Example #8
Source File: GotoTestOrCodeHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void navigateToElement(@Nonnull Navigatable element) {
  if (element instanceof PsiElement) {
    NavigationUtil.activateFileWithPsiElement((PsiElement)element, true);
  }
  else {
    element.navigate(true);
  }
}
 
Example #9
Source File: GotoTypeDeclarationAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
public void invoke(@Nonnull final Project project, @Nonnull Editor editor, @Nonnull PsiFile file) {
  PsiDocumentManager.getInstance(project).commitAllDocuments();

  int offset = editor.getCaretModel().getOffset();
  PsiElement[] symbolTypes = findSymbolTypes(editor, offset);
  if (symbolTypes == null || symbolTypes.length == 0) return;
  if (symbolTypes.length == 1) {
    navigate(project, symbolTypes[0]);
  }
  else {
    NavigationUtil.getPsiElementPopup(symbolTypes, CodeInsightBundle.message("choose.type.popup.title")).showInBestPositionFor(editor);
  }
}
 
Example #10
Source File: AbstractValueHint.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void invokeHint(Runnable hideRunnable) {
  myHideRunnable = hideRunnable;

  if (!canShowHint()) {
    hideHint();
    return;
  }

  if (myType == ValueHintType.MOUSE_ALT_OVER_HINT) {
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    TextAttributes attributes = scheme.getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR);
    attributes = NavigationUtil.patchAttributesColor(attributes, myCurrentRange, myEditor);

    myHighlighter = myEditor.getMarkupModel().addRangeHighlighter(myCurrentRange.getStartOffset(), myCurrentRange.getEndOffset(),
                                                                  HighlighterLayer.SELECTION + 1, attributes,
                                                                  HighlighterTargetArea.EXACT_RANGE);
    Component internalComponent = myEditor.getContentComponent();
    myStoredCursor = internalComponent.getCursor();
    internalComponent.addKeyListener(myEditorKeyListener);
    internalComponent.setCursor(hintCursor());
    if (LOG.isDebugEnabled()) {
      LOG.debug("internalComponent.setCursor(hintCursor())");
    }
  }
  else {
    evaluateAndShowHint();
  }
}
 
Example #11
Source File: NewDocumentHistoryTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testSelectFileOnNavigation() throws Exception {
  VirtualFile file1 = getFile("/src/1.txt");
  myManager.openFile(file1, true);
  VirtualFile file2 = getFile("/src/2.txt");
  myManager.openFile(file2, true);
  NavigationUtil.activateFileWithPsiElement(PsiManager.getInstance(getProject()).findFile(file1));
  VirtualFile[] files = myManager.getSelectedFiles();
  assertEquals(1, files.length);
  assertEquals("1.txt", files[0].getName());
}
 
Example #12
Source File: GenerateSqlXmlIntention.java    From NutzCodeInsight with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile psiFile) throws IncorrectOperationException {
    PsiDirectory psiDirectory = psiFile.getContainingDirectory();
    WriteCommandAction.runWriteCommandAction(project, () -> {
        try {
            Properties properties = new Properties();
            properties.setProperty("CLASSNAME", clazz);
            PsiElement element = TemplateFileUtil.createFromTemplate(SqlTplFileTemplateGroupFactory.NUTZ_SQL_TPL_XML, templateFileName, properties, psiDirectory);
            NavigationUtil.activateFileWithPsiElement(element, true);
        } catch (Exception e) {
            HintManager.getInstance().showErrorHint(editor, "Failed: " + e.getLocalizedMessage());
        }
    });
}
 
Example #13
Source File: RelatedPopupGotoLineMarker.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public void navigate(MouseEvent e, PsiElement elt) {
    List<GotoRelatedItem>  items = this.items;
    if (items.size() == 1) {
        items.get(0).navigate();
    } else {
        NavigationUtil.getRelatedItemsPopup(items, "Go to Related Files").show(new RelativePoint(e));
    }

}
 
Example #14
Source File: HaxeTypeAddImportIntentionAction.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws IncorrectOperationException {
  if (candidates.size() > 1) {
    NavigationUtil.getPsiElementPopup(
      candidates.toArray(new PsiElement[candidates.size()]),
      new DefaultPsiElementCellRenderer(),
      HaxeBundle.message("choose.class.to.import.title"),
      new PsiElementProcessor<PsiElement>() {
        public boolean execute(@NotNull final PsiElement element) {
          CommandProcessor.getInstance().executeCommand(
            project,
            new Runnable() {
              public void run() {
                doImport(editor, element);
              }
            },
            getClass().getName(),
            this
          );
          return false;
        }
      }
    ).showInBestPositionFor(editor);
  }
  else {
    doImport(editor, candidates.iterator().next());
  }
}
 
Example #15
Source File: RelatedPopupGotoLineMarker.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
public void navigate(MouseEvent e, PsiElement elt) {
    List<GotoRelatedItem>  items = this.items;
    if (items.size() == 1) {
        items.get(0).navigate();
    } else {
        NavigationUtil.getRelatedItemsPopup(items, "Go to Related Files").show(new RelativePoint(e));
    }

}
 
Example #16
Source File: RelatedPopupGotoLineMarker.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
public void navigate(MouseEvent e, PsiElement elt) {
    Collection<GotoRelatedItem>  items = this.items;
    if (items.size() == 1) {
        items.iterator().next().navigate();
    } else {
        NavigationUtil.getRelatedItemsPopup(new ArrayList<>(items), "Go to Related Files").show(new RelativePoint(e));
    }
}
 
Example #17
Source File: IocBeanInterfaceNavigationHandler.java    From NutzCodeInsight with Apache License 2.0 5 votes vote down vote up
@Override
public void navigate(MouseEvent mouseEvent, PsiElement psiElement) {
    if (implListElements.size() == 1) {
        NavigationUtil.activateFileWithPsiElement(implListElements.get(0), true);
    } else {
        NavigationUtil.getPsiElementPopup(implListElements.toArray(new PsiElement[0]), MessageFormat.format("请选择 {0} 的实现类", name)).show(new RelativePoint(mouseEvent));
    }
}