Avoid UNREFERENCED_PARAMETER(...)
[TortoiseGit.git] / src / TortoiseProc / RefLogDlg.cpp
blob8553549e75ca5bc6046a7248a5807950d4680be2
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2013 - TortoiseGit
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 // RefLogDlg.cpp : implementation file
22 #include "stdafx.h"
23 #include "resource.h"
24 #include "RefLogDlg.h"
25 #include "git.h"
26 #include "AppUtils.h"
27 #include "MessageBox.h"
29 // CRefLogDlg dialog
31 IMPLEMENT_DYNAMIC(CRefLogDlg, CResizableStandAloneDialog)
33 UINT CRefLogDlg::m_FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
35 CRefLogDlg::CRefLogDlg(CWnd* pParent /*=NULL*/)
36 : CResizableStandAloneDialog(CRefLogDlg::IDD, pParent)
37 , m_pFindDialog(NULL)
42 CRefLogDlg::~CRefLogDlg()
46 void CRefLogDlg::DoDataExchange(CDataExchange* pDX)
48 CDialog::DoDataExchange(pDX);
49 DDX_Control(pDX, IDC_COMBOBOXEX_REF, m_ChooseRef);
50 DDX_Control(pDX, IDC_REFLOG_LIST, m_RefList);
54 BEGIN_MESSAGE_MAP(CRefLogDlg, CResizableStandAloneDialog)
55 ON_BN_CLICKED(IDOK, &CRefLogDlg::OnBnClickedOk)
56 ON_BN_CLICKED(IDC_REFLOG_BUTTONCLEARSTASH, &CRefLogDlg::OnBnClickedClearStash)
57 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_REF, &CRefLogDlg::OnCbnSelchangeRef)
58 ON_MESSAGE(MSG_REFLOG_CHANGED,OnRefLogChanged)
59 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
60 END_MESSAGE_MAP()
62 LRESULT CRefLogDlg::OnRefLogChanged(WPARAM /*wParam*/, LPARAM /*lParam*/)
64 m_RefList.m_RefMap.clear();
65 OnCbnSelchangeRef();
66 return 0;
69 BOOL CRefLogDlg::OnInitDialog()
71 CResizableStandAloneDialog::OnInitDialog();
72 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
74 AddAnchor(IDOK,BOTTOM_RIGHT);
75 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
76 AddAnchor(IDC_REFLOG_BUTTONCLEARSTASH, BOTTOM_LEFT);
77 AddAnchor(IDC_REFLOG_LIST,TOP_LEFT,BOTTOM_RIGHT);
78 AddAnchor(IDHELP, BOTTOM_RIGHT);
79 AddAnchor(IDC_COMBOBOXEX_REF, TOP_LEFT, TOP_RIGHT);
81 AddOthersToAnchor();
82 this->EnableSaveRestore(_T("RefLogDlg"));
84 CString sWindowTitle;
85 GetWindowText(sWindowTitle);
86 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
88 m_ChooseRef.SetMaxHistoryItems(0x7FFFFFFF);
90 m_RefList.m_hasWC = !g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir);
92 this->m_RefList.InsertRefLogColumn();
94 Refresh();
96 return TRUE;
98 // CRefLogDlg message handlers
100 void CRefLogDlg::OnBnClickedOk()
102 if (m_RefList.GetSelectedCount() == 1)
104 // get the selected row
105 POSITION pos = m_RefList.GetFirstSelectedItemPosition();
106 int selIndex = m_RefList.GetNextSelectedItem(pos);
107 if (selIndex < m_RefList.m_arShownList.GetCount())
109 // all ok, pick up the revision
110 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_RefList.m_arShownList.GetAt(selIndex));
111 // extract the hash
112 m_SelectedHash = pLogEntry->m_CommitHash;
116 OnOK();
118 void CRefLogDlg::OnBnClickedClearStash()
120 if (CMessageBox::Show(this->GetSafeHwnd(), IDS_PROC_DELETEALLSTASH, IDS_APPNAME, 2, IDI_QUESTION, IDS_DELETEBUTTON, IDS_ABORTBUTTON) == 1)
122 CString cmdOut;
123 if (g_Git.Run(_T("git.exe stash clear"), &cmdOut, CP_UTF8))
125 MessageBox(cmdOut, _T("TortoiseGit"), MB_ICONERROR);
126 return;
129 m_RefList.m_RefMap.clear();
131 OnCbnSelchangeRef();
135 void CRefLogDlg::OnCbnSelchangeRef()
137 CString ref=m_ChooseRef.GetString();
138 if(m_RefList.m_RefMap.find(ref) == m_RefList.m_RefMap.end())
140 m_RefList.m_RefMap[ref].m_pLogCache = &m_RefList.m_LogCache;
141 m_RefList.m_RefMap[ref].ParserFromRefLog(ref);
143 m_RefList.ClearText();
145 //this->m_logEntries.ParserFromLog();
146 m_RefList.SetRedraw(false);
148 CLogDataVector *plog;
149 plog = &m_RefList.m_RefMap[ref];
151 m_RefList.SetItemCountEx((int)plog->size());
153 this->m_RefList.m_arShownList.RemoveAll();
155 for(unsigned int i=0;i<m_RefList.m_RefMap[ref].size();i++)
157 plog->GetGitRevAt(i).m_IsFull=TRUE;
158 this->m_RefList.m_arShownList.Add(&(plog->GetGitRevAt(i)));
162 m_RefList.SetRedraw(true);
164 m_RefList.Invalidate();
166 if (ref == _T("refs/stash"))
168 GetDlgItem(IDC_REFLOG_BUTTONCLEARSTASH)->ShowWindow(SW_SHOW);
169 GetDlgItem(IDC_REFLOG_BUTTONCLEARSTASH)->EnableWindow((m_RefList.m_arShownList.GetSize() > 0));
171 else
172 GetDlgItem(IDC_REFLOG_BUTTONCLEARSTASH)->ShowWindow(SW_HIDE);
175 BOOL CRefLogDlg::PreTranslateMessage(MSG* pMsg)
177 if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_F5)
178 Refresh();
179 else if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_F3 || (pMsg->wParam == 'F' && (GetAsyncKeyState(VK_CONTROL) & 0x8000))))
180 OnFind();
182 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
185 void CRefLogDlg::Refresh()
187 STRING_VECTOR list;
188 list.push_back(_T("HEAD"));
189 if (g_Git.GetRefList(list))
190 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
192 m_ChooseRef.AddString(list);
194 if (m_CurrentBranch.IsEmpty())
196 m_CurrentBranch.Format(_T("refs/heads/%s"), g_Git.GetCurrentBranch());
197 m_ChooseRef.SetCurSel(0); /* Choose HEAD */
199 else
201 bool found = false;
202 for (int i = 0; i < list.size(); i++)
204 if(list[i] == m_CurrentBranch)
206 m_ChooseRef.SetCurSel(i);
207 found = true;
208 break;
211 if (!found)
212 m_ChooseRef.SetCurSel(0);
215 m_RefList.m_RefMap.clear();
217 OnCbnSelchangeRef();
220 void CRefLogDlg::OnFind()
222 m_nSearchLine = 0;
223 m_pFindDialog = new CFindReplaceDialog();
224 m_pFindDialog->Create(TRUE, _T(""), NULL, FR_DOWN | FR_HIDEWHOLEWORD | FR_HIDEUPDOWN, this);
227 LRESULT CRefLogDlg::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
229 ASSERT(m_pFindDialog != NULL);
231 if (m_RefList.m_arShownList.IsEmpty())
232 return 0;
234 // If the FR_DIALOGTERM flag is set,
235 // invalidate the handle identifying the dialog box.
236 if (m_pFindDialog->IsTerminating())
238 m_pFindDialog = NULL;
239 return 0;
242 // If the FR_FINDNEXT flag is set,
243 // call the application-defined search routine
244 // to search for the requested string.
245 if (m_pFindDialog->FindNext())
247 //read data from dialog
248 CString findString = m_pFindDialog->GetFindString();
250 bool bFound = false;
251 bool bCaseSensitive = !!(m_pFindDialog->m_nFlags & FR_MATCHCASE);
253 if (!bCaseSensitive)
254 findString.MakeLower();
256 int i = m_nSearchLine;
257 if (i < 0 || i >= m_RefList.m_arShownList.GetCount())
258 i = 0;
262 GitRev * data = (GitRev*)m_RefList.m_arShownList.SafeGetAt(i);
264 CString str;
265 str += data->m_Ref;
266 str += _T("\n");
267 str += data->m_RefAction;
268 str += _T("\n");
269 str += data->m_CommitHash.ToString();
270 str += _T("\n");
271 str += data->GetSubject();
272 str += _T("\n");
273 str += data->GetBody();
274 str += _T("\n");
276 if (!bCaseSensitive)
277 str.MakeLower();
279 if (str.Find(findString) >= 0)
280 bFound = true;
282 i++;
283 if(!bFound && i >= m_RefList.m_arShownList.GetCount())
284 i=0;
285 } while (i != m_nSearchLine && (!bFound));
287 if (bFound)
289 m_RefList.SetHotItem(i - 1);
290 m_RefList.EnsureVisible(i - 1, FALSE);
291 m_nSearchLine = i;
293 else
294 MessageBox(_T("\"") + findString + _T("\" ") + CString(MAKEINTRESOURCE(IDS_NOTFOUND)), _T("TortoiseGit"), MB_ICONINFORMATION);
297 return 0;