com.intellij.openapi.vfs.VirtualFileWrapper Java Examples

The following examples show how to use com.intellij.openapi.vfs.VirtualFileWrapper. 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: FileSaverDialogImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
public VirtualFileWrapper save(@Nullable VirtualFile baseDir, @Nullable final String filename) {
  init();
  restoreSelection(baseDir);
  myFileSystemTree.addListener(new FileSystemTree.Listener() {
    public void selectionChanged(final List<? extends VirtualFile> selection) {
      updateFileName(selection);
      updateOkButton();
    }
  }, myDisposable);

  if (filename != null) {
    myFileName.setText(filename);
  }

  show();

  if (getExitCode() == OK_EXIT_CODE) {
    final File file = getFile();
    return file == null ? null : new VirtualFileWrapper(file);
  }
  return null;
}
 
Example #2
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 #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: FileSaverDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
VirtualFileWrapper save(@Nullable VirtualFile baseDir, @Nullable String filename);