com.intellij.openapi.fileChooser.FileSaverDescriptor Java Examples

The following examples show how to use com.intellij.openapi.fileChooser.FileSaverDescriptor. 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: 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 #2
Source File: FileChooserUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static VirtualFile getFileToSelect(@Nonnull FileChooserDescriptor descriptor, @Nullable Project project,
                                          @Nullable VirtualFile toSelect, @Nullable VirtualFile lastPath) {
  boolean chooseDir = descriptor instanceof FileSaverDescriptor;
  VirtualFile result;

  if (toSelect == null && lastPath == null) {
    result = project == null? null : project.getBaseDir();
  }
  else if (toSelect != null && lastPath != null) {
    if (Boolean.TRUE.equals(descriptor.getUserData(PathChooserDialog.PREFER_LAST_OVER_EXPLICIT))) {
      result = lastPath;
    }
    else {
      result = toSelect;
    }
  }
  else if (toSelect == null) {
    result = lastPath;
  }
  else {
    result = toSelect;
  }

  if (result != null) {
    if (chooseDir && !result.isDirectory()) {
      result = result.getParent();
    }
  }
  else if (SystemInfo.isUnix) {
    result = VfsUtil.getUserHomeDir();
  }

  return result;
}
 
Example #3
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 #4
Source File: DesktopFileSaveDialogProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public FileSaverDialog createSaveFileDialog(@Nonnull FileSaverDescriptor descriptor, @Nullable Project project, @Nullable Component parent) {
  if(parent != null) {
    return new FileSaverDialogImpl(descriptor, parent);
  }
  return new FileSaverDialogImpl(descriptor, project);
}
 
Example #5
Source File: MacFileSaveDialogProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public FileSaverDialog createSaveFileDialog(@Nonnull FileSaverDescriptor descriptor, @Nullable Project project, @Nullable Component parent) {
  if(parent != null) {
    return new MacFileSaverDialog(descriptor, parent);
  }
  return new MacFileSaverDialog(descriptor, project);
}
 
Example #6
Source File: FileSaverDialogImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FileSaverDialogImpl(@Nonnull FileSaverDescriptor descriptor, @Nonnull Component parent) {
  super(descriptor, parent);
  myDescriptor = descriptor;
  for (String ext : descriptor.getFileExtensions()) {
    myExtensions.addItem(ext);
  }
  setTitle(getChooserTitle(descriptor));
}
 
Example #7
Source File: FileSaverDialogImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FileSaverDialogImpl(@Nonnull FileSaverDescriptor descriptor, @Nullable Project project) {
  super(descriptor, project);
  myDescriptor = descriptor;
  for (String ext : descriptor.getFileExtensions()) {
    myExtensions.addItem(ext);
  }
  setTitle(getChooserTitle(descriptor));
}
 
Example #8
Source File: FileSaveDialogProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
FileSaverDialog createSaveFileDialog(@Nonnull FileSaverDescriptor descriptor, @Nullable Project project, @Nullable Component parent);
 
Example #9
Source File: FileSaverDialogImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static String getChooserTitle(final FileSaverDescriptor descriptor) {
  final String title = descriptor.getTitle();
  return title != null ? title : UIBundle.message("file.chooser.save.dialog.default.title");
}
 
Example #10
Source File: MacFileSaverDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
public MacFileSaverDialog(FileSaverDescriptor descriptor, Project project) {
  this(descriptor, IdeFocusManager.getInstance(project).getFocusOwner());
}
 
Example #11
Source File: MacFileSaverDialog.java    From consulo with Apache License 2.0 3 votes vote down vote up
public MacFileSaverDialog(FileSaverDescriptor descriptor, Component parent) {

    String title = getChooserTitle(descriptor);
    Consumer<Dialog> dialogConsumer = owner -> myFileDialog = new FileDialog(owner, title, FileDialog.SAVE);
    Consumer<Frame> frameConsumer = owner -> myFileDialog = new FileDialog(owner, title, FileDialog.SAVE);

    myDescriptor = descriptor;

    OwnerOptional.fromComponent(parent).ifDialog(dialogConsumer).ifFrame(frameConsumer).ifNull(frameConsumer);
  }