Search in sources :

Example 6 with VirtualFileWrapper

use of com.intellij.openapi.vfs.VirtualFileWrapper in project android by JetBrains.

the class ExportDeviceAction method actionPerformed.

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

Example 7 with VirtualFileWrapper

use of com.intellij.openapi.vfs.VirtualFileWrapper 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 8 with VirtualFileWrapper

use of com.intellij.openapi.vfs.VirtualFileWrapper 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)

Example 9 with VirtualFileWrapper

use of com.intellij.openapi.vfs.VirtualFileWrapper in project android by JetBrains.

the class ConfigureAndroidProjectStep method browseForFile.

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 = new File(homePath == null ? "/" : 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());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) Project(com.intellij.openapi.project.Project) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper)

Example 10 with VirtualFileWrapper

use of com.intellij.openapi.vfs.VirtualFileWrapper 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

VirtualFileWrapper (com.intellij.openapi.vfs.VirtualFileWrapper)14 FileSaverDescriptor (com.intellij.openapi.fileChooser.FileSaverDescriptor)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 FileSaverDialog (com.intellij.openapi.fileChooser.FileSaverDialog)8 File (java.io.File)6 Project (com.intellij.openapi.project.Project)4 Nullable (org.jetbrains.annotations.Nullable)4 IOException (java.io.IOException)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