use of com.intellij.ide.util.TreeFileChooser in project intellij-plugins by JetBrains.
the class DartCommandLineConfigurationEditorForm method initDartFileTextWithBrowse.
public static void initDartFileTextWithBrowse(@NotNull final Project project, @NotNull final TextFieldWithBrowseButton textWithBrowse) {
textWithBrowse.getButton().addActionListener(e -> {
final String initialPath = FileUtil.toSystemIndependentName(textWithBrowse.getText().trim());
final VirtualFile initialFile = initialPath.isEmpty() ? null : LocalFileSystem.getInstance().findFileByPath(initialPath);
final PsiFile initialPsiFile = initialFile == null ? null : PsiManager.getInstance(project).findFile(initialFile);
TreeFileChooser fileChooser = TreeFileChooserFactory.getInstance(project).createFileChooser(DartBundle.message("choose.dart.main.file"), initialPsiFile, DartFileType.INSTANCE, file -> !DartWritingAccessProvider.isInDartSdkOrDartPackagesFolder(file));
fileChooser.showDialog();
final PsiFile selectedFile = fileChooser.getSelectedFile();
final VirtualFile virtualFile = selectedFile == null ? null : selectedFile.getVirtualFile();
if (virtualFile != null) {
final String path = FileUtil.toSystemDependentName(virtualFile.getPath());
textWithBrowse.setText(path);
}
});
}
Aggregations