Search in sources :

Example 1 with PlatformProjectOpenProcessor

use of com.intellij.platform.PlatformProjectOpenProcessor in project intellij-community by JetBrains.

the class CommandLineProcessor method doOpenFile.

@Nullable
private static Project doOpenFile(VirtualFile file, int line, boolean tempProject) {
    Project[] projects = ProjectManager.getInstance().getOpenProjects();
    if (projects.length == 0 || tempProject) {
        PlatformProjectOpenProcessor processor = PlatformProjectOpenProcessor.getInstanceIfItExists();
        if (processor != null) {
            EnumSet<PlatformProjectOpenProcessor.Option> options = EnumSet.noneOf(PlatformProjectOpenProcessor.Option.class);
            if (tempProject) {
                options.add(PlatformProjectOpenProcessor.Option.TEMP_PROJECT);
                options.add(PlatformProjectOpenProcessor.Option.FORCE_NEW_FRAME);
            }
            return PlatformProjectOpenProcessor.doOpenProject(file, null, line, null, options);
        }
        Messages.showErrorDialog("No project found to open file in", "Cannot Open File");
        return null;
    } else {
        NonProjectFileWritingAccessProvider.allowWriting(file);
        Project project = findBestProject(file, projects);
        OpenFileDescriptor descriptor = line == -1 ? new OpenFileDescriptor(project, file) : new OpenFileDescriptor(project, file, line - 1, 0);
        descriptor.navigate(true);
        return project;
    }
}
Also used : Project(com.intellij.openapi.project.Project) PlatformProjectOpenProcessor(com.intellij.platform.PlatformProjectOpenProcessor) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PlatformProjectOpenProcessor

use of com.intellij.platform.PlatformProjectOpenProcessor in project android by JetBrains.

the class AndroidOpenFileAction method doOpenFile.

private static void doOpenFile(@Nullable Project project, @NotNull List<VirtualFile> result) {
    for (VirtualFile file : result) {
        if (file.isDirectory()) {
            // for the current project. The check is similar to what is done below for file-based projects
            if ((project != null) && !project.isDefault() && file.equals(project.getBaseDir())) {
                focusProjectWindow(project, false);
                return;
            }
            if (ProjectAttachProcessor.canAttachToProject()) {
                Project openedProject = PlatformProjectOpenProcessor.doOpenProject(file, project, false, -1, null, false);
                setLastOpenedFile(openedProject, file);
            } else {
                openOrImportProject(file, project);
            }
            return;
        }
        // try to open as a project - unless the file is an .ipr of the current one
        if ((project == null || !file.equals(project.getProjectFile())) && OpenProjectFileChooserDescriptor.isProjectFile(file)) {
            if (openOrImportProject(file, project)) {
                return;
            }
        }
        FileType type = getKnownFileTypeOrAssociate(file, project);
        if (type == null)
            return;
        if (project != null) {
            openFile(file, project);
        } else {
            PlatformProjectOpenProcessor processor = PlatformProjectOpenProcessor.getInstanceIfItExists();
            if (processor != null) {
                processor.doOpenProject(file, null, false);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Projects.canImportAsGradleProject(com.android.tools.idea.gradle.util.Projects.canImportAsGradleProject) PlatformProjectOpenProcessor(com.intellij.platform.PlatformProjectOpenProcessor) FileType(com.intellij.openapi.fileTypes.FileType)

Example 3 with PlatformProjectOpenProcessor

use of com.intellij.platform.PlatformProjectOpenProcessor in project intellij-community by JetBrains.

the class CommandLineProcessor method doOpenFileOrProject.

@Nullable
private static Project doOpenFileOrProject(String name) {
    final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(name);
    if (virtualFile == null) {
        Messages.showErrorDialog("Cannot find file '" + name + "'", "Cannot Find File");
        return null;
    }
    ProjectOpenProcessor provider = ProjectOpenProcessor.getImportProvider(virtualFile);
    if (provider instanceof PlatformProjectOpenProcessor && !virtualFile.isDirectory()) {
        // HACK: PlatformProjectOpenProcessor agrees to open anything
        provider = null;
    }
    if (provider != null || ProjectKt.isValidProjectPath(name)) {
        final Project result = ProjectUtil.openOrImport(name, null, true);
        if (result == null) {
            Messages.showErrorDialog("Cannot open project '" + name + "'", "Cannot Open Project");
        }
        return result;
    } else {
        return doOpenFile(virtualFile, -1, false);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PlatformProjectOpenProcessor(com.intellij.platform.PlatformProjectOpenProcessor) ProjectOpenProcessor(com.intellij.projectImport.ProjectOpenProcessor) PlatformProjectOpenProcessor(com.intellij.platform.PlatformProjectOpenProcessor) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with PlatformProjectOpenProcessor

use of com.intellij.platform.PlatformProjectOpenProcessor in project intellij-community by JetBrains.

the class OpenFileAction method doOpenFile.

private static void doOpenFile(@Nullable Project project, @NotNull List<VirtualFile> result) {
    for (VirtualFile file : result) {
        if (file.isDirectory()) {
            Project openedProject;
            if (ProjectAttachProcessor.canAttachToProject()) {
                EnumSet<PlatformProjectOpenProcessor.Option> options = EnumSet.noneOf(PlatformProjectOpenProcessor.Option.class);
                openedProject = PlatformProjectOpenProcessor.doOpenProject(file, project, -1, null, options);
            } else {
                openedProject = ProjectUtil.openOrImport(file.getPath(), project, false);
            }
            FileChooserUtil.setLastOpenedFile(openedProject, file);
            return;
        }
        // try to open as a project - unless the file is an .ipr of the current one
        if ((project == null || !file.equals(project.getProjectFile())) && OpenProjectFileChooserDescriptor.isProjectFile(file)) {
            int answer = file.getFileType() instanceof ProjectFileType ? Messages.YES : Messages.showYesNoCancelDialog(project, IdeBundle.message("message.open.file.is.project", file.getName()), IdeBundle.message("title.open.project"), IdeBundle.message("message.open.file.is.project.open.as.project"), IdeBundle.message("message.open.file.is.project.open.as.file"), IdeBundle.message("button.cancel"), Messages.getQuestionIcon());
            if (answer == Messages.CANCEL)
                return;
            if (answer == Messages.YES) {
                Project openedProject = ProjectUtil.openOrImport(file.getPath(), project, false);
                if (openedProject != null) {
                    FileChooserUtil.setLastOpenedFile(openedProject, file);
                }
                return;
            }
        }
        FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(file, project);
        if (type == null)
            return;
        if (project != null) {
            openFile(file, project);
        } else {
            PlatformProjectOpenProcessor processor = PlatformProjectOpenProcessor.getInstanceIfItExists();
            if (processor != null) {
                processor.doOpenProject(file, null, false);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PlatformProjectOpenProcessor(com.intellij.platform.PlatformProjectOpenProcessor) ProjectFileType(com.intellij.ide.highlighter.ProjectFileType) ProjectFileType(com.intellij.ide.highlighter.ProjectFileType) FileType(com.intellij.openapi.fileTypes.FileType)

Example 5 with PlatformProjectOpenProcessor

use of com.intellij.platform.PlatformProjectOpenProcessor in project intellij-community by JetBrains.

the class RecentProjectsManagerImpl method doOpenProject.

@Override
protected void doOpenProject(@NotNull String projectPath, Project projectToClose, boolean forceOpenInNewFrame) {
    File projectFile = new File(projectPath);
    if (projectFile.isDirectory() && !new File(projectFile, Project.DIRECTORY_STORE_FOLDER).exists()) {
        VirtualFile projectDir = LocalFileSystem.getInstance().findFileByIoFile(projectFile);
        PlatformProjectOpenProcessor processor = PlatformProjectOpenProcessor.getInstanceIfItExists();
        if (projectDir != null && processor != null) {
            processor.doOpenProject(projectDir, projectToClose, forceOpenInNewFrame);
            return;
        }
    }
    ProjectUtil.openProject(projectPath, projectToClose, forceOpenInNewFrame);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PlatformProjectOpenProcessor(com.intellij.platform.PlatformProjectOpenProcessor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

PlatformProjectOpenProcessor (com.intellij.platform.PlatformProjectOpenProcessor)5 Project (com.intellij.openapi.project.Project)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 FileType (com.intellij.openapi.fileTypes.FileType)2 Nullable (org.jetbrains.annotations.Nullable)2 Projects.canImportAsGradleProject (com.android.tools.idea.gradle.util.Projects.canImportAsGradleProject)1 ProjectFileType (com.intellij.ide.highlighter.ProjectFileType)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 ProjectOpenProcessor (com.intellij.projectImport.ProjectOpenProcessor)1 File (java.io.File)1