Skip to content

Commit

Permalink
Modify the "Substitution Filters" dialog.
Browse files Browse the repository at this point in the history
- Disable the "Remove" button when no item is selected.
- Disable the "Clear" button when no items are registered in the list.
  • Loading branch information
tjmprm77 committed Oct 15, 2023
1 parent 8bf53d7 commit d9a9586
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Src/SubstitutionFiltersDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ BEGIN_MESSAGE_MAP(SubstitutionFiltersDlg, CTrPropertyPage)
ON_BN_CLICKED(IDC_LFILTER_ADDBTN, OnBnClickedAddBtn)
ON_BN_CLICKED(IDC_LFILTER_CLEARBTN, OnBnClickedClearBtn)
ON_BN_CLICKED(IDC_LFILTER_REMOVEBTN, OnBnClickedRemovebtn)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_SUBSTITUTION_FILTERS, OnLvnItemChangedSubstitutionFilterList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

Expand All @@ -68,6 +69,8 @@ BOOL SubstitutionFiltersDlg::OnInitDialog()

InitList();

SetButtonState();

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Expand Down Expand Up @@ -145,6 +148,8 @@ void SubstitutionFiltersDlg::OnBnClickedAddBtn()
void SubstitutionFiltersDlg::OnBnClickedClearBtn()
{
m_listFilters.DeleteAllItems();

SetButtonState();
}

/**
Expand Down Expand Up @@ -211,4 +216,40 @@ void SubstitutionFiltersDlg::OnBnClickedRemovebtn()
bool bPartialOk = false;
m_listFilters.EnsureVisible(newSel, bPartialOk);
}

SetButtonState();
}

/**
* @brief Called when item state is changed.
*
* Set the state of the "Remove" and "Clear" buttons.
* @param [in] pNMHDR Listview item data.
* @param [out] pResult Result of the action is returned in here.
*/
void SubstitutionFiltersDlg::OnLvnItemChangedSubstitutionFilterList(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
if ((pNMLV->uOldState & LVIS_SELECTED) != (pNMLV->uNewState & LVIS_SELECTED))
{
SetButtonState();
}
*pResult = 0;
}

/**
* @brief Set the state of the "Remove" and "Clear" buttons.
*
* Disable the "Remove" button when no item is selected.
* Disable the "Clear" button when no item is registered in the list.
*/
void SubstitutionFiltersDlg::SetButtonState()
{
int sel = -1;
sel = m_listFilters.GetNextItem(sel, LVNI_SELECTED);
bool enabled = (sel != -1);
EnableDlgItem(IDC_LFILTER_REMOVEBTN, enabled);

enabled = (m_listFilters.GetItemCount() > 0);
EnableDlgItem(IDC_LFILTER_CLEARBTN, enabled);
}
3 changes: 3 additions & 0 deletions Src/SubstitutionFiltersDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class SubstitutionFiltersDlg : public CTrPropertyPage
afx_msg void OnBnClickedAddBtn();
afx_msg void OnBnClickedClearBtn();
afx_msg void OnBnClickedRemovebtn();
afx_msg void OnLvnItemChangedSubstitutionFilterList(NMHDR* pNMHDR, LRESULT* pResult);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

Expand All @@ -54,4 +55,6 @@ class SubstitutionFiltersDlg : public CTrPropertyPage
CSubeditList m_listFilters; /**< List control having filter strings */

SubstitutionFiltersList *m_pSubstitutionFiltersList;

void SetButtonState();
};

0 comments on commit d9a9586

Please sign in to comment.