use of com.intellij.openapi.fileEditor.TextEditor 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.TextEditor 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.TextEditor 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.TextEditor in project intellij-community by JetBrains.
the class ProxyUndoRedoAction method register.
public static void register(@Nullable Project project, @NotNull Editor editor, @NotNull JComponent component) {
UndoManager undoManager = project != null ? UndoManager.getInstance(project) : UndoManager.getGlobalInstance();
TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor);
if (undoManager != null) {
DiffUtil.registerAction(new ProxyUndoRedoAction(undoManager, textEditor, true), component);
DiffUtil.registerAction(new ProxyUndoRedoAction(undoManager, textEditor, false), component);
}
}
use of com.intellij.openapi.fileEditor.TextEditor 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