OSDN Git Service

Fix git blame log dialog show nothing
[tortoisegit/TortoiseGitJp.git] / src / TortoiseGitBlame / PropertiesWnd.cpp
1 \r
2 #include "stdafx.h"\r
3 \r
4 #include "PropertiesWnd.h"\r
5 #include "Resource.h"\r
6 #include "MainFrm.h"\r
7 #include "TortoiseGitBlame.h"\r
8 \r
9 #ifdef _DEBUG\r
10 #undef THIS_FILE\r
11 static char THIS_FILE[]=__FILE__;\r
12 #define new DEBUG_NEW\r
13 #endif\r
14 \r
15 /////////////////////////////////////////////////////////////////////////////\r
16 // CResourceViewBar\r
17 \r
18 CPropertiesWnd::CPropertiesWnd()\r
19 {\r
20 }\r
21 \r
22 CPropertiesWnd::~CPropertiesWnd()\r
23 {\r
24 }\r
25 \r
26 BEGIN_MESSAGE_MAP(CPropertiesWnd, CDockablePane)\r
27         ON_WM_CREATE()\r
28         ON_WM_SIZE()\r
29         ON_COMMAND(ID_EXPAND_ALL, OnExpandAllProperties)\r
30         ON_UPDATE_COMMAND_UI(ID_EXPAND_ALL, OnUpdateExpandAllProperties)\r
31         ON_COMMAND(ID_SORTPROPERTIES, OnSortProperties)\r
32         ON_UPDATE_COMMAND_UI(ID_SORTPROPERTIES, OnUpdateSortProperties)\r
33         ON_COMMAND(ID_PROPERTIES1, OnProperties1)\r
34         ON_UPDATE_COMMAND_UI(ID_PROPERTIES1, OnUpdateProperties1)\r
35         ON_COMMAND(ID_PROPERTIES2, OnProperties2)\r
36         ON_UPDATE_COMMAND_UI(ID_PROPERTIES2, OnUpdateProperties2)\r
37         ON_WM_SETFOCUS()\r
38         ON_WM_SETTINGCHANGE()\r
39 END_MESSAGE_MAP()\r
40 \r
41 /////////////////////////////////////////////////////////////////////////////\r
42 // CResourceViewBar message handlers\r
43 \r
44 void CPropertiesWnd::AdjustLayout()\r
45 {\r
46         if (GetSafeHwnd() == NULL)\r
47         {\r
48                 return;\r
49         }\r
50 \r
51         CRect rectClient,rectCombo;\r
52         GetClientRect(rectClient);\r
53 \r
54         m_wndObjectCombo.GetWindowRect(&rectCombo);\r
55 \r
56         int cyCmb = rectCombo.Size().cy;\r
57         int cyTlb = m_wndToolBar.CalcFixedLayout(FALSE, TRUE).cy;\r
58 \r
59         m_wndObjectCombo.SetWindowPos(NULL, rectClient.left, rectClient.top, rectClient.Width(), 200, SWP_NOACTIVATE | SWP_NOZORDER);\r
60         m_wndToolBar.SetWindowPos(NULL, rectClient.left, rectClient.top + cyCmb, rectClient.Width(), cyTlb, SWP_NOACTIVATE | SWP_NOZORDER);\r
61         m_wndPropList.SetWindowPos(NULL, rectClient.left, rectClient.top + cyCmb + cyTlb, rectClient.Width(), rectClient.Height() -(cyCmb+cyTlb), SWP_NOACTIVATE | SWP_NOZORDER);\r
62 }\r
63 \r
64 int CPropertiesWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)\r
65 {\r
66         if (CDockablePane::OnCreate(lpCreateStruct) == -1)\r
67                 return -1;\r
68 \r
69         CRect rectDummy;\r
70         rectDummy.SetRectEmpty();\r
71 \r
72         // Create combo:\r
73         const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_BORDER | CBS_SORT | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;\r
74 \r
75         if (!m_wndObjectCombo.Create(dwViewStyle, rectDummy, this, 1))\r
76         {\r
77                 TRACE0("Failed to create Properties Combo \n");\r
78                 return -1;      // fail to create\r
79         }\r
80 \r
81         m_wndObjectCombo.AddString(_T("Application"));\r
82         m_wndObjectCombo.AddString(_T("Properties Window"));\r
83         m_wndObjectCombo.SetFont(CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT)));\r
84         m_wndObjectCombo.SetCurSel(0);\r
85 \r
86         if (!m_wndPropList.Create(WS_VISIBLE | WS_CHILD, rectDummy, this, 2))\r
87         {\r
88                 TRACE0("Failed to create Properties Grid \n");\r
89                 return -1;      // fail to create\r
90         }\r
91 \r
92         InitPropList();\r
93 \r
94         m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_PROPERTIES);\r
95         m_wndToolBar.LoadToolBar(IDR_PROPERTIES, 0, 0, TRUE /* Is locked */);\r
96         m_wndToolBar.CleanUpLockedImages();\r
97         m_wndToolBar.LoadBitmap(theApp.m_bHiColorIcons ? IDB_PROPERTIES_HC : IDR_PROPERTIES, 0, 0, TRUE /* Locked */);\r
98 \r
99         m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);\r
100         m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() & ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));\r
101         m_wndToolBar.SetOwner(this);\r
102 \r
103         // All commands will be routed via this control , not via the parent frame:\r
104         m_wndToolBar.SetRouteCommandsViaFrame(FALSE);\r
105 \r
106         AdjustLayout();\r
107         return 0;\r
108 }\r
109 \r
110 void CPropertiesWnd::OnSize(UINT nType, int cx, int cy)\r
111 {\r
112         CDockablePane::OnSize(nType, cx, cy);\r
113         AdjustLayout();\r
114 }\r
115 \r
116 void CPropertiesWnd::OnExpandAllProperties()\r
117 {\r
118         m_wndPropList.ExpandAll();\r
119 }\r
120 \r
121 void CPropertiesWnd::OnUpdateExpandAllProperties(CCmdUI* pCmdUI)\r
122 {\r
123 }\r
124 \r
125 void CPropertiesWnd::OnSortProperties()\r
126 {\r
127         m_wndPropList.SetAlphabeticMode(!m_wndPropList.IsAlphabeticMode());\r
128 }\r
129 \r
130 void CPropertiesWnd::OnUpdateSortProperties(CCmdUI* pCmdUI)\r
131 {\r
132         pCmdUI->SetCheck(m_wndPropList.IsAlphabeticMode());\r
133 }\r
134 \r
135 void CPropertiesWnd::OnProperties1()\r
136 {\r
137         // TODO: Add your command handler code here\r
138 }\r
139 \r
140 void CPropertiesWnd::OnUpdateProperties1(CCmdUI* /*pCmdUI*/)\r
141 {\r
142         // TODO: Add your command update UI handler code here\r
143 }\r
144 \r
145 void CPropertiesWnd::OnProperties2()\r
146 {\r
147         // TODO: Add your command handler code here\r
148 }\r
149 \r
150 void CPropertiesWnd::OnUpdateProperties2(CCmdUI* /*pCmdUI*/)\r
151 {\r
152         // TODO: Add your command update UI handler code here\r
153 }\r
154 \r
155 void CPropertiesWnd::InitPropList()\r
156 {\r
157         SetPropListFont();\r
158 \r
159         m_wndPropList.EnableHeaderCtrl(FALSE);\r
160         m_wndPropList.EnableDescriptionArea();\r
161         m_wndPropList.SetVSDotNetLook();\r
162         m_wndPropList.MarkModifiedProperties();\r
163         \r
164         CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(_T("Basic Info"));\r
165 \r
166         \r
167         m_CommitHash = new CMFCPropertyGridProperty(\r
168                                 _T("Commit Hash"), \r
169                                 _T(""),\r
170                                 _T("Commit Hash")\r
171                                 );\r
172         pGroup1->AddSubItem(m_CommitHash);\r
173 \r
174         m_AuthorName = new CMFCPropertyGridProperty(\r
175                                 _T("Author"), \r
176                                 _T(""),\r
177                                 _T("Author")\r
178                                 );\r
179         pGroup1->AddSubItem(m_AuthorName);\r
180 \r
181         m_AuthorDate = new CMFCPropertyGridProperty(\r
182                                 _T("Author Date"), \r
183                                 _T(""),\r
184                                 _T("Author Date")\r
185                                 );\r
186         pGroup1->AddSubItem(m_AuthorDate);\r
187 \r
188         m_AuthorEmail= new CMFCPropertyGridProperty(\r
189                                 _T("Author Email"), \r
190                                 _T(""),\r
191                                 _T("Author Email")\r
192                                 );\r
193         pGroup1->AddSubItem(m_AuthorEmail);\r
194 \r
195         m_CommitterName = new CMFCPropertyGridProperty(\r
196                                 _T("Committer Name"), \r
197                                 _T(""),\r
198                                 _T("Committer Name")\r
199                                 );\r
200         pGroup1->AddSubItem(m_CommitterName);\r
201 \r
202         m_CommitterEmail =new CMFCPropertyGridProperty(\r
203                                 _T("Committer Email"), \r
204                                 _T(""),\r
205                                 _T("Committer Email")\r
206                                 );\r
207         pGroup1->AddSubItem(m_CommitterEmail);\r
208 \r
209         m_CommitterDate = new CMFCPropertyGridProperty(\r
210                                 _T("Committer Date"), \r
211                                 _T(""),\r
212                                 _T("Committer Date")\r
213                                 );;\r
214         pGroup1->AddSubItem(m_CommitterDate);\r
215 \r
216         m_Subject = new CMFCPropertyGridProperty(\r
217                                 _T("Subject"), \r
218                                 _T(""),\r
219                                 _T("Subject")\r
220                                 );;;\r
221         pGroup1->AddSubItem(m_Subject);\r
222 \r
223         m_Body = new CMFCPropertyGridProperty(\r
224                                 _T("Body"), \r
225                                 _T(""),\r
226                                 _T("Body")\r
227                                 );;;;\r
228         pGroup1->AddSubItem(m_Body);\r
229 \r
230         for(int i=0;i<pGroup1->GetSubItemsCount();i++)\r
231         {\r
232                 pGroup1->GetSubItem(i)->AllowEdit(FALSE);\r
233         }\r
234 \r
235         //std::vector<CMFCPropertyGridProperty*> m_ParentHash;\r
236         //std::vector<CMFCPropertyGridProperty*> m_ParentSubject;\r
237 \r
238         m_wndPropList.AddProperty(pGroup1);\r
239         m_BaseInfoGroup=pGroup1;\r
240 \r
241         m_ParentGroup=new CMFCPropertyGridProperty(_T("Parent"));\r
242 \r
243         m_wndPropList.AddProperty(m_ParentGroup);\r
244 #if 0\r
245         pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("Caption"), (_variant_t) _T("About"), _T("Specifies the text that will be displayed in the window's title bar")));\r
246 \r
247         \r
248 \r
249         CMFCPropertyGridProperty* pSize = new CMFCPropertyGridProperty(_T("Window Size"), 0, TRUE);\r
250 \r
251         pProp = new CMFCPropertyGridProperty(_T("Height"), (_variant_t) 250l, _T("Specifies the window's height"));\r
252         pProp->EnableSpinControl(TRUE, 0, 1000);\r
253         pSize->AddSubItem(pProp);\r
254 \r
255         pProp = new CMFCPropertyGridProperty( _T("Width"), (_variant_t) 150l, _T("Specifies the window's width"));\r
256         pProp->EnableSpinControl();\r
257         pSize->AddSubItem(pProp);\r
258 \r
259         m_wndPropList.AddProperty(pSize);\r
260 \r
261         CMFCPropertyGridProperty* pGroup2 = new CMFCPropertyGridProperty(_T("Font"));\r
262 \r
263         LOGFONT lf;\r
264         CFont* font = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));\r
265         font->GetLogFont(&lf);\r
266 \r
267         lstrcpy(lf.lfFaceName, _T("Arial"));\r
268 \r
269         pGroup2->AddSubItem(new CMFCPropertyGridFontProperty(_T("Font"), lf, CF_EFFECTS | CF_SCREENFONTS, _T("Specifies the default font for the window")));\r
270         pGroup2->AddSubItem(new CMFCPropertyGridProperty(_T("Use System Font"), (_variant_t) true, _T("Specifies that the window uses MS Shell Dlg font")));\r
271 \r
272         m_wndPropList.AddProperty(pGroup2);\r
273 \r
274         CMFCPropertyGridProperty* pGroup3 = new CMFCPropertyGridProperty(_T("Misc"));\r
275         pProp = new CMFCPropertyGridProperty(_T("(Name)"), _T("Application"));\r
276         pProp->Enable(FALSE);\r
277         pGroup3->AddSubItem(pProp);\r
278 \r
279         CMFCPropertyGridColorProperty* pColorProp = new CMFCPropertyGridColorProperty(_T("Window Color"), RGB(210, 192, 254), NULL, _T("Specifies the default window color"));\r
280         pColorProp->EnableOtherButton(_T("Other..."));\r
281         pColorProp->EnableAutomaticButton(_T("Default"), ::GetSysColor(COLOR_3DFACE));\r
282         pGroup3->AddSubItem(pColorProp);\r
283 \r
284         static TCHAR BASED_CODE szFilter[] = _T("Icon Files(*.ico)|*.ico|All Files(*.*)|*.*||");\r
285         pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("Icon"), TRUE, _T(""), _T("ico"), 0, szFilter, _T("Specifies the window icon")));\r
286 \r
287         pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("Folder"), _T("c:\\")));\r
288 \r
289         m_wndPropList.AddProperty(pGroup3);\r
290 \r
291         CMFCPropertyGridProperty* pGroup4 = new CMFCPropertyGridProperty(_T("Hierarchy"));\r
292 \r
293         CMFCPropertyGridProperty* pGroup41 = new CMFCPropertyGridProperty(_T("First sub-level"));\r
294         pGroup4->AddSubItem(pGroup41);\r
295 \r
296         CMFCPropertyGridProperty* pGroup411 = new CMFCPropertyGridProperty(_T("Second sub-level"));\r
297         pGroup41->AddSubItem(pGroup411);\r
298 \r
299         pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Item 1"), (_variant_t) _T("Value 1"), _T("This is a description")));\r
300         pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Item 2"), (_variant_t) _T("Value 2"), _T("This is a description")));\r
301         pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Item 3"), (_variant_t) _T("Value 3"), _T("This is a description")));\r
302 \r
303         pGroup4->Expand(FALSE);\r
304         m_wndPropList.AddProperty(pGroup4);\r
305 #endif\r
306 }\r
307 \r
308 void CPropertiesWnd::OnSetFocus(CWnd* pOldWnd)\r
309 {\r
310         CDockablePane::OnSetFocus(pOldWnd);\r
311         m_wndPropList.SetFocus();\r
312 }\r
313 \r
314 void CPropertiesWnd::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)\r
315 {\r
316         CDockablePane::OnSettingChange(uFlags, lpszSection);\r
317         SetPropListFont();\r
318 }\r
319 \r
320 void CPropertiesWnd::SetPropListFont()\r
321 {\r
322         ::DeleteObject(m_fntPropList.Detach());\r
323 \r
324         LOGFONT lf;\r
325         afxGlobalData.fontRegular.GetLogFont(&lf);\r
326 \r
327         NONCLIENTMETRICS info;\r
328         info.cbSize = sizeof(info);\r
329 \r
330         afxGlobalData.GetNonClientMetrics(info);\r
331 \r
332         lf.lfHeight = info.lfMenuFont.lfHeight;\r
333         lf.lfWeight = info.lfMenuFont.lfWeight;\r
334         lf.lfItalic = info.lfMenuFont.lfItalic;\r
335 \r
336         m_fntPropList.CreateFontIndirect(&lf);\r
337 \r
338         m_wndPropList.SetFont(&m_fntPropList);\r
339 }\r
340 void CPropertiesWnd::RemoveParent()\r
341 {\r
342         for(int i=0;i<m_ParentGroup->GetSubItemsCount();i++)\r
343         {\r
344                 CMFCPropertyGridProperty * p=m_ParentGroup->GetSubItem(0);\r
345                 m_ParentGroup->RemoveSubItem(p);\r
346         }\r
347         \r
348 }\r
349 void CPropertiesWnd::UpdateProperties(GitRev *rev)\r
350 {\r
351         if(rev)\r
352         {\r
353                 m_CommitHash->SetValue(rev->m_CommitHash.ToString());\r
354                 m_AuthorName->SetValue(rev->m_AuthorName);\r
355                 m_AuthorDate->SetValue(rev->m_AuthorDate.Format(_T("%Y-%m-%d %H:%M")));\r
356                 m_AuthorEmail->SetValue(rev->m_AuthorEmail);    \r
357 \r
358                 m_CommitterName->SetValue(rev->m_CommitterName);\r
359                 m_CommitterEmail->SetValue(rev->m_CommitterEmail);\r
360                 m_CommitterDate->SetValue(rev->m_CommitterDate.Format(_T("%Y-%m-%d %H:%M")));\r
361 \r
362                 m_Subject->SetValue(rev->m_Subject);\r
363                 m_Body->SetValue(rev->m_Body);\r
364 \r
365                 RemoveParent();\r
366 \r
367                 m_ParentGroup;\r
368         \r
369                 CLogDataVector          *pLogEntry = &((CMainFrame*)AfxGetApp()->GetMainWnd())->m_wndOutput.m_LogList.m_logEntries;\r
370 \r
371                 for(unsigned int i=0;i<rev->m_ParentHash.size();i++)\r
372                 {\r
373                         CString str;\r
374                         CString parentsubject;\r
375                         int index;\r
376 \r
377                         if( pLogEntry->m_HashMap.find(rev->m_ParentHash[i]) == pLogEntry->m_HashMap.end() )\r
378                         { \r
379                                 index = -1;\r
380                         }\r
381                         else\r
382                         {\r
383                                 index=pLogEntry->m_HashMap[rev->m_ParentHash[i]];\r
384                         }\r
385                         if(index>=0)\r
386                                 parentsubject=pLogEntry->GetGitRevAt(index).m_Subject;\r
387 \r
388                         str.Format(_T("%d - %s \n %s"),i,rev->m_ParentHash[i].ToString(),parentsubject);\r
389                         \r
390                         CMFCPropertyGridProperty*p=new CMFCPropertyGridProperty(\r
391                                                                                         rev->m_ParentHash[i].ToString().Left(8), \r
392                                                                                                 parentsubject,\r
393                                                                                                 str\r
394                                                                                         );\r
395                         m_ParentGroup->AddSubItem(p);\r
396                         m_ParentGroup->Expand();\r
397                 }\r
398                 for(int i=0;i<m_BaseInfoGroup->GetSubItemsCount();i++)\r
399                         m_BaseInfoGroup->GetSubItem(i)->SetDescription(m_BaseInfoGroup->GetSubItem(i)->GetValue());\r
400 \r
401         }else\r
402         {\r
403                 m_CommitHash->SetValue(_T(""));\r
404                 m_AuthorName->SetValue(_T(""));\r
405                 m_AuthorDate->SetValue(_T(""));\r
406                 m_AuthorEmail->SetValue(_T(""));\r
407 \r
408                 m_CommitterName->SetValue(_T(""));\r
409                 m_CommitterEmail->SetValue(_T(""));\r
410                 m_CommitterDate->SetValue(_T(""));\r
411 \r
412                 m_Subject->SetValue(_T(""));\r
413                 m_Body->SetValue(_T(""));\r
414 \r
415                 RemoveParent();\r
416                 //m_ParentGroup;\r
417 \r
418                 //m_ParentHash->SetValue(_T(""));\r
419                 //m_ParentSubject->SetValue(_T(""));            \r
420                 for(int i=0;i<m_BaseInfoGroup->GetSubItemsCount();i++)\r
421                         m_BaseInfoGroup->GetSubItem(i)->SetDescription(_T(""));\r
422         }\r
423         this->Invalidate();\r
424         m_wndPropList.Invalidate();\r
425 }