use of com.intellij.openapi.fileEditor.FileEditor 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.FileEditor in project intellij-community by JetBrains.
the class DaemonCodeAnalyzerImpl method getSelectedEditors.
@NotNull
private Collection<FileEditor> getSelectedEditors() {
ApplicationManager.getApplication().assertIsDispatchThread();
// Editors in modal context
List<Editor> editors = getActiveEditors();
Collection<FileEditor> activeTextEditors = new THashSet<>(editors.size());
for (Editor editor : editors) {
if (editor.isDisposed())
continue;
TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor);
activeTextEditors.add(textEditor);
}
if (ApplicationManager.getApplication().getCurrentModalityState() != ModalityState.NON_MODAL) {
return activeTextEditors;
}
// Editors in tabs.
Collection<FileEditor> result = new THashSet<>();
Collection<VirtualFile> files = new THashSet<>(activeTextEditors.size());
final FileEditor[] tabEditors = FileEditorManager.getInstance(myProject).getSelectedEditors();
for (FileEditor tabEditor : tabEditors) {
if (!tabEditor.isValid())
continue;
VirtualFile file = ((FileEditorManagerEx) FileEditorManager.getInstance(myProject)).getFile(tabEditor);
if (file != null) {
files.add(file);
}
result.add(tabEditor);
}
// do not duplicate documents
for (FileEditor fileEditor : activeTextEditors) {
VirtualFile file = ((FileEditorManagerEx) FileEditorManager.getInstance(myProject)).getFile(fileEditor);
if (file != null && files.contains(file))
continue;
result.add(fileEditor);
}
return result;
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class ShowUsagesAction method getEditorFor.
@Nullable
private static Editor getEditorFor(@NotNull Usage usage) {
FileEditorLocation location = usage.getLocation();
FileEditor newFileEditor = location == null ? null : location.getEditor();
return newFileEditor instanceof TextEditor ? ((TextEditor) newFileEditor).getEditor() : null;
}
use of com.intellij.openapi.fileEditor.FileEditor 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);
}
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class NavigationUtil method activatePsiElementIfOpen.
private static boolean activatePsiElementIfOpen(@NotNull PsiElement elt, boolean searchForOpen, boolean requestFocus) {
if (!elt.isValid())
return false;
elt = elt.getNavigationElement();
final PsiFile file = elt.getContainingFile();
if (file == null || !file.isValid())
return false;
VirtualFile vFile = file.getVirtualFile();
if (vFile == null)
return false;
if (!EditorHistoryManager.getInstance(elt.getProject()).hasBeenOpen(vFile))
return false;
final FileEditorManager fem = FileEditorManager.getInstance(elt.getProject());
if (!fem.isFileOpen(vFile)) {
fem.openFile(vFile, requestFocus, searchForOpen);
}
final TextRange range = elt.getTextRange();
if (range == null)
return false;
final FileEditor[] editors = fem.getEditors(vFile);
for (FileEditor editor : editors) {
if (editor instanceof TextEditor) {
final Editor text = ((TextEditor) editor).getEditor();
final int offset = text.getCaretModel().getOffset();
if (range.containsOffset(offset)) {
// select the file
fem.openFile(vFile, requestFocus, searchForOpen);
return true;
}
}
}
return false;
}
Aggregations