Search in sources :

Example 11 with FileSaverDescriptor

use of com.intellij.openapi.fileChooser.FileSaverDescriptor in project android by JetBrains.

the class SaveFileListener method actionPerformed.

@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());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) FileSaverDialog(com.intellij.openapi.fileChooser.FileSaverDialog) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper)

Example 12 with FileSaverDescriptor

use of com.intellij.openapi.fileChooser.FileSaverDescriptor in project azure-tools-for-java by Microsoft.

the class BlobExplorerFileEditor method saveAsSelectedFile.

private void saveAsSelectedFile() {
    BlobFile fileSelection = getFileSelection();
    assert fileSelection != null;
    FileSaverDescriptor fileDescriptor = new FileSaverDescriptor(SAVE_AS, "Select location to save blob file.");
    final FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(fileDescriptor, this.project);
    final VirtualFileWrapper save = dialog.save(LocalFileSystem.getInstance().findFileByPath(System.getProperty("user.home")), "");
    if (save != null) {
        downloadSelectedFile(save.getFile(), false);
    }
}
Also used : FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) FileSaverDialog(com.intellij.openapi.fileChooser.FileSaverDialog) BlobFile(com.microsoft.tooling.msservices.model.storage.BlobFile) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper)

Example 13 with FileSaverDescriptor

use of com.intellij.openapi.fileChooser.FileSaverDescriptor in project azure-tools-for-java by Microsoft.

the class NewCertificateDialog method getFileSaverListener.

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));
                }
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) ActionListener(java.awt.event.ActionListener) FileSaverDialog(com.intellij.openapi.fileChooser.FileSaverDialog) ActionEvent(java.awt.event.ActionEvent) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper)

Aggregations

FileSaverDescriptor (com.intellij.openapi.fileChooser.FileSaverDescriptor)13 VirtualFileWrapper (com.intellij.openapi.vfs.VirtualFileWrapper)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 FileSaverDialog (com.intellij.openapi.fileChooser.FileSaverDialog)8 Project (com.intellij.openapi.project.Project)4 File (java.io.File)4 IOException (java.io.IOException)3 Nullable (org.jetbrains.annotations.Nullable)3 AllIcons (com.intellij.icons.AllIcons)2 FileChooser (com.intellij.openapi.fileChooser.FileChooser)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 FileChooserFactory (com.intellij.openapi.fileChooser.FileChooserFactory)2 FileTypes (com.intellij.openapi.fileTypes.FileTypes)2 StdFileTypes (com.intellij.openapi.fileTypes.StdFileTypes)2 SearchableConfigurable (com.intellij.openapi.options.SearchableConfigurable)2 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)2 Messages (com.intellij.openapi.ui.Messages)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 com.intellij.ui (com.intellij.ui)2 KeyEvent (java.awt.event.KeyEvent)2