Drop only once used member
[TortoiseGit.git] / src / TortoiseMerge / FindDlg.cpp
blob866d7b349d226145c8c54f1533ac571db19cb9ca
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.
19 #include "stdafx.h"
20 #include "TortoiseMerge.h"
21 #include "FindDlg.h"
24 // CFindDlg dialog
26 IMPLEMENT_DYNAMIC(CFindDlg, CDialog)
28 CFindDlg::CFindDlg(CWnd* pParent /*=NULL*/)
29 : CDialog(CFindDlg::IDD, pParent)
30 , m_pParent(pParent)
31 , m_bTerminating(false)
32 , m_bFindNext(false)
33 , m_bMatchCase(FALSE)
34 , m_bLimitToDiffs(FALSE)
35 , m_bWholeWord(FALSE)
36 , m_bSearchUp(FALSE)
37 , m_FindMsg(0)
38 , m_clrFindStatus(RGB(0, 0, 255))
39 , m_bReadonly(false)
40 , m_regMatchCase(L"Software\\TortoiseGitMerge\\FindMatchCase", FALSE)
41 , m_regLimitToDiffs(L"Software\\TortoiseGitMerge\\FindLimitToDiffs", FALSE)
42 , m_regWholeWord(L"Software\\TortoiseGitMerge\\FindWholeWord", FALSE)
46 CFindDlg::~CFindDlg()
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)
67 ON_WM_CTLCOLOR()
68 ON_BN_CLICKED(IDC_REPLACE, &CFindDlg::OnBnClickedReplace)
69 ON_BN_CLICKED(IDC_REPLACEALL, &CFindDlg::OnBnClickedReplaceall)
70 END_MESSAGE_MAP()
73 // CFindDlg message handlers
75 void CFindDlg::OnCancel()
77 m_bTerminating = true;
78 SetStatusText(_T(""));
79 if (m_pParent)
80 m_pParent->SendMessage(m_FindMsg);
81 else if (GetParent())
82 GetParent()->SendMessage(m_FindMsg);
83 DestroyWindow();
86 void CFindDlg::PostNcDestroy()
88 delete this;
91 void CFindDlg::OnOK()
93 UpdateData();
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())
101 return;
102 m_bFindNext = true;
103 if (m_pParent)
104 m_pParent->SendMessage(m_FindMsg);
105 else if (GetParent())
106 GetParent()->SendMessage(m_FindMsg);
107 m_bFindNext = false;
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;
118 UpdateData(FALSE);
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();
132 return FALSE;
135 void CFindDlg::OnCbnEditchangeFindcombo()
137 UpdateData();
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()
145 UpdateData();
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())
153 return;
154 m_bFindNext = true;
155 if (m_pParent)
156 m_pParent->SendMessage(m_FindMsg, FindType::Count);
157 else if (GetParent())
158 GetParent()->SendMessage(m_FindMsg, FindType::Count);
159 m_bFindNext = false;
162 HBRUSH CFindDlg::OnCtlColor(CDC* pDC, CWnd *pWnd, UINT nCtlColor)
164 switch (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);
172 return hbr;
174 default:
175 break;
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()
196 UpdateData();
197 SetStatusText(L"");
198 m_FindCombo.SaveHistory();
199 m_ReplaceCombo.SaveHistory();
200 m_regMatchCase = m_bMatchCase;
201 m_regLimitToDiffs = m_bLimitToDiffs;
202 m_regWholeWord = m_bWholeWord;
204 m_bFindNext = true;
205 if (m_pParent)
206 m_pParent->SendMessage(m_FindMsg, FindType::Replace);
207 else if (GetParent())
208 GetParent()->SendMessage(m_FindMsg, FindType::Replace);
209 m_bFindNext = false;
212 void CFindDlg::OnBnClickedReplaceall()
214 UpdateData();
215 SetStatusText(L"");
216 m_FindCombo.SaveHistory();
217 m_ReplaceCombo.SaveHistory();
218 m_regMatchCase = m_bMatchCase;
219 m_regLimitToDiffs = m_bLimitToDiffs;
220 m_regWholeWord = m_bWholeWord;
222 m_bFindNext = true;
223 if (m_pParent)
224 m_pParent->SendMessage(m_FindMsg, FindType::ReplaceAll);
225 else if (GetParent())
226 GetParent()->SendMessage(m_FindMsg, FindType::ReplaceAll);
227 m_bFindNext = false;