Improve line margin icon for moved lines
[TortoiseGit.git] / src / TortoiseProc / FindDlg.cpp
blobbc57a57e32ebf14a0e484a358a90284f507e0eaa
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2016 - 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_bLimitToDiffs(FALSE)
35 , m_bWholeWord(FALSE)
36 , m_bRegex(FALSE)
37 , m_bIsRef(false)
38 , m_FindMsg(0)
39 , m_regMatchCase(L"Software\\TortoiseGit\\LogDialog\\FindMatchCase", FALSE)
40 , m_regWholeWord(L"Software\\TortoiseGit\\LogDialog\\FindWholeWord", FALSE)
41 , m_regRegex(L"Software\\TortoiseGit\\LogDialog\\FindRegex", FALSE)
42 , m_pParent(pParent)
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_WHOLEWORD, m_bWholeWord);
55 DDX_Check(pDX, IDC_CHECK_REGEX, m_bRegex);
56 DDX_Control(pDX, IDC_FINDCOMBO, m_FindCombo);
57 DDX_Control(pDX, IDC_LIST_REF, m_ctrlRefList);
58 DDX_Control(pDX, IDC_EDIT_FILTER, m_ctrlFilter);
62 BEGIN_MESSAGE_MAP(CFindDlg, CResizableStandAloneDialog)
63 ON_CBN_EDITCHANGE(IDC_FINDCOMBO, &CFindDlg::OnCbnEditchangeFindcombo)
64 ON_NOTIFY(NM_CLICK, IDC_LIST_REF, &CFindDlg::OnNMClickListRef)
65 ON_EN_CHANGE(IDC_EDIT_FILTER, &CFindDlg::OnEnChangeEditFilter)
66 ON_WM_TIMER()
67 END_MESSAGE_MAP()
70 // CFindDlg message handlers
72 void CFindDlg::OnCancel()
74 m_bTerminating = true;
76 CWnd *parent = m_pParent;
77 if (!parent)
78 parent = GetParent();
80 if (parent)
81 parent->SendMessage(m_FindMsg);
83 DestroyWindow();
86 void CFindDlg::PostNcDestroy()
88 delete this;
91 void CFindDlg::OnOK()
93 UpdateData();
94 m_FindCombo.SaveHistory();
96 m_regMatchCase = m_bMatchCase;
97 m_regWholeWord = m_bWholeWord;
98 m_regRegex = m_bRegex;
100 if (m_FindCombo.GetString().IsEmpty())
101 return;
102 m_bFindNext = true;
103 m_FindString = m_FindCombo.GetString();
105 CWnd *parent = m_pParent;
106 if (!parent)
107 parent = GetParent();
109 if (parent)
110 parent->SendMessage(m_FindMsg);
111 m_bFindNext = false;
114 BOOL CFindDlg::OnInitDialog()
116 __super::OnInitDialog();
117 m_FindMsg = RegisterWindowMessage(FINDMSGSTRING);
119 m_bMatchCase = (BOOL)(DWORD)m_regMatchCase;
120 m_bWholeWord = (BOOL)(DWORD)m_regWholeWord;
121 m_bRegex = (BOOL)(DWORD)m_regRegex;
122 UpdateData(FALSE);
124 m_FindCombo.SetCaseSensitive(TRUE);
125 m_FindCombo.LoadHistory(L"Software\\TortoiseGit\\History\\Find", L"Search");
126 m_FindCombo.SetCurSel(0);
127 m_FindCombo.SetFocus();
129 this->AddAnchor(IDC_STATIC_FIND, TOP_LEFT, TOP_RIGHT);
130 this->AddAnchor(IDC_FINDCOMBO, TOP_LEFT, TOP_RIGHT);
131 this->AddAnchor(IDOK, TOP_RIGHT);
132 this->AddAnchor(IDCANCEL, TOP_RIGHT);
133 this->AddAnchor(IDC_STATIC_GROUP_REF, TOP_LEFT, BOTTOM_RIGHT);
134 this->AddAnchor(IDC_STATIC_FILTER, BOTTOM_LEFT);
135 this->AddAnchor(IDC_EDIT_FILTER, BOTTOM_LEFT, BOTTOM_RIGHT);
136 this->AddAnchor(IDC_LIST_REF, TOP_LEFT, BOTTOM_RIGHT);
137 this->AddOthersToAnchor();
139 EnableSaveRestore(L"FindDlg");
141 CImageList *imagelist = new CImageList();
142 imagelist->Create(IDB_BITMAP_REFTYPE,16,3,RGB(255,255,255));
143 this->m_ctrlRefList.SetImageList(imagelist,LVSIL_SMALL);
145 CRect rect;
146 m_ctrlRefList.GetClientRect(&rect);
148 this->m_ctrlRefList.InsertColumn(0, L"Ref", 0, rect.Width() - 50);
149 if (CRegDWORD(L"Software\\TortoiseGit\\FullRowSelect", TRUE))
150 m_ctrlRefList.SetExtendedStyle(m_ctrlRefList.GetExtendedStyle() | LVS_EX_FULLROWSELECT);
151 RefreshList();
152 return FALSE;
155 void CFindDlg::RefreshList()
157 m_RefList.clear();
158 if (g_Git.GetRefList(m_RefList))
159 MessageBox(g_Git.GetGitLastErr(L"Could not get all refs."), L"TortoiseGit", MB_ICONERROR);
160 AddToList();
163 void CFindDlg::OnCbnEditchangeFindcombo()
165 UpdateData();
166 GetDlgItem(IDOK)->EnableWindow(!m_FindCombo.GetString().IsEmpty());
169 void CFindDlg::AddToList()
171 this->m_ctrlRefList.DeleteAllItems();
172 CString filter;
173 this->m_ctrlFilter.GetWindowText(filter);
175 int item =0;
176 for (size_t i = 0; i < m_RefList.size(); ++i)
178 int nImage = -1;
179 CString ref = m_RefList[i];
180 if (CStringUtils::StartsWith(ref, L"refs/tags/"))
181 nImage = 0;
182 else if (CStringUtils::StartsWith(ref, L"refs/remotes/"))
183 nImage = 2;
184 else if (CStringUtils::StartsWith(ref, L"refs/heads/"))
185 nImage = 1;
187 if(ref.Find(filter)>=0)
188 m_ctrlRefList.InsertItem(item++,ref,nImage);
192 void CFindDlg::OnNMClickListRef(NMHDR *pNMHDR, LRESULT *pResult)
194 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
196 this->m_FindString = this->m_ctrlRefList.GetItemText(pNMItemActivate->iItem,0);
197 this->m_bIsRef =true;
199 CWnd *parent = m_pParent;
200 if (!parent)
201 parent = GetParent();
203 if (parent)
204 parent->SendMessage(m_FindMsg);
206 this->m_bIsRef =false;
208 *pResult = 0;
211 void CFindDlg::OnEnChangeEditFilter()
213 SetTimer(IDT_FILTER, 1000, nullptr);
216 void CFindDlg::OnTimer(UINT_PTR nIDEvent)
218 if( nIDEvent == IDT_FILTER)
220 KillTimer(IDT_FILTER);
221 this->AddToList();
224 CResizableStandAloneDialog::OnTimer(nIDEvent);