Java Code Examples for com.intellij.openapi.fileChooser.FileChooser#chooseFile()
The following examples show how to use
com.intellij.openapi.fileChooser.FileChooser#chooseFile() .
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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
Source File: InstallSdkAction.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override void perform() { // Defaults to ~/flutter final FileChooserDescriptor descriptor = new FileChooserDescriptor(FileChooserDescriptorFactory.createSingleFolderDescriptor()) { @Override public void validateSelectedFiles(@NotNull VirtualFile[] files) { for (VirtualFile file : files) { // Eliminate some false positives, which occurs when an existing directory is deleted. VfsUtil.markDirtyAndRefresh(false, true, true, file); if (file.findChild("flutter") != null) { throw new IllegalArgumentException("A file called 'flutter' already exists in this location."); } } } }.withTitle("Flutter SDK Directory").withDescription("Choose a directory to install the Flutter SDK"); final VirtualFile installTarget = FileChooser.chooseFile(descriptor, null, null); if (installTarget != null) { FlutterInitializer.sendAnalyticsAction(ANALYTICS_KEY); installTo(installTarget); } else { // A valid SDK may have been deleted before the FileChooser was cancelled. validatePeer(); } }
Example 13
Source File: InstallSdkAction.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override void perform() { // Defaults to ~/flutter final FileChooserDescriptor descriptor = new FileChooserDescriptor(FileChooserDescriptorFactory.createSingleFolderDescriptor()) { @Override public void validateSelectedFiles(@NotNull VirtualFile[] files) { for (VirtualFile file : files) { // Eliminate some false positives, which occurs when an existing directory is deleted. VfsUtil.markDirtyAndRefresh(false, true, true, file); if (file.findChild("flutter") != null) { throw new IllegalArgumentException("A file called 'flutter' already exists in this location."); } } } }.withTitle("Flutter SDK Directory").withDescription("Choose a directory to install the Flutter SDK"); final VirtualFile installTarget = FileChooser.chooseFile(descriptor, null, null); if (installTarget != null) { FlutterInitializer.sendAnalyticsAction(ANALYTICS_KEY); installTo(installTarget); } else { // A valid SDK may have been deleted before the FileChooser was cancelled. validatePeer(); } }
Example 14
Source File: ProfilerSettingsDialog.java From idea-php-symfony2-plugin with MIT License | 5 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); String text = textField.getText(); VirtualFile toSelect = VfsUtil.findRelativeFile(text, projectDirectory); if(toSelect == null) { toSelect = projectDirectory; } VirtualFile selectedFile = FileChooser.chooseFile( FileChooserDescriptorFactory.createSingleFileDescriptor("csv"), project, toSelect ); if (null == selectedFile) { return; } String path = VfsUtil.getRelativePath(selectedFile, projectDirectory, '/'); if (null == path) { path = selectedFile.getPath(); } textField.setText(path); } }; }
Example 15
Source File: PsiUtil.java From CodeGen with MIT License | 5 votes |
public static VirtualFile chooseFile(@Nullable Project project, String title, String description, boolean showFileSystemRoots, boolean hideIgnored, @Nullable VirtualFile toSelect){ final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(); descriptor.setTitle(title); descriptor.setDescription(description); descriptor.setShowFileSystemRoots(showFileSystemRoots); descriptor.setHideIgnored(hideIgnored); return FileChooser.chooseFile(descriptor, project, toSelect); }
Example 16
Source File: ThriftFacetConf.java From intellij-thrift with Apache License 2.0 | 5 votes |
@Nullable @Override protected VirtualFile editItem(VirtualFile selected) { VirtualFile file = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(), this, myContext.getProject(), selected); if (file == null) { return null; } else { setModified(); return file; } }
Example 17
Source File: ImportTestsFromFileAction.java From consulo with Apache License 2.0 | 5 votes |
@Nullable @Override public VirtualFile getFile(@Nonnull Project project) { final FileChooserDescriptor xmlDescriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor().withFileFilter(virtualFile -> "xml".equals(virtualFile.getExtension())); xmlDescriptor.setTitle("Choose a File with Tests Result"); return FileChooser.chooseFile(xmlDescriptor, project, null); }
Example 18
Source File: PsiUtil.java From CodeGen with MIT License | 5 votes |
public static VirtualFile chooseFolder(@Nullable Project project, String title, String description, boolean showFileSystemRoots, boolean hideIgnored, @Nullable VirtualFile toSelect){ final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); descriptor.setTitle(title); descriptor.setDescription(description); descriptor.setShowFileSystemRoots(showFileSystemRoots); descriptor.setHideIgnored(hideIgnored); return FileChooser.chooseFile(descriptor, project, toSelect); }
Example 19
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 20
Source File: ViewOfflineResultsAction.java From consulo with Apache License 2.0 | 4 votes |
@Override public void actionPerformed(AnActionEvent event) { final Project project = event.getData(CommonDataKeys.PROJECT); LOG.assertTrue(project != null); final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false){ @Override public Image getIcon(VirtualFile file) { if (file.isDirectory()) { if (file.findChild(InspectionApplication.DESCRIPTIONS + ".xml") != null) { return AllIcons.Nodes.InspectionResults; } } return super.getIcon(file); } }; descriptor.setTitle("Select Path"); descriptor.setDescription("Select directory which contains exported inspections results"); final VirtualFile virtualFile = FileChooser.chooseFile(descriptor, project, null); if (virtualFile == null || !virtualFile.isDirectory()) return; final Map<String, Map<String, Set<OfflineProblemDescriptor>>> resMap = new HashMap<String, Map<String, Set<OfflineProblemDescriptor>>>(); final String [] profileName = new String[1]; final Runnable process = new Runnable() { @Override public void run() { final VirtualFile[] files = virtualFile.getChildren(); try { for (final VirtualFile inspectionFile : files) { if (inspectionFile.isDirectory()) continue; final String shortName = inspectionFile.getNameWithoutExtension(); final String extension = inspectionFile.getExtension(); if (shortName.equals(InspectionApplication.DESCRIPTIONS)) { profileName[0] = ApplicationManager.getApplication().runReadAction( new Computable<String>() { @Override @Nullable public String compute() { return OfflineViewParseUtil.parseProfileName(inspectionFile); } } ); } else if (XML_EXTENSION.equals(extension)) { resMap.put(shortName, ApplicationManager.getApplication().runReadAction( new Computable<Map<String, Set<OfflineProblemDescriptor>>>() { @Override public Map<String, Set<OfflineProblemDescriptor>> compute() { return OfflineViewParseUtil.parse(inspectionFile); } } )); } } } catch (final Exception e) { //all parse exceptions SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Messages.showInfoMessage(e.getMessage(), InspectionsBundle.message("offline.view.parse.exception.title")); } }); throw new ProcessCanceledException(); //cancel process } } }; ProgressManager.getInstance().runProcessWithProgressAsynchronously(project, InspectionsBundle.message("parsing.inspections.dump.progress.title"), process, new Runnable() { @Override public void run() { SwingUtilities.invokeLater(new Runnable(){ @Override public void run() { final String name = profileName[0]; showOfflineView(project, name, resMap, InspectionsBundle.message("offline.view.title") + " (" + (name != null ? name : InspectionsBundle.message("offline.view.editor.settings.title")) +")"); } }); } }, null, new PerformAnalysisInBackgroundOption(project)); }