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
.DisableTrimming();
126 m_ReplaceCombo
.LoadHistory(L
"Software\\TortoiseGitMerge\\History\\Find", L
"Replace");
127 m_ReplaceCombo
.SetCurSel(0);
129 m_FindCombo
.SetFocus();
134 void CFindDlg::OnCbnEditchangeFindcombo()
137 GetDlgItem(IDOK
)->EnableWindow(!m_FindCombo
.GetString().IsEmpty());
138 GetDlgItem(IDC_REPLACE
)->EnableWindow(!m_bReadonly
&& !m_FindCombo
.GetString().IsEmpty());
139 GetDlgItem(IDC_REPLACEALL
)->EnableWindow(!m_bReadonly
&& !m_FindCombo
.GetString().IsEmpty());
142 void CFindDlg::OnBnClickedCount()
145 SetStatusText(_T(""));
146 m_FindCombo
.SaveHistory();
147 m_regMatchCase
= m_bMatchCase
;
148 m_regLimitToDiffs
= m_bLimitToDiffs
;
149 m_regWholeWord
= m_bWholeWord
;
151 if (m_FindCombo
.GetString().IsEmpty())
155 m_pParent
->SendMessage(m_FindMsg
, FindType::Count
);
156 else if (GetParent())
157 GetParent()->SendMessage(m_FindMsg
, FindType::Count
);
161 HBRUSH
CFindDlg::OnCtlColor(CDC
* pDC
, CWnd
*pWnd
, UINT nCtlColor
)
165 case CTLCOLOR_STATIC
:
166 if (pWnd
== &m_FindStatus
)
168 HBRUSH hbr
= CDialog::OnCtlColor(pDC
, pWnd
, nCtlColor
);
169 pDC
->SetTextColor(m_clrFindStatus
);
170 pDC
->SetBkMode(TRANSPARENT
);
176 return CDialog::OnCtlColor(pDC
, pWnd
, nCtlColor
);
179 void CFindDlg::SetStatusText(const CString
& str
, COLORREF color
)
181 m_clrFindStatus
= color
;
182 m_FindStatus
.SetWindowText(str
);
185 void CFindDlg::SetReadonly(bool bReadonly
)
187 m_bReadonly
= bReadonly
;
188 m_ReplaceCombo
.EnableWindow(bReadonly
? FALSE
: TRUE
);
189 GetDlgItem(IDC_REPLACE
)->EnableWindow(!m_bReadonly
&& !m_FindCombo
.GetString().IsEmpty());
190 GetDlgItem(IDC_REPLACEALL
)->EnableWindow(!m_bReadonly
&& !m_FindCombo
.GetString().IsEmpty());
193 void CFindDlg::OnBnClickedReplace()
197 m_FindCombo
.SaveHistory();
198 m_ReplaceCombo
.SaveHistory();
199 m_regMatchCase
= m_bMatchCase
;
200 m_regLimitToDiffs
= m_bLimitToDiffs
;
201 m_regWholeWord
= m_bWholeWord
;
205 m_pParent
->SendMessage(m_FindMsg
, FindType::Replace
);
206 else if (GetParent())
207 GetParent()->SendMessage(m_FindMsg
, FindType::Replace
);
211 void CFindDlg::OnBnClickedReplaceall()
215 m_FindCombo
.SaveHistory();
216 m_ReplaceCombo
.SaveHistory();
217 m_regMatchCase
= m_bMatchCase
;
218 m_regLimitToDiffs
= m_bLimitToDiffs
;
219 m_regWholeWord
= m_bWholeWord
;
223 m_pParent
->SendMessage(m_FindMsg
, FindType::ReplaceAll
);
224 else if (GetParent())
225 GetParent()->SendMessage(m_FindMsg
, FindType::ReplaceAll
);