Browse Source

Changed the return values of some virtual methods in FileBasedDocument - Strings and File objects are now non-const, and the load/save functions return a Result object rather than a string.

tags/2021-05-28
jules 13 years ago
parent
commit
53b1e351cf
10 changed files with 73 additions and 72 deletions
  1. +5
    -4
      extras/Introjucer/Source/Application/jucer_CommandLine.cpp
  2. +14
    -6
      extras/Introjucer/Source/Project Saving/jucer_ProjectSaver.h
  3. +9
    -9
      extras/Introjucer/Source/Project/jucer_Project.cpp
  4. +6
    -6
      extras/Introjucer/Source/Project/jucer_Project.h
  5. +8
    -8
      extras/audio plugin host/Source/FilterGraph.cpp
  6. +4
    -4
      extras/audio plugin host/Source/FilterGraph.h
  7. +10
    -10
      extras/the jucer/src/model/jucer_JucerDocument.cpp
  8. +4
    -4
      extras/the jucer/src/model/jucer_JucerDocument.h
  9. +7
    -11
      modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp
  10. +6
    -10
      modules/juce_gui_extra/documents/juce_FileBasedDocument.h

+ 5
- 4
extras/Introjucer/Source/Application/jucer_CommandLine.cpp View File

@@ -82,12 +82,12 @@ namespace
: "The Introjucer - Re-saving file: ")
<< projectFile.getFullPathName() << std::endl;
String error (justSaveResources ? proj.saveResourcesOnly (projectFile)
Result error (justSaveResources ? proj.saveResourcesOnly (projectFile)
: proj.saveProject (projectFile, true));
if (error.isNotEmpty())
if (error.failed())
{
std::cout << "Error when saving: " << error << std::endl;
std::cout << "Error when saving: " << error.getErrorMessage() << std::endl;
return 1;
}
@@ -222,8 +222,9 @@ namespace
const File projectFile (getFile (args[1]));
Project proj (projectFile);
const Result result (proj.loadDocument (projectFile));
if (proj.loadDocument (projectFile).isNotEmpty())
if (result.failed())
{
std::cout << "Failed to load project: " << projectFile.getFullPathName() << std::endl;
return 1;


+ 14
- 6
extras/Introjucer/Source/Project Saving/jucer_ProjectSaver.h View File

@@ -50,7 +50,8 @@ public:
{
public:
SaveThread (ProjectSaver& saver_)
: ThreadWithProgressWindow ("Saving...", true, false), saver (saver_)
: ThreadWithProgressWindow ("Saving...", true, false),
saver (saver_), result (Result::ok())
{}
void run()
@@ -60,12 +61,12 @@ public:
}
ProjectSaver& saver;
String result;
Result result;
JUCE_DECLARE_NON_COPYABLE (SaveThread);
};
String save (bool showProgressBox)
Result save (bool showProgressBox)
{
if (showProgressBox)
{
@@ -111,15 +112,22 @@ public:
writeReadmeFile();
if (errors.size() > 0)
{
project.setFile (oldFile);
return Result::fail (errors[0]);
}
return errors[0];
return Result::ok();
}
String saveResourcesOnly()
Result saveResourcesOnly()
{
writeBinaryDataFiles();
return errors[0];
if (errors.size() > 0)
return Result::fail (errors[0]);
return Result::ok();
}
Project::Item saveGeneratedFile (const String& filePath, const MemoryOutputStream& newData)


+ 9
- 9
extras/Introjucer/Source/Project/jucer_Project.cpp View File

@@ -77,7 +77,7 @@ void Project::setTitle (const String& newTitle)
getMainGroup().getNameValue() = newTitle;
}
const String Project::getDocumentTitle()
String Project::getDocumentTitle()
{
return getProjectName().toString();
}
@@ -209,17 +209,17 @@ static void registerRecentFile (const File& file)
StoredSettings::getInstance()->flush();
}
const String Project::loadDocument (const File& file)
Result Project::loadDocument (const File& file)
{
ScopedPointer <XmlElement> xml (XmlDocument::parse (file));
if (xml == nullptr || ! xml->hasTagName (Tags::projectRoot.toString()))
return "Not a valid Jucer project!";
return Result::fail ("Not a valid Jucer project!");
ValueTree newTree (ValueTree::fromXml (*xml));
if (! newTree.hasType (Tags::projectRoot))
return "The document contains errors and couldn't be parsed!";
return Result::fail ("The document contains errors and couldn't be parsed!");
registerRecentFile (file);
projectRoot = newTree;
@@ -227,15 +227,15 @@ const String Project::loadDocument (const File& file)
removeDefunctExporters();
setMissingDefaultValues();
return String::empty;
return Result::ok();
}
const String Project::saveDocument (const File& file)
Result Project::saveDocument (const File& file)
{
return saveProject (file, false);
}
String Project::saveProject (const File& file, bool isCommandLineApp)
Result Project::saveProject (const File& file, bool isCommandLineApp)
{
updateProjectSettings();
sanitiseConfigFlags();
@@ -247,7 +247,7 @@ String Project::saveProject (const File& file, bool isCommandLineApp)
return saver.save (! isCommandLineApp);
}
String Project::saveResourcesOnly (const File& file)
Result Project::saveResourcesOnly (const File& file)
{
ProjectSaver saver (*this, file);
return saver.saveResourcesOnly();
@@ -256,7 +256,7 @@ String Project::saveResourcesOnly (const File& file)
//==============================================================================
File Project::lastDocumentOpened;
const File Project::getLastDocumentOpened()
File Project::getLastDocumentOpened()
{
return lastDocumentOpened;
}


+ 6
- 6
extras/Introjucer/Source/Project/jucer_Project.h View File

@@ -43,12 +43,12 @@ public:
//==============================================================================
// FileBasedDocument stuff..
const String getDocumentTitle();
const String loadDocument (const File& file);
const String saveDocument (const File& file);
String saveProject (const File& file, bool isCommandLineApp);
String saveResourcesOnly (const File& file);
const File getLastDocumentOpened();
String getDocumentTitle();
Result loadDocument (const File& file);
Result saveDocument (const File& file);
Result saveProject (const File& file, bool isCommandLineApp);
Result saveResourcesOnly (const File& file);
File getLastDocumentOpened();
void setLastDocumentOpened (const File& file);
void setTitle (const String& newTitle);


+ 8
- 8
extras/audio plugin host/Source/FilterGraph.cpp View File

@@ -233,7 +233,7 @@ void FilterGraph::clear()
}
//==============================================================================
const String FilterGraph::getDocumentTitle()
String FilterGraph::getDocumentTitle()
{
if (! getFile().exists())
return "Unnamed";
@@ -241,29 +241,29 @@ const String FilterGraph::getDocumentTitle()
return getFile().getFileNameWithoutExtension();
}
const String FilterGraph::loadDocument (const File& file)
Result FilterGraph::loadDocument (const File& file)
{
XmlDocument doc (file);
ScopedPointer<XmlElement> xml (doc.getDocumentElement());
if (xml == nullptr || ! xml->hasTagName ("FILTERGRAPH"))
return "Not a valid filter graph file";
return Result::fail ("Not a valid filter graph file");
restoreFromXml (*xml);
return String::empty;
return Result::ok();
}
const String FilterGraph::saveDocument (const File& file)
Result FilterGraph::saveDocument (const File& file)
{
ScopedPointer<XmlElement> xml (createXml());
if (! xml->writeToFile (file, String::empty))
return "Couldn't write to the file";
return Result::fail ("Couldn't write to the file");
return String::empty;
return Result::ok();
}
const File FilterGraph::getLastDocumentOpened()
File FilterGraph::getLastDocumentOpened()
{
RecentlyOpenedFilesList recentFiles;
recentFiles.restoreFromString (appProperties->getUserSettings()


+ 4
- 4
extras/audio plugin host/Source/FilterGraph.h View File

@@ -114,10 +114,10 @@ public:
void restoreFromXml (const XmlElement& xml);
//==============================================================================
const String getDocumentTitle();
const String loadDocument (const File& file);
const String saveDocument (const File& file);
const File getLastDocumentOpened();
String getDocumentTitle();
Result loadDocument (const File& file);
Result saveDocument (const File& file);
File getLastDocumentOpened();
void setLastDocumentOpened (const File& file);
/** The special channel index used to refer to a filter's midi channel.


+ 10
- 10
extras/the jucer/src/model/jucer_JucerDocument.cpp View File

@@ -252,7 +252,7 @@ void JucerDocument::setComponentOverlayOpacity (const float alpha)
}
//==============================================================================
const String JucerDocument::getDocumentTitle()
String JucerDocument::getDocumentTitle()
{
return className;
}
@@ -406,7 +406,7 @@ bool JucerDocument::loadFromXml (const XmlElement& xml)
}
//==============================================================================
const String JucerDocument::loadDocument (const File& file)
Result JucerDocument::loadDocument (const File& file)
{
const File cppFile (file.withFileExtension (".cpp"));
@@ -419,15 +419,15 @@ const String JucerDocument::loadDocument (const File& file)
if (xml != nullptr)
{
if (loadFromXml (*xml))
return String::empty;
return Result::ok();
return TRANS("Couldn't parse the XML section of this file correctly");
return Result::fail (TRANS("Couldn't parse the XML section of this file correctly"));
}
return TRANS("Not a valid Jucer cpp file");
return Result::fail (TRANS("Not a valid Jucer cpp file"));
}
const String JucerDocument::saveDocument (const File& file)
Result JucerDocument::saveDocument (const File& file)
{
const File cppFile (file.withFileExtension (".cpp"));
const File hFile (file.withFileExtension (".h"));
@@ -435,19 +435,19 @@ const String JucerDocument::saveDocument (const File& file)
String templateH, templateCpp;
if (! findTemplateFiles (templateH, templateCpp))
return TRANS("Couldn't find the required Jucer template files...\n\nMake sure the template files directory is set up correctly in the preferences box.");
return Result::fail (TRANS("Couldn't find the required Jucer template files...\n\nMake sure the template files directory is set up correctly in the preferences box."));
const bool ok = writeCodeFiles (hFile, cppFile, templateH, templateCpp);
TestComponent::reloadAll();
if (ok)
return String::empty;
return Result::ok();
else
return TRANS("Couldn't write to the file.");
return Result::fail (TRANS("Couldn't write to the file."));
}
//==============================================================================
const File JucerDocument::getLastDocumentOpened()
File JucerDocument::getLastDocumentOpened()
{
return StoredSettings::getInstance()->recentFiles.getFile (0);
}


+ 4
- 4
extras/the jucer/src/model/jucer_JucerDocument.h View File

@@ -157,10 +157,10 @@ public:
protected:
const String getDocumentTitle();
const String loadDocument (const File& file);
const String saveDocument (const File& file);
const File getLastDocumentOpened();
String getDocumentTitle();
Result loadDocument (const File& file);
Result saveDocument (const File& file);
File getLastDocumentOpened();
void setLastDocumentOpened (const File& file);


+ 7
- 11
modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp View File

@@ -75,13 +75,13 @@ bool FileBasedDocument::loadFrom (const File& newFile,
const File oldFile (documentFile);
documentFile = newFile;
String error;
Result result (Result::fail ("The file doesn't exist"));
if (newFile.existsAsFile())
{
error = loadDocument (newFile);
result = loadDocument (newFile);
if (error.isEmpty())
if (result.wasOk())
{
setChangedFlag (false);
MouseCursor::hideWaitCursor();
@@ -90,10 +90,6 @@ bool FileBasedDocument::loadFrom (const File& newFile,
return true;
}
}
else
{
error = "The file doesn't exist";
}
documentFile = oldFile;
MouseCursor::hideWaitCursor();
@@ -105,7 +101,7 @@ bool FileBasedDocument::loadFrom (const File& newFile,
TRANS("There was an error while trying to load the file:\n\n")
+ newFile.getFullPathName()
+ "\n\n"
+ error);
+ result.getErrorMessage());
}
return false;
@@ -171,9 +167,9 @@ FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
const File oldFile (documentFile);
documentFile = newFile;
String error (saveDocument (newFile));
const Result result (saveDocument (newFile));
if (error.isEmpty())
if (result.wasOk())
{
setChangedFlag (false);
MouseCursor::hideWaitCursor();
@@ -193,7 +189,7 @@ FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
+ TRANS("\" to the file:\n\n")
+ newFile.getFullPathName()
+ "\n\n"
+ error);
+ result.getErrorMessage());
}
return failedToWriteToFile;


+ 6
- 10
modules/juce_gui_extra/documents/juce_FileBasedDocument.h View File

@@ -226,21 +226,17 @@ protected:
This is used in message boxes, filenames and file choosers, so it should be
something sensible.
*/
virtual const String getDocumentTitle() = 0;
virtual String getDocumentTitle() = 0;
/** This method should try to load your document from the given file.
If it fails, it should return an error message. If it succeeds, it should return
an empty string.
@returns a Result object to indicate the whether there was an error.
*/
virtual const String loadDocument (const File& file) = 0;
virtual Result loadDocument (const File& file) = 0;
/** This method should try to write your document to the given file.
If it fails, it should return an error message. If it succeeds, it should return
an empty string.
@returns a Result object to indicate the whether there was an error.
*/
virtual const String saveDocument (const File& file) = 0;
virtual Result saveDocument (const File& file) = 0;
/** This is used for dialog boxes to make them open at the last folder you
were using.
@@ -258,7 +254,7 @@ protected:
@see RecentlyOpenedFilesList
*/
virtual const File getLastDocumentOpened() = 0;
virtual File getLastDocumentOpened() = 0;
/** This is used for dialog boxes to make them open at the last folder you
were using.


Loading…
Cancel
Save