From ba2c3d57f627328969d3507c55beb64909a50991 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Tue, 16 Apr 2013 21:17:44 -0400 Subject: [PATCH] Extend Settings to allow value restoration via message. --- .../debugger/settings/generic/Settings.cpp | 19 +++++++++++++++++++ src/apps/debugger/settings/generic/Settings.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/src/apps/debugger/settings/generic/Settings.cpp b/src/apps/debugger/settings/generic/Settings.cpp index 686b729d40..dfc176d3a7 100644 --- a/src/apps/debugger/settings/generic/Settings.cpp +++ b/src/apps/debugger/settings/generic/Settings.cpp @@ -1,4 +1,5 @@ /* + * Copyright 2013, Rene Gollent, rene@gollent.com. * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. * Distributed under the terms of the MIT License. */ @@ -81,6 +82,24 @@ Settings::SetValue(Setting* setting, const BVariant& value) } +bool +Settings::RestoreValues(const BMessage& message) +{ + AutoLocker locker(fLock); + + for (int32 i = 0; i < fDescription->CountSettings(); i++) { + Setting* setting = fDescription->SettingAt(i); + BVariant value; + if (value.SetFromMessage(message, setting->ID()) == B_OK) { + if (!SetValue(setting, value)) + return false; + } + } + + return true; +} + + SettingsOption* Settings::OptionValue(OptionsSetting* setting) const { diff --git a/src/apps/debugger/settings/generic/Settings.h b/src/apps/debugger/settings/generic/Settings.h index 5862fa3a02..b921702c1e 100644 --- a/src/apps/debugger/settings/generic/Settings.h +++ b/src/apps/debugger/settings/generic/Settings.h @@ -1,4 +1,5 @@ /* + * Copyright 2013, Rene Gollent, rene@gollent.com. * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. * Distributed under the terms of the MIT License. */ @@ -40,6 +41,8 @@ public: bool SetValue(Setting* setting, const BVariant& value); + bool RestoreValues(const BMessage& message); + bool BoolValue(BoolSetting* setting) const { return Value(setting).ToBool(); } SettingsOption* OptionValue(OptionsSetting* setting) const;