use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class EditorFixture method getCurrentFile.
/**
* Returns the current file being shown in the editor, if there is a current
* editor open and it's a file editor
*
* @return the currently edited file or null
*/
@Nullable
public VirtualFile getCurrentFile() {
FileEditorManager manager = FileEditorManager.getInstance(myFrame.getProject());
VirtualFile[] selectedFiles = manager.getSelectedFiles();
if (selectedFiles.length > 0) {
// we should be sure that EditorComponent is already showing
VirtualFile selectedFile = selectedFiles[0];
if (manager.getEditors(selectedFile).length == 0)
return null;
else {
FileEditor editor = manager.getEditors(selectedFile)[0];
return editor.getComponent().isShowing() ? selectedFile : null;
}
}
return null;
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community 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);
}
}
});
pause(new Condition("File " + quote(file.getPath()) + " to be opened") {
@Override
public boolean test() {
//noinspection ConstantConditions
return execute(new GuiQuery<Boolean>() {
@Override
protected Boolean executeInEDT() throws Throwable {
FileEditor[] editors = FileEditorManager.getInstance(myFrame.getProject()).getEditors(file);
if (editors.length == 0)
return false;
return editors[0].getComponent().isShowing();
}
});
}
}, SHORT_TIMEOUT);
// TODO: Maybe find a better way to keep Documents in sync with their VirtualFiles.
invokeActionViaKeystroke("Synchronize");
return this;
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class DaemonCodeAnalyzerImpl method getFileLevelHighlights.
@Override
@NotNull
@TestOnly
public List<HighlightInfo> getFileLevelHighlights(@NotNull Project project, @NotNull PsiFile file) {
VirtualFile vFile = file.getViewProvider().getVirtualFile();
final FileEditorManager manager = FileEditorManager.getInstance(project);
return Arrays.stream(manager.getEditors(vFile)).map(fileEditor -> fileEditor.getUserData(FILE_LEVEL_HIGHLIGHTS)).filter(Objects::nonNull).flatMap(Collection::stream).collect(Collectors.toList());
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class DaemonCodeAnalyzerImpl method addFileLevelHighlight.
@Override
public void addFileLevelHighlight(@NotNull final Project project, final int group, @NotNull final HighlightInfo info, @NotNull final PsiFile psiFile) {
VirtualFile vFile = psiFile.getViewProvider().getVirtualFile();
final FileEditorManager manager = FileEditorManager.getInstance(project);
for (FileEditor fileEditor : manager.getEditors(vFile)) {
if (fileEditor instanceof TextEditor) {
FileLevelIntentionComponent component = new FileLevelIntentionComponent(info.getDescription(), info.getSeverity(), info.getGutterIconRenderer(), info.quickFixActionRanges, project, psiFile, ((TextEditor) fileEditor).getEditor(), info.getToolTip());
manager.addTopComponent(fileEditor, component);
List<HighlightInfo> fileLevelInfos = fileEditor.getUserData(FILE_LEVEL_HIGHLIGHTS);
if (fileLevelInfos == null) {
fileLevelInfos = new ArrayList<>();
fileEditor.putUserData(FILE_LEVEL_HIGHLIGHTS, fileLevelInfos);
}
info.fileLevelComponent = component;
info.setGroup(group);
fileLevelInfos.add(info);
}
}
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class StructureViewUpdatingTest method testJavaClassStructure.
public void testJavaClassStructure() throws Exception {
final PsiClass psiClass = JavaDirectoryService.getInstance().getClasses(getPackageDirectory("com/package1"))[0];
final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
FileEditor[] fileEditors = fileEditorManager.openFile(virtualFile, false);
final FileEditor fileEditor = fileEditors[0];
try {
final StructureViewComponent structureViewComponent = (StructureViewComponent) fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
final Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiClass.getContainingFile());
structureViewComponent.setActionActive(InheritedMembersNodeProvider.ID, true);
PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" + " -Class1\n" + " getValue(): int\n" + " getClass(): Class<? extends Object>\n" + " hashCode(): int\n" + " equals(Object): boolean\n" + " clone(): Object\n" + " toString(): String\n" + " notify(): void\n" + " notifyAll(): void\n" + " wait(long): void\n" + " wait(long, int): void\n" + " wait(): void\n" + " finalize(): void\n" + " myField1: boolean\n" + " myField2: boolean\n");
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
final int offset = document.getLineStartOffset(5);
document.insertString(offset, " boolean myNewField = false;\n");
}
}.execute().throwException();
PsiDocumentManager.getInstance(myProject).commitDocument(document);
PlatformTestUtil.waitForAlarm(600);
//TreeUtil.expand(structureViewComponent.getTree(), 3);
PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" + " -Class1\n" + " getValue(): int\n" + " getClass(): Class<? extends Object>\n" + " hashCode(): int\n" + " equals(Object): boolean\n" + " clone(): Object\n" + " toString(): String\n" + " notify(): void\n" + " notifyAll(): void\n" + " wait(long): void\n" + " wait(long, int): void\n" + " wait(): void\n" + " finalize(): void\n" + " myField1: boolean\n" + " myField2: boolean\n" + " myNewField: boolean = false\n");
Disposer.dispose(structureViewComponent);
} finally {
fileEditorManager.closeFile(virtualFile);
}
}
Aggregations