Fixed issue #3307: Abort Merge on a single file always results in a parameter error...
[TortoiseGit.git] / src / TortoiseProc / FindDlg.cpp
blob50653d39d7797c5034aa795f8d9015dabe64502a
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2016, 2018 - TortoiseGit
4 // Copyright (C) 2006 - Stefan Kueng
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "resource.h"
22 #include "FindDlg.h"
23 #include "StringUtils.h"
25 // CFindDlg dialog
27 IMPLEMENT_DYNAMIC(CFindDlg, CResizableStandAloneDialog)
29 CFindDlg::CFindDlg(CWnd* pParent /*=nullptr*/)
30 : CResizableStandAloneDialog(CFindDlg::IDD, pParent)
31 , m_bTerminating(false)
32 , m_bFindNext(false)
33 , m_bMatchCase(FALSE)
34 , m_bRegex(FALSE)
35 , m_bIsRef(false)
36 , m_FindMsg(0)
37 , m_regMatchCase(L"Software\\TortoiseGit\\LogDialog\\FindMatchCase", FALSE)
38 , m_regRegex(L"Software\\TortoiseGit\\LogDialog\\FindRegex", FALSE)
39 , m_pParent(pParent)
43 CFindDlg::~CFindDlg()
47 void CFindDlg::DoDataExchange(CDataExchange* pDX)
49 CDialog::DoDataExchange(pDX);
50 DDX_Check(pDX, IDC_MATCHCASE, m_bMatchCase);
51 DDX_Check(pDX, IDC_CHECK_REGEX, m_bRegex);
52 DDX_Control(pDX, IDC_FINDCOMBO, m_FindCombo);
53 DDX_Control(pDX, IDC_LIST_REF, m_ctrlRefList);
54 DDX_Control(pDX, IDC_EDIT_FILTER, m_ctrlFilter);
58 BEGIN_MESSAGE_MAP(CFindDlg, CResizableStandAloneDialog)
59 ON_CBN_EDITCHANGE(IDC_FINDCOMBO, &CFindDlg::OnCbnEditchangeFindcombo)
60 ON_NOTIFY(NM_CLICK, IDC_LIST_REF, &CFindDlg::OnNMClickListRef)
61 ON_EN_CHANGE(IDC_EDIT_FILTER, &CFindDlg::OnEnChangeEditFilter)
62 ON_WM_TIMER()
63 END_MESSAGE_MAP()
66 // CFindDlg message handlers
68 void CFindDlg::OnCancel()
70 m_bTerminating = true;
72 CWnd *parent = m_pParent;
73 if (!parent)
74 parent = GetParent();
76 if (parent)
77 parent->SendMessage(m_FindMsg);
79 DestroyWindow();
82 void CFindDlg::PostNcDestroy()
84 delete this;
87 void CFindDlg::OnOK()
89 UpdateData();
90 m_FindCombo.SaveHistory();
92 m_regMatchCase = m_bMatchCase;
93 m_regRegex = m_bRegex;
95 if (m_FindCombo.GetString().IsEmpty())
96 return;
97 m_bFindNext = true;
98 m_FindString = m_FindCombo.GetString();
100 CWnd *parent = m_pParent;
101 if (!parent)
102 parent = GetParent();
104 if (parent)
105 parent->SendMessage(m_FindMsg);
106 m_bFindNext = false;
109 BOOL CFindDlg::OnInitDialog()
111 __super::OnInitDialog();
112 m_FindMsg = RegisterWindowMessage(FINDMSGSTRING);
114 m_bMatchCase = (BOOL)(DWORD)m_regMatchCase;
115 m_bRegex = (BOOL)(DWORD)m_regRegex;
116 UpdateData(FALSE);
118 m_FindCombo.SetCaseSensitive(TRUE);
119 m_FindCombo.LoadHistory(L"Software\\TortoiseGit\\History\\Find", L"Search");
120 m_FindCombo.SetCurSel(0);
121 m_FindCombo.SetFocus();
123 this->AddAnchor(IDC_STATIC_FIND, TOP_LEFT, TOP_RIGHT);
124 this->AddAnchor(IDC_FINDCOMBO, TOP_LEFT, TOP_RIGHT);
125 this->AddAnchor(IDOK, TOP_RIGHT);
126 this->AddAnchor(IDCANCEL, TOP_RIGHT);
127 this->AddAnchor(IDC_STATIC_GROUP_REF, TOP_LEFT, BOTTOM_RIGHT);
128 this->AddAnchor(IDC_STATIC_FILTER, BOTTOM_LEFT);
129 this->AddAnchor(IDC_EDIT_FILTER, BOTTOM_LEFT, BOTTOM_RIGHT);
130 this->AddAnchor(IDC_LIST_REF, TOP_LEFT, BOTTOM_RIGHT);
131 this->AddOthersToAnchor();
133 EnableSaveRestore(L"FindDlg");
135 CImageList *imagelist = new CImageList();
136 imagelist->Create(IDB_BITMAP_REFTYPE,16,3,RGB(255,255,255));
137 this->m_ctrlRefList.SetImageList(imagelist,LVSIL_SMALL);
139 CRect rect;
140 m_ctrlRefList.GetClientRect(&rect);
142 this->m_ctrlRefList.InsertColumn(0, L"Ref", 0, rect.Width() - 50);
143 if (CRegDWORD(L"Software\\TortoiseGit\\FullRowSelect", TRUE))
144 m_ctrlRefList.SetExtendedStyle(m_ctrlRefList.GetExtendedStyle() | LVS_EX_FULLROWSELECT);
145 RefreshList();
146 return FALSE;
149 void CFindDlg::RefreshList()
151 m_RefList.clear();
152 if (g_Git.GetRefList(m_RefList))
153 MessageBox(g_Git.GetGitLastErr(L"Could not get all refs."), L"TortoiseGit", MB_ICONERROR);
154 AddToList();
157 void CFindDlg::OnCbnEditchangeFindcombo()
159 UpdateData();
160 GetDlgItem(IDOK)->EnableWindow(!m_FindCombo.GetString().IsEmpty());
163 void CFindDlg::AddToList()
165 this->m_ctrlRefList.DeleteAllItems();
166 CString filter;
167 this->m_ctrlFilter.GetWindowText(filter);
169 int item =0;
170 for (size_t i = 0; i < m_RefList.size(); ++i)
172 int nImage = -1;
173 CString ref = m_RefList[i];
174 if (CStringUtils::StartsWith(ref, L"refs/tags/"))
175 nImage = 0;
176 else if (CStringUtils::StartsWith(ref, L"refs/remotes/"))
177 nImage = 2;
178 else if (CStringUtils::StartsWith(ref, L"refs/heads/"))
179 nImage = 1;
181 if(ref.Find(filter)>=0)
182 m_ctrlRefList.InsertItem(item++,ref,nImage);
186 void CFindDlg::OnNMClickListRef(NMHDR *pNMHDR, LRESULT *pResult)
188 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
190 this->m_FindString = this->m_ctrlRefList.GetItemText(pNMItemActivate->iItem,0);
191 this->m_bIsRef =true;
193 CWnd *parent = m_pParent;
194 if (!parent)
195 parent = GetParent();
197 if (parent)
198 parent->SendMessage(m_FindMsg);
200 this->m_bIsRef =false;
202 *pResult = 0;
205 void CFindDlg::OnEnChangeEditFilter()
207 SetTimer(IDT_FILTER, 1000, nullptr);
210 void CFindDlg::OnTimer(UINT_PTR nIDEvent)
212 if( nIDEvent == IDT_FILTER)
214 KillTimer(IDT_FILTER);
215 this->AddToList();
218 CResizableStandAloneDialog::OnTimer(nIDEvent);