34 chooserComponent (chooser),
36 cancelButton (
TRANS (
"Cancel")),
37 newFolderButton (
TRANS (
"New Folder")),
61 const int buttonHeight = 26;
70 chooserComponent.
setBounds (area.removeFromTop (area.getHeight() - buttonHeight - 20));
86 TextButton okButton, cancelButton, newFolderButton;
93 const String& instructions,
107 content->okButton.
onClick = [
this] { okButtonPressed(); };
108 content->cancelButton.
onClick = [
this] { closeButtonPressed(); };
109 content->newFolderButton.
onClick = [
this] { createNewFolder(); };
113 FileChooserDialogBox::selectionChanged();
127#if JUCE_MODAL_LOOPS_PERMITTED
128bool FileChooserDialogBox::show (
int w,
int h)
130 return showAt (-1, -1, w, h);
133bool FileChooserDialogBox::showAt (
int x,
int y,
int w,
int h)
135 if (w <= 0) w = getDefaultWidth();
154int FileChooserDialogBox::getDefaultWidth()
const
156 if (
auto* previewComp = content->chooserComponent.getPreviewComponent())
157 return 400 + previewComp->getWidth();
163void FileChooserDialogBox::closeButtonPressed()
168void FileChooserDialogBox::selectionChanged()
176void FileChooserDialogBox::fileDoubleClicked (
const File&)
182void FileChooserDialogBox::fileClicked (
const File&,
const MouseEvent&) {}
183void FileChooserDialogBox::browserRootChanged (
const File&) {}
185void FileChooserDialogBox::okButtonPressed()
187 if (warnAboutOverwritingExistingFiles
192 TRANS (
"File already exists"),
193 TRANS (
"There's already a file called: FLNM")
196 +
TRANS (
"Are you sure you want to overwrite it?"),
212void FileChooserDialogBox::createNewFolderCallback (
int result, FileChooserDialogBox* box,
213 Component::SafePointer<AlertWindow>
alert)
215 if (result != 0 &&
alert !=
nullptr && box !=
nullptr)
217 alert->setVisible (
false);
218 box->createNewFolderConfirmed (
alert->getTextEditorContents (
"Folder Name"));
222void FileChooserDialogBox::createNewFolder()
224 auto parent = content->chooserComponent.
getRoot();
226 if (parent.isDirectory())
228 auto*
aw =
new AlertWindow (
TRANS (
"New Folder"),
229 TRANS (
"Please enter the name for the folder"),
232 aw->addTextEditor (
"Folder Name", String(), String(),
false);
236 aw->enterModalState (
true,
238 Component::SafePointer<AlertWindow> (
aw)),
243void FileChooserDialogBox::createNewFolderConfirmed (
const String&
nameFromDialog)
247 if (! name.isEmpty())
249 auto parent = content->chooserComponent.
getRoot();
251 if (! parent.getChildFile (name).createDirectory())
254 TRANS (
"New Folder"),
255 TRANS (
"Couldn't create the folder!"));
259 content->chooserComponent.
refresh();
static ScopedMessageBox showScopedAsync(const MessageBoxOptions &options, std::function< void(int)> callback)
Shows an alert window using the specified options.
Represents a colour, also including a transparency value.
The base class for all JUCE user-interface objects.
void setInterceptsMouseClicks(bool allowClicksOnThisComponent, bool allowClicksOnChildComponents) noexcept
Changes the default return value for the hitTest() method.
void exitModalState(int returnValue=0)
Ends a component's modal state.
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 setAlwaysOnTop(bool shouldStayOnTop)
Sets whether the component should always be kept at the front of its siblings.
void setEnabled(bool shouldBeEnabled)
Enables or disables this component.
Component() noexcept
Creates a component.
void setBounds(int x, int y, int width, int height)
Changes the component's position and size.
int getWidth() const noexcept
Returns the component's width in pixels.
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.
void centreWithSize(int width, int height)
Changes the component's size and centres it within its parent.
void addChildComponent(Component *child, int zOrder=-1)
Adds a child component to this one.
virtual void setVisible(bool shouldBeVisible)
Makes the component visible or invisible.
String getName() const noexcept
Returns the name of this component.
A component for browsing and selecting a file or directory to open or save.
void refresh()
Refreshes the directory that's currently being listed.
File getSelectedFile(int index) const noexcept
Returns one of the files that the user has chosen.
virtual String getActionVerb() const
Returns a verb to describe what should happen when the file is accepted.
void removeListener(FileBrowserListener *listener)
Removes a listener.
bool isSaveMode() const noexcept
Returns true if the saveMode flag was set when this component was created.
const File & getRoot() const
Returns the directory whose contents are currently being shown in the listbox.
bool currentFileIsValid() const
Returns true if the currently selected file(s) are usable.
void addListener(FileBrowserListener *listener)
Adds a listener to be told when the user selects and clicks on files.
void paint(Graphics &g) override
Components can override this method to draw their content.
void resized() override
Called when this component's size has been changed.
void centreWithDefaultSize(Component *componentToCentreAround=nullptr)
Sets the size of this dialog box to its default and positions it either in the centre of the screen,...
~FileChooserDialogBox() override
Destructor.
FileChooserDialogBox(const String &title, const String &instructions, FileBrowserComponent &browserComponent, bool warnAboutOverwritingExistingFiles, Colour backgroundColour, Component *parentComponent=nullptr)
Creates a file chooser box.
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.
static String createLegalFileName(const String &fileNameToFix)
Returns a version of a filename with any illegal characters removed.
bool exists() const
Checks whether the file actually exists.
A graphics context, used for drawing a component or image.
Represents a key press, including any modifier keys that are needed.
static const int escapeKey
key-code for the escape key
static const int returnKey
key-code for the return key
static MessageBoxOptions makeOptionsOkCancel(MessageBoxIconType iconType, const String &title, const String &message, const String &button1Text=String(), const String &button2Text=String(), Component *associatedComponent=nullptr)
Creates options suitable for a message box with two buttons.
static MessageBoxOptions makeOptionsOk(MessageBoxIconType iconType, const String &title, const String &message, const String &buttonText=String(), Component *associatedComponent=nullptr)
Creates options suitable for a message box with a single button.
static ModalComponentManager::Callback * forComponent(void(*functionToCall)(int, ComponentType *), ComponentType *component)
This is a utility function to create a ModalComponentManager::Callback that will call a static functi...
Rectangle< float > toFloat() const noexcept
Casts this rectangle to a Rectangle<float>.
A base class for top-level windows that can be dragged around and resized.
void setResizable(bool shouldBeResizable, bool useBottomRightCornerResizer)
Make the window resizable or fixed.
void setResizeLimits(int newMinimumWidth, int newMinimumHeight, int newMaximumWidth, int newMaximumHeight) noexcept
This sets the maximum and minimum sizes for the window.
void setContentOwned(Component *newContentComponent, bool resizeToFitWhenContentChangesSize)
Changes the current content component.
A button that uses the standard lozenge-shaped background with a line of text on it.
void changeWidthToFitText()
Changes this button's width to fit neatly around its current text, without changing its height.
A Pre-formatted piece of text, which may contain multiple fonts and colours.
void draw(Graphics &, Rectangle< float > area) const
Draws the layout within the specified area.
float getHeight() const noexcept
Returns the maximum height of the content.
void createLayout(const AttributedString &, float maxWidth)
Creates a layout from the given attributed string.
void centreAroundComponent(Component *componentToCentreAround, int width, int height)
This will set the bounds of the window so that it's centred in front of another window.
#define TRANS(stringLiteral)
Uses the LocalisedStrings class to translate the given string literal.
@ WarningIcon
An exclamation mark to indicate that the dialog is a warning about something and shouldn't be ignored...
@ NoIcon
No icon will be shown on the dialog box.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.
static bool areThereAnyAlwaysOnTopWindows()
Returns true if any windows have a z order that is higher than normal.