From 998d83c15c1fe753526a43fb4c182a4b25e83252 Mon Sep 17 00:00:00 2001 From: thisismy-github <48284263+thisismy-github@users.noreply.github.com> Date: Thu, 12 Aug 2021 09:14:19 -0400 Subject: [PATCH] Auto-detect when setting is back to default value Intercepts *most* instances of FLAG_DEFAULT getting set, including when XML files are loaded and when Open-Shell starts, adding if-statements to those spots to check if a new value is actually different from the setting's default value. Ensures more consistency behind the scenes and gets rid of inaccurate bold highlights. --- Src/Lib/Settings.cpp | 20 +++++-- Src/Lib/SettingsUIHelper.cpp | 35 +++++++++--- Src/StartMenu/StartMenuDLL/SettingsUI.cpp | 65 ++++++++++++++++++----- 3 files changed, 96 insertions(+), 24 deletions(-) diff --git a/Src/Lib/Settings.cpp b/Src/Lib/Settings.cpp index df9646f4e..7b0d456a1 100644 --- a/Src/Lib/Settings.cpp +++ b/Src/Lib/Settings.cpp @@ -793,7 +793,10 @@ CString CSettingsManager::LoadSettingsXml( const wchar_t *fname ) } string.push_back(0); pSetting->value=CComVariant(&string[0]); - pSetting->flags&=~CSetting::FLAG_DEFAULT; + if (pSetting->value==pSetting->defValue) + pSetting->flags|=CSetting::FLAG_DEFAULT; + else + pSetting->flags&=~CSetting::FLAG_DEFAULT; } else { @@ -806,7 +809,10 @@ CString CSettingsManager::LoadSettingsXml( const wchar_t *fname ) if (pSetting->type>=CSetting::TYPE_STRING) { pSetting->value=value; - pSetting->flags&=~CSetting::FLAG_DEFAULT; + if (pSetting->value==pSetting->defValue) + pSetting->flags|=CSetting::FLAG_DEFAULT; + else + pSetting->flags&=~CSetting::FLAG_DEFAULT; } else if (pSetting->type==CSetting::TYPE_BOOL || (pSetting->type==CSetting::TYPE_INT && pSetting[1].type!=CSetting::TYPE_RADIO) || pSetting->type==CSetting::TYPE_HOTKEY || pSetting->type==CSetting::TYPE_HOTKEY_ANY || pSetting->type==CSetting::TYPE_COLOR) { @@ -815,7 +821,10 @@ CString CSettingsManager::LoadSettingsXml( const wchar_t *fname ) pSetting->value=CComVariant(val?1:0); else pSetting->value=CComVariant(val); - pSetting->flags&=~CSetting::FLAG_DEFAULT; + if (pSetting->value==pSetting->defValue) + pSetting->flags|=CSetting::FLAG_DEFAULT; + else + pSetting->flags&=~CSetting::FLAG_DEFAULT; } else if (pSetting->type==CSetting::TYPE_INT && pSetting[1].type==CSetting::TYPE_RADIO) { @@ -825,7 +834,10 @@ CString CSettingsManager::LoadSettingsXml( const wchar_t *fname ) if (_wcsicmp(pRadio->name,value.bstrVal)==0) { pSetting->value=CComVariant(val); - pSetting->flags&=~CSetting::FLAG_DEFAULT; + if (pSetting->value==pSetting->defValue) + pSetting->flags|=CSetting::FLAG_DEFAULT; + else + pSetting->flags&=~CSetting::FLAG_DEFAULT; break; } } diff --git a/Src/Lib/SettingsUIHelper.cpp b/Src/Lib/SettingsUIHelper.cpp index 05e2c03ad..e201720a2 100644 --- a/Src/Lib/SettingsUIHelper.cpp +++ b/Src/Lib/SettingsUIHelper.cpp @@ -1822,7 +1822,10 @@ void CCustomTreeDlg::SerializeData( void ) if ((m_pSetting->flags&CSetting::FLAG_DEFAULT) || wcscmp(strNew,strOld)!=0) SetSettingsDirty(); m_pSetting->value=CComVariant(strNew); - m_pSetting->flags&=~CSetting::FLAG_DEFAULT; + if (m_pSetting->value==m_pSetting->defValue) + m_pSetting->flags|=CSetting::FLAG_DEFAULT; + else + m_pSetting->flags&=~CSetting::FLAG_DEFAULT; ItemsChanged(); } @@ -2778,7 +2781,10 @@ void CTreeSettingsDlg::ToggleItem( HTREEITEM hItem, bool bDefault ) { CSettingsLockWrite lock; pSetting->value=CComVariant(state?0:1); - pSetting->flags&=~CSetting::FLAG_DEFAULT; + if (pSetting->value==pSetting->defValue) + pSetting->flags|=CSetting::FLAG_DEFAULT; + else + pSetting->flags&=~CSetting::FLAG_DEFAULT; SetSettingsDirty(); } if (pSetting->flags&CSetting::FLAG_CALLBACK) @@ -2802,7 +2808,10 @@ void CTreeSettingsDlg::ToggleItem( HTREEITEM hItem, bool bDefault ) { CSettingsLockWrite lock; pTarget->value=CComVariant(val); - pTarget->flags&=~CSetting::FLAG_DEFAULT; + if (pTarget->value==pTarget->defValue) + pTarget->flags|=CSetting::FLAG_DEFAULT; + else + pTarget->flags&=~CSetting::FLAG_DEFAULT; SetSettingsDirty(); } if (pParent->flags&CSetting::FLAG_CALLBACK) @@ -3013,7 +3022,10 @@ void CTreeSettingsDlg::ApplyEditBox( void ) if (pSetting->value.vt!=VT_I4 || pSetting->value.intVal!=val) { pSetting->value=CComVariant(val); - pSetting->flags&=~CSetting::FLAG_DEFAULT; + if (pSetting->value==pSetting->defValue) + pSetting->flags|=CSetting::FLAG_DEFAULT; + else + pSetting->flags&=~CSetting::FLAG_DEFAULT; } } else if (pSetting->type==CSetting::TYPE_COLOR) @@ -3023,7 +3035,10 @@ void CTreeSettingsDlg::ApplyEditBox( void ) if (pSetting->value.vt!=VT_I4 || pSetting->value.intVal!=val) { pSetting->value=CComVariant(val); - pSetting->flags&=~CSetting::FLAG_DEFAULT; + if (pSetting->value==pSetting->defValue) + pSetting->flags|=CSetting::FLAG_DEFAULT; + else + pSetting->flags&=~CSetting::FLAG_DEFAULT; } } else if (pSetting->type==CSetting::TYPE_HOTKEY || pSetting->type==CSetting::TYPE_HOTKEY_ANY) @@ -3031,7 +3046,10 @@ void CTreeSettingsDlg::ApplyEditBox( void ) if (pSetting->value.vt!=VT_I4 || pSetting->value.intVal!=g_HotKey) { pSetting->value=CComVariant(g_HotKey); - pSetting->flags&=~CSetting::FLAG_DEFAULT; + if (pSetting->value==pSetting->defValue) + pSetting->flags|=CSetting::FLAG_DEFAULT; + else + pSetting->flags&=~CSetting::FLAG_DEFAULT; } } else @@ -3039,7 +3057,10 @@ void CTreeSettingsDlg::ApplyEditBox( void ) if (pSetting->value.vt!=VT_BSTR || str!=pSetting->value.bstrVal) { pSetting->value=CComVariant(str); - pSetting->flags&=~CSetting::FLAG_DEFAULT; + if (pSetting->value==pSetting->defValue) + pSetting->flags|=CSetting::FLAG_DEFAULT; + else + pSetting->flags&=~CSetting::FLAG_DEFAULT; } } SetSettingsDirty(); diff --git a/Src/StartMenu/StartMenuDLL/SettingsUI.cpp b/Src/StartMenu/StartMenuDLL/SettingsUI.cpp index 8a7b7b240..aa0ee5d83 100644 --- a/Src/StartMenu/StartMenuDLL/SettingsUI.cpp +++ b/Src/StartMenu/StartMenuDLL/SettingsUI.cpp @@ -3616,7 +3616,10 @@ void CCustomMenuDlg7::SerializeData( void ) stringBuilder.push_back(0); CSettingsLockWrite lock; m_pSetting->value=CComVariant(&stringBuilder[0]); - m_pSetting->flags&=~CSetting::FLAG_DEFAULT; + if (m_pSetting->value==m_pSetting->defValue) + m_pSetting->flags|=CSetting::FLAG_DEFAULT; + else + m_pSetting->flags&=~CSetting::FLAG_DEFAULT; SetSettingsDirty(); } @@ -3843,7 +3846,10 @@ LRESULT CMenuStyleDlg::OnClick( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& CheckDlgButton(IDC_RADIO_CLASSIC,pSetting->value.intVal==MENU_CLASSIC1?BST_CHECKED:BST_UNCHECKED); CheckDlgButton(IDC_RADIO_TWO_COLUMNS,pSetting->value.intVal==MENU_CLASSIC2?BST_CHECKED:BST_UNCHECKED); CheckDlgButton(IDC_RADIO_WIN7,pSetting->value.intVal==MENU_WIN7?BST_CHECKED:BST_UNCHECKED); - pSetting->flags&=~CSetting::FLAG_DEFAULT; + if (pSetting->value==pSetting->defValue) + pSetting->flags|=CSetting::FLAG_DEFAULT; + else + pSetting->flags&=~CSetting::FLAG_DEFAULT; SetSettingsDirty(); SetSettingsStyle(styleFlag,CSetting::FLAG_MENU_MASK); @@ -3861,7 +3867,10 @@ LRESULT CMenuStyleDlg::OnEnabled( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL CSettingsLockWrite lock; CSetting *pSetting=FindSetting(L"EnableStartButton"); pSetting->value=CComVariant(bEnabled); - pSetting->flags&=~CSetting::FLAG_DEFAULT; + if (pSetting->value==pSetting->defValue) + pSetting->flags|=CSetting::FLAG_DEFAULT; + else + pSetting->flags&=~CSetting::FLAG_DEFAULT; SetSettingsDirty(); } Update(false); @@ -3900,7 +3909,10 @@ LRESULT CMenuStyleDlg::OnButtonStyle( WORD wNotifyCode, WORD wID, HWND hWndCtl, CSettingsLockWrite lock; CSetting *pSetting=FindSetting(L"StartButtonType"); pSetting->value=CComVariant(style); - pSetting->flags&=~CSetting::FLAG_DEFAULT; + if (pSetting->value==pSetting->defValue) + pSetting->flags|=CSetting::FLAG_DEFAULT; + else + pSetting->flags&=~CSetting::FLAG_DEFAULT; SetSettingsDirty(); } Update(false); @@ -3924,7 +3936,10 @@ LRESULT CMenuStyleDlg::OnPick( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& b CSettingsLockWrite lock; CSetting *pSetting=FindSetting(L"StartButtonPath"); pSetting->value=CComVariant(path); - pSetting->flags&=~CSetting::FLAG_DEFAULT; + if (pSetting->value==pSetting->defValue) + pSetting->flags|=CSetting::FLAG_DEFAULT; + else + pSetting->flags&=~CSetting::FLAG_DEFAULT; SetSettingsDirty(); } Update(true); @@ -4545,7 +4560,10 @@ void UpgradeSettings( bool bShared ) items.Replace(L"Command=recent_items\n",L"Command=recent_programs\n"); items.Replace(L"Command=control_panel_categories\n",L"Command=control_panel\n"); pSettingItems->value=items; - pSettingItems->flags&=~CSetting::FLAG_DEFAULT; + if (pSettingItems->value==pSettingItems->defValue) + pSettingItems->flags|=CSetting::FLAG_DEFAULT; + else + pSettingItems->flags&=~CSetting::FLAG_DEFAULT; } // set initial menu style @@ -4553,7 +4571,10 @@ void UpgradeSettings( bool bShared ) if (!pSettingStyle->IsLocked()) { pSettingStyle->value=(bTwoColumns?1:0); - pSettingStyle->flags&=~CSetting::FLAG_DEFAULT; + if (pSettingStyle->value==pSettingStyle->defValue) + pSettingStyle->flags|=CSetting::FLAG_DEFAULT; + else + pSettingStyle->flags&=~CSetting::FLAG_DEFAULT; SetSettingsStyle(bTwoColumns?CSetting::FLAG_MENU_CLASSIC2:CSetting::FLAG_MENU_CLASSIC1,CSetting::FLAG_MENU_MASK); } @@ -4565,7 +4586,10 @@ void UpgradeSettings( bool bShared ) if (!pSetting->IsDefault()) { pSettingSkin->value=pSetting->value; - pSettingSkin->flags&=~CSetting::FLAG_DEFAULT; + if (pSettingSkin->value==pSettingSkin->defValue) + pSettingSkin->flags|=CSetting::FLAG_DEFAULT; + else + pSettingSkin->flags&=~CSetting::FLAG_DEFAULT; } } CSetting *pSettingOpt=FindSetting(bTwoColumns?L"SkinOptionsC2":L"SkinOptionsC1"); @@ -4575,7 +4599,10 @@ void UpgradeSettings( bool bShared ) if (!pSetting->IsDefault()) { pSettingOpt->value=pSetting->value; - pSettingOpt->flags&=~CSetting::FLAG_DEFAULT; + if (pSettingOpt->value==pSettingOpt->defValue) + pSettingOpt->flags|=CSetting::FLAG_DEFAULT; + else + pSettingOpt->flags&=~CSetting::FLAG_DEFAULT; } } CSetting *pSettingVar=FindSetting(bTwoColumns?L"SkinVariationC2":L"SkinVariationC1"); @@ -4585,7 +4612,10 @@ void UpgradeSettings( bool bShared ) if (!pSetting->IsDefault()) { pSettingVar->value=pSetting->value; - pSettingVar->flags&=~CSetting::FLAG_DEFAULT; + if (pSettingVar->value==pSettingVar->defValue) + pSettingVar->flags|=CSetting::FLAG_DEFAULT; + else + pSettingVar->flags&=~CSetting::FLAG_DEFAULT; } } @@ -4597,7 +4627,10 @@ void UpgradeSettings( bool bShared ) if (!pSetting->IsDefault()) { pSettingSkin->value=pSetting->value; - pSettingSkin->flags&=~CSetting::FLAG_DEFAULT; + if (pSettingSkin->value==pSettingSkin->defValue) + pSettingSkin->flags|=CSetting::FLAG_DEFAULT; + else + pSettingSkin->flags&=~CSetting::FLAG_DEFAULT; } } pSettingOpt=FindSetting(L"SkinOptionsA"); @@ -4607,7 +4640,10 @@ void UpgradeSettings( bool bShared ) if (!pSetting->IsDefault()) { pSettingOpt->value=pSetting->value; - pSettingOpt->flags&=~CSetting::FLAG_DEFAULT; + if (pSettingOpt->value==pSettingOpt->defValue) + pSettingOpt->flags|=CSetting::FLAG_DEFAULT; + else + pSettingOpt->flags&=~CSetting::FLAG_DEFAULT; } } pSettingVar=FindSetting(L"SkinVariationA"); @@ -4617,7 +4653,10 @@ void UpgradeSettings( bool bShared ) if (!pSetting->IsDefault()) { pSettingVar->value=pSetting->value; - pSettingVar->flags&=~CSetting::FLAG_DEFAULT; + if (pSettingVar->value==pSettingVar->defValue) + pSettingVar->flags|=CSetting::FLAG_DEFAULT; + else + pSettingVar->flags&=~CSetting::FLAG_DEFAULT; } } }