com.intellij.openapi.fileChooser.FileChooserDescriptor Java Examples

The following examples show how to use com.intellij.openapi.fileChooser.FileChooserDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LibraryTypeServiceImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public NewLibraryConfiguration createLibraryFromFiles(@Nonnull LibraryRootsComponentDescriptor descriptor,
                                                      @Nonnull JComponent parentComponent,
                                                      @Nullable VirtualFile contextDirectory,
                                                      LibraryType<?> type,
                                                      final Project project) {
  final FileChooserDescriptor chooserDescriptor = descriptor.createAttachFilesChooserDescriptor(null);
  chooserDescriptor.setTitle("Select Library Files");
  final VirtualFile[] rootCandidates = FileChooser.chooseFiles(chooserDescriptor, parentComponent, project, contextDirectory);
  if (rootCandidates.length == 0) {
    return null;
  }

  final List<OrderRoot> roots = RootDetectionUtil.detectRoots(Arrays.asList(rootCandidates), parentComponent, project, descriptor);
  if (roots.isEmpty()) return null;
  String name = suggestLibraryName(roots);
  return doCreate(type, name, roots);
}
 
Example #2
Source File: PsiUtil.java    From CodeGen with MIT License 6 votes vote down vote up
public static PsiDirectory createDirectory(Project project, String title, String description) {
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    descriptor.setTitle(title);
    descriptor.setShowFileSystemRoots(false);
    descriptor.setDescription(description);
    descriptor.setHideIgnored(true);
    descriptor.setRoots(project.getBaseDir());
    descriptor.setForcedToUseIdeaFileChooser(true);
    VirtualFile file = FileChooser.chooseFile(descriptor, project, project.getBaseDir());
    if(Objects.isNull(file)){
        Messages.showInfoMessage("Cancel " + title, "Error");
        return null;
    }

    PsiDirectory psiDirectory = PsiDirectoryFactory.getInstance(project).createDirectory(file);
    if(PsiDirectoryFactory.getInstance(project).isPackage(psiDirectory)){
        return psiDirectory;
    }else {
        Messages.showInfoMessage("请选择正确的 package 路径。", "Error");
        return createDirectory(project, title, description);
    }
}
 
Example #3
Source File: PluginSettingsConfigurable.java    From IDEA-Native-Terminal-Plugin with MIT License 6 votes vote down vote up
public PluginSettingsConfigurable() {
    // Set 'chooseFolders' depend on OS, because macOS application represents a directory.
    terminalChooserDescriptor = new FileChooserDescriptor(true, OS.isMacOSX(), false, false, false, false);

    Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
    if (openProjects.length > 0) {
        project = openProjects[0];
    } else {
        project = ProjectManager.getInstance().getDefaultProject();
    }
    pluginSettingsForm = new PluginSettingsForm();
    pluginSettings = PluginSettings.getInstance();

    // FileChooserDialog support  -longforus
    String favoriteTerminal = "";
    if (pluginSettings.getState() != null) {
        favoriteTerminal = pluginSettings.getState().getFavoriteTerminal();
    }
    if (!TextUtils.isEmpty(favoriteTerminal)) {
        selectedTerminal = VirtualFileManager.getInstance().findFileByUrl(getFileUrl(favoriteTerminal));
    }

    pluginSettingsForm.getTerminalFileChooserButton().addActionListener(e -> {
        VirtualFile[] chosenTerminals = new FileChooserDialogImpl(terminalChooserDescriptor, project)
                .choose(project, selectedTerminal);

        if (chosenTerminals.length > 0) {
            VirtualFile file = chosenTerminals[0];
            if (file != null) {
                String canonicalPath = file.getCanonicalPath();
                Terminal terminal = Terminal.fromString(canonicalPath);
                if (terminal == Terminal.GENERIC) {
                    Messages.showWarningDialog(warningMessage, "Warning");
                }
                selectedTerminal = file;
                pluginSettingsForm.getFavoriteTerminalField().setText(canonicalPath);
            }
        }
    });
}
 
Example #4
Source File: PluginSettingTable.java    From ycy-intellij-plugin with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 添加表格行
 */
@Override
public void addRow() {
    FileChooserDescriptor descriptor = PluginSettingConfig.IMAGE_FILE_CHOOSER;
    FileChooserDialog dialog = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null);
    VirtualFile[] files = dialog.choose(null);
    List<String> chosenImageUrlList = Stream.of(files)
        .map(imageFile -> {
            try {
                return VfsUtil.toUri(imageFile).toURL().toString();
            } catch (MalformedURLException e) {
                LOG.error("parse the image \"" + imageFile.getName() + "\" to URL error", e);
                return null;
            }
        })
        .filter(Objects::nonNull)
        .filter(imageUrl -> !imageUrlList.contains(imageUrl))
        .collect(Collectors.toList());
    if (chosenImageUrlList.size() != 0) {
        imageUrlList.addAll(chosenImageUrlList);
        LOG.info("add rows: " + chosenImageUrlList);
        super.fireTableRowsInserted(imageUrlList.size() - 1 - files.length, imageUrlList.size() - 1);
    } else {
        LOG.info("choose no files");
    }
}
 
Example #5
Source File: GuiUtils.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static JPanel constructFileURLBrowserField(final TextFieldWithHistory field, final String objectName) {
  return constructFieldWithBrowseButton(field, new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      FileChooserDescriptor descriptor =
              FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor().withTitle("Select " + objectName);
      VirtualFile file = FileChooser.chooseFile(descriptor, field, null, null);
      if (file != null) {
        try {
          field.setText(VfsUtilCore.virtualToIoFile(file).toURI().toURL().toString());
        }
        catch (MalformedURLException e1) {
          field.setText("");
        }
      }
    }
  });
}
 
Example #6
Source File: Settings.java    From backgroundImagePlus with MIT License 6 votes vote down vote up
@Nullable
@Override
public JComponent createComponent() {
    FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    imageFolder.addBrowseFolderListener(new TextBrowseFolderListener(descriptor) {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = new JFileChooser();
            String current = imageFolder.getText();
            if (!current.isEmpty()) {
                fc.setCurrentDirectory(new File(current));
            }
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            fc.showOpenDialog(rootPanel);

            File file = fc.getSelectedFile();
            String path = file == null
                    ? ""
                    : file.getAbsolutePath();
            imageFolder.setText(path);
        }
    });
    autoChangeCheckBox.addActionListener(e -> intervalSpinner.setEnabled(autoChangeCheckBox.isSelected()));
    return rootPanel;
}
 
Example #7
Source File: OpenBlazeWorkspaceFileAction.java    From intellij with Apache License 2.0 6 votes vote down vote up
OpenBlazeWorkspaceFileActionDialog(
    Project project, WorkspacePathResolver workspacePathResolver) {
  super(project, /* canBeParent= */ false, IdeModalityType.PROJECT);
  this.project = project;

  component = new JPanel(new GridBagLayout());
  FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor();
  fileTextField =
      WorkspaceFileTextField.create(
          workspacePathResolver, descriptor, PATH_FIELD_WIDTH, myDisposable);

  component.add(new JBLabel("Path:"));
  component.add(fileTextField.getField(), UiUtil.getFillLineConstraints(0));

  UiUtil.fillBottom(component);
  init();
}
 
Example #8
Source File: ExportRunConfigurationDialog.java    From intellij with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #9
Source File: SimpleCreatePropertyQuickFix.java    From intellij-sdk-docs with Apache License 2.0 6 votes vote down vote up
@Override
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws
      IncorrectOperationException {
  ApplicationManager.getApplication().invokeLater(() -> {
    Collection<VirtualFile> virtualFiles =
          FileTypeIndex.getFiles(SimpleFileType.INSTANCE, GlobalSearchScope.allScope(project) );
    if (virtualFiles.size() == 1) {
      createProperty(project, virtualFiles.iterator().next());
    } else {
      final FileChooserDescriptor descriptor =
            FileChooserDescriptorFactory.createSingleFileDescriptor(SimpleFileType.INSTANCE);
      descriptor.setRoots(ProjectUtil.guessProjectDir(project));
      final VirtualFile file1 = FileChooser.chooseFile(descriptor, project, null);
      if (file1 != null) {
        createProperty(project, file1);
      }
    }
  });
}
 
Example #10
Source File: GaugeConfig.java    From Intellij-Plugin with Apache License 2.0 6 votes vote down vote up
JComponent createEditor() {
    FileChooserDescriptor homeFileDescriptor = new FileChooserDescriptor(false, true, false, false, false, false);
    homePath.addBrowseFolderListener(
            "",
            "Gauge Home Path",
            null,
            homeFileDescriptor,
            TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT);

    FileChooserDescriptor gaugePathFileDescriptor = new FileChooserDescriptor(true, false, false, false, false, false);
    gaugePath.addBrowseFolderListener(
            "",
            "Gauge Binary Path",
            null,
            gaugePathFileDescriptor,
            TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT);

    return configWindow;
}
 
Example #11
Source File: BaseCppRunSettingsEditor.java    From CppTools with Apache License 2.0 6 votes vote down vote up
protected void setupCommonUI(Project project) {
  ComboboxWithBrowseButton myExecutableName = getExecutableName();
  myExecutableName.getComboBox().setEditable(true);
  myExecutableName.addBrowseFolderListener(
    CHOOSE_EXECUTABLE_TITLE,
    CHOOSE_EXECUTABLE_TITLE,
    project,
    new FileChooserDescriptor(true, false, false, false, false, false) {
      @Override
      public boolean isFileSelectable(VirtualFile file) {
        return super.isFileSelectable(file);
      }
    },
    TextComponentAccessor.STRING_COMBOBOX_WHOLE_TEXT
  );
}
 
Example #12
Source File: SdkType.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public FileChooserDescriptor getHomeChooserDescriptor() {
  final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) {
    @Override
    public void validateSelectedFiles(VirtualFile[] files) throws Exception {
      if (files.length != 0) {
        final String selectedPath = files[0].getPath();
        boolean valid = isValidSdkHome(selectedPath);
        if (!valid) {
          valid = isValidSdkHome(adjustSelectedSdkHome(selectedPath));
          if (!valid) {
            String message = files[0].isDirectory()
                             ? ProjectBundle.message("sdk.configure.home.invalid.error", getPresentableName())
                             : ProjectBundle.message("sdk.configure.home.file.invalid.error", getPresentableName());
            throw new Exception(message);
          }
        }
      }
    }
  };
  descriptor.setTitle(ProjectBundle.message("sdk.configure.home.title", getPresentableName()));
  return descriptor;
}
 
Example #13
Source File: ExternalProjectPathField.java    From consulo with Apache License 2.0 5 votes vote down vote up
MyBrowseListener(@Nonnull final FileChooserDescriptor descriptor,
                 @Nonnull final String fileChooserTitle,
                 @Nonnull final Project project)
{
  descriptor.setTitle(fileChooserTitle);
  myDescriptor = descriptor;
  myProject = project;
}
 
Example #14
Source File: ContentEntriesEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public AddContentEntryAction() {
  super(ProjectBundle.message("module.paths.add.content.action"),
        ProjectBundle.message("module.paths.add.content.action.description"), AllIcons.Modules.AddContentEntry);
  myDescriptor = new FileChooserDescriptor(false, true, true, false, true, true) {
    @Override
    public void validateSelectedFiles(VirtualFile[] files) throws Exception {
      validateContentEntriesCandidates(files);
    }
  };
  myDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, getModule());
  myDescriptor.setTitle(ProjectBundle.message("module.paths.add.content.title"));
  myDescriptor.setDescription(ProjectBundle.message("module.paths.add.content.prompt"));
  myDescriptor.putUserData(FileChooserKeys.DELETE_ACTION_AVAILABLE, false);
}
 
Example #15
Source File: FileChooserTextBoxBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
public Controller(FileChooserTextBoxBuilder builder) {
  myAccessor = builder.myTextBoxAccessor;
  myProject = builder.myProject;
  myFileChooserDescriptor = builder.myFileChooserDescriptor;
  mySelectedFileMapper = builder.mySelectedFileMapper;

  myTextBox = TextBoxWithExtensions.create();
  if(!builder.myDisableCompletion) {
    FileChooserFactory.getInstance().installFileCompletion(myTextBox, myFileChooserDescriptor, true, builder.myDisposable);
  }

  myTextBox.setExtensions(new TextBoxWithExtensions.Extension(false, AllIcons.Nodes.CopyOfFolder, null, new Clickable.ClickListener() {
    @RequiredUIAccess
    @Override
    public void onClick() {
      FileChooserDescriptor fileChooserDescriptor = (FileChooserDescriptor)myFileChooserDescriptor.clone();
      fileChooserDescriptor.setTitle(builder.myDialogTitle);
      fileChooserDescriptor.setDescription(builder.myDialogDescription);

      String text = myAccessor.getValue(myTextBox);

      FileChooser.chooseFile(fileChooserDescriptor, myProject, mySelectedFileMapper.apply(text)).doWhenDone((f) -> {
        myAccessor.setValue(myTextBox, f.getPresentableUrl());
      });
    }
  }));

}
 
Example #16
Source File: FileChooser.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Shows file/folder open dialog, allows user to choose file/folder and then passes result to callback in EDT.
 *
 * @param descriptor file chooser descriptor
 * @param project    project
 * @param parent     parent component
 * @param toSelect   file to preselect
 */
@Nonnull
@RequiredUIAccess
public static AsyncResult<VirtualFile> chooseFile(@Nonnull final FileChooserDescriptor descriptor, @Nullable Project project, @Nullable Component parent, @Nullable VirtualFile toSelect) {
  LOG.assertTrue(!descriptor.isChooseMultiple());
  AsyncResult<VirtualFile> result = AsyncResult.undefined();

  AsyncResult<VirtualFile[]> filesAsync = chooseFiles(descriptor, project, parent, toSelect);
  filesAsync.doWhenDone((f) -> result.setDone(f[0]));
  filesAsync.doWhenRejected((Runnable)result::setRejected);
  return result;
}
 
Example #17
Source File: DirectoryCopyElementType.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public List<? extends DirectoryCopyPackagingElement> chooseAndCreate(@Nonnull ArtifactEditorContext context, @Nonnull Artifact artifact,
                                                                     @Nonnull CompositePackagingElement<?> parent) {
  final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createMultipleFoldersDescriptor();
  final VirtualFile[] files = FileChooser.chooseFiles(descriptor, context.getProject(), null);
  final List<DirectoryCopyPackagingElement> list = new ArrayList<DirectoryCopyPackagingElement>();
  for (VirtualFile file : files) {
    list.add(new DirectoryCopyPackagingElement(file.getPath()));
  }
  return list;
}
 
Example #18
Source File: ComponentWithBrowseButton.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void addBrowseFolderListener(@Nullable @Nls(capitalization = Nls.Capitalization.Title) String title,
                                    @Nullable @Nls(capitalization = Nls.Capitalization.Sentence) String description,
                                    @Nullable Project project,
                                    FileChooserDescriptor fileChooserDescriptor,
                                    TextComponentAccessor<Comp> accessor) {
  addActionListener(new BrowseFolderActionListener<>(title, description, this, project, fileChooserDescriptor, accessor));
}
 
Example #19
Source File: VirtualFileDiffElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Callable<DiffElement<VirtualFile>> getElementChooser(final Project project) {
  return () -> {
    final FileChooserDescriptor descriptor = getChooserDescriptor();
    final VirtualFile[] result = FileChooser.chooseFiles(descriptor, project, getValue());
    return result.length == 1 ? createElement(result[0]) : null;
  };
}
 
Example #20
Source File: ApplyPatchAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
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).doWhenDone(file -> {
      final VirtualFile parent = file.getParent();
      if (parent != null) {
        settings.PATCH_STORAGE_LOCATION = FileUtil.toSystemDependentName(parent.getPath());
      }
      showApplyPatch(project, file);
    });
  }
}
 
Example #21
Source File: BuckSettingsUI.java    From buck with Apache License 2.0 5 votes vote down vote up
private TextFieldWithBrowseButton createTextFieldWithBrowseButton(
    String emptyText, String title, String description, Project project) {
  JBTextField textField = new JBTextField();
  textField.getEmptyText().setText(emptyText);
  TextFieldWithBrowseButton field = new TextFieldWithBrowseButton(textField);
  FileChooserDescriptor fileChooserDescriptor =
      new FileChooserDescriptor(true, false, false, false, false, false);
  field.addBrowseFolderListener(
      title,
      description,
      project,
      fileChooserDescriptor,
      TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT);
  return field;
}
 
Example #22
Source File: ApplyPatchDifferentiatedDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static FileChooserDescriptor createSelectPatchDescriptor() {
  return new FileChooserDescriptor(true, false, false, false, false, false) {
    @Override
    public boolean isFileSelectable(VirtualFile file) {
      return file.getFileType() == PatchFileType.INSTANCE || file.getFileType() == PlainTextFileType.INSTANCE;
    }
  };
}
 
Example #23
Source File: ConfigANTLRPerGrammar.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void initAntlrFields(Project project, String qualFileName) {
	FileChooserDescriptor dirChooser =
			FileChooserDescriptorFactory.createSingleFolderDescriptor();
	outputDirField.addBrowseFolderListener("Select output dir", null, project, dirChooser);
	outputDirField.setTextFieldPreferredWidth(50);

	dirChooser =
			FileChooserDescriptorFactory.createSingleFolderDescriptor();
	libDirField.addBrowseFolderListener("Select lib dir", null, project, dirChooser);
	libDirField.setTextFieldPreferredWidth(50);

	loadValues(project, qualFileName);
}
 
Example #24
Source File: LibraryRootsComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected List<OrderRoot> selectRoots(@Nullable VirtualFile initialSelection) {
  final String name = getLibraryEditor().getName();
  final FileChooserDescriptor chooserDescriptor = myDescriptor.createAttachFilesChooserDescriptor(name);
  if (myContextModule != null) {
    chooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, myContextModule);
  }
  final VirtualFile[] files = FileChooser.chooseFiles(chooserDescriptor, myPanel, myProject, initialSelection);
  if (files.length == 0) return Collections.emptyList();

  return RootDetectionUtil.detectRoots(Arrays.asList(files), myPanel, myProject, myDescriptor);
}
 
Example #25
Source File: ApplyPatchDifferentiatedDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void run() {
  final FileChooserDescriptor descriptor = myDirectorySelector
                                           ? FileChooserDescriptorFactory.createSingleFolderDescriptor()
                                           : FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor();
  descriptor.setTitle(String.format("Select %s Base", myDirectorySelector ? "Directory" : "File"));
  VirtualFile selectedFile = FileChooser.chooseFile(descriptor, myProject, null);
  if (selectedFile == null) {
    return;
  }

  final List<AbstractFilePatchInProgress.PatchChange> selectedChanges = myChangesTreeList.getSelectedChanges();
  if (selectedChanges.size() >= 1) {
    for (AbstractFilePatchInProgress.PatchChange patchChange : selectedChanges) {
      final AbstractFilePatchInProgress patch = patchChange.getPatchInProgress();
      if (myDirectorySelector) {
        patch.setNewBase(selectedFile);
      }
      else {
        final FilePatch filePatch = patch.getPatch();
        //if file was renamed in the patch but applied on another or already renamed local one then we shouldn't apply this rename/move
        filePatch.setAfterName(selectedFile.getName());
        filePatch.setBeforeName(selectedFile.getName());
        patch.setNewBase(selectedFile.getParent());
      }
    }
    updateTree(false);
  }
}
 
Example #26
Source File: UserDefinedLibraryPanelGuiTest.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@Override
protected PanelTestingFrame getPanelTestingFrame() {
    panel = new UserDefinedLibraryPanel() {
        @Override
        protected void chooseFilesWithFileChooser(FileChooserDescriptor descriptor, Consumer<List<VirtualFile>>
                consumer) {
            fileChooserUsedToChooseFiles = true;
        }
    };
    return new PanelTestingFrame(panel.getMainPanel());
}
 
Example #27
Source File: GuiUtils.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static JPanel constructDirectoryBrowserField(final JTextField field, final String objectName) {
  return constructFieldWithBrowseButton(field, new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor().withTitle("Select " + objectName);
      VirtualFile file = FileChooser.chooseFile(descriptor, field, null, null);
      if (file != null) {
        field.setText(FileUtil.toSystemDependentName(file.getPath()));
        field.postActionEvent();
      }
    }
  });
}
 
Example #28
Source File: PsiUtil.java    From CodeGen with MIT License 5 votes vote down vote up
public static VirtualFile chooseFolder(@Nullable Project project, String title, String description, boolean showFileSystemRoots, boolean hideIgnored, @Nullable VirtualFile toSelect){
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    descriptor.setTitle(title);
    descriptor.setDescription(description);
    descriptor.setShowFileSystemRoots(showFileSystemRoots);
    descriptor.setHideIgnored(hideIgnored);
    return FileChooser.chooseFile(descriptor, project, toSelect);
}
 
Example #29
Source File: TextFieldWithHistoryWithBrowseButton.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void addBrowseFolderListener(@Nullable String title,
                                    @Nullable String description,
                                    @Nullable Project project,
                                    FileChooserDescriptor fileChooserDescriptor,
                                    TextComponentAccessor<TextFieldWithHistory> accessor,
                                    boolean autoRemoveOnHide) {
  super.addBrowseFolderListener(title, description, project, fileChooserDescriptor, accessor, autoRemoveOnHide);
  FileChooserFactory.getInstance().installFileCompletion(getChildComponent().getTextEditor(), fileChooserDescriptor, false, project);
}
 
Example #30
Source File: ExcludedEntriesConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void addPath(FileChooserDescriptor descriptor) {
  FileChooser.chooseFiles(descriptor, myProject, null).doWhenDone(chosen -> {
    int selected = -1 /*myExcludedTable.getSelectedRow() + 1*/;
    if (selected < 0) {
      selected = myExcludeEntryDescriptions.size();
    }
    int savedSelected = selected;

    for (final VirtualFile chosenFile : chosen) {
      if (isFileExcluded(chosenFile)) {
        continue;
      }
      ExcludeEntryDescription description;
      if (chosenFile.isDirectory()) {
        description = new ExcludeEntryDescription(chosenFile, true, false, myProject);
      }
      else {
        description = new ExcludeEntryDescription(chosenFile, false, true, myProject);
      }
      myExcludeEntryDescriptions.add(selected, description);
      selected++;
    }
    if (selected > savedSelected) { // actually added something
      AbstractTableModel model = (AbstractTableModel)myExcludedTable.getModel();
      model.fireTableRowsInserted(savedSelected, selected - 1);
      myExcludedTable.setRowSelectionInterval(savedSelected, selected - 1);
    }
  });
}