Fixed issue #1571: Warn author not set when editing notes
[TortoiseGit.git] / src / TortoiseGitBlame / PropertiesWnd.cpp
blob69f4313f78a630e7356cda4fa81cf623b981f030
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()
44 CPropertiesWnd::~CPropertiesWnd()
48 BEGIN_MESSAGE_MAP(CPropertiesWnd, CDockablePane)
49 ON_WM_CREATE()
50 ON_WM_SIZE()
51 ON_WM_SETFOCUS()
52 ON_WM_SETTINGCHANGE()
53 ON_WM_CONTEXTMENU()
54 END_MESSAGE_MAP()
56 /////////////////////////////////////////////////////////////////////////////
57 // CResourceViewBar message handlers
59 void CPropertiesWnd::AdjustLayout()
61 if (GetSafeHwnd() == NULL)
63 return;
66 CRect rectClient,rectCombo;
67 GetClientRect(rectClient);
69 m_wndPropList.SetWindowPos(NULL, rectClient.left, rectClient.top, rectClient.Width(), rectClient.Height(), SWP_NOACTIVATE | SWP_NOZORDER);
72 int CPropertiesWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
74 if (CDockablePane::OnCreate(lpCreateStruct) == -1)
75 return -1;
77 CRect rectDummy;
78 rectDummy.SetRectEmpty();
80 // Create combo:
81 const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_BORDER | CBS_SORT | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
83 if (!m_wndPropList.Create(WS_VISIBLE | WS_CHILD, rectDummy, this, 2))
85 TRACE0("Failed to create Properties Grid \n");
86 return -1; // fail to create
89 InitPropList();
91 AdjustLayout();
92 return 0;
95 void CPropertiesWnd::OnSize(UINT nType, int cx, int cy)
97 CDockablePane::OnSize(nType, cx, cy);
98 AdjustLayout();
101 void CPropertiesWnd::InitPropList()
103 SetPropListFont();
105 m_wndPropList.EnableHeaderCtrl(FALSE);
106 m_wndPropList.EnableDescriptionArea();
107 m_wndPropList.SetVSDotNetLook();
108 m_wndPropList.MarkModifiedProperties();
110 CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(CString(MAKEINTRESOURCE(IDS_PROPERTIES_BASICINFO)));
113 m_CommitHash = new CMFCPropertyGridProperty(
114 CString(MAKEINTRESOURCE(IDS_LOG_HASH)),
115 _T(""),
116 CString(MAKEINTRESOURCE(IDS_LOG_HASH))
118 pGroup1->AddSubItem(m_CommitHash);
120 m_AuthorName = new CMFCPropertyGridProperty(
121 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR)),
122 _T(""),
123 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR))
125 pGroup1->AddSubItem(m_AuthorName);
127 m_AuthorDate = new CMFCPropertyGridProperty(
128 CString(MAKEINTRESOURCE(IDS_LOG_DATE)),
129 _T(""),
130 CString(MAKEINTRESOURCE(IDS_LOG_DATE))
132 pGroup1->AddSubItem(m_AuthorDate);
134 m_AuthorEmail= new CMFCPropertyGridProperty(
135 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL)),
136 _T(""),
137 CString(MAKEINTRESOURCE(IDS_LOG_EMAIL))
139 pGroup1->AddSubItem(m_AuthorEmail);
141 m_CommitterName = new CMFCPropertyGridProperty(
142 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_NAME)),
143 _T(""),
144 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_NAME))
146 pGroup1->AddSubItem(m_CommitterName);
148 m_CommitterEmail =new CMFCPropertyGridProperty(
149 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_EMAIL)),
150 _T(""),
151 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_EMAIL))
153 pGroup1->AddSubItem(m_CommitterEmail);
155 m_CommitterDate = new CMFCPropertyGridProperty(
156 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_DATE)),
157 _T(""),
158 CString(MAKEINTRESOURCE(IDS_LOG_COMMIT_DATE))
160 pGroup1->AddSubItem(m_CommitterDate);
162 m_Subject = new CMFCPropertyGridProperty(
163 CString(MAKEINTRESOURCE(IDS_SUBJECT)),
164 _T(""),
165 CString(MAKEINTRESOURCE(IDS_SUBJECT))
166 );;;
167 pGroup1->AddSubItem(m_Subject);
169 m_Body = new CMFCPropertyGridProperty(
170 CString(MAKEINTRESOURCE(IDS_BODY)),
171 _T(""),
172 CString(MAKEINTRESOURCE(IDS_BODY))
173 );;;;
174 pGroup1->AddSubItem(m_Body);
176 for(int i=0;i<pGroup1->GetSubItemsCount();i++)
178 pGroup1->GetSubItem(i)->AllowEdit(FALSE);
181 m_wndPropList.AddProperty(pGroup1);
182 m_BaseInfoGroup=pGroup1;
184 m_ParentGroup=new CMFCPropertyGridProperty(CString(MAKEINTRESOURCE(IDS_PARENTS)));
186 m_wndPropList.AddProperty(m_ParentGroup);
189 void CPropertiesWnd::OnSetFocus(CWnd* pOldWnd)
191 CDockablePane::OnSetFocus(pOldWnd);
192 m_wndPropList.SetFocus();
195 void CPropertiesWnd::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
197 CDockablePane::OnSettingChange(uFlags, lpszSection);
198 SetPropListFont();
201 void CPropertiesWnd::SetPropListFont()
203 ::DeleteObject(m_fntPropList.Detach());
205 LOGFONT lf;
206 afxGlobalData.fontRegular.GetLogFont(&lf);
208 NONCLIENTMETRICS info;
209 info.cbSize = sizeof(info);
211 afxGlobalData.GetNonClientMetrics(info);
213 lf.lfHeight = info.lfMenuFont.lfHeight;
214 lf.lfWeight = info.lfMenuFont.lfWeight;
215 lf.lfItalic = info.lfMenuFont.lfItalic;
217 m_fntPropList.CreateFontIndirect(&lf);
219 m_wndPropList.SetFont(&m_fntPropList);
221 void CPropertiesWnd::RemoveParent()
223 m_ParentGroup->Expand(false);
224 for(int i=0;i<m_ParentGroup->GetSubItemsCount();i++)
226 CMFCPropertyGridProperty * p=m_ParentGroup->GetSubItem(0);
227 m_ParentGroup->RemoveSubItem(p);
231 void CPropertiesWnd::UpdateProperties(GitRev *rev)
233 if(rev)
235 m_CommitHash->SetValue(rev->m_CommitHash.ToString());
236 m_AuthorName->SetValue(rev->GetAuthorName());
237 m_AuthorDate->SetValue(rev->GetAuthorDate().Format(_T("%Y-%m-%d %H:%M")));
238 m_AuthorEmail->SetValue(rev->GetAuthorEmail());
240 m_CommitterName->SetValue(rev->GetAuthorName());
241 m_CommitterEmail->SetValue(rev->GetCommitterEmail());
242 m_CommitterDate->SetValue(rev->GetCommitterDate().Format(_T("%Y-%m-%d %H:%M")));
244 m_Subject->SetValue(rev->GetSubject());
245 m_Body->SetValue(rev->GetBody().Trim());
247 RemoveParent();
249 m_ParentGroup;
251 CLogDataVector *pLogEntry = &((CMainFrame*)AfxGetApp()->GetMainWnd())->m_wndOutput.m_LogList.m_logEntries;
253 for(unsigned int i=0;i<rev->m_ParentHash.size();i++)
255 CString str;
256 CString parentsubject;
258 GitRev *p =NULL;
260 if( pLogEntry->m_pLogCache->m_HashMap.find(rev->m_ParentHash[i]) == pLogEntry->m_pLogCache->m_HashMap.end())
262 p=NULL;
264 else
266 p= &pLogEntry->m_pLogCache->m_HashMap[rev->m_ParentHash[i]] ;
268 if(p)
269 parentsubject=p->GetSubject();
271 str.Format(_T("%d - %s \n %s"),i,rev->m_ParentHash[i].ToString(),parentsubject);
273 CMFCPropertyGridProperty*pProtery=new CMFCPropertyGridProperty(
274 rev->m_ParentHash[i].ToString().Left(8),
275 parentsubject,
278 pProtery->AllowEdit(FALSE);
279 m_ParentGroup->AddSubItem(pProtery);
281 m_ParentGroup->Expand();
282 for(int i=0;i<m_BaseInfoGroup->GetSubItemsCount();i++)
283 m_BaseInfoGroup->GetSubItem(i)->SetDescription(m_BaseInfoGroup->GetSubItem(i)->GetValue());
286 else
288 m_CommitHash->SetValue(_T(""));
289 m_AuthorName->SetValue(_T(""));
290 m_AuthorDate->SetValue(_T(""));
291 m_AuthorEmail->SetValue(_T(""));
293 m_CommitterName->SetValue(_T(""));
294 m_CommitterEmail->SetValue(_T(""));
295 m_CommitterDate->SetValue(_T(""));
297 m_Subject->SetValue(_T(""));
298 m_Body->SetValue(_T(""));
300 RemoveParent();
302 for(int i=0;i<m_BaseInfoGroup->GetSubItemsCount();i++)
303 m_BaseInfoGroup->GetSubItem(i)->SetDescription(_T(""));
305 this->Invalidate();
306 m_wndPropList.Invalidate();
309 void CPropertiesWnd::OnContextMenu(CWnd* pWnd, CPoint point)
311 CMFCPropertyGridProperty * pProtery = m_wndPropList.GetCurSel();
313 CString sMenuItemText;
314 CIconMenu popup;
315 if (pProtery && !pProtery->IsGroup() && popup.CreatePopupMenu())
317 sMenuItemText.LoadString(IDS_SCIEDIT_COPY);
318 popup.AppendMenu(MF_STRING | MF_ENABLED, WM_COPY, sMenuItemText);
320 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
321 switch (cmd)
323 case 0:
324 break; // no command selected
325 case WM_COPY:
326 CStringUtils::WriteAsciiStringToClipboard(pProtery->GetValue(), GetSafeHwnd());
327 break;