コード例 #1
0
  private void doShowDialogAndStartFind(
      @NotNull PsiElement psiElement,
      PsiFile scopeFile,
      FileEditor editor,
      boolean showDialog,
      boolean useMaximalScope) {
    FindUsagesHandler handler = getNewFindUsagesHandler(psiElement, false);
    if (handler == null) return;

    boolean singleFile = scopeFile != null;
    AbstractFindUsagesDialog dialog =
        handler.getFindUsagesDialog(singleFile, shouldOpenInNewTab(), mustOpenInNewTab());
    if (showDialog) {
      dialog.show();
      if (!dialog.isOK()) return;
    } else {
      dialog.close(DialogWrapper.OK_EXIT_CODE);
    }

    setOpenInNewTab(dialog.isShowInSeparateWindow());

    FindUsagesOptions findUsagesOptions = dialog.calcFindUsagesOptions();
    if (!showDialog && useMaximalScope) {
      findUsagesOptions.searchScope = getMaximalScope(handler);
    }

    clearFindingNextUsageInFile();
    LOG.assertTrue(handler.getPsiElement().isValid());
    PsiElement[] primaryElements = handler.getPrimaryElements();
    checkNotNull(primaryElements, handler, "getPrimaryElements()");
    PsiElement[] secondaryElements = handler.getSecondaryElements();
    checkNotNull(secondaryElements, handler, "getSecondaryElements()");
    UsageInfoToUsageConverter.TargetElementsDescriptor descriptor =
        new UsageInfoToUsageConverter.TargetElementsDescriptor(primaryElements, secondaryElements);
    if (singleFile) {
      findUsagesOptions = findUsagesOptions.clone();
      editor.putUserData(KEY_START_USAGE_AGAIN, null);
      findUsagesInEditor(
          descriptor, handler, scopeFile, FileSearchScope.FROM_START, findUsagesOptions, editor);
    } else {
      findUsages(
          descriptor,
          handler,
          dialog.isSkipResultsWhenOneUsage(),
          dialog.isShowInSeparateWindow(),
          findUsagesOptions);
    }
  }
コード例 #2
0
 @NotNull
 public UsageViewPresentation createPresentation(
     @NotNull FindUsagesHandler handler, @NotNull FindUsagesOptions findUsagesOptions) {
   PsiElement element = handler.getPsiElement();
   LOG.assertTrue(element.isValid());
   return createPresentation(element, findUsagesOptions, myToOpenInNewTab);
 }
コード例 #3
0
 @NotNull
 public static GlobalSearchScope getMaximalScope(@NotNull FindUsagesHandler handler) {
   PsiElement element = handler.getPsiElement();
   Project project = element.getProject();
   PsiFile file = element.getContainingFile();
   if (file != null
       && ProjectFileIndex.SERVICE
           .getInstance(project)
           .isInContent(file.getViewProvider().getVirtualFile())) {
     return GlobalSearchScope.projectScope(project);
   }
   return GlobalSearchScope.allScope(project);
 }
コード例 #4
0
  @NotNull
  public static ProgressIndicator startProcessUsages(
      @NotNull FindUsagesHandler handler,
      @NotNull final Processor<Usage> processor,
      @NotNull FindUsagesOptions findUsagesOptions,
      @NotNull final Runnable onComplete) {
    final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor =
        new UsageInfoToUsageConverter.TargetElementsDescriptor(
            handler.getPrimaryElements(), handler.getSecondaryElements());

    final UsageSearcher usageSearcher =
        createUsageSearcher(descriptor, handler, findUsagesOptions, null);

    final ProgressIndicatorBase indicator = new ProgressIndicatorBase();
    ApplicationManager.getApplication()
        .executeOnPooledThread(
            new Runnable() {
              @Override
              public void run() {
                try {
                  ProgressManager.getInstance()
                      .runProcess(
                          new Runnable() {
                            @Override
                            public void run() {
                              usageSearcher.generate(processor);
                            }
                          },
                          indicator);
                } finally {
                  onComplete.run();
                }
              }
            });

    return indicator;
  }
コード例 #5
0
  public void showSettingsAndFindUsages(@NotNull NavigationItem[] targets) {
    UsageTarget[] usageTargets = (UsageTarget[]) targets;
    PsiElement[] elements = getPsiElements(usageTargets);
    if (elements.length == 0) return;
    final FindUsagesHandler handler = getNewFindUsagesHandler(elements[0], false);

    if (handler == null) {
      return;
    }

    final AbstractFindUsagesDialog dialog =
        handler.getFindUsagesDialog(false, shouldOpenInNewTab(), mustOpenInNewTab());
    dialog.show();
    if (!dialog.isOK()) {
      return;
    }

    setOpenInNewTab(dialog.isShowInSeparateWindow());

    FindUsagesOptions findUsagesOptions = dialog.calcFindUsagesOptions();

    clearFindingNextUsageInFile();
    LOG.assertTrue(handler.getPsiElement().isValid());
    PsiElement[] primaryElements = handler.getPrimaryElements();
    checkNotNull(primaryElements, handler, "getPrimaryElements()");
    PsiElement[] secondaryElements = handler.getSecondaryElements();
    checkNotNull(secondaryElements, handler, "getSecondaryElements()");
    UsageInfoToUsageConverter.TargetElementsDescriptor descriptor =
        new UsageInfoToUsageConverter.TargetElementsDescriptor(primaryElements, secondaryElements);
    findUsages(
        descriptor,
        handler,
        dialog.isSkipResultsWhenOneUsage(),
        dialog.isShowInSeparateWindow(),
        findUsagesOptions);
  }