Fix typos
[TortoiseGit.git] / src / TortoiseGitBlame / PropertiesWnd.cpp
blob7f6379e171b7923395b8881dc666387b4fd79c93
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.
22 #include "stdafx.h"
24 #include "PropertiesWnd.h"
25 #include "Resource.h"
26 #include "MainFrm.h"
27 #include "TortoiseGitBlame.h"
28 #include "IconMenu.h"
29 #include "StringUtils.h"
30 #include "Theme.h"
32 #ifdef _DEBUG
33 #undef THIS_FILE
34 static char THIS_FILE[]=__FILE__;
35 #define new DEBUG_NEW
36 #endif
38 /////////////////////////////////////////////////////////////////////////////
39 // CResourceViewBar
41 CPropertiesWnd::CPropertiesWnd()
45 CPropertiesWnd::~CPropertiesWnd()
49 BEGIN_MESSAGE_MAP(CPropertiesWnd, CDockablePane)
50 ON_WM_CREATE()
51 ON_WM_SIZE()
52 ON_WM_SETFOCUS()
53 ON_WM_SETTINGCHANGE()
54 ON_WM_CONTEXTMENU()
55 END_MESSAGE_MAP()
57 /////////////////////////////////////////////////////////////////////////////
58 // CResourceViewBar message handlers
60 void CPropertiesWnd::AdjustLayout()
62 if (!GetSafeHwnd())
64 return;
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)
76 return -1;
78 CRect rectDummy;
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
87 InitPropList();
89 AdjustLayout();
91 m_themeCallbackId = CTheme::Instance().RegisterThemeChangeCallback(
92 [this]() {
93 SetTheme(CTheme::Instance().IsDarkTheme());
94 });
95 SetTheme(CTheme::Instance().IsDarkTheme());
96 return 0;
99 void CPropertiesWnd::SetTheme(bool bDark)
101 if (bDark)
102 m_wndPropList.SetCustomColors(CTheme::darkBkColor, CTheme::darkTextColor, RGB(83, 83, 83), CTheme::darkTextColor, CTheme::darkBkColor, CTheme::darkTextColor, static_cast<COLORREF>(-1));
103 else
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);
110 AdjustLayout();
113 void CPropertiesWnd::InitPropList()
115 SetPropListFont();
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)),
127 L"",
128 CString(MAKEINTRESOURCE(IDS_LOG_HASH))
130 pGroup1->AddSubItem(m_CommitHash);
132 m_AuthorName = new CMFCPropertyGridProperty(
133 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR)),
134 L"",
135 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR))
137 pGroup1->AddSubItem(m_AuthorName);
139 m_AuthorDate = new CMFCPropertyGridProperty(
140 CString(MAKEINTRESOURCE(IDS_LOG_DATE)),
141 L"",
142 CString(MAKEINTRESOURCE(IDS_LOG_DATE))
144 pGroup1->AddSubItem(m_AuthorDate);
146 m_AuthorEmail= new CMFCPropertyGridProperty(
147 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL)),
148 L"",
149 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL))
151 pGroup1->AddSubItem(m_AuthorEmail);
153 m_CommitterName = new CMFCPropertyGridProperty(
154 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_NAME)),
155 L"",
156 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_NAME))
158 pGroup1->AddSubItem(m_CommitterName);
160 m_CommitterEmail =new CMFCPropertyGridProperty(
161 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_EMAIL)),
162 L"",
163 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_EMAIL))
165 pGroup1->AddSubItem(m_CommitterEmail);
167 m_CommitterDate = new CMFCPropertyGridProperty(
168 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_DATE)),
169 L"",
170 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_DATE))
172 pGroup1->AddSubItem(m_CommitterDate);
174 m_Subject = new CMFCPropertyGridProperty(
175 CString(MAKEINTRESOURCE(IDS_SUBJECT)),
176 L"",
177 CString(MAKEINTRESOURCE(IDS_SUBJECT))
178 );;;
179 pGroup1->AddSubItem(m_Subject);
181 m_Body = new CMFCPropertyGridProperty(
182 CString(MAKEINTRESOURCE(IDS_BODY)),
183 L"",
184 CString(MAKEINTRESOURCE(IDS_BODY))
185 );;;;
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);
208 SetPropListFont();
211 void CPropertiesWnd::SetPropListFont()
213 ::DeleteObject(m_fntPropList.Detach());
215 LOGFONT lf;
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)
244 if (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());
266 RemoveParent();
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)
273 CString str;
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());
290 else
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"");
304 RemoveParent();
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;
317 CIconMenu popup;
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);
324 switch (cmd)
326 case 0:
327 break; // no command selected
328 case WM_COPY:
329 CStringUtils::WriteAsciiStringToClipboard(pProperty->GetValue(), GetSafeHwnd());
330 break;