mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-30 02:50:05 +00:00
FileChoosers: Added a file-chooser save mode where the caller already supplies a temporary file which should be saved. JUCE will automatically move the temporary file to the location selected by the user
This commit is contained in:
parent
fd6b7de444
commit
df8fc9b910
8 changed files with 86 additions and 37 deletions
|
|
@ -73,7 +73,7 @@ private:
|
|||
result.add (URL (browserComponent.getSelectedFile (i)));
|
||||
}
|
||||
|
||||
owner.finished (result);
|
||||
owner.finished (result, true);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -137,12 +137,13 @@ bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* pre
|
|||
previewComp);
|
||||
}
|
||||
|
||||
bool FileChooser::browseForFileToSave (const bool warnAboutOverwrite)
|
||||
bool FileChooser::browseForFileToSave (const bool warnAboutOverwrite,
|
||||
const File& fileWhichShouldBeSaved)
|
||||
{
|
||||
return showDialog (FileBrowserComponent::saveMode
|
||||
| FileBrowserComponent::canSelectFiles
|
||||
| (warnAboutOverwrite ? FileBrowserComponent::warnAboutOverwriting : 0),
|
||||
nullptr);
|
||||
nullptr, fileWhichShouldBeSaved);
|
||||
}
|
||||
|
||||
bool FileChooser::browseForDirectory()
|
||||
|
|
@ -152,8 +153,11 @@ bool FileChooser::browseForDirectory()
|
|||
nullptr);
|
||||
}
|
||||
|
||||
bool FileChooser::showDialog (const int flags, FilePreviewComponent* const previewComp)
|
||||
bool FileChooser::showDialog (const int flags, FilePreviewComponent* const previewComp,
|
||||
const File& fileWhichShouldBeSaved)
|
||||
{
|
||||
fileToSave = (flags & FileBrowserComponent::saveMode) != 0 ? fileWhichShouldBeSaved : File();
|
||||
|
||||
FocusRestorer focusRestorer;
|
||||
|
||||
pimpl = createPimpl (flags, previewComp);
|
||||
|
|
@ -167,7 +171,8 @@ bool FileChooser::showDialog (const int flags, FilePreviewComponent* const previ
|
|||
#endif
|
||||
|
||||
void FileChooser::launchAsync (int flags, std::function<void (const FileChooser&)> callback,
|
||||
FilePreviewComponent* previewComp)
|
||||
FilePreviewComponent* previewComp,
|
||||
const File& fileWhichShouldBeSaved)
|
||||
{
|
||||
// You must specify a callback when using launchAsync
|
||||
jassert (callback);
|
||||
|
|
@ -175,6 +180,8 @@ void FileChooser::launchAsync (int flags, std::function<void (const FileChooser&
|
|||
// you cannot run two file chooser dialog boxes at the same time
|
||||
jassert (asyncCallback == nullptr);
|
||||
|
||||
fileToSave = (flags & FileBrowserComponent::saveMode) != 0 ? fileWhichShouldBeSaved : File();
|
||||
|
||||
asyncCallback = static_cast<std::function<void (const FileChooser&)>&&> (callback);
|
||||
|
||||
pimpl = createPimpl (flags, previewComp);
|
||||
|
|
@ -249,13 +256,23 @@ URL FileChooser::getURLResult() const
|
|||
return results.getFirst();
|
||||
}
|
||||
|
||||
void FileChooser::finished (const Array<URL>& asyncResults)
|
||||
void FileChooser::finished (const Array<URL>& asyncResults, bool shouldMove)
|
||||
{
|
||||
std::function<void (const FileChooser&)> callback;
|
||||
std::swap (callback, asyncCallback);
|
||||
|
||||
results = asyncResults;
|
||||
|
||||
if (shouldMove && fileToSave.existsAsFile() && results.size() > 0)
|
||||
{
|
||||
// The user either selected multiple files or wants to save the file to a URL
|
||||
// Both are not supported
|
||||
jassert (results.size() == 1 && results.getReference (0).isLocalFile());
|
||||
|
||||
if (! fileToSave.moveFileTo (results.getReference (0).getLocalFile()))
|
||||
results.clear();
|
||||
}
|
||||
|
||||
pimpl = nullptr;
|
||||
|
||||
if (callback)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue