Search in sources :

Example 26 with FindModel

use of com.intellij.find.FindModel 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 27 with FindModel

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

the class UsageViewManagerTest method testScopeCreatedForFindInModuleContent.

public void testScopeCreatedForFindInModuleContent() {
    FindModel findModel = new FindModel();
    findModel.setModuleName(getModule().getName());
    findModel.setProjectScope(false);
    UsageTarget target = new FindInProjectUtil.StringUsageTarget(getProject(), findModel);
    UsageViewManagerImpl manager = (UsageViewManagerImpl) UsageViewManager.getInstance(getProject());
    SearchScope scope = manager.getMaxSearchScopeToWarnOfFallingOutOf(new UsageTarget[] { target });
    assertEquals(scope, getModule().getModuleContentScope());
}
Also used : FindModel(com.intellij.find.FindModel) SearchScope(com.intellij.psi.search.SearchScope) UsageTarget(com.intellij.usages.UsageTarget)

Example 28 with FindModel

use of com.intellij.find.FindModel 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 29 with FindModel

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

the class TodoPanel method initUI.

private void initUI() {
    UIUtil.setLineStyleAngled(myTree);
    myTree.setShowsRootHandles(true);
    myTree.setRootVisible(false);
    myTree.setCellRenderer(new TodoCompositeRenderer());
    EditSourceOnDoubleClickHandler.install(myTree);
    new TreeSpeedSearch(myTree);
    DefaultActionGroup group = new DefaultActionGroup();
    group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE));
    group.addSeparator();
    group.add(ActionManager.getInstance().getAction(IdeActions.GROUP_VERSION_CONTROLS));
    PopupHandler.installPopupHandler(myTree, group, ActionPlaces.TODO_VIEW_POPUP, ActionManager.getInstance());
    myTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (!e.isConsumed() && KeyEvent.VK_ENTER == e.getKeyCode()) {
                TreePath path = myTree.getSelectionPath();
                if (path == null) {
                    return;
                }
                final Object userObject = ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject();
                if (!((userObject instanceof NodeDescriptor ? (NodeDescriptor) userObject : null) instanceof TodoItemNode)) {
                    return;
                }
                OpenSourceUtil.openSourcesFrom(DataManager.getInstance().getDataContext(TodoPanel.this), false);
            }
        }
    });
    myUsagePreviewPanel = new UsagePreviewPanel(myProject, FindInProjectUtil.setupViewPresentation(false, new FindModel()));
    Disposer.register(this, myUsagePreviewPanel);
    myUsagePreviewPanel.setVisible(mySettings.showPreview);
    setContent(createCenterComponent());
    myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(final TreeSelectionEvent e) {
            ApplicationManager.getApplication().invokeLater(() -> {
                if (myUsagePreviewPanel.isVisible()) {
                    updatePreviewPanel();
                }
            }, ModalityState.NON_MODAL, myProject.getDisposed());
        }
    });
    // Create tool bars and register custom shortcuts
    JPanel toolBarPanel = new JPanel(new GridLayout());
    DefaultActionGroup leftGroup = new DefaultActionGroup();
    leftGroup.add(new PreviousOccurenceToolbarAction(myOccurenceNavigator));
    leftGroup.add(new NextOccurenceToolbarAction(myOccurenceNavigator));
    leftGroup.add(new ContextHelpAction("find.todoList"));
    toolBarPanel.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.TODO_VIEW_TOOLBAR, leftGroup, false).getComponent());
    DefaultActionGroup rightGroup = new DefaultActionGroup();
    AnAction expandAllAction = CommonActionsManager.getInstance().createExpandAllAction(myTreeExpander, this);
    rightGroup.add(expandAllAction);
    AnAction collapseAllAction = CommonActionsManager.getInstance().createCollapseAllAction(myTreeExpander, this);
    rightGroup.add(collapseAllAction);
    if (!myCurrentFileMode) {
        MyShowModulesAction showModulesAction = new MyShowModulesAction();
        showModulesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_M, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK)), myTree);
        rightGroup.add(showModulesAction);
        MyShowPackagesAction showPackagesAction = new MyShowPackagesAction();
        showPackagesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_P, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK)), myTree);
        rightGroup.add(showPackagesAction);
        MyFlattenPackagesAction flattenPackagesAction = new MyFlattenPackagesAction();
        flattenPackagesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK)), myTree);
        rightGroup.add(flattenPackagesAction);
    }
    MyAutoScrollToSourceHandler autoScrollToSourceHandler = new MyAutoScrollToSourceHandler();
    autoScrollToSourceHandler.install(myTree);
    rightGroup.add(autoScrollToSourceHandler.createToggleAction());
    SetTodoFilterAction setTodoFilterAction = new SetTodoFilterAction(myProject, mySettings, todoFilter -> setTodoFilter(todoFilter));
    rightGroup.add(setTodoFilterAction);
    rightGroup.add(new MyPreviewAction());
    toolBarPanel.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.TODO_VIEW_TOOLBAR, rightGroup, false).getComponent());
    setToolbar(toolBarPanel);
}
Also used : FindModel(com.intellij.find.FindModel) KeyAdapter(java.awt.event.KeyAdapter) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) UsagePreviewPanel(com.intellij.usages.impl.UsagePreviewPanel) TreeSelectionListener(javax.swing.event.TreeSelectionListener) ContextHelpAction(com.intellij.ide.actions.ContextHelpAction) PreviousOccurenceToolbarAction(com.intellij.ide.actions.PreviousOccurenceToolbarAction) KeyEvent(java.awt.event.KeyEvent) NextOccurenceToolbarAction(com.intellij.ide.actions.NextOccurenceToolbarAction) TodoItemNode(com.intellij.ide.todo.nodes.TodoItemNode) TreePath(javax.swing.tree.TreePath) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 30 with FindModel

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

the class IconsReferencesContributor method execute.

@Override
public boolean execute(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull final Processor<PsiReference> consumer) {
    final PsiElement file = queryParameters.getElementToSearch();
    if (file instanceof PsiBinaryFile) {
        final Module module = ApplicationManager.getApplication().runReadAction(new Computable<Module>() {

            @Override
            public Module compute() {
                return ModuleUtilCore.findModuleForPsiElement(file);
            }
        });
        final VirtualFile image = ((PsiBinaryFile) file).getVirtualFile();
        if (isImage(image) && isIconsModule(module)) {
            final Project project = file.getProject();
            final FindModel model = new FindModel();
            final String path = getPathToImage(image, module);
            if (path == null)
                return true;
            model.setStringToFind(path);
            model.setCaseSensitive(true);
            model.setFindAll(true);
            model.setWholeWordsOnly(true);
            FindInProjectUtil.findUsages(model, project, usage -> {
                ApplicationManager.getApplication().runReadAction(() -> {
                    final PsiElement element = usage.getElement();
                    final ProperTextRange textRange = usage.getRangeInElement();
                    if (element != null && textRange != null) {
                        final PsiElement start = element.findElementAt(textRange.getStartOffset());
                        final PsiElement end = element.findElementAt(textRange.getEndOffset());
                        if (start != null && end != null) {
                            PsiElement value = PsiTreeUtil.findCommonParent(start, end);
                            if (value instanceof PsiJavaToken) {
                                value = value.getParent();
                            }
                            if (value != null) {
                                final PsiFileReference reference = FileReferenceUtil.findFileReference(value);
                                if (reference != null) {
                                    consumer.process(reference);
                                }
                            }
                        }
                    }
                });
                return true;
            }, new FindUsagesProcessPresentation(new UsageViewPresentation()));
        }
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UsageViewPresentation(com.intellij.usages.UsageViewPresentation) FindModel(com.intellij.find.FindModel) FindUsagesProcessPresentation(com.intellij.usages.FindUsagesProcessPresentation) ProperTextRange(com.intellij.openapi.util.ProperTextRange) Project(com.intellij.openapi.project.Project) PsiFileReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.PsiFileReference) Module(com.intellij.openapi.module.Module)

Aggregations

FindModel (com.intellij.find.FindModel)31 FindManager (com.intellij.find.FindManager)8 Project (com.intellij.openapi.project.Project)7 UsageInfo (com.intellij.usageView.UsageInfo)6 FindUsagesProcessPresentation (com.intellij.usages.FindUsagesProcessPresentation)5 EditorSearchSession (com.intellij.find.EditorSearchSession)4 Editor (com.intellij.openapi.editor.Editor)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 FindResult (com.intellij.find.FindResult)3 StatusBar (com.intellij.openapi.wm.StatusBar)3 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)2 Application (com.intellij.openapi.application.Application)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 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2 Module (com.intellij.openapi.module.Module)2 WindowManager (com.intellij.openapi.wm.WindowManager)2 PsiClass (com.intellij.psi.PsiClass)2 PsiElement (com.intellij.psi.PsiElement)2