diff --git a/src/Main.cpp b/src/Main.cpp index b7e66868..09685ab2 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -297,6 +297,10 @@ class GuiAppApplication : public JUCEApplication, public FocusChangeListener void saveWindowPosition() { + // Check if we should save + if (! Settings::getSaveOnExit()) + return; + // Don't save minimized position if (! isMinimised()) { diff --git a/src/utils/Settings.h b/src/utils/Settings.h index ea6069fb..dadf857b 100644 --- a/src/utils/Settings.h +++ b/src/utils/Settings.h @@ -169,6 +169,10 @@ class Settings } } + static void setSaveOnExit(bool shouldSave) { getInstance()->saveOnExit = shouldSave; } + + static bool getSaveOnExit() { return getInstance()->saveOnExit; } + private: Settings() : appProperties(nullptr) {} @@ -180,4 +184,5 @@ class Settings } ApplicationProperties* appProperties; + bool saveOnExit = true; }; diff --git a/src/windows/settings/GeneralSettingsTab.cpp b/src/windows/settings/GeneralSettingsTab.cpp index ff7c2c05..3671860b 100644 --- a/src/windows/settings/GeneralSettingsTab.cpp +++ b/src/windows/settings/GeneralSettingsTab.cpp @@ -11,6 +11,11 @@ GeneralSettingsTab::GeneralSettingsTab() openSettingsButton.setButtonText("Open Settings File"); openSettingsButton.onClick = [this] { handleOpenSettings(); }; addAndMakeVisible(openSettingsButton); + + // Set up button to restore default settings + restoreDefaultSettingsButton.setButtonText("Restore Default Settings"); + restoreDefaultSettingsButton.onClick = [this] { handleRestoreDefaultSettings(); }; + addAndMakeVisible(restoreDefaultSettingsButton); } void GeneralSettingsTab::resized() @@ -22,6 +27,10 @@ void GeneralSettingsTab::resized() area.removeFromTop(10); // Filler space openSettingsButton.setBounds(area.removeFromTop(30)); + + area.removeFromTop(10); // Filler space + + restoreDefaultSettingsButton.setBounds(area.removeFromTop(30)); } void GeneralSettingsTab::handleOpenLogFolder() @@ -40,3 +49,38 @@ void GeneralSettingsTab::handleOpenSettings() // TODO - handler error case } } + +void GeneralSettingsTab::handleRestoreDefaultSettings() +{ + NativeMessageBox::showYesNoBox( + AlertWindow::QuestionIcon, + "Restore Default Settings", + "Are you sure you want to restore default settings? This will delete your current settings " + "file and reset all preferences to their defaults.", + this, + ModalCallbackFunction::create( + [this](int result) + { + if (result == 1) // Yes + { + if (auto* settings = Settings::getUserSettings()) + { + // Delete the settings file + settings->getFile().deleteFile(); + + // Clear in-memory settings + settings->clear(); + + // Prevent saving on exit + Settings::setSaveOnExit(false); + + NativeMessageBox::showMessageBoxAsync( + AlertWindow::InfoIcon, + "Settings Restored", + "Settings have been restored to defaults. It is recommended to restart " + "the application for all changes to take full effect.", + this); + } + } + })); +} diff --git a/src/windows/settings/GeneralSettingsTab.h b/src/windows/settings/GeneralSettingsTab.h index 2462303b..349d7e6b 100644 --- a/src/windows/settings/GeneralSettingsTab.h +++ b/src/windows/settings/GeneralSettingsTab.h @@ -24,9 +24,11 @@ class GeneralSettingsTab : public Component private: void handleOpenLogFolder(); void handleOpenSettings(); + void handleRestoreDefaultSettings(); TextButton openLogFolderButton; TextButton openSettingsButton; + TextButton restoreDefaultSettingsButton; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(GeneralSettingsTab) };