Search in sources :

Example 6 with FindManager

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

the class HighlightUtil method highlightElements.

public static void highlightElements(@NotNull final Collection<? extends PsiElement> elementCollection, @NotNull final String statusBarText) {
    if (elementCollection.isEmpty()) {
        return;
    }
    final Application application = ApplicationManager.getApplication();
    application.invokeLater(() -> {
        final PsiElement[] elements = PsiUtilCore.toPsiElementArray(elementCollection);
        final PsiElement firstElement = elements[0];
        if (!firstElement.isValid()) {
            return;
        }
        final Project project = firstElement.getProject();
        final FileEditorManager editorManager = FileEditorManager.getInstance(project);
        final EditorColorsManager editorColorsManager = EditorColorsManager.getInstance();
        final Editor editor = editorManager.getSelectedTextEditor();
        if (editor == null) {
            return;
        }
        final EditorColorsScheme globalScheme = editorColorsManager.getGlobalScheme();
        final TextAttributes textattributes = globalScheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
        final HighlightManager highlightManager = HighlightManager.getInstance(project);
        highlightManager.addOccurrenceHighlights(editor, elements, textattributes, true, null);
        final FindManager findmanager = FindManager.getInstance(project);
        FindModel findmodel = findmanager.getFindNextModel();
        if (findmodel == null) {
            findmodel = findmanager.getFindInFileModel();
        }
        findmodel.setSearchHighlighters(true);
        findmanager.setFindWasPerformed();
        findmanager.setFindNextModel(findmodel);
        application.invokeLater(() -> {
            final WindowManager windowManager = WindowManager.getInstance();
            final StatusBar statusBar = windowManager.getStatusBar(project);
            if (statusBar != null) {
                statusBar.setInfo(statusBarText);
            }
        });
    });
}
Also used : FindModel(com.intellij.find.FindModel) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) StatusBar(com.intellij.openapi.wm.StatusBar) WindowManager(com.intellij.openapi.wm.WindowManager) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FindManager(com.intellij.find.FindManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Editor(com.intellij.openapi.editor.Editor) Application(com.intellij.openapi.application.Application) PsiElement(com.intellij.psi.PsiElement)

Example 7 with FindManager

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

the class HighlightUtils method highlightElements.

public static void highlightElements(@NotNull final Collection<? extends PsiElement> elementCollection) {
    if (elementCollection.isEmpty()) {
        return;
    }
    if (elementCollection.contains(null)) {
        throw new IllegalArgumentException("Nulls passed in collection: " + elementCollection);
    }
    final Application application = ApplicationManager.getApplication();
    application.invokeLater(() -> {
        final PsiElement[] elements = PsiUtilCore.toPsiElementArray(elementCollection);
        final PsiElement firstElement = elements[0];
        if (ContainerUtil.exists(elements, element -> !element.isValid())) {
            return;
        }
        final Project project = firstElement.getProject();
        if (project.isDisposed())
            return;
        final FileEditorManager editorManager = FileEditorManager.getInstance(project);
        final EditorColorsManager editorColorsManager = EditorColorsManager.getInstance();
        final Editor editor = editorManager.getSelectedTextEditor();
        if (editor == null) {
            return;
        }
        final EditorColorsScheme globalScheme = editorColorsManager.getGlobalScheme();
        final TextAttributes textattributes = globalScheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
        final HighlightManager highlightManager = HighlightManager.getInstance(project);
        highlightManager.addOccurrenceHighlights(editor, elements, textattributes, true, null);
        final WindowManager windowManager = WindowManager.getInstance();
        final StatusBar statusBar = windowManager.getStatusBar(project);
        statusBar.setInfo(InspectionGadgetsBundle.message("press.escape.to.remove.highlighting.message"));
        final FindManager findmanager = FindManager.getInstance(project);
        FindModel findmodel = findmanager.getFindNextModel();
        if (findmodel == null) {
            findmodel = findmanager.getFindInFileModel();
        }
        findmodel.setSearchHighlighters(true);
        findmanager.setFindWasPerformed();
        findmanager.setFindNextModel(findmodel);
    });
}
Also used : FindModel(com.intellij.find.FindModel) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) StatusBar(com.intellij.openapi.wm.StatusBar) WindowManager(com.intellij.openapi.wm.WindowManager) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FindManager(com.intellij.find.FindManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Editor(com.intellij.openapi.editor.Editor) Application(com.intellij.openapi.application.Application) PsiElement(com.intellij.psi.PsiElement)

Example 8 with FindManager

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

the class SearchBackAction method actionPerformed.

@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, () -> {
        PsiDocumentManager.getInstance(project).commitAllDocuments();
        FindManager findManager = FindManager.getInstance(project);
        if (!findManager.selectNextOccurrenceWasPerformed() && findManager.findPreviousUsageInEditor(editor)) {
            return;
        }
        FindUtil.searchBack(project, editor, e.getDataContext());
    }, IdeBundle.message("command.find.previous"), 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 9 with FindManager

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

the class ExpressionOccurrenceManager method findExpressionOccurrences.

public PsiExpression[] findExpressionOccurrences() {
    if (myMainOccurence instanceof PsiLiteralExpression && !myMainOccurence.isPhysical()) {
        final FindManager findManager = FindManager.getInstance(getScope().getProject());
        final FindModel findModel = (FindModel) findManager.getFindInFileModel().clone();
        findModel.setCaseSensitive(true);
        findModel.setRegularExpressions(false);
        String value = StringUtil.stripQuotesAroundValue(myMainOccurence.getText());
        if (value.length() > 0) {
            findModel.setStringToFind(value);
            final List<PsiExpression> results = new ArrayList<>();
            final PsiFile file = getScope().getContainingFile();
            final String text = getScope().getText();
            final int offset = getScope().getTextRange().getStartOffset();
            FindResult result = findManager.findString(text, 0, findModel);
            final Set<PsiLiteralExpression> literals = new HashSet<>();
            while (result.isStringFound()) {
                final int startOffset = offset + result.getStartOffset();
                final int endOffset = result.getEndOffset();
                final PsiLiteralExpression literalExpression = PsiTreeUtil.getParentOfType(file.findElementAt(startOffset), PsiLiteralExpression.class);
                if (literalExpression != null && !literals.contains(literalExpression)) {
                    //enum. occurrences inside string literals
                    final PsiExpression expression = IntroduceVariableBase.getSelectedExpression(file.getProject(), file, startOffset, offset + endOffset);
                    if (expression != null && IntroduceVariableBase.getErrorMessage(expression) == null) {
                        results.add(expression);
                        literals.add(literalExpression);
                    }
                }
                result = findManager.findString(text, endOffset, findModel);
            }
            return results.toArray(new PsiExpression[results.size()]);
        }
    }
    return CodeInsightUtil.findExpressionOccurrences(myScope, myMainOccurence);
}
Also used : FindManager(com.intellij.find.FindManager) FindModel(com.intellij.find.FindModel) FindResult(com.intellij.find.FindResult)

Example 10 with FindManager

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

the class FindInProjectManager method startFindInProject.

public void startFindInProject(@NotNull FindModel findModel) {
    if (findModel.getDirectoryName() != null && FindInProjectUtil.getDirectory(findModel) == null) {
        return;
    }
    com.intellij.usages.UsageViewManager manager = com.intellij.usages.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(FindSettings.getInstance().isShowResultsInSeparateView(), findModelCopy);
    final boolean showPanelIfOnlyOneUsage = !FindSettings.getInstance().isSkipResultsWithOneUsage();
    final FindUsagesProcessPresentation processPresentation = FindInProjectUtil.setupProcessPresentation(myProject, showPanelIfOnlyOneUsage, 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();
                return processor.process(usage);
            };
            FindInProjectUtil.findUsages(findModelCopy, myProject, consumer, processPresentation);
        } finally {
            myIsFindInProgress = false;
        }
    }, processPresentation, presentation, null);
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) FindManagerImpl(com.intellij.find.impl.FindManagerImpl) com.intellij.usages(com.intellij.usages) Content(com.intellij.ui.content.Content) UsageInfo(com.intellij.usageView.UsageInfo) FindInProjectUtil(com.intellij.find.impl.FindInProjectUtil) FindManager(com.intellij.find.FindManager) ReplaceInProjectManager(com.intellij.find.replaceInProject.ReplaceInProjectManager) PlatformDataKeys(com.intellij.openapi.actionSystem.PlatformDataKeys) ServiceManager(com.intellij.openapi.components.ServiceManager) Processor(com.intellij.util.Processor) FindModel(com.intellij.find.FindModel) Project(com.intellij.openapi.project.Project) FindSettings(com.intellij.find.FindSettings) NotNull(org.jetbrains.annotations.NotNull) UsageViewManager(com.intellij.usageView.UsageViewManager) FindModel(com.intellij.find.FindModel) FindManager(com.intellij.find.FindManager) com.intellij.usages(com.intellij.usages) 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