Java Code Examples for com.intellij.openapi.fileChooser.FileChooser#chooseFiles()
The following examples show how to use
com.intellij.openapi.fileChooser.FileChooser#chooseFiles() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectPackageTemplatePresenterImpl.java From PackageTemplates with Apache License 2.0 | 6 votes |
@Override public void onExportAction(String path) { VirtualFile[] files = FileChooser.chooseFiles(FileReaderUtil.getDirectoryDescriptor(), project, null); //todo remove // LocalFileSystem.getInstance().findFileByIoFile(new File("E:" + File.separator + "Downloads"))); if (files.length <= 0) { return; } PackageTemplate pt = PackageTemplateHelper.getPackageTemplate(path); VirtualFile directoryToExport = files[0]; PackageTemplateHelper.exportPackageTemplate(project, pt, directoryToExport.getPath()); }
Example 2
Source File: LibraryTypeServiceImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public NewLibraryConfiguration createLibraryFromFiles(@Nonnull LibraryRootsComponentDescriptor descriptor, @Nonnull JComponent parentComponent, @Nullable VirtualFile contextDirectory, LibraryType<?> type, final Project project) { final FileChooserDescriptor chooserDescriptor = descriptor.createAttachFilesChooserDescriptor(null); chooserDescriptor.setTitle("Select Library Files"); final VirtualFile[] rootCandidates = FileChooser.chooseFiles(chooserDescriptor, parentComponent, project, contextDirectory); if (rootCandidates.length == 0) { return null; } final List<OrderRoot> roots = RootDetectionUtil.detectRoots(Arrays.asList(rootCandidates), parentComponent, project, descriptor); if (roots.isEmpty()) return null; String name = suggestLibraryName(roots); return doCreate(type, name, roots); }
Example 3
Source File: InsertPathAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(AnActionEvent e) { String selectedText = myTextField.getSelectedText(); VirtualFile virtualFile; if (selectedText != null ) { virtualFile = LocalFileSystem.getInstance().findFileByPath(selectedText.replace(File.separatorChar, '/')); } else { virtualFile = null; } //TODO use from openapi //FeatureUsageTracker.getInstance().triggerFeatureUsed("ui.commandLine.insertPath"); VirtualFile[] files = FileChooser.chooseFiles(myDescriptor, myTextField, getEventProject(e), virtualFile); if (files.length != 0) { myTextField.replaceSelection(files[0].getPresentableUrl()); } }
Example 4
Source File: PathEditor.java From consulo with Apache License 2.0 | 6 votes |
private VirtualFile[] doAdd() { VirtualFile baseDir = myAddBaseDir; Project project = DataManager.getInstance().getDataContext(myComponent).getData(CommonDataKeys.PROJECT); if (baseDir == null && project != null) { baseDir = project.getBaseDir(); } VirtualFile[] files = FileChooser.chooseFiles(myDescriptor, myComponent, project, baseDir); files = adjustAddedFileSet(myComponent, files); List<VirtualFile> added = new ArrayList<VirtualFile>(files.length); for (VirtualFile vFile : files) { if (addElement(vFile)) { added.add(vFile); } } return VfsUtil.toVirtualFileArray(added); }
Example 5
Source File: DependencyViewer.java From gradle-view with Apache License 2.0 | 5 votes |
private void promptForGradleBaseDir() { FileChooserDescriptor fcd = FileChooserDescriptorFactory.createSingleFolderDescriptor(); fcd.setShowFileSystemRoots(true); fcd.setTitle("Choose a Project Folder"); fcd.setDescription("Pick the top level directory to use when viewing dependencies (in case you have a multi-module project)."); fcd.setHideIgnored(false); FileChooser.chooseFiles(fcd, project, project.getBaseDir(), new Consumer<List<VirtualFile>>() { @Override public void consume(List<VirtualFile> files) { gradleBaseDir = files.get(0).getPath(); } }); }
Example 6
Source File: ModelDialog.java From intellij-extra-icons-plugin with MIT License | 5 votes |
/** * Opens a file chooser dialog and loads the icon. */ private CustomIconLoader.ImageWrapper loadCustomIcon() { VirtualFile[] virtualFiles = FileChooser.chooseFiles( new FileChooserDescriptor(true, false, false, false, false, false) .withFileFilter(file -> extensions.contains(file.getExtension())), settingsForm.getProject(), null); if (virtualFiles.length > 0) { return CustomIconLoader.loadFromVirtualFile(virtualFiles[0]); } return null; }
Example 7
Source File: LibraryRootsComponent.java From consulo with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(AnActionEvent e) { FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createMultipleJavaPathDescriptor(); descriptor.setTitle("Exclude from Library"); descriptor.setDescription("Select directories which should be excluded from the library content. Content of excluded directories won't be processed by IDE."); Set<VirtualFile> roots = getNotExcludedRoots(); descriptor.setRoots(roots.toArray(new VirtualFile[roots.size()])); if (roots.size() < 2) { descriptor.setIsTreeRootVisible(true); } VirtualFile toSelect = null; for (Object o : getSelectedElements()) { Object itemElement = o instanceof ExcludedRootElement ? ((ExcludedRootElement)o).getParentDescriptor() : o; if (itemElement instanceof ItemElement) { toSelect = VirtualFileManager.getInstance().findFileByUrl(((ItemElement)itemElement).getUrl()); break; } } final VirtualFile[] files = FileChooser.chooseFiles(descriptor, myPanel, myProject, toSelect); if (files.length > 0) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { for (VirtualFile file : files) { getLibraryEditor().addExcludedRoot(file.getUrl()); } } }); myLastChosen = files[0]; libraryChanged(true); } }
Example 8
Source File: LibraryRootsComponent.java From consulo with Apache License 2.0 | 5 votes |
@Override protected List<OrderRoot> selectRoots(@Nullable VirtualFile initialSelection) { final String name = getLibraryEditor().getName(); final FileChooserDescriptor chooserDescriptor = myDescriptor.createAttachFilesChooserDescriptor(name); if (myContextModule != null) { chooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, myContextModule); } final VirtualFile[] files = FileChooser.chooseFiles(chooserDescriptor, myPanel, myProject, initialSelection); if (files.length == 0) return Collections.emptyList(); return RootDetectionUtil.detectRoots(Arrays.asList(files), myPanel, myProject, myDescriptor); }
Example 9
Source File: ChooserBasedAttachRootButtonDescriptor.java From consulo with Apache License 2.0 | 5 votes |
@Override public VirtualFile[] selectFiles(final @Nonnull JComponent parent, @Nullable VirtualFile initialSelection, final @Nullable Module contextModule, @Nonnull LibraryEditor libraryEditor) { final FileChooserDescriptor chooserDescriptor = createChooserDescriptor(); chooserDescriptor.setTitle(getChooserTitle(libraryEditor.getName())); chooserDescriptor.setDescription(getChooserDescription()); if (contextModule != null) { chooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, contextModule); } return FileChooser.chooseFiles(chooserDescriptor, parent, contextModule != null ? contextModule.getProject() : null, initialSelection); }
Example 10
Source File: VirtualFileDiffElement.java From consulo with Apache License 2.0 | 5 votes |
@Override public Callable<DiffElement<VirtualFile>> getElementChooser(final Project project) { return () -> { final FileChooserDescriptor descriptor = getChooserDescriptor(); final VirtualFile[] result = FileChooser.chooseFiles(descriptor, project, getValue()); return result.length == 1 ? createElement(result[0]) : null; }; }
Example 11
Source File: FileCopyElementType.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public List<? extends FileCopyPackagingElement> chooseAndCreate(@Nonnull ArtifactEditorContext context, @Nonnull Artifact artifact, @Nonnull CompositePackagingElement<?> parent) { final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, true, false, true); final VirtualFile[] files = FileChooser.chooseFiles(descriptor, context.getProject(), null); final List<FileCopyPackagingElement> list = new ArrayList<FileCopyPackagingElement>(); for (VirtualFile file : files) { list.add(new FileCopyPackagingElement(file.getPath())); } return list; }
Example 12
Source File: DirectoryCopyElementType.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public List<? extends DirectoryCopyPackagingElement> chooseAndCreate(@Nonnull ArtifactEditorContext context, @Nonnull Artifact artifact, @Nonnull CompositePackagingElement<?> parent) { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createMultipleFoldersDescriptor(); final VirtualFile[] files = FileChooser.chooseFiles(descriptor, context.getProject(), null); final List<DirectoryCopyPackagingElement> list = new ArrayList<DirectoryCopyPackagingElement>(); for (VirtualFile file : files) { list.add(new DirectoryCopyPackagingElement(file.getPath())); } return list; }
Example 13
Source File: BrowseFilesListener.java From consulo with Apache License 2.0 | 5 votes |
public void actionPerformed( ActionEvent e ) { final VirtualFile fileToSelect = getFileToSelect(); myChooserDescriptor.setTitle(myTitle); // important to set title and description here because a shared descriptor instance can be used myChooserDescriptor.setDescription(myDescription); FileChooser.chooseFiles(myChooserDescriptor, null, fileToSelect, new Consumer<List<VirtualFile>>() { @Override public void consume(final List<VirtualFile> files) { doSetText(FileUtil.toSystemDependentName(files.get(0).getPath())); } }); }
Example 14
Source File: ProjectSettingsForm.java From EclipseCodeFormatter with Apache License 2.0 | 5 votes |
private boolean browseForFile(@NotNull final JTextField target, FileChooserDescriptor descriptor, String title) { descriptor.setHideIgnored(false); descriptor.setTitle(title); String text = target.getText(); final VirtualFile toSelect = text == null || text.isEmpty() ? getProject().getBaseDir() : LocalFileSystem.getInstance().findFileByPath(text); // 10.5 does not have #chooseFile VirtualFile[] virtualFile = FileChooser.chooseFiles(descriptor, getProject(), toSelect); if (virtualFile != null && virtualFile.length > 0) { target.setText(virtualFile[0].getPath()); return true; } return false; }
Example 15
Source File: SelectPackageTemplatePresenterImpl.java From PackageTemplates with Apache License 2.0 | 5 votes |
@Override public void onImportAction() { VirtualFile[] files = FileChooser.chooseFiles(FileReaderUtil.getPackageTemplatesDescriptorForImport(), project, null); //todo remove // LocalFileSystem.getInstance().findFileByIoFile(new File("E:" + File.separator + "Downloads"))); if (files.length <= 0) { return; } importFromFiles(files, WriteRules.ASK_ME); }
Example 16
Source File: SelectFolder.java From floobits-intellij with Apache License 2.0 | 4 votes |
public static void build(String owner, String workspace, final RunLater<String> runLater) { FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false); descriptor.setTitle("Select Folder For Workspace"); descriptor.setDescription("NOTE: Floobits will NOT make a new, root directory inside the folder you choose. If you have cloned the project already, select that folder."); FloorcJson floorcJson; try { floorcJson = Settings.get(); } catch (Exception e) { Flog.errorMessage("Your floorc.json has invalid json.", null); return; } File file = null; String shareDir = floorcJson.share_dir; if (shareDir != null) { if (shareDir.substring(0, 2).equals("~/")) { shareDir = shareDir.replaceFirst("~/", System.getProperty("user.home") + "/"); } file = createDir(shareDir, owner, workspace); if (file == null) { Flog.errorMessage(String.format("Your floorc.json share_dir setting %s did not work, using default ~/floobits", floorcJson.share_dir), null); } } if (file == null) { file = createDir(Constants.shareDir, owner, workspace); } if (file == null) { Flog.errorMessage(String.format("Could not create a directory for this workspace, tried %s", Constants.shareDir), null); return; } VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); VirtualFile[] vFiles = FileChooser.chooseFiles(descriptor, null, virtualFile); if (vFiles.length == 0) { return; } if (vFiles.length > 1) { Flog.errorMessage("You can only select one directory!", null); return; } final String selectedPath = vFiles[0].getPath(); runLater.run(selectedPath); }
Example 17
Source File: UserDefinedLibraryPanel.java From intellij-xquery with Apache License 2.0 | 4 votes |
protected void chooseFilesWithFileChooser(FileChooserDescriptor descriptor, Consumer<List<VirtualFile>> consumer) { FileChooser.chooseFiles(descriptor, null, null, consumer); }