BrowseRefsDlg: Insert separator into filter context menu
[TortoiseGit.git] / src / TortoiseGitBlame / PropertiesWnd.cpp
blob0710c38cac05a3d1f9d112b1631e33601b9de759
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2015-2016, 2018 - TortoiseGit
4 // Copyright (C) 2011-2013 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"
31 #ifdef _DEBUG
32 #undef THIS_FILE
33 static char THIS_FILE[]=__FILE__;
34 #define new DEBUG_NEW
35 #endif
37 /////////////////////////////////////////////////////////////////////////////
38 // CResourceViewBar
40 CPropertiesWnd::CPropertiesWnd()
41 : m_CommitHash(nullptr)
42 , m_AuthorName(nullptr)
43 , m_AuthorEmail(nullptr)
44 , m_AuthorDate(nullptr)
45 , m_CommitterName(nullptr)
46 , m_CommitterEmail(nullptr)
47 , m_CommitterDate(nullptr)
48 , m_Subject(nullptr)
49 , m_Body(nullptr)
50 , m_ParentGroup(nullptr)
51 , m_BaseInfoGroup(nullptr)
55 CPropertiesWnd::~CPropertiesWnd()
59 BEGIN_MESSAGE_MAP(CPropertiesWnd, CDockablePane)
60 ON_WM_CREATE()
61 ON_WM_SIZE()
62 ON_WM_SETFOCUS()
63 ON_WM_SETTINGCHANGE()
64 ON_WM_CONTEXTMENU()
65 END_MESSAGE_MAP()
67 /////////////////////////////////////////////////////////////////////////////
68 // CResourceViewBar message handlers
70 void CPropertiesWnd::AdjustLayout()
72 if (!GetSafeHwnd())
74 return;
77 CRect rectClient,rectCombo;
78 GetClientRect(rectClient);
80 m_wndPropList.SetWindowPos(nullptr, rectClient.left, rectClient.top, rectClient.Width(), rectClient.Height(), SWP_NOACTIVATE | SWP_NOZORDER);
83 int CPropertiesWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
85 if (CDockablePane::OnCreate(lpCreateStruct) == -1)
86 return -1;
88 CRect rectDummy;
89 rectDummy.SetRectEmpty();
91 if (!m_wndPropList.Create(WS_VISIBLE | WS_CHILD, rectDummy, this, 2))
93 TRACE0("Failed to create Properties Grid \n");
94 return -1; // fail to create
97 InitPropList();
99 AdjustLayout();
100 return 0;
103 void CPropertiesWnd::OnSize(UINT nType, int cx, int cy)
105 CDockablePane::OnSize(nType, cx, cy);
106 AdjustLayout();
109 void CPropertiesWnd::InitPropList()
111 SetPropListFont();
113 m_wndPropList.EnableHeaderCtrl(FALSE);
114 m_wndPropList.EnableDescriptionArea();
115 m_wndPropList.SetVSDotNetLook();
116 m_wndPropList.MarkModifiedProperties();
118 CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(CString(MAKEINTRESOURCE(IDS_PROPERTIES_BASICINFO)));
121 m_CommitHash = new CMFCPropertyGridProperty(
122 CString(MAKEINTRESOURCE(IDS_LOG_HASH)),
123 L"",
124 CString(MAKEINTRESOURCE(IDS_LOG_HASH))
126 pGroup1->AddSubItem(m_CommitHash);
128 m_AuthorName = new CMFCPropertyGridProperty(
129 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR)),
130 L"",
131 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR))
133 pGroup1->AddSubItem(m_AuthorName);
135 m_AuthorDate = new CMFCPropertyGridProperty(
136 CString(MAKEINTRESOURCE(IDS_LOG_DATE)),
137 L"",
138 CString(MAKEINTRESOURCE(IDS_LOG_DATE))
140 pGroup1->AddSubItem(m_AuthorDate);
142 m_AuthorEmail= new CMFCPropertyGridProperty(
143 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL)),
144 L"",
145 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL))
147 pGroup1->AddSubItem(m_AuthorEmail);
149 m_CommitterName = new CMFCPropertyGridProperty(
150 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_NAME)),
151 L"",
152 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_NAME))
154 pGroup1->AddSubItem(m_CommitterName);
156 m_CommitterEmail =new CMFCPropertyGridProperty(
157 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_EMAIL)),
158 L"",
159 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_EMAIL))
161 pGroup1->AddSubItem(m_CommitterEmail);
163 m_CommitterDate = new CMFCPropertyGridProperty(
164 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_DATE)),
165 L"",
166 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_DATE))
168 pGroup1->AddSubItem(m_CommitterDate);
170 m_Subject = new CMFCPropertyGridProperty(
171 CString(MAKEINTRESOURCE(IDS_SUBJECT)),
172 L"",
173 CString(MAKEINTRESOURCE(IDS_SUBJECT))
174 );;;
175 pGroup1->AddSubItem(m_Subject);
177 m_Body = new CMFCPropertyGridProperty(
178 CString(MAKEINTRESOURCE(IDS_BODY)),
179 L"",
180 CString(MAKEINTRESOURCE(IDS_BODY))
181 );;;;
182 pGroup1->AddSubItem(m_Body);
184 for (int i = 0; i < pGroup1->GetSubItemsCount(); ++i)
185 pGroup1->GetSubItem(i)->AllowEdit(FALSE);
187 m_wndPropList.AddProperty(pGroup1);
188 m_BaseInfoGroup=pGroup1;
190 m_ParentGroup=new CMFCPropertyGridProperty(CString(MAKEINTRESOURCE(IDS_PARENTS)));
192 m_wndPropList.AddProperty(m_ParentGroup);
195 void CPropertiesWnd::OnSetFocus(CWnd* pOldWnd)
197 CDockablePane::OnSetFocus(pOldWnd);
198 m_wndPropList.SetFocus();
201 void CPropertiesWnd::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
203 CDockablePane::OnSettingChange(uFlags, lpszSection);
204 SetPropListFont();
207 void CPropertiesWnd::SetPropListFont()
209 ::DeleteObject(m_fntPropList.Detach());
211 LOGFONT lf;
212 afxGlobalData.fontRegular.GetLogFont(&lf);
214 NONCLIENTMETRICS info;
215 info.cbSize = sizeof(info);
217 afxGlobalData.GetNonClientMetrics(info);
219 lf.lfHeight = info.lfMenuFont.lfHeight;
220 lf.lfWeight = info.lfMenuFont.lfWeight;
221 lf.lfItalic = info.lfMenuFont.lfItalic;
223 m_fntPropList.CreateFontIndirect(&lf);
225 m_wndPropList.SetFont(&m_fntPropList);
228 void CPropertiesWnd::RemoveParent()
230 m_ParentGroup->Expand(FALSE);
231 while (m_ParentGroup->GetSubItemsCount())
233 CMFCPropertyGridProperty * p=m_ParentGroup->GetSubItem(0);
234 m_ParentGroup->RemoveSubItem(p);
238 void CPropertiesWnd::UpdateProperties(GitRevLoglist* pRev)
240 if (pRev)
242 if (pRev->m_ParentHash.empty())
244 if (pRev->GetParentFromHash(pRev->m_CommitHash))
245 MessageBox(pRev->GetLastErr(), L"TortoiseGit", MB_ICONERROR);
247 CString hash = pRev->m_CommitHash.ToString();
248 m_CommitHash->SetValue(hash);
249 m_AuthorName->SetValue(pRev->GetAuthorName());
250 CString authorDate = pRev->GetAuthorDate().Format(L"%Y-%m-%d %H:%M");
251 m_AuthorDate->SetValue(authorDate);
252 m_AuthorEmail->SetValue(pRev->GetAuthorEmail());
254 m_CommitterName->SetValue(pRev->GetAuthorName());
255 m_CommitterEmail->SetValue(pRev->GetCommitterEmail());
256 CString committerDate = pRev->GetCommitterDate().Format(L"%Y-%m-%d %H:%M");
257 m_CommitterDate->SetValue(committerDate);
259 m_Subject->SetValue(pRev->GetSubject());
260 m_Body->SetValue(pRev->GetBody().Trim());
262 RemoveParent();
264 CLogDataVector* pLogEntry = &static_cast<CMainFrame*>(AfxGetApp()->GetMainWnd())->m_wndOutput.m_LogList.m_logEntries;
266 CGitHashMap & hashMap = pLogEntry->m_pLogCache->m_HashMap;
267 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
269 CString str;
270 CString parentsubject;
272 auto it = hashMap.find(pRev->m_ParentHash[i]);
273 if (it != hashMap.end())
274 parentsubject = it->second.GetSubject();
276 str.Format(L"%u - %s\n%s", i, (LPCTSTR)pRev->m_ParentHash[i].ToString(), (LPCTSTR)parentsubject);
278 auto pProperty = new CMFCPropertyGridProperty(pRev->m_ParentHash[i].ToString().Left(g_Git.GetShortHASHLength()), parentsubject, str);
279 pProperty->AllowEdit(FALSE);
280 m_ParentGroup->AddSubItem(pProperty);
282 m_ParentGroup->Expand();
283 for (int i = 0; i < m_BaseInfoGroup->GetSubItemsCount(); ++i)
284 m_BaseInfoGroup->GetSubItem(i)->SetDescription(m_BaseInfoGroup->GetSubItem(i)->GetValue());
286 else
288 m_CommitHash->SetValue(L"");
289 m_AuthorName->SetValue(L"");
290 m_AuthorDate->SetValue(L"");
291 m_AuthorEmail->SetValue(L"");
293 m_CommitterName->SetValue(L"");
294 m_CommitterEmail->SetValue(L"");
295 m_CommitterDate->SetValue(L"");
297 m_Subject->SetValue(L"");
298 m_Body->SetValue(L"");
300 RemoveParent();
302 for (int i = 0; i < m_BaseInfoGroup->GetSubItemsCount(); ++i)
303 m_BaseInfoGroup->GetSubItem(i)->SetDescription(L"");
305 m_wndPropList.AdjustLayout();
308 void CPropertiesWnd::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
310 CMFCPropertyGridProperty * pProperty = m_wndPropList.GetCurSel();
312 CString sMenuItemText;
313 CIconMenu popup;
314 if (pProperty && !pProperty->IsGroup() && popup.CreatePopupMenu())
316 sMenuItemText.LoadString(IDS_SCIEDIT_COPY);
317 popup.AppendMenu(MF_STRING | MF_ENABLED, WM_COPY, sMenuItemText);
319 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this);
320 switch (cmd)
322 case 0:
323 break; // no command selected
324 case WM_COPY:
325 CStringUtils::WriteAsciiStringToClipboard(pProperty->GetValue(), GetSafeHwnd());
326 break;