1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2015-2016, 2018-2020, 2023 - TortoiseGit
4 // Copyright (C) 2011-2013, 2023 Sven Strickroth <email@cs-ware.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "PropertiesWnd.h"
27 #include "TortoiseGitBlame.h"
29 #include "StringUtils.h"
34 static char THIS_FILE
[]=__FILE__
;
38 /////////////////////////////////////////////////////////////////////////////
41 CPropertiesWnd::CPropertiesWnd()
45 CPropertiesWnd::~CPropertiesWnd()
49 BEGIN_MESSAGE_MAP(CPropertiesWnd
, CDockablePane
)
57 /////////////////////////////////////////////////////////////////////////////
58 // CResourceViewBar message handlers
60 void CPropertiesWnd::AdjustLayout()
67 CRect rectClient
,rectCombo
;
68 GetClientRect(rectClient
);
70 m_wndPropList
.SetWindowPos(nullptr, rectClient
.left
, rectClient
.top
, rectClient
.Width(), rectClient
.Height(), SWP_NOACTIVATE
| SWP_NOZORDER
);
73 int CPropertiesWnd::OnCreate(LPCREATESTRUCT lpCreateStruct
)
75 if (CDockablePane::OnCreate(lpCreateStruct
) == -1)
79 rectDummy
.SetRectEmpty();
81 if (!m_wndPropList
.Create(WS_VISIBLE
| WS_CHILD
, rectDummy
, this, 2))
83 TRACE0("Failed to create Properties Grid \n");
84 return -1; // fail to create
91 m_themeCallbackId
= CTheme::Instance().RegisterThemeChangeCallback(
93 SetTheme(CTheme::Instance().IsDarkTheme());
95 SetTheme(CTheme::Instance().IsDarkTheme());
99 void CPropertiesWnd::SetTheme(bool bDark
)
102 m_wndPropList
.SetCustomColors(CTheme::darkBkColor
, CTheme::darkTextColor
, RGB(83, 83, 83), CTheme::darkTextColor
, CTheme::darkBkColor
, CTheme::darkTextColor
, static_cast<COLORREF
>(-1));
104 m_wndPropList
.SetCustomColors(static_cast<COLORREF
>(-1), static_cast<COLORREF
>(-1), static_cast<COLORREF
>(-1), static_cast<COLORREF
>(-1), static_cast<COLORREF
>(-1), static_cast<COLORREF
>(-1), static_cast<COLORREF
>(-1));
107 void CPropertiesWnd::OnSize(UINT nType
, int cx
, int cy
)
109 CDockablePane::OnSize(nType
, cx
, cy
);
113 void CPropertiesWnd::InitPropList()
117 m_wndPropList
.EnableHeaderCtrl(FALSE
);
118 m_wndPropList
.EnableDescriptionArea();
119 m_wndPropList
.SetVSDotNetLook();
120 m_wndPropList
.MarkModifiedProperties();
122 CMFCPropertyGridProperty
* pGroup1
= new CMFCPropertyGridProperty(CString(MAKEINTRESOURCE(IDS_PROPERTIES_BASICINFO
)));
125 m_CommitHash
= new CMFCPropertyGridProperty(
126 CString(MAKEINTRESOURCE(IDS_LOG_HASH
)),
128 CString(MAKEINTRESOURCE(IDS_LOG_HASH
))
130 pGroup1
->AddSubItem(m_CommitHash
);
132 m_AuthorName
= new CMFCPropertyGridProperty(
133 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR
)),
135 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR
))
137 pGroup1
->AddSubItem(m_AuthorName
);
139 m_AuthorDate
= new CMFCPropertyGridProperty(
140 CString(MAKEINTRESOURCE(IDS_LOG_DATE
)),
142 CString(MAKEINTRESOURCE(IDS_LOG_DATE
))
144 pGroup1
->AddSubItem(m_AuthorDate
);
146 m_AuthorEmail
= new CMFCPropertyGridProperty(
147 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL
)),
149 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL
))
151 pGroup1
->AddSubItem(m_AuthorEmail
);
153 m_CommitterName
= new CMFCPropertyGridProperty(
154 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_NAME
)),
156 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_NAME
))
158 pGroup1
->AddSubItem(m_CommitterName
);
160 m_CommitterEmail
=new CMFCPropertyGridProperty(
161 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_EMAIL
)),
163 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_EMAIL
))
165 pGroup1
->AddSubItem(m_CommitterEmail
);
167 m_CommitterDate
= new CMFCPropertyGridProperty(
168 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_DATE
)),
170 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_DATE
))
172 pGroup1
->AddSubItem(m_CommitterDate
);
174 m_Subject
= new CMFCPropertyGridProperty(
175 CString(MAKEINTRESOURCE(IDS_SUBJECT
)),
177 CString(MAKEINTRESOURCE(IDS_SUBJECT
))
179 pGroup1
->AddSubItem(m_Subject
);
181 m_Body
= new CMFCPropertyGridProperty(
182 CString(MAKEINTRESOURCE(IDS_BODY
)),
184 CString(MAKEINTRESOURCE(IDS_BODY
))
186 pGroup1
->AddSubItem(m_Body
);
188 for (int i
= 0; i
< pGroup1
->GetSubItemsCount(); ++i
)
189 pGroup1
->GetSubItem(i
)->AllowEdit(FALSE
);
191 m_wndPropList
.AddProperty(pGroup1
);
192 m_BaseInfoGroup
=pGroup1
;
194 m_ParentGroup
=new CMFCPropertyGridProperty(CString(MAKEINTRESOURCE(IDS_PARENTS
)));
196 m_wndPropList
.AddProperty(m_ParentGroup
);
199 void CPropertiesWnd::OnSetFocus(CWnd
* pOldWnd
)
201 CDockablePane::OnSetFocus(pOldWnd
);
202 m_wndPropList
.SetFocus();
205 void CPropertiesWnd::OnSettingChange(UINT uFlags
, LPCWSTR lpszSection
)
207 CDockablePane::OnSettingChange(uFlags
, lpszSection
);
211 void CPropertiesWnd::SetPropListFont()
213 ::DeleteObject(m_fntPropList
.Detach());
216 afxGlobalData
.fontRegular
.GetLogFont(&lf
);
218 NONCLIENTMETRICS info
;
219 info
.cbSize
= sizeof(info
);
221 afxGlobalData
.GetNonClientMetrics(info
);
223 lf
.lfHeight
= info
.lfMenuFont
.lfHeight
;
224 lf
.lfWeight
= info
.lfMenuFont
.lfWeight
;
225 lf
.lfItalic
= info
.lfMenuFont
.lfItalic
;
227 m_fntPropList
.CreateFontIndirect(&lf
);
229 m_wndPropList
.SetFont(&m_fntPropList
);
232 void CPropertiesWnd::RemoveParent()
234 m_ParentGroup
->Expand(FALSE
);
235 while (m_ParentGroup
->GetSubItemsCount())
237 CMFCPropertyGridProperty
* p
=m_ParentGroup
->GetSubItem(0);
238 m_ParentGroup
->RemoveSubItem(p
);
242 void CPropertiesWnd::UpdateProperties(GitRevLoglist
* pRev
)
246 if (pRev
->m_ParentHash
.empty())
248 if (pRev
->GetParentFromHash(pRev
->m_CommitHash
))
249 MessageBox(pRev
->GetLastErr(), L
"TortoiseGit", MB_ICONERROR
);
251 CString hash
= pRev
->m_CommitHash
.ToString();
252 m_CommitHash
->SetValue(hash
);
253 m_AuthorName
->SetValue(pRev
->GetAuthorName());
254 CString authorDate
= pRev
->GetAuthorDate().Format(L
"%Y-%m-%d %H:%M");
255 m_AuthorDate
->SetValue(authorDate
);
256 m_AuthorEmail
->SetValue(pRev
->GetAuthorEmail());
258 m_CommitterName
->SetValue(pRev
->GetCommitterName());
259 m_CommitterEmail
->SetValue(pRev
->GetCommitterEmail());
260 CString committerDate
= pRev
->GetCommitterDate().Format(L
"%Y-%m-%d %H:%M");
261 m_CommitterDate
->SetValue(committerDate
);
263 m_Subject
->SetValue(pRev
->GetSubject());
264 m_Body
->SetValue(pRev
->GetBody().Trim());
268 CLogDataVector
* pLogEntry
= &static_cast<CMainFrame
*>(AfxGetApp()->GetMainWnd())->m_wndOutput
.m_LogList
.m_logEntries
;
270 CGitHashMap
& hashMap
= pLogEntry
->m_pLogCache
->m_HashMap
;
271 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
274 CString parentsubject
;
276 auto it
= hashMap
.find(pRev
->m_ParentHash
[i
]);
277 if (it
!= hashMap
.end())
278 parentsubject
= it
->second
.GetSubject();
280 str
.Format(L
"%u - %s\n%s", i
, static_cast<LPCWSTR
>(pRev
->m_ParentHash
[i
].ToString()), static_cast<LPCWSTR
>(parentsubject
));
282 auto pProperty
= new CMFCPropertyGridProperty(pRev
->m_ParentHash
[i
].ToString(g_Git
.GetShortHASHLength()), parentsubject
, str
);
283 pProperty
->AllowEdit(FALSE
);
284 m_ParentGroup
->AddSubItem(pProperty
);
286 m_ParentGroup
->Expand();
287 for (int i
= 0; i
< m_BaseInfoGroup
->GetSubItemsCount(); ++i
)
288 m_BaseInfoGroup
->GetSubItem(i
)->SetDescription(m_BaseInfoGroup
->GetSubItem(i
)->GetValue());
292 m_CommitHash
->SetValue(L
"");
293 m_AuthorName
->SetValue(L
"");
294 m_AuthorDate
->SetValue(L
"");
295 m_AuthorEmail
->SetValue(L
"");
297 m_CommitterName
->SetValue(L
"");
298 m_CommitterEmail
->SetValue(L
"");
299 m_CommitterDate
->SetValue(L
"");
301 m_Subject
->SetValue(L
"");
302 m_Body
->SetValue(L
"");
306 for (int i
= 0; i
< m_BaseInfoGroup
->GetSubItemsCount(); ++i
)
307 m_BaseInfoGroup
->GetSubItem(i
)->SetDescription(L
"");
309 m_wndPropList
.AdjustLayout();
312 void CPropertiesWnd::OnContextMenu(CWnd
* /*pWnd*/, CPoint point
)
314 CMFCPropertyGridProperty
* pProperty
= m_wndPropList
.GetCurSel();
316 CString sMenuItemText
;
318 if (pProperty
&& !pProperty
->IsGroup() && popup
.CreatePopupMenu())
320 sMenuItemText
.LoadString(IDS_SCIEDIT_COPY
);
321 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, WM_COPY
, sMenuItemText
);
323 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this);
327 break; // no command selected
329 CStringUtils::WriteAsciiStringToClipboard(pProperty
->GetValue(), GetSafeHwnd());