36 const String& textWhenNothingSelected)
41 enforcedSuffix (suffix)
63 g.
setColour (Colours::red.withAlpha (0.2f));
70 getLookAndFeel().layoutFilenameComponent (*
this, &filenameBox, browseButton.get());
89 browseButton.reset (
getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
91 browseButton->setConnectedEdges (Button::ConnectedOnLeft);
92 browseButton->onClick = [
this] { showChooser(); };
109 if (lastFilename.
isEmpty() && defaultBrowseFile !=
File())
110 return defaultBrowseFile;
115void FilenameComponent::showChooser()
117 chooser = std::make_unique<FileChooser> (isDir ?
TRANS (
"Choose a new directory")
118 :
TRANS (
"Choose a new file"),
128 if (chooser->getResult() ==
File{})
142 isFileDragOver =
false;
153 isFileDragOver =
true;
159 isFileDragOver =
false;
186 if (
newFile.getFullPathName() != lastFilename)
188 lastFilename =
newFile.getFullPathName();
214 for (
int i = 0; i < filenameBox.
getNumItems(); ++i)
226 for (
int i = 0; i <
jmin (
filenames.size(), maxRecentFiles); ++i)
254 listeners.add (listener);
259 listeners.remove (listener);
262void FilenameComponent::handleAsyncUpdate()
void handleUpdateNowIfNeeded()
If an update has been triggered and is pending, this will invoke it synchronously.
void triggerAsyncUpdate()
Causes the callback to be triggered at a later time.
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.
std::function< void()> onChange
You can assign a lambda to this callback object to have it called when the selected ID is changed.
void setTextWhenNothingSelected(const String &newMessage)
Sets a message to display when there is no item currently selected.
String getItemText(int index) const
Returns the text for one of the items in the list.
void setTooltip(const String &newTooltip) override
Gives the ComboBox a tooltip.
void setEditableText(bool isEditable)
Sets whether the text in the combo-box is editable.
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.
void setTextWhenNoChoicesAvailable(const String &newMessage)
Sets the message to show when there are no items in the list, and the user clicks on the drop-down bo...
A class to keep an eye on a component and check for it being deleted.
The base class for all JUCE user-interface objects.
virtual std::unique_ptr< ComponentTraverser > createKeyboardFocusTraverser()
Creates a ComponentTraverser object to use to determine the logic by which keyboard focus should be p...
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 repaint()
Marks the whole component as needing to be redrawn.
bool getWantsKeyboardFocus() const noexcept
Returns true if the component is interested in getting keyboard focus.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
@ 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).
@ canSelectDirectories
specifies that the user can select directories (can be used in conjunction with canSelectFiles).
@ openMode
specifies that the component should allow the user to choose an existing file with the intention of o...
Creates a dialog box to choose a file or directory to load or save.
Represents a local file or directory.
bool isDirectory() const
Checks whether the file is a directory that exists.
const String & getFullPathName() const noexcept
Returns the complete, absolute path of this file.
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.
File withFileExtension(StringRef newExtension) const
Returns a version of this file with a different file extension.
bool exists() const
Checks whether the file actually exists.
Listens for events happening to a FilenameComponent.
void addRecentlyUsedFile(const File &file)
Adds an entry to the recently-used files dropdown list.
void lookAndFeelChanged() override
Called to let the component react to a change in the look-and-feel setting.
File getCurrentFile() const
Returns the currently displayed filename.
void setRecentlyUsedFilenames(const StringArray &filenames)
Sets all the entries on the recent files list.
bool isInterestedInFileDrag(const StringArray &) override
Callback to check whether this target is interested in the set of files being offered.
String getCurrentFileText() const
Returns the raw text that the user has entered.
void setDefaultBrowseTarget(const File &newDefaultDirectory)
Sets a file or directory to be the default starting point for the browser to show.
void removeListener(FilenameComponentListener *listener)
Removes a previously-registered listener.
void setFilenameIsEditable(bool shouldBeEditable)
Changes whether the use can type into the filename box.
void fileDragExit(const StringArray &) override
Callback to indicate that the mouse has moved away from this component.
void paintOverChildren(Graphics &) override
Components can override this method to draw over the top of their children.
~FilenameComponent() override
Destructor.
void fileDragEnter(const StringArray &, int, int) override
Callback to indicate that some files are being dragged over this component.
void setBrowseButtonText(const String &browseButtonText)
Changes the text shown on the 'browse' button.
std::unique_ptr< ComponentTraverser > createKeyboardFocusTraverser() override
Creates a ComponentTraverser object to use to determine the logic by which keyboard focus should be p...
StringArray getRecentlyUsedFilenames() const
Returns all the entries on the recent files list.
virtual File getLocationToBrowse()
This can be overridden to return a custom location that you want the dialog box to show when the brow...
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.
void setMaxNumberOfRecentFiles(int newMaximum)
Changes the limit for the number of files that will be stored in the recent-file list.
void filesDropped(const StringArray &, int, int) override
Callback to indicate that the user has dropped the files onto this component.
void resized() override
Called when this component's size has been changed.
void addListener(FilenameComponentListener *listener)
Adds a listener that will be called when the selected file is changed.
void setCurrentFile(File newFile, bool addToRecentlyUsedList, NotificationType notification=sendNotificationAsync)
Changes the current filename.
void setTooltip(const String &newTooltip) override
Gives the component a tooltip.
A graphics context, used for drawing a component or image.
void drawRect(int x, int y, int width, int height, int lineThickness=1) const
Draws a rectangular outline, using the current colour or brush.
void setColour(Colour newColour)
Changes the current drawing colour.
A special array for holding a list of strings.
void add(String stringToAdd)
Appends a string at the end of the array.
bool isEmpty() const noexcept
Returns true if the string contains no characters.
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
#define TRANS(stringLiteral)
Uses the LocalisedStrings class to translate the given string literal.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
NotificationType
These enums are used in various classes to indicate whether a notification event should be sent out.
@ sendNotificationSync
Requests a synchronous notification.
@ 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...