Fixed issue #1701: Changing commit order in rebase dialog doesn't auto scroll
[TortoiseGit.git] / src / TortoiseProc / FindDlg.cpp
blobde13bc77a80d59bce4e8b184c4a485e354bd962b
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_bIsRef(false)
38 , m_FindMsg(0)
39 , m_regMatchCase(L"Software\\TortoiseGit\\LogDialog\\FindMatchCase", FALSE)
40 , m_regWholeWord(L"Software\\TortoiseGit\\LogDialog\\FindWholeWord", FALSE)
42 m_pParent = pParent;
45 CFindDlg::~CFindDlg()
49 void CFindDlg::DoDataExchange(CDataExchange* pDX)
51 CDialog::DoDataExchange(pDX);
52 DDX_Check(pDX, IDC_MATCHCASE, m_bMatchCase);
53 DDX_Check(pDX, IDC_WHOLEWORD, m_bWholeWord);
54 DDX_Control(pDX, IDC_FINDCOMBO, m_FindCombo);
55 DDX_Control(pDX, IDC_LIST_REF, m_ctrlRefList);
56 DDX_Control(pDX, IDC_EDIT_FILTER, m_ctrlFilter);
60 BEGIN_MESSAGE_MAP(CFindDlg, CResizableStandAloneDialog)
61 ON_CBN_EDITCHANGE(IDC_FINDCOMBO, &CFindDlg::OnCbnEditchangeFindcombo)
62 ON_NOTIFY(NM_CLICK, IDC_LIST_REF, &CFindDlg::OnNMClickListRef)
63 ON_EN_CHANGE(IDC_EDIT_FILTER, &CFindDlg::OnEnChangeEditFilter)
64 ON_WM_TIMER()
65 END_MESSAGE_MAP()
68 // CFindDlg message handlers
70 void CFindDlg::OnCancel()
72 m_bTerminating = true;
74 CWnd *parent = m_pParent;
75 if(parent == NULL)
76 parent = GetParent();
78 if (parent)
79 parent->SendMessage(m_FindMsg);
81 DestroyWindow();
84 void CFindDlg::PostNcDestroy()
86 delete this;
89 void CFindDlg::OnOK()
91 UpdateData();
92 m_FindCombo.SaveHistory();
94 m_regMatchCase = m_bMatchCase;
95 m_regWholeWord = m_bWholeWord;
97 if (m_FindCombo.GetString().IsEmpty())
98 return;
99 m_bFindNext = true;
100 m_FindString = m_FindCombo.GetString();
102 CWnd *parent = m_pParent;
103 if(parent == NULL)
104 parent = GetParent();
106 if (parent)
107 parent->SendMessage(m_FindMsg);
108 m_bFindNext = false;
111 BOOL CFindDlg::OnInitDialog()
113 CDialog::OnInitDialog();
114 m_FindMsg = RegisterWindowMessage(FINDMSGSTRING);
116 m_bMatchCase = (BOOL)(DWORD)m_regMatchCase;
117 m_bWholeWord = (BOOL)(DWORD)m_regWholeWord;
118 UpdateData(FALSE);
120 m_FindCombo.LoadHistory(_T("Software\\TortoiseGit\\History\\Find"), _T("Search"));
121 m_FindCombo.SetCurSel(0);
122 m_FindCombo.SetFocus();
124 this->AddAnchor(IDC_STATIC_FIND, TOP_LEFT, TOP_RIGHT);
125 this->AddAnchor(IDC_FINDCOMBO, TOP_LEFT, TOP_RIGHT);
126 this->AddAnchor(IDOK, TOP_RIGHT);
127 this->AddAnchor(IDCANCEL, TOP_RIGHT);
128 this->AddAnchor(IDC_STATIC_GROUP_REF, TOP_LEFT, BOTTOM_RIGHT);
129 this->AddAnchor(IDC_STATIC_FILTER, BOTTOM_LEFT);
130 this->AddAnchor(IDC_EDIT_FILTER, BOTTOM_LEFT, BOTTOM_RIGHT);
131 this->AddAnchor(IDC_LIST_REF, TOP_LEFT, BOTTOM_RIGHT);
132 this->AddOthersToAnchor();
134 EnableSaveRestore(_T("FindDlg"));
136 CImageList *imagelist = new CImageList();
137 imagelist->Create(IDB_BITMAP_REFTYPE,16,3,RGB(255,255,255));
138 this->m_ctrlRefList.SetImageList(imagelist,LVSIL_SMALL);
140 CRect rect;
141 m_ctrlRefList.GetClientRect(&rect);
143 this->m_ctrlRefList.InsertColumn(0,_T("Ref"),0, rect.Width()-50);
144 if (g_Git.GetRefList(m_RefList))
145 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
146 AddToList();
147 return FALSE;
150 void CFindDlg::OnCbnEditchangeFindcombo()
152 UpdateData();
153 GetDlgItem(IDOK)->EnableWindow(!m_FindCombo.GetString().IsEmpty());
156 void CFindDlg::AddToList()
158 this->m_ctrlRefList.DeleteAllItems();
159 CString filter;
160 this->m_ctrlFilter.GetWindowText(filter);
162 int item =0;
163 for (size_t i = 0; i < m_RefList.size(); ++i)
165 int nImage = -1;
166 CString ref = m_RefList[i];
167 if(ref.Find(_T("refs/tags")) == 0)
168 nImage = 0;
169 else if(ref.Find(_T("refs/remotes"))==0)
170 nImage = 2;
171 else if(ref.Find(_T("refs/heads"))== 0)
172 nImage = 1;
174 if(ref.Find(filter)>=0)
175 m_ctrlRefList.InsertItem(item++,ref,nImage);
179 void CFindDlg::OnNMClickListRef(NMHDR *pNMHDR, LRESULT *pResult)
181 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
183 this->m_FindString = this->m_ctrlRefList.GetItemText(pNMItemActivate->iItem,0);
184 this->m_bIsRef =true;
186 CWnd *parent = m_pParent;
187 if(parent == NULL)
188 parent = GetParent();
190 if (parent)
191 parent->SendMessage(m_FindMsg);
193 this->m_bIsRef =false;
195 *pResult = 0;
198 void CFindDlg::OnEnChangeEditFilter()
200 SetTimer(IDT_FILTER, 1000, NULL);
203 void CFindDlg::OnTimer(UINT_PTR nIDEvent)
205 if( nIDEvent == IDT_FILTER)
207 KillTimer(IDT_FILTER);
208 this->AddToList();
211 CResizableStandAloneDialog::OnTimer(nIDEvent);