Refactor code that gets ref label color
[TortoiseGit.git] / src / TortoiseGitBlame / PropertiesWnd.cpp
blob4a9c9756fac541f00ae1b0964af66783bd547380
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2011-2012 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()
42 m_CommitHash = NULL;
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() == NULL)
64 return;
67 CRect rectClient,rectCombo;
68 GetClientRect(rectClient);
70 m_wndPropList.SetWindowPos(NULL, 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();
90 return 0;
93 void CPropertiesWnd::OnSize(UINT nType, int cx, int cy)
95 CDockablePane::OnSize(nType, cx, cy);
96 AdjustLayout();
99 void CPropertiesWnd::InitPropList()
101 SetPropListFont();
103 m_wndPropList.EnableHeaderCtrl(FALSE);
104 m_wndPropList.EnableDescriptionArea();
105 m_wndPropList.SetVSDotNetLook();
106 m_wndPropList.MarkModifiedProperties();
108 CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(CString(MAKEINTRESOURCE(IDS_PROPERTIES_BASICINFO)));
111 m_CommitHash = new CMFCPropertyGridProperty(
112 CString(MAKEINTRESOURCE(IDS_LOG_HASH)),
113 _T(""),
114 CString(MAKEINTRESOURCE(IDS_LOG_HASH))
116 pGroup1->AddSubItem(m_CommitHash);
118 m_AuthorName = new CMFCPropertyGridProperty(
119 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR)),
120 _T(""),
121 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR))
123 pGroup1->AddSubItem(m_AuthorName);
125 m_AuthorDate = new CMFCPropertyGridProperty(
126 CString(MAKEINTRESOURCE(IDS_LOG_DATE)),
127 _T(""),
128 CString(MAKEINTRESOURCE(IDS_LOG_DATE))
130 pGroup1->AddSubItem(m_AuthorDate);
132 m_AuthorEmail= new CMFCPropertyGridProperty(
133 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL)),
134 _T(""),
135 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL))
137 pGroup1->AddSubItem(m_AuthorEmail);
139 m_CommitterName = new CMFCPropertyGridProperty(
140 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_NAME)),
141 _T(""),
142 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_NAME))
144 pGroup1->AddSubItem(m_CommitterName);
146 m_CommitterEmail =new CMFCPropertyGridProperty(
147 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_EMAIL)),
148 _T(""),
149 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_EMAIL))
151 pGroup1->AddSubItem(m_CommitterEmail);
153 m_CommitterDate = new CMFCPropertyGridProperty(
154 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_DATE)),
155 _T(""),
156 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_DATE))
158 pGroup1->AddSubItem(m_CommitterDate);
160 m_Subject = new CMFCPropertyGridProperty(
161 CString(MAKEINTRESOURCE(IDS_SUBJECT)),
162 _T(""),
163 CString(MAKEINTRESOURCE(IDS_SUBJECT))
164 );;;
165 pGroup1->AddSubItem(m_Subject);
167 m_Body = new CMFCPropertyGridProperty(
168 CString(MAKEINTRESOURCE(IDS_BODY)),
169 _T(""),
170 CString(MAKEINTRESOURCE(IDS_BODY))
171 );;;;
172 pGroup1->AddSubItem(m_Body);
174 for(int i=0;i<pGroup1->GetSubItemsCount();i++)
176 pGroup1->GetSubItem(i)->AllowEdit(FALSE);
179 m_wndPropList.AddProperty(pGroup1);
180 m_BaseInfoGroup=pGroup1;
182 m_ParentGroup=new CMFCPropertyGridProperty(CString(MAKEINTRESOURCE(IDS_PARENTS)));
184 m_wndPropList.AddProperty(m_ParentGroup);
187 void CPropertiesWnd::OnSetFocus(CWnd* pOldWnd)
189 CDockablePane::OnSetFocus(pOldWnd);
190 m_wndPropList.SetFocus();
193 void CPropertiesWnd::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
195 CDockablePane::OnSettingChange(uFlags, lpszSection);
196 SetPropListFont();
199 void CPropertiesWnd::SetPropListFont()
201 ::DeleteObject(m_fntPropList.Detach());
203 LOGFONT lf;
204 afxGlobalData.fontRegular.GetLogFont(&lf);
206 NONCLIENTMETRICS info;
207 info.cbSize = sizeof(info);
209 afxGlobalData.GetNonClientMetrics(info);
211 lf.lfHeight = info.lfMenuFont.lfHeight;
212 lf.lfWeight = info.lfMenuFont.lfWeight;
213 lf.lfItalic = info.lfMenuFont.lfItalic;
215 m_fntPropList.CreateFontIndirect(&lf);
217 m_wndPropList.SetFont(&m_fntPropList);
219 void CPropertiesWnd::RemoveParent()
221 m_ParentGroup->Expand(false);
222 for(int i=0;i<m_ParentGroup->GetSubItemsCount();i++)
224 CMFCPropertyGridProperty * p=m_ParentGroup->GetSubItem(0);
225 m_ParentGroup->RemoveSubItem(p);
229 void CPropertiesWnd::UpdateProperties(GitRev *rev)
231 if(rev)
233 m_CommitHash->SetValue(rev->m_CommitHash.ToString());
234 m_AuthorName->SetValue(rev->GetAuthorName());
235 m_AuthorDate->SetValue(rev->GetAuthorDate().Format(_T("%Y-%m-%d %H:%M")));
236 m_AuthorEmail->SetValue(rev->GetAuthorEmail());
238 m_CommitterName->SetValue(rev->GetAuthorName());
239 m_CommitterEmail->SetValue(rev->GetCommitterEmail());
240 m_CommitterDate->SetValue(rev->GetCommitterDate().Format(_T("%Y-%m-%d %H:%M")));
242 m_Subject->SetValue(rev->GetSubject());
243 m_Body->SetValue(rev->GetBody().Trim());
245 RemoveParent();
247 m_ParentGroup;
249 CLogDataVector *pLogEntry = &((CMainFrame*)AfxGetApp()->GetMainWnd())->m_wndOutput.m_LogList.m_logEntries;
251 for(unsigned int i=0;i<rev->m_ParentHash.size();i++)
253 CString str;
254 CString parentsubject;
256 GitRev *p =NULL;
258 if( pLogEntry->m_pLogCache->m_HashMap.find(rev->m_ParentHash[i]) == pLogEntry->m_pLogCache->m_HashMap.end())
260 p=NULL;
262 else
264 p= &pLogEntry->m_pLogCache->m_HashMap[rev->m_ParentHash[i]] ;
266 if(p)
267 parentsubject=p->GetSubject();
269 str.Format(_T("%d - %s \n %s"),i,rev->m_ParentHash[i].ToString(),parentsubject);
271 CMFCPropertyGridProperty*pProtery=new CMFCPropertyGridProperty(
272 rev->m_ParentHash[i].ToString().Left(8),
273 parentsubject,
276 pProtery->AllowEdit(FALSE);
277 m_ParentGroup->AddSubItem(pProtery);
279 m_ParentGroup->Expand();
280 for(int i=0;i<m_BaseInfoGroup->GetSubItemsCount();i++)
281 m_BaseInfoGroup->GetSubItem(i)->SetDescription(m_BaseInfoGroup->GetSubItem(i)->GetValue());
284 else
286 m_CommitHash->SetValue(_T(""));
287 m_AuthorName->SetValue(_T(""));
288 m_AuthorDate->SetValue(_T(""));
289 m_AuthorEmail->SetValue(_T(""));
291 m_CommitterName->SetValue(_T(""));
292 m_CommitterEmail->SetValue(_T(""));
293 m_CommitterDate->SetValue(_T(""));
295 m_Subject->SetValue(_T(""));
296 m_Body->SetValue(_T(""));
298 RemoveParent();
300 for(int i=0;i<m_BaseInfoGroup->GetSubItemsCount();i++)
301 m_BaseInfoGroup->GetSubItem(i)->SetDescription(_T(""));
303 this->Invalidate();
304 m_wndPropList.Invalidate();
307 void CPropertiesWnd::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
309 CMFCPropertyGridProperty * pProtery = m_wndPropList.GetCurSel();
311 CString sMenuItemText;
312 CIconMenu popup;
313 if (pProtery && !pProtery->IsGroup() && popup.CreatePopupMenu())
315 sMenuItemText.LoadString(IDS_SCIEDIT_COPY);
316 popup.AppendMenu(MF_STRING | MF_ENABLED, WM_COPY, sMenuItemText);
318 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
319 switch (cmd)
321 case 0:
322 break; // no command selected
323 case WM_COPY:
324 CStringUtils::WriteAsciiStringToClipboard(pProtery->GetValue(), GetSafeHwnd());
325 break;