use of com.intellij.openapi.fileEditor.ex.FileEditorManagerEx in project intellij-community by JetBrains.
the class SplitAction method actionPerformed.
public void actionPerformed(final AnActionEvent event) {
final Project project = event.getData(CommonDataKeys.PROJECT);
final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
final EditorWindow window = event.getData(EditorWindow.DATA_KEY);
final VirtualFile file = event.getData(CommonDataKeys.VIRTUAL_FILE);
fileEditorManager.createSplitter(myOrientation, window);
if (myCloseSource && window != null && file != null) {
window.closeFile(file, false, false);
}
}
use of com.intellij.openapi.fileEditor.ex.FileEditorManagerEx in project intellij-community by JetBrains.
the class TabNavigationActionBase method update.
public void update(AnActionEvent event) {
Presentation presentation = event.getPresentation();
DataContext dataContext = event.getDataContext();
Project project = CommonDataKeys.PROJECT.getData(dataContext);
presentation.setEnabled(false);
if (project == null || project.isDisposed()) {
return;
}
final ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
if (windowManager.isEditorComponentActive()) {
final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(project);
EditorWindow currentWindow = EditorWindow.DATA_KEY.getData(dataContext);
if (currentWindow == null) {
editorManager.getCurrentWindow();
}
if (currentWindow != null) {
final VirtualFile[] files = currentWindow.getFiles();
presentation.setEnabled(files.length > 1);
}
return;
}
ContentManager contentManager = PlatformDataKeys.NONEMPTY_CONTENT_MANAGER.getData(dataContext);
presentation.setEnabled(contentManager != null && contentManager.getContentCount() > 1 && contentManager.isSingleSelection());
}
use of com.intellij.openapi.fileEditor.ex.FileEditorManagerEx in project intellij-community by JetBrains.
the class TabNavigationActionBase method doNavigate.
private void doNavigate(DataContext dataContext, Project project) {
final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(project);
EditorWindow currentWindow = EditorWindow.DATA_KEY.getData(dataContext);
if (currentWindow == null) {
currentWindow = editorManager.getCurrentWindow();
}
VirtualFile selectedFile = currentWindow.getSelectedFile();
if (selectedFile == null) {
selectedFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
}
final VirtualFile[] files = currentWindow.getFiles();
int index = ArrayUtil.find(files, selectedFile);
LOG.assertTrue(index != -1);
editorManager.openFile(files[(index + files.length + myDir) % files.length], true);
}
use of com.intellij.openapi.fileEditor.ex.FileEditorManagerEx in project intellij-community by JetBrains.
the class EditorHistoryManager method fileOpenedImpl.
/**
* Makes file most recent one
*/
private void fileOpenedImpl(@NotNull final VirtualFile file, @Nullable final FileEditor fallbackEditor, @Nullable FileEditorProvider fallbackProvider) {
ApplicationManager.getApplication().assertIsDispatchThread();
// don't add files that cannot be found via VFM (light & etc.)
if (VirtualFileManager.getInstance().findFileByUrl(file.getUrl()) == null)
return;
final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(myProject);
final Pair<FileEditor[], FileEditorProvider[]> editorsWithProviders = editorManager.getEditorsWithProviders(file);
FileEditor[] editors = editorsWithProviders.getFirst();
FileEditorProvider[] oldProviders = editorsWithProviders.getSecond();
LOG.assertTrue(editors.length == oldProviders.length, "Different number of editors and providers");
if (editors.length <= 0 && fallbackEditor != null && fallbackProvider != null) {
editors = new FileEditor[] { fallbackEditor };
oldProviders = new FileEditorProvider[] { fallbackProvider };
}
if (editors.length <= 0) {
LOG.error("No editors for file " + file.getPresentableUrl());
}
FileEditor selectedEditor = editorManager.getSelectedEditor(file);
if (selectedEditor == null) {
selectedEditor = fallbackEditor;
}
LOG.assertTrue(selectedEditor != null);
final int selectedProviderIndex = ArrayUtilRt.find(editors, selectedEditor);
LOG.assertTrue(selectedProviderIndex != -1, "Can't find " + selectedEditor + " among " + Arrays.asList(editors));
final HistoryEntry entry = getEntry(file);
if (entry != null) {
moveOnTop(entry);
} else {
final FileEditorState[] states = new FileEditorState[editors.length];
final FileEditorProvider[] providers = new FileEditorProvider[editors.length];
for (int i = states.length - 1; i >= 0; i--) {
final FileEditorProvider provider = oldProviders[i];
LOG.assertTrue(provider != null);
providers[i] = provider;
FileEditor editor = editors[i];
if (editor.isValid()) {
states[i] = editor.getState(FileEditorStateLevel.FULL);
}
}
addEntry(HistoryEntry.createHeavy(myProject, file, providers, states, providers[selectedProviderIndex]));
trimToSize();
}
}
use of com.intellij.openapi.fileEditor.ex.FileEditorManagerEx in project intellij-community by JetBrains.
the class EditorTabbedContainer method close.
@Override
public void close() {
TabInfo selected = myTabs.getTargetInfo();
if (selected == null)
return;
final VirtualFile file = (VirtualFile) selected.getObject();
final FileEditorManagerEx mgr = FileEditorManagerEx.getInstanceEx(myProject);
AsyncResult<EditorWindow> window = mgr.getActiveWindow();
window.doWhenDone((Consumer<EditorWindow>) wnd -> {
if (wnd != null) {
if (wnd.findFileComposite(file) != null) {
mgr.closeFile(file, wnd);
}
}
});
}
Aggregations