| @@ -88,50 +88,61 @@ public: | |||
| //============================================================================== | |||
| File getLastFile() const | |||
| { | |||
| File f; | |||
| if (settings != nullptr) | |||
| f = File (settings->getValue ("lastStateFile")); | |||
| if (f == File::nonexistent) | |||
| f = File::getSpecialLocation (File::userDocumentsDirectory); | |||
| return f; | |||
| } | |||
| void setLastFile (const FileChooser& fc) | |||
| { | |||
| if (settings != nullptr) | |||
| settings->setValue ("lastStateFile", fc.getResult().getFullPathName()); | |||
| } | |||
| /** Pops up a dialog letting the user save the processor's state to a file. */ | |||
| void askUserToSaveState (const String& fileSuffix = String()) | |||
| { | |||
| FileChooser fc (TRANS("Save current state"), | |||
| settings != nullptr ? File (settings->getValue ("lastStateFile")) | |||
| : File::getSpecialLocation (File::userDocumentsDirectory), | |||
| getFilePatterns (fileSuffix)); | |||
| FileChooser fc (TRANS("Save current state"), getLastFile(), getFilePatterns (fileSuffix)); | |||
| if (fc.browseForFileToSave (true)) | |||
| { | |||
| setLastFile (fc); | |||
| MemoryBlock data; | |||
| processor->getStateInformation (data); | |||
| if (! fc.getResult().replaceWithData (data.getData(), data.getSize())) | |||
| { | |||
| AlertWindow::showMessageBox (AlertWindow::WarningIcon, | |||
| TRANS("Error whilst saving"), | |||
| TRANS("Couldn't write to the specified file!")); | |||
| } | |||
| } | |||
| } | |||
| /** Pops up a dialog letting the user re-load the processor's state from a file. */ | |||
| void askUserToLoadState (const String& fileSuffix = String()) | |||
| { | |||
| FileChooser fc (TRANS("Load a saved state"), | |||
| settings != nullptr ? File (settings->getValue ("lastStateFile")) | |||
| : File::getSpecialLocation (File::userDocumentsDirectory), | |||
| getFilePatterns (fileSuffix)); | |||
| FileChooser fc (TRANS("Load a saved state"), getLastFile(), getFilePatterns (fileSuffix)); | |||
| if (fc.browseForFileToOpen()) | |||
| { | |||
| setLastFile (fc); | |||
| MemoryBlock data; | |||
| if (fc.getResult().loadFileAsData (data)) | |||
| { | |||
| processor->setStateInformation (data.getData(), (int) data.getSize()); | |||
| } | |||
| else | |||
| { | |||
| AlertWindow::showMessageBox (AlertWindow::WarningIcon, | |||
| TRANS("Error whilst loading"), | |||
| TRANS("Couldn't read from the specified file!")); | |||
| } | |||
| } | |||
| } | |||