Java Code Examples for com.intellij.openapi.fileChooser.FileChooserDescriptor#setForcedToUseIdeaFileChooser()

The following examples show how to use com.intellij.openapi.fileChooser.FileChooserDescriptor#setForcedToUseIdeaFileChooser() . 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: 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 2
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 3
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);
}