Search in sources :

Example 6 with FileChooserDialog

use of com.intellij.openapi.fileChooser.FileChooserDialog in project intellij-community by JetBrains.

the class ImportModuleAction method selectFileAndCreateWizard.

@Nullable
public static AddModuleWizard selectFileAndCreateWizard(@Nullable Project project, @Nullable Component dialogParent, @NotNull FileChooserDescriptor descriptor, ProjectImportProvider[] providers) {
    FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, project, dialogParent);
    VirtualFile toSelect = null;
    String lastLocation = PropertiesComponent.getInstance().getValue(LAST_IMPORTED_LOCATION);
    if (lastLocation != null) {
        toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(lastLocation);
    }
    VirtualFile[] files = chooser.choose(project, toSelect);
    if (files.length == 0) {
        return null;
    }
    final VirtualFile file = files[0];
    if (project == null) {
        // wizard will create a new project
        for (Project p : ProjectManager.getInstance().getOpenProjects()) {
            if (ProjectUtil.isSameProject(file.getPath(), p)) {
                ProjectUtil.focusProjectWindow(p, false);
                return null;
            }
        }
    }
    PropertiesComponent.getInstance().setValue(LAST_IMPORTED_LOCATION, file.getPath());
    return createImportWizard(project, dialogParent, file, providers);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileChooserDialog(com.intellij.openapi.fileChooser.FileChooserDialog) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with FileChooserDialog

use of com.intellij.openapi.fileChooser.FileChooserDialog in project azure-tools-for-java by Microsoft.

the class StorageChooser method chooseFile.

public VirtualFile[] chooseFile() {
    Component parentComponent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
    final FileChooserDialog chooser = new StorageChooserDialogImpl(this.descriptor, parentComponent, null);
    return chooser.choose(null, this.root);
}
Also used : FileChooserDialog(com.intellij.openapi.fileChooser.FileChooserDialog)

Example 8 with FileChooserDialog

use of com.intellij.openapi.fileChooser.FileChooserDialog in project intellij by bazelbuild.

the class CopyExternalProjectViewOption method chooseWorkspacePath.

private void chooseWorkspacePath() {
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false).withShowHiddenFiles(// Show root project view file
    true).withHideIgnored(false).withTitle("Select Project View File").withDescription("Select a project view file to import.").withFileFilter(virtualFile -> ProjectViewStorageManager.isProjectViewFile(new File(virtualFile.getPath())));
    FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null);
    File startingLocation = null;
    String projectViewPath = getProjectViewPath();
    if (!projectViewPath.isEmpty()) {
        File fileLocation = new File(projectViewPath);
        if (fileLocation.exists()) {
            startingLocation = fileLocation;
        }
    }
    final VirtualFile[] files;
    if (startingLocation != null) {
        VirtualFile toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(startingLocation.getPath());
        files = chooser.choose(null, toSelect);
    } else {
        files = chooser.choose(null);
    }
    if (files.length == 0) {
        return;
    }
    VirtualFile file = files[0];
    projectViewPathField.setText(file.getPath());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) FileChooserDialog(com.intellij.openapi.fileChooser.FileChooserDialog)

Example 9 with FileChooserDialog

use of com.intellij.openapi.fileChooser.FileChooserDialog in project intellij by bazelbuild.

the class ImportFromWorkspaceProjectViewOption method chooseWorkspacePath.

private void chooseWorkspacePath() {
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false).withShowHiddenFiles(// Show root project view file
    true).withHideIgnored(false).withTitle("Select Project View File").withDescription("Select a project view file to import.").withFileFilter(virtualFile -> ProjectViewStorageManager.isProjectViewFile(new File(virtualFile.getPath())));
    FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null);
    WorkspacePathResolver workspacePathResolver = builder.getWorkspaceOption().getWorkspacePathResolver();
    File fileBrowserRoot = builder.getWorkspaceOption().getFileBrowserRoot();
    File startingLocation = fileBrowserRoot;
    String projectViewPath = getProjectViewPath();
    if (!projectViewPath.isEmpty()) {
        // If the user has typed part of the path then clicked the '...', try to start from the
        // partial state
        projectViewPath = StringUtil.trimEnd(projectViewPath, '/');
        if (WorkspacePath.isValid(projectViewPath)) {
            File fileLocation = workspacePathResolver.resolveToFile(new WorkspacePath(projectViewPath));
            if (fileLocation.exists() && FileUtil.isAncestor(getCanonicalPathSafe(fileBrowserRoot), getCanonicalPathSafe(fileLocation), true)) {
                startingLocation = fileLocation;
            }
        }
    }
    VirtualFile toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(startingLocation.getPath());
    VirtualFile[] files = chooser.choose(null, toSelect);
    if (files.length == 0) {
        return;
    }
    VirtualFile file = files[0];
    if (!FileUtil.isAncestor(getCanonicalPathSafe(fileBrowserRoot), getCanonicalPathSafe(file), true)) {
        Messages.showErrorDialog(String.format("You must choose a project view file under %s. " + "To use an external project view, please use the 'Copy external' option.", fileBrowserRoot.getPath()), "Cannot Use Project View File");
        return;
    }
    String newWorkspacePath = FileUtil.getRelativePath(getCanonicalPathSafe(fileBrowserRoot), getCanonicalPathSafe(new File(file.getPath())), File.separatorChar);
    projectViewPathField.setText(newWorkspacePath);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) FileChooserDialog(com.intellij.openapi.fileChooser.FileChooserDialog)

Example 10 with FileChooserDialog

use of com.intellij.openapi.fileChooser.FileChooserDialog in project intellij by bazelbuild.

the class UseExistingBazelWorkspaceOption method chooseDirectory.

private void chooseDirectory() {
    FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) {

        @Override
        public boolean isFileSelectable(VirtualFile file) {
            // we want to make sure only workspace roots are selectable
            return super.isFileSelectable(file) && isWorkspaceRoot(file);
        }
    }.withHideIgnored(false).withTitle("Select Workspace Root").withDescription("Select the directory of the workspace you want to use.").withFileFilter(UseExistingBazelWorkspaceOption::isWorkspaceRoot);
    FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null);
    final VirtualFile[] files;
    File existingLocation = new File(getDirectory());
    if (existingLocation.exists()) {
        VirtualFile toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(existingLocation.getPath());
        files = chooser.choose(null, toSelect);
    } else {
        files = chooser.choose(null);
    }
    if (files.length == 0) {
        return;
    }
    VirtualFile file = files[0];
    directoryField.setText(file.getPath());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) FileChooserDialog(com.intellij.openapi.fileChooser.FileChooserDialog)

Aggregations

FileChooserDialog (com.intellij.openapi.fileChooser.FileChooserDialog)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)7 File (java.io.File)5 Nullable (org.jetbrains.annotations.Nullable)3 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)2 WorkspacePathResolver (com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver)2 Project (com.intellij.openapi.project.Project)2 BuildSystemProvider (com.google.idea.blaze.base.bazel.BuildSystemProvider)1 ProjectViewFile (com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile)1 LeiningenProjectsManager (de.janthomae.leiningenplugin.project.LeiningenProjectsManager)1 HashSet (java.util.HashSet)1