use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-plugins by JetBrains.
the class BaseEditorAction method update.
public void update(AnActionEvent e) {
FileEditorManager editorManager = FileEditorManager.getInstance(getProject(e));
Editor editor = editorManager.getSelectedTextEditor();
T command = getCommand(e);
MutablePicoContainer container = getContainer(e);
if (command != null && editor != null && container != null) {
VirtualFile file = FileDocumentManager.getInstance().getFile(editor.getDocument());
if (file != null) {
VFile vFile = VFSUtil.createFileFrom(file, editor.getProject());
if (vFile == null) {
return;
}
command.setVFile(vFile);
setUser(container, command);
prepareCommand(command, editor, container);
}
}
super.update(e);
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project android by JetBrains.
the class EditorFixture method selectEditorTab.
/**
* Selects the given tab in the current editor. Used to switch between
* design mode and editor mode for example.
*
* @param tab the tab to switch to
*/
public EditorFixture selectEditorTab(@NotNull final Tab tab) {
String tabName = tab.myTabName;
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
VirtualFile currentFile = getCurrentFile();
assertNotNull("Can't switch to tab " + tabName + " when no file is open in the editor", currentFile);
FileEditorManager manager = FileEditorManager.getInstance(myFrame.getProject());
FileEditor[] editors = manager.getAllEditors(currentFile);
FileEditor target = null;
for (FileEditor editor : editors) {
if (tabName == null || tabName.equals(editor.getName())) {
target = editor;
break;
}
}
if (target != null) {
// Have to use reflection
//FileEditorManagerImpl#setSelectedEditor(final FileEditor editor)
method("setSelectedEditor").withParameterTypes(FileEditor.class).in(manager).invoke(target);
return;
}
List<String> tabNames = Lists.newArrayList();
for (FileEditor editor : editors) {
tabNames.add(editor.getName());
}
fail("Could not find editor tab \"" + (tabName != null ? tabName : "<default>") + "\": Available tabs = " + tabNames);
}
});
return this;
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project android by JetBrains.
the class EditorFixture method open.
/**
* Opens up a different file. This will run through the "Open File..." dialog to
* find and select the given file.
*
* @param file the file to open
* @param tab which tab to open initially, if there are multiple editors
*/
public EditorFixture open(@NotNull final VirtualFile file, @NotNull final Tab tab) {
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
// TODO: Use UI to navigate to the file instead
Project project = myFrame.getProject();
FileEditorManager manager = FileEditorManager.getInstance(project);
if (tab == Tab.EDITOR) {
manager.openTextEditor(new OpenFileDescriptor(project, file), true);
} else {
manager.openFile(file, true);
}
}
});
selectEditorTab(tab);
Wait.seconds(5).expecting("file " + quote(file.getPath()) + " to be opened and loaded").until(() -> {
if (!file.equals(getCurrentFile())) {
return false;
}
FileEditor fileEditor = FileEditorManager.getInstance(myFrame.getProject()).getSelectedEditor(file);
JComponent editorComponent = fileEditor.getComponent();
if (editorComponent instanceof JBLoadingPanel) {
return !((JBLoadingPanel) editorComponent).isLoading();
}
return true;
});
myFrame.requestFocusIfLost();
robot.waitForIdle();
return this;
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project android by JetBrains.
the class HtmlLinkManager method openEditor.
private static boolean openEditor(@NotNull Project project, @NotNull VirtualFile file, int line, int column) {
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, line, column);
FileEditorManager manager = FileEditorManager.getInstance(project);
// Attempt to prefer text editor if it's available for this file
if (manager.openTextEditor(descriptor, true) != null) {
return true;
}
return !manager.openEditor(descriptor, true).isEmpty();
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class ImageEditorImpl method propertyChanged.
void propertyChanged(@NotNull VirtualFilePropertyEvent event) {
if (file.equals(event.getFile())) {
// Change document
file.refresh(true, false, () -> {
if (ImageFileTypeManager.getInstance().isImage(file)) {
setValue(file);
} else {
setValue(null);
// Close editor
FileEditorManager editorManager = FileEditorManager.getInstance(project);
editorManager.closeFile(file);
}
});
}
}
Aggregations