Search in sources :

Example 1 with FileSaverDialog

use of com.intellij.openapi.fileChooser.FileSaverDialog in project intellij-community by JetBrains.

the class ApplyPatchSaveToFileExecutor method apply.

@Override
public void apply(@NotNull List<FilePatch> remaining, @NotNull MultiMap<VirtualFile, TextFilePatchInProgress> patchGroupsToApply, @Nullable LocalChangeList localList, @Nullable String fileName, @Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
    FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Save Patch to", ""), myProject);
    VirtualFileWrapper targetFile = dialog.save(myProject.getBaseDir(), "TheirsChanges.patch");
    if (targetFile != null) {
        savePatch(patchGroupsToApply, targetFile);
    }
}
Also used : FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) FileSaverDialog(com.intellij.openapi.fileChooser.FileSaverDialog) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper)

Example 2 with FileSaverDialog

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

the class ConvertToNinePatchAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final VirtualFile pngFile = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
    if (!isPngFile(pngFile)) {
        return;
    }
    FileSaverDescriptor descriptor = new FileSaverDescriptor(AndroidBundle.message("android.9patch.creator.save.title"), "", SdkConstants.EXT_PNG);
    FileSaverDialog saveFileDialog = FileChooserFactory.getInstance().createSaveFileDialog(descriptor, (Project) null);
    VirtualFileWrapper fileWrapper = saveFileDialog.save(pngFile.getParent(), pngFile.getNameWithoutExtension().concat(SdkConstants.DOT_9PNG));
    if (fileWrapper == null) {
        return;
    }
    final File patchFile = fileWrapper.getFile();
    new Task.Modal(null, "Creating 9-Patch File", false) {

        private IOException myException;

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            try {
                BufferedImage pngImage = ImageIO.read(VfsUtilCore.virtualToIoFile(pngFile));
                BufferedImage patchImage = ImageUtils.addMargin(pngImage, 1);
                ImageIO.write(patchImage, SdkConstants.EXT_PNG, patchFile);
                LocalFileSystem.getInstance().refreshAndFindFileByIoFile(patchFile);
            } catch (IOException e) {
                myException = e;
            }
        }

        @Override
        public void onSuccess() {
            if (myException != null) {
                Messages.showErrorDialog(AndroidBundle.message("android.9patch.creator.error", myException.getMessage()), AndroidBundle.message("android.9patch.creator.error.title"));
            }
        }
    }.queue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) Task(com.intellij.openapi.progress.Task) FileSaverDialog(com.intellij.openapi.fileChooser.FileSaverDialog) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper)

Example 3 with FileSaverDialog

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

the class ScreenshotViewer method doOKAction.

@Override
protected void doOKAction() {
    FileSaverDescriptor descriptor = new FileSaverDescriptor(AndroidBundle.message("android.ddms.screenshot.save.title"), "", SdkConstants.EXT_PNG);
    FileSaverDialog saveFileDialog = FileChooserFactory.getInstance().createSaveFileDialog(descriptor, myProject);
    VirtualFile baseDir = loadScreenshotPath();
    VirtualFileWrapper fileWrapper = saveFileDialog.save(baseDir, getDefaultFileName());
    if (fileWrapper == null) {
        return;
    }
    myScreenshotFile = fileWrapper.getFile();
    try {
        ImageIO.write(myDisplayedImageRef.get(), SdkConstants.EXT_PNG, myScreenshotFile);
    } catch (IOException e) {
        Messages.showErrorDialog(myProject, AndroidBundle.message("android.ddms.screenshot.save.error", e), AndroidBundle.message("android.ddms.actions.screenshot"));
        return;
    }
    VirtualFile virtualFile = fileWrapper.getVirtualFile();
    if (virtualFile != null) {
        PropertiesComponent properties = PropertiesComponent.getInstance(myProject);
        properties.setValue(SCREENSHOT_SAVE_PATH_KEY, virtualFile.getParent().getPath());
    }
    super.doOKAction();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) FileSaverDialog(com.intellij.openapi.fileChooser.FileSaverDialog) IOException(java.io.IOException) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper)

Example 4 with FileSaverDialog

use of com.intellij.openapi.fileChooser.FileSaverDialog in project intellij-community by JetBrains.

the class AbstractSchemeActions method exportScheme.

/**
   * Export the scheme using the given exporter name.
   *
   * @param scheme The scheme to export.
   * @param exporterName The exporter name.
   * @see SchemeExporter
   * @see SchemeExporterEP
   */
protected void exportScheme(@NotNull T scheme, @NotNull String exporterName) {
    SchemeExporter<T> exporter = SchemeExporterEP.getExporter(exporterName, getSchemeType());
    if (exporter != null) {
        String ext = exporter.getExtension();
        FileSaverDialog saver = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor(ApplicationBundle.message("scheme.exporter.ui.file.chooser.title"), ApplicationBundle.message("scheme.exporter.ui.file.chooser.message"), ext), getSchemesPanel());
        VirtualFileWrapper target = saver.save(null, SchemeManager.getDisplayName(scheme) + "." + ext);
        if (target != null) {
            VirtualFile targetFile = target.getVirtualFile(true);
            String message;
            MessageType messageType;
            if (targetFile != null) {
                try {
                    WriteAction.run(() -> {
                        OutputStream outputStream = targetFile.getOutputStream(this);
                        try {
                            exporter.exportScheme(scheme, outputStream);
                        } finally {
                            outputStream.close();
                        }
                    });
                    message = ApplicationBundle.message("scheme.exporter.ui.scheme.exported.message", scheme.getName(), getSchemesPanel().getSchemeTypeName(), targetFile.getPresentableUrl());
                    messageType = MessageType.INFO;
                } catch (Exception e) {
                    message = ApplicationBundle.message("scheme.exporter.ui.export.failed", e.getMessage());
                    messageType = MessageType.ERROR;
                }
            } else {
                message = ApplicationBundle.message("scheme.exporter.ui.cannot.write.message");
                messageType = MessageType.ERROR;
            }
            getSchemesPanel().showStatus(message, messageType);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) FileSaverDialog(com.intellij.openapi.fileChooser.FileSaverDialog) OutputStream(java.io.OutputStream) MessageType(com.intellij.openapi.ui.MessageType) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper)

Example 5 with FileSaverDialog

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

the class UIHelperImpl method showFileSaver.

@Override
public File showFileSaver(String title, String fileName) {
    FileSaverDescriptor fileDescriptor = new FileSaverDescriptor(title, "");
    final FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(fileDescriptor, (Project) null);
    final VirtualFileWrapper save = dialog.save(LocalFileSystem.getInstance().findFileByPath(System.getProperty("user.home")), fileName);
    if (save != null) {
        return save.getFile();
    }
    return null;
}
Also used : FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) FileSaverDialog(com.intellij.openapi.fileChooser.FileSaverDialog) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper)

Aggregations

FileSaverDescriptor (com.intellij.openapi.fileChooser.FileSaverDescriptor)8 FileSaverDialog (com.intellij.openapi.fileChooser.FileSaverDialog)8 VirtualFileWrapper (com.intellij.openapi.vfs.VirtualFileWrapper)8 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 BlobFile (com.microsoft.tooling.msservices.model.storage.BlobFile)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 BufferedImage (java.awt.image.BufferedImage)1 OutputStream (java.io.OutputStream)1