Search in sources :

Example 11 with FileEditorManager

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

the class ScratchFileServiceImpl method initFileOpenedListener.

private void initFileOpenedListener(MessageBus messageBus) {
    final FileEditorManagerListener editorListener = new FileEditorManagerListener() {

        @Override
        public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            if (!isEditable(file))
                return;
            RootType rootType = getRootType(file);
            if (rootType == null)
                return;
            rootType.fileOpened(file, source);
        }

        @Override
        public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            if (Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN)))
                return;
            if (!isEditable(file))
                return;
            RootType rootType = getRootType(file);
            if (rootType == null)
                return;
            rootType.fileClosed(file, source);
        }

        boolean isEditable(@NotNull VirtualFile file) {
            return FileDocumentManager.getInstance().getDocument(file) != null;
        }
    };
    ProjectManagerAdapter projectListener = new ProjectManagerAdapter() {

        @Override
        public void projectOpened(Project project) {
            project.getMessageBus().connect(project).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, editorListener);
            FileEditorManager editorManager = FileEditorManager.getInstance(project);
            for (VirtualFile virtualFile : editorManager.getOpenFiles()) {
                editorListener.fileOpened(editorManager, virtualFile);
            }
        }
    };
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        projectListener.projectOpened(project);
    }
    messageBus.connect().subscribe(ProjectManager.TOPIC, projectListener);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Project(com.intellij.openapi.project.Project) ProjectManagerAdapter(com.intellij.openapi.project.ProjectManagerAdapter) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with FileEditorManager

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

the class DetectedIndentOptionsNotificationProvider method updateIndentNotification.

public static void updateIndentNotification(@NotNull PsiFile file, boolean enforce) {
    VirtualFile vFile = file.getVirtualFile();
    if (vFile == null)
        return;
    if (!ApplicationManager.getApplication().isHeadlessEnvironment() || ApplicationManager.getApplication().isUnitTestMode() && myShowNotificationInTest) {
        Project project = file.getProject();
        FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
        if (fileEditorManager == null)
            return;
        FileEditor fileEditor = fileEditorManager.getSelectedEditor(vFile);
        if (fileEditor != null) {
            Boolean notifiedFlag = fileEditor.getUserData(NOTIFIED_FLAG);
            if (notifiedFlag == null || enforce) {
                fileEditor.putUserData(NOTIFIED_FLAG, Boolean.TRUE);
                EditorNotifications.getInstance(project).updateNotifications(vFile);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

Example 13 with FileEditorManager

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

the class BraceHighlightingHandler method highlightBraces.

private void highlightBraces(@Nullable TextRange lBrace, @Nullable TextRange rBrace, boolean matched, boolean scopeHighlighting, @NotNull FileType fileType) {
    if (!matched && fileType == FileTypes.PLAIN_TEXT) {
        return;
    }
    EditorColorsScheme scheme = myEditor.getColorsScheme();
    final TextAttributes attributes = matched ? scheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES) : scheme.getAttributes(CodeInsightColors.UNMATCHED_BRACE_ATTRIBUTES);
    if (rBrace != null && !scopeHighlighting) {
        highlightBrace(rBrace, matched);
    }
    if (lBrace != null && !scopeHighlighting) {
        highlightBrace(lBrace, matched);
    }
    // null in default project
    FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
    if (fileEditorManager == null || !myEditor.equals(fileEditorManager.getSelectedTextEditor())) {
        return;
    }
    if (lBrace != null && rBrace != null) {
        final int startLine = myEditor.offsetToLogicalPosition(lBrace.getStartOffset()).line;
        final int endLine = myEditor.offsetToLogicalPosition(rBrace.getEndOffset()).line;
        if (endLine - startLine > 0) {
            final Runnable runnable = () -> {
                if (myProject.isDisposed() || myEditor.isDisposed())
                    return;
                Color color = attributes.getBackgroundColor();
                if (color == null)
                    return;
                color = ColorUtil.isDark(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground()) ? ColorUtil.shift(color, 1.5d) : color.darker();
                lineMarkFragment(startLine, endLine, color);
            };
            if (!scopeHighlighting) {
                myAlarm.addRequest(runnable, 300);
            } else {
                runnable.run();
            }
        } else {
            removeLineMarkers();
        }
        if (!scopeHighlighting) {
            showScopeHint(lBrace.getStartOffset(), lBrace.getEndOffset());
        }
    } else {
        if (!myCodeInsightSettings.HIGHLIGHT_SCOPE) {
            removeLineMarkers();
        }
    }
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) LightweightHint(com.intellij.ui.LightweightHint)

Example 14 with FileEditorManager

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

the class MacroManager method getCorrectContext.

private static DataContext getCorrectContext(DataContext dataContext) {
    if (PlatformDataKeys.FILE_EDITOR.getData(dataContext) != null) {
        return dataContext;
    }
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return dataContext;
    }
    FileEditorManager editorManager = FileEditorManager.getInstance(project);
    VirtualFile[] files = editorManager.getSelectedFiles();
    if (files.length == 0) {
        return dataContext;
    }
    FileEditor fileEditor = editorManager.getSelectedEditor(files[0]);
    return fileEditor == null ? dataContext : DataManager.getInstance().getDataContext(fileEditor.getComponent());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

Example 15 with FileEditorManager

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

the class CreateFileFix method openFile.

protected void openFile(@NotNull Project project, PsiDirectory directory, PsiFile newFile, String text) {
    final FileEditorManager editorManager = FileEditorManager.getInstance(directory.getProject());
    final FileEditor[] fileEditors = editorManager.openFile(newFile.getVirtualFile(), true);
    if (text != null) {
        for (FileEditor fileEditor : fileEditors) {
            if (fileEditor instanceof TextEditor) {
                // JSP is not safe to edit via Psi
                final Document document = ((TextEditor) fileEditor).getEditor().getDocument();
                document.setText(text);
                if (ApplicationManager.getApplication().isUnitTestMode()) {
                    FileDocumentManager.getInstance().saveDocument(document);
                }
                PsiDocumentManager.getInstance(project).commitDocument(document);
                break;
            }
        }
    }
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Document(com.intellij.openapi.editor.Document)

Aggregations

FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)66 VirtualFile (com.intellij.openapi.vfs.VirtualFile)35 FileEditor (com.intellij.openapi.fileEditor.FileEditor)29 Editor (com.intellij.openapi.editor.Editor)22 Project (com.intellij.openapi.project.Project)21 TextEditor (com.intellij.openapi.fileEditor.TextEditor)12 PsiFile (com.intellij.psi.PsiFile)10 Document (com.intellij.openapi.editor.Document)9 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