Search in sources :

Example 6 with FileSaverDialog

use of com.intellij.openapi.fileChooser.FileSaverDialog 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)

Aggregations

FileSaverDescriptor (com.intellij.openapi.fileChooser.FileSaverDescriptor)6 FileSaverDialog (com.intellij.openapi.fileChooser.FileSaverDialog)6 VirtualFileWrapper (com.intellij.openapi.vfs.VirtualFileWrapper)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 File (java.io.File)2 IOException (java.io.IOException)2 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 MessageType (com.intellij.openapi.ui.MessageType)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 BufferedImage (java.awt.image.BufferedImage)1 OutputStream (java.io.OutputStream)1