com.intellij.openapi.fileChooser.FileChooserFactory Java Examples

The following examples show how to use com.intellij.openapi.fileChooser.FileChooserFactory. 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: 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 #2
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 #3
Source File: RunAnythingChooseContextAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  Application.get().invokeLater(() -> {
    Project project = e.getProject();

    FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    descriptor.setUseApplicationDialog();

    PathChooserDialog chooser = FileChooserFactory.getInstance().createPathChooser(descriptor, project, e.getDataContext().getData(PlatformDataKeys.CONTEXT_COMPONENT));

    chooser.chooseAsync(project.getBaseDir()).doWhenDone(virtualFiles -> {
      List<String> recentDirectories = RunAnythingContextRecentDirectoryCache.getInstance(project).getState().paths;

      String path = ArrayUtil.getFirstElement(virtualFiles).getPath();

      if (recentDirectories.size() >= Registry.intValue("run.anything.context.recent.directory.number")) {
        recentDirectories.remove(0);
      }

      recentDirectories.add(path);

      setSelectedContext(new RunAnythingContext.RecentDirectoryContext(path));
    });
  });
}
 
Example #4
Source File: ToolEditorDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void addWorkingDirectoryBrowseAction(final JPanel pane,
                                               FixedSizeButton browseDirectoryButton,
                                               JTextField tfCommandWorkingDirectory) {
  browseDirectoryButton.addActionListener(
    new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
        PathChooserDialog chooser = FileChooserFactory.getInstance().createPathChooser(descriptor, myProject, pane);

        chooser.choose(null, new Consumer<List<VirtualFile>>() {
          @Override
          public void consume(List<VirtualFile> files) {
            VirtualFile file = files.size() > 0 ? files.get(0) : null;
            if (file != null) {
              myTfCommandWorkingDirectory.setText(file.getPresentableUrl());
            }
          }
        });
      }
    }
  );
}
 
Example #5
Source File: BuildElementsEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private CommitableFieldPanel createOutputPathPanel(final String title, final CommitPathRunnable commitPathRunnable) {
  final JTextField textField = new JTextField();
  final FileChooserDescriptor outputPathsChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
  outputPathsChooserDescriptor.setHideIgnored(false);
  InsertPathAction.addTo(textField, outputPathsChooserDescriptor);
  FileChooserFactory.getInstance().installFileCompletion(textField, outputPathsChooserDescriptor, true, null);

  CommitableFieldPanel commitableFieldPanel =
          new CommitableFieldPanel(textField, null, null, new BrowseFilesListener(textField, title, "", outputPathsChooserDescriptor), null);
  commitableFieldPanel.myCommitRunnable = new Runnable() {
    @Override
    public void run() {
      if (!getModel().isWritable()) {
        return;
      }
      String url = commitableFieldPanel.getUrl();
      commitPathRunnable.saveUrl(url);
    }
  };
  return commitableFieldPanel;
}
 
Example #6
Source File: CopyExternalProjectViewOption.java    From intellij with Apache License 2.0 5 votes vote down vote up
private void chooseWorkspacePath() {
  FileChooserDescriptor descriptor =
      new FileChooserDescriptor(true, false, false, false, false, false)
          .withShowHiddenFiles(true) // Show root project view file
          .withHideIgnored(false)
          .withTitle("Select Project View File")
          .withDescription("Select a project view file to import.")
          .withFileFilter(
              virtualFile ->
                  ProjectViewStorageManager.isProjectViewFile(new File(virtualFile.getPath())));
  // File filters are broken for the native Mac file chooser.
  descriptor.setForcedToUseIdeaFileChooser(true);
  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());
}
 
Example #7
Source File: ParseTreeContextualMenu.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static JMenuItem createExportMenuItem(UberTreeViewer parseTreeViewer, String label, boolean useTransparentBackground) {
    JMenuItem item = new JMenuItem(label);
    boolean isMacNativSaveDialog = SystemInfo.isMac && Registry.is("ide.mac.native.save.dialog");

    item.addActionListener(event -> {
        String[] extensions = useTransparentBackground ? new String[]{"png", "svg"} : new String[]{"png", "jpg", "svg"};
        FileSaverDescriptor descriptor = new FileSaverDescriptor("Export Image to", "Choose the destination file", extensions);
        FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(descriptor, (Project) null);

        String fileName = "parseTree" + (isMacNativSaveDialog ? ".png" : "");
        VirtualFileWrapper vf = dialog.save(null, fileName);

        if (vf == null) {
            return;
        }

        File file = vf.getFile();
        String imageFormat = FileUtilRt.getExtension(file.getName());
        if (StringUtils.isBlank(imageFormat)) {
            imageFormat = "png";
        }

        if ("svg".equals(imageFormat)) {
            exportToSvg(parseTreeViewer, file, useTransparentBackground);
        } else {
            exportToImage(parseTreeViewer, file, useTransparentBackground, imageFormat);
        }
    });

    return item;
}
 
Example #8
Source File: ToolEditorDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void addCommandBrowseAction(final JPanel pane, FixedSizeButton browseCommandButton, JTextField tfCommand) {
  browseCommandButton.addActionListener(
    new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileOrExecutableAppDescriptor();
        PathChooserDialog chooser = FileChooserFactory.getInstance().createPathChooser(descriptor, myProject, pane);
        chooser.choose(null, new Consumer<List<VirtualFile>>() {
          @Override
          public void consume(List<VirtualFile> files) {
            VirtualFile file = files.size() > 0 ? files.get(0) : null;
            if (file != null) {
              myTfCommand.setText(file.getPresentableUrl());
              String workingDirectory = myTfCommandWorkingDirectory.getText();
              if (workingDirectory == null || workingDirectory.length() == 0) {
                VirtualFile parent = file.getParent();
                if (parent != null && parent.isDirectory()) {
                  myTfCommandWorkingDirectory.setText(parent.getPresentableUrl());
                }
              }
            }
          }
        });
      }
    }
  );
}
 
Example #9
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 #10
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) {
  super.addBrowseFolderListener(title, description, project, fileChooserDescriptor, accessor);
  FileChooserFactory.getInstance().installFileCompletion(getChildComponent().getTextEditor(), fileChooserDescriptor, false, project);
}
 
Example #11
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 #12
Source File: CreatePatchConfigurationPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public CreatePatchConfigurationPanel(@Nonnull final Project project) {
  myProject = project;
  initMainPanel();

  myFileNameField.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      final FileSaverDialog dialog =
              FileChooserFactory.getInstance().createSaveFileDialog(
                      new FileSaverDescriptor("Save Patch to", ""), myMainPanel);
      final String path = FileUtil.toSystemIndependentName(getFileName());
      final int idx = path.lastIndexOf("/");
      VirtualFile baseDir = idx == -1 ? project.getBaseDir() :
                            (LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(path.substring(0, idx))));
      baseDir = baseDir == null ? project.getBaseDir() : baseDir;
      final String name = idx == -1 ? path : path.substring(idx + 1);
      final VirtualFileWrapper fileWrapper = dialog.save(baseDir, name);
      if (fileWrapper != null) {
        myFileNameField.setText(fileWrapper.getFile().getPath());
      }
    }
  });

  myFileNameField.setTextFieldPreferredWidth(TEXT_FIELD_WIDTH);
  myBasePathField.setTextFieldPreferredWidth(TEXT_FIELD_WIDTH);
  myBasePathField.addBrowseFolderListener(new TextBrowseFolderListener(FileChooserDescriptorFactory.createSingleFolderDescriptor()));
  myWarningLabel.setForeground(JBColor.RED);
  selectBasePath(ObjectUtils.assertNotNull(myProject.getBaseDir()));
  initEncodingCombo();
}
 
Example #13
Source File: MoveFilesOrDirectoriesDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected JComponent createNorthPanel() {
  myNameLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true);

  myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton();
  final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS);
  if (recentEntries != null) {
    myTargetDirectoryField.getChildComponent().setHistory(recentEntries);
  }
  final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
  myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"),
                                                 RefactoringBundle.message("the.file.will.be.moved.to.this.directory"),
                                                 myProject,
                                                 descriptor,
                                                 TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);
  final JTextField textField = myTargetDirectoryField.getChildComponent().getTextEditor();
  FileChooserFactory.getInstance().installFileCompletion(textField, descriptor, true, getDisposable());
  textField.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      validateOKButton();
    }
  });
  myTargetDirectoryField.setTextFieldPreferredWidth(CopyFilesOrDirectoriesDialog.MAX_PATH_LENGTH);
  Disposer.register(getDisposable(), myTargetDirectoryField);

  String shortcutText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION));

  myCbSearchForReferences = new NonFocusableCheckBox(RefactoringBundle.message("search.for.references"));
  myCbSearchForReferences.setSelected(RefactoringSettings.getInstance().MOVE_SEARCH_FOR_REFERENCES_FOR_FILE);

  myOpenInEditorCb = new NonFocusableCheckBox("Open moved files in editor");
  myOpenInEditorCb.setSelected(isOpenInEditor());

  return FormBuilder.createFormBuilder().addComponent(myNameLabel)
          .addLabeledComponent(RefactoringBundle.message("move.files.to.directory.label"), myTargetDirectoryField, UIUtil.LARGE_VGAP)
          .addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText))
          .addComponentToRightColumn(myCbSearchForReferences, UIUtil.LARGE_VGAP)
          .addComponentToRightColumn(myOpenInEditorCb, UIUtil.LARGE_VGAP)
          .getPanel();
}
 
Example #14
Source File: ExportToHTMLDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected JComponent createNorthPanel() {
  OptionGroup optionGroup = new OptionGroup();

  myRbCurrentFile = new JRadioButton(CodeEditorBundle.message("export.to.html.file.name.radio", (myFileName != null ? myFileName : "")));
  optionGroup.add(myRbCurrentFile);

  myRbSelectedText = new JRadioButton(CodeEditorBundle.message("export.to.html.selected.text.radio"));
  optionGroup.add(myRbSelectedText);

  myRbCurrentPackage = new JRadioButton(
    CodeEditorBundle.message("export.to.html.all.files.in.directory.radio", (myDirectoryName != null ? myDirectoryName : "")));
  optionGroup.add(myRbCurrentPackage);

  myCbIncludeSubpackages = new JCheckBox(CodeEditorBundle.message("export.to.html.include.subdirectories.checkbox"));
  optionGroup.add(myCbIncludeSubpackages, true);

  FileTextField field = FileChooserFactory.getInstance().createFileTextField(FileChooserDescriptorFactory.createSingleFolderDescriptor(), myDisposable);
  myTargetDirectoryField = new TextFieldWithBrowseButton(field.getField());
  LabeledComponent<TextFieldWithBrowseButton> labeledComponent = assignLabel(myTargetDirectoryField, myProject);

  optionGroup.add(labeledComponent);

  ButtonGroup buttonGroup = new ButtonGroup();
  buttonGroup.add(myRbCurrentFile);
  buttonGroup.add(myRbSelectedText);
  buttonGroup.add(myRbCurrentPackage);

  ActionListener actionListener = new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      myCbIncludeSubpackages.setEnabled(myRbCurrentPackage.isSelected());
    }
  };

  myRbCurrentFile.addActionListener(actionListener);
  myRbSelectedText.addActionListener(actionListener);
  myRbCurrentPackage.addActionListener(actionListener);

  return optionGroup.createPanel();
}
 
Example #15
Source File: ProjectConfigurable.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void init() {
  myPanel = new JPanel(new VerticalFlowLayout(true, false));

  final JPanel namePanel = new JPanel(new BorderLayout());
  final JLabel label = new JLabel("<html><body><b>Project name:</b></body></html>", SwingConstants.LEFT);
  namePanel.add(label, BorderLayout.NORTH);

  myProjectName = new JTextField();
  myProjectName.setColumns(40);

  final JPanel nameFieldPanel = new JPanel();
  nameFieldPanel.setLayout(new BoxLayout(nameFieldPanel, BoxLayout.X_AXIS));
  nameFieldPanel.add(Box.createHorizontalStrut(4));
  nameFieldPanel.add(myProjectName);

  namePanel.add(nameFieldPanel, BorderLayout.CENTER);
  final JPanel wrapper = new JPanel(new FlowLayout(FlowLayout.LEFT));
  wrapper.add(namePanel);
  wrapper.setAlignmentX(0);
  myPanel.add(wrapper);

  myPanel.add(new JLabel(ProjectBundle.message("project.compiler.output")));

  final JTextField textField = new JTextField();
  final FileChooserDescriptor outputPathsChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
  InsertPathAction.addTo(textField, outputPathsChooserDescriptor);
  outputPathsChooserDescriptor.setHideIgnored(false);
  BrowseFilesListener listener = new BrowseFilesListener(textField, "", ProjectBundle.message("project.compiler.output"), outputPathsChooserDescriptor);
  myProjectCompilerOutput = new FieldPanel(textField, null, null, listener, EmptyRunnable.getInstance());
  FileChooserFactory.getInstance().installFileCompletion(myProjectCompilerOutput.getTextField(), outputPathsChooserDescriptor, true, null);

  myProjectCompilerOutput.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      if (myFreeze) return;
      myModulesConfigurator.processModuleCompilerOutputChanged(getCompilerOutputUrl());
    }
  });

  myPanel.add(myProjectCompilerOutput);
  myPanel.add(ScrollPaneFactory.createScrollPane(myErrorsComponent, true));
}
 
Example #16
Source File: TextFieldWithBrowseButton.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void installPathCompletion(final FileChooserDescriptor fileChooserDescriptor,
                                     @Nullable Disposable parent) {
  final Application application = ApplicationManager.getApplication();
  if (application == null || application.isUnitTestMode() || application.isHeadlessEnvironment()) return;
  FileChooserFactory.getInstance().installFileCompletion(getChildComponent(), fileChooserDescriptor, true, parent);
}
 
Example #17
Source File: FileChooser.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@RequiredUIAccess
public static AsyncResult<VirtualFile[]> chooseFiles(@Nonnull FileChooserDescriptor descriptor, @Nullable Component parent, @Nullable Project project, @Nullable VirtualFile toSelect) {
  final FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, project, parent);
  return chooser.chooseAsync(project, toSelect == null ? VirtualFile.EMPTY_ARRAY : new VirtualFile[]{toSelect});
}
 
Example #18
Source File: ImportFromWorkspaceProjectViewOption.java    From intellij with Apache License 2.0 4 votes vote down vote up
private void chooseWorkspacePath() {
  FileChooserDescriptor descriptor =
      new FileChooserDescriptor(true, false, false, false, false, false)
          .withShowHiddenFiles(true) // Show root project view file
          .withHideIgnored(false)
          .withTitle("Select Project View File")
          .withDescription("Select a project view file to import.")
          .withFileFilter(
              virtualFile ->
                  ProjectViewStorageManager.isProjectViewFile(new File(virtualFile.getPath())));
  // File filters are broken for the native Mac file chooser.
  descriptor.setForcedToUseIdeaFileChooser(true);
  FileChooserDialog chooser =
      FileChooserFactory.getInstance().createFileChooser(descriptor, null, null);

  WorkspacePathResolver workspacePathResolver =
      builder.getWorkspaceData().workspacePathResolver();
  File fileBrowserRoot = builder.getWorkspaceData().fileBrowserRoot();
  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(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.startsWith(file.getPath(), fileBrowserRoot.getPath())) {
    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(fileBrowserRoot, new File(file.getPath()));
  projectViewPathField.setText(newWorkspacePath);
}
 
Example #19
Source File: FileChooser.java    From consulo with Apache License 2.0 3 votes vote down vote up
/**
 * Shows file/folder open dialog, allows user to choose files/folders and then passes result to callback in EDT.
 * On MacOS Open Dialog will be shown with slide effect if Macish UI is turned on.
 *
 * @param descriptor file chooser descriptor
 * @param project    project
 * @param parent     parent component
 * @param toSelect   file to preselect
 */
@Nonnull
@RequiredUIAccess
public static AsyncResult<VirtualFile[]> chooseFiles(@Nonnull FileChooserDescriptor descriptor, @Nullable Project project, @Nullable Component parent, @Nullable VirtualFile toSelect) {
  final FileChooserFactory factory = FileChooserFactory.getInstance();
  final PathChooserDialog pathChooser = factory.createPathChooser(descriptor, project, parent);
  return pathChooser.chooseAsync(toSelect);
}