Fixed issue #4126: Capitalize the first letter in the Push dialog
[TortoiseGit.git] / src / TortoiseProc / FindDlg.cpp
blob1b0a8e34beafbd3b4e18793d430ea560f608a51f
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2016, 2018-2019, 2023 - 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_bFindNext(false)
32 , m_bMatchCase(FALSE)
33 , m_bRegex(FALSE)
34 , m_bIsRef(false)
35 , m_regMatchCase(L"Software\\TortoiseGit\\LogDialog\\FindMatchCase", FALSE)
36 , m_regRegex(L"Software\\TortoiseGit\\LogDialog\\FindRegex", FALSE)
37 , m_pParent(pParent)
41 CFindDlg::~CFindDlg()
45 void CFindDlg::DoDataExchange(CDataExchange* pDX)
47 CDialog::DoDataExchange(pDX);
48 DDX_Check(pDX, IDC_MATCHCASE, m_bMatchCase);
49 DDX_Check(pDX, IDC_CHECK_REGEX, m_bRegex);
50 DDX_Control(pDX, IDC_FINDCOMBO, m_FindCombo);
51 DDX_Control(pDX, IDC_LIST_REF, m_ctrlRefList);
52 DDX_Control(pDX, IDC_EDIT_FILTER, m_ctrlFilter);
56 BEGIN_MESSAGE_MAP(CFindDlg, CResizableStandAloneDialog)
57 ON_CBN_EDITCHANGE(IDC_FINDCOMBO, &CFindDlg::OnCbnEditchangeFindcombo)
58 ON_NOTIFY(NM_CLICK, IDC_LIST_REF, &CFindDlg::OnNMClickListRef)
59 ON_EN_CHANGE(IDC_EDIT_FILTER, &CFindDlg::OnEnChangeEditFilter)
60 ON_WM_TIMER()
61 END_MESSAGE_MAP()
64 // CFindDlg message handlers
66 void CFindDlg::OnCancel()
68 m_bTerminating = true;
70 CWnd *parent = m_pParent;
71 if (!parent)
72 parent = GetParent();
74 if (parent)
75 parent->SendMessage(m_FindMsg);
77 DestroyWindow();
80 void CFindDlg::PostNcDestroy()
82 delete this;
85 void CFindDlg::OnOK()
87 UpdateData();
88 m_FindCombo.SaveHistory();
90 m_regMatchCase = m_bMatchCase;
91 m_regRegex = m_bRegex;
93 if (m_FindCombo.GetString().IsEmpty())
94 return;
95 m_bFindNext = true;
96 m_FindString = m_FindCombo.GetString();
98 CWnd *parent = m_pParent;
99 if (!parent)
100 parent = GetParent();
102 if (parent)
103 parent->SendMessage(m_FindMsg);
104 m_bFindNext = false;
107 BOOL CFindDlg::OnInitDialog()
109 __super::OnInitDialog();
110 m_FindMsg = RegisterWindowMessage(FINDMSGSTRING);
112 m_bMatchCase = m_regMatchCase;
113 m_bRegex = m_regRegex;
114 UpdateData(FALSE);
116 m_FindCombo.SetCaseSensitive(TRUE);
117 m_FindCombo.LoadHistory(L"Software\\TortoiseGit\\History\\Find", L"Search");
118 m_FindCombo.SetCurSel(0);
119 m_FindCombo.SetFocus();
121 this->AddAnchor(IDC_STATIC_FIND, TOP_LEFT, TOP_RIGHT);
122 this->AddAnchor(IDC_FINDCOMBO, TOP_LEFT, TOP_RIGHT);
123 this->AddAnchor(IDOK, TOP_RIGHT);
124 this->AddAnchor(IDCANCEL, TOP_RIGHT);
125 this->AddAnchor(IDC_STATIC_GROUP_REF, TOP_LEFT, BOTTOM_RIGHT);
126 this->AddAnchor(IDC_STATIC_FILTER, BOTTOM_LEFT);
127 this->AddAnchor(IDC_EDIT_FILTER, BOTTOM_LEFT, BOTTOM_RIGHT);
128 this->AddAnchor(IDC_LIST_REF, TOP_LEFT, BOTTOM_RIGHT);
129 this->AddOthersToAnchor();
131 EnableSaveRestore(L"FindDlg");
133 CImageList *imagelist = new CImageList();
134 imagelist->Create(IDB_BITMAP_REFTYPE,16,3,RGB(255,255,255));
135 this->m_ctrlRefList.SetImageList(imagelist,LVSIL_SMALL);
137 CRect rect;
138 m_ctrlRefList.GetClientRect(&rect);
140 this->m_ctrlRefList.InsertColumn(0, L"Ref", 0, rect.Width() - 50);
141 if (CRegDWORD(L"Software\\TortoiseGit\\FullRowSelect", TRUE))
142 m_ctrlRefList.SetExtendedStyle(m_ctrlRefList.GetExtendedStyle() | LVS_EX_FULLROWSELECT);
143 RefreshList();
144 return FALSE;
147 void CFindDlg::RefreshList()
149 m_RefList.clear();
150 if (g_Git.GetRefList(m_RefList))
151 MessageBox(g_Git.GetGitLastErr(L"Could not get all refs."), L"TortoiseGit", MB_ICONERROR);
152 AddToList();
155 void CFindDlg::OnCbnEditchangeFindcombo()
157 UpdateData();
158 GetDlgItem(IDOK)->EnableWindow(!m_FindCombo.GetString().IsEmpty());
161 void CFindDlg::AddToList()
163 this->m_ctrlRefList.DeleteAllItems();
164 CString filter;
165 this->m_ctrlFilter.GetWindowText(filter);
167 int item =0;
168 for (size_t i = 0; i < m_RefList.size(); ++i)
170 int nImage = -1;
171 CString ref = m_RefList[i];
172 if (CStringUtils::StartsWith(ref, L"refs/tags/"))
173 nImage = 0;
174 else if (CStringUtils::StartsWith(ref, L"refs/remotes/"))
175 nImage = 2;
176 else if (CStringUtils::StartsWith(ref, L"refs/heads/"))
177 nImage = 1;
179 if(ref.Find(filter)>=0)
180 m_ctrlRefList.InsertItem(item++,ref,nImage);
184 void CFindDlg::OnNMClickListRef(NMHDR *pNMHDR, LRESULT *pResult)
186 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
188 this->m_FindString = this->m_ctrlRefList.GetItemText(pNMItemActivate->iItem,0);
189 this->m_bIsRef =true;
191 CWnd *parent = m_pParent;
192 if (!parent)
193 parent = GetParent();
195 if (parent)
196 parent->SendMessage(m_FindMsg);
198 this->m_bIsRef =false;
200 *pResult = 0;
203 void CFindDlg::OnEnChangeEditFilter()
205 SetTimer(IDT_FILTER, 1000, nullptr);
208 void CFindDlg::OnTimer(UINT_PTR nIDEvent)
210 if( nIDEvent == IDT_FILTER)
212 KillTimer(IDT_FILTER);
213 this->AddToList();
216 CResizableStandAloneDialog::OnTimer(nIDEvent);