1 // TortoiseMerge - a Diff/Patch program
3 // Copyright (C) 2013 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "TortoiseMerge.h"
21 #include "RegexFiltersDlg.h"
22 #include "RegexFilterDlg.h"
23 #include <afxdialogex.h>
26 // CRegexFiltersDlg dialog
28 IMPLEMENT_DYNAMIC(CRegexFiltersDlg
, CDialogEx
)
30 CRegexFiltersDlg::CRegexFiltersDlg(CWnd
* pParent
/*=nullptr*/)
31 : CDialogEx(CRegexFiltersDlg::IDD
, pParent
)
36 CRegexFiltersDlg::~CRegexFiltersDlg()
40 void CRegexFiltersDlg::DoDataExchange(CDataExchange
* pDX
)
42 CDialogEx::DoDataExchange(pDX
);
43 DDX_Control(pDX
, IDC_REGEXLIST
, m_RegexList
);
47 BEGIN_MESSAGE_MAP(CRegexFiltersDlg
, CDialogEx
)
48 ON_BN_CLICKED(IDC_ADD
, &CRegexFiltersDlg::OnBnClickedAdd
)
49 ON_BN_CLICKED(IDC_EDIT
, &CRegexFiltersDlg::OnBnClickedEdit
)
50 ON_BN_CLICKED(IDC_REMOVE
, &CRegexFiltersDlg::OnBnClickedRemove
)
51 ON_NOTIFY(NM_DBLCLK
, IDC_REGEXLIST
, &CRegexFiltersDlg::OnNMDblclkRegexlist
)
52 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_REGEXLIST
, &CRegexFiltersDlg::OnLvnItemchangedRegexlist
)
56 // CRegexFiltersDlg message handlers
59 void CRegexFiltersDlg::OnBnClickedAdd()
61 CRegexFilterDlg
dlg(this);
62 if (dlg
.DoModal() == IDOK
)
64 m_pIni
->SetValue(dlg
.m_sName
, L
"regex", dlg
.m_sRegex
);
65 m_pIni
->SetValue(dlg
.m_sName
, L
"replace", dlg
.m_sReplace
);
71 void CRegexFiltersDlg::OnBnClickedEdit()
73 CRegexFilterDlg
dlg(this);
74 auto pos
= m_RegexList
.GetFirstSelectedItemPosition();
75 int index
= m_RegexList
.GetNextSelectedItem(pos
);
78 CString sName
= m_RegexList
.GetItemText(index
, 0);
80 CString sRegex
= m_pIni
->GetValue(sName
, L
"regex", L
"");
81 dlg
.m_sRegex
= sRegex
;
82 CString sReplace
= m_pIni
->GetValue(sName
, L
"replace", L
"");
83 dlg
.m_sReplace
= sReplace
;
84 if (dlg
.DoModal() == IDOK
)
86 if (sName
!= dlg
.m_sName
)
88 m_pIni
->Delete(sName
, L
"regex", true);
89 m_pIni
->Delete(sName
, L
"replace", true);
91 if (!dlg
.m_sName
.IsEmpty())
93 m_pIni
->SetValue(dlg
.m_sName
, L
"regex", dlg
.m_sRegex
);
94 m_pIni
->SetValue(dlg
.m_sName
, L
"replace", dlg
.m_sReplace
);
102 void CRegexFiltersDlg::OnBnClickedRemove()
104 auto pos
= m_RegexList
.GetFirstSelectedItemPosition();
105 int index
= m_RegexList
.GetNextSelectedItem(pos
);
108 CString sName
= m_RegexList
.GetItemText(index
, 0);
109 m_pIni
->Delete(sName
, L
"regex", true);
110 m_pIni
->Delete(sName
, L
"replace", true);
116 BOOL
CRegexFiltersDlg::OnInitDialog()
118 CDialogEx::OnInitDialog();
120 SetWindowTheme(m_RegexList
.GetSafeHwnd(), L
"Explorer", nullptr);
125 return TRUE
; // return TRUE unless you set the focus to a control
126 // EXCEPTION: OCX Property Pages should return FALSE
129 void CRegexFiltersDlg::OnNMDblclkRegexlist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
131 UNREFERENCED_PARAMETER(pNMHDR
);
132 //LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
137 void CRegexFiltersDlg::SetupListControl()
139 m_RegexList
.SetRedraw(false);
140 m_RegexList
.DeleteAllItems();
142 int c
= m_RegexList
.GetHeaderCtrl()->GetItemCount() - 1;
144 m_RegexList
.DeleteColumn(c
--);
145 m_RegexList
.InsertColumn(0, L
"Regex");
148 m_RegexList
.GetClientRect(&rect
);
149 m_RegexList
.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER
);
151 CSimpleIni::TNamesDepend sections
;
152 m_pIni
->GetAllSections(sections
);
155 for (const auto& section
: sections
)
157 m_RegexList
.InsertItem(index
++, section
.pItem
);
160 m_RegexList
.SetRedraw(true);
164 void CRegexFiltersDlg::OnLvnItemchangedRegexlist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
166 UNREFERENCED_PARAMETER(pNMHDR
);
167 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
169 bool bOneItemSelected
= (m_RegexList
.GetSelectedCount() == 1);
170 GetDlgItem(IDC_EDIT
) ->EnableWindow(bOneItemSelected
);
171 GetDlgItem(IDC_REMOVE
)->EnableWindow(bOneItemSelected
);