use of com.intellij.openapi.fileChooser.FileChooserDialog in project intellij-community by JetBrains.
the class ImportModuleAction method selectFileAndCreateWizard.
@Nullable
public static AddModuleWizard selectFileAndCreateWizard(@Nullable Project project, @Nullable Component dialogParent, @NotNull FileChooserDescriptor descriptor, ProjectImportProvider[] providers) {
FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, project, dialogParent);
VirtualFile toSelect = null;
String lastLocation = PropertiesComponent.getInstance().getValue(LAST_IMPORTED_LOCATION);
if (lastLocation != null) {
toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(lastLocation);
}
VirtualFile[] files = chooser.choose(project, toSelect);
if (files.length == 0) {
return null;
}
final VirtualFile file = files[0];
if (project == null) {
// wizard will create a new project
for (Project p : ProjectManager.getInstance().getOpenProjects()) {
if (ProjectUtil.isSameProject(file.getPath(), p)) {
ProjectUtil.focusProjectWindow(p, false);
return null;
}
}
}
PropertiesComponent.getInstance().setValue(LAST_IMPORTED_LOCATION, file.getPath());
return createImportWizard(project, dialogParent, file, providers);
}
use of com.intellij.openapi.fileChooser.FileChooserDialog in project azure-tools-for-java by Microsoft.
the class StorageChooser method chooseFile.
public VirtualFile[] chooseFile() {
Component parentComponent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
final FileChooserDialog chooser = new StorageChooserDialogImpl(this.descriptor, parentComponent, null);
return chooser.choose(null, this.root);
}
use of com.intellij.openapi.fileChooser.FileChooserDialog in project intellij by bazelbuild.
the class CopyExternalProjectViewOption method chooseWorkspacePath.
private void chooseWorkspacePath() {
FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false).withShowHiddenFiles(// Show root project view file
true).withHideIgnored(false).withTitle("Select Project View File").withDescription("Select a project view file to import.").withFileFilter(virtualFile -> ProjectViewStorageManager.isProjectViewFile(new File(virtualFile.getPath())));
FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null);
File startingLocation = null;
String projectViewPath = getProjectViewPath();
if (!projectViewPath.isEmpty()) {
File fileLocation = new File(projectViewPath);
if (fileLocation.exists()) {
startingLocation = fileLocation;
}
}
final VirtualFile[] files;
if (startingLocation != null) {
VirtualFile toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(startingLocation.getPath());
files = chooser.choose(null, toSelect);
} else {
files = chooser.choose(null);
}
if (files.length == 0) {
return;
}
VirtualFile file = files[0];
projectViewPathField.setText(file.getPath());
}
use of com.intellij.openapi.fileChooser.FileChooserDialog in project intellij by bazelbuild.
the class ImportFromWorkspaceProjectViewOption method chooseWorkspacePath.
private void chooseWorkspacePath() {
FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false).withShowHiddenFiles(// Show root project view file
true).withHideIgnored(false).withTitle("Select Project View File").withDescription("Select a project view file to import.").withFileFilter(virtualFile -> ProjectViewStorageManager.isProjectViewFile(new File(virtualFile.getPath())));
FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null);
WorkspacePathResolver workspacePathResolver = builder.getWorkspaceOption().getWorkspacePathResolver();
File fileBrowserRoot = builder.getWorkspaceOption().getFileBrowserRoot();
File startingLocation = fileBrowserRoot;
String projectViewPath = getProjectViewPath();
if (!projectViewPath.isEmpty()) {
// If the user has typed part of the path then clicked the '...', try to start from the
// partial state
projectViewPath = StringUtil.trimEnd(projectViewPath, '/');
if (WorkspacePath.isValid(projectViewPath)) {
File fileLocation = workspacePathResolver.resolveToFile(new WorkspacePath(projectViewPath));
if (fileLocation.exists() && FileUtil.isAncestor(getCanonicalPathSafe(fileBrowserRoot), getCanonicalPathSafe(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(getCanonicalPathSafe(fileBrowserRoot), getCanonicalPathSafe(file), true)) {
Messages.showErrorDialog(String.format("You must choose a project view file under %s. " + "To use an external project view, please use the 'Copy external' option.", fileBrowserRoot.getPath()), "Cannot Use Project View File");
return;
}
String newWorkspacePath = FileUtil.getRelativePath(getCanonicalPathSafe(fileBrowserRoot), getCanonicalPathSafe(new File(file.getPath())), File.separatorChar);
projectViewPathField.setText(newWorkspacePath);
}
use of com.intellij.openapi.fileChooser.FileChooserDialog in project intellij by bazelbuild.
the class UseExistingBazelWorkspaceOption method chooseDirectory.
private void chooseDirectory() {
FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) {
@Override
public boolean isFileSelectable(VirtualFile file) {
// we want to make sure only workspace roots are selectable
return super.isFileSelectable(file) && isWorkspaceRoot(file);
}
}.withHideIgnored(false).withTitle("Select Workspace Root").withDescription("Select the directory of the workspace you want to use.").withFileFilter(UseExistingBazelWorkspaceOption::isWorkspaceRoot);
FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null);
final VirtualFile[] files;
File existingLocation = new File(getDirectory());
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];
directoryField.setText(file.getPath());
}
Aggregations