Search in sources :

Example 1 with EditorComposite

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

the class CloseAllUnpinnedEditorsAction method isActionEnabled.

@Override
protected boolean isActionEnabled(final Project project, final AnActionEvent event) {
    final ArrayList<Pair<EditorComposite, EditorWindow>> filesToClose = getFilesToClose(event);
    if (filesToClose.isEmpty())
        return false;
    Set<EditorWindow> checked = new HashSet<>();
    boolean hasPinned = false;
    boolean hasUnpinned = false;
    for (Pair<EditorComposite, EditorWindow> pair : filesToClose) {
        final EditorWindow window = pair.second;
        if (checked.add(window)) {
            for (EditorWithProviderComposite e : window.getEditors()) {
                if (e.isPinned()) {
                    hasPinned = true;
                } else {
                    hasUnpinned = true;
                }
            }
            if (/*hasPinned && */
            hasUnpinned) {
                return true;
            }
        }
    }
    return false;
}
Also used : EditorWithProviderComposite(com.intellij.openapi.fileEditor.impl.EditorWithProviderComposite) EditorComposite(com.intellij.openapi.fileEditor.impl.EditorComposite) Pair(com.intellij.openapi.util.Pair) HashSet(com.intellij.util.containers.HashSet) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow)

Example 2 with EditorComposite

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

the class CloseEditorsActionBase method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final CommandProcessor commandProcessor = CommandProcessor.getInstance();
    commandProcessor.executeCommand(project, () -> {
        final ArrayList<Pair<EditorComposite, EditorWindow>> filesToClose = getFilesToClose(e);
        for (int i = 0; i != filesToClose.size(); ++i) {
            final Pair<EditorComposite, EditorWindow> we = filesToClose.get(i);
            we.getSecond().closeFile(we.getFirst().getFile());
        }
    }, IdeBundle.message("command.close.all.unmodified.editors"), null);
}
Also used : Project(com.intellij.openapi.project.Project) CommandProcessor(com.intellij.openapi.command.CommandProcessor) EditorComposite(com.intellij.openapi.fileEditor.impl.EditorComposite) Pair(com.intellij.openapi.util.Pair) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow)

Example 3 with EditorComposite

use of com.intellij.openapi.fileEditor.impl.EditorComposite 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)

Aggregations

EditorComposite (com.intellij.openapi.fileEditor.impl.EditorComposite)3 EditorWindow (com.intellij.openapi.fileEditor.impl.EditorWindow)3 Pair (com.intellij.openapi.util.Pair)3 Project (com.intellij.openapi.project.Project)2 CommandProcessor (com.intellij.openapi.command.CommandProcessor)1 FileEditorManagerEx (com.intellij.openapi.fileEditor.ex.FileEditorManagerEx)1 EditorWithProviderComposite (com.intellij.openapi.fileEditor.impl.EditorWithProviderComposite)1 FileStatusManager (com.intellij.openapi.vcs.FileStatusManager)1 HashSet (com.intellij.util.containers.HashSet)1 ArrayList (java.util.ArrayList)1