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;
}
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);
}
}
}
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);
}
}
}
}
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;
}
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);
}
}
}
Aggregations