31 public FileChooser::Pimpl
40 filter (selectsFiles ? owner.filters :
String(), selectsDirectories ?
"*" :
String(), {}),
41 browserComponent (flags, owner.startingFile, &filter,
preview),
42 dialogBox (owner.title, {}, browserComponent, warnAboutOverwrite,
51 void launch()
override
58 if (
auto locked = ref.lock())
59 locked->modalStateFinished (r);
65 void runModally()
override
67 #if JUCE_MODAL_LOOPS_PERMITTED
68 modalStateFinished (dialogBox.show() ? 1 : 0);
75 void modalStateFinished (
int returnValue)
85 owner.finished (result);
90 bool selectsDirectories, selectsFiles, warnAboutOverwrite;
110 useNativeDialogBox (
useNativeBox && isPlatformDialogAvailable()),
123 asyncCallback =
nullptr;
126#if JUCE_MODAL_LOOPS_PERMITTED
134bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComp)
142bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComp)
151bool FileChooser::browseForFileToSave (
const bool warnAboutOverwrite)
159bool FileChooser::browseForDirectory()
166bool FileChooser::showDialog (
const int flags, FilePreviewComponent*
const previewComp)
170 pimpl = createPimpl (flags, previewComp);
176 return (results.size() > 0);
187 jassert (asyncCallback ==
nullptr);
189 asyncCallback = std::move (callback);
191 pimpl = createPimpl (flags, previewComp);
203 if (pimpl !=
nullptr)
218 if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
220 if (useNativeDialogBox)
223 return showPlatformDialog (*
this, flags, previewComp);
226 return std::make_unique<NonNative> (*
this, flags, previewComp);
234 if (url.isLocalFile())
235 files.
add (url.getLocalFile());
257 return results.getFirst();
262 const auto callback =
std::exchange (asyncCallback,
nullptr);
@ backgroundColourId
The background colour for the window.
Holds a resizable array of primitive or copy-by-value objects.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
The base class for all JUCE user-interface objects.
void exitModalState(int returnValue=0)
Ends a component's modal state.
int getHeight() const noexcept
Returns the component's height in pixels.
void enterModalState(bool takeKeyboardFocus=true, ModalComponentManager::Callback *callback=nullptr, bool deleteWhenDismissed=false)
Puts the component into a modal state.
int getWidth() const noexcept
Returns the component's width in pixels.
A component for browsing and selecting a file or directory to open or save.
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...
@ canSelectMultipleItems
specifies that the user can select multiple items.
@ warnAboutOverwriting
specifies that the dialog should warn about overwriting existing files (if possible).
@ 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...
int getNumSelectedFiles() const noexcept
Returns the number of files that the user has got selected.
A file open/save dialog box.
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,...
Creates a dialog box to choose a file or directory to load or save.
const Array< URL > & getURLResults() const noexcept
Returns a list of all the files that were chosen during the last call to a browse method.
~FileChooser()
Destructor.
URL getURLResult() const
Returns the last document that was chosen by one of the browseFor methods.
Array< File > getResults() const noexcept
Returns a list of all the files that were chosen during the last call to a browse method.
void launchAsync(int flags, std::function< void(const FileChooser &)>, FilePreviewComponent *previewComponent=nullptr)
Use this method to launch the file browser window asynchronously.
static void registerCustomMimeTypeForFileExtension(const String &mimeType, const String &fileExtension)
Associate a particular file-extension to a mime-type.
File getResult() const
Returns the last file that was chosen by one of the browseFor methods.
FileChooser(const String &dialogBoxTitle, const File &initialFileOrDirectory=File(), const String &filePatternsAllowed=String(), bool useOSNativeDialogBox=true, bool treatFilePackagesAsDirectories=false, Component *parentComponent=nullptr)
Creates a FileChooser.
Base class for components that live inside a file chooser dialog box and show previews of the files t...
~FilePreviewComponent() override
Destructor.
FilePreviewComponent()
Creates a FilePreviewComponent.
Represents a local file or directory.
static ModalComponentManager::Callback * create(CallbackFn &&fn)
This is a utility function to create a ModalComponentManager::Callback that will call a callable obje...
Represents a URL and has a bunch of useful functions to manipulate it.
A type of FileFilter that works by wildcard pattern matching.
void ignoreUnused(Types &&...) noexcept
Handy function for avoiding unused variables warning.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
T shared_from_this(T... args)