Search in sources :

Example 56 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class XPathEvalAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent event) {
    final Project project = event.getProject();
    if (project == null) {
        // no active project
        LOG.debug("No project");
        return;
    }
    Editor editor = CommonDataKeys.EDITOR.getData(event.getDataContext());
    if (editor == null) {
        FileEditorManager fem = FileEditorManager.getInstance(project);
        editor = fem.getSelectedTextEditor();
    }
    if (editor == null) {
        // no editor available
        LOG.debug("No editor");
        return;
    }
    // do we have an xml file?
    final PsiDocumentManager pdm = PsiDocumentManager.getInstance(project);
    final PsiFile psiFile = pdm.getPsiFile(editor.getDocument());
    if (!(psiFile instanceof XmlFile)) {
        // not xml
        LOG.debug("No XML-File: " + psiFile);
        return;
    }
    // make sure PSI is in sync with document
    pdm.commitDocument(editor.getDocument());
    execute(editor);
}
Also used : Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Editor(com.intellij.openapi.editor.Editor) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 57 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager 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 58 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class OpenFilesActivity method runActivity.

@Override
public void runActivity(@NotNull Project project) {
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    if (fileEditorManager instanceof FileEditorManagerImpl) {
        final FileEditorManagerImpl manager = (FileEditorManagerImpl) fileEditorManager;
        manager.getMainSplitters().openFiles();
        manager.initDockableContentFactory();
    }
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager)

Example 59 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class SrcFileAnnotator method hideCoverageData.

public void hideCoverageData() {
    Editor editor = myEditor;
    PsiFile file = myFile;
    Document document = myDocument;
    if (editor == null || editor.isDisposed() || file == null || document == null)
        return;
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
    final List<RangeHighlighter> highlighters = editor.getUserData(COVERAGE_HIGHLIGHTERS);
    if (highlighters != null) {
        for (final RangeHighlighter highlighter : highlighters) {
            ApplicationManager.getApplication().invokeLater(() -> highlighter.dispose());
        }
        editor.putUserData(COVERAGE_HIGHLIGHTERS, null);
    }
    final Map<FileEditor, EditorNotificationPanel> map = file.getCopyableUserData(NOTIFICATION_PANELS);
    if (map != null) {
        final VirtualFile vFile = getVirtualFile(file);
        boolean freeAll = !fileEditorManager.isFileOpen(vFile);
        file.putCopyableUserData(NOTIFICATION_PANELS, null);
        for (FileEditor fileEditor : map.keySet()) {
            if (!freeAll && !isCurrentEditor(fileEditor)) {
                continue;
            }
            fileEditorManager.removeTopComponent(fileEditor, map.get(fileEditor));
        }
    }
    final DocumentListener documentListener = editor.getUserData(COVERAGE_DOCUMENT_LISTENER);
    if (documentListener != null) {
        document.removeDocumentListener(documentListener);
        editor.putUserData(COVERAGE_DOCUMENT_LISTENER, null);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) FileEditor(com.intellij.openapi.fileEditor.FileEditor) EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) PsiFile(com.intellij.psi.PsiFile) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Editor(com.intellij.openapi.editor.Editor) Document(com.intellij.openapi.editor.Document)

Example 60 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class CoverageDataManagerImpl method renewInformationInEditors.

private void renewInformationInEditors() {
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
    final VirtualFile[] openFiles = fileEditorManager.getOpenFiles();
    for (VirtualFile openFile : openFiles) {
        final FileEditor[] allEditors = fileEditorManager.getAllEditors(openFile);
        applyInformationToEditor(allEditors, openFile);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

Aggregations

FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)67 VirtualFile (com.intellij.openapi.vfs.VirtualFile)36 FileEditor (com.intellij.openapi.fileEditor.FileEditor)29 Editor (com.intellij.openapi.editor.Editor)22 Project (com.intellij.openapi.project.Project)22 TextEditor (com.intellij.openapi.fileEditor.TextEditor)12 Document (com.intellij.openapi.editor.Document)10 PsiFile (com.intellij.psi.PsiFile)10 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)9 Nullable (org.jetbrains.annotations.Nullable)8 TextRange (com.intellij.openapi.util.TextRange)6 NotNull (org.jetbrains.annotations.NotNull)6 FileEditorManagerListener (com.intellij.openapi.fileEditor.FileEditorManagerListener)5 PsiElement (com.intellij.psi.PsiElement)5 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)4 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)4 GuiTask (org.fest.swing.edt.GuiTask)4 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)3 ResourceBundleAsVirtualFile (com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)3 PsiClass (com.intellij.psi.PsiClass)3