@NotNull
 private static FindUsagesOptions getDefaultOptions(@NotNull FindUsagesHandler handler) {
   FindUsagesOptions options =
       handler.getFindUsagesOptions(DataManager.getInstance().getDataContext());
   // by default, scope in FindUsagesOptions is copied from the FindSettings, but we need a default
   // one
   options.searchScope = FindUsagesManager.getMaximalScope(handler);
   return options;
 }
 private void searchEverywhere(
     @NotNull FindUsagesOptions options,
     @NotNull FindUsagesHandler handler,
     Editor editor,
     @NotNull RelativePoint popupPosition,
     int maxUsages) {
   FindUsagesOptions cloned = options.clone();
   cloned.searchScope = FindUsagesManager.getMaximalScope(handler);
   showElementUsages(handler, editor, popupPosition, maxUsages, cloned);
 }
  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);
    }
  }