Fixed issue #4126: Capitalize the first letter in the Push dialog
[TortoiseGit.git] / src / TortoiseProc / refloglist.cpp
blobdb9f5502515dd3dd2d9caa1164396de11af929d3
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2011, 2013, 2015-2020, 2023 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"
24 #include "DPIAware.h"
26 IMPLEMENT_DYNAMIC(CRefLogList, CGitLogList)
28 CRefLogList::CRefLogList()
30 m_ColumnRegKey = L"reflog";
31 this->m_ContextMenuMask |= this->GetContextMenuBit(ID_LOG);
32 this->m_ContextMenuMask &= ~GetContextMenuBit(ID_COMPARETWOCOMMITCHANGES);
35 void CRefLogList::InsertRefLogColumn()
37 CString temp;
39 Init();
40 SetStyle();
42 static UINT normal[] =
44 IDS_HASH,
45 IDS_REF,
46 IDS_ACTION,
47 IDS_MESSAGE,
48 IDS_STATUSLIST_COLDATE,
51 auto columnWidth = CDPIAware::Instance().ScaleX(GetSafeHwnd(), ICONITEMBORDER + 16 * 4);
52 static int with[] =
54 columnWidth,
55 columnWidth,
56 columnWidth,
57 CDPIAware::Instance().ScaleX(GetSafeHwnd(), LOGLIST_MESSAGE_MIN),
58 columnWidth,
60 m_dwDefaultColumns = 0xFFFF;
62 SetRedraw(false);
64 m_ColumnManager.SetNames(normal, _countof(normal));
65 constexpr int columnVersion = 6; // adjust when changing number/names/etc. of columns
66 m_ColumnManager.ReadSettings(m_dwDefaultColumns, 0, m_ColumnRegKey + L"loglist", columnVersion, _countof(normal), with);
68 SetRedraw(true);
71 void CRefLogList::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
73 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
75 // Create a pointer to the item
76 LV_ITEM* pItem = &(pDispInfo)->item;
78 // Do the list need text information?
79 if (!(pItem->mask & LVIF_TEXT))
80 return;
82 // By default, clear text buffer.
83 lstrcpyn(pItem->pszText, L"", pItem->cchTextMax);
85 bool bOutOfRange = pItem->iItem >= static_cast<int>(m_arShownList.size());
87 *pResult = 0;
88 if (m_bNoDispUpdates || bOutOfRange)
89 return;
91 // Which item number?
92 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(pItem->iItem);
94 CString temp;
96 // Which column?
97 switch (pItem->iSubItem)
99 case REFLOG_HASH:
100 if (pLogEntry)
102 lstrcpyn(pItem->pszText,pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax - 1);
104 break;
105 case REFLOG_REF:
106 if(pLogEntry)
107 lstrcpyn(pItem->pszText, pLogEntry->m_Ref, pItem->cchTextMax - 1);
108 break;
109 case REFLOG_ACTION:
110 if (pLogEntry)
111 lstrcpyn(pItem->pszText, static_cast<LPCWSTR>(pLogEntry->m_RefAction), pItem->cchTextMax - 1);
112 break;
113 case REFLOG_MESSAGE:
114 if (pLogEntry)
115 lstrcpyn(pItem->pszText, static_cast<LPCWSTR>(pLogEntry->GetSubject().Trim()), pItem->cchTextMax - 1);
116 break;
117 case REFLOG_DATE:
118 if (pLogEntry)
119 lstrcpyn(pItem->pszText, static_cast<LPCWSTR>(CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes)), pItem->cchTextMax - 1);
120 break;
122 default:
123 ASSERT(false);
127 void CRefLogList::OnNMDblclkLoglist(NMHDR* /*pNMHDR*/, LRESULT* pResult)
129 // a double click on an entry in the revision list has happened
130 *pResult = 0;
132 POSITION pos = GetFirstSelectedItemPosition();
133 const int indexNext = GetNextSelectedItem(pos);
134 if (indexNext < 0)
135 return;
137 auto pSelLogEntry = m_arShownList.SafeGetAt(indexNext);
138 if (!pSelLogEntry)
139 return;
141 CString cmdline;
142 cmdline.Format(L"/command:log /path:\"%s\" /endrev:%s", static_cast<LPCWSTR>(g_Git.CombinePath(m_Path)), static_cast<LPCWSTR>(pSelLogEntry->m_CommitHash.ToString()));
143 CAppUtils::RunTortoiseGitProc(cmdline);
146 void CRefLogList::OnNMCustomdrawLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
148 // Take the default processing unless we set this to something else below.
149 *pResult = CDRF_DODEFAULT;
152 BOOL CRefLogList::OnToolTipText(UINT /*id*/, NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
154 return FALSE;
157 void CRefLogList::CopySelectionToClipBoard(int toCopy)
159 CString sClipdata;
160 POSITION pos = GetFirstSelectedItemPosition();
161 if (pos)
163 CString sRev;
164 sRev.LoadString(IDS_LOG_REVISION);
165 CString sDate;
166 sDate.LoadString(IDS_LOG_DATE);
167 CString sMessage;
168 sMessage.LoadString(IDS_LOG_MESSAGE);
169 bool first = true;
170 while (pos)
172 auto pLogEntry = m_arShownList.SafeGetAt(GetNextSelectedItem(pos));
174 if (toCopy == ID_COPYCLIPBOARDFULL)
176 sClipdata.AppendFormat(L"%s: %s\r\n%s: %s\r\n%s: %s%s%s\r\n",
177 static_cast<LPCWSTR>(sRev), static_cast<LPCWSTR>(pLogEntry->m_CommitHash.ToString()),
178 static_cast<LPCWSTR>(sDate), static_cast<LPCWSTR>(CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes)),
179 static_cast<LPCWSTR>(sMessage), static_cast<LPCWSTR>(pLogEntry->m_RefAction), pLogEntry->m_RefAction.IsEmpty() ? L"" : L": ", static_cast<LPCWSTR>(pLogEntry->GetSubjectBody(true)));
181 else if (toCopy == ID_COPYCLIPBOARDMESSAGES)
183 sClipdata += L"* ";
184 if (!pLogEntry->m_RefAction.IsEmpty())
186 sClipdata += pLogEntry->m_RefAction;
187 sClipdata += L": ";
189 sClipdata += pLogEntry->GetSubjectBody(true);
190 sClipdata += L"\r\n\r\n";
192 else
194 if (!first)
195 sClipdata += L"\r\n";
196 sClipdata += pLogEntry->m_CommitHash.ToString();
199 first = false;
201 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());