use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class NavigatableRule method getData.
@Override
public Object getData(DataProvider dataProvider) {
final Navigatable navigatable = CommonDataKeys.NAVIGATABLE.getData(dataProvider);
if (navigatable != null && navigatable instanceof OpenFileDescriptor) {
final OpenFileDescriptor openFileDescriptor = (OpenFileDescriptor) navigatable;
if (openFileDescriptor.getFile().isValid()) {
return openFileDescriptor;
}
}
final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataProvider);
if (element instanceof Navigatable) {
return element;
}
if (element != null) {
return EditSourceUtil.getDescriptor(element);
}
final Object selection = PlatformDataKeys.SELECTED_ITEM.getData(dataProvider);
if (selection instanceof Navigatable) {
return selection;
}
return null;
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class PackageDependenciesNode method getDescriptor.
@Nullable
private OpenFileDescriptor getDescriptor() {
if (getProject() == null)
return null;
final PsiElement psiElement = getPsiElement();
if (psiElement == null)
return null;
final VirtualFile virtualFile = psiElement.getContainingFile().getVirtualFile();
if (virtualFile == null || !virtualFile.isValid())
return null;
return new OpenFileDescriptor(getProject(), virtualFile, psiElement.getTextOffset());
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class EditSourceUtil method getDescriptor.
@Nullable
public static Navigatable getDescriptor(@NotNull PsiElement element) {
PsiElement original = getNavigatableOriginalElement(element);
if (original != null) {
element = original;
} else if (!canNavigate(element)) {
return null;
}
if (element instanceof PomTargetPsiElement) {
return ((PomTargetPsiElement) element).getTarget();
}
final PsiElement navigationElement = element.getNavigationElement();
if (navigationElement instanceof PomTargetPsiElement) {
return ((PomTargetPsiElement) navigationElement).getTarget();
}
final int offset = navigationElement instanceof PsiFile ? -1 : navigationElement.getTextOffset();
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(navigationElement);
if (virtualFile == null || !virtualFile.isValid()) {
return null;
}
OpenFileDescriptor desc = new OpenFileDescriptor(navigationElement.getProject(), virtualFile, offset);
desc.setUseCurrentWindow(FileEditorManager.USE_CURRENT_WINDOW.isIn(navigationElement));
return desc;
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class ConsoleViewImpl method getData.
@Override
public Object getData(final String dataId) {
if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
if (myEditor == null) {
return null;
}
final LogicalPosition pos = myEditor.getCaretModel().getLogicalPosition();
final HyperlinkInfo info = myHyperlinks.getHyperlinkInfoByLineAndCol(pos.line, pos.column);
final OpenFileDescriptor openFileDescriptor = info instanceof FileHyperlinkInfo ? ((FileHyperlinkInfo) info).getDescriptor() : null;
if (openFileDescriptor == null || !openFileDescriptor.getFile().isValid()) {
return null;
}
return openFileDescriptor;
}
if (CommonDataKeys.EDITOR.is(dataId)) {
return myEditor;
}
if (PlatformDataKeys.HELP_ID.is(dataId)) {
return myHelpId;
}
if (LangDataKeys.CONSOLE_VIEW.is(dataId)) {
return this;
}
return null;
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class CodeInsightUtil method positionCursor.
public static Editor positionCursor(final Project project, PsiFile targetFile, @NotNull PsiElement element) {
TextRange range = element.getTextRange();
LOG.assertTrue(range != null, "element: " + element + "; valid: " + element.isValid());
int textOffset = range.getStartOffset();
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, targetFile.getVirtualFile(), textOffset);
return FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
}
Aggregations