Search in sources :

Example 91 with OpenFileDescriptor

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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CaptureService(com.android.tools.idea.profiling.capture.CaptureService) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) IOException(java.io.IOException) Capture(com.android.tools.idea.profiling.capture.Capture)

Example 92 with OpenFileDescriptor

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeaSourceProvider(org.jetbrains.android.facet.IdeaSourceProvider) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 93 with OpenFileDescriptor

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 94 with OpenFileDescriptor

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);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Navigatable(com.intellij.pom.Navigatable)

Example 95 with OpenFileDescriptor

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);
}
Also used : OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Aggregations

OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)155 VirtualFile (com.intellij.openapi.vfs.VirtualFile)97 Project (com.intellij.openapi.project.Project)40 Editor (com.intellij.openapi.editor.Editor)30 PsiElement (com.intellij.psi.PsiElement)27 PsiFile (com.intellij.psi.PsiFile)21 Navigatable (com.intellij.pom.Navigatable)19 Nullable (org.jetbrains.annotations.Nullable)18 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)10 Document (com.intellij.openapi.editor.Document)9 FileEditor (com.intellij.openapi.fileEditor.FileEditor)9 TextRange (com.intellij.openapi.util.TextRange)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)9 File (java.io.File)9 Result (com.intellij.openapi.application.Result)8 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)8 NotNull (org.jetbrains.annotations.NotNull)6 TemplateBuilder (com.intellij.codeInsight.template.TemplateBuilder)5 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)5 XmlTag (com.intellij.psi.xml.XmlTag)5