Fixed issue #1067: Add clear button into "stash list"
[TortoiseGit.git] / src / TortoiseProc / RefLogDlg.cpp
blob4e9426421001b2aa690b5e5e05ac103c608c2194
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2012 - 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 CRefLogDlg::CRefLogDlg(CWnd* pParent /*=NULL*/)
34 : CResizableStandAloneDialog(CRefLogDlg::IDD, pParent)
39 CRefLogDlg::~CRefLogDlg()
43 void CRefLogDlg::DoDataExchange(CDataExchange* pDX)
45 CDialog::DoDataExchange(pDX);
46 DDX_Control(pDX, IDC_COMBOBOXEX_REF, m_ChooseRef);
47 DDX_Control(pDX, IDC_REFLOG_LIST, m_RefList);
51 BEGIN_MESSAGE_MAP(CRefLogDlg, CResizableStandAloneDialog)
52 ON_BN_CLICKED(IDOK, &CRefLogDlg::OnBnClickedOk)
53 ON_BN_CLICKED(IDC_REFLOG_BUTTONCLEARSTASH, &CRefLogDlg::OnBnClickedClearStash)
54 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_REF, &CRefLogDlg::OnCbnSelchangeRef)
55 ON_MESSAGE(MSG_REFLOG_CHANGED,OnRefLogChanged)
56 END_MESSAGE_MAP()
58 LRESULT CRefLogDlg::OnRefLogChanged(WPARAM wParam, LPARAM lParam)
60 UNREFERENCED_PARAMETER(wParam);
61 UNREFERENCED_PARAMETER(lParam);
62 m_RefList.m_RefMap.clear();
63 OnCbnSelchangeRef();
64 return 0;
67 BOOL CRefLogDlg::OnInitDialog()
69 CResizableStandAloneDialog::OnInitDialog();
70 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
72 AddAnchor(IDOK,BOTTOM_RIGHT);
73 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
74 AddAnchor(IDC_REFLOG_BUTTONCLEARSTASH, BOTTOM_LEFT);
75 AddAnchor(IDC_REFLOG_LIST,TOP_LEFT,BOTTOM_RIGHT);
76 AddAnchor(IDHELP, BOTTOM_RIGHT);
78 AddOthersToAnchor();
79 this->EnableSaveRestore(_T("RefLogDlg"));
81 CString sWindowTitle;
82 GetWindowText(sWindowTitle);
83 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
85 STRING_VECTOR list;
86 list.push_back(_T("HEAD"));
87 g_Git.GetRefList(list);
89 m_RefList.m_hasWC = !g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir);
91 m_ChooseRef.SetMaxHistoryItems(0x7FFFFFFF);
92 this->m_ChooseRef.AddString(list);
94 this->m_RefList.InsertRefLogColumn();
95 //m_RefList.m_logEntries.ParserFromRefLog(_T("master"));
96 if(this->m_CurrentBranch.IsEmpty())
98 m_CurrentBranch.Format(_T("refs/heads/%s"),g_Git.GetCurrentBranch());
99 m_ChooseRef.SetCurSel(0); /* Choose HEAD */
101 else
103 for(int i=0;i<list.size();i++)
105 if(list[i] == m_CurrentBranch)
107 m_ChooseRef.SetCurSel(i);
108 break;
114 OnCbnSelchangeRef();
116 return TRUE;
118 // CRefLogDlg message handlers
120 void CRefLogDlg::OnBnClickedOk()
122 if (m_RefList.GetSelectedCount() == 1)
124 // get the selected row
125 POSITION pos = m_RefList.GetFirstSelectedItemPosition();
126 int selIndex = m_RefList.GetNextSelectedItem(pos);
127 if (selIndex < m_RefList.m_arShownList.GetCount())
129 // all ok, pick up the revision
130 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_RefList.m_arShownList.GetAt(selIndex));
131 // extract the hash
132 m_SelectedHash = pLogEntry->m_CommitHash;
136 OnOK();
138 void CRefLogDlg::OnBnClickedClearStash()
140 if (CMessageBox::Show(this->GetSafeHwnd(), IDS_PROC_DELETEALLSTASH, IDS_APPNAME, 2, IDI_QUESTION, IDS_DELETEBUTTON, IDS_ABORTBUTTON) == 1)
142 CString cmdOut;
143 if (g_Git.Run(_T("git.exe stash clear"), &cmdOut, CP_UTF8))
145 MessageBox(cmdOut, _T("TortoiseGit"), MB_ICONERROR);
146 return;
149 m_RefList.m_RefMap.clear();
151 OnCbnSelchangeRef();
155 void CRefLogDlg::OnCbnSelchangeRef()
157 CString ref=m_ChooseRef.GetString();
158 if(m_RefList.m_RefMap.find(ref) == m_RefList.m_RefMap.end())
160 m_RefList.m_RefMap[ref].m_pLogCache = &m_RefList.m_LogCache;
161 m_RefList.m_RefMap[ref].ParserFromRefLog(ref);
163 m_RefList.ClearText();
165 //this->m_logEntries.ParserFromLog();
166 m_RefList.SetRedraw(false);
168 CLogDataVector *plog;
169 plog = &m_RefList.m_RefMap[ref];
171 m_RefList.SetItemCountEx(plog->size());
173 this->m_RefList.m_arShownList.RemoveAll();
175 for(unsigned int i=0;i<m_RefList.m_RefMap[ref].size();i++)
177 plog->GetGitRevAt(i).m_IsFull=TRUE;
178 this->m_RefList.m_arShownList.Add(&(plog->GetGitRevAt(i)));
182 m_RefList.SetRedraw(true);
184 m_RefList.Invalidate();
186 if (ref == _T("refs/stash"))
188 GetDlgItem(IDC_REFLOG_BUTTONCLEARSTASH)->ShowWindow(SW_SHOW);
189 GetDlgItem(IDC_REFLOG_BUTTONCLEARSTASH)->EnableWindow((m_RefList.m_arShownList.GetSize() > 0));
191 else
192 GetDlgItem(IDC_REFLOG_BUTTONCLEARSTASH)->ShowWindow(SW_HIDE);