diff --git a/Source/Project64-core/Settings/SettingType/SettingsType-SelectedDirectory.cpp b/Source/Project64-core/Settings/SettingType/SettingsType-SelectedDirectory.cpp index d4521036b..488989107 100644 --- a/Source/Project64-core/Settings/SettingType/SettingsType-SelectedDirectory.cpp +++ b/Source/Project64-core/Settings/SettingType/SettingsType-SelectedDirectory.cpp @@ -11,75 +11,87 @@ #include "stdafx.h" #include "SettingsType-SelectedDirectory.h" -CSettingTypeSelectedDirectory::CSettingTypeSelectedDirectory(const char * Name, SettingID InitialDir, SettingID SelectedDir, SettingID UseSelected ) : - m_Name(Name), - m_InitialDir(InitialDir), - m_SelectedDir(SelectedDir), - m_UseSelected(UseSelected) +CSettingTypeSelectedDirectory::CSettingTypeSelectedDirectory(const char * Name, SettingID InitialDir, SettingID SelectedDir, SettingID UseSelected, SettingID NotifyChangeId) : +m_Name(Name), +m_InitialDir(InitialDir), +m_SelectedDir(SelectedDir), +m_UseSelected(UseSelected), +m_NotifyChangeId(NotifyChangeId) { + g_Settings->RegisterChangeCB(m_InitialDir, this, (CSettings::SettingChangedFunc)DirectoryChanged); + g_Settings->RegisterChangeCB(m_SelectedDir, this, (CSettings::SettingChangedFunc)DirectoryChanged); + g_Settings->RegisterChangeCB(m_UseSelected, this, (CSettings::SettingChangedFunc)DirectoryChanged); } CSettingTypeSelectedDirectory::~CSettingTypeSelectedDirectory() { + g_Settings->UnregisterChangeCB(m_InitialDir, this, (CSettings::SettingChangedFunc)DirectoryChanged); + g_Settings->UnregisterChangeCB(m_SelectedDir, this, (CSettings::SettingChangedFunc)DirectoryChanged); + g_Settings->UnregisterChangeCB(m_UseSelected, this, (CSettings::SettingChangedFunc)DirectoryChanged); } -bool CSettingTypeSelectedDirectory::Load ( int /*Index*/, bool & /*Value*/ ) const +bool CSettingTypeSelectedDirectory::Load(int /*Index*/, bool & /*Value*/) const { - g_Notify->BreakPoint(__FILE__,__LINE__); + g_Notify->BreakPoint(__FILE__, __LINE__); return false; } -bool CSettingTypeSelectedDirectory::Load ( int /*Index*/, uint32_t & /*Value*/ ) const +bool CSettingTypeSelectedDirectory::Load(int /*Index*/, uint32_t & /*Value*/) const { - g_Notify->BreakPoint(__FILE__,__LINE__); + g_Notify->BreakPoint(__FILE__, __LINE__); return false; } -bool CSettingTypeSelectedDirectory::Load ( int /*Index*/, stdstr & Value ) const +bool CSettingTypeSelectedDirectory::Load(int /*Index*/, stdstr & Value) const { SettingID DirSettingId = g_Settings->LoadBool(m_UseSelected) ? m_SelectedDir : m_InitialDir; return g_Settings->LoadStringVal(DirSettingId, Value); } //return the default values -void CSettingTypeSelectedDirectory::LoadDefault ( int /*Index*/, bool & /*Value*/ ) const +void CSettingTypeSelectedDirectory::LoadDefault(int /*Index*/, bool & /*Value*/) const { - g_Notify->BreakPoint(__FILE__,__LINE__); + g_Notify->BreakPoint(__FILE__, __LINE__); } -void CSettingTypeSelectedDirectory::LoadDefault ( int /*Index*/, uint32_t & /*Value*/ ) const +void CSettingTypeSelectedDirectory::LoadDefault(int /*Index*/, uint32_t & /*Value*/) const { - g_Notify->BreakPoint(__FILE__,__LINE__); + g_Notify->BreakPoint(__FILE__, __LINE__); } -void CSettingTypeSelectedDirectory::LoadDefault ( int /*Index*/, stdstr & /*Value*/ ) const +void CSettingTypeSelectedDirectory::LoadDefault(int /*Index*/, stdstr & /*Value*/) const { - g_Notify->BreakPoint(__FILE__,__LINE__); + g_Notify->BreakPoint(__FILE__, __LINE__); } //Update the settings -void CSettingTypeSelectedDirectory::Save ( int /*Index*/, bool /*Value*/ ) +void CSettingTypeSelectedDirectory::Save(int /*Index*/, bool /*Value*/) { - g_Notify->BreakPoint(__FILE__,__LINE__); + g_Notify->BreakPoint(__FILE__, __LINE__); } -void CSettingTypeSelectedDirectory::Save ( int /*Index*/, uint32_t /*Value*/ ) +void CSettingTypeSelectedDirectory::Save(int /*Index*/, uint32_t /*Value*/) { - g_Notify->BreakPoint(__FILE__,__LINE__); + g_Notify->BreakPoint(__FILE__, __LINE__); } -void CSettingTypeSelectedDirectory::Save ( int /*Index*/, const stdstr & /*Value*/ ) +void CSettingTypeSelectedDirectory::Save(int /*Index*/, const stdstr & /*Value*/) { - g_Notify->BreakPoint(__FILE__,__LINE__); + g_Notify->BreakPoint(__FILE__, __LINE__); } -void CSettingTypeSelectedDirectory::Save ( int /*Index*/, const char * Value ) +void CSettingTypeSelectedDirectory::Save(int /*Index*/, const char * Value) { - g_Settings->SaveBool(m_UseSelected,true); - g_Settings->SaveString(m_SelectedDir,Value); + g_Settings->SaveBool(m_UseSelected, true); + g_Settings->SaveString(m_SelectedDir, Value); } -void CSettingTypeSelectedDirectory::Delete( int /*Index*/ ) +void CSettingTypeSelectedDirectory::Delete(int /*Index*/) { - g_Notify->BreakPoint(__FILE__,__LINE__); + g_Notify->BreakPoint(__FILE__, __LINE__); +} + +void CSettingTypeSelectedDirectory::DirectoryChanged(CSettingTypeSelectedDirectory * _this) +{ + g_Settings->NotifyCallBacks(_this->m_NotifyChangeId); } diff --git a/Source/Project64-core/Settings/SettingType/SettingsType-SelectedDirectory.h b/Source/Project64-core/Settings/SettingType/SettingsType-SelectedDirectory.h index 980fbe7b4..5cfb0a220 100644 --- a/Source/Project64-core/Settings/SettingType/SettingsType-SelectedDirectory.h +++ b/Source/Project64-core/Settings/SettingType/SettingsType-SelectedDirectory.h @@ -16,40 +16,43 @@ class CSettingTypeSelectedDirectory : public CSettingType { public: - CSettingTypeSelectedDirectory(const char * Name, SettingID InitialDir, SettingID SelectedDir, SettingID UseSelected ); + CSettingTypeSelectedDirectory(const char * Name, SettingID InitialDir, SettingID SelectedDir, SettingID UseSelected, SettingID NotifyChangeId); ~CSettingTypeSelectedDirectory(); - virtual bool IndexBasedSetting ( void ) const { return false; } - virtual SettingType GetSettingType ( void ) const { return SettingType_SelectedDirectory; } + virtual bool IndexBasedSetting(void) const { return false; } + virtual SettingType GetSettingType(void) const { return SettingType_SelectedDirectory; } - const char * GetName ( void ) const { return m_Name.c_str(); } + const char * GetName(void) const { return m_Name.c_str(); } //return the values - virtual bool Load ( int32_t Index, bool & Value ) const; - virtual bool Load ( int32_t Index, uint32_t & Value ) const; - virtual bool Load ( int32_t Index, stdstr & Value ) const; + virtual bool Load(int32_t Index, bool & Value) const; + virtual bool Load(int32_t Index, uint32_t & Value) const; + virtual bool Load(int32_t Index, stdstr & Value) const; //return the default values - virtual void LoadDefault ( int32_t Index, bool & Value ) const; - virtual void LoadDefault ( int32_t Index, uint32_t & Value ) const; - virtual void LoadDefault ( int32_t Index, stdstr & Value ) const; + virtual void LoadDefault(int32_t Index, bool & Value) const; + virtual void LoadDefault(int32_t Index, uint32_t & Value) const; + virtual void LoadDefault(int32_t Index, stdstr & Value) const; //Update the settings - virtual void Save ( int32_t Index, bool Value ); - virtual void Save ( int32_t Index, uint32_t Value ); - virtual void Save ( int32_t Index, const stdstr & Value ); - virtual void Save ( int32_t Index, const char * Value ); + virtual void Save(int32_t Index, bool Value); + virtual void Save(int32_t Index, uint32_t Value); + virtual void Save(int32_t Index, const stdstr & Value); + virtual void Save(int32_t Index, const char * Value); // Delete the setting - virtual void Delete ( int32_t Index ); + virtual void Delete(int32_t Index); private: CSettingTypeSelectedDirectory(void); // Disable default constructor CSettingTypeSelectedDirectory(const CSettingTypeSelectedDirectory&); // Disable copy constructor CSettingTypeSelectedDirectory& operator=(const CSettingTypeSelectedDirectory&); // Disable assignment + static void DirectoryChanged(CSettingTypeSelectedDirectory * _this); + std::string m_Name; SettingID m_InitialDir; SettingID m_SelectedDir; SettingID m_UseSelected; + SettingID m_NotifyChangeId; }; diff --git a/Source/Project64-core/Settings/SettingsClass.h b/Source/Project64-core/Settings/SettingsClass.h index 725a130da..b614217d2 100644 --- a/Source/Project64-core/Settings/SettingsClass.h +++ b/Source/Project64-core/Settings/SettingsClass.h @@ -101,6 +101,9 @@ public: static uint32_t FindSetting(CSettings * _this, const char * Name); static void FlushSettings(CSettings * _this); + //Notification + void NotifyCallBacks(SettingID Type); + private: void AddHandler(SettingID TypeID, CSettingType * Handler); void AddHowToHandleSetting(const char * BaseDirectory); @@ -117,9 +120,6 @@ private: typedef std::map SETTING_MAP; typedef SETTING_MAP::iterator SETTING_HANDLER; -private: - void NotifyCallBacks(SettingID Type); - SETTING_MAP m_SettingInfo; SETTING_CALLBACK m_Callback; int32_t m_NextAutoSettingId;