use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class JavaGotoSuperHandler method invoke.
@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(GotoSuperAction.FEATURE_ID);
int offset = editor.getCaretModel().getOffset();
PsiElement[] superElements = findSuperElements(file, offset);
if (superElements.length == 0)
return;
if (superElements.length == 1) {
PsiElement superElement = superElements[0].getNavigationElement();
final PsiFile containingFile = superElement.getContainingFile();
if (containingFile == null)
return;
final VirtualFile virtualFile = containingFile.getVirtualFile();
if (virtualFile == null)
return;
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile, superElement.getTextOffset());
FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
} else if (superElements[0] instanceof PsiMethod) {
boolean showMethodNames = !PsiUtil.allMethodsHaveSameSignature((PsiMethod[]) superElements);
PsiElementListNavigator.openTargets(editor, (PsiMethod[]) superElements, CodeInsightBundle.message("goto.super.method.chooser.title"), CodeInsightBundle.message("goto.super.method.findUsages.title", ((PsiMethod) superElements[0]).getName()), new MethodCellRenderer(showMethodNames));
} else {
NavigationUtil.getPsiElementPopup(superElements, CodeInsightBundle.message("goto.super.class.chooser.title")).showInBestPositionFor(editor);
}
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class DuplicatesImpl method invoke.
public static void invoke(final Project project, final MatchProvider provider) {
final List<Match> duplicates = provider.getDuplicates();
int idx = 0;
final Ref<Boolean> showAll = new Ref<>();
final String confirmDuplicatePrompt = getConfirmationPrompt(provider, duplicates);
for (final Match match : duplicates) {
final PsiFile file = match.getFile();
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null || !virtualFile.isValid())
return;
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, file))
return;
final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile), false);
LOG.assertTrue(editor != null);
if (!match.getMatchStart().isValid() || !match.getMatchEnd().isValid())
continue;
if (replaceMatch(project, provider, match, editor, ++idx, duplicates.size(), showAll, confirmDuplicatePrompt, false))
return;
}
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class InjectedLanguageUtil method openEditorFor.
public static Editor openEditorFor(@NotNull PsiFile file, @NotNull Project project) {
Document document = PsiDocumentManager.getInstance(project).getDocument(file);
// may return editor injected in current selection in the host editor, not for the file passed as argument
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) {
return null;
}
if (virtualFile instanceof VirtualFileWindow) {
virtualFile = ((VirtualFileWindow) virtualFile).getDelegate();
}
Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile, -1), false);
if (editor == null || editor instanceof EditorWindow || editor.isDisposed())
return editor;
if (document instanceof DocumentWindowImpl) {
return EditorWindowImpl.create((DocumentWindowImpl) document, (EditorImpl) editor, file);
}
return editor;
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class AnnotateStackTraceAction method getHyperlinkVirtualFile.
@Nullable
@CalledWithReadLock
private static VirtualFile getHyperlinkVirtualFile(@NotNull List<RangeHighlighter> links) {
RangeHighlighter key = ContainerUtil.getLastItem(links);
if (key == null)
return null;
HyperlinkInfo info = EditorHyperlinkSupport.getHyperlinkInfo(key);
if (!(info instanceof FileHyperlinkInfo))
return null;
OpenFileDescriptor descriptor = ((FileHyperlinkInfo) info).getDescriptor();
return descriptor != null ? descriptor.getFile() : null;
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class UsageViewUtil method navigateTo.
public static void navigateTo(@NotNull UsageInfo info, boolean requestFocus) {
int offset = info.getNavigationOffset();
VirtualFile file = info.getVirtualFile();
Project project = info.getProject();
if (file != null) {
FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, file, offset), requestFocus);
}
}
Aggregations