diff --git a/modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp b/modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp index 1273d1d758..1e9d8697d5 100644 --- a/modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp +++ b/modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp @@ -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; } diff --git a/modules/juce_gui_extra/documents/juce_FileBasedDocument.h b/modules/juce_gui_extra/documents/juce_FileBasedDocument.h index 9d77d6845b..66e1dda855 100644 --- a/modules/juce_gui_extra/documents/juce_FileBasedDocument.h +++ b/modules/juce_gui_extra/documents/juce_FileBasedDocument.h @@ -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