Java Code Examples for com.intellij.openapi.fileChooser.FileChooserDescriptor

The following examples show how to use com.intellij.openapi.fileChooser.FileChooserDescriptor. These examples are extracted from open source projects. 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
/**
 * 添加表格行
 */
@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 Project: CodeGen   Source File: PsiUtil.java    License: 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 Project: consulo   Source File: GuiUtils.java    License: 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 4
Source Project: backgroundImagePlus   Source File: Settings.java    License: 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 5
Source Project: intellij   Source File: OpenBlazeWorkspaceFileAction.java    License: 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 6
Source Project: intellij   Source File: ExportRunConfigurationDialog.java    License: 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 7
@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 8
Source Project: Intellij-Plugin   Source File: GaugeConfig.java    License: 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 9
Source Project: CppTools   Source File: BaseCppRunSettingsEditor.java    License: 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 10
Source Project: consulo   Source File: SdkType.java    License: 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 11
Source Project: consulo   Source File: LibraryTypeServiceImpl.java    License: 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 12
Source Project: consulo   Source File: LibraryRootsComponent.java    License: 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 13
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 14
Source Project: CodeGen   Source File: PsiUtil.java    License: 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 15
Source Project: CodeGen   Source File: PsiUtil.java    License: MIT License 5 votes vote down vote up
public static VirtualFile chooseFile(@Nullable Project project, String title, String description, boolean showFileSystemRoots, boolean hideIgnored, @Nullable VirtualFile toSelect){
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor();
    descriptor.setTitle(title);
    descriptor.setDescription(description);
    descriptor.setShowFileSystemRoots(showFileSystemRoots);
    descriptor.setHideIgnored(hideIgnored);
    return FileChooser.chooseFile(descriptor, project, toSelect);
}
 
Example 16
Source Project: PackageTemplates   Source File: FileReaderUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static FileChooserDescriptor getPackageTemplatesDescriptor() {
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false);
    descriptor.withFileFilter(file -> {
        if (file.getExtension() == null) {
            return false;
        }

        return file.getExtension().toLowerCase().equals(Const.PACKAGE_TEMPLATES_EXTENSION);
    });
    return descriptor;
}
 
Example 17
private static boolean acceptAll(FileChooserDescriptor descriptor, Collection<VirtualFile> files) {
  for (VirtualFile file : files) {
    if (!descriptor.isFileSelectable(file) || !descriptor.isFileVisible(file, true)) {
      return false;
    }
  }
  return true;
}
 
Example 18
Source Project: intellij   Source File: CopyExternalProjectViewOption.java    License: 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 19
Source Project: intellij   Source File: WorkspaceFileTextField.java    License: Apache License 2.0 5 votes vote down vote up
public static FileTextField create(
    WorkspacePathResolver pathResolver,
    FileChooserDescriptor descriptor,
    int columns,
    Disposable parent) {
  JTextField textField = new WorkspacePathTextField(pathResolver, columns);
  return new WorkspaceFileTextField(
      pathResolver, textField, new FileChooserFilter(descriptor, /* showHidden= */ true), parent);
}
 
Example 20
Source Project: consulo   Source File: LibraryRootsComponent.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createMultipleJavaPathDescriptor();
  descriptor.setTitle("Exclude from Library");
  descriptor.setDescription("Select directories which should be excluded from the library content. Content of excluded directories won't be processed by IDE.");
  Set<VirtualFile> roots = getNotExcludedRoots();
  descriptor.setRoots(roots.toArray(new VirtualFile[roots.size()]));
  if (roots.size() < 2) {
    descriptor.setIsTreeRootVisible(true);
  }
  VirtualFile toSelect = null;
  for (Object o : getSelectedElements()) {
    Object itemElement = o instanceof ExcludedRootElement ? ((ExcludedRootElement)o).getParentDescriptor() : o;
    if (itemElement instanceof ItemElement) {
      toSelect = VirtualFileManager.getInstance().findFileByUrl(((ItemElement)itemElement).getUrl());
      break;
    }
  }
  final VirtualFile[] files = FileChooser.chooseFiles(descriptor, myPanel, myProject, toSelect);
  if (files.length > 0) {
    ApplicationManager.getApplication().runWriteAction(new Runnable() {
      @Override
      public void run() {
        for (VirtualFile file : files) {
          getLibraryEditor().addExcludedRoot(file.getUrl());
        }
      }
    });
    myLastChosen = files[0];
    libraryChanged(true);
  }
}
 
Example 21
Source Project: azure-devops-intellij   Source File: SimpleCheckoutForm.java    License: MIT License 5 votes vote down vote up
private void ensureInitialized() {
    if (!initialized) {

        // Setup folder browser
        parentDirectory.getInsets().right = 0;
        parentDirectory.addBrowseFolderListener(
                TfPluginBundle.message(TfPluginBundle.KEY_CHECKOUT_DIALOG_PARENT_FOLDER_DIALOG_TITLE), null, null,
                new FileChooserDescriptor(false, true, false, false, false, false));

        initialized = true;
    }
}
 
Example 22
Source Project: consulo   Source File: DesktopFileChooseDialogProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public FileChooserDialog createFileChooser(@Nonnull FileChooserDescriptor descriptor, @Nullable Project project, @Nullable Component parent) {
  if (parent != null) {
    return new FileChooserDialogImpl(descriptor, parent, project);
  }
  else {
    return new FileChooserDialogImpl(descriptor, project);
  }
}
 
Example 23
Source Project: consulo   Source File: FileSystemTreeImpl.java    License: Apache License 2.0 5 votes vote down vote up
protected AbstractTreeBuilder createTreeBuilder(final JTree tree,
                                                DefaultTreeModel treeModel,
                                                final AbstractTreeStructure treeStructure,
                                                final Comparator<NodeDescriptor> comparator,
                                                FileChooserDescriptor descriptor,
                                                @Nullable final Runnable onInitialized) {
  return new FileTreeBuilder(tree, treeModel, treeStructure, comparator, descriptor, onInitialized);
}
 
Example 24
Source Project: consulo   Source File: NamePathComponent.java    License: Apache License 2.0 5 votes vote down vote up
public NamePathComponent(String nameLabelText, String pathLabelText, final String pathChooserTitle, final String pathChooserDescription, boolean hideIgnored, boolean bold) {
  super(new GridBagLayout());

  myTfName = new JTextField();
  myTfName.setDocument(new NameFieldDocument());
  myTfName.setPreferredSize(new Dimension(200, myTfName.getPreferredSize().height));

  myTfPath = new JTextField();
  myTfPath.setDocument(new PathFieldDocument());
  myTfPath.setPreferredSize(new Dimension(200, myTfPath.getPreferredSize().height));

  myNameLabel = new JLabel(nameLabelText);
  if (bold) myNameLabel.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
  myNameLabel.setLabelFor(myTfName);
  Insets insets = new Insets(0, 0, 5, 4);
  this.add(myNameLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, insets, 0, 0));

  insets = new Insets(0, 0, 5, 0);
  this.add(myTfName, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, insets, 0, 0));
  // todo: review texts
  final FileChooserDescriptor chooserDescriptor = (FileChooserDescriptor)BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR.clone();
  chooserDescriptor.setHideIgnored(hideIgnored);
  final BrowseFilesListener browseButtonActionListener = new BrowseFilesListener(myTfPath, pathChooserTitle, pathChooserDescription, chooserDescriptor) {
    @Override
    public void actionPerformed(ActionEvent e) {
      super.actionPerformed(e);
      myIsPathChangedByUser = true;
    }
  };
  myPathPanel = new FieldPanel(myTfPath, null, null, browseButtonActionListener, null);
  myPathLabel = new JLabel(pathLabelText);
  myPathLabel.setLabelFor(myTfPath);
  if (bold) myPathLabel.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
  insets = new Insets(0, 0, 5, 4);
  this.add(myPathLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, insets, 0, 0));
  insets = new Insets(0, 0, 5, 0);
  this.add(myPathPanel, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, insets, 0, 0));
}
 
Example 25
Source Project: CppTools   Source File: IncludeFilesListEditor.java    License: Apache License 2.0 5 votes vote down vote up
protected FileChooserDescriptor configureFileChooserDescriptor() {
  return new FileChooserDescriptor(true, false, false, false, false, false) {
    public boolean isFileSelectable(VirtualFile virtualFile) {
      return Communicator.isHeaderFile(virtualFile);
    }
  };
}
 
Example 26
Source Project: BashSupport   Source File: BashConfigForm.java    License: Apache License 2.0 5 votes vote down vote up
protected void initOwnComponents() {
    Project project = getProject();

    FileChooserDescriptor chooseInterpreterDescriptor = FileChooserDescriptorFactory.createSingleLocalFileDescriptor();
    chooseInterpreterDescriptor.setTitle("Choose Interpreter...");

    interpreterPathField = new TextFieldWithBrowseButton();
    interpreterPathField.addBrowseFolderListener(new MacroAwareTextBrowseFolderListener(chooseInterpreterDescriptor, project));

    interpreterPathComponent = LabeledComponent.create(createComponentWithMacroBrowse(interpreterPathField), "Interpreter path:");
    interpreterPathComponent.setLabelLocation(BorderLayout.WEST);

    projectInterpreterCheckbox = new JBCheckBox();
    projectInterpreterCheckbox.setToolTipText("If enabled then the interpreter path configured in the project settings will be used instead of a custom location.");
    projectInterpreterCheckbox.addChangeListener(e -> {
        boolean selected = projectInterpreterCheckbox.isSelected();
        UIUtil.setEnabled(interpreterPathComponent, !selected, true);
    });
    projectInterpreterLabeled = LabeledComponent.create(projectInterpreterCheckbox, "Use project interpreter");
    projectInterpreterLabeled.setLabelLocation(BorderLayout.WEST);

    interpreterParametersComponent = LabeledComponent.create(new RawCommandLineEditor(), "Interpreter options");
    interpreterParametersComponent.setLabelLocation(BorderLayout.WEST);

    scriptNameField = new TextFieldWithBrowseButton();
    scriptNameField.addBrowseFolderListener(new MacroAwareTextBrowseFolderListener(FileChooserDescriptorFactory.createSingleLocalFileDescriptor(), project));

    scriptNameComponent = LabeledComponent.create(createComponentWithMacroBrowse(scriptNameField), "Script:");
    scriptNameComponent.setLabelLocation(BorderLayout.WEST);
}
 
Example 27
Source Project: JHelper   Source File: FileSelector.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public FileSelector(Project project, String initialValue, FileChooserDescriptor descriptor) {
	super(new JTextField(initialValue));
	addBrowseFolderListener(
			new RelativePathBrowseListener(descriptor, project)
	);
	installPathCompletion(descriptor);
}
 
Example 28
@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 29
Source Project: intellij-haxe   Source File: HaxeSdkType.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public FileChooserDescriptor getHomeChooserDescriptor() {
  final FileChooserDescriptor result = super.getHomeChooserDescriptor();
  if (SystemInfo.isMac) {
    result.withShowHiddenFiles(true); // TODO: Test on a mac: converted for v15.
  }
  return result;
}
 
Example 30
Source Project: consulo   Source File: GuiUtils.java    License: 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();
      }
    }
  });
}