Search in sources :

Example 11 with VirtualFileWrapper

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

the class MacFileSaverDialog method save.

@Nullable
@Override
public VirtualFileWrapper save(@Nullable VirtualFile baseDir, @Nullable String filename) {
    myFileDialog.setDirectory(baseDir == null ? null : baseDir.getCanonicalPath());
    myFileDialog.setFile(filename);
    myFileDialog.setFilenameFilter((dir, name) -> {
        File file = new File(dir, name);
        return myDescriptor.isFileSelectable(fileToVirtualFile(file));
    });
    myFileDialog.setVisible(true);
    String file = myFileDialog.getFile();
    if (file == null) {
        return null;
    }
    return new VirtualFileWrapper(new File(myFileDialog.getDirectory() + File.separator + file));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with VirtualFileWrapper

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

the class FileSaverDialogImpl method save.

@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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSystemTree(com.intellij.openapi.fileChooser.FileSystemTree) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with VirtualFileWrapper

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

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

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