From e233124fc35381d15247ff9eebc5ef6324fe8b83 Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 30 Jul 2014 11:35:43 +0100 Subject: [PATCH] Fix for StandAloneFilterWindow path saving. --- .../Standalone/juce_StandaloneFilterWindow.h | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h b/modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h index e69f383977..bdf72694b1 100644 --- a/modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h +++ b/modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h @@ -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!")); - } } }