Search in sources :

Example 1 with FindManager

use of com.intellij.find.FindManager in project intellij-community by JetBrains.

the class EscapeHandler method execute.

@Override
public void execute(Editor editor, DataContext dataContext) {
    editor.setHeaderComponent(null);
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    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);
}
Also used : Project(com.intellij.openapi.project.Project) FindManager(com.intellij.find.FindManager) FindModel(com.intellij.find.FindModel) StatusBar(com.intellij.openapi.wm.StatusBar)

Example 2 with FindManager

use of com.intellij.find.FindManager in project intellij-community by JetBrains.

the class FindInProjectManager method findInProject.

public void findInProject(@NotNull DataContext dataContext) {
    final boolean isOpenInNewTabEnabled;
    final boolean toOpenInNewTab;
    Content selectedContent = UsageViewManager.getInstance(myProject).getSelectedContent(true);
    if (selectedContent != null && selectedContent.isPinned()) {
        toOpenInNewTab = true;
        isOpenInNewTabEnabled = false;
    } else {
        toOpenInNewTab = FindSettings.getInstance().isShowResultsInSeparateView();
        isOpenInNewTabEnabled = UsageViewManager.getInstance(myProject).getReusableContentsCount() > 0;
    }
    final FindManager findManager = FindManager.getInstance(myProject);
    final FindModel findModel = findManager.getFindInProjectModel().clone();
    findModel.setReplaceState(false);
    findModel.setOpenInNewTabVisible(true);
    findModel.setOpenInNewTabEnabled(isOpenInNewTabEnabled);
    findModel.setOpenInNewTab(toOpenInNewTab);
    initModel(findModel, dataContext);
    findManager.showFindDialog(findModel, () -> {
        findModel.setOpenInNewTabVisible(false);
        if (isOpenInNewTabEnabled) {
            FindSettings.getInstance().setShowResultsInSeparateView(findModel.isOpenInNewTab());
        }
        startFindInProject(findModel);
        //todo check it in both cases: dialog & popup
        findModel.setOpenInNewTabVisible(false);
    });
}
Also used : FindManager(com.intellij.find.FindManager) FindModel(com.intellij.find.FindModel) Content(com.intellij.ui.content.Content)

Example 3 with FindManager

use of com.intellij.find.FindManager in project intellij-community by JetBrains.

the class SearchAgainAction method actionPerformed.

@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, () -> {
        PsiDocumentManager.getInstance(project).commitAllDocuments();
        IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
        FindManager findManager = FindManager.getInstance(project);
        if (!findManager.selectNextOccurrenceWasPerformed() && findManager.findNextUsageInEditor(editor)) {
            return;
        }
        FindUtil.searchAgain(project, editor, e.getDataContext());
    }, IdeBundle.message("command.find.next"), null);
}
Also used : Project(com.intellij.openapi.project.Project) FileEditor(com.intellij.openapi.fileEditor.FileEditor) FindManager(com.intellij.find.FindManager) CommandProcessor(com.intellij.openapi.command.CommandProcessor)

Example 4 with FindManager

use of com.intellij.find.FindManager in project intellij-community by JetBrains.

the class SearchResults method findInRange.

private void findInRange(TextRange r, Editor editor, FindModel findModel, ArrayList<FindResult> results) {
    VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(editor.getDocument());
    CharSequence charSequence = editor.getDocument().getCharsSequence();
    int offset = r.getStartOffset();
    int maxOffset = Math.min(r.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);
        } catch (PatternSyntaxException | ProcessCanceledException e) {
            result = null;
        }
        if (result == null || !result.isStringFound())
            break;
        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;
        }
        results.add(result);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FindManager(com.intellij.find.FindManager) FindResult(com.intellij.find.FindResult) PatternSyntaxException(java.util.regex.PatternSyntaxException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 5 with FindManager

use of com.intellij.find.FindManager in project android by JetBrains.

the class SearchInBuildFilesHyperlink method searchInBuildFiles.

public static void searchInBuildFiles(@NotNull String text, @NotNull final Project project) {
    FindManager findManager = FindManager.getInstance(project);
    UsageViewManager usageViewManager = UsageViewManager.getInstance(project);
    FindModel findModel = findManager.getFindInProjectModel().clone();
    findModel.setStringToFind(text);
    findModel.setReplaceState(false);
    findModel.setOpenInNewTabVisible(true);
    findModel.setOpenInNewTabEnabled(true);
    findModel.setOpenInNewTab(true);
    findModel.setFileFilter(SdkConstants.FN_BUILD_GRADLE);
    findManager.getFindInProjectModel().copyFrom(findModel);
    final FindModel findModelCopy = findModel.clone();
    UsageViewPresentation presentation = setupViewPresentation(findModel.isOpenInNewTabEnabled(), findModelCopy);
    boolean showPanelIfOnlyOneUsage = !FindSettings.getInstance().isSkipResultsWithOneUsage();
    final FindUsagesProcessPresentation processPresentation = setupProcessPresentation(project, showPanelIfOnlyOneUsage, presentation);
    UsageTarget usageTarget = new StringUsageTarget(project, findModel);
    usageViewManager.searchAndShowUsages(new UsageTarget[] { usageTarget }, new Factory<UsageSearcher>() {

        @Override
        public UsageSearcher create() {
            return new UsageSearcher() {

                @Override
                public void generate(@NotNull final Processor<Usage> processor) {
                    AdapterProcessor<UsageInfo, Usage> consumer = new AdapterProcessor<UsageInfo, Usage>(processor, UsageInfo2UsageAdapter.CONVERTER);
                    findUsages(findModelCopy, project, consumer, processPresentation);
                }
            };
        }
    }, processPresentation, presentation, null);
}
Also used : FindModel(com.intellij.find.FindModel) FindManager(com.intellij.find.FindManager) AdapterProcessor(com.intellij.util.AdapterProcessor) UsageInfo(com.intellij.usageView.UsageInfo)

Aggregations

FindManager (com.intellij.find.FindManager)11 FindModel (com.intellij.find.FindModel)8 Project (com.intellij.openapi.project.Project)6 StatusBar (com.intellij.openapi.wm.StatusBar)3 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)2 FindResult (com.intellij.find.FindResult)2 Application (com.intellij.openapi.application.Application)2 CommandProcessor (com.intellij.openapi.command.CommandProcessor)2 Editor (com.intellij.openapi.editor.Editor)2 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)2 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)2 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2 WindowManager (com.intellij.openapi.wm.WindowManager)2 PsiElement (com.intellij.psi.PsiElement)2 Content (com.intellij.ui.content.Content)2 UsageInfo (com.intellij.usageView.UsageInfo)2 FindSettings (com.intellij.find.FindSettings)1 FindInProjectUtil (com.intellij.find.impl.FindInProjectUtil)1