1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2015 - 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.
24 #include "PropertiesWnd.h"
27 #include "TortoiseGitBlame.h"
29 #include "StringUtils.h"
33 static char THIS_FILE
[]=__FILE__
;
37 /////////////////////////////////////////////////////////////////////////////
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)
50 , m_ParentGroup(nullptr)
51 , m_BaseInfoGroup(nullptr)
55 CPropertiesWnd::~CPropertiesWnd()
59 BEGIN_MESSAGE_MAP(CPropertiesWnd
, CDockablePane
)
67 /////////////////////////////////////////////////////////////////////////////
68 // CResourceViewBar message handlers
70 void CPropertiesWnd::AdjustLayout()
72 if (GetSafeHwnd() == NULL
)
77 CRect rectClient
,rectCombo
;
78 GetClientRect(rectClient
);
80 m_wndPropList
.SetWindowPos(NULL
, rectClient
.left
, rectClient
.top
, rectClient
.Width(), rectClient
.Height(), SWP_NOACTIVATE
| SWP_NOZORDER
);
83 int CPropertiesWnd::OnCreate(LPCREATESTRUCT lpCreateStruct
)
85 if (CDockablePane::OnCreate(lpCreateStruct
) == -1)
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
103 void CPropertiesWnd::OnSize(UINT nType
, int cx
, int cy
)
105 CDockablePane::OnSize(nType
, cx
, cy
);
109 void CPropertiesWnd::InitPropList()
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
)),
124 CString(MAKEINTRESOURCE(IDS_LOG_HASH
))
126 pGroup1
->AddSubItem(m_CommitHash
);
128 m_AuthorName
= new CMFCPropertyGridProperty(
129 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR
)),
131 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR
))
133 pGroup1
->AddSubItem(m_AuthorName
);
135 m_AuthorDate
= new CMFCPropertyGridProperty(
136 CString(MAKEINTRESOURCE(IDS_LOG_DATE
)),
138 CString(MAKEINTRESOURCE(IDS_LOG_DATE
))
140 pGroup1
->AddSubItem(m_AuthorDate
);
142 m_AuthorEmail
= new CMFCPropertyGridProperty(
143 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL
)),
145 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL
))
147 pGroup1
->AddSubItem(m_AuthorEmail
);
149 m_CommitterName
= new CMFCPropertyGridProperty(
150 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_NAME
)),
152 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_NAME
))
154 pGroup1
->AddSubItem(m_CommitterName
);
156 m_CommitterEmail
=new CMFCPropertyGridProperty(
157 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_EMAIL
)),
159 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_EMAIL
))
161 pGroup1
->AddSubItem(m_CommitterEmail
);
163 m_CommitterDate
= new CMFCPropertyGridProperty(
164 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_DATE
)),
166 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_DATE
))
168 pGroup1
->AddSubItem(m_CommitterDate
);
170 m_Subject
= new CMFCPropertyGridProperty(
171 CString(MAKEINTRESOURCE(IDS_SUBJECT
)),
173 CString(MAKEINTRESOURCE(IDS_SUBJECT
))
175 pGroup1
->AddSubItem(m_Subject
);
177 m_Body
= new CMFCPropertyGridProperty(
178 CString(MAKEINTRESOURCE(IDS_BODY
)),
180 CString(MAKEINTRESOURCE(IDS_BODY
))
182 pGroup1
->AddSubItem(m_Body
);
184 for (int i
= 0; i
< pGroup1
->GetSubItemsCount(); ++i
)
186 pGroup1
->GetSubItem(i
)->AllowEdit(FALSE
);
189 m_wndPropList
.AddProperty(pGroup1
);
190 m_BaseInfoGroup
=pGroup1
;
192 m_ParentGroup
=new CMFCPropertyGridProperty(CString(MAKEINTRESOURCE(IDS_PARENTS
)));
194 m_wndPropList
.AddProperty(m_ParentGroup
);
197 void CPropertiesWnd::OnSetFocus(CWnd
* pOldWnd
)
199 CDockablePane::OnSetFocus(pOldWnd
);
200 m_wndPropList
.SetFocus();
203 void CPropertiesWnd::OnSettingChange(UINT uFlags
, LPCTSTR lpszSection
)
205 CDockablePane::OnSettingChange(uFlags
, lpszSection
);
209 void CPropertiesWnd::SetPropListFont()
211 ::DeleteObject(m_fntPropList
.Detach());
214 afxGlobalData
.fontRegular
.GetLogFont(&lf
);
216 NONCLIENTMETRICS info
;
217 info
.cbSize
= sizeof(info
);
219 afxGlobalData
.GetNonClientMetrics(info
);
221 lf
.lfHeight
= info
.lfMenuFont
.lfHeight
;
222 lf
.lfWeight
= info
.lfMenuFont
.lfWeight
;
223 lf
.lfItalic
= info
.lfMenuFont
.lfItalic
;
225 m_fntPropList
.CreateFontIndirect(&lf
);
227 m_wndPropList
.SetFont(&m_fntPropList
);
230 void CPropertiesWnd::RemoveParent()
232 m_ParentGroup
->Expand(FALSE
);
233 while (m_ParentGroup
->GetSubItemsCount())
235 CMFCPropertyGridProperty
* p
=m_ParentGroup
->GetSubItem(0);
236 m_ParentGroup
->RemoveSubItem(p
);
240 void CPropertiesWnd::UpdateProperties(GitRevLoglist
* pRev
)
244 if (pRev
->m_ParentHash
.empty())
246 if (pRev
->GetParentFromHash(pRev
->m_CommitHash
))
247 MessageBox(pRev
->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR
);
249 CString hash
= pRev
->m_CommitHash
.ToString();
250 m_CommitHash
->SetValue(hash
);
251 m_AuthorName
->SetValue(pRev
->GetAuthorName());
252 CString authorDate
= pRev
->GetAuthorDate().Format(_T("%Y-%m-%d %H:%M"));
253 m_AuthorDate
->SetValue(authorDate
);
254 m_AuthorEmail
->SetValue(pRev
->GetAuthorEmail());
256 m_CommitterName
->SetValue(pRev
->GetAuthorName());
257 m_CommitterEmail
->SetValue(pRev
->GetCommitterEmail());
258 CString committerDate
= pRev
->GetCommitterDate().Format(_T("%Y-%m-%d %H:%M"));
259 m_CommitterDate
->SetValue(committerDate
);
261 m_Subject
->SetValue(pRev
->GetSubject());
262 m_Body
->SetValue(pRev
->GetBody().Trim());
266 CLogDataVector
*pLogEntry
= &((CMainFrame
*)AfxGetApp()->GetMainWnd())->m_wndOutput
.m_LogList
.m_logEntries
;
268 CGitHashMap
& hashMap
= pLogEntry
->m_pLogCache
->m_HashMap
;
269 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
272 CString parentsubject
;
274 auto it
= hashMap
.find(pRev
->m_ParentHash
[i
]);
275 if (it
!= hashMap
.end())
276 parentsubject
= it
->second
.GetSubject();
278 str
.Format(_T("%u - %s\n%s"), i
, pRev
->m_ParentHash
[i
].ToString(), parentsubject
);
280 CMFCPropertyGridProperty
*pProperty
= new CMFCPropertyGridProperty(pRev
->m_ParentHash
[i
].ToString().Left(8), parentsubject
, str
);
281 pProperty
->AllowEdit(FALSE
);
282 m_ParentGroup
->AddSubItem(pProperty
);
284 m_ParentGroup
->Expand();
285 for (int i
= 0; i
< m_BaseInfoGroup
->GetSubItemsCount(); ++i
)
286 m_BaseInfoGroup
->GetSubItem(i
)->SetDescription(m_BaseInfoGroup
->GetSubItem(i
)->GetValue());
290 m_CommitHash
->SetValue(_T(""));
291 m_AuthorName
->SetValue(_T(""));
292 m_AuthorDate
->SetValue(_T(""));
293 m_AuthorEmail
->SetValue(_T(""));
295 m_CommitterName
->SetValue(_T(""));
296 m_CommitterEmail
->SetValue(_T(""));
297 m_CommitterDate
->SetValue(_T(""));
299 m_Subject
->SetValue(_T(""));
300 m_Body
->SetValue(_T(""));
304 for (int i
= 0; i
< m_BaseInfoGroup
->GetSubItemsCount(); ++i
)
305 m_BaseInfoGroup
->GetSubItem(i
)->SetDescription(_T(""));
307 m_wndPropList
.AdjustLayout();
310 void CPropertiesWnd::OnContextMenu(CWnd
* /*pWnd*/, CPoint point
)
312 CMFCPropertyGridProperty
* pProperty
= m_wndPropList
.GetCurSel();
314 CString sMenuItemText
;
316 if (pProperty
&& !pProperty
->IsGroup() && popup
.CreatePopupMenu())
318 sMenuItemText
.LoadString(IDS_SCIEDIT_COPY
);
319 popup
.AppendMenu(MF_STRING
| MF_ENABLED
, WM_COPY
, sMenuItemText
);
321 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
325 break; // no command selected
327 CStringUtils::WriteAsciiStringToClipboard(pProperty
->GetValue(), GetSafeHwnd());