use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.
the class BuildElementsEditor method createOutputPathPanel.
private CommitableFieldPanel createOutputPathPanel(final String title, final CommitPathRunnable commitPathRunnable) {
final JTextField textField = new JTextField();
final FileChooserDescriptor outputPathsChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
outputPathsChooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, getModel().getModule());
outputPathsChooserDescriptor.setHideIgnored(false);
InsertPathAction.addTo(textField, outputPathsChooserDescriptor);
FileChooserFactory.getInstance().installFileCompletion(textField, outputPathsChooserDescriptor, true, null);
final Runnable commitRunnable = () -> {
if (!getModel().isWritable()) {
return;
}
final String path = textField.getText().trim();
if (path.length() == 0) {
commitPathRunnable.saveUrl(null);
} else {
// should set only absolute paths
String canonicalPath;
try {
canonicalPath = FileUtil.resolveShortWindowsName(path);
} catch (IOException e) {
canonicalPath = path;
}
commitPathRunnable.saveUrl(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(canonicalPath)));
}
};
final ActionListener listener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
commitRunnable.run();
}
};
myPerModuleCompilerOutput.addActionListener(listener);
textField.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
commitRunnable.run();
}
});
return new CommitableFieldPanel(textField, null, null, new BrowseFilesListener(textField, title, "", outputPathsChooserDescriptor) {
@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
commitRunnable.run();
}
}, null, commitRunnable);
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.
the class ImportTestsFromFileAction method getFile.
@Nullable
@Override
public VirtualFile getFile(@NotNull Project project) {
final FileChooserDescriptor xmlDescriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(StdFileTypes.XML);
xmlDescriptor.setTitle("Choose a File with Tests Result");
return FileChooser.chooseFile(xmlDescriptor, project, null);
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.
the class ApplyPatchAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
if (ChangeListManager.getInstance(project).isFreezedWithNotification("Can not apply patch now"))
return;
FileDocumentManager.getInstance().saveAllDocuments();
VirtualFile vFile = null;
final String place = e.getPlace();
if (isProjectOrScopeView(place) || ActionPlaces.MAIN_MENU.equals(place)) {
vFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
}
if (isPatchFile(vFile)) {
showApplyPatch(project, vFile);
} else {
final FileChooserDescriptor descriptor = ApplyPatchDifferentiatedDialog.createSelectPatchDescriptor();
final VcsApplicationSettings settings = VcsApplicationSettings.getInstance();
final VirtualFile toSelect = settings.PATCH_STORAGE_LOCATION == null ? null : LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(settings.PATCH_STORAGE_LOCATION));
FileChooser.chooseFile(descriptor, project, toSelect, new Consumer<VirtualFile>() {
@Override
public void consume(VirtualFile file) {
final VirtualFile parent = file.getParent();
if (parent != null) {
settings.PATCH_STORAGE_LOCATION = parent.getPath();
}
showApplyPatch(project, file);
}
});
}
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor 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];
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-plugins by JetBrains.
the class AddAdapterSupportDialog method createSelectDirectoryPanel.
@NotNull
private JPanel createSelectDirectoryPanel(@NotNull Project project, @NotNull JTextField directoryTextField) {
FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
String adapterName = getAssertFrameworkAdapterName();
String title = "Select a directory for " + adapterName + " files";
String description = adapterName + " source files will be copied to the selected directory";
TextFieldWithBrowseButton directoryTextFieldWithBrowseButton = new TextFieldWithBrowseButton(directoryTextField);
directoryTextFieldWithBrowseButton.addBrowseFolderListener(title, description, project, fileChooserDescriptor);
Dimension oldDimension = directoryTextFieldWithBrowseButton.getPreferredSize();
directoryTextFieldWithBrowseButton.setMaximumSize(oldDimension);
JPanel panel = new JPanel(new BorderLayout(0, 2));
panel.add(new JLabel("Copy these files to directory:"), BorderLayout.NORTH);
panel.add(directoryTextFieldWithBrowseButton, BorderLayout.CENTER);
return SwingHelper.wrapWithHorizontalStretch(panel);
}
Aggregations