Can dynamically set show/hide checkboxes in GitStatusListCtrl
[TortoiseGit.git] / src / TortoiseProc / FindDlg.cpp
bloba9d44734e1bf15b9af3d7307e8087467418e1946
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"
25 // CFindDlg dialog
27 IMPLEMENT_DYNAMIC(CFindDlg, CResizableStandAloneDialog)
29 CFindDlg::CFindDlg(CWnd* pParent /*=NULL*/)
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_bIsRef(false)
37 , m_FindMsg(0)
39 m_pParent = pParent;
42 CFindDlg::~CFindDlg()
46 void CFindDlg::DoDataExchange(CDataExchange* pDX)
48 CDialog::DoDataExchange(pDX);
49 DDX_Check(pDX, IDC_MATCHCASE, m_bMatchCase);
50 DDX_Check(pDX, IDC_WHOLEWORD, m_bWholeWord);
51 DDX_Control(pDX, IDC_FINDCOMBO, m_FindCombo);
52 DDX_Control(pDX, IDC_LIST_REF, m_ctrlRefList);
53 DDX_Control(pDX, IDC_EDIT_FILTER, m_ctrlFilter);
57 BEGIN_MESSAGE_MAP(CFindDlg, CResizableStandAloneDialog)
58 ON_CBN_EDITCHANGE(IDC_FINDCOMBO, &CFindDlg::OnCbnEditchangeFindcombo)
59 ON_NOTIFY(NM_CLICK, IDC_LIST_REF, &CFindDlg::OnNMClickListRef)
60 ON_EN_CHANGE(IDC_EDIT_FILTER, &CFindDlg::OnEnChangeEditFilter)
61 ON_WM_TIMER()
62 END_MESSAGE_MAP()
65 // CFindDlg message handlers
67 void CFindDlg::OnCancel()
69 m_bTerminating = true;
71 CWnd *parent = m_pParent;
72 if(parent == NULL)
73 parent = GetParent();
75 if (parent)
76 parent->SendMessage(m_FindMsg);
78 DestroyWindow();
81 void CFindDlg::PostNcDestroy()
83 delete this;
86 void CFindDlg::OnOK()
88 UpdateData();
89 m_FindCombo.SaveHistory();
91 if (m_FindCombo.GetString().IsEmpty())
92 return;
93 m_bFindNext = true;
94 m_FindString = m_FindCombo.GetString();
96 CWnd *parent = m_pParent;
97 if(parent == NULL)
98 parent = GetParent();
100 if (parent)
101 parent->SendMessage(m_FindMsg);
102 m_bFindNext = false;
105 BOOL CFindDlg::OnInitDialog()
107 CDialog::OnInitDialog();
108 m_FindMsg = RegisterWindowMessage(FINDMSGSTRING);
110 m_FindCombo.LoadHistory(_T("Software\\TortoiseGit\\History\\Find"), _T("Search"));
112 m_FindCombo.SetFocus();
114 this->AddAnchor(IDC_STATIC_FIND, TOP_LEFT, TOP_RIGHT);
115 this->AddAnchor(IDC_FINDCOMBO, TOP_LEFT, TOP_RIGHT);
116 this->AddAnchor(IDOK, TOP_RIGHT);
117 this->AddAnchor(IDCANCEL, TOP_RIGHT);
118 this->AddAnchor(IDC_STATIC_GROUP_REF, TOP_LEFT, BOTTOM_RIGHT);
119 this->AddAnchor(IDC_STATIC_FILTER, BOTTOM_LEFT);
120 this->AddAnchor(IDC_EDIT_FILTER, BOTTOM_LEFT, BOTTOM_RIGHT);
121 this->AddAnchor(IDC_LIST_REF, TOP_LEFT, BOTTOM_RIGHT);
122 this->AddOthersToAnchor();
124 EnableSaveRestore(_T("FindDlg"));
126 CImageList *imagelist = new CImageList();
127 imagelist->Create(IDB_BITMAP_REFTYPE,16,3,RGB(255,255,255));
128 this->m_ctrlRefList.SetImageList(imagelist,LVSIL_SMALL);
130 CRect rect;
131 m_ctrlRefList.GetClientRect(&rect);
133 this->m_ctrlRefList.InsertColumn(0,_T("Ref"),0, rect.Width()-50);
134 if (g_Git.GetRefList(m_RefList))
135 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
136 AddToList();
137 return FALSE;
140 void CFindDlg::OnCbnEditchangeFindcombo()
142 UpdateData();
143 GetDlgItem(IDOK)->EnableWindow(!m_FindCombo.GetString().IsEmpty());
146 void CFindDlg::AddToList()
148 this->m_ctrlRefList.DeleteAllItems();
149 CString filter;
150 this->m_ctrlFilter.GetWindowText(filter);
152 int item =0;
153 for (size_t i = 0; i < m_RefList.size(); ++i)
155 int nImage = -1;
156 CString ref = m_RefList[i];
157 if(ref.Find(_T("refs/tags")) == 0)
158 nImage = 0;
159 else if(ref.Find(_T("refs/remotes"))==0)
160 nImage = 2;
161 else if(ref.Find(_T("refs/heads"))== 0)
162 nImage = 1;
164 if(ref.Find(filter)>=0)
165 m_ctrlRefList.InsertItem(item++,ref,nImage);
169 void CFindDlg::OnNMClickListRef(NMHDR *pNMHDR, LRESULT *pResult)
171 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
173 this->m_FindString = this->m_ctrlRefList.GetItemText(pNMItemActivate->iItem,0);
174 this->m_bIsRef =true;
176 CWnd *parent = m_pParent;
177 if(parent == NULL)
178 parent = GetParent();
180 if (parent)
181 parent->SendMessage(m_FindMsg);
183 this->m_bIsRef =false;
185 *pResult = 0;
188 void CFindDlg::OnEnChangeEditFilter()
190 SetTimer(IDT_FILTER, 1000, NULL);
193 void CFindDlg::OnTimer(UINT_PTR nIDEvent)
195 if( nIDEvent == IDT_FILTER)
197 KillTimer(IDT_FILTER);
198 this->AddToList();
201 CResizableStandAloneDialog::OnTimer(nIDEvent);