use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project android by JetBrains.
the class HierarchyViewCaptureTask method onSuccess.
@Override
public void onSuccess() {
if (myError != null) {
Messages.showErrorDialog("Error obtaining view hierarchy: " + StringUtil.notNullize(myError), TITLE);
return;
}
CaptureService service = CaptureService.getInstance(myProject);
try {
Capture capture = service.createCapture(HierarchyViewCaptureType.class, myData, service.getSuggestedName(myClient));
final VirtualFile file = capture.getFile();
file.refresh(true, false, new Runnable() {
@Override
public void run() {
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
OpenFileDescriptor descriptor = new OpenFileDescriptor(myProject, file);
FileEditorManager.getInstance(myProject).openEditor(descriptor, true);
}
});
}
});
} catch (IOException e) {
Messages.showErrorDialog("Error creating hierarchy view capture: " + e, TITLE);
}
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project android by JetBrains.
the class CreateMissingClassQuickFix method applyFix.
@Override
public void applyFix(@NotNull final Project project, @NotNull ProblemDescriptor descriptor) {
final PsiPackage aPackage = myPackage.getElement();
if (aPackage == null) {
return;
}
final AndroidFacet facet = AndroidFacet.getInstance(myModule);
if (facet == null) {
return;
}
final List<IdeaSourceProvider> providerList = IdeaSourceProvider.getCurrentSourceProviders(facet);
final List<VirtualFile> javaDirectories = Lists.newArrayList();
for (IdeaSourceProvider provider : providerList) {
javaDirectories.addAll(provider.getJavaDirectories());
}
final PsiDirectory[] directories = aPackage.getDirectories();
final List<PsiDirectory> filteredDirectories = Lists.newArrayListWithExpectedSize(directories.length);
for (PsiDirectory directory : directories) {
for (VirtualFile file : javaDirectories) {
if (VfsUtilCore.isAncestor(file, directory.getVirtualFile(), true)) {
filteredDirectories.add(directory);
break;
}
}
}
final PsiDirectory directory;
switch(filteredDirectories.size()) {
case 0:
directory = null;
break;
case 1:
directory = filteredDirectories.get(0);
break;
default:
// There are several directories, present a dialog window for a user to choose a particular destination directory
final PsiDirectory[] array = filteredDirectories.toArray(new PsiDirectory[filteredDirectories.size()]);
directory = DirectoryChooserUtil.selectDirectory(aPackage.getProject(), array, filteredDirectories.get(0), "");
}
if (directory == null) {
return;
}
final RunResult<PsiClass> result = new WriteCommandAction<PsiClass>(project) {
@Override
protected void run(@NotNull Result<PsiClass> result) throws Throwable {
// Create a new class
final PsiClass psiClass = JavaDirectoryService.getInstance().createClass(directory, myClassName);
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
// Add a base class to "extends" list
final PsiReferenceList list = psiClass.getExtendsList();
if (list != null && myBaseClassFqcn != null) {
final PsiClass parentClass = facade.findClass(myBaseClassFqcn, GlobalSearchScope.allScope(project));
if (parentClass != null) {
list.add(facade.getElementFactory().createClassReferenceElement(parentClass));
}
}
// Add a "public" modifier, which is absent by default. Required because classes references in AndroidManifest
// have to point to public classes.
final PsiModifierList modifierList = psiClass.getModifierList();
if (modifierList != null) {
modifierList.setModifierProperty(PsiModifier.PUBLIC, true);
}
result.setResult(psiClass);
}
}.execute();
PsiClass aClass = result.getResultObject();
OpenFileDescriptor fileDescriptor = new OpenFileDescriptor(project, aClass.getContainingFile().getVirtualFile());
FileEditorManager.getInstance(project).openEditor(fileDescriptor, true);
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project android by JetBrains.
the class AnalyzeApkAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
Project project = e.getProject();
if (project == null) {
Logger.getInstance(AnalyzeApkAction.class).warn("Unable to obtain project from event");
return;
}
// find the apk to open
VirtualFile vf = promptUserForApk(project);
if (vf == null) {
return;
}
OpenFileDescriptor fd = new OpenFileDescriptor(project, vf);
FileEditorManager.getInstance(project).openEditor(fd, true);
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project android by JetBrains.
the class OpenFileHyperlink method execute.
@Override
protected void execute(@NotNull Project project) {
VirtualFile projectFile = project.getProjectFile();
if (projectFile == null) {
// This is the default project. This will NEVER happen.
return;
}
VirtualFile file = projectFile.getParent().getFileSystem().findFileByPath(myFilePath);
if (file != null) {
Navigatable openFile = new OpenFileDescriptor(project, file, myLineNumber, myColumn, false);
if (openFile.canNavigate()) {
openFile.navigate(true);
}
}
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project android by JetBrains.
the class GradleDslMethodNotFoundErrorHandler method openFile.
private static void openFile(@NotNull VirtualFile virtualFile, @NotNull NotificationData notification, @NotNull Project project) {
int line = notification.getLine() - 1;
int column = notification.getColumn() - 1;
// NotificationData uses 1-based offsets, while OpenFileDescriptor 0-based.
line = line < 0 ? -1 : line;
column = column < 0 ? -1 : column + 1;
new OpenFileDescriptor(project, virtualFile, line, column).navigate(true);
}
Aggregations