Search in sources :

Example 1 with TreeFileChooser

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);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TreeFileChooser(com.intellij.ide.util.TreeFileChooser) PsiFile(com.intellij.psi.PsiFile)

Aggregations

TreeFileChooser (com.intellij.ide.util.TreeFileChooser)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1