Fixed issue #1789: Tooltips not properly displayed in Log List if that commit has...
[TortoiseGit.git] / src / TortoiseProc / FindDlg.cpp
blobe87e38c76ef3265cce2627dcb8b6821451342aaa
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2013 - 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 "registry.h"
26 // CFindDlg dialog
28 IMPLEMENT_DYNAMIC(CFindDlg, CResizableStandAloneDialog)
30 CFindDlg::CFindDlg(CWnd* pParent /*=NULL*/)
31 : CResizableStandAloneDialog(CFindDlg::IDD, pParent)
32 , m_bTerminating(false)
33 , m_bFindNext(false)
34 , m_bMatchCase(FALSE)
35 , m_bLimitToDiffs(FALSE)
36 , m_bWholeWord(FALSE)
37 , m_bRegex(FALSE)
38 , m_bIsRef(false)
39 , m_FindMsg(0)
40 , m_regMatchCase(L"Software\\TortoiseGit\\LogDialog\\FindMatchCase", FALSE)
41 , m_regWholeWord(L"Software\\TortoiseGit\\LogDialog\\FindWholeWord", FALSE)
42 , m_regRegex(L"Software\\TortoiseGit\\LogDialog\\FindRegex", FALSE)
44 m_pParent = pParent;
47 CFindDlg::~CFindDlg()
51 void CFindDlg::DoDataExchange(CDataExchange* pDX)
53 CDialog::DoDataExchange(pDX);
54 DDX_Check(pDX, IDC_MATCHCASE, m_bMatchCase);
55 DDX_Check(pDX, IDC_WHOLEWORD, m_bWholeWord);
56 DDX_Check(pDX, IDC_CHECK_REGEX, m_bRegex);
57 DDX_Control(pDX, IDC_FINDCOMBO, m_FindCombo);
58 DDX_Control(pDX, IDC_LIST_REF, m_ctrlRefList);
59 DDX_Control(pDX, IDC_EDIT_FILTER, m_ctrlFilter);
63 BEGIN_MESSAGE_MAP(CFindDlg, CResizableStandAloneDialog)
64 ON_CBN_EDITCHANGE(IDC_FINDCOMBO, &CFindDlg::OnCbnEditchangeFindcombo)
65 ON_NOTIFY(NM_CLICK, IDC_LIST_REF, &CFindDlg::OnNMClickListRef)
66 ON_EN_CHANGE(IDC_EDIT_FILTER, &CFindDlg::OnEnChangeEditFilter)
67 ON_WM_TIMER()
68 END_MESSAGE_MAP()
71 // CFindDlg message handlers
73 void CFindDlg::OnCancel()
75 m_bTerminating = true;
77 CWnd *parent = m_pParent;
78 if(parent == NULL)
79 parent = GetParent();
81 if (parent)
82 parent->SendMessage(m_FindMsg);
84 DestroyWindow();
87 void CFindDlg::PostNcDestroy()
89 delete this;
92 void CFindDlg::OnOK()
94 UpdateData();
95 m_FindCombo.SaveHistory();
97 m_regMatchCase = m_bMatchCase;
98 m_regWholeWord = m_bWholeWord;
99 m_regRegex = m_bRegex;
101 if (m_FindCombo.GetString().IsEmpty())
102 return;
103 m_bFindNext = true;
104 m_FindString = m_FindCombo.GetString();
106 CWnd *parent = m_pParent;
107 if(parent == NULL)
108 parent = GetParent();
110 if (parent)
111 parent->SendMessage(m_FindMsg);
112 m_bFindNext = false;
115 BOOL CFindDlg::OnInitDialog()
117 CDialog::OnInitDialog();
118 m_FindMsg = RegisterWindowMessage(FINDMSGSTRING);
120 m_bMatchCase = (BOOL)(DWORD)m_regMatchCase;
121 m_bWholeWord = (BOOL)(DWORD)m_regWholeWord;
122 m_bRegex = (BOOL)(DWORD)m_regRegex;
123 UpdateData(FALSE);
125 m_FindCombo.SetCaseSensitive(TRUE);
126 m_FindCombo.LoadHistory(_T("Software\\TortoiseGit\\History\\Find"), _T("Search"));
127 m_FindCombo.SetCurSel(0);
128 m_FindCombo.SetFocus();
130 this->AddAnchor(IDC_STATIC_FIND, TOP_LEFT, TOP_RIGHT);
131 this->AddAnchor(IDC_FINDCOMBO, TOP_LEFT, TOP_RIGHT);
132 this->AddAnchor(IDOK, TOP_RIGHT);
133 this->AddAnchor(IDCANCEL, TOP_RIGHT);
134 this->AddAnchor(IDC_STATIC_GROUP_REF, TOP_LEFT, BOTTOM_RIGHT);
135 this->AddAnchor(IDC_STATIC_FILTER, BOTTOM_LEFT);
136 this->AddAnchor(IDC_EDIT_FILTER, BOTTOM_LEFT, BOTTOM_RIGHT);
137 this->AddAnchor(IDC_LIST_REF, TOP_LEFT, BOTTOM_RIGHT);
138 this->AddOthersToAnchor();
140 EnableSaveRestore(_T("FindDlg"));
142 CImageList *imagelist = new CImageList();
143 imagelist->Create(IDB_BITMAP_REFTYPE,16,3,RGB(255,255,255));
144 this->m_ctrlRefList.SetImageList(imagelist,LVSIL_SMALL);
146 CRect rect;
147 m_ctrlRefList.GetClientRect(&rect);
149 this->m_ctrlRefList.InsertColumn(0,_T("Ref"),0, rect.Width()-50);
150 RefreshList();
151 return FALSE;
154 void CFindDlg::RefreshList()
156 m_RefList.clear();
157 if (g_Git.GetRefList(m_RefList))
158 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
159 AddToList();
162 void CFindDlg::OnCbnEditchangeFindcombo()
164 UpdateData();
165 GetDlgItem(IDOK)->EnableWindow(!m_FindCombo.GetString().IsEmpty());
168 void CFindDlg::AddToList()
170 this->m_ctrlRefList.DeleteAllItems();
171 CString filter;
172 this->m_ctrlFilter.GetWindowText(filter);
174 int item =0;
175 for (size_t i = 0; i < m_RefList.size(); ++i)
177 int nImage = -1;
178 CString ref = m_RefList[i];
179 if(ref.Find(_T("refs/tags")) == 0)
180 nImage = 0;
181 else if(ref.Find(_T("refs/remotes"))==0)
182 nImage = 2;
183 else if(ref.Find(_T("refs/heads"))== 0)
184 nImage = 1;
186 if(ref.Find(filter)>=0)
187 m_ctrlRefList.InsertItem(item++,ref,nImage);
191 void CFindDlg::OnNMClickListRef(NMHDR *pNMHDR, LRESULT *pResult)
193 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
195 this->m_FindString = this->m_ctrlRefList.GetItemText(pNMItemActivate->iItem,0);
196 this->m_bIsRef =true;
198 CWnd *parent = m_pParent;
199 if(parent == NULL)
200 parent = GetParent();
202 if (parent)
203 parent->SendMessage(m_FindMsg);
205 this->m_bIsRef =false;
207 *pResult = 0;
210 void CFindDlg::OnEnChangeEditFilter()
212 SetTimer(IDT_FILTER, 1000, NULL);
215 void CFindDlg::OnTimer(UINT_PTR nIDEvent)
217 if( nIDEvent == IDT_FILTER)
219 KillTimer(IDT_FILTER);
220 this->AddToList();
223 CResizableStandAloneDialog::OnTimer(nIDEvent);