Java 类com.intellij.openapi.vfs.VirtualFileWrapper 实例源码

项目:intellij-ce-playground    文件:ConfigureAndroidProjectStep.java   
private void browseForFile() {
  FileSaverDescriptor fileSaverDescriptor = new FileSaverDescriptor("Project location", "Please choose a location for your project");
  File currentPath = new File(myProjectLocation.getText());
  File parentPath = currentPath.getParentFile();
  if (parentPath == null) {
    String homePath = System.getProperty("user.home");
    parentPath = homePath == null ? new File("/") : new File(homePath);
  }
  VirtualFile parent = LocalFileSystem.getInstance().findFileByIoFile(parentPath);
  String filename = currentPath.getName();
  VirtualFileWrapper fileWrapper =
    FileChooserFactory.getInstance().createSaveFileDialog(fileSaverDescriptor, (Project)null).save(parent, filename);
  if (fileWrapper != null) {
    myProjectLocation.setText(fileWrapper.getFile().getAbsolutePath());
  }
}
项目:sutr-io    文件:SutrConfigPanel.java   
private void AddFileSelectorHandler(TextFieldWithBrowseButton textFieldWithBrowseButton, Project project, String label, String description) {

        textFieldWithBrowseButton.addActionListener(
            e -> {
                final FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor(label, description), myPanel);
                final String path = FileUtil.toSystemIndependentName(getFileName(textFieldWithBrowseButton));
                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) {
                    textFieldWithBrowseButton.setText(fileWrapper.getFile().getPath());
                }
            }
        );
    }
项目:intellij-ce-playground    文件:FileSaverDialogImpl.java   
@Override
@Nullable
public VirtualFileWrapper save(@Nullable VirtualFile baseDir, @Nullable final String filename) {
  init();
  restoreSelection(baseDir);
  myFileSystemTree.addListener(new FileSystemTree.Listener() {
    @Override
    public void selectionChanged(final List<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;
}
项目:intellij-ce-playground    文件:ModulesToImportDialog.java   
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
  String title = "Save Module Selection";
  FileSaverDescriptor descriptor = new FileSaverDescriptor(title, "Save the list of selected Modules to a file",
                                                           SdkConstants.EXT_XML);
  FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(descriptor, getWindow());
  VirtualFile baseDir = myProject != null ? myProject.getBaseDir() : null;
  VirtualFileWrapper result = dialog.save(baseDir, null);
  if (result != null) {
    File file = result.getFile();
    try {
      Selection.save(getUserSelectedModules(), file);
    }
    catch (IOException error) {
      String msg = String.format("Failed to save Module selection to file '%1$s'", file.getPath());
      Messages.showErrorDialog(getWindow(), msg, title);
      String cause = error.getMessage();
      if (isNotEmpty(cause)) {
        msg = msg + ":\n" + cause;
      }
      Logger.getInstance(ModulesToImportDialog.class).info(msg, error);
    }
  }
}
项目:Azure-Toolkit-for-IntelliJ    文件:NewCertificateDialog.java   
private ActionListener getFileSaverListener(final TextFieldWithBrowseButton field, final TextFieldWithBrowseButton fieldToUpdate,
                                            final String suffixToReplace, final String suffix) {
    return new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(
                    new FileSaverDescriptor(message("newCertDlgBrwFldr"), "", suffixToReplace), field);
            final VirtualFile baseDir = myProject.getBaseDir();
            final VirtualFileWrapper save = dialog.save(baseDir, "");
            if (save != null) {
                field.setText(FileUtil.toSystemDependentName(save.getFile().getAbsolutePath()));
                if (fieldToUpdate.getText().isEmpty()) {
                    fieldToUpdate.setText(Utils.replaceLastSubString(field.getText(), suffixToReplace, suffix));
                }
            }
        }
    };
}
项目:fossil4idea    文件:InitAction.java   
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
  final Project project = PlatformDataKeys.PROJECT.getData(anActionEvent.getDataContext());
  if (project == null) return;

  final FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Init Fossil Repository",
          "Select file where to create new Fossil repository."), project);
  final VirtualFileWrapper wrapper = dialog.save(null, null);
  if (wrapper == null) return;
  final Task.Backgroundable task = new Task.Backgroundable(project, "Init Fossil Repository", false, PerformInBackgroundOption.ALWAYS_BACKGROUND) {
    @Override
    public void run(@NotNull ProgressIndicator progressIndicator) {
      try {
        new CheckoutUtil(project).initRepository(wrapper.getFile());
        VcsBalloonProblemNotifier.showOverVersionControlView(project, "Fossil repository successfully created: " + wrapper.getFile().getPath(), MessageType.INFO);
      } catch (VcsException e) {
        VcsBalloonProblemNotifier.showOverVersionControlView(project, "Fossil repository not created: " + e.getMessage(), MessageType.ERROR);
      }
    }
  };
  ProgressManager.getInstance().run(task);
}
项目:tools-idea    文件:FileSaverDialogImpl.java   
@Nullable
public VirtualFileWrapper save(@Nullable VirtualFile baseDir, @Nullable final String filename) {
  init();
  restoreSelection(baseDir);
  myFileSystemTree.addListener(new FileSystemTree.Listener() {
    public void selectionChanged(final List<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;
}
项目:ali-idea-plugin    文件:AttachmentDownloadAction.java   
@Override
protected void actionPerformed(AnActionEvent event, Project project, Entity entity) {
    String name = entity.getPropertyValue("name");
    FileSaverDescriptor desc = new FileSaverDescriptor("Download Attachment", "Download attachment to the local filesystem.");
    final VirtualFileWrapper file = FileChooserFactory.getInstance().createSaveFileDialog(desc, project).save(lastDir, name.replaceFirst("\\.agmlink$", ""));
    if(file != null) {
        VirtualFile vf = file.getVirtualFile(true);
        if(vf == null) {
            Messages.showErrorDialog("Invalid file specified", "Error");
            return;
        }
        lastDir = vf.getParent();
        if (!name.endsWith(".agmlink") || file.getFile().getName().endsWith(".agmlink")) {
            // either regular file or we explicitly ask for .agmlink file
            ProgressManager.getInstance().run(new AttachmentDownloadTask(project, file.getFile(), name, Integer.valueOf(entity.getPropertyValue("file-size")), new EntityRef(entity.getPropertyValue("parent-type"), Integer.valueOf(entity.getPropertyValue("parent-id"))), null));
        } else {
            // download referenced content instead
            ProgressManager.getInstance().run(new AttachmentAgmLinkDownloadTask(project, file.getFile(), name, Integer.valueOf(entity.getPropertyValue("file-size")), new EntityRef(entity.getPropertyValue("parent-type"), Integer.valueOf(entity.getPropertyValue("parent-id"))), null));
        }
    }
}
项目:consulo    文件:FileSaverDialogImpl.java   
@javax.annotation.Nullable
public VirtualFileWrapper save(@Nullable VirtualFile baseDir, @javax.annotation.Nullable final String filename) {
  init();
  restoreSelection(baseDir);
  myFileSystemTree.addListener(new FileSystemTree.Listener() {
    public void selectionChanged(final List<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;
}
项目:intellij-ce-playground    文件:SaveFileListener.java   
@Override
public void actionPerformed(ActionEvent e) {
  String path = myTextField.getText().trim();
  if (path.length() == 0) {
    String defaultLocation = getDefaultLocation();
    path = defaultLocation != null && defaultLocation.length() > 0
           ? defaultLocation
           : SystemProperties.getUserHome();
  }
  File file = new File(path);
  if (!file.exists()) {
    path = SystemProperties.getUserHome();
  }
  FileSaverDescriptor descriptor = new FileSaverDescriptor(myDialogTitle, "Save as *." + myExtension, myExtension);
  FileSaverDialog saveFileDialog = FileChooserFactory.getInstance().createSaveFileDialog(descriptor, myContentPanel);

  VirtualFile vf = LocalFileSystem.getInstance().findFileByIoFile(file.exists() ? file : new File(path));
  if (vf == null) {
    vf = VfsUtil.getUserHomeDir();
  }

  VirtualFileWrapper result = saveFileDialog.save(vf, null);


  if (result == null || result.getFile() == null) {
    return;
  }

  myTextField.setText(result.getFile().getPath());
}
项目:intellij-ce-playground    文件:ExportDeviceAction.java   
@Override
public void actionPerformed(ActionEvent e) {
  FileSaverDescriptor descriptor = new FileSaverDescriptor("Export Location", "Select a location for the exported device", "xml");
  String homePath = System.getProperty("user.home");
  File parentPath = homePath == null ? new File("/") : new File(homePath);
  VirtualFile parent = LocalFileSystem.getInstance().findFileByIoFile(parentPath);
  VirtualFileWrapper fileWrapper =
    FileChooserFactory.getInstance().createSaveFileDialog(descriptor, (Project)null).save(parent, "device.xml");
  Device device = myProvider.getDevice();
  if (device != null && fileWrapper != null) {
    DeviceManagerConnection.writeDevicesToFile(ImmutableList.of(device), fileWrapper.getFile());
  }
}
项目:intellij-ce-playground    文件:ScreenRecorderAction.java   
private void pullRecording() {
  FileSaverDescriptor descriptor = new FileSaverDescriptor("Save As", "", "mp4");
  FileSaverDialog saveFileDialog = FileChooserFactory.getInstance().createSaveFileDialog(descriptor, myProject);
  VirtualFile baseDir = ourLastSavedFolder != null ? ourLastSavedFolder : VfsUtil.getUserHomeDir();
  VirtualFileWrapper fileWrapper = saveFileDialog.save(baseDir, getDefaultFileName());
  if (fileWrapper == null) {
    return;
  }

  File f = fileWrapper.getFile();
  //noinspection AssignmentToStaticFieldFromInstanceMethod
  ourLastSavedFolder = VfsUtil.findFileByIoFile(f.getParentFile(), false);

  new PullRecordingTask(myProject, myDevice, f.getAbsolutePath()).queue();
}
项目:intellij-ce-playground    文件:ApplyPatchSaveToFileExecutor.java   
@Override
public void apply(MultiMap<VirtualFile, TextFilePatchInProgress> patchGroups,
                  LocalChangeList localList,
                  String fileName,
                  TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
  final FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(
    new FileSaverDescriptor("Save Patch to", ""), myProject);
  final VirtualFile baseDir = myProject.getBaseDir();
  final VirtualFileWrapper save = dialog.save(baseDir, "TheirsChanges.patch");
  if (save != null) {
    final CommitContext commitContext = new CommitContext();

    final VirtualFile baseForPatch = myBaseForPatch == null ? baseDir : myBaseForPatch;
    try {
      final List<FilePatch> textPatches = patchGroupsToOneGroup(patchGroups, baseForPatch);
      commitContext.putUserData(BaseRevisionTextPatchEP.ourPutBaseRevisionTextKey, false);
      PatchWriter.writePatches(myProject, save.getFile().getPath(), textPatches, commitContext, CharsetToolkit.UTF8_CHARSET);
    }
    catch (final IOException e) {
      LOG.info(e);
      WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() {
        @Override
        public void run() {
          Messages.showErrorDialog(myProject, VcsBundle.message("create.patch.error.title", e.getMessage()), CommonBundle.getErrorTitle());
        }
      }, null, myProject);
    }
  }
}
项目:tools-idea    文件:ApplyPatchSaveToFileExecutor.java   
@Override
public void apply(MultiMap<VirtualFile, FilePatchInProgress> patchGroups,
                  LocalChangeList localList,
                  String fileName,
                  TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
  final FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(
    new FileSaverDescriptor("Save patch to", ""), myProject);
  final VirtualFile baseDir = myProject.getBaseDir();
  final VirtualFileWrapper save = dialog.save(baseDir, "TheirsChanges.patch");
  if (save != null && save.getFile() != null) {
    final CommitContext commitContext = new CommitContext();

    final VirtualFile baseForPatch = myBaseForPatch == null ? baseDir : myBaseForPatch;
    try {
      final List<FilePatch> textPatches = patchGroupsToOneGroup(patchGroups, baseForPatch);
      commitContext.putUserData(BaseRevisionTextPatchEP.ourPutBaseRevisionTextKey, false);
      PatchWriter.writePatches(myProject, save.getFile().getPath(), textPatches, commitContext, CharsetToolkit.UTF8_CHARSET);
    }
    catch (final IOException e) {
      LOG.info(e);
      WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() {
        public void run() {
          Messages.showErrorDialog(myProject, VcsBundle.message("create.patch.error.title", e.getMessage()), CommonBundle.getErrorTitle());
        }
      }, null, myProject);
    }
  }
}
项目:ali-idea-plugin    文件:AliConfigurable.java   
protected Component getSouthernComponent() {
    JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    final TroubleShootService troubleShootService = ApplicationManager.getApplication().getComponent(TroubleShootService.class);
    final JButton troubleshoot = new JButton(troubleShootService.isRunning()? "Stop Troubleshoot": "Troubleshoot");
    troubleshoot.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if(troubleshoot.getText().equals("Troubleshoot")) {
                if(!troubleShootService.isRunning()) {
                    if(Messages.showYesNoDialog("Do you want to log complete ALM server communication?", "Confirmation", null) == Messages.YES) {
                        FileSaverDescriptor desc = new FileSaverDescriptor("Log server communication", "Log server communication on the local filesystem.");
                        final VirtualFileWrapper file = FileChooserFactory.getInstance().createSaveFileDialog(desc, troubleshoot).save(null, "REST_log.txt");
                        if(file == null) {
                            return;
                        }

                        troubleShootService.start(file.getFile());
                        troubleshoot.setText("Stop Troubleshoot");
                    }
                }
            } else {
                troubleShootService.stop();
                troubleshoot.setText("Troubleshoot");
            }
        }
    });
    southPanel.add(troubleshoot);
    return southPanel;
}
项目:consulo    文件:CreatePatchConfigurationPanel.java   
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();
}
项目:intellij-ce-playground    文件:FileSaverDialog.java   
@Nullable
VirtualFileWrapper save(@Nullable VirtualFile baseDir, @Nullable String filename);
项目:fossil4idea    文件:CloneAndOpenAction.java   
private JComponent createPanel(final Project project, final Consumer<Boolean> enableConsumer) {
  final JPanel main = new JPanel(new GridBagLayout());
  main.setMinimumSize(new Dimension(150, 50));
  final GridBagConstraints gbc = new GridBagConstraints();
  gbc.gridx = 0;
  gbc.gridy = 0;
  gbc.insets = new Insets(2,2,2,2);
  gbc.anchor = GridBagConstraints.NORTHWEST;

  main.add(new JLabel("Remote URL: "), gbc);
  myUrlField = new JTextField(50);
  gbc.gridx ++;
  gbc.fill = GridBagConstraints.HORIZONTAL;
  gbc.weightx = 1;
  main.add(myUrlField, gbc);
  gbc.gridx = 0;
  gbc.gridy ++;
  gbc.weightx = 0;
  gbc.fill = GridBagConstraints.NONE;
  main.add(new JLabel("Local Repository File: "), gbc);
  myLocalRepoFile = new TextFieldWithBrowseButton();
  myLocalRepoFile.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      final FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(
              new FileSaverDescriptor("Fossil Clone", "Select local file"), project);
      final String path = FileUtil.toSystemIndependentName(myLocalRepoFile.getText().trim());
      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) {
        myLocalRepoFile.setText(fileWrapper.getFile().getPath());
      }
    }
  });

  gbc.weightx = 1;
  gbc.gridx ++;
  gbc.fill = GridBagConstraints.HORIZONTAL;
  main.add(myLocalRepoFile, gbc);

  gbc.gridx = 0;
  gbc.gridy ++;
  gbc.fill = GridBagConstraints.NONE;
  main.add(new JLabel("Local Checkout Folder: "), gbc);
  myLocalPath = new TextFieldWithBrowseButton();
  myLocalPath.addBrowseFolderListener("Select Checkout Folder", null, project, new FileChooserDescriptor(false, true, false, false, false, false));
  /*myLocalPath.addBrowseFolderListener("Select Local File", "Select local file for clone", project,
          new FileSaverDescriptor("Fossil Clone", "Select local file", "checkout", ""));*/
  gbc.weightx = 1;
  gbc.gridx ++;
  gbc.fill = GridBagConstraints.HORIZONTAL;
  main.add(myLocalPath, gbc);
  return main;
}
项目:fossil4idea    文件:CloneAction.java   
private JComponent createPanel(final Project project, final Consumer<Boolean> enableConsumer) {
  final JPanel main = new JPanel(new GridBagLayout());
  main.setMinimumSize(new Dimension(150, 50));
  final GridBagConstraints gbc = new GridBagConstraints();
  gbc.gridx = 0;
  gbc.gridy = 0;
  gbc.insets = new Insets(2,2,2,2);
  gbc.anchor = GridBagConstraints.NORTHWEST;

  main.add(new JLabel("Remote URL: "), gbc);
  myUrlField = new JTextField(50);
  gbc.gridx ++;
  gbc.fill = GridBagConstraints.HORIZONTAL;
  gbc.weightx = 1;
  main.add(myUrlField, gbc);
  gbc.gridx = 0;
  gbc.gridy ++;
  gbc.weightx = 0;
  gbc.fill = GridBagConstraints.NONE;
  main.add(new JLabel("Local Folder: "), gbc);
  myLocalPath = new TextFieldWithBrowseButton();
  myLocalPath.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      final FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(
              new FileSaverDescriptor("Fossil Clone", "Select local file"), project);
      final String path = FileUtil.toSystemIndependentName(myLocalPath.getText().trim());
      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) {
        myLocalPath.setText(fileWrapper.getFile().getPath());
      }
    }
  });
  /*myLocalPath.addBrowseFolderListener("Select Local File", "Select local file for clone", project,
          new FileSaverDescriptor("Fossil Clone", "Select local file", "checkout", ""));*/
  gbc.weightx = 1;
  gbc.gridx ++;
  gbc.fill = GridBagConstraints.HORIZONTAL;
  main.add(myLocalPath, gbc);

  /*final ActionListener listener = new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      enableConsumer.consume(!myUrlField.getText().isEmpty() && !myLocalPath.getText().isEmpty());
    }
  };
  myUrlField.addActionListener(listener);
  myLocalPath.addActionListener(listener);*/
  return main;
}
项目:tools-idea    文件:FileSaverDialog.java   
@Nullable
VirtualFileWrapper save(@Nullable VirtualFile baseDir, @Nullable String filename);
项目:consulo    文件:FileSaverDialog.java   
@Nullable
VirtualFileWrapper save(@Nullable VirtualFile baseDir, @Nullable String filename);