Fixed issue #1264: TortoiseProc might crash if commands are executed w/o a working...
[TortoiseGit.git] / src / TortoiseProc / FindDlg.cpp
blobde40b789bbbea67b1c3daf7d8e6d3da819817d63
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2006 - Stefan Kueng
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "resource.h"
21 #include "FindDlg.h"
24 // CFindDlg dialog
26 IMPLEMENT_DYNAMIC(CFindDlg, CResizableStandAloneDialog)
28 CFindDlg::CFindDlg(CWnd* pParent /*=NULL*/)
29 : CResizableStandAloneDialog(CFindDlg::IDD, pParent)
30 , m_bTerminating(false)
31 , m_bFindNext(false)
32 , m_bMatchCase(FALSE)
33 , m_bLimitToDiffs(FALSE)
34 , m_bWholeWord(FALSE)
35 , m_bIsRef(false)
37 m_pParent = pParent;
40 CFindDlg::~CFindDlg()
44 void CFindDlg::DoDataExchange(CDataExchange* pDX)
46 CDialog::DoDataExchange(pDX);
47 DDX_Check(pDX, IDC_MATCHCASE, m_bMatchCase);
48 DDX_Check(pDX, IDC_WHOLEWORD, m_bWholeWord);
49 DDX_Control(pDX, IDC_FINDCOMBO, m_FindCombo);
50 DDX_Control(pDX, IDC_LIST_REF, m_ctrlRefList);
51 DDX_Control(pDX, IDC_EDIT_FILTER, m_ctrlFilter);
55 BEGIN_MESSAGE_MAP(CFindDlg, CResizableStandAloneDialog)
56 ON_CBN_EDITCHANGE(IDC_FINDCOMBO, &CFindDlg::OnCbnEditchangeFindcombo)
57 ON_NOTIFY(NM_CLICK, IDC_LIST_REF, &CFindDlg::OnNMClickListRef)
58 ON_EN_CHANGE(IDC_EDIT_FILTER, &CFindDlg::OnEnChangeEditFilter)
59 ON_WM_TIMER()
60 END_MESSAGE_MAP()
63 // CFindDlg message handlers
65 void CFindDlg::OnCancel()
67 m_bTerminating = true;
69 CWnd *parent = m_pParent;
70 if(parent == NULL)
71 parent = GetParent();
73 if (parent)
74 parent->SendMessage(m_FindMsg);
76 DestroyWindow();
79 void CFindDlg::PostNcDestroy()
81 delete this;
84 void CFindDlg::OnOK()
86 UpdateData();
87 m_FindCombo.SaveHistory();
89 if (m_FindCombo.GetString().IsEmpty())
90 return;
91 m_bFindNext = true;
92 m_FindString = m_FindCombo.GetString();
94 CWnd *parent = m_pParent;
95 if(parent == NULL)
96 parent = GetParent();
98 if (parent)
99 parent->SendMessage(m_FindMsg);
100 m_bFindNext = false;
103 BOOL CFindDlg::OnInitDialog()
105 CDialog::OnInitDialog();
106 m_FindMsg = RegisterWindowMessage(FINDMSGSTRING);
108 m_FindCombo.LoadHistory(_T("Software\\TortoiseGit\\History\\Find"), _T("Search"));
110 m_FindCombo.SetFocus();
112 this->AddAnchor(IDC_STATIC_FIND, TOP_LEFT, TOP_RIGHT);
113 this->AddAnchor(IDC_FINDCOMBO, TOP_LEFT, TOP_RIGHT);
114 this->AddAnchor(IDOK, TOP_RIGHT);
115 this->AddAnchor(IDCANCEL, TOP_RIGHT);
116 this->AddAnchor(IDC_STATIC_GROUP_REF, TOP_LEFT, BOTTOM_RIGHT);
117 this->AddAnchor(IDC_STATIC_FILTER, BOTTOM_LEFT);
118 this->AddAnchor(IDC_EDIT_FILTER, BOTTOM_LEFT, BOTTOM_RIGHT);
119 this->AddAnchor(IDC_LIST_REF, TOP_LEFT, BOTTOM_RIGHT);
120 this->AddOthersToAnchor();
122 EnableSaveRestore(_T("FindDlg"));
124 CImageList *imagelist = new CImageList();
125 imagelist->Create(IDB_BITMAP_REFTYPE,16,3,RGB(255,255,255));
126 this->m_ctrlRefList.SetImageList(imagelist,LVSIL_SMALL);
128 CRect rect;
129 m_ctrlRefList.GetClientRect(&rect);
131 this->m_ctrlRefList.InsertColumn(0,_T("Ref"),0, rect.Width()-50);
132 g_Git.GetRefList(m_RefList);
133 AddToList();
134 return FALSE;
137 void CFindDlg::OnCbnEditchangeFindcombo()
139 UpdateData();
140 GetDlgItem(IDOK)->EnableWindow(!m_FindCombo.GetString().IsEmpty());
143 void CFindDlg::AddToList()
145 this->m_ctrlRefList.DeleteAllItems();
146 CString filter;
147 this->m_ctrlFilter.GetWindowText(filter);
149 int item =0;
150 for(int i=0;i< m_RefList.size();i++)
152 int nImage = -1;
153 CString ref = m_RefList[i];
154 if(ref.Find(_T("refs/tags")) == 0)
155 nImage = 0;
156 else if(ref.Find(_T("refs/remotes"))==0)
157 nImage = 2;
158 else if(ref.Find(_T("refs/heads"))== 0)
159 nImage = 1;
161 if(ref.Find(filter)>=0)
162 m_ctrlRefList.InsertItem(item++,ref,nImage);
166 void CFindDlg::OnNMClickListRef(NMHDR *pNMHDR, LRESULT *pResult)
168 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
170 this->m_FindString = this->m_ctrlRefList.GetItemText(pNMItemActivate->iItem,0);
171 this->m_bIsRef =true;
173 CWnd *parent = m_pParent;
174 if(parent == NULL)
175 parent = GetParent();
177 if (parent)
178 parent->SendMessage(m_FindMsg);
180 this->m_bIsRef =false;
182 *pResult = 0;
185 void CFindDlg::OnEnChangeEditFilter()
187 SetTimer(IDT_FILTER, 1000, NULL);
190 void CFindDlg::OnTimer(UINT_PTR nIDEvent)
192 if( nIDEvent == IDT_FILTER)
194 KillTimer(IDT_FILTER);
195 this->AddToList();
198 CResizableStandAloneDialog::OnTimer(nIDEvent);