Limit GUI updates the the main thread
[TortoiseGit.git] / src / TortoiseProc / FindDlg.cpp
blob66ae85c930df135ff66d2cbfc68751991579869b
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)
36 , m_FindMsg(0)
38 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_WHOLEWORD, m_bWholeWord);
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 == NULL)
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 if (m_FindCombo.GetString().IsEmpty())
91 return;
92 m_bFindNext = true;
93 m_FindString = m_FindCombo.GetString();
95 CWnd *parent = m_pParent;
96 if(parent == NULL)
97 parent = GetParent();
99 if (parent)
100 parent->SendMessage(m_FindMsg);
101 m_bFindNext = false;
104 BOOL CFindDlg::OnInitDialog()
106 CDialog::OnInitDialog();
107 m_FindMsg = RegisterWindowMessage(FINDMSGSTRING);
109 m_FindCombo.LoadHistory(_T("Software\\TortoiseGit\\History\\Find"), _T("Search"));
111 m_FindCombo.SetFocus();
113 this->AddAnchor(IDC_STATIC_FIND, TOP_LEFT, TOP_RIGHT);
114 this->AddAnchor(IDC_FINDCOMBO, TOP_LEFT, TOP_RIGHT);
115 this->AddAnchor(IDOK, TOP_RIGHT);
116 this->AddAnchor(IDCANCEL, TOP_RIGHT);
117 this->AddAnchor(IDC_STATIC_GROUP_REF, TOP_LEFT, BOTTOM_RIGHT);
118 this->AddAnchor(IDC_STATIC_FILTER, BOTTOM_LEFT);
119 this->AddAnchor(IDC_EDIT_FILTER, BOTTOM_LEFT, BOTTOM_RIGHT);
120 this->AddAnchor(IDC_LIST_REF, TOP_LEFT, BOTTOM_RIGHT);
121 this->AddOthersToAnchor();
123 EnableSaveRestore(_T("FindDlg"));
125 CImageList *imagelist = new CImageList();
126 imagelist->Create(IDB_BITMAP_REFTYPE,16,3,RGB(255,255,255));
127 this->m_ctrlRefList.SetImageList(imagelist,LVSIL_SMALL);
129 CRect rect;
130 m_ctrlRefList.GetClientRect(&rect);
132 this->m_ctrlRefList.InsertColumn(0,_T("Ref"),0, rect.Width()-50);
133 g_Git.GetRefList(m_RefList);
134 AddToList();
135 return FALSE;
138 void CFindDlg::OnCbnEditchangeFindcombo()
140 UpdateData();
141 GetDlgItem(IDOK)->EnableWindow(!m_FindCombo.GetString().IsEmpty());
144 void CFindDlg::AddToList()
146 this->m_ctrlRefList.DeleteAllItems();
147 CString filter;
148 this->m_ctrlFilter.GetWindowText(filter);
150 int item =0;
151 for(int i=0;i< m_RefList.size();i++)
153 int nImage = -1;
154 CString ref = m_RefList[i];
155 if(ref.Find(_T("refs/tags")) == 0)
156 nImage = 0;
157 else if(ref.Find(_T("refs/remotes"))==0)
158 nImage = 2;
159 else if(ref.Find(_T("refs/heads"))== 0)
160 nImage = 1;
162 if(ref.Find(filter)>=0)
163 m_ctrlRefList.InsertItem(item++,ref,nImage);
167 void CFindDlg::OnNMClickListRef(NMHDR *pNMHDR, LRESULT *pResult)
169 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
171 this->m_FindString = this->m_ctrlRefList.GetItemText(pNMItemActivate->iItem,0);
172 this->m_bIsRef =true;
174 CWnd *parent = m_pParent;
175 if(parent == NULL)
176 parent = GetParent();
178 if (parent)
179 parent->SendMessage(m_FindMsg);
181 this->m_bIsRef =false;
183 *pResult = 0;
186 void CFindDlg::OnEnChangeEditFilter()
188 SetTimer(IDT_FILTER, 1000, NULL);
191 void CFindDlg::OnTimer(UINT_PTR nIDEvent)
193 if( nIDEvent == IDT_FILTER)
195 KillTimer(IDT_FILTER);
196 this->AddToList();
199 CResizableStandAloneDialog::OnTimer(nIDEvent);