diff --git a/aegisub/libaegisub/include/libaegisub/option_value.h b/aegisub/libaegisub/include/libaegisub/option_value.h index 3b38b2dcc..e767a0932 100644 --- a/aegisub/libaegisub/include/libaegisub/option_value.h +++ b/aegisub/libaegisub/include/libaegisub/option_value.h @@ -113,6 +113,7 @@ public: virtual std::vector const& GetDefaultListColour() const { throw ListTypeError("colour"); } virtual std::vector const& GetDefaultListBool() const { throw ListTypeError("string"); } + virtual void Set(const OptionValue *new_value)=0; DEFINE_SIGNAL_ADDERS(ValueChanged, Subscribe) }; @@ -132,6 +133,7 @@ public: std::string GetName() const { return name; } \ void Reset() { value = value_default; NotifyChanged(); } \ bool IsDefault() const { return value == value_default; } \ + void Set(const OptionValue *new_val) { Set##type_name(new_val->Get##type_name()); } \ }; CONFIG_OPTIONVALUE(String, std::string) @@ -147,7 +149,8 @@ CONFIG_OPTIONVALUE(Bool, bool) std::string name; \ public: \ virtual std::string GetString() const { return "";} \ - OptionValueList##type_name(std::string member_name): name(member_name) {} \ + OptionValueList##type_name(std::string const& name, std::vector const& value = std::vector()) \ + : array(value), array_default(value), name(name) { } \ std::vector const& GetList##type_name() const { return array; } \ void SetList##type_name(const std::vector& val) { array = val; NotifyChanged(); } \ std::vector const& GetDefaultList##type_name() const { return array_default; } \ @@ -155,6 +158,7 @@ CONFIG_OPTIONVALUE(Bool, bool) std::string GetName() const { return name; } \ void Reset() { array = array_default; NotifyChanged(); } \ bool IsDefault() const { return array == array_default; } \ + void Set(const OptionValue *nv) { SetList##type_name(nv->GetList##type_name()); } \ }; diff --git a/aegisub/src/preferences.cpp b/aegisub/src/preferences.cpp index 0ee755e87..2fd1e86ba 100644 --- a/aegisub/src/preferences.cpp +++ b/aegisub/src/preferences.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -626,26 +627,7 @@ void Preferences::OnOK(wxCommandEvent &event) { void Preferences::OnApply(wxCommandEvent &) { for (std::map::iterator cur = pending_changes.begin(); cur != pending_changes.end(); ++cur) { - agi::OptionValue *opt = OPT_SET(cur->first); - switch (opt->GetType()) { - case agi::OptionValue::Type_Bool: - opt->SetBool(cur->second->GetBool()); - break; - case agi::OptionValue::Type_Colour: - opt->SetColour(cur->second->GetColour()); - break; - case agi::OptionValue::Type_Double: - opt->SetDouble(cur->second->GetDouble()); - break; - case agi::OptionValue::Type_Int: - opt->SetInt(cur->second->GetInt()); - break; - case agi::OptionValue::Type_String: - opt->SetString(cur->second->GetString()); - break; - default: - throw PreferenceNotSupported("Unsupported type"); - } + OPT_SET(cur->first)->Set(cur->second); delete cur->second; } pending_changes.clear();