1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2006, 2011-2014 - 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"
26 IMPLEMENT_DYNAMIC(CFindDlg
, CDialog
)
28 CFindDlg::CFindDlg(CWnd
* pParent
/*=NULL*/)
29 : CDialog(CFindDlg::IDD
, pParent
)
31 , m_bTerminating(false)
34 , m_bLimitToDiffs(FALSE
)
38 , m_clrFindStatus(RGB(0, 0, 255))
40 , m_regMatchCase(L
"Software\\TortoiseGitMerge\\FindMatchCase", FALSE
)
41 , m_regLimitToDiffs(L
"Software\\TortoiseGitMerge\\FindLimitToDiffs", FALSE
)
42 , m_regWholeWord(L
"Software\\TortoiseGitMerge\\FindWholeWord", FALSE
)
50 void CFindDlg::DoDataExchange(CDataExchange
* pDX
)
52 CDialog::DoDataExchange(pDX
);
53 DDX_Check(pDX
, IDC_MATCHCASE
, m_bMatchCase
);
54 DDX_Check(pDX
, IDC_LIMITTODIFFS
, m_bLimitToDiffs
);
55 DDX_Check(pDX
, IDC_WHOLEWORD
, m_bWholeWord
);
56 DDX_Check(pDX
, IDC_SEARCHUP
, m_bSearchUp
);
57 DDX_Control(pDX
, IDC_FINDCOMBO
, m_FindCombo
);
58 DDX_Control(pDX
, IDC_REPLACECOMBO
, m_ReplaceCombo
);
59 DDX_Control(pDX
, IDC_FINDSTATUS
, m_FindStatus
);
63 BEGIN_MESSAGE_MAP(CFindDlg
, CDialog
)
64 ON_CBN_EDITCHANGE(IDC_FINDCOMBO
, &CFindDlg::OnCbnEditchangeFindcombo
)
65 ON_CBN_EDITCHANGE(IDC_REPLACECOMBO
, &CFindDlg::OnCbnEditchangeFindcombo
)
66 ON_BN_CLICKED(IDC_COUNT
, &CFindDlg::OnBnClickedCount
)
68 ON_BN_CLICKED(IDC_REPLACE
, &CFindDlg::OnBnClickedReplace
)
69 ON_BN_CLICKED(IDC_REPLACEALL
, &CFindDlg::OnBnClickedReplaceall
)
73 // CFindDlg message handlers
75 void CFindDlg::OnCancel()
77 m_bTerminating
= true;
78 SetStatusText(_T(""));
80 m_pParent
->SendMessage(m_FindMsg
);
82 GetParent()->SendMessage(m_FindMsg
);
86 void CFindDlg::PostNcDestroy()
94 SetStatusText(_T(""));
95 m_FindCombo
.SaveHistory();
96 m_regMatchCase
= m_bMatchCase
;
97 m_regLimitToDiffs
= m_bLimitToDiffs
;
98 m_regWholeWord
= m_bWholeWord
;
100 if (m_FindCombo
.GetString().IsEmpty())
104 m_pParent
->SendMessage(m_FindMsg
);
105 else if (GetParent())
106 GetParent()->SendMessage(m_FindMsg
);
110 BOOL
CFindDlg::OnInitDialog()
112 CDialog::OnInitDialog();
113 m_FindMsg
= RegisterWindowMessage(FINDMSGSTRING
);
115 m_bMatchCase
= (BOOL
)(DWORD
)m_regMatchCase
;
116 m_bLimitToDiffs
= (BOOL
)(DWORD
)m_regLimitToDiffs
;
117 m_bWholeWord
= (BOOL
)(DWORD
)m_regWholeWord
;
120 m_FindCombo
.SetCaseSensitive(TRUE
);
121 m_FindCombo
.DisableTrimming();
122 m_FindCombo
.LoadHistory(_T("Software\\TortoiseGitMerge\\History\\Find"), _T("Search"));
123 m_FindCombo
.SetCurSel(0);
125 m_ReplaceCombo
.SetCaseSensitive(TRUE
);
126 m_ReplaceCombo
.DisableTrimming();
127 m_ReplaceCombo
.LoadHistory(L
"Software\\TortoiseGitMerge\\History\\Find", L
"Replace");
128 m_ReplaceCombo
.SetCurSel(0);
130 m_FindCombo
.SetFocus();
135 void CFindDlg::OnCbnEditchangeFindcombo()
138 GetDlgItem(IDOK
)->EnableWindow(!m_FindCombo
.GetString().IsEmpty());
139 GetDlgItem(IDC_REPLACE
)->EnableWindow(!m_bReadonly
&& !m_FindCombo
.GetString().IsEmpty());
140 GetDlgItem(IDC_REPLACEALL
)->EnableWindow(!m_bReadonly
&& !m_FindCombo
.GetString().IsEmpty());
143 void CFindDlg::OnBnClickedCount()
146 SetStatusText(_T(""));
147 m_FindCombo
.SaveHistory();
148 m_regMatchCase
= m_bMatchCase
;
149 m_regLimitToDiffs
= m_bLimitToDiffs
;
150 m_regWholeWord
= m_bWholeWord
;
152 if (m_FindCombo
.GetString().IsEmpty())
156 m_pParent
->SendMessage(m_FindMsg
, FindType::Count
);
157 else if (GetParent())
158 GetParent()->SendMessage(m_FindMsg
, FindType::Count
);
162 HBRUSH
CFindDlg::OnCtlColor(CDC
* pDC
, CWnd
*pWnd
, UINT nCtlColor
)
166 case CTLCOLOR_STATIC
:
167 if (pWnd
== &m_FindStatus
)
169 HBRUSH hbr
= CDialog::OnCtlColor(pDC
, pWnd
, nCtlColor
);
170 pDC
->SetTextColor(m_clrFindStatus
);
171 pDC
->SetBkMode(TRANSPARENT
);
177 return CDialog::OnCtlColor(pDC
, pWnd
, nCtlColor
);
180 void CFindDlg::SetStatusText(const CString
& str
, COLORREF color
)
182 m_clrFindStatus
= color
;
183 m_FindStatus
.SetWindowText(str
);
186 void CFindDlg::SetReadonly(bool bReadonly
)
188 m_bReadonly
= bReadonly
;
189 m_ReplaceCombo
.EnableWindow(bReadonly
? FALSE
: TRUE
);
190 GetDlgItem(IDC_REPLACE
)->EnableWindow(!m_bReadonly
&& !m_FindCombo
.GetString().IsEmpty());
191 GetDlgItem(IDC_REPLACEALL
)->EnableWindow(!m_bReadonly
&& !m_FindCombo
.GetString().IsEmpty());
194 void CFindDlg::OnBnClickedReplace()
198 m_FindCombo
.SaveHistory();
199 m_ReplaceCombo
.SaveHistory();
200 m_regMatchCase
= m_bMatchCase
;
201 m_regLimitToDiffs
= m_bLimitToDiffs
;
202 m_regWholeWord
= m_bWholeWord
;
206 m_pParent
->SendMessage(m_FindMsg
, FindType::Replace
);
207 else if (GetParent())
208 GetParent()->SendMessage(m_FindMsg
, FindType::Replace
);
212 void CFindDlg::OnBnClickedReplaceall()
216 m_FindCombo
.SaveHistory();
217 m_ReplaceCombo
.SaveHistory();
218 m_regMatchCase
= m_bMatchCase
;
219 m_regLimitToDiffs
= m_bLimitToDiffs
;
220 m_regWholeWord
= m_bWholeWord
;
224 m_pParent
->SendMessage(m_FindMsg
, FindType::ReplaceAll
);
225 else if (GetParent())
226 GetParent()->SendMessage(m_FindMsg
, FindType::ReplaceAll
);