Search in sources :

Example 6 with TextBrowseFolderListener

use of com.intellij.openapi.ui.TextBrowseFolderListener in project intellij-community by JetBrains.

the class StartBrowserPanel method setupUrlField.

public static void setupUrlField(@NotNull TextFieldWithBrowseButton field, @NotNull final Project project) {
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) {

        @Override
        public boolean isFileSelectable(VirtualFile file) {
            return HtmlUtil.isHtmlFile(file) || virtualFileToUrl(file, project) != null;
        }
    };
    descriptor.setTitle(XmlBundle.message("javascript.debugger.settings.choose.file.title"));
    descriptor.setDescription(XmlBundle.message("javascript.debugger.settings.choose.file.subtitle"));
    descriptor.setRoots(ProjectRootManager.getInstance(project).getContentRoots());
    field.addBrowseFolderListener(new TextBrowseFolderListener(descriptor, project) {

        @NotNull
        @Override
        protected String chosenFileToResultingText(@NotNull VirtualFile chosenFile) {
            if (chosenFile.isDirectory()) {
                return chosenFile.getPath();
            }
            Url url = virtualFileToUrl(chosenFile, project);
            return url == null ? chosenFile.getUrl() : url.toDecodedForm();
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) TextBrowseFolderListener(com.intellij.openapi.ui.TextBrowseFolderListener) NotNull(org.jetbrains.annotations.NotNull) Url(com.intellij.util.Url)

Example 7 with TextBrowseFolderListener

use of com.intellij.openapi.ui.TextBrowseFolderListener in project ballerina by ballerina-lang.

the class BallerinaRunUtil method installWorkingDirectoryChooser.

private static void installWorkingDirectoryChooser(@NotNull Project project, @NotNull ComponentWithBrowseButton field) {
    FileChooserDescriptor chooseDirectoryDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    chooseDirectoryDescriptor.setShowFileSystemRoots(true);
    chooseDirectoryDescriptor.withShowHiddenFiles(false);
    if (field instanceof TextFieldWithBrowseButton) {
        ((TextFieldWithBrowseButton) field).addBrowseFolderListener(new TextBrowseFolderListener(chooseDirectoryDescriptor, project));
    } else {
        // noinspection unchecked
        field.addBrowseFolderListener(project, new ComponentWithBrowseButton.BrowseFolderActionListener(null, null, field, project, chooseDirectoryDescriptor, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT));
    }
}
Also used : TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ComponentWithBrowseButton(com.intellij.openapi.ui.ComponentWithBrowseButton) TextBrowseFolderListener(com.intellij.openapi.ui.TextBrowseFolderListener)

Aggregations

FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)7 TextBrowseFolderListener (com.intellij.openapi.ui.TextBrowseFolderListener)7 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)4 ComponentWithBrowseButton (com.intellij.openapi.ui.ComponentWithBrowseButton)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 NotNull (org.jetbrains.annotations.NotNull)2 AndroidTargetHash.getAddonHashString (com.android.sdklib.AndroidTargetHash.getAddonHashString)1 BuildFileKey (com.android.tools.idea.gradle.parser.BuildFileKey)1 Project (com.intellij.openapi.project.Project)1 ComboBox (com.intellij.openapi.ui.ComboBox)1 DocumentAdapter (com.intellij.ui.DocumentAdapter)1 JBLabel (com.intellij.ui.components.JBLabel)1 JBTextField (com.intellij.ui.components.JBTextField)1 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)1 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)1 Url (com.intellij.util.Url)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 DocumentEvent (javax.swing.event.DocumentEvent)1