Search in sources :

Example 36 with FileChooserDescriptor

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

the class BuildElementsEditor method createOutputPathPanel.

private CommitableFieldPanel createOutputPathPanel(final String title, final CommitPathRunnable commitPathRunnable) {
    final JTextField textField = new JTextField();
    final FileChooserDescriptor outputPathsChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    outputPathsChooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, getModel().getModule());
    outputPathsChooserDescriptor.setHideIgnored(false);
    InsertPathAction.addTo(textField, outputPathsChooserDescriptor);
    FileChooserFactory.getInstance().installFileCompletion(textField, outputPathsChooserDescriptor, true, null);
    final Runnable commitRunnable = () -> {
        if (!getModel().isWritable()) {
            return;
        }
        final String path = textField.getText().trim();
        if (path.length() == 0) {
            commitPathRunnable.saveUrl(null);
        } else {
            // should set only absolute paths
            String canonicalPath;
            try {
                canonicalPath = FileUtil.resolveShortWindowsName(path);
            } catch (IOException e) {
                canonicalPath = path;
            }
            commitPathRunnable.saveUrl(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(canonicalPath)));
        }
    };
    final ActionListener listener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            commitRunnable.run();
        }
    };
    myPerModuleCompilerOutput.addActionListener(listener);
    textField.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            commitRunnable.run();
        }
    });
    return new CommitableFieldPanel(textField, null, null, new BrowseFilesListener(textField, title, "", outputPathsChooserDescriptor) {

        @Override
        public void actionPerformed(ActionEvent e) {
            super.actionPerformed(e);
            commitRunnable.run();
        }
    }, null, commitRunnable);
}
Also used : ActionListener(java.awt.event.ActionListener) BrowseFilesListener(com.intellij.ide.util.BrowseFilesListener) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) IOException(java.io.IOException) DocumentEvent(javax.swing.event.DocumentEvent)

Example 37 with FileChooserDescriptor

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

the class ImportTestsFromFileAction method getFile.

@Nullable
@Override
public VirtualFile getFile(@NotNull Project project) {
    final FileChooserDescriptor xmlDescriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(StdFileTypes.XML);
    xmlDescriptor.setTitle("Choose a File with Tests Result");
    return FileChooser.chooseFile(xmlDescriptor, project, null);
}
Also used : FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 38 with FileChooserDescriptor

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

the class ApplyPatchAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    if (ChangeListManager.getInstance(project).isFreezedWithNotification("Can not apply patch now"))
        return;
    FileDocumentManager.getInstance().saveAllDocuments();
    VirtualFile vFile = null;
    final String place = e.getPlace();
    if (isProjectOrScopeView(place) || ActionPlaces.MAIN_MENU.equals(place)) {
        vFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
    }
    if (isPatchFile(vFile)) {
        showApplyPatch(project, vFile);
    } else {
        final FileChooserDescriptor descriptor = ApplyPatchDifferentiatedDialog.createSelectPatchDescriptor();
        final VcsApplicationSettings settings = VcsApplicationSettings.getInstance();
        final VirtualFile toSelect = settings.PATCH_STORAGE_LOCATION == null ? null : LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(settings.PATCH_STORAGE_LOCATION));
        FileChooser.chooseFile(descriptor, project, toSelect, new Consumer<VirtualFile>() {

            @Override
            public void consume(VirtualFile file) {
                final VirtualFile parent = file.getParent();
                if (parent != null) {
                    settings.PATCH_STORAGE_LOCATION = parent.getPath();
                }
                showApplyPatch(project, file);
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) VcsApplicationSettings(com.intellij.openapi.vcs.VcsApplicationSettings) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PatchFileType.isPatchFile(com.intellij.openapi.vcs.changes.patch.PatchFileType.isPatchFile)

Example 39 with FileChooserDescriptor

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

the class SchemeImportUtil method selectImportSource.

@Nullable
public static VirtualFile selectImportSource(@NotNull final String[] sourceExtensions, @NotNull Component parent, @Nullable VirtualFile preselect, @Nullable String description) {
    final Set<String> extensions = new HashSet<>(Arrays.asList(sourceExtensions));
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return (file.isDirectory() || extensions.contains(file.getExtension())) && (showHiddenFiles || !FileElement.isFileHidden(file));
        }

        @Override
        public boolean isFileSelectable(VirtualFile file) {
            return !file.isDirectory() && extensions.contains(file.getExtension());
        }
    };
    if (description != null) {
        descriptor.setDescription(description);
    }
    FileChooserDialog fileChooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, parent);
    final VirtualFile[] preselectFiles;
    if (preselect != null) {
        preselectFiles = new VirtualFile[1];
        preselectFiles[0] = preselect;
    } else {
        preselectFiles = VirtualFile.EMPTY_ARRAY;
    }
    final VirtualFile[] virtualFiles = fileChooser.choose(null, preselectFiles);
    //CodeStyleSchemesUIConfiguration.Util.getRecentImportFile());
    if (virtualFiles.length != 1)
        return null;
    virtualFiles[0].refresh(false, false);
    return virtualFiles[0];
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) FileChooserDialog(com.intellij.openapi.fileChooser.FileChooserDialog) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 40 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-plugins by JetBrains.

the class AddAdapterSupportDialog method createSelectDirectoryPanel.

@NotNull
private JPanel createSelectDirectoryPanel(@NotNull Project project, @NotNull JTextField directoryTextField) {
    FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    String adapterName = getAssertFrameworkAdapterName();
    String title = "Select a directory for " + adapterName + " files";
    String description = adapterName + " source files will be copied to the selected directory";
    TextFieldWithBrowseButton directoryTextFieldWithBrowseButton = new TextFieldWithBrowseButton(directoryTextField);
    directoryTextFieldWithBrowseButton.addBrowseFolderListener(title, description, project, fileChooserDescriptor);
    Dimension oldDimension = directoryTextFieldWithBrowseButton.getPreferredSize();
    directoryTextFieldWithBrowseButton.setMaximumSize(oldDimension);
    JPanel panel = new JPanel(new BorderLayout(0, 2));
    panel.add(new JLabel("Copy these files to directory:"), BorderLayout.NORTH);
    panel.add(directoryTextFieldWithBrowseButton, BorderLayout.CENTER);
    return SwingHelper.wrapWithHorizontalStretch(panel);
}
Also used : TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)166 VirtualFile (com.intellij.openapi.vfs.VirtualFile)110 NotNull (org.jetbrains.annotations.NotNull)35 File (java.io.File)24 Project (com.intellij.openapi.project.Project)22 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)21 Nullable (org.jetbrains.annotations.Nullable)19 ActionEvent (java.awt.event.ActionEvent)17 ActionListener (java.awt.event.ActionListener)16 DocumentEvent (javax.swing.event.DocumentEvent)14 DocumentAdapter (com.intellij.ui.DocumentAdapter)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 FileChooser (com.intellij.openapi.fileChooser.FileChooser)9 List (java.util.List)9 FileChooserDialog (com.intellij.openapi.fileChooser.FileChooserDialog)7 JBLabel (com.intellij.ui.components.JBLabel)7 javax.swing (javax.swing)7 MacroComboBoxWithBrowseButton (com.intellij.execution.ui.MacroComboBoxWithBrowseButton)5 Module (com.intellij.openapi.module.Module)5