use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project buck by facebook.
the class BuckToolWindowFactory method handleClickOnError.
private void handleClickOnError(BuckTreeNodeDetailError node) {
TreeNode parentNode = node.getParent();
if (parentNode instanceof BuckTreeNodeFileError) {
BuckTreeNodeFileError buckParentNode = (BuckTreeNodeFileError) parentNode;
DataContext dataContext = DataManager.getInstance().getDataContext();
Project project = DataKeys.PROJECT.getData(dataContext);
String relativePath = buckParentNode.getFilePath().replace(project.getBasePath(), "");
VirtualFile virtualFile = project.getBaseDir().findFileByRelativePath(relativePath);
OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, virtualFile, node.getLine() - 1, node.getColumn() - 1);
openFileDescriptor.navigate(true);
}
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class XsltDebuggerSession method openLocation.
@Nullable
public static Editor openLocation(Project project, @NotNull String uri, int lineNumber) {
try {
final VirtualFile file = VfsUtil.findFileByURL(new URI(uri).toURL());
final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, lineNumber, 0);
descriptor.navigate(true);
return FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
} catch (MalformedURLException | URISyntaxException e) {
//To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
return null;
}
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class PyiRelatedItemLineMarkerProvider method createLineMarkerInfo.
@NotNull
private static RelatedItemLineMarkerInfo<PsiElement> createLineMarkerInfo(@NotNull PsiElement element, @NotNull PsiElement relatedElement, @NotNull String itemTitle) {
final SmartPointerManager pointerManager = SmartPointerManager.getInstance(element.getProject());
final SmartPsiElementPointer<PsiElement> relatedElementPointer = pointerManager.createSmartPsiElementPointer(relatedElement);
final String stubFileName = relatedElement.getContainingFile().getName();
return new RelatedItemLineMarkerInfo<>(element, element.getTextRange(), ICON, Pass.LINE_MARKERS, element1 -> itemTitle + " in " + stubFileName, new GutterIconNavigationHandler<PsiElement>() {
@Override
public void navigate(MouseEvent e, PsiElement elt) {
final PsiElement restoredRelatedElement = relatedElementPointer.getElement();
if (restoredRelatedElement == null) {
return;
}
final int offset = restoredRelatedElement instanceof PsiFile ? -1 : restoredRelatedElement.getTextOffset();
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(restoredRelatedElement);
if (virtualFile != null && virtualFile.isValid()) {
new OpenFileDescriptor(restoredRelatedElement.getProject(), virtualFile, offset).navigate(true);
}
}
}, GutterIconRenderer.Alignment.RIGHT, GotoRelatedItem.createItems(Collections.singletonList(relatedElement)));
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class CreateLocalVariableFromUsageFix method positionCursor.
@Nullable
protected static Editor positionCursor(Project project, PsiFile targetFile, PsiElement element) {
TextRange range = element.getTextRange();
int textOffset = range.getStartOffset();
VirtualFile vFile = targetFile.getVirtualFile();
assert vFile != null;
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vFile, textOffset);
return FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class MavenOpenOrCreateFilesAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final Project project = MavenActionUtil.getProject(e.getDataContext());
if (project == null)
return;
final List<File> files = getFiles(e);
final List<VirtualFile> virtualFiles = collectVirtualFiles(files);
if (files.size() == 1 && virtualFiles.isEmpty()) {
new WriteCommandAction(project, e.getPresentation().getText()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
File file = files.get(0);
try {
final VirtualFile virtualFile = VfsUtil.createDirectoryIfMissing(file.getParent());
if (virtualFile != null) {
VirtualFile newFile = virtualFile.createChildData(this, file.getName());
virtualFiles.add(newFile);
MavenUtil.runFileTemplate(project, newFile, getFileTemplate());
}
} catch (IOException ex) {
MavenUtil.showError(project, "Cannot create " + file.getName(), ex);
}
}
}.execute();
return;
}
for (VirtualFile each : virtualFiles) {
new OpenFileDescriptor(project, each).navigate(true);
}
}
Aggregations