mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-28 01:07:49 +08:00
[site] Cleanup
This commit is contained in:
parent
88f7c4ec54
commit
bb74e8ecb1
@ -10,17 +10,47 @@ INITIAL_SOURCE https://confluence.jetbrains.com/display/IDEADEV/File+and+Class+C
|
||||
|
||||
## File Choosers
|
||||
|
||||
To let a user choose a file, directory or multiple files, use the ```FileChooser.chooseFiles()``` method. This method has multiple overloads; the best method to use is the one which returns void and takes a callback receiving the list of selected files as a parameter. This is the only overload which will display a native file open dialog on Mac OS X.
|
||||
To let a user choose a file, directory or multiple files, use the
|
||||
[FileChooser.chooseFiles()](https://github.com/JetBrains/intellij-community/blob/master/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooser.java)
|
||||
method.
|
||||
This method has multiple overloads.
|
||||
The best method to use is the one which returns void and takes a callback receiving the list of selected files as a parameter.
|
||||
This is the only overload which will display a native file open dialog on Mac OS X.
|
||||
|
||||
The FileChooserDescriptor class allows you to control which files can be selected. The constructor parameters specify whether files and/or directories can be selected, and whether multiple selection is allowed. For more fine-grained control over the allowed selection, you can overload the ```isFileSelectable()``` method. You can also customize the presentation of files by overloading getIcon(), getName() and getComment() methods on FileChooserDescriptor. Note that the native Mac OS X file chooser does not support most of the customizations, so if you rely on them, you need to use an overload of ```chooseFiles()``` which displays the standard IntelliJ IDEA dialog.
|
||||
The
|
||||
[FileChooserDescriptor](https://github.com/JetBrains/intellij-community/blob/master/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooserDescriptor.java)
|
||||
class allows you to control which files can be selected.
|
||||
The constructor parameters specify whether files and/or directories can be selected, and whether multiple selection is allowed.
|
||||
For more fine-grained control over the allowed selection, you can overload the ```isFileSelectable()``` method.
|
||||
You can also customize the presentation of files by overloading ```getIcon()```, ```getName()``` and ```getComment()``` methods on
|
||||
[FileChooserDescriptor](https://github.com/JetBrains/intellij-community/blob/master/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooserDescriptor.java).
|
||||
Note that the native Mac OS X file chooser does not support most of the customizations, so if you rely on them, you need to use an overload of ```chooseFiles()``` which displays the standard *IntelliJ IDEA* dialog.
|
||||
|
||||
A very common way of using file choosers is to use a text field for entering the path with an ellipsis button ("...") for showing the file chooser. To create such a control, use the ```TextFieldWithBrowseButton``` component and call the ```addBrowseFolderListener()``` method on it to set up the file chooser. As an added bonus, this will enable filename completion when entering paths in the text box.
|
||||
A very common way of using file choosers is to use a text field for entering the path with an ellipsis button ("...") for showing the file chooser.
|
||||
To create such a control, use the
|
||||
[TextFieldWithBrowseButton](https://github.com/JetBrains/intellij-community/blob/master/platform/platform-api/src/com/intellij/openapi/ui/TextFieldWithBrowseButton.java)
|
||||
component and call the ```addBrowseFolderListener()``` method on it to set up the file chooser.
|
||||
As an added bonus, this will enable filename completion when entering paths in the text box.
|
||||
|
||||
An alternative UI for selecting files, which works best when the most common way of selecting a file is by typing its name, is available through the ```TreeFileChooserFactory``` class. The dialog shown by this API has two tabs: one shows the project structure and another shows a list of files similar to the one used by the "Goto File" popup. To show the dialog, call ```showDialog()``` on the chooser returned from ```createFileChooser()```, and then call ```getSelectedFile``` to retrieve the user's selection.
|
||||
An alternative UI for selecting files, which works best when the most common way of selecting a file is by typing its name, is available through the
|
||||
[TreeFileChooserFactory](https://github.com/JetBrains/intellij-community/blob/master/platform/lang-api/src/com/intellij/ide/util/TreeFileChooserFactory.java) class.
|
||||
|
||||
The dialog shown by this API has two tabs:
|
||||
|
||||
* One shows the project structure
|
||||
|
||||
* Another shows a list of files similar to the one used by the ```Goto File``` popup.
|
||||
|
||||
To show the dialog, call ```showDialog()``` on the chooser returned from ```createFileChooser()```, and then call ```getSelectedFile``` to retrieve the user's selection.
|
||||
|
||||
## Class and Package Choosers
|
||||
|
||||
If you want to offer the user a possibility to select a Java class, you can use the ```TreeClassChooserFactory``` class. Its different methods allow you to specify the scope from which the classes are taken, to restrict the choice to descendants of a specific class or implementations of an interface, and to include or exclude inner classes from the list.
|
||||
If you want to offer the user a possibility to select a Java class, you can use the
|
||||
[TreeClassChooserFactory](https://github.com/JetBrains/intellij-community/blob/master/java/openapi/src/com/intellij/ide/util/TreeClassChooserFactory.java)
|
||||
class.
|
||||
Its different methods allow you to specify the scope from which the classes are taken, to restrict the choice to descendants of a specific class or implementations of an interface, and to include or exclude inner classes from the list.
|
||||
|
||||
For choosing a Java package, you can use the ```PackageChooserDialog``` class.
|
||||
For choosing a Java package, you can use the
|
||||
[PackageChooserDialog](https://github.com/JetBrains/intellij-community/blob/master/java/java-impl/src/com/intellij/ide/util/PackageChooserDialog.java)
|
||||
class.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user