Fixed issue #3304: Double click on stash list item does nothing, show log instead
[TortoiseGit.git] / src / TortoiseProc / refloglist.cpp
blob812de6969c5e1312c6d77db2d3d8dba545fb2853
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2011, 2013, 2015-2018 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 #include "stdafx.h"
20 #include "resource.h"
21 #include "refloglist.h"
22 #include "LoglistUtils.h"
23 #include "AppUtils.h"
25 IMPLEMENT_DYNAMIC(CRefLogList, CGitLogList)
27 CRefLogList::CRefLogList()
29 m_ColumnRegKey = L"reflog";
30 this->m_ContextMenuMask |= this->GetContextMenuBit(ID_LOG);
31 this->m_ContextMenuMask &= ~GetContextMenuBit(ID_COMPARETWOCOMMITCHANGES);
34 void CRefLogList::InsertRefLogColumn()
36 CString temp;
38 Init();
39 SetStyle();
41 static UINT normal[] =
43 IDS_HASH,
44 IDS_REF,
45 IDS_ACTION,
46 IDS_MESSAGE,
47 IDS_STATUSLIST_COLDATE,
50 static int with[] =
52 ICONITEMBORDER+16*4,
53 ICONITEMBORDER+16*4,
54 ICONITEMBORDER+16*4,
55 LOGLIST_MESSAGE_MIN,
56 ICONITEMBORDER+16*4,
58 m_dwDefaultColumns = 0xFFFF;
60 SetRedraw(false);
62 m_ColumnManager.SetNames(normal, _countof(normal));
63 m_ColumnManager.ReadSettings(m_dwDefaultColumns, 0, m_ColumnRegKey + L"loglist", _countof(normal), with);
65 SetRedraw(true);
68 void CRefLogList::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
70 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
72 // Create a pointer to the item
73 LV_ITEM* pItem = &(pDispInfo)->item;
75 // Do the list need text information?
76 if (!(pItem->mask & LVIF_TEXT))
77 return;
79 // By default, clear text buffer.
80 lstrcpyn(pItem->pszText, L"", pItem->cchTextMax);
82 bool bOutOfRange = pItem->iItem >= (int)m_arShownList.size();
84 *pResult = 0;
85 if (m_bNoDispUpdates || bOutOfRange)
86 return;
88 // Which item number?
89 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(pItem->iItem);
91 CString temp;
93 // Which column?
94 switch (pItem->iSubItem)
96 case REFLOG_HASH:
97 if (pLogEntry)
99 lstrcpyn(pItem->pszText,pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax - 1);
101 break;
102 case REFLOG_REF:
103 if(pLogEntry)
104 lstrcpyn(pItem->pszText, pLogEntry->m_Ref, pItem->cchTextMax - 1);
105 break;
106 case REFLOG_ACTION:
107 if (pLogEntry)
108 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_RefAction, pItem->cchTextMax - 1);
109 break;
110 case REFLOG_MESSAGE:
111 if (pLogEntry)
112 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject().Trim(), pItem->cchTextMax - 1);
113 break;
114 case REFLOG_DATE:
115 if (pLogEntry)
116 lstrcpyn(pItem->pszText, (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes), pItem->cchTextMax - 1);
117 break;
119 default:
120 ASSERT(false);
124 void CRefLogList::OnNMDblclkLoglist(NMHDR* /*pNMHDR*/, LRESULT* pResult)
126 // a double click on an entry in the revision list has happened
127 *pResult = 0;
129 POSITION pos = GetFirstSelectedItemPosition();
130 int indexNext = GetNextSelectedItem(pos);
131 if (indexNext < 0)
132 return;
134 auto pSelLogEntry = m_arShownList.SafeGetAt(indexNext);
135 if (!pSelLogEntry)
136 return;
138 CString cmdline;
139 cmdline.Format(L"/command:log /path:\"%s\" /endrev:%s", (LPCTSTR)g_Git.CombinePath(m_Path), (LPCTSTR)pSelLogEntry->m_CommitHash.ToString());
140 CAppUtils::RunTortoiseGitProc(cmdline);
143 void CRefLogList::OnNMCustomdrawLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
145 // Take the default processing unless we set this to something else below.
146 *pResult = CDRF_DODEFAULT;
149 BOOL CRefLogList::OnToolTipText(UINT /*id*/, NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
151 return FALSE;