Exemplo n.º 1
0
  private void updateResults(final boolean allowedToChangedEditorSelection) {
    final String text = myFindModel.getStringToFind();
    if (text.length() == 0) {
      nothingToSearchFor();
    } else {

      if (myFindModel.isRegularExpressions()) {
        try {
          Pattern.compile(text);
        } catch (Exception e) {
          setNotFoundBackground();
          myClickToHighlightLabel.setVisible(false);
          mySearchResults.clear();
          myMatchInfoLabel.setText("Incorrect regular expression");
          return;
        }
      }

      final FindManager findManager = FindManager.getInstance(myProject);
      if (allowedToChangedEditorSelection) {
        findManager.setFindWasPerformed();
        FindModel copy = new FindModel();
        copy.copyFrom(myFindModel);
        copy.setReplaceState(false);
        findManager.setFindNextModel(copy);
      }
      if (myLivePreviewController != null) {
        myLivePreviewController.updateInBackground(myFindModel, allowedToChangedEditorSelection);
      }
    }
  }
  private static int addToUsages(
      @NotNull Document document,
      @NotNull Processor<UsageInfo> consumer,
      @NotNull FindModel findModel,
      @NotNull final PsiFile psiFile,
      @NotNull int[] offsetRef,
      int maxUsages) {
    int count = 0;
    CharSequence text = document.getCharsSequence();
    int textLength = document.getTextLength();
    int offset = offsetRef[0];

    Project project = psiFile.getProject();

    FindManager findManager = FindManager.getInstance(project);
    while (offset < textLength) {
      FindResult result = findManager.findString(text, offset, findModel, psiFile.getVirtualFile());
      if (!result.isStringFound()) break;

      final SearchScope customScope = findModel.getCustomScope();
      if (customScope instanceof LocalSearchScope) {
        final TextRange range = new TextRange(result.getStartOffset(), result.getEndOffset());
        if (!((LocalSearchScope) customScope).containsRange(psiFile, range)) break;
      }
      UsageInfo info = new FindResultUsageInfo(findManager, psiFile, offset, findModel, result);
      if (!consumer.process(info)) {
        throw new ProcessCanceledException();
      }
      count++;

      final int prevOffset = offset;
      offset = result.getEndOffset();

      if (prevOffset == offset) {
        // for regular expr the size of the match could be zero -> could be infinite loop in finding
        // usages!
        ++offset;
      }
      if (maxUsages > 0 && count >= maxUsages) {
        break;
      }
    }
    offsetRef[0] = offset;
    return count;
  }
Exemplo n.º 3
0
 private static FindModel createDefaultFindModel(Project project, Editor editor) {
   FindModel findModel = new FindModel();
   findModel.copyFrom(FindManager.getInstance(project).getFindInFileModel());
   if (editor.getSelectionModel().hasSelection()) {
     String selectedText = editor.getSelectionModel().getSelectedText();
     if (selectedText != null) {
       findModel.setStringToFind(selectedText);
     }
   }
   findModel.setPromptOnReplace(false);
   return findModel;
 }
Exemplo n.º 4
0
 public void showHistory(final boolean byClickingToolbarButton, JTextComponent textField) {
   FeatureUsageTracker.getInstance().triggerFeatureUsed("find.recent.search");
   FindSettings settings = FindSettings.getInstance();
   String[] recent =
       textField == mySearchTextComponent
           ? settings.getRecentFindStrings()
           : settings.getRecentReplaceStrings();
   final boolean toShowAd =
       textField == mySearchTextComponent
           && textField.getText().isEmpty()
           && FindManager.getInstance(myProject).getPreviousFindModel() != null;
   Utils.showCompletionPopup(
       byClickingToolbarButton ? mySearchActionsToolbar1 : null,
       new JBList((Object[]) ArrayUtil.reverseArray(recent)),
       "Recent " + (textField == mySearchTextComponent ? "Searches" : "Replaces"),
       textField,
       toShowAd ? RestorePreviousSettingsAction.getAd() : null);
 }