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.
21 #include "refloglist.h"
22 #include "LoglistUtils.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()
42 static UINT normal
[] =
48 IDS_STATUSLIST_COLDATE
,
51 auto columnWidth
= CDPIAware::Instance().ScaleX(GetSafeHwnd(), ICONITEMBORDER
+ 16 * 4);
57 CDPIAware::Instance().ScaleX(GetSafeHwnd(), LOGLIST_MESSAGE_MIN
),
60 m_dwDefaultColumns
= 0xFFFF;
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
);
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
))
82 // By default, clear text buffer.
83 lstrcpyn(pItem
->pszText
, L
"", pItem
->cchTextMax
);
85 bool bOutOfRange
= pItem
->iItem
>= static_cast<int>(m_arShownList
.size());
88 if (m_bNoDispUpdates
|| bOutOfRange
)
92 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(pItem
->iItem
);
97 switch (pItem
->iSubItem
)
102 lstrcpyn(pItem
->pszText
,pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
- 1);
107 lstrcpyn(pItem
->pszText
, pLogEntry
->m_Ref
, pItem
->cchTextMax
- 1);
111 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(pLogEntry
->m_RefAction
), pItem
->cchTextMax
- 1);
115 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(pLogEntry
->GetSubject().Trim()), pItem
->cchTextMax
- 1);
119 lstrcpyn(pItem
->pszText
, static_cast<LPCWSTR
>(CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
)), pItem
->cchTextMax
- 1);
127 void CRefLogList::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
* pResult
)
129 // a double click on an entry in the revision list has happened
132 POSITION pos
= GetFirstSelectedItemPosition();
133 const int indexNext
= GetNextSelectedItem(pos
);
137 auto pSelLogEntry
= m_arShownList
.SafeGetAt(indexNext
);
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*/)
157 void CRefLogList::CopySelectionToClipBoard(int toCopy
)
160 POSITION pos
= GetFirstSelectedItemPosition();
164 sRev
.LoadString(IDS_LOG_REVISION
);
166 sDate
.LoadString(IDS_LOG_DATE
);
168 sMessage
.LoadString(IDS_LOG_MESSAGE
);
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
)
184 if (!pLogEntry
->m_RefAction
.IsEmpty())
186 sClipdata
+= pLogEntry
->m_RefAction
;
189 sClipdata
+= pLogEntry
->GetSubjectBody(true);
190 sClipdata
+= L
"\r\n\r\n";
195 sClipdata
+= L
"\r\n";
196 sClipdata
+= pLogEntry
->m_CommitHash
.ToString();
201 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());