use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project psiviewer by cmf.
the class EditorCaretMover method openInEditor.
public Editor openInEditor(PsiElement element) {
PsiFile psiFile;
int i;
if (element instanceof PsiFile) {
psiFile = (PsiFile) element;
i = -1;
} else {
psiFile = PluginPsiUtil.getContainingFile(element);
i = element.getTextOffset();
}
if (psiFile == null)
return null;
final VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile == null)
return null;
// 20050826 IDEA 5.0.1 #3461
OpenFileDescriptor fileDesc = new OpenFileDescriptor(_project, virtualFile, i);
disableMovementOneTime();
return FileEditorManager.getInstance(_project).openTextEditor(fileDesc, false);
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij by bazelbuild.
the class BlazeBuildSystemServiceTest method testAddDependencyWithBuildTargetPsi.
@Test
public void testAddDependencyWithBuildTargetPsi() throws Exception {
PsiElement buildTargetPsi = mock(PsiElement.class);
PsiFile psiFile = mock(PsiFile.class);
BuildReferenceManager buildReferenceManager = BuildReferenceManager.getInstance(project);
when(buildReferenceManager.resolveLabel(Label.create("//foo:bar"))).thenReturn(buildTargetPsi);
when(buildTargetPsi.getContainingFile()).thenReturn(psiFile);
when(buildTargetPsi.getTextOffset()).thenReturn(1337);
VirtualFile buildFile = VirtualFileSystemProvider.getInstance().getSystem().findFileByPath("/foo/BUILD");
assertThat(buildFile).isNotNull();
when(psiFile.getVirtualFile()).thenReturn(buildFile);
// Doesn't matter.
String dependency = "com.android.foo:bar";
service.addDependency(module, dependency);
ArgumentCaptor<OpenFileDescriptor> descriptorCaptor = ArgumentCaptor.forClass(OpenFileDescriptor.class);
verify(FileEditorManager.getInstance(project)).openTextEditor(descriptorCaptor.capture(), eq(true));
OpenFileDescriptor descriptor = descriptorCaptor.getValue();
assertThat(descriptor.getProject()).isEqualTo(project);
assertThat(descriptor.getFile()).isEqualTo(buildFile);
assertThat(descriptor.getOffset()).isEqualTo(1337);
verifyNoMoreInteractions(FileEditorManager.getInstance(project));
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij by bazelbuild.
the class AddGeneratedResourceDirectoryNavigatable method addDirectoryToProjectView.
private static void addDirectoryToProjectView(Project project, File projectViewFile, ArtifactLocation generatedResDir) {
ProjectViewEdit edit = ProjectViewEdit.editLocalProjectView(project, builder -> {
ListSection<GenfilesPath> existingSection = builder.getLast(GeneratedAndroidResourcesSection.KEY);
ListSection.Builder<GenfilesPath> directoryBuilder = ListSection.update(GeneratedAndroidResourcesSection.KEY, existingSection);
directoryBuilder.add(new GenfilesPath(generatedResDir.getRelativePath()));
builder.replace(existingSection, directoryBuilder);
return true;
});
if (edit == null) {
Messages.showErrorDialog("Could not modify project view. Check for errors in your project view and try again", "Error");
return;
}
edit.apply();
VirtualFile projectView = VfsUtil.findFileByIoFile(projectViewFile, false);
if (projectView != null) {
FileEditorManager.getInstance(project).openEditor(new OpenFileDescriptor(project, projectView), true);
}
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij by bazelbuild.
the class BlazeBuildSystemService method addDependency.
@Override
public void addDependency(Module module, String artifact) {
Project project = module.getProject();
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null) {
return;
}
AndroidResourceModuleRegistry registry = AndroidResourceModuleRegistry.getInstance(project);
TargetIdeInfo targetIdeInfo = blazeProjectData.targetMap.get(registry.getTargetKey(module));
if (targetIdeInfo == null || targetIdeInfo.buildFile == null) {
return;
}
// TODO: automagically edit deps instead of just opening the BUILD file?
// Need to translate Gradle coordinates into blaze targets.
// Will probably need to hardcode for each dependency.
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
PsiElement buildTargetPsi = BuildReferenceManager.getInstance(project).resolveLabel(targetIdeInfo.key.label);
if (buildTargetPsi != null) {
// If we can find a PSI for the target,
// then we can jump straight to the target in the build file.
fileEditorManager.openTextEditor(new OpenFileDescriptor(project, buildTargetPsi.getContainingFile().getVirtualFile(), buildTargetPsi.getTextOffset()), true);
} else {
// If not, just the build file is good enough.
File buildIoFile = blazeProjectData.artifactLocationDecoder.decode(targetIdeInfo.buildFile);
VirtualFile buildVirtualFile = VfsUtils.resolveVirtualFile(buildIoFile);
if (buildVirtualFile != null) {
fileEditorManager.openFile(buildVirtualFile, true);
}
}
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij by bazelbuild.
the class ProjectViewHelper method openProjectViewFile.
static void openProjectViewFile(Project project, ProjectViewFile projectViewFile) {
File file = projectViewFile.projectViewFile;
if (file != null) {
VirtualFile virtualFile = VfsUtil.findFileByIoFile(file, true);
if (virtualFile != null) {
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
}
}
}
Aggregations