Search in sources :

Example 31 with FileEditorManagerEx

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

the class CloseEditorsActionBase method getFilesToClose.

protected ArrayList<Pair<EditorComposite, EditorWindow>> getFilesToClose(final AnActionEvent event) {
    final ArrayList<Pair<EditorComposite, EditorWindow>> res = new ArrayList<>();
    final DataContext dataContext = event.getDataContext();
    final Project project = event.getData(CommonDataKeys.PROJECT);
    final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(project);
    final EditorWindow editorWindow = EditorWindow.DATA_KEY.getData(dataContext);
    final EditorWindow[] windows;
    if (editorWindow != null) {
        windows = new EditorWindow[] { editorWindow };
    } else {
        windows = editorManager.getWindows();
    }
    final FileStatusManager fileStatusManager = FileStatusManager.getInstance(project);
    if (fileStatusManager != null) {
        for (int i = 0; i != windows.length; ++i) {
            final EditorWindow window = windows[i];
            final EditorComposite[] editors = window.getEditors();
            for (final EditorComposite editor : editors) {
                if (isFileToClose(editor, window)) {
                    res.add(Pair.create(editor, window));
                }
            }
        }
    }
    return res;
}
Also used : Project(com.intellij.openapi.project.Project) ArrayList(java.util.ArrayList) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) EditorComposite(com.intellij.openapi.fileEditor.impl.EditorComposite) Pair(com.intellij.openapi.util.Pair) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow) FileStatusManager(com.intellij.openapi.vcs.FileStatusManager)

Example 32 with FileEditorManagerEx

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

the class CloseAllEditorsButActiveAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
    VirtualFile selectedFile;
    final EditorWindow window = e.getData(EditorWindow.DATA_KEY);
    if (window != null) {
        window.closeAllExcept(e.getData(CommonDataKeys.VIRTUAL_FILE));
        return;
    }
    selectedFile = fileEditorManager.getSelectedFiles()[0];
    final VirtualFile[] siblings = fileEditorManager.getSiblings(selectedFile);
    for (final VirtualFile sibling : siblings) {
        if (!Comparing.equal(selectedFile, sibling)) {
            fileEditorManager.closeFile(sibling);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow)

Example 33 with FileEditorManagerEx

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

the class FileDropHandler method openFiles.

private void openFiles(final Project project, final List<File> fileList, EditorWindow editorWindow) {
    if (editorWindow == null && myEditor != null) {
        editorWindow = findEditorWindow(project);
    }
    final LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    for (File file : fileList) {
        final VirtualFile vFile = fileSystem.refreshAndFindFileByIoFile(file);
        final FileEditorManagerEx fileEditorManager = (FileEditorManagerEx) FileEditorManager.getInstance(project);
        if (vFile != null) {
            NonProjectFileWritingAccessProvider.allowWriting(vFile);
            if (editorWindow != null) {
                fileEditorManager.openFileWithProviders(vFile, true, editorWindow);
            } else {
                new OpenFileDescriptor(project, vFile).navigate(true);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx)

Example 34 with FileEditorManagerEx

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

the class FileDropHandler method findEditorWindow.

@Nullable
private EditorWindow findEditorWindow(Project project) {
    final Document document = myEditor.getDocument();
    final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
    if (file != null) {
        final FileEditorManagerEx fileEditorManager = (FileEditorManagerEx) FileEditorManager.getInstance(project);
        final EditorWindow[] windows = fileEditorManager.getWindows();
        for (EditorWindow window : windows) {
            final EditorWithProviderComposite composite = window.findFileComposite(file);
            if (composite == null) {
                continue;
            }
            for (FileEditor editor : composite.getEditors()) {
                if (editor instanceof TextEditor && ((TextEditor) editor).getEditor() == myEditor) {
                    return window;
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) EditorWithProviderComposite(com.intellij.openapi.fileEditor.impl.EditorWithProviderComposite) Document(com.intellij.openapi.editor.Document) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow) Nullable(org.jetbrains.annotations.Nullable)

Example 35 with FileEditorManagerEx

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

the class EditorHistoryManager method updateHistoryEntry.

private void updateHistoryEntry(@Nullable final VirtualFile file, @Nullable final FileEditor fallbackEditor, @Nullable FileEditorProvider fallbackProvider, final boolean changeEntryOrderOnly) {
    if (file == null) {
        return;
    }
    final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(myProject);
    final Pair<FileEditor[], FileEditorProvider[]> editorsWithProviders = editorManager.getEditorsWithProviders(file);
    FileEditor[] editors = editorsWithProviders.getFirst();
    FileEditorProvider[] providers = editorsWithProviders.getSecond();
    if (editors.length <= 0 && fallbackEditor != null) {
        editors = new FileEditor[] { fallbackEditor };
        providers = new FileEditorProvider[] { fallbackProvider };
    }
    if (editors.length == 0) {
        // makes no sense to put the file in the history
        return;
    }
    final HistoryEntry entry = getEntry(file);
    if (entry == null) {
        // Size of entry list can be less than number of opened editors (some entries can be removed)
        if (file.isValid()) {
            // the file could have been deleted, so the isValid() check is essential
            fileOpenedImpl(file, fallbackEditor, fallbackProvider);
        }
        return;
    }
    if (!changeEntryOrderOnly) {
        //LOG.assertTrue(editors.length > 0);
        for (int i = editors.length - 1; i >= 0; i--) {
            final FileEditor editor = editors[i];
            final FileEditorProvider provider = providers[i];
            // can happen if fallbackProvider is null
            if (provider == null)
                continue;
            if (!editor.isValid()) {
                // and this method was called during corresponding myEditor close up
                continue;
            }
            final FileEditorState oldState = entry.getState(provider);
            final FileEditorState newState = editor.getState(FileEditorStateLevel.FULL);
            if (!newState.equals(oldState)) {
                entry.putState(provider, newState);
            }
        }
    }
    final Pair<FileEditor, FileEditorProvider> selectedEditorWithProvider = editorManager.getSelectedEditorWithProvider(file);
    if (selectedEditorWithProvider != null) {
        //LOG.assertTrue(selectedEditorWithProvider != null);
        entry.setSelectedProvider(selectedEditorWithProvider.getSecond());
        LOG.assertTrue(entry.getSelectedProvider() != null);
        if (changeEntryOrderOnly) {
            moveOnTop(entry);
        }
    }
}
Also used : FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx)

Aggregations

FileEditorManagerEx (com.intellij.openapi.fileEditor.ex.FileEditorManagerEx)37 EditorWindow (com.intellij.openapi.fileEditor.impl.EditorWindow)19 Project (com.intellij.openapi.project.Project)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)16 FileEditor (com.intellij.openapi.fileEditor.FileEditor)5 CommandProcessor (com.intellij.openapi.command.CommandProcessor)4 ToolWindowManager (com.intellij.openapi.wm.ToolWindowManager)3 NotNull (org.jetbrains.annotations.NotNull)3 Presentation (com.intellij.openapi.actionSystem.Presentation)2 Document (com.intellij.openapi.editor.Document)2 Editor (com.intellij.openapi.editor.Editor)2 TextEditor (com.intellij.openapi.fileEditor.TextEditor)2 Pair (com.intellij.openapi.util.Pair)2 EditorBoundHighlightingPass (com.intellij.codeHighlighting.EditorBoundHighlightingPass)1 HighlightingPass (com.intellij.codeHighlighting.HighlightingPass)1 TextEditorHighlightingPass (com.intellij.codeHighlighting.TextEditorHighlightingPass)1 AllIcons (com.intellij.icons.AllIcons)1 GeneralSettings (com.intellij.ide.GeneralSettings)1 IdeEventQueue (com.intellij.ide.IdeEventQueue)1 CloseAction (com.intellij.ide.actions.CloseAction)1