37 currentPathBox (
"path"),
38 fileLabel (
"f",
TRANS (
"file:")),
39 thread (
"JUCE FileBrowser"),
40 wasProcessActive (
true)
43 jassert ((flags & (saveMode | openMode)) != 0);
44 jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
47 jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
69 fileList.reset (
new DirectoryContentsList (
this, thread));
70 fileList->setDirectory (currentRoot,
true,
true);
72 if ((flags & useTreeView) != 0)
74 auto tree =
new FileTreeComponent (*fileList);
75 fileListComponent.reset (tree);
77 if ((flags & canSelectMultipleItems) != 0)
78 tree->setMultiSelectEnabled (
true);
80 addAndMakeVisible (tree);
84 auto list =
new FileListComponent (*fileList);
85 fileListComponent.reset (list);
86 list->setOutlineThickness (1);
88 if ((flags & canSelectMultipleItems) != 0)
89 list->setMultipleSelectionEnabled (
true);
91 addAndMakeVisible (list);
94 fileListComponent->addListener (
this);
96 addAndMakeVisible (currentPathBox);
97 currentPathBox.setEditableText (
true);
99 currentPathBox.onChange = [
this] { updateSelectedPath(); };
101 addAndMakeVisible (filenameBox);
102 filenameBox.setMultiLine (
false);
103 filenameBox.setSelectAllWhenFocused (
true);
104 filenameBox.setText (filename,
false);
105 filenameBox.onTextChange = [
this] { sendListenerChangeMessage(); };
106 filenameBox.onReturnKey = [
this] { changeFilename(); };
107 filenameBox.onFocusLost = [
this]
113 filenameBox.setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
115 addAndMakeVisible (fileLabel);
116 fileLabel.attachToComponent (&filenameBox,
true);
118 if (previewComp !=
nullptr)
119 addAndMakeVisible (previewComp);
121 lookAndFeelChanged();
123 setRoot (currentRoot);
126 setFileName (filename);
133 fileListComponent.reset();
146 listeners.remove (listener);
160 return chosenFiles.size();
165 if ((flags & canSelectDirectories) != 0 && filenameBox.getText().isEmpty())
168 if (! filenameBox.isReadOnly())
169 return currentRoot.
getChildFile (filenameBox.getText());
171 return chosenFiles[index];
186 return fileListComponent->getSelectedFile (0);
191 fileListComponent->deselectAllFiles();
206bool FileBrowserComponent::isFileOrDirSuitable (
const File& f)
const
224 bool callListeners =
false;
228 callListeners =
true;
229 fileListComponent->scrollToTop();
243 for (
int i = currentPathBox.
getNumItems(); --i >= 0;)
258 fileList->setDirectory (currentRoot,
true,
true);
282 filenameBox.
setText (newName,
true);
284 fileListComponent->setSelectedFile (currentRoot.
getChildFile (newName));
289 currentPathBox.
clear();
294 for (
int i = 0; i <
rootNames.size(); ++i)
341DirectoryContentsDisplayComponent* FileBrowserComponent::getDisplayComponent()
const noexcept
343 return fileListComponent.get();
350 .layoutFileBrowserComponent (*
this, fileListComponent.get(), previewComp,
351 ¤tPathBox, &filenameBox, goUpButton.get());
357 goUpButton.reset (
getLookAndFeel().createFileBrowserGoUpButton());
377void FileBrowserComponent::sendListenerChangeMessage()
381 if (previewComp !=
nullptr)
395 for (
int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
397 const File f (fileListComponent->getSelectedFile (i));
399 if (isFileOrDirSuitable (f))
415 sendListenerChangeMessage();
444 #if JUCE_LINUX || JUCE_BSD || JUCE_WINDOWS
445 if (key.getModifiers().isCommandDown()
446 && (key.getKeyCode() ==
'H' || key.getKeyCode() ==
'h'))
448 fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
458void FileBrowserComponent::changeFilename()
487void FileBrowserComponent::updateSelectedPath()
530 for (
int i = 0; i <
roots.size(); ++i)
532 const File& drive =
roots.getReference (i);
544 name <<
" [" <<
volume <<
']';
548 name <<
" [" <<
TRANS (
"CD/DVD drive") <<
']';
583 if (
volume.isDirectory() && !
volume.getFileName().startsWithChar (
'.'))
605void FileBrowserComponent::timerCallback()
607 const auto isProcessActive = detail::WindowingHelpers::isForegroundOrEmbeddedProcess (
this);
621 return std::make_unique<AccessibilityHandler> (*
this, AccessibilityRole::group);
Holds a resizable array of primitive or copy-by-value objects.
@ arrowColourId
The colour for the arrow shape that pops up the menu.
@ textColourId
The colour for the text in the box.
@ backgroundColourId
The background colour to fill the box with.
void setText(const String &newText, NotificationType notification=sendNotificationAsync)
Sets the contents of the combo-box's text field.
void clear(NotificationType notification=sendNotificationAsync)
Removes all the items from the drop-down list.
String getItemText(int index) const
Returns the text for one of the items in the list.
void addSeparator()
Adds a separator line to the drop-down list.
int getSelectedId() const noexcept
Returns the ID of the item that's currently shown in the box.
String getText() const
Returns the text that is currently shown in the combo-box's text field.
void addItem(const String &newItemText, int newItemId)
Adds an item to be shown in the drop-down list.
int getNumItems() const noexcept
Returns the number of items that have been added to the list.
A class to keep an eye on a component and check for it being deleted.
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
void setColour(int colourID, Colour newColour)
Registers a colour to be used for a particular purpose.
Colour findColour(int colourID, bool inheritFromParent=false) const
Looks for a colour that has been registered with the given colour ID number.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
void refresh()
Refreshes the directory that's currently being listed.
void resized() override
Called when this component's size has been changed.
static void getDefaultRoots(StringArray &rootNames, StringArray &rootPaths)
Returns a platform-specific list of names and paths for some suggested places the user might want to ...
File getSelectedFile(int index) const noexcept
Returns one of the files that the user has chosen.
@ saveMode
specifies that the component should allow the user to specify the name of a file that will be used to...
@ canSelectFiles
specifies that the user can select files (can be used in conjunction with canSelectDirectories).
@ doNotClearFileNameOnRootChange
specifies that the file name should not be cleared upon root change.
@ canSelectDirectories
specifies that the user can select directories (can be used in conjunction with canSelectFiles).
void selectionChanged() override
Callback when the user selects a different file in the browser.
FileBrowserComponent(int flags, const File &initialFileOrDirectory, const FileFilter *fileFilter, FilePreviewComponent *previewComp)
Creates a FileBrowserComponent.
virtual String getActionVerb() const
Returns a verb to describe what should happen when the file is accepted.
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 browserRootChanged(const File &) override
Callback when the browser's root folder changes.
void setFileFilter(const FileFilter *newFileFilter)
Changes the filter that's being used to sift the files.
void goUp()
Equivalent to pressing the "up" button to browse the parent directory.
void fileClicked(const File &, const MouseEvent &) override
Callback when the user clicks on a file in the browser.
void setFilenameBoxLabel(const String &name)
Sets the label that will be displayed next to the filename entry box.
void setRoot(const File &newRootDirectory)
Changes the directory that's being shown in the listbox.
void deselectAllFiles()
Deselects any files that are currently selected.
void removeListener(FileBrowserListener *listener)
Removes a listener.
void lookAndFeelChanged() override
Called to let the component react to a change in the look-and-feel setting.
void setFileName(const String &newName)
Changes the name that is currently shown in the filename box.
bool isDirectorySuitable(const File &) const override
Should return true if this directory is suitable for inclusion in whatever context the object is bein...
File getHighlightedFile() const noexcept
This returns the last item in the view that the user has highlighted.
bool isFileSuitable(const File &) const override
Should return true if this file is suitable for inclusion in whatever context the object is being use...
bool isSaveMode() const noexcept
Returns true if the saveMode flag was set when this component was created.
int getNumSelectedFiles() const noexcept
Returns the number of files that the user has got selected.
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
const File & getRoot() const
Returns the directory whose contents are currently being shown in the listbox.
~FileBrowserComponent() override
Destructor.
bool currentFileIsValid() const
Returns true if the currently selected file(s) are usable.
@ currentPathBoxTextColourId
The colour to use for the text of the current path ComboBox.
@ filenameBoxBackgroundColourId
The colour to use to fill the background of the filename TextEditor.
@ currentPathBoxBackgroundColourId
The colour to use to fill the background of the current path ComboBox.
@ filenameBoxTextColourId
The colour to use for the text of the filename TextEditor.
@ currentPathBoxArrowColourId
The colour to use to draw the arrow of the current path ComboBox.
void addListener(FileBrowserListener *listener)
Adds a listener to be told when the user selects and clicks on files.
bool keyPressed(const KeyPress &) override
Called when a key is pressed.
void fileDoubleClicked(const File &) override
Callback when the user double-clicks on a file in the browser.
void resetRecentPaths()
Updates the items in the dropdown list of recent paths with the values from getRoots().
A listener for user selection events in a file browser.
Interface for deciding which files are suitable for something.
virtual bool isFileSuitable(const File &file) const =0
Should return true if this file is suitable for inclusion in whatever context the object is being use...
virtual bool isDirectorySuitable(const File &file) const =0
Should return true if this directory is suitable for inclusion in whatever context the object is bein...
Base class for components that live inside a file chooser dialog box and show previews of the files t...
virtual void selectedFileChanged(const File &newSelectedFile)=0
Called to indicate that the user's currently selected file has changed.
A component that displays the files in a directory as a treeview.
Represents a local file or directory.
bool isOnHardDisk() const
Returns true if this file is on a hard disk.
bool isDirectory() const
Checks whether the file is a directory that exists.
Array< File > findChildFiles(int whatToLookFor, bool searchRecursively, const String &wildCardPattern="*", FollowSymlinks followSymlinks=FollowSymlinks::yes) const
Searches this directory for files matching a wildcard pattern.
bool isOnCDRomDrive() const
Returns true if this file is on a CD or DVD drive.
static StringRef getSeparatorString()
The system-specific file separator character, as a string.
const String & getFullPathName() const noexcept
Returns the complete, absolute path of this file.
String getFileName() const
Returns the last section of the pathname.
File getChildFile(StringRef relativeOrAbsolutePath) const
Returns a file that represents a relative (or absolute) sub-path of the current one.
static File getCurrentWorkingDirectory()
Returns the current working directory.
@ userMusicDirectory
The most likely place where a user might store their music files.
@ userDocumentsDirectory
The user's default documents folder.
@ userPicturesDirectory
The most likely place where a user might store their picture files.
@ userDesktopDirectory
The folder that contains the user's desktop objects.
@ userHomeDirectory
The user's home folder.
static void findFileSystemRoots(Array< File > &results)
Creates a set of files to represent each file root.
String getRelativePathFrom(const File &directoryToBeRelativeTo) const
Creates a relative path that refers to a file relatively to a given directory.
@ findDirectories
Use this flag to indicate that you want to find directories.
static File JUCE_CALLTYPE getSpecialLocation(const SpecialLocationType type)
Finds the location of a special type of file or directory, such as a home folder or documents folder.
File getParentDirectory() const
Returns the directory that contains this file or directory.
String getVolumeLabel() const
Finds the name of the drive on which this file lives.
static juce_wchar getSeparatorChar()
The system-specific file separator character.
bool exists() const
Checks whether the file actually exists.
Represents a key press, including any modifier keys that are needed.
void setText(const String &newText, NotificationType notification)
Changes the label text.
Contains position and status information about a mouse event.
A special array for holding a list of strings.
bool equalsIgnoreCase(const String &other) const noexcept
Case-insensitive comparison with another string.
String trim() const
Returns a copy of this string with any whitespace characters removed from the start and end.
bool isEmpty() const noexcept
Returns true if the string contains no characters.
bool containsChar(juce_wchar character) const noexcept
Tests whether the string contains a particular character.
String unquoted() const
Removes quotation marks from around the string, (if there are any).
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
@ backgroundColourId
The colour to use for the text component's background - this can be transparent if necessary.
void applyColourToAllText(const Colour &newColour, bool changeCurrentTextColour=true)
Applies a colour to all the text in the editor.
void setText(const String &newText, bool sendTextChangeMessage=true)
Sets the entire content of the editor.
String getText() const
Returns the entire contents of the editor.
bool stopThread(int timeOutMilliseconds)
Attempts to stop the thread running.
@ low
Uses efficiency cores when possible.
#define TRANS(stringLiteral)
Uses the LocalisedStrings class to translate the given string literal.
@ dontSendNotification
No notification message should be sent.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...