pulled latest translations from Transifex
[TortoiseGit.git] / src / TortoiseGitBlame / PropertiesWnd.cpp
blobd66fcdab9f70cbd17248eaca6fb04fc1545c436f
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
4 // Copyright (C) 2011 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"
29 #ifdef _DEBUG
30 #undef THIS_FILE
31 static char THIS_FILE[]=__FILE__;
32 #define new DEBUG_NEW
33 #endif
35 /////////////////////////////////////////////////////////////////////////////
36 // CResourceViewBar
38 CPropertiesWnd::CPropertiesWnd()
42 CPropertiesWnd::~CPropertiesWnd()
46 BEGIN_MESSAGE_MAP(CPropertiesWnd, CDockablePane)
47 ON_WM_CREATE()
48 ON_WM_SIZE()
49 ON_COMMAND(ID_EXPAND_ALL, OnExpandAllProperties)
50 ON_UPDATE_COMMAND_UI(ID_EXPAND_ALL, OnUpdateExpandAllProperties)
51 ON_COMMAND(ID_SORTPROPERTIES, OnSortProperties)
52 ON_UPDATE_COMMAND_UI(ID_SORTPROPERTIES, OnUpdateSortProperties)
53 ON_WM_SETFOCUS()
54 ON_WM_SETTINGCHANGE()
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 int cyTlb = m_wndToolBar.CalcFixedLayout(FALSE, TRUE).cy;
72 m_wndToolBar.SetWindowPos(NULL, rectClient.left, rectClient.top, rectClient.Width(), 200, SWP_NOACTIVATE | SWP_NOZORDER);
73 m_wndPropList.SetWindowPos(NULL, rectClient.left, rectClient.top + cyTlb, rectClient.Width(), rectClient.Height() - cyTlb, SWP_NOACTIVATE | SWP_NOZORDER);
76 int CPropertiesWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
78 if (CDockablePane::OnCreate(lpCreateStruct) == -1)
79 return -1;
81 CRect rectDummy;
82 rectDummy.SetRectEmpty();
84 // Create combo:
85 const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_BORDER | CBS_SORT | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
87 if (!m_wndPropList.Create(WS_VISIBLE | WS_CHILD, rectDummy, this, 2))
89 TRACE0("Failed to create Properties Grid \n");
90 return -1; // fail to create
93 InitPropList();
95 m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_PROPERTIES);
96 m_wndToolBar.LoadToolBar(IDR_PROPERTIES, 0, 0, TRUE /* Is locked */);
97 m_wndToolBar.CleanUpLockedImages();
98 m_wndToolBar.LoadBitmap(theApp.m_bHiColorIcons ? IDB_PROPERTIES_HC : IDR_PROPERTIES, 0, 0, TRUE /* Locked */);
100 m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
101 m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() & ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
102 m_wndToolBar.SetOwner(this);
104 // All commands will be routed via this control , not via the parent frame:
105 m_wndToolBar.SetRouteCommandsViaFrame(FALSE);
107 AdjustLayout();
108 return 0;
111 void CPropertiesWnd::OnSize(UINT nType, int cx, int cy)
113 CDockablePane::OnSize(nType, cx, cy);
114 AdjustLayout();
117 void CPropertiesWnd::OnExpandAllProperties()
119 m_wndPropList.ExpandAll();
122 void CPropertiesWnd::OnUpdateExpandAllProperties(CCmdUI* pCmdUI)
126 void CPropertiesWnd::OnSortProperties()
128 m_wndPropList.SetAlphabeticMode(!m_wndPropList.IsAlphabeticMode());
131 void CPropertiesWnd::OnUpdateSortProperties(CCmdUI* pCmdUI)
133 pCmdUI->SetCheck(m_wndPropList.IsAlphabeticMode());
136 void CPropertiesWnd::InitPropList()
138 SetPropListFont();
140 m_wndPropList.EnableHeaderCtrl(FALSE);
141 m_wndPropList.EnableDescriptionArea();
142 m_wndPropList.SetVSDotNetLook();
143 m_wndPropList.MarkModifiedProperties();
145 CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(_T("Basic Info"));
148 m_CommitHash = new CMFCPropertyGridProperty(
149 _T("Commit Hash"),
150 _T(""),
151 _T("Commit Hash")
153 pGroup1->AddSubItem(m_CommitHash);
155 m_AuthorName = new CMFCPropertyGridProperty(
156 _T("Author"),
157 _T(""),
158 _T("Author")
160 pGroup1->AddSubItem(m_AuthorName);
162 m_AuthorDate = new CMFCPropertyGridProperty(
163 _T("Author Date"),
164 _T(""),
165 _T("Author Date")
167 pGroup1->AddSubItem(m_AuthorDate);
169 m_AuthorEmail= new CMFCPropertyGridProperty(
170 _T("Author Email"),
171 _T(""),
172 _T("Author Email")
174 pGroup1->AddSubItem(m_AuthorEmail);
176 m_CommitterName = new CMFCPropertyGridProperty(
177 _T("Committer Name"),
178 _T(""),
179 _T("Committer Name")
181 pGroup1->AddSubItem(m_CommitterName);
183 m_CommitterEmail =new CMFCPropertyGridProperty(
184 _T("Committer Email"),
185 _T(""),
186 _T("Committer Email")
188 pGroup1->AddSubItem(m_CommitterEmail);
190 m_CommitterDate = new CMFCPropertyGridProperty(
191 _T("Committer Date"),
192 _T(""),
193 _T("Committer Date")
195 pGroup1->AddSubItem(m_CommitterDate);
197 m_Subject = new CMFCPropertyGridProperty(
198 _T("Subject"),
199 _T(""),
200 _T("Subject")
201 );;;
202 pGroup1->AddSubItem(m_Subject);
204 m_Body = new CMFCPropertyGridProperty(
205 _T("Body"),
206 _T(""),
207 _T("Body")
208 );;;;
209 pGroup1->AddSubItem(m_Body);
211 for(int i=0;i<pGroup1->GetSubItemsCount();i++)
213 pGroup1->GetSubItem(i)->AllowEdit(FALSE);
216 //std::vector<CMFCPropertyGridProperty*> m_ParentHash;
217 //std::vector<CMFCPropertyGridProperty*> m_ParentSubject;
219 m_wndPropList.AddProperty(pGroup1);
220 m_BaseInfoGroup=pGroup1;
222 m_ParentGroup=new CMFCPropertyGridProperty(_T("Parent(s)"));
224 m_wndPropList.AddProperty(m_ParentGroup);
225 #if 0
226 pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("Caption"), (_variant_t) _T("About"), _T("Specifies the text that will be displayed in the window's title bar")));
230 CMFCPropertyGridProperty* pSize = new CMFCPropertyGridProperty(_T("Window Size"), 0, TRUE);
232 pProp = new CMFCPropertyGridProperty(_T("Height"), (_variant_t) 250l, _T("Specifies the window's height"));
233 pProp->EnableSpinControl(TRUE, 0, 1000);
234 pSize->AddSubItem(pProp);
236 pProp = new CMFCPropertyGridProperty( _T("Width"), (_variant_t) 150l, _T("Specifies the window's width"));
237 pProp->EnableSpinControl();
238 pSize->AddSubItem(pProp);
240 m_wndPropList.AddProperty(pSize);
242 CMFCPropertyGridProperty* pGroup2 = new CMFCPropertyGridProperty(_T("Font"));
244 LOGFONT lf;
245 CFont* font = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
246 font->GetLogFont(&lf);
248 lstrcpy(lf.lfFaceName, _T("Arial"));
250 pGroup2->AddSubItem(new CMFCPropertyGridFontProperty(_T("Font"), lf, CF_EFFECTS | CF_SCREENFONTS, _T("Specifies the default font for the window")));
251 pGroup2->AddSubItem(new CMFCPropertyGridProperty(_T("Use System Font"), (_variant_t) true, _T("Specifies that the window uses MS Shell Dlg font")));
253 m_wndPropList.AddProperty(pGroup2);
255 CMFCPropertyGridProperty* pGroup3 = new CMFCPropertyGridProperty(_T("Misc"));
256 pProp = new CMFCPropertyGridProperty(_T("(Name)"), _T("Application"));
257 pProp->Enable(FALSE);
258 pGroup3->AddSubItem(pProp);
260 CMFCPropertyGridColorProperty* pColorProp = new CMFCPropertyGridColorProperty(_T("Window Color"), RGB(210, 192, 254), NULL, _T("Specifies the default window color"));
261 pColorProp->EnableOtherButton(_T("Other..."));
262 pColorProp->EnableAutomaticButton(_T("Default"), ::GetSysColor(COLOR_3DFACE));
263 pGroup3->AddSubItem(pColorProp);
265 static TCHAR BASED_CODE szFilter[] = _T("Icon Files(*.ico)|*.ico|All Files(*.*)|*.*||");
266 pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("Icon"), TRUE, _T(""), _T("ico"), 0, szFilter, _T("Specifies the window icon")));
268 pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("Folder"), _T("c:\\")));
270 m_wndPropList.AddProperty(pGroup3);
272 CMFCPropertyGridProperty* pGroup4 = new CMFCPropertyGridProperty(_T("Hierarchy"));
274 CMFCPropertyGridProperty* pGroup41 = new CMFCPropertyGridProperty(_T("First sub-level"));
275 pGroup4->AddSubItem(pGroup41);
277 CMFCPropertyGridProperty* pGroup411 = new CMFCPropertyGridProperty(_T("Second sub-level"));
278 pGroup41->AddSubItem(pGroup411);
280 pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Item 1"), (_variant_t) _T("Value 1"), _T("This is a description")));
281 pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Item 2"), (_variant_t) _T("Value 2"), _T("This is a description")));
282 pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Item 3"), (_variant_t) _T("Value 3"), _T("This is a description")));
284 pGroup4->Expand(FALSE);
285 m_wndPropList.AddProperty(pGroup4);
286 #endif
289 void CPropertiesWnd::OnSetFocus(CWnd* pOldWnd)
291 CDockablePane::OnSetFocus(pOldWnd);
292 m_wndPropList.SetFocus();
295 void CPropertiesWnd::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
297 CDockablePane::OnSettingChange(uFlags, lpszSection);
298 SetPropListFont();
301 void CPropertiesWnd::SetPropListFont()
303 ::DeleteObject(m_fntPropList.Detach());
305 LOGFONT lf;
306 afxGlobalData.fontRegular.GetLogFont(&lf);
308 NONCLIENTMETRICS info;
309 info.cbSize = sizeof(info);
311 afxGlobalData.GetNonClientMetrics(info);
313 lf.lfHeight = info.lfMenuFont.lfHeight;
314 lf.lfWeight = info.lfMenuFont.lfWeight;
315 lf.lfItalic = info.lfMenuFont.lfItalic;
317 m_fntPropList.CreateFontIndirect(&lf);
319 m_wndPropList.SetFont(&m_fntPropList);
321 void CPropertiesWnd::RemoveParent()
323 m_ParentGroup->Expand(false);
324 for(int i=0;i<m_ParentGroup->GetSubItemsCount();i++)
326 CMFCPropertyGridProperty * p=m_ParentGroup->GetSubItem(0);
327 m_ParentGroup->RemoveSubItem(p);
331 void CPropertiesWnd::UpdateProperties(GitRev *rev)
333 if(rev)
335 m_CommitHash->SetValue(rev->m_CommitHash.ToString());
336 m_AuthorName->SetValue(rev->GetAuthorName());
337 m_AuthorDate->SetValue(rev->GetAuthorDate().Format(_T("%Y-%m-%d %H:%M")));
338 m_AuthorEmail->SetValue(rev->GetAuthorEmail());
340 m_CommitterName->SetValue(rev->GetAuthorName());
341 m_CommitterEmail->SetValue(rev->GetCommitterEmail());
342 m_CommitterDate->SetValue(rev->GetCommitterDate().Format(_T("%Y-%m-%d %H:%M")));
344 m_Subject->SetValue(rev->GetSubject());
345 m_Body->SetValue(rev->GetBody().Trim());
347 RemoveParent();
349 m_ParentGroup;
351 CLogDataVector *pLogEntry = &((CMainFrame*)AfxGetApp()->GetMainWnd())->m_wndOutput.m_LogList.m_logEntries;
353 for(unsigned int i=0;i<rev->m_ParentHash.size();i++)
355 CString str;
356 CString parentsubject;
358 GitRev *p =NULL;
360 if( pLogEntry->m_pLogCache->m_HashMap.find(rev->m_ParentHash[i]) == pLogEntry->m_pLogCache->m_HashMap.end())
362 p=NULL;
364 else
366 p= &pLogEntry->m_pLogCache->m_HashMap[rev->m_ParentHash[i]] ;
368 if(p)
369 parentsubject=p->GetSubject();
371 str.Format(_T("%d - %s \n %s"),i,rev->m_ParentHash[i].ToString(),parentsubject);
373 CMFCPropertyGridProperty*pProtery=new CMFCPropertyGridProperty(
374 rev->m_ParentHash[i].ToString().Left(8),
375 parentsubject,
378 pProtery->AllowEdit(FALSE);
379 m_ParentGroup->AddSubItem(pProtery);
381 m_ParentGroup->Expand();
382 for(int i=0;i<m_BaseInfoGroup->GetSubItemsCount();i++)
383 m_BaseInfoGroup->GetSubItem(i)->SetDescription(m_BaseInfoGroup->GetSubItem(i)->GetValue());
386 else
388 m_CommitHash->SetValue(_T(""));
389 m_AuthorName->SetValue(_T(""));
390 m_AuthorDate->SetValue(_T(""));
391 m_AuthorEmail->SetValue(_T(""));
393 m_CommitterName->SetValue(_T(""));
394 m_CommitterEmail->SetValue(_T(""));
395 m_CommitterDate->SetValue(_T(""));
397 m_Subject->SetValue(_T(""));
398 m_Body->SetValue(_T(""));
400 RemoveParent();
402 for(int i=0;i<m_BaseInfoGroup->GetSubItemsCount();i++)
403 m_BaseInfoGroup->GetSubItem(i)->SetDescription(_T(""));
405 this->Invalidate();
406 m_wndPropList.Invalidate();