Skip to content

Commit

Permalink
Auto-detect when setting is back to default value
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thisismy-github authored and Ibuprophen committed Aug 13, 2022
1 parent 0cb43dd commit 998d83c
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 24 deletions.
20 changes: 16 additions & 4 deletions Src/Lib/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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;
}
}
Expand Down
35 changes: 28 additions & 7 deletions Src/Lib/SettingsUIHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -3023,23 +3035,32 @@ 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)
{
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
{
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();
Expand Down
65 changes: 52 additions & 13 deletions Src/StartMenu/StartMenuDLL/SettingsUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -4545,15 +4560,21 @@ 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
CSetting *pSettingStyle=FindSetting(L"MenuStyle");
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);
}

Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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;
}
}

Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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;
}
}
}
Expand Down

0 comments on commit 998d83c

Please sign in to comment.