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
24 #include "RefLogDlg.h"
27 #include "MessageBox.h"
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
)
58 LRESULT
CRefLogDlg::OnRefLogChanged(WPARAM wParam
, LPARAM lParam
)
60 UNREFERENCED_PARAMETER(wParam
);
61 UNREFERENCED_PARAMETER(lParam
);
62 m_RefList
.m_RefMap
.clear();
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
);
79 this->EnableSaveRestore(_T("RefLogDlg"));
82 GetWindowText(sWindowTitle
);
83 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
85 m_ChooseRef
.SetMaxHistoryItems(0x7FFFFFFF);
87 m_RefList
.m_hasWC
= !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
);
89 this->m_RefList
.InsertRefLogColumn();
95 // CRefLogDlg message handlers
97 void CRefLogDlg::OnBnClickedOk()
99 if (m_RefList
.GetSelectedCount() == 1)
101 // get the selected row
102 POSITION pos
= m_RefList
.GetFirstSelectedItemPosition();
103 int selIndex
= m_RefList
.GetNextSelectedItem(pos
);
104 if (selIndex
< m_RefList
.m_arShownList
.GetCount())
106 // all ok, pick up the revision
107 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_RefList
.m_arShownList
.GetAt(selIndex
));
109 m_SelectedHash
= pLogEntry
->m_CommitHash
;
115 void CRefLogDlg::OnBnClickedClearStash()
117 if (CMessageBox::Show(this->GetSafeHwnd(), IDS_PROC_DELETEALLSTASH
, IDS_APPNAME
, 2, IDI_QUESTION
, IDS_DELETEBUTTON
, IDS_ABORTBUTTON
) == 1)
120 if (g_Git
.Run(_T("git.exe stash clear"), &cmdOut
, CP_UTF8
))
122 MessageBox(cmdOut
, _T("TortoiseGit"), MB_ICONERROR
);
126 m_RefList
.m_RefMap
.clear();
132 void CRefLogDlg::OnCbnSelchangeRef()
134 CString ref
=m_ChooseRef
.GetString();
135 if(m_RefList
.m_RefMap
.find(ref
) == m_RefList
.m_RefMap
.end())
137 m_RefList
.m_RefMap
[ref
].m_pLogCache
= &m_RefList
.m_LogCache
;
138 m_RefList
.m_RefMap
[ref
].ParserFromRefLog(ref
);
140 m_RefList
.ClearText();
142 //this->m_logEntries.ParserFromLog();
143 m_RefList
.SetRedraw(false);
145 CLogDataVector
*plog
;
146 plog
= &m_RefList
.m_RefMap
[ref
];
148 m_RefList
.SetItemCountEx(plog
->size());
150 this->m_RefList
.m_arShownList
.RemoveAll();
152 for(unsigned int i
=0;i
<m_RefList
.m_RefMap
[ref
].size();i
++)
154 plog
->GetGitRevAt(i
).m_IsFull
=TRUE
;
155 this->m_RefList
.m_arShownList
.Add(&(plog
->GetGitRevAt(i
)));
159 m_RefList
.SetRedraw(true);
161 m_RefList
.Invalidate();
163 if (ref
== _T("refs/stash"))
165 GetDlgItem(IDC_REFLOG_BUTTONCLEARSTASH
)->ShowWindow(SW_SHOW
);
166 GetDlgItem(IDC_REFLOG_BUTTONCLEARSTASH
)->EnableWindow((m_RefList
.m_arShownList
.GetSize() > 0));
169 GetDlgItem(IDC_REFLOG_BUTTONCLEARSTASH
)->ShowWindow(SW_HIDE
);
172 BOOL
CRefLogDlg::PreTranslateMessage(MSG
* pMsg
)
174 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== VK_F5
)
177 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
180 void CRefLogDlg::Refresh()
183 list
.push_back(_T("HEAD"));
184 g_Git
.GetRefList(list
);
186 m_ChooseRef
.AddString(list
);
188 if (m_CurrentBranch
.IsEmpty())
190 m_CurrentBranch
.Format(_T("refs/heads/%s"), g_Git
.GetCurrentBranch());
191 m_ChooseRef
.SetCurSel(0); /* Choose HEAD */
196 for (int i
= 0; i
< list
.size(); i
++)
198 if(list
[i
] == m_CurrentBranch
)
200 m_ChooseRef
.SetCurSel(i
);
206 m_ChooseRef
.SetCurSel(0);
209 m_RefList
.m_RefMap
.clear();