TortoiseSVN -> TortoiseGit
[TortoiseGit.git] / src / TortoiseProc / RefLogDlg.cpp
blob8c0dace1f24b703b9412bcf58daca260827317a7
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2011 - 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"
28 // CRefLogDlg dialog
30 IMPLEMENT_DYNAMIC(CRefLogDlg, CResizableStandAloneDialog)
32 CRefLogDlg::CRefLogDlg(CWnd* pParent /*=NULL*/)
33 : CResizableStandAloneDialog(CRefLogDlg::IDD, pParent)
38 CRefLogDlg::~CRefLogDlg()
42 void CRefLogDlg::DoDataExchange(CDataExchange* pDX)
44 CDialog::DoDataExchange(pDX);
45 DDX_Control(pDX, IDC_COMBOBOXEX_REF, m_ChooseRef);
46 DDX_Control(pDX, IDC_REFLOG_LIST, m_RefList);
50 BEGIN_MESSAGE_MAP(CRefLogDlg, CResizableStandAloneDialog)
51 ON_BN_CLICKED(IDOK, &CRefLogDlg::OnBnClickedOk)
52 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_REF, &CRefLogDlg::OnCbnSelchangeRef)
53 ON_MESSAGE(MSG_REFLOG_CHANGED,OnRefLogChanged)
54 END_MESSAGE_MAP()
56 LRESULT CRefLogDlg::OnRefLogChanged(WPARAM wParam, LPARAM lParam)
58 UNREFERENCED_PARAMETER(wParam);
59 UNREFERENCED_PARAMETER(lParam);
60 m_RefList.m_RefMap.clear();
61 OnCbnSelchangeRef();
62 return 0;
65 BOOL CRefLogDlg::OnInitDialog()
67 CResizableStandAloneDialog::OnInitDialog();
68 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
70 AddAnchor(IDOK,BOTTOM_RIGHT);
71 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
73 AddAnchor(IDC_REFLOG_LIST,TOP_LEFT,BOTTOM_RIGHT);
74 AddAnchor(IDHELP, BOTTOM_RIGHT);
76 AddOthersToAnchor();
77 this->EnableSaveRestore(_T("RefLogDlg"));
79 STRING_VECTOR list;
80 list.push_back(_T("HEAD"));
81 g_Git.GetRefList(list);
83 m_ChooseRef.SetMaxHistoryItems(0x7FFFFFFF);
84 this->m_ChooseRef.AddString(list);
86 this->m_RefList.InsertRefLogColumn();
87 //m_RefList.m_logEntries.ParserFromRefLog(_T("master"));
88 if(this->m_CurrentBranch.IsEmpty())
90 m_CurrentBranch.Format(_T("refs/heads/%s"),g_Git.GetCurrentBranch());
91 m_ChooseRef.SetCurSel(0); /* Choose HEAD */
92 }else
94 for(int i=0;i<list.size();i++)
96 if(list[i] == m_CurrentBranch)
98 m_ChooseRef.SetCurSel(i);
99 break;
105 OnCbnSelchangeRef();
107 return TRUE;
109 // CRefLogDlg message handlers
111 void CRefLogDlg::OnBnClickedOk()
113 if (m_RefList.GetSelectedCount() == 1)
115 // get the selected row
116 POSITION pos = m_RefList.GetFirstSelectedItemPosition();
117 int selIndex = m_RefList.GetNextSelectedItem(pos);
118 if (selIndex < m_RefList.m_arShownList.GetCount())
120 // all ok, pick up the revision
121 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_RefList.m_arShownList.GetAt(selIndex));
122 // extract the hash
123 m_SelectedHash = pLogEntry->m_CommitHash;
127 OnOK();
130 void CRefLogDlg::OnCbnSelchangeRef()
132 CString ref=m_ChooseRef.GetString();
133 if(m_RefList.m_RefMap.find(ref) == m_RefList.m_RefMap.end())
135 m_RefList.m_RefMap[ref].m_pLogCache = &m_RefList.m_LogCache;
136 m_RefList.m_RefMap[ref].ParserFromRefLog(ref);
138 m_RefList.ClearText();
140 //this->m_logEntries.ParserFromLog();
141 m_RefList.SetRedraw(false);
143 CLogDataVector *plog;
144 plog = &m_RefList.m_RefMap[ref];
146 m_RefList.SetItemCountEx(plog->size());
148 this->m_RefList.m_arShownList.RemoveAll();
150 for(unsigned int i=0;i<m_RefList.m_RefMap[ref].size();i++)
152 plog->GetGitRevAt(i).m_IsFull=TRUE;
153 this->m_RefList.m_arShownList.Add(&(plog->GetGitRevAt(i)));
157 m_RefList.SetRedraw(true);
159 m_RefList.Invalidate();