com.intellij.find.FindManager Java Examples

The following examples show how to use com.intellij.find.FindManager. 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: FindAllAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent e) {
  Editor editor = e.getRequiredData(CommonDataKeys.EDITOR_EVEN_IF_INACTIVE);
  Project project = e.getRequiredData(CommonDataKeys.PROJECT);
  EditorSearchSession search = e.getRequiredData(EditorSearchSession.SESSION_KEY);

  if (project.isDisposed()) return;

  FindModel oldModel = FindManager.getInstance(project).getFindInFileModel();
  FindModel newModel = oldModel.clone();
  String text = search.getTextInField();
  if (StringUtil.isEmpty(text)) return;

  newModel.setStringToFind(text);
  FindUtil.findAllAndShow(project, editor, newModel);
}
 
Example #2
Source File: FindInProjectManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * @param model would be used for search if not null, otherwise shared (project-level) model would be used
 */
public void findInProject(@Nonnull DataContext dataContext, @Nullable FindModel model) {

  final FindManager findManager = FindManager.getInstance(myProject);
  final FindModel findModel;
  if (model != null) {
    findModel = model.clone();
  }
  else {
    findModel = findManager.getFindInProjectModel().clone();
    findModel.setReplaceState(false);
    initModel(findModel, dataContext);
  }

  findManager.showFindDialog(findModel, () -> {
    if (findModel.isReplaceState()) {
      ReplaceInProjectManager.getInstance(myProject).replaceInPath(findModel);
    }
    else {
      findInPath(findModel);
    }
  });
}
 
Example #3
Source File: SearchBackAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent e) {
  final Project project = e.getData(CommonDataKeys.PROJECT);
  final FileEditor editor = e.getData(PlatformDataKeys.FILE_EDITOR);
  CommandProcessor commandProcessor = CommandProcessor.getInstance();
  commandProcessor.executeCommand(
      project, new Runnable() {
      @Override
      public void run() {
        PsiDocumentManager.getInstance(project).commitAllDocuments();
        if(FindManager.getInstance(project).findPreviousUsageInEditor(editor)) {
          return;
        }
        FindUtil.searchBack(project, editor, e.getDataContext());
      }
    },
    IdeBundle.message("command.find.previous"),
    null
  );
}
 
Example #4
Source File: SearchAgainAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent e) {
  final Project project = e.getData(CommonDataKeys.PROJECT);
  final FileEditor editor = e.getData(PlatformDataKeys.FILE_EDITOR);
  if (editor == null || project == null) return;
  CommandProcessor commandProcessor = CommandProcessor.getInstance();
  commandProcessor.executeCommand(
      project, new Runnable() {
      @Override
      public void run() {
        PsiDocumentManager.getInstance(project).commitAllDocuments();
        IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
        if(FindManager.getInstance(project).findNextUsageInEditor(editor)) {
          return;
        }

        FindUtil.searchAgain(project, editor, e.getDataContext());
      }
    },
    IdeBundle.message("command.find.next"),
    null
  );
}
 
Example #5
Source File: FindResultUsageInfo.java    From consulo with Apache License 2.0 6 votes vote down vote up
public FindResultUsageInfo(@Nonnull FindManager finder, @Nonnull PsiFile file, int offset, @Nonnull FindModel findModel, @Nonnull FindResult result) {
  super(file, result.getStartOffset(), result.getEndOffset());

  myFindManager = finder;
  myFindModel = findModel;

  assert result.isStringFound();

  if (myFindModel.isRegularExpressions() ||
      myFindModel.isInCommentsOnly() ||
      myFindModel.isInStringLiteralsOnly() ||
      myFindModel.isExceptStringLiterals() ||
      myFindModel.isExceptCommentsAndStringLiterals() ||
      myFindModel.isExceptComments()
          ) {
    myAnchor = SmartPointerManager.getInstance(getProject()).createSmartPsiFileRangePointer(file, TextRange.from(offset, 0));
  }

}
 
Example #6
Source File: LivePreview.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showReplacementPreview() {
  hideBalloon();
  if (!mySearchResults.isUpToDate()) return;
  final FindResult cursor = mySearchResults.getCursor();
  final Editor editor = mySearchResults.getEditor();
  final FindModel findModel = mySearchResults.getFindModel();
  if (myDelegate != null && cursor != null && findModel.isReplaceState() && findModel.isRegularExpressions()) {
    String replacementPreviewText;
    try {
      replacementPreviewText = myDelegate.getStringToReplace(editor, cursor);
    }
    catch (FindManager.MalformedReplacementStringException e) {
      return;
    }
    if (replacementPreviewText == null) {
      return;//malformed replacement string
    }
    if (Registry.is("ide.find.show.replacement.hint.for.simple.regexp")) {
      showBalloon(editor, replacementPreviewText.isEmpty() ? EMPTY_STRING_DISPLAY_TEXT : replacementPreviewText);
    }
    else if (!replacementPreviewText.equals(findModel.getStringToReplace())) {
      showBalloon(editor, replacementPreviewText);
    }
  }
}
 
Example #7
Source File: PsiElement2UsageTargetAdapter.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void highlightUsages(@Nonnull PsiFile file, @Nonnull Editor editor, boolean clearHighlights) {
  PsiElement target = getElement();

  if (file instanceof PsiCompiledFile) file = ((PsiCompiledFile)file).getDecompiledPsiFile();

  Project project = target.getProject();
  final FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(project)).getFindUsagesManager();
  final FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(target, true);

  // in case of injected file, use host file to highlight all occurrences of the target in each injected file
  PsiFile context = InjectedLanguageManager.getInstance(project).getTopLevelFile(file);
  SearchScope searchScope = new LocalSearchScope(context);
  Collection<PsiReference> refs = handler == null ? ReferencesSearch.search(target, searchScope, false).findAll() : handler.findReferencesToHighlight(target, searchScope);

  new HighlightUsagesHandler.DoHighlightRunnable(new ArrayList<>(refs), project, target, editor, context, clearHighlights).run();
}
 
Example #8
Source File: DefaultUsageTargetProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public UsageTarget[] getTargets(PsiElement psiElement) {
  if (psiElement instanceof NavigationItem) {
    if (FindManager.getInstance(psiElement.getProject()).canFindUsages(psiElement)) {
      return new UsageTarget[]{new PsiElement2UsageTargetAdapter(psiElement)};
    }
  }
  return null;
}
 
Example #9
Source File: FindInProjectManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void startFindInProject(@Nonnull FindModel findModel) {
  if (findModel.getDirectoryName() != null && FindInProjectUtil.getDirectory(findModel) == null) {
    return;
  }

  UsageViewManager manager = UsageViewManager.getInstance(myProject);

  if (manager == null) return;
  final FindManager findManager = FindManager.getInstance(myProject);
  findManager.getFindInProjectModel().copyFrom(findModel);
  final FindModel findModelCopy = findModel.clone();
  final UsageViewPresentation presentation = FindInProjectUtil.setupViewPresentation(findModelCopy);
  final FindUsagesProcessPresentation processPresentation = FindInProjectUtil.setupProcessPresentation(myProject, presentation);
  ConfigurableUsageTarget usageTarget = new FindInProjectUtil.StringUsageTarget(myProject, findModel);

  ((FindManagerImpl)FindManager.getInstance(myProject)).getFindUsagesManager().addToHistory(usageTarget);

  manager.searchAndShowUsages(new UsageTarget[]{usageTarget}, () -> processor -> {
    myIsFindInProgress = true;

    try {
      Processor<UsageInfo> consumer = info -> {
        Usage usage = UsageInfo2UsageAdapter.CONVERTER.fun(info);
        usage.getPresentation().getIcon(); // cache icon
        return processor.process(usage);
      };
      FindInProjectUtil.findUsages(findModelCopy, myProject, consumer, processPresentation);
    }
    finally {
      myIsFindInProgress = false;
    }
  }, processPresentation, presentation, null);
}
 
Example #10
Source File: Unity3dAssetEditorNotificationProvider.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@Nonnull VirtualFile file, @Nonnull FileEditor fileEditor)
{
	if(file.getFileType() != Unity3dYMLAssetFileType.INSTANCE || !ArrayUtil.contains(file.getExtension(), Unity3dAssetFileTypeDetector.ourAssetExtensions))
	{
		return null;
	}
	final String uuid = Unity3dAssetUtil.getGUID(myProject, file);
	if(uuid == null)
	{
		return null;
	}
	MultiMap<VirtualFile, Unity3dYMLAsset> map = Unity3dYMLAsset.findAssetAsAttach(myProject, file);
	if(map.isEmpty())
	{
		return null;
	}

	PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
	if(psiFile == null)
	{
		return null;
	}

	final EditorNotificationPanel panel = new EditorNotificationPanel();
	panel.text("Used asset...");
	panel.createActionLabel("Find usages...", () -> FindManager.getInstance(myProject).findUsages(psiFile));
	return panel;
}
 
Example #11
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private ActiveComponent createPinButton(@Nonnull final FindUsagesHandler handler,
                                        @Nonnull final UsageViewImpl usageView,
                                        @Nonnull final FindUsagesOptions options,
                                        @Nonnull final JBPopup[] popup,
                                        @Nonnull DefaultActionGroup pinGroup) {
  final AnAction pinAction = new AnAction("Open Find Usages Toolwindow", "Show all usages in a separate toolwindow", AllIcons.General.AutohideOff) {
    {
      AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_USAGES);
      setShortcutSet(action.getShortcutSet());
    }

    @Override
    public boolean startInTransaction() {
      return true;
    }

    @Override
    public void actionPerformed(@Nonnull AnActionEvent e) {
      hideHints();
      cancel(popup[0]);
      FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(usageView.getProject())).getFindUsagesManager();
      findUsagesManager.findUsages(handler.getPrimaryElements(), handler.getSecondaryElements(), handler, options,
                                   FindSettings.getInstance().isSkipResultsWithOneUsage());
    }
  };
  pinGroup.add(pinAction);
  final ActionToolbar pinToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.USAGE_VIEW_TOOLBAR, pinGroup, true);
  pinToolbar.setReservePlaceAutoPopupIcon(false);
  final JComponent pinToolBar = pinToolbar.getComponent();
  pinToolBar.setBorder(null);
  pinToolBar.setOpaque(false);

  return new ActiveComponent.Adapter() {
    @Override
    public JComponent getComponent() {
      return pinToolBar;
    }
  };
}
 
Example #12
Source File: PsiElement2UsageTargetAdapter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void showSettings() {
  PsiElement element = getElement();
  if (element != null) {
    FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(myPointer.getProject())).getFindUsagesManager();
    findUsagesManager.findUsages(element, null, null, true, null);
  }
}
 
Example #13
Source File: PsiElement2UsageTargetComposite.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void findUsages() {
  PsiElement element = getElement();
  if (element == null) return;
  FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(element.getProject())).getFindUsagesManager();
  FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(element, false);
  boolean skipResultsWithOneUsage = FindSettings.getInstance().isSkipResultsWithOneUsage();
  findUsagesManager.findUsages(myDescriptor.getPrimaryElements(), myDescriptor.getAdditionalElements(), handler, myOptions, skipResultsWithOneUsage);
}
 
Example #14
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void startFindUsages(@Nonnull PsiElement element, @Nonnull RelativePoint popupPosition, Editor editor, int maxUsages) {
  Project project = element.getProject();
  FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(project)).getFindUsagesManager();
  FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(element, false);
  if (handler == null) return;
  if (myShowSettingsDialogBefore) {
    showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
    return;
  }
  showElementUsages(editor, popupPosition, handler, maxUsages, handler.getFindUsagesOptions(DataManager.getInstance().getDataContext()));
}
 
Example #15
Source File: SearchResults.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updatePreviousFindModel(@Nonnull FindModel model) {
  FindModel prev = FindManager.getInstance(getProject()).getPreviousFindModel();
  if (prev == null) {
    prev = new FindModel();
  }
  if (!model.getStringToFind().isEmpty()) {
    prev.copyFrom(model);
    FindManager.getInstance(getProject()).setPreviousFindModel(prev);
  }
}
 
Example #16
Source File: SearchResults.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void findInRange(@Nonnull TextRange range, @Nonnull Editor editor, @Nonnull FindModel findModel, @Nonnull List<? super FindResult> results) {
  VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(editor.getDocument());

  // Document can change even while we're holding read lock (example case - console), so we're taking an immutable snapshot of text here
  CharSequence charSequence = editor.getDocument().getImmutableCharSequence();

  int offset = range.getStartOffset();
  int maxOffset = Math.min(range.getEndOffset(), charSequence.length());
  FindManager findManager = FindManager.getInstance(getProject());

  while (true) {
    FindResult result;
    try {
      CharSequence bombedCharSequence = StringUtil.newBombedCharSequence(charSequence, 3000);
      result = findManager.findString(bombedCharSequence, offset, findModel, virtualFile);
      ((StringUtil.BombedCharSequence)bombedCharSequence).defuse();
    }
    catch (PatternSyntaxException | ProcessCanceledException e) {
      result = null;
    }
    if (result == null || !result.isStringFound()) break;
    final int newOffset = result.getEndOffset();
    if (result.getEndOffset() > maxOffset) break;
    if (offset == newOffset) {
      if (offset < maxOffset - 1) {
        offset++;
      }
      else {
        results.add(result);
        break;
      }
    }
    else {
      offset = newOffset;
      if (offset == result.getStartOffset()) ++offset; // skip zero width result
    }
    results.add(result);
  }
}
 
Example #17
Source File: OttoProjectHandler.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
protected OttoProjectHandler(Project project, PsiManager psiManager) {
  super(project);
  this.findUsagesManager =
      ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
  this.psiManager = psiManager;
  project.putUserData(KEY, this);
  //System.out.println("OttoProjectHandler initialized");
}
 
Example #18
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
void startFindUsages(@NotNull PsiElement element, @NotNull RelativePoint popupPosition, Editor editor, int maxUsages) {
  Project project = element.getProject();
  FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(project)).getFindUsagesManager();
  FindUsagesHandler handler = findUsagesManager.getNewFindUsagesHandler(element, false);
  if (handler == null) return;
  if (showSettingsDialogBefore) {
    showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
    return;
  }
  showElementUsages(handler, editor, popupPosition, maxUsages, getDefaultOptions(handler));
}
 
Example #19
Source File: RestorePreviousSettingsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  Project project = e.getProject();
  EditorSearchSession search = e.getData(EditorSearchSession.SESSION_KEY);
  e.getPresentation().setEnabled(project != null && search != null && !project.isDisposed() &&
                                 search.getTextInField().isEmpty() &&
                                 FindManager.getInstance(project).getPreviousFindModel() != null);
}
 
Example #20
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
public void startFindUsages(@NotNull PsiElement element, @NotNull RelativePoint popupPosition,
    Editor editor, int maxUsages) {
  Project project = element.getProject();
  FindUsagesManager findUsagesManager =
      ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
  FindUsagesHandler handler = findUsagesManager.getNewFindUsagesHandler(element, false);
  if (handler == null) return;
  if (showSettingsDialogBefore) {
    showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
    return;
  }
  showElementUsages(handler, editor, popupPosition, maxUsages, getDefaultOptions(handler));
}
 
Example #21
Source File: SearchForUsagesRunnable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private HyperlinkListener createGotToOptionsListener(@Nonnull final UsageTarget[] targets) {
  return new HyperlinkAdapter() {
    @Override
    protected void hyperlinkActivated(HyperlinkEvent e) {
      if (e.getDescription().equals(FIND_OPTIONS_HREF_TARGET)) {
        TransactionGuard.getInstance().submitTransactionAndWait(() -> FindManager.getInstance(myProject).showSettingsAndFindUsages(targets));
      }
    }
  };
}
 
Example #22
Source File: SearchForUsagesRunnable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private HyperlinkListener createSearchInProjectListener() {
  return new HyperlinkAdapter() {
    @Override
    protected void hyperlinkActivated(HyperlinkEvent e) {
      if (e.getDescription().equals(SEARCH_IN_PROJECT_HREF_TARGET)) {
        PsiElement psiElement = getPsiElement(mySearchFor);
        if (psiElement != null) {
          TransactionGuard.getInstance().submitTransactionAndWait(
                  () -> FindManager.getInstance(myProject).findUsagesInScope(psiElement, GlobalSearchScope.projectScope(myProject)));
        }
      }
    }
  };
}
 
Example #23
Source File: UsagePreviewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void showBalloon(Project project, Editor editor, TextRange range, @Nonnull FindModel findModel) {
  try {
    String replacementPreviewText = FindManager.getInstance(project).getStringToReplace(editor.getDocument().getText(range), findModel, range.getStartOffset(), editor.getDocument().getText());
    if (!Registry.is("ide.find.show.replacement.hint.for.simple.regexp") && (Comparing.equal(replacementPreviewText, findModel.getStringToReplace()))) {
      return;
    }
    ReplacementView replacementView = new ReplacementView(replacementPreviewText);

    BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createBalloonBuilder(replacementView);
    balloonBuilder.setFadeoutTime(0);
    balloonBuilder.setFillColor(IdeTooltipManager.GRAPHITE_COLOR);
    balloonBuilder.setAnimationCycle(0);
    balloonBuilder.setHideOnClickOutside(false);
    balloonBuilder.setHideOnKeyOutside(false);
    balloonBuilder.setHideOnAction(false);
    balloonBuilder.setCloseButtonEnabled(true);
    Balloon balloon = balloonBuilder.createBalloon();
    EditorUtil.disposeWithEditor(editor, balloon);

    balloon.show(new ReplacementBalloonPositionTracker(project, editor, range, findModel), Balloon.Position.below);
    editor.putUserData(REPLACEMENT_BALLOON_KEY, balloon);

  }
  catch (FindManager.MalformedReplacementStringException e) {
    //Not a problem, just don't show balloon in this case
  }
}
 
Example #24
Source File: HighlightHandlerBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void setupFindModel(final Project project) {
  final FindManager findManager = FindManager.getInstance(project);
  FindModel model = findManager.getFindNextModel();
  if (model == null) {
    model = findManager.getFindInFileModel();
  }
  model.setSearchHighlighters(true);
  findManager.setFindWasPerformed();
  findManager.setFindNextModel(model);
}
 
Example #25
Source File: EscapeHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Editor editor, DataContext dataContext){
  editor.setHeaderComponent(null);

  Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project != null) {
    HighlightManagerImpl highlightManager = (HighlightManagerImpl)HighlightManager.getInstance(project);
    if (highlightManager != null && highlightManager.hideHighlights(editor, HighlightManager.HIDE_BY_ESCAPE | HighlightManager.HIDE_BY_ANY_KEY)) {

      StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
      if (statusBar != null) {
        statusBar.setInfo("");
      }

      FindManager findManager = FindManager.getInstance(project);
      if (findManager != null) {
        FindModel model = findManager.getFindNextModel(editor);
        if (model != null) {
          model.setSearchHighlighters(false);
          findManager.setFindNextModel(model);
        }
      }

      return;
    }
  }

  myOriginalHandler.execute(editor, dataContext);
}
 
Example #26
Source File: IdentifierHighlighterPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Couple<Collection<TextRange>> getUsages(@Nonnull PsiElement target, PsiElement psiElement, boolean withDeclarations, boolean detectAccess) {
  List<TextRange> readRanges = new ArrayList<>();
  List<TextRange> writeRanges = new ArrayList<>();
  final ReadWriteAccessDetector detector = detectAccess ? ReadWriteAccessDetector.findDetector(target) : null;
  final FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(target.getProject())).getFindUsagesManager();
  final FindUsagesHandler findUsagesHandler = findUsagesManager.getFindUsagesHandler(target, true);
  final LocalSearchScope scope = new LocalSearchScope(psiElement);
  Collection<PsiReference> refs = findUsagesHandler != null
                                  ? findUsagesHandler.findReferencesToHighlight(target, scope)
                                  : ReferencesSearch.search(target, scope).findAll();
  for (PsiReference psiReference : refs) {
    if (psiReference == null) {
      LOG.error("Null reference returned, findUsagesHandler=" + findUsagesHandler + "; target=" + target + " of " + target.getClass());
      continue;
    }
    List<TextRange> destination;
    if (detector == null || detector.getReferenceAccess(target, psiReference) == ReadWriteAccessDetector.Access.Read) {
      destination = readRanges;
    }
    else {
      destination = writeRanges;
    }
    HighlightUsagesHandler.collectRangesToHighlight(psiReference, destination);
  }

  if (withDeclarations) {
    final TextRange declRange = HighlightUsagesHandler.getNameIdentifierRange(psiElement.getContainingFile(), target);
    if (declRange != null) {
      if (detector != null && detector.isDeclarationWriteAccess(target)) {
        writeRanges.add(declRange);
      }
      else {
        readRanges.add(declRange);
      }
    }
  }

  return Couple.<Collection<TextRange>>of(readRanges, writeRanges);
}
 
Example #27
Source File: IncrementalFindAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(final Editor editor, DataContext dataContext) {
  final Project project = DataManager.getInstance().getDataContext(editor.getComponent()).getData(CommonDataKeys.PROJECT);
  if (!editor.isOneLineMode()) {
    EditorSearchSession search = EditorSearchSession.get(editor);
    if (search != null) {
      search.getComponent().requestFocusInTheSearchFieldAndSelectContent(project);
      FindUtil.configureFindModel(myReplace, editor, search.getFindModel(), false);
    } else {
      FindManager findManager = FindManager.getInstance(project);
      FindModel model;
      if (myReplace) {
        model = findManager.createReplaceInFileModel();
      } else {
        model = new FindModel();
        model.copyFrom(findManager.getFindInFileModel());
      }
      boolean consoleViewEditor = ConsoleViewUtil.isConsoleViewEditor(editor);
      FindUtil.configureFindModel(myReplace, editor, model, consoleViewEditor);
      EditorSearchSession.start(editor, model, project).getComponent()
              .requestFocusInTheSearchFieldAndSelectContent(project);
      if (!consoleViewEditor && editor.getSelectionModel().hasSelection()) {
        // selection is used as string to find without search model modification so save the pattern explicitly
        FindUtil.updateFindInFileModel(project, model, true);
      }
    }
  }
}
 
Example #28
Source File: SelectAllOccurrencesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void doExecute(Editor editor, @Nullable Caret c, DataContext dataContext) {
  Caret caret = c == null ? editor.getCaretModel().getPrimaryCaret() : c;

  if (!caret.hasSelection()) {
    TextRange wordSelectionRange = getSelectionRange(editor, caret);
    if (wordSelectionRange != null) {
      setSelection(editor, caret, wordSelectionRange);
    }
  }

  String selectedText = caret.getSelectedText();
  Project project = editor.getProject();
  if (project == null || selectedText == null) {
    return;
  }

  int caretShiftFromSelectionStart = caret.getOffset() - caret.getSelectionStart();
  FindManager findManager = FindManager.getInstance(project);

  FindModel model = new FindModel();
  model.setStringToFind(selectedText);
  model.setCaseSensitive(true);
  model.setWholeWordsOnly(true);

  int searchStartOffset = 0;
  FindResult findResult = findManager.findString(editor.getDocument().getCharsSequence(), searchStartOffset, model);
  while (findResult.isStringFound()) {
    int newCaretOffset = caretShiftFromSelectionStart + findResult.getStartOffset();
    EditorActionUtil.makePositionVisible(editor, newCaretOffset);
    Caret newCaret = editor.getCaretModel().addCaret(editor.offsetToVisualPosition(newCaretOffset));
    if (newCaret != null) {
      setSelection(editor, newCaret, findResult);
    }
    findResult = findManager.findString(editor.getDocument().getCharsSequence(), findResult.getEndOffset(), model);
  }
  editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
}
 
Example #29
Source File: ReplacePromptDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ReplacePromptDialog(boolean isMultipleFiles, String title, Project project, @Nullable FindManager.MalformedReplacementStringException exception) {
  super(project, true);
  myIsMultiple = isMultipleFiles;
  myException = exception;
  setButtonsAlignment(SwingConstants.CENTER);
  setTitle(title);
  init();
}
 
Example #30
Source File: ReplacePromptDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
protected Action[] createActions(){
  DoAction replaceAction = new DoAction(UIBundle.message("replace.prompt.replace.button"), FindManager.PromptResult.OK);
  replaceAction.putValue(DEFAULT_ACTION,Boolean.TRUE);
  if (myException == null) {
    if (myIsMultiple){
      return new Action[]{
        replaceAction,
        createSkipAction(),
        new DoAction(UIBundle.message("replace.prompt.all.in.this.file.button"), FindManager.PromptResult.ALL_IN_THIS_FILE),
        new DoAction(UIBundle.message("replace.prompt.all.files.action"), FindManager.PromptResult.ALL_FILES),
        getCancelAction()
      };
    }
    else {
      return new Action[]{
        replaceAction,
        createSkipAction(),
        new DoAction(UIBundle.message("replace.prompt.all.button"), FindManager.PromptResult.ALL),
        getCancelAction()
      };
    }
  } else {
    return new Action[] {
      createSkipAction(),
      getCancelAction()
    };
  }
}