Sync translations with Transifex
[TortoiseGit.git] / src / TortoiseGitBlame / PropertiesWnd.cpp
blobbaf38d830bedda729cf14f06f1ac4a40a46f6438
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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() == NULL)
74 return;
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)
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 _T(""),
124 CString(MAKEINTRESOURCE(IDS_LOG_HASH))
126 pGroup1->AddSubItem(m_CommitHash);
128 m_AuthorName = new CMFCPropertyGridProperty(
129 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR)),
130 _T(""),
131 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR))
133 pGroup1->AddSubItem(m_AuthorName);
135 m_AuthorDate = new CMFCPropertyGridProperty(
136 CString(MAKEINTRESOURCE(IDS_LOG_DATE)),
137 _T(""),
138 CString(MAKEINTRESOURCE(IDS_LOG_DATE))
140 pGroup1->AddSubItem(m_AuthorDate);
142 m_AuthorEmail= new CMFCPropertyGridProperty(
143 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL)),
144 _T(""),
145 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL))
147 pGroup1->AddSubItem(m_AuthorEmail);
149 m_CommitterName = new CMFCPropertyGridProperty(
150 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_NAME)),
151 _T(""),
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 _T(""),
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 _T(""),
166 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_DATE))
168 pGroup1->AddSubItem(m_CommitterDate);
170 m_Subject = new CMFCPropertyGridProperty(
171 CString(MAKEINTRESOURCE(IDS_SUBJECT)),
172 _T(""),
173 CString(MAKEINTRESOURCE(IDS_SUBJECT))
174 );;;
175 pGroup1->AddSubItem(m_Subject);
177 m_Body = new CMFCPropertyGridProperty(
178 CString(MAKEINTRESOURCE(IDS_BODY)),
179 _T(""),
180 CString(MAKEINTRESOURCE(IDS_BODY))
181 );;;;
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);
206 SetPropListFont();
209 void CPropertiesWnd::SetPropListFont()
211 ::DeleteObject(m_fntPropList.Detach());
213 LOGFONT lf;
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(GitRev *pRev)
242 if (pRev)
244 if (pRev->m_ParentHash.empty())
248 pRev->GetParentFromHash(pRev->m_CommitHash);
250 catch (const char* msg)
252 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
255 CString hash = pRev->m_CommitHash.ToString();
256 m_CommitHash->SetValue(hash);
257 m_AuthorName->SetValue(pRev->GetAuthorName());
258 CString authorDate = pRev->GetAuthorDate().Format(_T("%Y-%m-%d %H:%M"));
259 m_AuthorDate->SetValue(authorDate);
260 m_AuthorEmail->SetValue(pRev->GetAuthorEmail());
262 m_CommitterName->SetValue(pRev->GetAuthorName());
263 m_CommitterEmail->SetValue(pRev->GetCommitterEmail());
264 CString committerDate = pRev->GetCommitterDate().Format(_T("%Y-%m-%d %H:%M"));
265 m_CommitterDate->SetValue(committerDate);
267 m_Subject->SetValue(pRev->GetSubject());
268 m_Body->SetValue(pRev->GetBody().Trim());
270 RemoveParent();
272 CLogDataVector *pLogEntry = &((CMainFrame*)AfxGetApp()->GetMainWnd())->m_wndOutput.m_LogList.m_logEntries;
274 CGitHashMap & hashMap = pLogEntry->m_pLogCache->m_HashMap;
275 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
277 CString str;
278 CString parentsubject;
280 auto it = hashMap.find(pRev->m_ParentHash[i]);
281 if (it != hashMap.end())
282 parentsubject = it->second.GetSubject();
284 str.Format(_T("%u - %s\n%s"), i, pRev->m_ParentHash[i].ToString(), parentsubject);
286 CMFCPropertyGridProperty *pProperty = new CMFCPropertyGridProperty(pRev->m_ParentHash[i].ToString().Left(8), parentsubject, str);
287 pProperty->AllowEdit(FALSE);
288 m_ParentGroup->AddSubItem(pProperty);
290 m_ParentGroup->Expand();
291 for (int i = 0; i < m_BaseInfoGroup->GetSubItemsCount(); ++i)
292 m_BaseInfoGroup->GetSubItem(i)->SetDescription(m_BaseInfoGroup->GetSubItem(i)->GetValue());
294 else
296 m_CommitHash->SetValue(_T(""));
297 m_AuthorName->SetValue(_T(""));
298 m_AuthorDate->SetValue(_T(""));
299 m_AuthorEmail->SetValue(_T(""));
301 m_CommitterName->SetValue(_T(""));
302 m_CommitterEmail->SetValue(_T(""));
303 m_CommitterDate->SetValue(_T(""));
305 m_Subject->SetValue(_T(""));
306 m_Body->SetValue(_T(""));
308 RemoveParent();
310 for (int i = 0; i < m_BaseInfoGroup->GetSubItemsCount(); ++i)
311 m_BaseInfoGroup->GetSubItem(i)->SetDescription(_T(""));
313 m_wndPropList.AdjustLayout();
316 void CPropertiesWnd::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
318 CMFCPropertyGridProperty * pProperty = m_wndPropList.GetCurSel();
320 CString sMenuItemText;
321 CIconMenu popup;
322 if (pProperty && !pProperty->IsGroup() && popup.CreatePopupMenu())
324 sMenuItemText.LoadString(IDS_SCIEDIT_COPY);
325 popup.AppendMenu(MF_STRING | MF_ENABLED, WM_COPY, sMenuItemText);
327 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
328 switch (cmd)
330 case 0:
331 break; // no command selected
332 case WM_COPY:
333 CStringUtils::WriteAsciiStringToClipboard(pProperty->GetValue(), GetSafeHwnd());
334 break;