com.intellij.openapi.fileChooser.FileChooser Java Examples
The following examples show how to use
com.intellij.openapi.fileChooser.FileChooser.
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: SimpleCreatePropertyQuickFix.java From intellij-sdk-docs with Apache License 2.0 | 6 votes |
@Override public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws IncorrectOperationException { ApplicationManager.getApplication().invokeLater(() -> { Collection<VirtualFile> virtualFiles = FileTypeIndex.getFiles(SimpleFileType.INSTANCE, GlobalSearchScope.allScope(project) ); if (virtualFiles.size() == 1) { createProperty(project, virtualFiles.iterator().next()); } else { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(SimpleFileType.INSTANCE); descriptor.setRoots(ProjectUtil.guessProjectDir(project)); final VirtualFile file1 = FileChooser.chooseFile(descriptor, project, null); if (file1 != null) { createProperty(project, file1); } } }); }
Example #2
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 #3
Source File: GuiUtils.java From consulo with Apache License 2.0 | 6 votes |
public static JPanel constructFileURLBrowserField(final TextFieldWithHistory field, final String objectName) { return constructFieldWithBrowseButton(field, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor().withTitle("Select " + objectName); VirtualFile file = FileChooser.chooseFile(descriptor, field, null, null); if (file != null) { try { field.setText(VfsUtilCore.virtualToIoFile(file).toURI().toURL().toString()); } catch (MalformedURLException e1) { field.setText(""); } } } }); }
Example #4
Source File: BuckSettingsUI.java From buck with Apache License 2.0 | 6 votes |
private void discoverCells() { final FileChooserDescriptor dirChooser = FileChooserDescriptorFactory.createSingleFolderDescriptor() .withTitle("Select any directory within a buck cell"); Project project = buckProjectSettingsProvider.getProject(); Optional.ofNullable( FileChooser.chooseFile(dirChooser, BuckSettingsUI.this, project, project.getBaseDir())) .ifPresent( defaultCell -> ProgressManager.getInstance() .run( new Modal(project, "Autodetecting buck cells", true) { @Override public void run(@NotNull ProgressIndicator progressIndicator) { discoverCells( buckExecutableForAutoDiscovery(), defaultCell, progressIndicator); } })); }
Example #5
Source File: LocalPathCellEditor.java From consulo with Apache License 2.0 | 6 votes |
protected ActionListener createActionListener(final JTable table) { return new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String initial = (String)getCellEditorValue(); VirtualFile initialFile = StringUtil.isNotEmpty(initial) ? LocalFileSystem.getInstance().findFileByPath(initial) : null; FileChooser.chooseFile(getFileChooserDescriptor(), myProject, table, initialFile, new Consumer<VirtualFile>() { @Override public void consume(VirtualFile file) { String path = file.getPresentableUrl(); if (SystemInfo.isWindows && path.length() == 2 && Character.isLetter(path.charAt(0)) && path.charAt(1) == ':') { path += "\\"; // make path absolute } myComponent.getChildComponent().setText(path); } }); } }; }
Example #6
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 #7
Source File: SettingsForm.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private TextBrowseFolderListener createBrowseFolderListener(final JTextField textField, final FileChooserDescriptor fileChooserDescriptor) { return new TextBrowseFolderListener(fileChooserDescriptor) { @Override public void actionPerformed(ActionEvent e) { VirtualFile projectDirectory = ProjectUtil.getProjectDir(project); VirtualFile selectedFile = FileChooser.chooseFile( fileChooserDescriptor, project, VfsUtil.findRelativeFile(textField.getText(), projectDirectory) ); if (null == selectedFile) { return; // Ignore but keep the previous path } String path = VfsUtil.getRelativePath(selectedFile, projectDirectory, '/'); if (null == path) { path = selectedFile.getPath(); } textField.setText(path); } }; }
Example #8
Source File: UiSettingsUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable public static String getPathDialog(@NotNull Project project, @NotNull FileType fileType, @Nullable String current) { VirtualFile projectDirectory = ProjectUtil.getProjectDir(project); VirtualFile selectedFileBefore = null; if(current != null) { selectedFileBefore = VfsUtil.findRelativeFile(current, projectDirectory); } VirtualFile selectedFile = FileChooser.chooseFile( FileChooserDescriptorFactory.createSingleFileDescriptor(fileType), project, selectedFileBefore ); if (null == selectedFile) { return null; } String path = VfsUtil.getRelativePath(selectedFile, projectDirectory, '/'); if (null == path) { path = selectedFile.getPath(); } return path; }
Example #9
Source File: TwigNamespaceDialog.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private TextBrowseFolderListener createBrowseFolderListener(final JTextField textField, final FileChooserDescriptor fileChooserDescriptor) { return new TextBrowseFolderListener(fileChooserDescriptor) { @Override public void actionPerformed(ActionEvent e) { VirtualFile projectDirectory = ProjectUtil.getProjectDir(project); VirtualFile selectedFile = FileChooser.chooseFile( fileChooserDescriptor, project, VfsUtil.findRelativeFile(textField.getText(), projectDirectory) ); if (null == selectedFile) { return; // Ignore but keep the previous path } String path = VfsUtil.getRelativePath(selectedFile, projectDirectory, '/'); if (null == path) { path = selectedFile.getPath(); } textField.setText(path); } }; }
Example #10
Source File: GUI.java From svgtoandroid with MIT License | 6 votes |
private void showSVGChooser() { FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); if (!batch.isSelected()) { descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor("svg"); } VirtualFile virtualFile = FileChooser.chooseFile(descriptor, project, null); if (virtualFile != null) { if (!virtualFile.isDirectory() && virtualFile.getName().toLowerCase().endsWith("svg")) { svg = (XmlFile) PsiManager.getInstance(project).findFile(virtualFile); //got *.svg file as xml svgPath.setText(virtualFile.getPath()); xmlName.setEditable(true); xmlName.setEnabled(true); xmlName.setText(CommonUtil.getValidName(svg.getName().split("\\.")[0]) + ".xml"); } else if (virtualFile.isDirectory()) { svgDir = PsiManager.getInstance(project).findDirectory(virtualFile); svgPath.setText(virtualFile.getPath()); xmlName.setEditable(false); xmlName.setEnabled(false); xmlName.setText("keep origin name"); } } frame.setAlwaysOnTop(true); }
Example #11
Source File: RootWindow.java From WIFIADB with Apache License 2.0 | 6 votes |
private void specifyADBPath() { final String adbPath = Global.instance().adbPath(); final VirtualFile toSelect; if (Utils.isBlank(adbPath)) { toSelect = null; } else { toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(adbPath); } final VirtualFile vFile = FileChooser.chooseFile( FileChooserDescriptorFactory.createSingleFileOrFolderDescriptor(), Global.instance().project(), toSelect); if (vFile == null || !vFile.exists()) { return; } mPresenter.chooseADBPath(vFile); }
Example #12
Source File: MuleUIUtils.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
@Nullable public static MuleSdk selectSdk(@NotNull JComponent parentComponent) { final VirtualFile initial = findFile(System.getenv("MULE_HOME")); final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) { @Override public boolean isFileSelectable(VirtualFile file) { return super.isFileSelectable(file) && MuleSdk.isValidMuleHome(file.getCanonicalPath()); } }; descriptor.setTitle("Mule SDK"); descriptor.setDescription("Choose a directory containing Mule distribution"); final VirtualFile dir = FileChooser.chooseFile(descriptor, parentComponent, null, initial); if (dir == null || !MuleSdk.isValidMuleHome(dir.getCanonicalPath())) { return null; } return new MuleSdk(dir.getCanonicalPath()); }
Example #13
Source File: SendProjectFileAction.java From SmartIM4IntelliJ with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(AnActionEvent e) { if (!console.enableUpload()) { console.error("文件发送中,请勿频繁操作"); return; } FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, true, false, false); final VirtualFile virtualFile = FileChooser.chooseFile(descriptor, IMWindowFactory.getDefault().getProject(), null); if (virtualFile == null) { return; } String path = virtualFile.getCanonicalPath(); if (path != null) { console.send(path); } return; }
Example #14
Source File: SelectPathDialog.java From code-generator with Apache License 2.0 | 6 votes |
private void initBtn() { basePackageBtn.addActionListener(e -> { PackageChooser packageChooser = new PackageChooserDialog("Select Base Package", project); packageChooser.show(); PsiPackage psiPackage = packageChooser.getSelectedPackage(); if (Objects.nonNull(psiPackage)) { basePackageField.setText(psiPackage.getQualifiedName()); } }); outputPathBtn.addActionListener(e -> { FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false); VirtualFile virtualFile = FileChooser.chooseFile(descriptor, project, null); if (Objects.nonNull(virtualFile)) { outputPathField.setText(virtualFile.getPath()); } }); }
Example #15
Source File: PsiUtil.java From CodeGen with MIT License | 6 votes |
public static PsiDirectory createDirectory(Project project, String title, String description) { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); descriptor.setTitle(title); descriptor.setShowFileSystemRoots(false); descriptor.setDescription(description); descriptor.setHideIgnored(true); descriptor.setRoots(project.getBaseDir()); descriptor.setForcedToUseIdeaFileChooser(true); VirtualFile file = FileChooser.chooseFile(descriptor, project, project.getBaseDir()); if(Objects.isNull(file)){ Messages.showInfoMessage("Cancel " + title, "Error"); return null; } PsiDirectory psiDirectory = PsiDirectoryFactory.getInstance(project).createDirectory(file); if(PsiDirectoryFactory.getInstance(project).isPackage(psiDirectory)){ return psiDirectory; }else { Messages.showInfoMessage("请选择正确的 package 路径。", "Error"); return createDirectory(project, title, description); } }
Example #16
Source File: OpenSampleAction.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(AnActionEvent anActionEvent) { logger.debug("Loading sample!"); final Project project = anActionEvent.getProject(); final PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE); VirtualFile sample = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(), project, null); if (sample == null) return; try { final String text = new String(sample.contentsToByteArray(), sample.getCharset()); new WriteCommandAction.Simple(project, psiFile) { @Override protected void run() throws Throwable { document.setText(text); } }.execute(); } catch (Exception e) { logger.error(e); } }
Example #17
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 #18
Source File: PlaybackDebugger.java From consulo with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(AnActionEvent e) { if (pathToFile() == null) { VirtualFile selectedFile = FileChooser.chooseFile(FILE_DESCRIPTOR, myComponent, getEventProject(e), null); if (selectedFile != null) { myState.currentScript = selectedFile.getPresentableUrl(); myCurrentScript.setText(myState.currentScript); } else { Messages.showErrorDialog("File to save is not selected.", "Cannot save script"); return; } } ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { save(); } }); }
Example #19
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 #20
Source File: ApplyPatchDifferentiatedDialog.java From consulo with Apache License 2.0 | 5 votes |
public void run() { final FileChooserDescriptor descriptor = myDirectorySelector ? FileChooserDescriptorFactory.createSingleFolderDescriptor() : FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(); descriptor.setTitle(String.format("Select %s Base", myDirectorySelector ? "Directory" : "File")); VirtualFile selectedFile = FileChooser.chooseFile(descriptor, myProject, null); if (selectedFile == null) { return; } final List<AbstractFilePatchInProgress.PatchChange> selectedChanges = myChangesTreeList.getSelectedChanges(); if (selectedChanges.size() >= 1) { for (AbstractFilePatchInProgress.PatchChange patchChange : selectedChanges) { final AbstractFilePatchInProgress patch = patchChange.getPatchInProgress(); if (myDirectorySelector) { patch.setNewBase(selectedFile); } else { final FilePatch filePatch = patch.getPatch(); //if file was renamed in the patch but applied on another or already renamed local one then we shouldn't apply this rename/move filePatch.setAfterName(selectedFile.getName()); filePatch.setBeforeName(selectedFile.getName()); patch.setNewBase(selectedFile.getParent()); } } updateTree(false); } }
Example #21
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 #22
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 #23
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 #24
Source File: PlaybackDebugger.java From consulo with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(AnActionEvent e) { VirtualFile selectedFile = FileChooser.chooseFile(FILE_DESCRIPTOR, myComponent, getEventProject(e), pathToFile()); if (selectedFile != null) { myState.currentScript = selectedFile.getPresentableUrl(); loadFrom(selectedFile); myCurrentScript.setText(myState.currentScript); } }
Example #25
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 #26
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 #27
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 #28
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 #29
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 #30
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); }