A component for browsing and selecting a file or directory to open or save. More...
Inherits Component, ChangeBroadcaster, FileBrowserListener, TextEditor::Listener, ComboBox::Listener, and FileFilter.
Public Types | |
| enum | FileChooserFlags { openMode = 1, saveMode = 2, canSelectFiles = 4, canSelectDirectories = 8, canSelectMultipleItems = 16, useTreeView = 32, filenameBoxIsReadOnly = 64 } |
Various options for the browser. More... | |
Public Member Functions | |
| FileBrowserComponent (int flags, const File &initialFileOrDirectory, const FileFilter *fileFilter, FilePreviewComponent *previewComp) | |
| Creates a FileBrowserComponent. | |
| ~FileBrowserComponent () | |
| Destructor. | |
| int | getNumSelectedFiles () const noexcept |
| Returns the number of files that the user has got selected. | |
| File | getSelectedFile (int index) const noexcept |
| Returns one of the files that the user has chosen. | |
| void | deselectAllFiles () |
| Deselects any files that are currently selected. | |
| bool | currentFileIsValid () const |
| Returns true if the currently selected file(s) are usable. | |
| File | getHighlightedFile () const noexcept |
| This returns the last item in the view that the user has highlighted. | |
| const File & | getRoot () const |
| Returns the directory whose contents are currently being shown in the listbox. | |
| void | setRoot (const File &newRootDirectory) |
| Changes the directory that's being shown in the listbox. | |
| void | goUp () |
| Equivalent to pressing the "up" button to browse the parent directory. | |
| void | refresh () |
| Refreshes the directory that's currently being listed. | |
| void | setFileFilter (const FileFilter *newFileFilter) |
| Changes the filter that's being used to sift the files. | |
| virtual const String | getActionVerb () const |
| Returns a verb to describe what should happen when the file is accepted. | |
| bool | isSaveMode () const noexcept |
| Returns true if the saveMode flag was set when this component was created. | |
| void | addListener (FileBrowserListener *listener) |
| Adds a listener to be told when the user selects and clicks on files. | |
| void | removeListener (FileBrowserListener *listener) |
| Removes a listener. | |
| void | resized () |
| Called when this component's size has been changed. | |
| void | buttonClicked (Button *b) |
| void | comboBoxChanged (ComboBox *) |
| Called when a ComboBox has its selected item changed. | |
| void | textEditorTextChanged (TextEditor &editor) |
| Called when the user changes the text in some way. | |
| void | textEditorReturnKeyPressed (TextEditor &editor) |
| Called when the user presses the return key. | |
| void | textEditorEscapeKeyPressed (TextEditor &editor) |
| Called when the user presses the escape key. | |
| void | textEditorFocusLost (TextEditor &editor) |
| Called when the text editor loses focus. | |
| bool | keyPressed (const KeyPress &key) |
| Called when a key is pressed. | |
| void | selectionChanged () |
| Callback when the user selects a different file in the browser. | |
| void | fileClicked (const File &f, const MouseEvent &e) |
| Callback when the user clicks on a file in the browser. | |
| void | fileDoubleClicked (const File &f) |
| Callback when the user double-clicks on a file in the browser. | |
| bool | isFileSuitable (const File &file) const |
| Should return true if this file is suitable for inclusion in whatever context the object is being used. | |
| bool | isDirectorySuitable (const File &) const |
| Should return true if this directory is suitable for inclusion in whatever context the object is being used. | |
| FilePreviewComponent * | getPreviewComponent () const noexcept |
Protected Member Functions | |
| virtual void | getRoots (StringArray &rootNames, StringArray &rootPaths) |
| Returns a list of names and paths for the default places the user might want to look. | |
| void | resetRecentPaths () |
| Updates the items in the dropdown list of recent paths with the values from getRoots(). | |
A component for browsing and selecting a file or directory to open or save.
This contains a FileListComponent and adds various boxes and controls for navigating and selecting a file. It can work in different modes so that it can be used for loading or saving a file, or for choosing a directory.
Various options for the browser.
A combination of these is passed into the FileBrowserComponent constructor.
| FileBrowserComponent::FileBrowserComponent | ( | int | flags, |
| const File & | initialFileOrDirectory, | ||
| const FileFilter * | fileFilter, | ||
| FilePreviewComponent * | previewComp | ||
| ) |
Creates a FileBrowserComponent.
| flags | A combination of flags from the FileChooserFlags enumeration, used to specify the component's behaviour. The flags must contain either openMode or saveMode, and canSelectFiles and/or canSelectDirectories. |
| initialFileOrDirectory | The file or directory that should be selected when the component begins. If this is File::nonexistent, a default directory will be chosen. |
| fileFilter | an optional filter to use to determine which files are shown. If this is 0 then all files are displayed. Note that a pointer is kept internally to this object, so make sure that it is not deleted before the browser object is deleted. |
| previewComp | an optional preview component that will be used to show previews of files that the user selects |
| FileBrowserComponent::~FileBrowserComponent | ( | ) |
Destructor.
| int FileBrowserComponent::getNumSelectedFiles | ( | ) | const |
Returns the number of files that the user has got selected.
If multiple select isn't active, this will only be 0 or 1. To get the complete list of files they've chosen, pass an index to getCurrentFile().
| File FileBrowserComponent::getSelectedFile | ( | int | index ) | const |
Returns one of the files that the user has chosen.
If the box has multi-select enabled, the index lets you specify which of the files to get - see getNumSelectedFiles() to find out how many files were chosen.
| void FileBrowserComponent::deselectAllFiles | ( | ) |
Deselects any files that are currently selected.
| bool FileBrowserComponent::currentFileIsValid | ( | ) | const |
Returns true if the currently selected file(s) are usable.
This can be used to decide whether the user can press "ok" for the current file. What it does depends on the mode, so for example in an "open" mode, this only returns true if a file has been selected and if it exists. In a "save" mode, a non-existent file would also be valid.
| File FileBrowserComponent::getHighlightedFile | ( | ) | const |
This returns the last item in the view that the user has highlighted.
This may be different from getCurrentFile(), which returns the value that is shown in the filename box, and if there are multiple selections, this will only return one of them.
| const File& FileBrowserComponent::getRoot | ( | ) | const |
Returns the directory whose contents are currently being shown in the listbox.
| void FileBrowserComponent::setRoot | ( | const File & | newRootDirectory ) |
Changes the directory that's being shown in the listbox.
| void FileBrowserComponent::goUp | ( | ) |
Equivalent to pressing the "up" button to browse the parent directory.
| void FileBrowserComponent::refresh | ( | ) |
Refreshes the directory that's currently being listed.
| void FileBrowserComponent::setFileFilter | ( | const FileFilter * | newFileFilter ) |
Changes the filter that's being used to sift the files.
| virtual const String FileBrowserComponent::getActionVerb | ( | ) | const [virtual] |
Returns a verb to describe what should happen when the file is accepted.
E.g. if browsing in "load file" mode, this will be "Open", if in "save file" mode, it'll be "Save", etc.
| bool FileBrowserComponent::isSaveMode | ( | ) | const |
Returns true if the saveMode flag was set when this component was created.
| void FileBrowserComponent::addListener | ( | FileBrowserListener * | listener ) |
Adds a listener to be told when the user selects and clicks on files.
| void FileBrowserComponent::removeListener | ( | FileBrowserListener * | listener ) |
Removes a listener.
| void FileBrowserComponent::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 FileBrowserComponent::buttonClicked | ( | Button * | b ) |
| void FileBrowserComponent::comboBoxChanged | ( | ComboBox * | comboBoxThatHasChanged ) | [virtual] |
Called when a ComboBox has its selected item changed.
Implements ComboBox::Listener.
| void FileBrowserComponent::textEditorTextChanged | ( | TextEditor & | editor ) | [virtual] |
Called when the user changes the text in some way.
Reimplemented from TextEditor::Listener.
| void FileBrowserComponent::textEditorReturnKeyPressed | ( | TextEditor & | editor ) | [virtual] |
Called when the user presses the return key.
Reimplemented from TextEditor::Listener.
| void FileBrowserComponent::textEditorEscapeKeyPressed | ( | TextEditor & | editor ) | [virtual] |
Called when the user presses the escape key.
Reimplemented from TextEditor::Listener.
| void FileBrowserComponent::textEditorFocusLost | ( | TextEditor & | editor ) | [virtual] |
Called when the text editor loses focus.
Reimplemented from TextEditor::Listener.
| bool FileBrowserComponent::keyPressed | ( | const KeyPress & | key ) | [virtual] |
Called when a key is pressed.
When a key is pressed, the component that has the keyboard focus will have this method called. Remember that a component will only be given the focus if its setWantsKeyboardFocus() method has been used to enable this.
If your implementation returns true, the event will be consumed and not passed on to any other listeners. If it returns false, the key will be passed to any KeyListeners that have been registered with this component. As soon as one of these returns true, the process will stop, but if they all return false, the event will be passed upwards to this component's parent, and so on.
The default implementation of this method does nothing and returns false.
Reimplemented from Component.
| void FileBrowserComponent::selectionChanged | ( | ) | [virtual] |
Callback when the user selects a different file in the browser.
Implements FileBrowserListener.
| void FileBrowserComponent::fileClicked | ( | const File & | file, |
| const MouseEvent & | e | ||
| ) | [virtual] |
Callback when the user clicks on a file in the browser.
Implements FileBrowserListener.
| void FileBrowserComponent::fileDoubleClicked | ( | const File & | file ) | [virtual] |
Callback when the user double-clicks on a file in the browser.
Implements FileBrowserListener.
| bool FileBrowserComponent::isFileSuitable | ( | const File & | file ) | const [virtual] |
Should return true if this file is suitable for inclusion in whatever context the object is being used.
Implements FileFilter.
| bool FileBrowserComponent::isDirectorySuitable | ( | const File & | file ) | const [virtual] |
Should return true if this directory is suitable for inclusion in whatever context the object is being used.
Implements FileFilter.
| FilePreviewComponent* FileBrowserComponent::getPreviewComponent | ( | ) | const |
| virtual void FileBrowserComponent::getRoots | ( | StringArray & | rootNames, |
| StringArray & | rootPaths | ||
| ) | [protected, virtual] |
Returns a list of names and paths for the default places the user might want to look.
Use an empty string to indicate a section break.
| void FileBrowserComponent::resetRecentPaths | ( | ) | [protected] |
Updates the items in the dropdown list of recent paths with the values from getRoots().