Shows a filename as an editable text box, with a 'browse' button and a drop-down list for recently selected files. More...
Inherits Component, SettableTooltipClient, FileDragAndDropTarget, AsyncUpdater, and ComboBox::Listener.
Public Member Functions | |
| FilenameComponent (const String &name, const File ¤tFile, bool canEditFilename, bool isDirectory, bool isForSaving, const String &fileBrowserWildcard, const String &enforcedSuffix, const String &textWhenNothingSelected) | |
| Creates a FilenameComponent. | |
| ~FilenameComponent () | |
| Destructor. | |
| File | getCurrentFile () const |
| Returns the currently displayed filename. | |
| void | setCurrentFile (File newFile, bool addToRecentlyUsedList, bool sendChangeNotification=true) |
| Changes the current filename. | |
| void | setFilenameIsEditable (bool shouldBeEditable) |
| Changes whether the use can type into the filename box. | |
| void | setDefaultBrowseTarget (const File &newDefaultDirectory) |
| Sets a file or directory to be the default starting point for the browser to show. | |
| StringArray | getRecentlyUsedFilenames () const |
| Returns all the entries on the recent files list. | |
| void | setRecentlyUsedFilenames (const StringArray &filenames) |
| Sets all the entries on the recent files list. | |
| void | addRecentlyUsedFile (const File &file) |
| Adds an entry to the recently-used files dropdown list. | |
| void | setMaxNumberOfRecentFiles (int newMaximum) |
| Changes the limit for the number of files that will be stored in the recent-file list. | |
| void | setBrowseButtonText (const String &browseButtonText) |
| Changes the text shown on the 'browse' button. | |
| void | addListener (FilenameComponentListener *listener) |
| Adds a listener that will be called when the selected file is changed. | |
| void | removeListener (FilenameComponentListener *listener) |
| Removes a previously-registered listener. | |
| void | setTooltip (const String &newTooltip) |
| Gives the component a tooltip. | |
| void | paintOverChildren (Graphics &g) |
| Components can override this method to draw over the top of their children. | |
| void | resized () |
| Called when this component's size has been changed. | |
| void | lookAndFeelChanged () |
| Called to let the component react to a change in the look-and-feel setting. | |
| bool | isInterestedInFileDrag (const StringArray &files) |
| Callback to check whether this target is interested in the set of files being offered. | |
| void | filesDropped (const StringArray &files, int, int) |
| Callback to indicate that the user has dropped the files onto this component. | |
| void | fileDragEnter (const StringArray &files, int, int) |
| Callback to indicate that some files are being dragged over this component. | |
| void | fileDragExit (const StringArray &files) |
| Callback to indicate that the mouse has moved away from this component. | |
Shows a filename as an editable text box, with a 'browse' button and a drop-down list for recently selected files.
A handy component for dialogue boxes where you want the user to be able to select a file or directory.
Attach an FilenameComponentListener using the addListener() method, and it will get called each time the user changes the filename, either by browsing for a file and clicking 'ok', or by typing a new filename into the box and pressing return.
| FilenameComponent::FilenameComponent | ( | const String & | name, |
| const File & | currentFile, | ||
| bool | canEditFilename, | ||
| bool | isDirectory, | ||
| bool | isForSaving, | ||
| const String & | fileBrowserWildcard, | ||
| const String & | enforcedSuffix, | ||
| const String & | textWhenNothingSelected | ||
| ) |
Creates a FilenameComponent.
| name | the name for this component. |
| currentFile | the file to initially show in the box |
| canEditFilename | if true, the user can manually edit the filename; if false, they can only change it by browsing for a new file |
| isDirectory | if true, the file will be treated as a directory, and an appropriate directory browser used |
| isForSaving | if true, the file browser will allow non-existent files to be picked, as the file is assumed to be used for saving rather than loading |
| fileBrowserWildcard | a wildcard pattern to use in the file browser - e.g. "*.txt;*.foo". If an empty string is passed in, then the pattern is assumed to be "*" |
| enforcedSuffix | if this is non-empty, it is treated as a suffix that will be added to any filenames that are entered or chosen |
| textWhenNothingSelected | the message to display in the box before any filename is entered. (This will only appear if the initial file isn't valid) |
| FilenameComponent::~FilenameComponent | ( | ) |
Destructor.
| File FilenameComponent::getCurrentFile | ( | ) | const |
Returns the currently displayed filename.
| void FilenameComponent::setCurrentFile | ( | File | newFile, |
| bool | addToRecentlyUsedList, | ||
| bool | sendChangeNotification = true |
||
| ) |
Changes the current filename.
If addToRecentlyUsedList is true, the filename will also be added to the drop-down list of recent files.
If sendChangeNotification is false, then the listeners won't be told of the change.
| void FilenameComponent::setFilenameIsEditable | ( | bool | shouldBeEditable ) |
Changes whether the use can type into the filename box.
| void FilenameComponent::setDefaultBrowseTarget | ( | const File & | newDefaultDirectory ) |
Sets a file or directory to be the default starting point for the browser to show.
This is only used if the current file hasn't been set.
| StringArray FilenameComponent::getRecentlyUsedFilenames | ( | ) | const |
Returns all the entries on the recent files list.
This can be used in conjunction with setRecentlyUsedFilenames() for saving the state of this list.
| void FilenameComponent::setRecentlyUsedFilenames | ( | const StringArray & | filenames ) |
Sets all the entries on the recent files list.
This can be used in conjunction with getRecentlyUsedFilenames() for saving the state of this list.
| void FilenameComponent::addRecentlyUsedFile | ( | const File & | file ) |
Adds an entry to the recently-used files dropdown list.
If the file is already in the list, it will be moved to the top. A limit is also placed on the number of items that are kept in the list.
| void FilenameComponent::setMaxNumberOfRecentFiles | ( | int | newMaximum ) |
Changes the limit for the number of files that will be stored in the recent-file list.
| void FilenameComponent::setBrowseButtonText | ( | const String & | browseButtonText ) |
Changes the text shown on the 'browse' button.
By default this button just says "..." but you can change it. The button itself can be changed using the look-and-feel classes, so it might not actually have any text on it.
| void FilenameComponent::addListener | ( | FilenameComponentListener * | listener ) |
Adds a listener that will be called when the selected file is changed.
| void FilenameComponent::removeListener | ( | FilenameComponentListener * | listener ) |
Removes a previously-registered listener.
| void FilenameComponent::setTooltip | ( | const String & | newTooltip ) | [virtual] |
Gives the component a tooltip.
Reimplemented from SettableTooltipClient.
| void FilenameComponent::paintOverChildren | ( | Graphics & | g ) | [virtual] |
| void FilenameComponent::resized | ( | ) | [virtual] |
Called when this component's size has been changed.
A component can implement this method to do things such as laying out its child components when its width or height changes.
The method is called synchronously as a result of the setBounds or setSize methods, so repeatedly changing a components size will repeatedly call its resized method (unlike things like repainting, where multiple calls to repaint are coalesced together).
If the component is a top-level window on the desktop, its size could also be changed by operating-system factors beyond the application's control.
Reimplemented from Component.
| void FilenameComponent::lookAndFeelChanged | ( | ) | [virtual] |
Called to let the component react to a change in the look-and-feel setting.
When the look-and-feel is changed for a component, this will be called in all its child components, recursively.
It can also be triggered manually by the sendLookAndFeelChange() method, in case an application uses a LookAndFeel class that might have changed internally.
Reimplemented from Component.
| bool FilenameComponent::isInterestedInFileDrag | ( | const StringArray & | files ) | [virtual] |
Callback to check whether this target is interested in the set of files being offered.
Note that this will be called repeatedly when the user is dragging the mouse around over your component, so don't do anything time-consuming in here, like opening the files to have a look inside them!
| files | the set of (absolute) pathnames of the files that the user is dragging |
Implements FileDragAndDropTarget.
| void FilenameComponent::filesDropped | ( | const StringArray & | files, |
| int | x, | ||
| int | y | ||
| ) | [virtual] |
Callback to indicate that the user has dropped the files onto this component.
When the user drops the files, this get called, and you can use the files in whatever way is appropriate.
Note that after this is called, the fileDragExit method may not be called, so you should clean up in here if there's anything you need to do when the drag finishes.
| files | the set of (absolute) pathnames of the files that the user is dragging |
| x | the mouse x position, relative to this component |
| y | the mouse y position, relative to this component |
Implements FileDragAndDropTarget.
| void FilenameComponent::fileDragEnter | ( | const StringArray & | files, |
| int | x, | ||
| int | y | ||
| ) | [virtual] |
Callback to indicate that some files are being dragged over this component.
This gets called when the user moves the mouse into this component while dragging.
Use this callback as a trigger to make your component repaint itself to give the user feedback about whether the files can be dropped here or not.
| files | the set of (absolute) pathnames of the files that the user is dragging |
| x | the mouse x position, relative to this component |
| y | the mouse y position, relative to this component |
Reimplemented from FileDragAndDropTarget.
| void FilenameComponent::fileDragExit | ( | const StringArray & | files ) | [virtual] |
Callback to indicate that the mouse has moved away from this component.
This gets called when the user moves the mouse out of this component while dragging the files.
If you've used fileDragEnter() to repaint your component and give feedback, use this as a signal to repaint it in its normal state.
| files | the set of (absolute) pathnames of the files that the user is dragging |
Reimplemented from FileDragAndDropTarget.