Search in sources :

Example 1 with FileChooserDialog

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

the class SchemeImportUtil method selectImportSource.

@Nullable
public static VirtualFile selectImportSource(@NotNull final String[] sourceExtensions, @NotNull Component parent, @Nullable VirtualFile preselect, @Nullable String description) {
    final Set<String> extensions = new HashSet<>(Arrays.asList(sourceExtensions));
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return (file.isDirectory() || extensions.contains(file.getExtension())) && (showHiddenFiles || !FileElement.isFileHidden(file));
        }

        @Override
        public boolean isFileSelectable(VirtualFile file) {
            return !file.isDirectory() && extensions.contains(file.getExtension());
        }
    };
    if (description != null) {
        descriptor.setDescription(description);
    }
    FileChooserDialog fileChooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, parent);
    final VirtualFile[] preselectFiles;
    if (preselect != null) {
        preselectFiles = new VirtualFile[1];
        preselectFiles[0] = preselect;
    } else {
        preselectFiles = VirtualFile.EMPTY_ARRAY;
    }
    final VirtualFile[] virtualFiles = fileChooser.choose(null, preselectFiles);
    //CodeStyleSchemesUIConfiguration.Util.getRecentImportFile());
    if (virtualFiles.length != 1)
        return null;
    virtualFiles[0].refresh(false, false);
    return virtualFiles[0];
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) FileChooserDialog(com.intellij.openapi.fileChooser.FileChooserDialog) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with FileChooserDialog

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

the class AndroidImportProjectAction method selectFileAndCreateWizard.

@Nullable
private AddModuleWizard selectFileAndCreateWizard(@NotNull FileChooserDescriptor descriptor) throws IOException, ConfigurationException {
    FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null);
    VirtualFile toSelect = null;
    String lastLocation = PropertiesComponent.getInstance().getValue(LAST_IMPORTED_LOCATION);
    if (lastLocation != null) {
        toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(lastLocation);
    }
    VirtualFile[] files = chooser.choose(null, toSelect);
    if (files.length == 0) {
        return null;
    }
    VirtualFile file = files[0];
    PropertiesComponent.getInstance().setValue(LAST_IMPORTED_LOCATION, file.getPath());
    return createImportWizard(file);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDialog(com.intellij.openapi.fileChooser.FileChooserDialog) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with FileChooserDialog

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

the class ExportRunConfigurationDialog method chooseDirectory.

private void chooseDirectory() {
    FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor().withTitle("Export Directory Location").withDescription("Choose directory to export run configurations to").withHideIgnored(false);
    FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null);
    final VirtualFile[] files;
    File existingLocation = new File(getOutputDirectoryPath());
    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];
    outputDirectoryPanel.setText(file.getPath());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) File(java.io.File) FileChooserDialog(com.intellij.openapi.fileChooser.FileChooserDialog)

Example 4 with FileChooserDialog

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

the class GenerateFromBuildFileSelectProjectViewOption method chooseWorkspacePath.

private void chooseWorkspacePath() {
    BuildSystemProvider buildSystem = BuildSystemProvider.getBuildSystemProvider(builder.getBuildSystem());
    assert buildSystem != null;
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false).withShowHiddenFiles(// Show root project view file
    true).withHideIgnored(false).withTitle("Select BUILD File").withDescription("Select a BUILD file to synthesize a project view from.").withFileFilter(virtualFile -> buildSystem.isBuildFile(virtualFile.getName()));
    FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null);
    WorkspacePathResolver workspacePathResolver = builder.getWorkspaceOption().getWorkspacePathResolver();
    File fileBrowserRoot = builder.getWorkspaceOption().getFileBrowserRoot();
    File startingLocation = fileBrowserRoot;
    String buildFilePath = getBuildFilePath();
    if (!buildFilePath.isEmpty() && WorkspacePath.isValid(buildFilePath)) {
        // If the user has typed part of the path then clicked the '...', try to start from the
        // partial state
        buildFilePath = StringUtil.trimEnd(buildFilePath, '/');
        if (WorkspacePath.isValid(buildFilePath)) {
            File fileLocation = workspacePathResolver.resolveToFile(new WorkspacePath(buildFilePath));
            if (fileLocation.exists() && FileUtil.isAncestor(fileBrowserRoot, 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(fileBrowserRoot.getPath(), file.getPath(), true)) {
        Messages.showErrorDialog(String.format("You must choose a BUILD file under %s.", fileBrowserRoot.getPath()), "Cannot Use BUILD File");
        return;
    }
    String newWorkspacePath = FileUtil.getRelativePath(fileBrowserRoot, new File(file.getPath()));
    buildFilePathField.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) BuildSystemProvider(com.google.idea.blaze.base.bazel.BuildSystemProvider) 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 5 with FileChooserDialog

use of com.intellij.openapi.fileChooser.FileChooserDialog in project intellij-leiningen-plugin by derkork.

the class AddManagedFilesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project ideaProject = e.getData(PlatformDataKeys.PROJECT);
    final LeiningenProjectsManager manager = LeiningenProjectsManager.getInstance(ideaProject);
    FileChooserDescriptor leinProjectFileDescriptor = new FileChooserDescriptor(true, false, false, false, false, true) {

        @Override
        public boolean isFileSelectable(VirtualFile file) {
            return super.isFileSelectable(file) && !manager.isManagedFile(file);
        }

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return (file.isDirectory() || LeiningenProjectsManager.isProjectFile(file)) && super.isFileVisible(file, showHiddenFiles);
        }
    };
    VirtualFile fileToSelect = e.getData(PlatformDataKeys.VIRTUAL_FILE);
    FileChooserDialog dialog = FileChooserFactory.getInstance().createFileChooser(leinProjectFileDescriptor, ideaProject, null);
    VirtualFile[] files = dialog.choose(fileToSelect, ideaProject);
    if (files.length == 0)
        return;
    for (VirtualFile file : files) {
        manager.importLeiningenProject(file, ideaProject);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) LeiningenProjectsManager(de.janthomae.leiningenplugin.project.LeiningenProjectsManager) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) 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