mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-07 04:10:08 +00:00
Made some FileBasedDocument methods return Result objects instead of bools, and made it less modal.
This commit is contained in:
parent
484bcf4e3c
commit
3fe70cd8f0
2 changed files with 27 additions and 31 deletions
|
|
@ -65,16 +65,14 @@ void FileBasedDocument::setFile (const File& newFile)
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
#if JUCE_MODAL_LOOPS_PERMITTED
|
||||
bool FileBasedDocument::loadFrom (const File& newFile,
|
||||
const bool showMessageOnFailure)
|
||||
Result FileBasedDocument::loadFrom (const File& newFile, const bool showMessageOnFailure)
|
||||
{
|
||||
MouseCursor::showWaitCursor();
|
||||
|
||||
const File oldFile (documentFile);
|
||||
documentFile = newFile;
|
||||
|
||||
Result result (Result::fail ("The file doesn't exist"));
|
||||
Result result (Result::fail (TRANS("The file doesn't exist")));
|
||||
|
||||
if (newFile.existsAsFile())
|
||||
{
|
||||
|
|
@ -86,7 +84,7 @@ bool FileBasedDocument::loadFrom (const File& newFile,
|
|||
MouseCursor::hideWaitCursor();
|
||||
|
||||
setLastDocumentOpened (newFile);
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -94,19 +92,18 @@ bool FileBasedDocument::loadFrom (const File& newFile,
|
|||
MouseCursor::hideWaitCursor();
|
||||
|
||||
if (showMessageOnFailure)
|
||||
{
|
||||
AlertWindow::showMessageBox (AlertWindow::WarningIcon,
|
||||
TRANS("Failed to open file..."),
|
||||
TRANS("There was an error while trying to load the file: FLNM")
|
||||
.replace ("FLNM", "\n" + newFile.getFullPathName())
|
||||
+ "\n\n"
|
||||
+ result.getErrorMessage());
|
||||
}
|
||||
AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
|
||||
TRANS("Failed to open file..."),
|
||||
TRANS("There was an error while trying to load the file: FLNM")
|
||||
.replace ("FLNM", "\n" + newFile.getFullPathName())
|
||||
+ "\n\n"
|
||||
+ result.getErrorMessage());
|
||||
|
||||
return false;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
|
||||
#if JUCE_MODAL_LOOPS_PERMITTED
|
||||
Result FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
|
||||
{
|
||||
FileChooser fc (openFileDialogTitle,
|
||||
getLastDocumentOpened(),
|
||||
|
|
@ -115,7 +112,7 @@ bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailu
|
|||
if (fc.browseForFileToOpen())
|
||||
return loadFrom (fc.getResult(), showMessageOnFailure);
|
||||
|
||||
return false;
|
||||
return Result::fail (TRANS("User cancelled"));
|
||||
}
|
||||
|
||||
static bool askToOverwriteFile (const File& newFile)
|
||||
|
|
@ -179,15 +176,13 @@ FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
|
|||
MouseCursor::hideWaitCursor();
|
||||
|
||||
if (showMessageOnFailure)
|
||||
{
|
||||
AlertWindow::showMessageBox (AlertWindow::WarningIcon,
|
||||
TRANS("Error writing to file..."),
|
||||
TRANS("An error occurred while trying to save \"DCNM\" to the file: FLNM")
|
||||
.replace ("DCNM", getDocumentTitle())
|
||||
.replace ("FLNM", "\n" + newFile.getFullPathName())
|
||||
+ "\n\n"
|
||||
+ result.getErrorMessage());
|
||||
}
|
||||
AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
|
||||
TRANS("Error writing to file..."),
|
||||
TRANS("An error occurred while trying to save \"DCNM\" to the file: FLNM")
|
||||
.replace ("DCNM", getDocumentTitle())
|
||||
.replace ("FLNM", "\n" + newFile.getFullPathName())
|
||||
+ "\n\n"
|
||||
+ result.getErrorMessage());
|
||||
|
||||
return failedToWriteToFile;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,11 +100,12 @@ public:
|
|||
to this new one; if it fails, the document's file is left unchanged, and optionally
|
||||
a message box is shown telling the user there was an error.
|
||||
|
||||
@returns true if the new file loaded successfully
|
||||
@returns A result indicating whether the new file loaded successfully, or the error
|
||||
message if it failed.
|
||||
@see loadDocument, loadFromUserSpecifiedFile
|
||||
*/
|
||||
bool loadFrom (const File& fileToLoadFrom,
|
||||
bool showMessageOnFailure);
|
||||
Result loadFrom (const File& fileToLoadFrom,
|
||||
bool showMessageOnFailure);
|
||||
|
||||
/** Asks the user for a file and tries to load it.
|
||||
|
||||
|
|
@ -113,11 +114,11 @@ public:
|
|||
for a file. If they pick one, the loadFrom() method is used to
|
||||
try to load it, optionally showing a message if it fails.
|
||||
|
||||
@returns true if a file was loaded; false if the user cancelled or if they
|
||||
picked a file which failed to load correctly
|
||||
@returns a result indicating success; This will be a failure message if the user
|
||||
cancelled or if they picked a file which failed to load correctly
|
||||
@see loadFrom
|
||||
*/
|
||||
bool loadFromUserSpecifiedFile (bool showMessageOnFailure);
|
||||
Result loadFromUserSpecifiedFile (bool showMessageOnFailure);
|
||||
|
||||
//==============================================================================
|
||||
/** A set of possible outcomes of one of the save() methods
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue