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.
24 #include "PropertiesWnd.h"
27 #include "TortoiseGitBlame.h"
29 #include "StringUtils.h"
33 static char THIS_FILE
[]=__FILE__
;
37 /////////////////////////////////////////////////////////////////////////////
40 CPropertiesWnd::CPropertiesWnd()
45 CPropertiesWnd::~CPropertiesWnd()
49 BEGIN_MESSAGE_MAP(CPropertiesWnd
, CDockablePane
)
57 /////////////////////////////////////////////////////////////////////////////
58 // CResourceViewBar message handlers
60 void CPropertiesWnd::AdjustLayout()
62 if (GetSafeHwnd() == NULL
)
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)
79 rectDummy
.SetRectEmpty();
82 const DWORD dwViewStyle
= WS_CHILD
| WS_VISIBLE
| CBS_DROPDOWNLIST
| WS_BORDER
| CBS_SORT
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
84 if (!m_wndPropList
.Create(WS_VISIBLE
| WS_CHILD
, rectDummy
, this, 2))
86 TRACE0("Failed to create Properties Grid \n");
87 return -1; // fail to create
96 void CPropertiesWnd::OnSize(UINT nType
, int cx
, int cy
)
98 CDockablePane::OnSize(nType
, cx
, cy
);
102 void CPropertiesWnd::InitPropList()
106 m_wndPropList
.EnableHeaderCtrl(FALSE
);
107 m_wndPropList
.EnableDescriptionArea();
108 m_wndPropList
.SetVSDotNetLook();
109 m_wndPropList
.MarkModifiedProperties();
111 CMFCPropertyGridProperty
* pGroup1
= new CMFCPropertyGridProperty(CString(MAKEINTRESOURCE(IDS_PROPERTIES_BASICINFO
)));
114 m_CommitHash
= new CMFCPropertyGridProperty(
115 CString(MAKEINTRESOURCE(IDS_LOG_HASH
)),
117 CString(MAKEINTRESOURCE(IDS_LOG_HASH
))
119 pGroup1
->AddSubItem(m_CommitHash
);
121 m_AuthorName
= new CMFCPropertyGridProperty(
122 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR
)),
124 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR
))
126 pGroup1
->AddSubItem(m_AuthorName
);
128 m_AuthorDate
= new CMFCPropertyGridProperty(
129 CString(MAKEINTRESOURCE(IDS_LOG_DATE
)),
131 CString(MAKEINTRESOURCE(IDS_LOG_DATE
))
133 pGroup1
->AddSubItem(m_AuthorDate
);
135 m_AuthorEmail
= new CMFCPropertyGridProperty(
136 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL
)),
138 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL
))
140 pGroup1
->AddSubItem(m_AuthorEmail
);
142 m_CommitterName
= new CMFCPropertyGridProperty(
143 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_NAME
)),
145 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_NAME
))
147 pGroup1
->AddSubItem(m_CommitterName
);
149 m_CommitterEmail
=new CMFCPropertyGridProperty(
150 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_EMAIL
)),
152 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_EMAIL
))
154 pGroup1
->AddSubItem(m_CommitterEmail
);
156 m_CommitterDate
= new CMFCPropertyGridProperty(
157 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_DATE
)),
159 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_DATE
))
161 pGroup1
->AddSubItem(m_CommitterDate
);
163 m_Subject
= new CMFCPropertyGridProperty(
164 CString(MAKEINTRESOURCE(IDS_SUBJECT
)),
166 CString(MAKEINTRESOURCE(IDS_SUBJECT
))
168 pGroup1
->AddSubItem(m_Subject
);
170 m_Body
= new CMFCPropertyGridProperty(
171 CString(MAKEINTRESOURCE(IDS_BODY
)),
173 CString(MAKEINTRESOURCE(IDS_BODY
))
175 pGroup1
->AddSubItem(m_Body
);
177 for(int i
=0;i
<pGroup1
->GetSubItemsCount();i
++)
179 pGroup1
->GetSubItem(i
)->AllowEdit(FALSE
);
182 m_wndPropList
.AddProperty(pGroup1
);
183 m_BaseInfoGroup
=pGroup1
;
185 m_ParentGroup
=new CMFCPropertyGridProperty(CString(MAKEINTRESOURCE(IDS_PARENTS
)));
187 m_wndPropList
.AddProperty(m_ParentGroup
);
190 void CPropertiesWnd::OnSetFocus(CWnd
* pOldWnd
)
192 CDockablePane::OnSetFocus(pOldWnd
);
193 m_wndPropList
.SetFocus();
196 void CPropertiesWnd::OnSettingChange(UINT uFlags
, LPCTSTR lpszSection
)
198 CDockablePane::OnSettingChange(uFlags
, lpszSection
);
202 void CPropertiesWnd::SetPropListFont()
204 ::DeleteObject(m_fntPropList
.Detach());
207 afxGlobalData
.fontRegular
.GetLogFont(&lf
);
209 NONCLIENTMETRICS info
;
210 info
.cbSize
= sizeof(info
);
212 afxGlobalData
.GetNonClientMetrics(info
);
214 lf
.lfHeight
= info
.lfMenuFont
.lfHeight
;
215 lf
.lfWeight
= info
.lfMenuFont
.lfWeight
;
216 lf
.lfItalic
= info
.lfMenuFont
.lfItalic
;
218 m_fntPropList
.CreateFontIndirect(&lf
);
220 m_wndPropList
.SetFont(&m_fntPropList
);
222 void CPropertiesWnd::RemoveParent()
224 m_ParentGroup
->Expand(false);
225 for(int i
=0;i
<m_ParentGroup
->GetSubItemsCount();i
++)
227 CMFCPropertyGridProperty
* p
=m_ParentGroup
->GetSubItem(0);
228 m_ParentGroup
->RemoveSubItem(p
);
232 void CPropertiesWnd::UpdateProperties(GitRev
*rev
)
236 m_CommitHash
->SetValue(rev
->m_CommitHash
.ToString());
237 m_AuthorName
->SetValue(rev
->GetAuthorName());
238 m_AuthorDate
->SetValue(rev
->GetAuthorDate().Format(_T("%Y-%m-%d %H:%M")));
239 m_AuthorEmail
->SetValue(rev
->GetAuthorEmail());
241 m_CommitterName
->SetValue(rev
->GetAuthorName());
242 m_CommitterEmail
->SetValue(rev
->GetCommitterEmail());
243 m_CommitterDate
->SetValue(rev
->GetCommitterDate().Format(_T("%Y-%m-%d %H:%M")));
245 m_Subject
->SetValue(rev
->GetSubject());
246 m_Body
->SetValue(rev
->GetBody().Trim());
252 CLogDataVector
*pLogEntry
= &((CMainFrame
*)AfxGetApp()->GetMainWnd())->m_wndOutput
.m_LogList
.m_logEntries
;
254 for(unsigned int i
=0;i
<rev
->m_ParentHash
.size();i
++)
257 CString parentsubject
;
261 if( pLogEntry
->m_pLogCache
->m_HashMap
.find(rev
->m_ParentHash
[i
]) == pLogEntry
->m_pLogCache
->m_HashMap
.end())
267 p
= &pLogEntry
->m_pLogCache
->m_HashMap
[rev
->m_ParentHash
[i
]] ;
270 parentsubject
=p
->GetSubject();
272 str
.Format(_T("%d - %s \n %s"),i
,rev
->m_ParentHash
[i
].ToString(),parentsubject
);
274 CMFCPropertyGridProperty
*pProtery
=new CMFCPropertyGridProperty(
275 rev
->m_ParentHash
[i
].ToString().Left(8),
279 pProtery
->AllowEdit(FALSE
);
280 m_ParentGroup
->AddSubItem(pProtery
);
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());
289 m_CommitHash
->SetValue(_T(""));
290 m_AuthorName
->SetValue(_T(""));
291 m_AuthorDate
->SetValue(_T(""));
292 m_AuthorEmail
->SetValue(_T(""));
294 m_CommitterName
->SetValue(_T(""));
295 m_CommitterEmail
->SetValue(_T(""));
296 m_CommitterDate
->SetValue(_T(""));
298 m_Subject
->SetValue(_T(""));
299 m_Body
->SetValue(_T(""));
303 for(int i
=0;i
<m_BaseInfoGroup
->GetSubItemsCount();i
++)
304 m_BaseInfoGroup
->GetSubItem(i
)->SetDescription(_T(""));
307 m_wndPropList
.Invalidate();
310 void CPropertiesWnd::OnContextMenu(CWnd
* pWnd
, CPoint point
)
312 CMFCPropertyGridProperty
* pProtery
= m_wndPropList
.GetCurSel();
314 CString sMenuItemText
;
316 if (pProtery
&& !pProtery
->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(pProtery
->GetValue(), GetSafeHwnd());