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];
}
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);
}
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());
}
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);
}
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);
}
}
Aggregations