OSDN Git Service

04ebca90e65b1455d2d1a28ee6f05f9a65c7024c
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / GitLogListBase.cpp
1 // GitLogList.cpp : implementation file\r
2 //\r
3 /*\r
4         Description: qgit revision list view\r
5 \r
6         Author: Marco Costalba (C) 2005-2007\r
7 \r
8         Copyright: See COPYING file that comes with this distribution\r
9 \r
10 */\r
11 #include "stdafx.h"\r
12 #include "GitLogListBase.h"\r
13 #include "GitRev.h"\r
14 //#include "VssStyle.h"\r
15 #include "IconMenu.h"\r
16 // CGitLogListBase\r
17 #include "cursor.h"\r
18 #include "InputDlg.h"\r
19 #include "PropDlg.h"\r
20 #include "SVNProgressDlg.h"\r
21 #include "ProgressDlg.h"\r
22 //#include "RepositoryBrowser.h"\r
23 //#include "CopyDlg.h"\r
24 //#include "StatGraphDlg.h"\r
25 #include "Logdlg.h"\r
26 #include "MessageBox.h"\r
27 #include "Registry.h"\r
28 #include "AppUtils.h"\r
29 #include "PathUtils.h"\r
30 #include "StringUtils.h"\r
31 #include "UnicodeUtils.h"\r
32 #include "TempFile.h"\r
33 //#include "GitInfo.h"\r
34 //#include "GitDiff.h"\r
35 #include "IconMenu.h"\r
36 //#include "RevisionRangeDlg.h"\r
37 //#include "BrowseFolder.h"\r
38 //#include "BlameDlg.h"\r
39 //#include "Blame.h"\r
40 //#include "GitHelpers.h"\r
41 #include "GitStatus.h"\r
42 //#include "LogDlgHelper.h"\r
43 //#include "CachedLogInfo.h"\r
44 //#include "RepositoryInfo.h"\r
45 //#include "EditPropertiesDlg.h"\r
46 #include "FileDiffDlg.h"\r
47 #include "..\\TortoiseShell\\Resource.h"\r
48 \r
49 \r
50 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)\r
51 \r
52 CGitLogListBase::CGitLogListBase():CHintListCtrl()\r
53         ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)\r
54         ,m_nSearchIndex(0)\r
55         ,m_bNoDispUpdates(FALSE)\r
56         , m_bThreadRunning(FALSE)\r
57         , m_bStrictStopped(false)\r
58         , m_pStoreSelection(NULL)\r
59         , m_nSelectedFilter(LOGFILTER_ALL)\r
60         , m_bVista(false)\r
61         , m_bShowWC(false)\r
62 {\r
63         // use the default GUI font, create a copy of it and\r
64         // change the copy to BOLD (leave the rest of the font\r
65         // the same)\r
66         HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);\r
67         LOGFONT lf = {0};\r
68         GetObject(hFont, sizeof(LOGFONT), &lf);\r
69         lf.lfWeight = FW_BOLD;\r
70         m_boldFont = CreateFontIndirect(&lf);\r
71         \r
72         m_bShowBugtraqColumn=0;\r
73 \r
74         m_IsIDReplaceAction=FALSE;\r
75 \r
76         m_wcRev.m_CommitHash=GIT_REV_ZERO;\r
77         m_wcRev.m_Subject=_T("Working dir changes");\r
78         m_wcRev.m_ParentHash.clear();\r
79         m_wcRev.m_Mark=_T('-');\r
80         m_wcRev.m_IsUpdateing=FALSE;\r
81         m_wcRev.m_IsFull = TRUE;\r
82 \r
83         m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
84         m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
85         m_hAddedIcon    =  (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
86         m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
87 \r
88         m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);\r
89 \r
90         g_Git.GetMapHashToFriendName(m_HashMap);\r
91         m_CurrentBranch=g_Git.GetCurrentBranch();\r
92         this->m_HeadHash=g_Git.GetHash(CString(_T("HEAD"))).Left(40);\r
93 \r
94         m_From=CTime(1970,1,2,0,0,0);\r
95         m_To=CTime::GetCurrentTime();\r
96     m_ShowMask = 0;\r
97         m_LoadingThread = NULL;\r
98 \r
99         m_bExitThread=FALSE;\r
100         m_IsOldFirst = FALSE;\r
101         m_IsRebaseReplaceGraph = FALSE;\r
102 \r
103 \r
104         for(int i=0;i<Lanes::COLORS_NUM;i++)\r
105         {\r
106                 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));\r
107         }\r
108         // get short/long datetime setting from registry\r
109         DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);\r
110         if ( RegUseShortDateFormat )\r
111         {\r
112                 m_DateFormat = DATE_SHORTDATE;\r
113         }\r
114         else\r
115         {\r
116                 m_DateFormat = DATE_LONGDATE;\r
117         }\r
118         // get relative time display setting from registry\r
119         DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);\r
120         m_bRelativeTimes = (regRelativeTimes != 0);\r
121         m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;\r
122 \r
123         m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);\r
124         m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);\r
125         m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);\r
126         m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);\r
127 \r
128         OSVERSIONINFOEX inf;\r
129         SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));\r
130         inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);\r
131         GetVersionEx((OSVERSIONINFO *)&inf);\r
132         WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);\r
133         m_bVista = (fullver >= 0x0600);\r
134 \r
135         m_ColumnRegKey=_T("log");\r
136 }\r
137 \r
138 CGitLogListBase::~CGitLogListBase()\r
139 {\r
140         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
141 \r
142         DestroyIcon(m_hModifiedIcon);\r
143         DestroyIcon(m_hReplacedIcon);\r
144         DestroyIcon(m_hAddedIcon);\r
145         DestroyIcon(m_hDeletedIcon);\r
146         m_logEntries.ClearAll();\r
147 \r
148         if (m_boldFont)\r
149                 DeleteObject(m_boldFont);\r
150 \r
151         if ( m_pStoreSelection )\r
152         {\r
153                 delete m_pStoreSelection;\r
154                 m_pStoreSelection = NULL;\r
155         }\r
156 \r
157         if(this->m_bThreadRunning)\r
158         {\r
159                 m_bExitThread=true;\r
160                 WaitForSingleObject(m_LoadingThread->m_hThread,1000);\r
161                 TerminateThread();\r
162         }\r
163 }\r
164 \r
165 \r
166 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)\r
167         ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)\r
168         ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)\r
169         ON_WM_CONTEXTMENU()\r
170         ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)\r
171         ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)\r
172         ON_WM_CREATE()\r
173         ON_WM_DESTROY()\r
174         ON_MESSAGE(MSG_LOADED,OnLoad)\r
175         ON_WM_MEASUREITEM()\r
176         ON_WM_MEASUREITEM_REFLECT()\r
177 END_MESSAGE_MAP()\r
178 \r
179 void CGitLogListBase::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)\r
180 {\r
181         // TODO: ÔÚ´ËÌí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂëºÍ/»òµ÷ÓÃĬÈÏÖµ\r
182 \r
183         CListCtrl::OnMeasureItem(nIDCtl, lpMeasureItemStruct);\r
184 }\r
185 \r
186 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)\r
187 {\r
188         //if (m_nRowHeight>0)\r
189         {\r
190                 lpMeasureItemStruct->itemHeight = 50;\r
191         }\r
192 }\r
193 \r
194 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)\r
195 {\r
196         PreSubclassWindow();\r
197         return CHintListCtrl::OnCreate(lpCreateStruct);\r
198 }\r
199 \r
200 void CGitLogListBase::PreSubclassWindow()\r
201 {\r
202         SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);\r
203         // load the icons for the action columns\r
204 //      m_Theme.Open(m_hWnd, L"ListView");\r
205         m_Theme.Open(m_hWnd, L"Explorer::ListView;ListView");\r
206         m_Theme.SetWindowTheme(m_hWnd, L"Explorer", NULL);\r
207         CHintListCtrl::PreSubclassWindow();\r
208 }\r
209 \r
210 void CGitLogListBase::InsertGitColumn()\r
211 {\r
212         CString temp;\r
213 \r
214         int c = GetHeaderCtrl()->GetItemCount()-1;\r
215         \r
216         while (c>=0)\r
217                 DeleteColumn(c--);\r
218         temp.LoadString(IDS_LOG_GRAPH);\r
219 \r
220         if(m_IsRebaseReplaceGraph)\r
221         {\r
222                 temp=_T("Rebase");\r
223         }\r
224         else\r
225         {\r
226                 temp.LoadString(IDS_LOG_GRAPH);\r
227         }\r
228         InsertColumn(this->LOGLIST_GRAPH, temp);\r
229         \r
230 #if 0   \r
231         // make the revision column right aligned\r
232         LVCOLUMN Column;\r
233         Column.mask = LVCF_FMT;\r
234         Column.fmt = LVCFMT_RIGHT;\r
235         SetColumn(0, &Column); \r
236 #endif  \r
237 //      CString log;\r
238 //      g_Git.GetLog(log);\r
239 \r
240         if(m_IsIDReplaceAction)\r
241         {\r
242                 temp.LoadString(IDS_LOG_ID);\r
243                 InsertColumn(this->LOGLIST_ACTION, temp);\r
244         }\r
245         else\r
246         {\r
247                 temp.LoadString(IDS_LOG_ACTIONS);\r
248                 InsertColumn(this->LOGLIST_ACTION, temp);\r
249         }\r
250         temp.LoadString(IDS_LOG_MESSAGE);\r
251         InsertColumn(this->LOGLIST_MESSAGE, temp);\r
252         \r
253         temp.LoadString(IDS_LOG_AUTHOR);\r
254         InsertColumn(this->LOGLIST_AUTHOR, temp);\r
255         \r
256         temp.LoadString(IDS_LOG_DATE);\r
257         InsertColumn(this->LOGLIST_DATE, temp);\r
258         \r
259 \r
260         if (m_bShowBugtraqColumn)\r
261         {\r
262 //              temp = m_ProjectProperties.sLabel;\r
263                 if (temp.IsEmpty())\r
264                         temp.LoadString(IDS_LOG_BUGIDS);\r
265                 InsertColumn(this->LOGLIST_BUG, temp);\r
266 \r
267         }\r
268         \r
269         SetRedraw(false);\r
270         ResizeAllListCtrlCols();\r
271         SetRedraw(true);\r
272 \r
273 }\r
274 \r
275 /**\r
276  * Resizes all columns in a list control to values in registry.\r
277  */\r
278 void CGitLogListBase::ResizeAllListCtrlCols()\r
279 {\r
280         // column max and min widths to allow\r
281         static const int nMinimumWidth = 10;\r
282         static const int nMaximumWidth = 1000;\r
283         CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));\r
284         if (pHdrCtrl)\r
285         {\r
286                 int numcols = pHdrCtrl->GetItemCount();\r
287                 for (int col = 0; col < numcols; col++)\r
288                 {\r
289                         // get width for this col last time from registry\r
290                         CString regentry;\r
291                         regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);\r
292                         CRegDWORD regwidth(regentry, 0);\r
293                         int cx = regwidth;\r
294                         if ( cx == 0 )\r
295                         {\r
296                                 // no saved value, setup sensible defaults\r
297                                 if (col == this->LOGLIST_MESSAGE)\r
298                                 {\r
299                                         cx = LOGLIST_MESSAGE_MIN;\r
300                                 }\r
301                                 else\r
302                                 {\r
303                                         cx = ICONITEMBORDER+16*4;\r
304                                 }\r
305                         }\r
306                         if (cx < nMinimumWidth)\r
307                         {\r
308                                 cx = nMinimumWidth;\r
309                         } else if (cx > nMaximumWidth)\r
310                         {\r
311                                 cx = nMaximumWidth;\r
312                         }\r
313 \r
314                         SetColumnWidth(col, cx);\r
315                 }\r
316         }\r
317 \r
318 }\r
319 \r
320 \r
321 BOOL CGitLogListBase::GetShortName(CString ref, CString &shortname,CString prefix)\r
322 {\r
323         TRACE(_T("%s %s\r\n"),ref,prefix);\r
324         if(ref.Left(prefix.GetLength()) ==  prefix)\r
325         {\r
326                 shortname = ref.Right(ref.GetLength()-prefix.GetLength());\r
327                 if(shortname.Right(3)==_T("^{}"))\r
328                         shortname=shortname.Left(shortname.GetLength()-3);\r
329                 return TRUE;\r
330         }\r
331         return FALSE;\r
332 }\r
333 \r
334 void CGitLogListBase::FillBackGround(HDC hdc, int Index,CRect &rect)\r
335 {       \r
336 //      HBRUSH brush;\r
337         LVITEM   rItem;\r
338         SecureZeroMemory(&rItem, sizeof(LVITEM));\r
339         rItem.mask  = LVIF_STATE;\r
340         rItem.iItem = Index;\r
341         rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;\r
342         GetItem(&rItem);\r
343 \r
344         GitRev* pLogEntry = (GitRev*)m_arShownList.GetAt(Index);\r
345         HBRUSH brush = NULL;\r
346 \r
347         \r
348         if (m_Theme.IsAppThemed() && m_bVista)\r
349         {\r
350                 int state = LISS_NORMAL;\r
351                 if (rItem.state & LVIS_SELECTED)\r
352                 {\r
353                         if (::GetFocus() == m_hWnd)\r
354                                 state |= LISS_SELECTED;\r
355                         else\r
356                                 state |= LISS_SELECTEDNOTFOCUS;\r
357                 }\r
358                 else\r
359                 {\r
360                         if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH)\r
361                                 brush = ::CreateSolidBrush(RGB(156,156,156));\r
362                         else if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT)\r
363                                 brush = ::CreateSolidBrush(RGB(200,200,128));\r
364                 }\r
365 \r
366                 if (brush != NULL)\r
367                 {\r
368                         ::FillRect(hdc, &rect, brush);\r
369                         ::DeleteObject(brush);\r
370                 }\r
371                 else\r
372                 {\r
373                         if (m_Theme.IsBackgroundPartiallyTransparent(LVP_LISTITEM, state))\r
374                                 m_Theme.DrawParentBackground(m_hWnd, hdc, &rect);\r
375 \r
376                         CRect rectDraw = rect;\r
377                         if(rItem.state & LVIS_SELECTED)\r
378                                 rectDraw.InflateRect(1,0);\r
379                         else\r
380                                 rectDraw.InflateRect(1,1);\r
381 \r
382                         m_Theme.DrawBackground(hdc, LVP_LISTITEM, state, rectDraw, &rect);\r
383                 }\r
384         }\r
385         else\r
386         {\r
387                 \r
388                 if (rItem.state & LVIS_SELECTED)\r
389                 {\r
390                         if (::GetFocus() == m_hWnd)\r
391                                 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));\r
392                         else\r
393                                 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));\r
394                 }\r
395                 else\r
396                 {\r
397                         //if (pLogEntry->bCopiedSelf)\r
398                         //      brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));\r
399                         //else\r
400                         if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH)\r
401                                 brush = ::CreateSolidBrush(RGB(156,156,156));\r
402                         else if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT)\r
403                                 brush = ::CreateSolidBrush(RGB(200,200,128));\r
404                         else\r
405                                 brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));\r
406                 }\r
407                 if (brush == NULL)\r
408                         return;\r
409 \r
410                 ::FillRect(hdc, &rect, brush);\r
411                 ::DeleteObject(brush);\r
412                 \r
413         }\r
414 }\r
415 \r
416 void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index)\r
417 {\r
418         GitRev* data = (GitRev*)m_arShownList.GetAt(index);\r
419         CRect rt=rect;\r
420         LVITEM   rItem;\r
421         SecureZeroMemory(&rItem, sizeof(LVITEM));\r
422         rItem.mask  = LVIF_STATE;\r
423         rItem.iItem = index;\r
424         rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;\r
425         GetItem(&rItem);\r
426 \r
427         for(unsigned int i=0;i<m_HashMap[data->m_CommitHash].size();i++)\r
428         {\r
429                 CString str;\r
430                 str=m_HashMap[data->m_CommitHash][i];\r
431                 \r
432                 CString shortname;\r
433                 HBRUSH brush = 0;\r
434                 shortname = _T("");\r
435                 COLORREF colRef = 0;\r
436 \r
437                 //Determine label color\r
438                 if(GetShortName(str,shortname,_T("refs/heads/")))\r
439                 {\r
440                         if( shortname == m_CurrentBranch )\r
441                                 colRef = m_Colors.GetColor(CColors::CurrentBranch);\r
442                         else\r
443                                 colRef = m_Colors.GetColor(CColors::LocalBranch);\r
444 \r
445                 }else if(GetShortName(str,shortname,_T("refs/remotes/")))\r
446                 {\r
447                         colRef = m_Colors.GetColor(CColors::RemoteBranch);\r
448                 }\r
449                 else if(GetShortName(str,shortname,_T("refs/tags/")))\r
450                 {\r
451                         colRef = m_Colors.GetColor(CColors::Tag);\r
452                 }\r
453                 else if(GetShortName(str,shortname,_T("refs/stash")))\r
454                 {\r
455                         colRef = m_Colors.GetColor(CColors::Stash);\r
456                         shortname=_T("stash");\r
457                 }\r
458 \r
459                 //When row selected, ajust label color\r
460                 if (!(m_Theme.IsAppThemed() && m_bVista))\r
461                         if (rItem.state & LVIS_SELECTED)\r
462                                 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);\r
463 \r
464                 brush = ::CreateSolidBrush(colRef);\r
465                 \r
466 \r
467                 if(!shortname.IsEmpty())\r
468                 {\r
469                         SIZE size;\r
470                         memset(&size,0,sizeof(SIZE));\r
471                         GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);\r
472                 \r
473                         rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);\r
474                         rt.right+=8;\r
475 \r
476                         //Fill interior of ref label\r
477                         ::FillRect(hdc, &rt, brush);\r
478 \r
479                         //Draw edge of label\r
480                         CDC W_Dc;\r
481                         W_Dc.Attach(hdc);\r
482 \r
483                         CRect rectEdge = rt;\r
484 \r
485                         W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,100), m_Colors.Darken(colRef,100));\r
486                         rectEdge.DeflateRect(1,1);\r
487                         W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,50), m_Colors.Darken(colRef,50));\r
488 \r
489                         W_Dc.Detach();\r
490 \r
491                         //Draw text inside label\r
492                         if (m_Theme.IsAppThemed() && m_bVista)\r
493                         {\r
494                                 int txtState = LISS_NORMAL;\r
495                                 if (rItem.state & LVIS_SELECTED)\r
496                                         txtState = LISS_SELECTED;\r
497 \r
498                                 m_Theme.DrawText(hdc, LVP_LISTITEM, txtState, shortname, -1, DT_CENTER | DT_SINGLELINE | DT_VCENTER, 0, &rt);\r
499                         }\r
500                         else\r
501                         {\r
502                                 if (rItem.state & LVIS_SELECTED)\r
503                                 {\r
504                                         COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);\r
505                                         COLORREF   clrOld   = ::SetTextColor(hdc,clrNew);   \r
506                                         ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER | DT_SINGLELINE | DT_VCENTER);\r
507                                         ::SetTextColor(hdc,clrOld);\r
508                                 }else\r
509                                 {\r
510                                         ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER | DT_SINGLELINE | DT_VCENTER);\r
511                                 }\r
512                         }\r
513 \r
514                         \r
515                         //::MoveToEx(hdc,rt.left,rt.top,NULL);\r
516                         //::LineTo(hdc,rt.right,rt.top);\r
517                         //::LineTo(hdc,rt.right,rt.bottom);\r
518                         //::LineTo(hdc,rt.left,rt.bottom);\r
519                         //::LineTo(hdc,rt.left,rt.top);\r
520 \r
521                                 \r
522                         rt.left=rt.right+1;\r
523                 }\r
524                 if(brush)\r
525                         ::DeleteObject(brush);\r
526         }               \r
527         rt.right=rect.right;\r
528 \r
529         if (m_Theme.IsAppThemed() && m_bVista)\r
530         {\r
531                 int txtState = LISS_NORMAL;\r
532                 if (rItem.state & LVIS_SELECTED)\r
533                         txtState = LISS_SELECTED;\r
534 \r
535                 m_Theme.DrawText(hdc, LVP_LISTITEM, txtState, data->m_Subject, -1, DT_LEFT | DT_SINGLELINE | DT_VCENTER, 0, &rt);\r
536         }\r
537         else\r
538         {\r
539                 if (rItem.state & LVIS_SELECTED)\r
540                 {\r
541                         COLORREF   clrOld   = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));   \r
542                         ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT | DT_SINGLELINE | DT_VCENTER);\r
543                         ::SetTextColor(hdc,clrOld);   \r
544                 }else\r
545                 {\r
546                         ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT | DT_SINGLELINE | DT_VCENTER);\r
547                 }\r
548         }\r
549 }\r
550 \r
551 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {\r
552 \r
553         // Returns ((256 - amount)*col1 + amount*col2) / 256;\r
554         return RGB(((256 - amount)*GetRValue(col1)   + amount*GetRValue(col2)  ) / 256,\r
555                       ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,\r
556                       ((256 - amount)*GetBValue(col1)  + amount*GetBValue(col2) ) / 256);\r
557 }\r
558 \r
559 Gdiplus::Color GetGdiColor(COLORREF col)\r
560 {\r
561         return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));\r
562 }\r
563 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,\r
564                                       const COLORREF& col,const COLORREF& activeColor, int top\r
565                                                                           )  \r
566 {\r
567         int h = laneHeight / 2;\r
568         int m = (x1 + x2) / 2;\r
569         int r = (x2 - x1) / 3;\r
570         int d =  2 * r;\r
571 \r
572         #define P_CENTER m , h+top\r
573         #define P_0      x2, h+top\r
574         #define P_90     m , 0+top\r
575         #define P_180    x1, h+top\r
576         #define P_270    m , 2 * h+top\r
577         #define R_CENTER m - r, h - r+top, m - r+d, h - r+top+d\r
578 \r
579 \r
580         #define DELTA_UR_B 2*(x1 - m), 2*h +top \r
581         #define DELTA_UR_E 0*16, 90*16 +top  // -,\r
582 \r
583         #define DELTA_DR_B 2*(x1 - m), 2*-h +top\r
584         #define DELTA_DR_E 270*16, 90*16 +top  // -'\r
585 \r
586         #define DELTA_UL_B 2*(x2 - m), 2*h +top\r
587         #define DELTA_UL_E 90*16, 90*16 +top //  ,-\r
588 \r
589         #define DELTA_DL_B 2*(x2 - m),2*-h +top \r
590         #define DELTA_DL_E 180*16, 90*16  //  '-\r
591 \r
592         #define CENTER_UR x1, 2*h, 225\r
593         #define CENTER_DR x1, 0  , 135\r
594         #define CENTER_UL x2, 2*h, 315\r
595         #define CENTER_DL x2, 0  ,  45\r
596 \r
597 \r
598         Gdiplus::Graphics graphics( hdc );\r
599 \r
600         // arc\r
601         switch (type) {\r
602         case Lanes::JOIN:\r
603         case Lanes::JOIN_R:\r
604         case Lanes::HEAD:\r
605         case Lanes::HEAD_R: \r
606         {\r
607                 Gdiplus::LinearGradientBrush gradient(\r
608                                                                 Gdiplus::Point(x1-2, h+top-2),\r
609                                                                 Gdiplus::Point(P_270),\r
610                                                                 GetGdiColor(activeColor),GetGdiColor(col));\r
611 \r
612                 \r
613                 Gdiplus::Pen mypen(&gradient,2);\r
614                 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);\r
615                 \r
616                 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);\r
617                 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1+1,laneHeight+1,270,90);\r
618                 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);\r
619 \r
620                 break;\r
621         }\r
622         case Lanes::JOIN_L: \r
623         {\r
624         \r
625                 Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);\r
626 \r
627                 \r
628                 graphics.DrawArc(&mypen,x1,top+h, x2-x1,laneHeight,270,90);\r
629 \r
630                 break;\r
631         }\r
632         case Lanes::TAIL:\r
633         case Lanes::TAIL_R: \r
634         {\r
635                 \r
636                 Gdiplus::LinearGradientBrush gradient(\r
637                                                                 Gdiplus::Point(x1-2, h+top-2),\r
638                                                                 Gdiplus::Point(P_90),\r
639                                                                 GetGdiColor(activeColor),GetGdiColor(col));\r
640 \r
641                 \r
642                 Gdiplus::Pen mypen(&gradient,2);\r
643 \r
644                 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1+1,laneHeight+1,0,90);\r
645 \r
646 \r
647 #if 0\r
648                 QConicalGradient gradient(CENTER_DR);\r
649                 gradient.setColorAt(0.375, activeCol);\r
650                 gradient.setColorAt(0.625, col);\r
651                 myPen.setBrush(gradient);\r
652                 p->setPen(myPen);\r
653                 p->drawArc(P_CENTER, DELTA_DR);\r
654 #endif\r
655                 break;\r
656         }\r
657         default:\r
658                 break;\r
659         }\r
660 \r
661 \r
662         //static QPen myPen(Qt::black, 2); // fast path here\r
663         CPen pen;\r
664         pen.CreatePen(PS_SOLID,2,col);\r
665         //myPen.setColor(col);\r
666         HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);\r
667 \r
668         Gdiplus::Pen myPen(GetGdiColor(col),2);\r
669 \r
670         //p->setPen(myPen);\r
671 \r
672         // vertical line\r
673         switch (type) {\r
674         case Lanes::ACTIVE:\r
675         case Lanes::NOT_ACTIVE:\r
676         case Lanes::MERGE_FORK:\r
677         case Lanes::MERGE_FORK_R:\r
678         case Lanes::MERGE_FORK_L:\r
679         case Lanes::JOIN:\r
680         case Lanes::JOIN_R:\r
681         case Lanes::JOIN_L:\r
682         case Lanes::CROSS:\r
683                 //DrawLine(hdc,P_90,P_270);\r
684                 graphics.DrawLine(&myPen,P_90,P_270);\r
685                 //p->drawLine(P_90, P_270);\r
686                 break;\r
687         case Lanes::HEAD_L:\r
688         case Lanes::BRANCH:\r
689                 //DrawLine(hdc,P_CENTER,P_270);\r
690                 graphics.DrawLine(&myPen,P_CENTER,P_270);\r
691                 //p->drawLine(P_CENTER, P_270);\r
692                 break;\r
693         case Lanes::TAIL_L:\r
694         case Lanes::INITIAL:\r
695         case Lanes::BOUNDARY:\r
696         case Lanes::BOUNDARY_C:\r
697         case Lanes::BOUNDARY_R:\r
698         case Lanes::BOUNDARY_L:\r
699                 //DrawLine(hdc,P_90, P_CENTER);\r
700                 graphics.DrawLine(&myPen,P_90,P_CENTER);\r
701                 //p->drawLine(P_90, P_CENTER);\r
702                 break;\r
703         default:\r
704                 break;\r
705         }\r
706 \r
707         myPen.SetColor(GetGdiColor(activeColor));\r
708 \r
709         // horizontal line\r
710         switch (type) {\r
711         case Lanes::MERGE_FORK:\r
712         case Lanes::JOIN:\r
713         case Lanes::HEAD:\r
714         case Lanes::TAIL:\r
715         case Lanes::CROSS:\r
716         case Lanes::CROSS_EMPTY:\r
717         case Lanes::BOUNDARY_C:\r
718                 //DrawLine(hdc,P_180,P_0);\r
719                 graphics.DrawLine(&myPen,P_180,P_0);\r
720                 //p->drawLine(P_180, P_0);\r
721                 break;\r
722         case Lanes::MERGE_FORK_R:\r
723         case Lanes::BOUNDARY_R:\r
724                 //DrawLine(hdc,P_180,P_CENTER);\r
725                 graphics.DrawLine(&myPen,P_180,P_CENTER);\r
726                 //p->drawLine(P_180, P_CENTER);\r
727                 break;\r
728         case Lanes::MERGE_FORK_L:\r
729         case Lanes::HEAD_L:\r
730         case Lanes::TAIL_L:\r
731         case Lanes::BOUNDARY_L:\r
732                 //DrawLine(hdc,P_CENTER,P_0);\r
733                 graphics.DrawLine(&myPen,P_CENTER,P_0);\r
734                 //p->drawLine(P_CENTER, P_0);\r
735                 break;\r
736         default:\r
737                 break;\r
738         }\r
739 \r
740         CBrush brush;\r
741         brush.CreateSolidBrush(col);\r
742         HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);\r
743         // center symbol, e.g. rect or ellipse\r
744         switch (type) {\r
745         case Lanes::ACTIVE:\r
746         case Lanes::INITIAL:\r
747         case Lanes::BRANCH:\r
748 \r
749                 //p->setPen(Qt::NoPen);\r
750                 //p->setBrush(col);\r
751                 ::Ellipse(hdc, R_CENTER);\r
752                 //p->drawEllipse(R_CENTER);\r
753                 break;\r
754         case Lanes::MERGE_FORK:\r
755         case Lanes::MERGE_FORK_R:\r
756         case Lanes::MERGE_FORK_L:\r
757                 //p->setPen(Qt::NoPen);\r
758                 //p->setBrush(col);\r
759                 //p->drawRect(R_CENTER);\r
760                 Rectangle(hdc,R_CENTER);\r
761                 break;\r
762         case Lanes::UNAPPLIED:\r
763                 // Red minus sign\r
764                 //p->setPen(Qt::NoPen);\r
765                 //p->setBrush(Qt::red);\r
766                 //p->drawRect(m - r, h - 1, d, 2);\r
767                 ::Rectangle(hdc,m-r,h-1,d,2);\r
768                 break;\r
769         case Lanes::APPLIED:\r
770                 // Green plus sign\r
771                 //p->setPen(Qt::NoPen);\r
772                 //p->setBrush(DARK_GREEN);\r
773                 //p->drawRect(m - r, h - 1, d, 2);\r
774                 //p->drawRect(m - 1, h - r, 2, d);\r
775                 ::Rectangle(hdc,m-r,h-1,d,2);\r
776                 ::Rectangle(hdc,m-1,h-r,2,d);\r
777                 break;\r
778         case Lanes::BOUNDARY:\r
779                 //p->setBrush(back);\r
780                 //p->drawEllipse(R_CENTER);\r
781                 ::Ellipse(hdc, R_CENTER);\r
782                 break;\r
783         case Lanes::BOUNDARY_C:\r
784         case Lanes::BOUNDARY_R:\r
785         case Lanes::BOUNDARY_L:\r
786                 //p->setBrush(back);\r
787                 //p->drawRect(R_CENTER);\r
788                 ::Rectangle(hdc,R_CENTER);\r
789                 break;\r
790         default:\r
791                 break;\r
792         }\r
793 \r
794         ::SelectObject(hdc,oldpen);\r
795         ::SelectObject(hdc,oldbrush);\r
796         #undef P_CENTER\r
797         #undef P_0\r
798         #undef P_90\r
799         #undef P_180\r
800         #undef P_270\r
801         #undef R_CENTER\r
802 }\r
803 \r
804 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)\r
805 {\r
806         //todo unfinished\r
807 //      return;\r
808         GitRev* data = (GitRev*)m_arShownList.GetAt(index);\r
809         if(data->m_CommitHash.IsEmpty())\r
810                 return;\r
811 \r
812         CRect rt=rect;\r
813         LVITEM   rItem;\r
814         SecureZeroMemory(&rItem, sizeof(LVITEM));\r
815         rItem.mask  = LVIF_STATE;\r
816         rItem.iItem = index;\r
817         rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;\r
818         GetItem(&rItem);\r
819 \r
820         \r
821 //      p->translate(QPoint(opt.rect.left(), opt.rect.top()));\r
822 \r
823 \r
824 \r
825         if (data->m_Lanes.size() == 0)\r
826                 m_logEntries.setLane(data->m_CommitHash);\r
827 \r
828         std::vector<int>& lanes=data->m_Lanes;\r
829         UINT laneNum = lanes.size();\r
830         UINT activeLane = 0;\r
831         for (UINT i = 0; i < laneNum; i++)\r
832                 if (Lanes::isMerge(lanes[i])) {\r
833                         activeLane = i;\r
834                         break;\r
835                 }\r
836 \r
837         int x1 = 0, x2 = 0;\r
838         int maxWidth = rect.Width();\r
839         int lw = 3 * rect.Height() / 4; //laneWidth() \r
840 \r
841         COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];\r
842         //if (opt.state & QStyle::State_Selected)\r
843         //      activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);\r
844         \r
845 \r
846         for (unsigned int i = 0; i < laneNum && x2 < maxWidth; i++) \r
847         {\r
848 \r
849                 x1 = x2;\r
850                 x2 += lw;\r
851 \r
852                 int ln = lanes[i];\r
853                 if (ln == Lanes::EMPTY)\r
854                         continue;\r
855 \r
856                 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];\r
857                 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);\r
858         }\r
859 \r
860 #if 0\r
861         for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {\r
862 \r
863                 x1 = x2;\r
864                 x2 += lw;\r
865 \r
866                 int ln = lanes[i];\r
867                 if (ln == Lanes::EMPTY)\r
868                         continue;\r
869 \r
870                 UINT col = (  Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)\r
871                             || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;\r
872 \r
873                 if (ln == Lanes::CROSS) {\r
874                         paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);\r
875                         paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);\r
876                 } else\r
877                         paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);\r
878         }\r
879 #endif\r
880 \r
881 }\r
882 \r
883 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
884 {\r
885 \r
886         NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );\r
887         // Take the default processing unless we set this to something else below.\r
888         *pResult = CDRF_DODEFAULT;\r
889 \r
890         if (m_bNoDispUpdates)\r
891                 return;\r
892 \r
893 \r
894 \r
895         switch (pLVCD->nmcd.dwDrawStage)\r
896         {\r
897         case CDDS_PREPAINT:\r
898                 {\r
899                         *pResult = CDRF_NOTIFYITEMDRAW;\r
900                         return;\r
901                 }\r
902                 break;\r
903         case CDDS_ITEMPREPAINT:\r
904                 {\r
905                         // This is the prepaint stage for an item. Here's where we set the\r
906                         // item's text color. \r
907                         \r
908                         // Tell Windows to send draw notifications for each subitem.\r
909                         *pResult = CDRF_NOTIFYSUBITEMDRAW;\r
910 \r
911                         COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);\r
912 \r
913                         if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
914                         {\r
915                                 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);\r
916                                 if (data)\r
917                                 {\r
918 #if 0\r
919                                         if (data->bCopiedSelf)\r
920                                         {\r
921                                                 // only change the background color if the item is not 'hot' (on vista with m_Themes enabled)\r
922                                                 if (!m_Theme.IsAppm_Themed() || !m_bVista || ((pLVCD->nmcd.uItemState & CDIS_HOT)==0))\r
923                                                         pLVCD->clrTextBk = GetSysColor(COLOR_MENU);\r
924                                         }\r
925 \r
926                                         if (data->bCopies)\r
927                                                 crText = m_Colors.GetColor(CColors::Modified);\r
928 #endif\r
929                                         if (data->m_Action& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) ) \r
930                                                 crText = RGB(128,128,128);\r
931 \r
932                                         if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH)\r
933                                                 pLVCD->clrTextBk = RGB(156,156,156);\r
934                                         else if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT)\r
935                                                 pLVCD->clrTextBk  = RGB(200,200,128);\r
936                                         else\r
937                                                 pLVCD->clrTextBk  = ::GetSysColor(COLOR_WINDOW);\r
938 \r
939                                         if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_CURRENT)\r
940                                         {\r
941                                                 SelectObject(pLVCD->nmcd.hdc, m_boldFont);\r
942                                                 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;\r
943                                         }\r
944 \r
945                                         if(data->m_CommitHash == m_HeadHash)\r
946                                         {\r
947                                                 SelectObject(pLVCD->nmcd.hdc, m_boldFont);\r
948                                                 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;\r
949                                         }\r
950 \r
951 //                                      if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))\r
952 //                                              crText = GetSysColor(COLOR_GRAYTEXT);\r
953 //                                      \r
954                                         if (data->m_CommitHash == GIT_REV_ZERO)\r
955                                         {\r
956                                                 //crText = GetSysColor(RGB(200,200,0));\r
957                                                 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);\r
958                                                 // We changed the font, so we're returning CDRF_NEWFONT. This\r
959                                                 // tells the control to recalculate the extent of the text.\r
960                                                 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;\r
961                                         }\r
962                                 }\r
963                         }\r
964                         if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
965                         {\r
966                                 if (m_bStrictStopped)\r
967                                         crText = GetSysColor(COLOR_GRAYTEXT);\r
968                         }\r
969                         // Store the color back in the NMLVCUSTOMDRAW struct.\r
970                         pLVCD->clrText = crText;\r
971                         return;\r
972                 }\r
973                 break;\r
974         case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:\r
975                 {\r
976                         if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))\r
977                         {\r
978                                 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);\r
979                         }\r
980 \r
981                         if (pLVCD->iSubItem == LOGLIST_GRAPH)\r
982                         {\r
983                                 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )\r
984                                 {\r
985                                         CRect rect;\r
986                                         GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);\r
987                                         if(pLVCD->iSubItem == 0)\r
988                                         {\r
989                                                 CRect second;\r
990                                                 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem+1, LVIR_BOUNDS, second);\r
991                                                 rect.right=second.left;\r
992                                         }\r
993                                         \r
994                                         TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);\r
995                                         FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);\r
996                                         \r
997                                         GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);\r
998                                         if( data ->m_CommitHash != GIT_REV_ZERO)\r
999                                                 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);\r
1000 \r
1001                                         *pResult = CDRF_SKIPDEFAULT;\r
1002                                         return;\r
1003                                 \r
1004                                 }\r
1005                         }\r
1006 \r
1007                         if (pLVCD->iSubItem == LOGLIST_MESSAGE)\r
1008                         {\r
1009                                 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
1010                                 {\r
1011                                         GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);\r
1012                                         //if(!data->m_IsFull)\r
1013                                         //{\r
1014                                                 //if(data->SafeFetchFullInfo(&g_Git))\r
1015                                                 //      this->Invalidate();\r
1016                                                 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);\r
1017                                         //}\r
1018 \r
1019                                         if(m_HashMap[data->m_CommitHash].size()!=0)\r
1020                                         {\r
1021                                                 CRect rect;\r
1022 \r
1023                                                 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);\r
1024                                         \r
1025                                                 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);\r
1026                                                 DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);\r
1027 \r
1028                                                 *pResult = CDRF_SKIPDEFAULT;\r
1029                                                 return;\r
1030 \r
1031                                         }\r
1032 \r
1033                                 }       \r
1034                         }\r
1035                         \r
1036                         if (pLVCD->iSubItem == 1)\r
1037                         {\r
1038                                 if(this->m_IsIDReplaceAction)\r
1039                                 {\r
1040                                         *pResult = CDRF_DODEFAULT;\r
1041                                         return;\r
1042                                 }\r
1043                                 *pResult = CDRF_DODEFAULT;\r
1044 \r
1045                                 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
1046                                         return;\r
1047 \r
1048                                 int             nIcons = 0;\r
1049                                 int             iconwidth = ::GetSystemMetrics(SM_CXSMICON);\r
1050                                 int             iconheight = ::GetSystemMetrics(SM_CYSMICON);\r
1051 \r
1052                                 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec));\r
1053                                 CRect rect;\r
1054                                 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);\r
1055                                 TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);\r
1056                                 // Get the selected state of the\r
1057                                 // item being drawn.                                                    \r
1058 \r
1059                                 // Fill the background\r
1060                                 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);\r
1061                                 \r
1062                                 // Draw the icon(s) into the compatible DC\r
1063                                 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_MODIFIED)\r
1064                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
1065                                 nIcons++;\r
1066 \r
1067                                 if (pLogEntry->m_Action & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) )\r
1068                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
1069                                 nIcons++;\r
1070 \r
1071                                 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_DELETED)\r
1072                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
1073                                 nIcons++;\r
1074 \r
1075                                 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_REPLACED)\r
1076                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
1077                                 nIcons++;\r
1078                                 *pResult = CDRF_SKIPDEFAULT;\r
1079                                 return;\r
1080                         }\r
1081                 }\r
1082                 break;\r
1083         }\r
1084         *pResult = CDRF_DODEFAULT;\r
1085 \r
1086 }\r
1087 \r
1088 // CGitLogListBase message handlers\r
1089 \r
1090 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
1091 {\r
1092         NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);\r
1093 \r
1094         // Create a pointer to the item\r
1095         LV_ITEM* pItem = &(pDispInfo)->item;\r
1096 \r
1097         // Do the list need text information?\r
1098         if (!(pItem->mask & LVIF_TEXT))\r
1099                 return;\r
1100 \r
1101         // By default, clear text buffer.\r
1102         lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);\r
1103 \r
1104         bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();\r
1105         \r
1106         *pResult = 0;\r
1107         if (m_bNoDispUpdates || bOutOfRange)\r
1108                 return;\r
1109 \r
1110         // Which item number?\r
1111         int itemid = pItem->iItem;\r
1112         GitRev * pLogEntry = NULL;\r
1113         if (itemid < m_arShownList.GetCount())\r
1114                 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(pItem->iItem));\r
1115 \r
1116         CString temp;\r
1117         if(m_IsOldFirst)\r
1118         {\r
1119                 temp.Format(_T("%d"),pItem->iItem+1);\r
1120 \r
1121         }else\r
1122         {\r
1123                 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);\r
1124         }\r
1125             \r
1126         // Which column?\r
1127         switch (pItem->iSubItem)\r
1128         {\r
1129         case this->LOGLIST_GRAPH:       //Graphic\r
1130                 if (pLogEntry)\r
1131                 {\r
1132                         if(this->m_IsRebaseReplaceGraph)\r
1133                         {\r
1134                                 CTGitPath path;\r
1135                                 path.m_Action=pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_MODE_MASK;\r
1136 \r
1137                                 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);\r
1138                         }\r
1139                 }\r
1140                 break;\r
1141         case this->LOGLIST_ACTION: //action -- no text in the column\r
1142                 if(this->m_IsIDReplaceAction)\r
1143                         lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);\r
1144                 break;\r
1145         case this->LOGLIST_MESSAGE: //Message\r
1146                 if (pLogEntry)\r
1147                         lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_Subject, pItem->cchTextMax);\r
1148                 break;\r
1149         case this->LOGLIST_AUTHOR: //Author\r
1150                 if (pLogEntry)\r
1151                         lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_AuthorName, pItem->cchTextMax);\r
1152                 break;\r
1153         case this->LOGLIST_DATE: //Date\r
1154                 if (pLogEntry && pLogEntry->m_CommitHash != GIT_REV_ZERO)\r
1155                         lstrcpyn(pItem->pszText,\r
1156                                 CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat, true, m_bRelativeTimes ), \r
1157                                 pItem->cchTextMax);\r
1158                 break;\r
1159                 \r
1160         case 5:\r
1161 \r
1162                 break;\r
1163         default:\r
1164                 ASSERT(false);\r
1165         }\r
1166 }\r
1167 \r
1168 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)\r
1169 {\r
1170 \r
1171         int selIndex = GetSelectionMark();\r
1172         if (selIndex < 0)\r
1173                 return; // nothing selected, nothing to do with a context menu\r
1174 \r
1175         // if the user selected the info text telling about not all revisions shown due to\r
1176         // the "stop on copy/rename" option, we also don't show the context menu\r
1177         if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))\r
1178                 return;\r
1179 \r
1180         // if the context menu is invoked through the keyboard, we have to use\r
1181         // a calculated position on where to anchor the menu on\r
1182         if ((point.x == -1) && (point.y == -1))\r
1183         {\r
1184                 CRect rect;\r
1185                 GetItemRect(selIndex, &rect, LVIR_LABEL);\r
1186                 ClientToScreen(&rect);\r
1187                 point = rect.CenterPoint();\r
1188         }\r
1189         m_nSearchIndex = selIndex;\r
1190         m_bCancelled = FALSE;\r
1191 \r
1192         // calculate some information the context menu commands can use\r
1193 //      CString pathURL = GetURLFromPath(m_path);\r
1194 \r
1195         POSITION pos = GetFirstSelectedItemPosition();\r
1196         int indexNext = GetNextSelectedItem(pos);\r
1197         if (indexNext < 0)\r
1198                 return;\r
1199 \r
1200         GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(indexNext));\r
1201 #if 0\r
1202         GitRev revSelected = pSelLogEntry->Rev;\r
1203         GitRev revPrevious = git_revnum_t(revSelected)-1;\r
1204         if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))\r
1205         {\r
1206                 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)\r
1207                 {\r
1208                         LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->GetAt(i);\r
1209                         if (changedpath->lCopyFromRev)\r
1210                                 revPrevious = changedpath->lCopyFromRev;\r
1211                 }\r
1212         }\r
1213         GitRev revSelected2;\r
1214         if (pos)\r
1215         {\r
1216                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));\r
1217                 revSelected2 = pLogEntry->Rev;\r
1218         }\r
1219         bool bAllFromTheSameAuthor = true;\r
1220         CString firstAuthor;\r
1221         CLogDataVector selEntries;\r
1222         GitRev revLowest, revHighest;\r
1223         GitRevRangeArray revisionRanges;\r
1224         {\r
1225                 POSITION pos = GetFirstSelectedItemPosition();\r
1226                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));\r
1227                 revisionRanges.AddRevision(pLogEntry->Rev);\r
1228                 selEntries.push_back(pLogEntry);\r
1229                 firstAuthor = pLogEntry->sAuthor;\r
1230                 revLowest = pLogEntry->Rev;\r
1231                 revHighest = pLogEntry->Rev;\r
1232                 while (pos)\r
1233                 {\r
1234                         pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));\r
1235                         revisionRanges.AddRevision(pLogEntry->Rev);\r
1236                         selEntries.push_back(pLogEntry);\r
1237                         if (firstAuthor.Compare(pLogEntry->sAuthor))\r
1238                                 bAllFromTheSameAuthor = false;\r
1239                         revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);\r
1240                         revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);\r
1241                 }\r
1242         }\r
1243 \r
1244 #endif\r
1245 \r
1246         int FirstSelect=-1, LastSelect=-1;\r
1247         pos = GetFirstSelectedItemPosition();\r
1248         FirstSelect = GetNextSelectedItem(pos);\r
1249         while(pos)\r
1250         {\r
1251                 LastSelect = GetNextSelectedItem(pos);\r
1252         }\r
1253         //entry is selected, now show the popup menu\r
1254         CIconMenu popup;\r
1255         CIconMenu submenu;\r
1256         if (popup.CreatePopupMenu())\r
1257         {\r
1258 \r
1259                 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))\r
1260                         popup.AppendMenuIcon(ID_REBASE_PICK,  IDS_REBASE_PICK,   IDI_PICK);\r
1261 \r
1262                 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))\r
1263                         popup.AppendMenuIcon(ID_REBASE_SQUASH,IDS_REBASE_SQUASH, IDI_SQUASH);\r
1264 \r
1265                 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))\r
1266                         popup.AppendMenuIcon(ID_REBASE_EDIT,  IDS_REBASE_EDIT,   IDI_EDIT);\r
1267 \r
1268                 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))\r
1269                         popup.AppendMenuIcon(ID_REBASE_SKIP,  IDS_REBASE_SKIP,   IDI_SKIP);\r
1270                 \r
1271                 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|\r
1272                               GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))\r
1273                         popup.AppendMenu(MF_SEPARATOR, NULL);\r
1274 \r
1275                 if (GetSelectedCount() == 1)\r
1276                 {\r
1277                         \r
1278                         {\r
1279                                 if(pSelLogEntry->m_CommitHash != GIT_REV_ZERO)\r
1280                                 {\r
1281                                         if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE))\r
1282                                                 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);\r
1283                                         // TODO:\r
1284                                         // TortoiseMerge could be improved to take a /blame switch\r
1285                                         // and then not 'cat' the files from a unified diff but\r
1286                                         // blame then.\r
1287                                         // But until that's implemented, the context menu entry for\r
1288                                         // this feature is commented out.\r
1289                                         //popup.AppendMenu(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);\r
1290                                 }else\r
1291                                 {\r
1292                                         if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))\r
1293                                                 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);\r
1294                                 }\r
1295                                 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1))\r
1296                                         popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);\r
1297 \r
1298                                 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))\r
1299                                         popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);\r
1300                                 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);\r
1301                                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
1302                         }\r
1303 \r
1304 //                      if (!m_ProjectProperties.sWebViewerRev.IsEmpty())\r
1305 //                      {\r
1306 //                              popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);\r
1307 //                      }\r
1308 //                      if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())\r
1309 //                      {\r
1310 //                              popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);\r
1311 //                      }\r
1312 //                      if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||\r
1313 //                              (!m_ProjectProperties.sWebViewerRev.IsEmpty()))\r
1314 //                      {\r
1315 //                              popup.AppendMenu(MF_SEPARATOR, NULL);\r
1316 //                      }\r
1317 \r
1318                         //if (m_hasWC)\r
1319                         //      popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);\r
1320                         //if (m_hasWC)\r
1321                         //      popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);\r
1322                         //if (m_hasWC)\r
1323                         //      popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREV, IDI_MERGE);\r
1324                         \r
1325                         CString str,format;\r
1326                         format.LoadString(IDS_RESET_TO_THIS_FORMAT);\r
1327                         str.Format(format,g_Git.GetCurrentBranch());\r
1328 \r
1329                         if(pSelLogEntry->m_CommitHash != GIT_REV_ZERO)\r
1330                         {\r
1331                                 if(m_ContextMenuMask&GetContextMenuBit(ID_RESET))\r
1332                                         popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);\r
1333 \r
1334                                 if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV))\r
1335                                         popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);\r
1336 \r
1337                                 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH))\r
1338                                         popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);\r
1339 \r
1340                                 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG))\r
1341                                         popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_COPY);\r
1342                         \r
1343                                 format.LoadString(IDS_REBASE_THIS_FORMAT);\r
1344                                 str.Format(format,g_Git.GetCurrentBranch());\r
1345 \r
1346                                 if(pSelLogEntry->m_CommitHash != m_HeadHash)\r
1347                                         if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))\r
1348                                                 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);                   \r
1349 \r
1350                                 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))\r
1351                                         popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT); \r
1352                         \r
1353 \r
1354                                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
1355                         }\r
1356 \r
1357                 }\r
1358 \r
1359                 if(!pSelLogEntry->m_Ref.IsEmpty() && GetSelectedCount() == 1)\r
1360                 {\r
1361                         popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL,     IDI_DELETE);    \r
1362                         popup.AppendMenuIcon(ID_STASH_APPLY,IDS_MENUSTASHAPPLY, IDI_RELOCATE);  \r
1363                         popup.AppendMenu(MF_SEPARATOR, NULL);\r
1364                 }\r
1365         \r
1366                 if (GetSelectedCount() >= 2)\r
1367                 {\r
1368                         bool bAddSeparator = false;\r
1369                         if (IsSelectionContinuous() || (GetSelectedCount() == 2))\r
1370                         {\r
1371                                 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO))\r
1372                                         popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);\r
1373                         }\r
1374 \r
1375                         if (GetSelectedCount() == 2)\r
1376                         {\r
1377                                 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);\r
1378                                 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2))\r
1379                                         popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);\r
1380                                 bAddSeparator = true;\r
1381                         }\r
1382 \r
1383                         if (m_hasWC)\r
1384                         {\r
1385                                 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);\r
1386 //                              if (m_hasWC)\r
1387 //                                      popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);\r
1388                                 bAddSeparator = true;\r
1389                         }\r
1390                         if (bAddSeparator)\r
1391                                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
1392                 }\r
1393 \r
1394                 if ( GetSelectedCount() >0 && pSelLogEntry->m_CommitHash != GIT_REV_ZERO)\r
1395                 {\r
1396                         if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )\r
1397                         {\r
1398                                 if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT))\r
1399                                 {\r
1400                                         CString head;\r
1401                                         int headindex;\r
1402                                         headindex = this->GetHeadIndex();\r
1403                                         if(headindex>=0)\r
1404                                         {\r
1405                                                 head.Format(_T("HEAD~%d"),LastSelect-headindex);\r
1406                                                 CString hash=g_Git.GetHash(head);\r
1407                                                 hash=hash.Left(40);\r
1408                                                 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));\r
1409                                                 if(pLastEntry->m_CommitHash == hash)\r
1410                                                         popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);\r
1411                                         }\r
1412                                 }\r
1413                         }\r
1414                         if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK))\r
1415                                 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);\r
1416 \r
1417                         if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))\r
1418                                 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH))\r
1419                                         popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);\r
1420                         \r
1421                         popup.AppendMenu(MF_SEPARATOR, NULL);\r
1422         \r
1423                 }\r
1424 \r
1425                 \r
1426 #if 0\r
1427 //              if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))\r
1428 //              {\r
1429 //                      popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);\r
1430 //              }\r
1431 //              if (GetSelectedCount() == 1)\r
1432 //              {\r
1433 //                      popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);\r
1434 //                      popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"\r
1435 //                      popup.AppendMenu(MF_SEPARATOR, NULL);\r
1436 //              }\r
1437 #endif\r
1438 \r
1439                 \r
1440                 if (GetSelectedCount() == 1)\r
1441                 {\r
1442                         if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))\r
1443                                 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH);\r
1444                 }\r
1445                 if (GetSelectedCount() != 0)\r
1446                 {\r
1447                         if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))\r
1448                                 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD);\r
1449                 }\r
1450 \r
1451                 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))\r
1452                         popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND);\r
1453 \r
1454 \r
1455                 if (GetSelectedCount() == 1)\r
1456                 {\r
1457                         if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))\r
1458                         {\r
1459                                 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )\r
1460                                 {\r
1461                                         CString str;\r
1462                                         str.LoadString(IDS_DELETE_BRANCHTAG);\r
1463                                         if( m_HashMap[pSelLogEntry->m_CommitHash].size() == 1 )\r
1464                                         {\r
1465                                                 str+=_T(" ");\r
1466                                                 str+=m_HashMap[pSelLogEntry->m_CommitHash].at(0);\r
1467                                                 popup.AppendMenuIcon(ID_DELETE,str+_T("..."),IDI_DELETE);\r
1468                                         }\r
1469                                         else if( m_HashMap[pSelLogEntry->m_CommitHash].size() > 1 )\r
1470                                         {\r
1471                                                 \r
1472                                                 submenu.CreatePopupMenu();\r
1473                                                 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)\r
1474                                                 {\r
1475                                                         submenu.AppendMenuIcon(ID_DELETE+(i<<16),m_HashMap[pSelLogEntry->m_CommitHash][i]+_T("..."));\r
1476                                                 }\r
1477 \r
1478                                                 popup.AppendMenu(MF_BYPOSITION|MF_POPUP|MF_STRING,(UINT) submenu.m_hMenu,str); \r
1479 \r
1480                                         }\r
1481                                         \r
1482                                 }\r
1483                         }\r
1484                 }\r
1485 \r
1486                 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);\r
1487 //              DialogEnableWindow(IDOK, FALSE);\r
1488 //              SetPromptApp(&theApp);\r
1489         \r
1490                 this->ContextMenuAction(cmd, FirstSelect, LastSelect);\r
1491                 \r
1492 //              EnableOKButton();\r
1493         } // if (popup.CreatePopupMenu())\r
1494 \r
1495 }\r
1496 \r
1497 bool CGitLogListBase::IsSelectionContinuous()\r
1498 {\r
1499         if ( GetSelectedCount()==1 )\r
1500         {\r
1501                 // if only one revision is selected, the selection is of course\r
1502                 // continuous\r
1503                 return true;\r
1504         }\r
1505 \r
1506         POSITION pos = GetFirstSelectedItemPosition();\r
1507         bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());\r
1508         if (bContinuous)\r
1509         {\r
1510                 int itemindex = GetNextSelectedItem(pos);\r
1511                 while (pos)\r
1512                 {\r
1513                         int nextindex = GetNextSelectedItem(pos);\r
1514                         if (nextindex - itemindex > 1)\r
1515                         {\r
1516                                 bContinuous = false;\r
1517                                 break;\r
1518                         }\r
1519                         itemindex = nextindex;\r
1520                 }\r
1521         }\r
1522         return bContinuous;\r
1523 }\r
1524 \r
1525 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly)\r
1526 {\r
1527 \r
1528         CString sClipdata;\r
1529         POSITION pos = GetFirstSelectedItemPosition();\r
1530         if (pos != NULL)\r
1531         {\r
1532                 CString sRev;\r
1533                 sRev.LoadString(IDS_LOG_REVISION);\r
1534                 CString sAuthor;\r
1535                 sAuthor.LoadString(IDS_LOG_AUTHOR);\r
1536                 CString sDate;\r
1537                 sDate.LoadString(IDS_LOG_DATE);\r
1538                 CString sMessage;\r
1539                 sMessage.LoadString(IDS_LOG_MESSAGE);\r
1540                 while (pos)\r
1541                 {\r
1542                         CString sLogCopyText;\r
1543                         CString sPaths;\r
1544                         GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(GetNextSelectedItem(pos)));\r
1545 \r
1546                         if(!HashOnly)\r
1547                         {\r
1548                                 //pLogEntry->m_Files\r
1549                                 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;\r
1550                         \r
1551                                 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->m_Files.GetCount(); ++cpPathIndex)\r
1552                                 {\r
1553                                         sPaths += ((CTGitPath&)pLogEntry->m_Files[cpPathIndex]).GetActionName() + _T(" : ") + pLogEntry->m_Files[cpPathIndex].GetGitPathString();\r
1554                                         sPaths += _T("\r\n");\r
1555                                 }\r
1556                                 sPaths.Trim();\r
1557                                 sLogCopyText.Format(_T("%s: %s\r\n%s: %s\r\n%s: %s\r\n%s:\r\n%s\r\n----\r\n%s\r\n\r\n"),\r
1558                                         (LPCTSTR)sRev, pLogEntry->m_CommitHash,\r
1559                                         (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->m_AuthorName,\r
1560                                         (LPCTSTR)sDate, \r
1561                                         (LPCTSTR)CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat, true, m_bRelativeTimes ),\r
1562                                         (LPCTSTR)sMessage, pLogEntry->m_Subject+_T("\r\n")+pLogEntry->m_Body,\r
1563                                         (LPCTSTR)sPaths);\r
1564                                 sClipdata +=  sLogCopyText;\r
1565                         }else\r
1566                         {\r
1567                                 sClipdata += pLogEntry->m_CommitHash;\r
1568                                 break;\r
1569                         }\r
1570 \r
1571                 }\r
1572                 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());\r
1573         }\r
1574 \r
1575 }\r
1576 \r
1577 void CGitLogListBase::DiffSelectedRevWithPrevious()\r
1578 {\r
1579         if (m_bThreadRunning)\r
1580                 return;\r
1581 \r
1582         int FirstSelect=-1, LastSelect=-1;\r
1583         POSITION pos = GetFirstSelectedItemPosition();\r
1584         FirstSelect = GetNextSelectedItem(pos);\r
1585         while(pos)\r
1586         {\r
1587                 LastSelect = GetNextSelectedItem(pos);\r
1588         }\r
1589 \r
1590         ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect);\r
1591 \r
1592 #if 0\r
1593         UpdateLogInfoLabel();\r
1594         int selIndex = m_LogList.GetSelectionMark();\r
1595         if (selIndex < 0)\r
1596                 return;\r
1597         int selCount = m_LogList.GetSelectedCount();\r
1598         if (selCount != 1)\r
1599                 return;\r
1600 \r
1601         // Find selected entry in the log list\r
1602         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1603         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1604         long rev1 = pLogEntry->Rev;\r
1605         long rev2 = rev1-1;\r
1606         CTGitPath path = m_path;\r
1607 \r
1608         // See how many files under the relative root were changed in selected revision\r
1609         int nChanged = 0;\r
1610         LogChangedPath * changed = NULL;\r
1611         for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)\r
1612         {\r
1613                 LogChangedPath * cpath = pLogEntry->pArChangedPaths->GetAt(c);\r
1614                 if (cpath  &&  cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)\r
1615                 {\r
1616                         ++nChanged;\r
1617                         changed = cpath;\r
1618                 }\r
1619         }\r
1620 \r
1621         if (m_path.IsDirectory() && nChanged == 1) \r
1622         {\r
1623                 // We're looking at the log for a directory and only one file under dir was changed in the revision\r
1624                 // Do diff on that file instead of whole directory\r
1625                 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));\r
1626         } \r
1627 \r
1628         m_bCancelled = FALSE;\r
1629         DialogEnableWindow(IDOK, FALSE);\r
1630         SetPromptApp(&theApp);\r
1631         theApp.DoWaitCursor(1);\r
1632 \r
1633         if (PromptShown())\r
1634         {\r
1635                 GitDiff diff(this, m_hWnd, true);\r
1636                 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1637                 diff.SetHEADPeg(m_LogRevision);\r
1638                 diff.ShowCompare(path, rev2, path, rev1);\r
1639         }\r
1640         else\r
1641         {\r
1642                 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1643         }\r
1644 \r
1645         theApp.DoWaitCursor(-1);\r
1646         EnableOKButton();\r
1647 #endif\r
1648 }\r
1649 \r
1650 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
1651 {\r
1652         LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);\r
1653         *pResult = -1;\r
1654         \r
1655         if (pFindInfo->lvfi.flags & LVFI_PARAM)\r
1656                 return; \r
1657         if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))\r
1658                 return;\r
1659         if (pFindInfo->lvfi.psz == 0)\r
1660                 return;\r
1661 #if 0\r
1662         CString sCmp = pFindInfo->lvfi.psz;\r
1663         CString sRev;   \r
1664         for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)\r
1665         {\r
1666                 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(i));\r
1667                 sRev.Format(_T("%ld"), pLogEntry->Rev);\r
1668                 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)\r
1669                 {\r
1670                         if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)\r
1671                         {\r
1672                                 *pResult = i;\r
1673                                 return;\r
1674                         }\r
1675                 }\r
1676                 else\r
1677                 {\r
1678                         if (sCmp.Compare(sRev)==0)\r
1679                         {\r
1680                                 *pResult = i;\r
1681                                 return;\r
1682                         }\r
1683                 }\r
1684         }\r
1685         if (pFindInfo->lvfi.flags & LVFI_WRAP)\r
1686         {\r
1687                 for (int i=0; i<pFindInfo->iStart; ++i)\r
1688                 {\r
1689                         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));\r
1690                         sRev.Format(_T("%ld"), pLogEntry->Rev);\r
1691                         if (pFindInfo->lvfi.flags & LVFI_PARTIAL)\r
1692                         {\r
1693                                 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)\r
1694                                 {\r
1695                                         *pResult = i;\r
1696                                         return;\r
1697                                 }\r
1698                         }\r
1699                         else\r
1700                         {\r
1701                                 if (sCmp.Compare(sRev)==0)\r
1702                                 {\r
1703                                         *pResult = i;\r
1704                                         return;\r
1705                                 }\r
1706                         }\r
1707                 }\r
1708         }\r
1709 #endif\r
1710         *pResult = -1;\r
1711 }\r
1712 \r
1713 int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to)\r
1714 {\r
1715         ClearText();\r
1716 \r
1717         this->m_logEntries.ClearAll();\r
1718         this->m_logEntries.ParserFromLog(path,-1,info,from,to);\r
1719 \r
1720         //this->m_logEntries.ParserFromLog();\r
1721         SetItemCountEx(this->m_logEntries.size());\r
1722 \r
1723         this->m_arShownList.RemoveAll();\r
1724 \r
1725         for(unsigned int i=0;i<m_logEntries.size();i++)\r
1726         {\r
1727                 if(m_IsOldFirst)\r
1728                 {\r
1729                         m_logEntries[m_logEntries.size()-i-1].m_IsFull=TRUE;\r
1730                         this->m_arShownList.Add(&m_logEntries[m_logEntries.size()-i-1]);\r
1731                 \r
1732                 }else\r
1733                 {\r
1734                         m_logEntries[i].m_IsFull=TRUE;\r
1735                         this->m_arShownList.Add(&m_logEntries[i]);\r
1736                 }\r
1737         }\r
1738 \r
1739     if(path)\r
1740         m_Path=*path;\r
1741         return 0;\r
1742 \r
1743 }\r
1744 \r
1745 int CGitLogListBase::FillGitShortLog()\r
1746 {\r
1747         ClearText();\r
1748 \r
1749         this->m_logEntries.ClearAll();\r
1750 \r
1751         m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);\r
1752 \r
1753     CTGitPath *path;\r
1754     if(this->m_Path.IsEmpty())\r
1755         path=NULL;\r
1756     else\r
1757         path=&this->m_Path;\r
1758 \r
1759         CString hash;\r
1760         int mask;\r
1761         mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;\r
1762 //      if(this->m_bAllBranch)\r
1763         mask |= m_ShowMask;\r
1764         \r
1765         if(m_bShowWC)\r
1766                 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev);\r
1767 \r
1768         this->m_logEntries.FetchShortLog(path,m_StartRef,-1,mask,m_bShowWC?1:0);\r
1769 \r
1770         //this->m_logEntries.ParserFromLog();\r
1771         if(IsInWorkingThread())\r
1772         {\r
1773                 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);\r
1774         }\r
1775         else\r
1776         {\r
1777                 SetItemCountEx(this->m_logEntries.size());\r
1778         }\r
1779 \r
1780         this->m_arShownList.RemoveAll();\r
1781 \r
1782         for(unsigned int i=0;i<m_logEntries.size();i++)\r
1783         {\r
1784                 if(i>0 || m_logEntries[i].m_CommitHash != GIT_REV_ZERO)\r
1785                         m_logEntries[i].m_Subject=_T("parser...");\r
1786 \r
1787                 if(this->m_IsOldFirst)\r
1788                 {\r
1789                         this->m_arShownList.Add(&m_logEntries[m_logEntries.size()-1-i]);\r
1790 \r
1791                 }else\r
1792                 {\r
1793                         this->m_arShownList.Add(&m_logEntries[i]);\r
1794                 }\r
1795         }\r
1796         return 0;\r
1797 }\r
1798 \r
1799 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)\r
1800 {\r
1801         // Skip Ctrl-C when copying text out of the log message or search filter\r
1802         BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );\r
1803         if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')\r
1804         {\r
1805                 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))\r
1806                 {\r
1807                         if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))\r
1808                         {\r
1809                                 DiffSelectedRevWithPrevious();\r
1810                                 return TRUE;\r
1811                         }\r
1812                 }\r
1813 #if 0\r
1814                 if (GetFocus()==GetDlgItem(IDC_LOGMSG))\r
1815                 {\r
1816                         DiffSelectedFile();\r
1817                         return TRUE;\r
1818                 }\r
1819 #endif\r
1820         }\r
1821 \r
1822 #if 0\r
1823         if (m_hAccel && !bSkipAccelerator)\r
1824         {\r
1825                 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);\r
1826                 if (ret)\r
1827                         return TRUE;\r
1828         }\r
1829         \r
1830 #endif\r
1831         //m_tooltips.RelayEvent(pMsg);\r
1832         return __super::PreTranslateMessage(pMsg);\r
1833 }\r
1834 \r
1835 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)\r
1836 {\r
1837         // a double click on an entry in the revision list has happened\r
1838         *pResult = 0;\r
1839 \r
1840         if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))\r
1841                 DiffSelectedRevWithPrevious();\r
1842 }\r
1843 \r
1844 int CGitLogListBase::FetchLogAsync(void * data)\r
1845 {\r
1846         m_ProcData=data;\r
1847         m_bExitThread=FALSE;\r
1848         InterlockedExchange(&m_bThreadRunning, TRUE);\r
1849         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
1850         m_LoadingThread = AfxBeginThread(LogThreadEntry, this);\r
1851         if (m_LoadingThread ==NULL)\r
1852         {\r
1853                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
1854                 InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
1855                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
1856                 return -1;\r
1857         }\r
1858         return 0;\r
1859 }\r
1860 \r
1861 //this is the thread function which calls the subversion function\r
1862 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)\r
1863 {\r
1864         return ((CGitLogListBase*)pVoid)->LogThread();\r
1865 }\r
1866 \r
1867 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)\r
1868 {\r
1869         //CTime time;\r
1870         oldest=CTime::GetCurrentTime();\r
1871         latest=CTime(1971,1,2,0,0,0);\r
1872         for(unsigned int i=0;i<m_logEntries.size();i++)\r
1873         {\r
1874                 if(m_logEntries[i].m_AuthorDate.GetTime() < oldest.GetTime())\r
1875                         oldest = m_logEntries[i].m_AuthorDate.GetTime();\r
1876 \r
1877                 if(m_logEntries[i].m_AuthorDate.GetTime() > latest.GetTime())\r
1878                         latest = m_logEntries[i].m_AuthorDate.GetTime();\r
1879 \r
1880         }\r
1881 }\r
1882 \r
1883 //Helper class for FetchFullLogInfo()\r
1884 class CGitCall_FetchFullLogInfo : public CGitCall\r
1885 {\r
1886 public:\r
1887         CGitCall_FetchFullLogInfo(CGitLogListBase* ploglist):m_ploglist(ploglist),m_CollectedCount(0){}\r
1888         virtual bool OnOutputData(const BYTE* data, size_t size)\r
1889         {\r
1890                 if(size==0)\r
1891                         return m_ploglist->m_bExitThread;\r
1892                 //Add received data to byte collector\r
1893                 m_ByteCollector.append(data,size);\r
1894 \r
1895                 //Find loginfo endmarker\r
1896                 static const BYTE dataToFind[]={0,0,'#','<'};\r
1897                 int found=m_ByteCollector.findData(dataToFind,4);\r
1898                 if(found<0)\r
1899                         return m_ploglist->m_bExitThread;//Not found\r
1900                 found+=2;//Position after loginfo end-marker\r
1901 \r
1902                 //Prepare data for OnLogInfo and call it\r
1903                 BYTE_VECTOR logInfo;\r
1904                 logInfo.append(&*m_ByteCollector.begin(),found);\r
1905                 OnLogInfo(logInfo);\r
1906 \r
1907                 //Remove loginfo from bytecollector\r
1908                 m_ByteCollector.erase(m_ByteCollector.begin(),m_ByteCollector.begin()+found);\r
1909 \r
1910                 return m_ploglist->m_bExitThread;\r
1911         }\r
1912         virtual void OnEnd()\r
1913         {\r
1914                 //Rest should be a complete log line.\r
1915                 if(!m_ByteCollector.empty())\r
1916                         OnLogInfo(m_ByteCollector);\r
1917         }\r
1918 \r
1919 \r
1920         void OnLogInfo(BYTE_VECTOR& logInfo)\r
1921         {\r
1922                 GitRev fullRev;\r
1923                 fullRev.ParserFromLog(logInfo);\r
1924                 MAP_HASH_REV::iterator itRev=m_ploglist->m_logEntries.m_HashMap.find(fullRev.m_CommitHash);\r
1925                 if(itRev==m_ploglist->m_logEntries.m_HashMap.end())\r
1926                 {\r
1927                         //Should not occur, only when Git-tree updated in the mean time. (Race condition)\r
1928                         return;//Ignore\r
1929                 }\r
1930                 //Set updating\r
1931                 int rev=itRev->second;\r
1932                 GitRev* revInVector=&m_ploglist->m_logEntries[rev];\r
1933 \r
1934 \r
1935                 if(revInVector->m_IsFull)\r
1936                         return;\r
1937 \r
1938                 if(!m_ploglist->m_LogCache.GetCacheData(m_ploglist->m_logEntries[rev]))\r
1939                 {\r
1940                         ++m_CollectedCount;\r
1941                         InterlockedExchange(&m_ploglist->m_logEntries[rev].m_IsUpdateing,FALSE);\r
1942                         InterlockedExchange(&m_ploglist->m_logEntries[rev].m_IsFull,TRUE);\r
1943                         ::PostMessage(m_ploglist->m_hWnd,MSG_LOADED,(WPARAM)rev,0);\r
1944                         return;\r
1945                 }\r
1946 \r
1947 //              fullRev.m_IsUpdateing=TRUE;\r
1948 //              fullRev.m_IsFull=TRUE;\r
1949         \r
1950 \r
1951                 if(InterlockedExchange(&revInVector->m_IsUpdateing,TRUE))\r
1952                         return;//Cannot update this row now. Ignore.\r
1953                 TCHAR oldmark=revInVector->m_Mark;\r
1954                 GIT_REV_LIST oldlist=revInVector->m_ParentHash;\r
1955 //              CString oldhash=m_CommitHash;\r
1956 \r
1957                 //Parse new rev info\r
1958                 revInVector->ParserFromLog(logInfo);\r
1959 \r
1960                 if(oldmark!=0)\r
1961                         revInVector->m_Mark=oldmark;  //parser full log will cause old mark overwrited. \r
1962                                                                //So we need keep old bound mark.\r
1963                 revInVector->m_ParentHash=oldlist;\r
1964 \r
1965                 //update cache\r
1966                 m_ploglist->m_LogCache.AddCacheEntry(*revInVector);\r
1967 \r
1968                 //Reset updating\r
1969                 InterlockedExchange(&revInVector->m_IsFull,TRUE);\r
1970                 InterlockedExchange(&revInVector->m_IsUpdateing,FALSE);\r
1971 \r
1972                 //Notify listcontrol and update progress bar\r
1973                 ++m_CollectedCount;\r
1974 \r
1975                 ::PostMessage(m_ploglist->m_hWnd,MSG_LOADED,(WPARAM)rev,0);\r
1976 \r
1977                 DWORD percent=m_CollectedCount*68/m_ploglist->m_logEntries.size() + GITLOG_START+1+30;\r
1978                 if(percent == GITLOG_END)\r
1979                         percent = GITLOG_END -1;\r
1980                 \r
1981                 ::PostMessage(m_ploglist->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);\r
1982         }\r
1983 \r
1984         CGitLogListBase*        m_ploglist;\r
1985         BYTE_VECTOR                     m_ByteCollector;\r
1986         int                                     m_CollectedCount;\r
1987 \r
1988 };\r
1989 \r
1990 void CGitLogListBase::FetchFullLogInfo(CString &from, CString &to)\r
1991 {\r
1992         CGitCall_FetchFullLogInfo fetcher(this);\r
1993         int mask=\r
1994                 CGit::LOG_INFO_FULL_DIFF|\r
1995                 CGit::LOG_INFO_STAT|\r
1996                 CGit::LOG_INFO_FILESTATE|\r
1997                 CGit::LOG_INFO_DETECT_COPYRENAME|\r
1998                 CGit::LOG_INFO_SHOW_MERGEDFILE |\r
1999                 m_ShowMask;\r
2000 \r
2001         CTGitPath *path;\r
2002     if(this->m_Path.IsEmpty())\r
2003         path=NULL;\r
2004     else\r
2005         path=&this->m_Path;\r
2006 \r
2007         g_Git.GetLog(&fetcher,CString(),path,-1,mask,&from,&to);\r
2008 }\r
2009 \r
2010 void CGitLogListBase::FetchLastLogInfo()\r
2011 {\r
2012         unsigned int updated=0;\r
2013         int percent=0;\r
2014         CRect rect;\r
2015         {\r
2016                 for(unsigned int i=0;i<m_logEntries.size();i++)\r
2017                 {\r
2018                         if(m_logEntries[i].m_IsFull)\r
2019                                 continue;\r
2020 \r
2021                         if(m_LogCache.GetCacheData(m_logEntries[i]))\r
2022                         {\r
2023                                 if(!m_logEntries.FetchFullInfo(i))\r
2024                                 {\r
2025                                         updated++;\r
2026                                 }\r
2027                                 m_LogCache.AddCacheEntry(m_logEntries[i]);\r
2028 \r
2029                         }else\r
2030                         {\r
2031                                 updated++;\r
2032                                 InterlockedExchange(&m_logEntries[i].m_IsUpdateing,FALSE);\r
2033                                 InterlockedExchange(&m_logEntries[i].m_IsFull,TRUE);\r
2034                         }\r
2035                         \r
2036                         ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);\r
2037 \r
2038                         if(m_bExitThread)\r
2039                         {\r
2040                                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
2041                                 InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2042                                 return;\r
2043                         }                       \r
2044                 }\r
2045         }\r
2046 }\r
2047 \r
2048 UINT CGitLogListBase::LogThread()\r
2049 {\r
2050 \r
2051 //      if(m_ProcCallBack)\r
2052 //              m_ProcCallBack(m_ProcData,GITLOG_START);\r
2053         ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);\r
2054 \r
2055         InterlockedExchange(&m_bThreadRunning, TRUE);\r
2056         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
2057 \r
2058     //does the user force the cache to refresh (shift or control key down)?\r
2059     bool refresh =    (GetKeyState (VK_CONTROL) < 0) \r
2060                    || (GetKeyState (VK_SHIFT) < 0);\r
2061 \r
2062         //disable the "Get All" button while we're receiving\r
2063         //log messages.\r
2064 \r
2065         FillGitShortLog();\r
2066         \r
2067         if(this->m_bExitThread)\r
2068         {\r
2069                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
2070                 InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2071                 return 0;\r
2072         }\r
2073         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2074         ::PostMessage(GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START_ALL, 0);\r
2075 \r
2076         int start=0; CString firstcommit,lastcommit;\r
2077         int update=0;\r
2078         for(int i=0;i<m_logEntries.size();i++)\r
2079         {\r
2080                 if( i==0 && m_logEntries[i].m_CommitHash == GIT_REV_ZERO)\r
2081                 {\r
2082                         m_logEntries[i].m_Files.Clear();\r
2083                         m_logEntries[i].m_ParentHash.clear();\r
2084                         m_logEntries[i].m_ParentHash.push_back(m_HeadHash);\r
2085                         g_Git.GetCommitDiffList(m_logEntries[i].m_CommitHash,this->m_HeadHash,m_logEntries[i].m_Files);\r
2086                         m_logEntries[i].m_Action =0;\r
2087                         for(int j=0;j< m_logEntries[i].m_Files.GetCount();j++)\r
2088                                 m_logEntries[i].m_Action |= m_logEntries[i].m_Files[j].m_Action;\r
2089                         \r
2090                         m_logEntries[i].m_Body.Format(_T("%d files changed"),m_logEntries[i].m_Files.GetCount());\r
2091                         ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);\r
2092                         continue;\r
2093                 }\r
2094 \r
2095                 start=this->m_logEntries[i].ParserFromLog(m_logEntries.m_RawlogData,start);\r
2096                 m_logEntries.m_HashMap[m_logEntries[i].m_CommitHash]=i;\r
2097 \r
2098                 if(m_LogCache.GetCacheData(m_logEntries[i]))\r
2099                 {\r
2100                         if(firstcommit.IsEmpty())\r
2101                                 firstcommit=m_logEntries[i].m_CommitHash;\r
2102                         lastcommit=m_logEntries[i].m_CommitHash;\r
2103 \r
2104                 }else\r
2105                 {\r
2106                         InterlockedExchange(&m_logEntries[i].m_IsUpdateing,FALSE);\r
2107                         InterlockedExchange(&m_logEntries[i].m_IsFull,TRUE);\r
2108                         update++;\r
2109                 }\r
2110                 if(start<0)\r
2111                         break;\r
2112                 if(start>=m_logEntries.m_RawlogData.size())\r
2113                         break;\r
2114 \r
2115                 int percent=i*30/m_logEntries.size() + GITLOG_START+1;\r
2116 \r
2117                 ::PostMessage(GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent, 0);\r
2118                 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM) i, 0);\r
2119 \r
2120                 if(this->m_bExitThread)\r
2121                 {       \r
2122                         InterlockedExchange(&m_bThreadRunning, FALSE);\r
2123                         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2124                         return 0;\r
2125                 }\r
2126         }\r
2127         if(!lastcommit.IsEmpty())\r
2128                 FetchFullLogInfo(lastcommit,firstcommit);\r
2129         \r
2130         this->FetchLastLogInfo();\r
2131         \r
2132 #if 0\r
2133         RedrawItems(0, m_arShownList.GetCount());\r
2134 //      SetRedraw(false);\r
2135 //      ResizeAllListCtrlCols();\r
2136 //      SetRedraw(true);\r
2137 \r
2138         if ( m_pStoreSelection )\r
2139         {\r
2140                 // Deleting the instance will restore the\r
2141                 // selection of the CLogDlg.\r
2142                 delete m_pStoreSelection;\r
2143                 m_pStoreSelection = NULL;\r
2144         }\r
2145         else\r
2146         {\r
2147                 // If no selection has been set then this must be the first time\r
2148                 // the revisions are shown. Let's preselect the topmost revision.\r
2149                 if ( GetItemCount()>0 )\r
2150                 {\r
2151                         SetSelectionMark(0);\r
2152                         SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);\r
2153                 }\r
2154         }\r
2155 #endif\r
2156 \r
2157 \r
2158 \r
2159         //FetchFullLogInfo();\r
2160         //FetchFullLogInfoOrig();\r
2161         //RefreshCursor();\r
2162         // make sure the filter is applied (if any) now, after we refreshed/fetched\r
2163         // the log messages\r
2164 \r
2165         ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);\r
2166 \r
2167         InterlockedExchange(&m_bThreadRunning, FALSE);\r
2168 \r
2169         return 0;\r
2170 }\r
2171 \r
2172 void CGitLogListBase::Refresh()\r
2173 {       \r
2174         m_bExitThread=TRUE;\r
2175         if(m_LoadingThread!=NULL)\r
2176         {\r
2177                 DWORD ret =::WaitForSingleObject(m_LoadingThread->m_hThread,20000);\r
2178                 if(ret == WAIT_TIMEOUT)\r
2179                         TerminateThread();\r
2180         }\r
2181         \r
2182         this->SetItemCountEx(0);\r
2183         this->Clear();\r
2184 \r
2185         //Update branch and Tag info\r
2186         ReloadHashMap();\r
2187         //Assume Thread have exited\r
2188         //if(!m_bThreadRunning)\r
2189         {\r
2190                 \r
2191                 m_logEntries.clear();\r
2192                 m_bExitThread=FALSE;\r
2193                 InterlockedExchange(&m_bThreadRunning, TRUE);\r
2194                 InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
2195                 if (AfxBeginThread(LogThreadEntry, this)==NULL)\r
2196                 {\r
2197                         InterlockedExchange(&m_bThreadRunning, FALSE);\r
2198                         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2199                         CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
2200                 }\r
2201                 m_sFilterText.Empty();\r
2202                 m_From=CTime(1970,1,2,0,0,0);\r
2203                 m_To=CTime::GetCurrentTime();\r
2204         }\r
2205 }\r
2206 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)\r
2207 {\r
2208         try\r
2209         {\r
2210                 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;\r
2211                 if (!bMatchCase)\r
2212                         type |= tr1::regex_constants::icase;\r
2213                 pat = tr1::wregex(regexp_str, type);\r
2214                 return true;\r
2215         }\r
2216         catch (exception) {}\r
2217         return false;\r
2218 }\r
2219 \r
2220 void CGitLogListBase::RecalculateShownList(CPtrArray * pShownlist)\r
2221 {\r
2222 \r
2223         pShownlist->RemoveAll();\r
2224         tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);\r
2225         bool bRegex = false;\r
2226         if (m_bFilterWithRegex)\r
2227                 bRegex = ValidateRegexp(m_sFilterText, pat, false);\r
2228 \r
2229         tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;\r
2230         CString sRev;\r
2231         for (DWORD i=0; i<m_logEntries.size(); ++i)\r
2232         {\r
2233                 if ((bRegex)&&(m_bFilterWithRegex))\r
2234                 {\r
2235 #if 0\r
2236                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))\r
2237                         {\r
2238                                 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);\r
2239                                 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))\r
2240                                 {\r
2241                                         pShownlist->Add(m_logEntries[i]);\r
2242                                         continue;\r
2243                                 }\r
2244                         }\r
2245 #endif\r
2246                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))\r
2247                         {\r
2248                                 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries[i].m_Subject);\r
2249                                 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_Subject), pat, flags)&&IsEntryInDateRange(i))\r
2250                                 {\r
2251                                         pShownlist->Add(&m_logEntries[i]);\r
2252                                         continue;\r
2253                                 }\r
2254 \r
2255                                 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries[i].m_Body);\r
2256                                 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_Body), pat, flags)&&IsEntryInDateRange(i))\r
2257                                 {\r
2258                                         pShownlist->Add(&m_logEntries[i]);\r
2259                                         continue;\r
2260                                 }\r
2261                         }\r
2262 #if 0\r
2263                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))\r
2264                         {\r
2265                                 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;\r
2266 \r
2267                                 bool bGoing = true;\r
2268                                 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)\r
2269                                 {\r
2270                                         LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
2271                                         if (regex_search(wstring((LPCTSTR)cpath->sCopyFromPath), pat, flags)&&IsEntryInDateRange(i))\r
2272                                         {\r
2273                                                 pShownlist->Add(m_logEntries[i]);\r
2274                                                 bGoing = false;\r
2275                                                 continue;\r
2276                                         }\r
2277                                         if (regex_search(wstring((LPCTSTR)cpath->sPath), pat, flags)&&IsEntryInDateRange(i))\r
2278                                         {\r
2279                                                 pShownlist->Add(m_logEntries[i]);\r
2280                                                 bGoing = false;\r
2281                                                 continue;\r
2282                                         }\r
2283                                         if (regex_search(wstring((LPCTSTR)cpath->GetAction()), pat, flags)&&IsEntryInDateRange(i))\r
2284                                         {\r
2285                                                 pShownlist->Add(m_logEntries[i]);\r
2286                                                 bGoing = false;\r
2287                                                 continue;\r
2288                                         }\r
2289                                 }\r
2290                                 if (!bGoing)\r
2291                                         continue;\r
2292                         }\r
2293 #endif\r
2294                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))\r
2295                         {\r
2296                                 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_AuthorName), pat, flags)&&IsEntryInDateRange(i))\r
2297                                 {\r
2298                                         pShownlist->Add(&m_logEntries[i]);\r
2299                                         continue;\r
2300                                 }\r
2301                         }\r
2302                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))\r
2303                         {\r
2304                                 sRev.Format(_T("%s"), m_logEntries[i].m_CommitHash);\r
2305                                 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))\r
2306                                 {\r
2307                                         pShownlist->Add(&m_logEntries[i]);\r
2308                                         continue;\r
2309                                 }\r
2310                         }\r
2311                 } // if (bRegex)\r
2312                 else\r
2313                 {\r
2314                         CString find = m_sFilterText;\r
2315                         find.MakeLower();\r
2316 #if 0\r
2317                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))\r
2318                         {\r
2319                                 CString sBugIDs = m_logEntries[i]->sBugIDs;\r
2320 \r
2321                                 sBugIDs = sBugIDs.MakeLower();\r
2322                                 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))\r
2323                                 {\r
2324                                         pShownlist->Add(m_logEntries[i]);\r
2325                                         continue;\r
2326                                 }\r
2327                         }\r
2328 #endif\r
2329                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))\r
2330                         {\r
2331                                 CString msg = m_logEntries[i].m_Subject;\r
2332 \r
2333                                 msg = msg.MakeLower();\r
2334                                 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))\r
2335                                 {\r
2336                                         pShownlist->Add(&m_logEntries[i]);\r
2337                                         continue;\r
2338                                 }\r
2339                                 msg = m_logEntries[i].m_Body;\r
2340 \r
2341                                 msg = msg.MakeLower();\r
2342                                 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))\r
2343                                 {\r
2344                                         pShownlist->Add(&m_logEntries[i]);\r
2345                                         continue;\r
2346                                 }\r
2347                         }\r
2348 #if 0\r
2349                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))\r
2350                         {\r
2351                                 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;\r
2352 \r
2353                                 bool bGoing = true;\r
2354                                 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)\r
2355                                 {\r
2356                                         LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
2357                                         CString path = cpath->sCopyFromPath;\r
2358                                         path.MakeLower();\r
2359                                         if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))\r
2360                                         {\r
2361                                                 pShownlist->Add(m_logEntries[i]);\r
2362                                                 bGoing = false;\r
2363                                                 continue;\r
2364                                         }\r
2365                                         path = cpath->sPath;\r
2366                                         path.MakeLower();\r
2367                                         if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))\r
2368                                         {\r
2369                                                 pShownlist->Add(m_logEntries[i]);\r
2370                                                 bGoing = false;\r
2371                                                 continue;\r
2372                                         }\r
2373                                         path = cpath->GetAction();\r
2374                                         path.MakeLower();\r
2375                                         if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))\r
2376                                         {\r
2377                                                 pShownlist->Add(m_logEntries[i]);\r
2378                                                 bGoing = false;\r
2379                                                 continue;\r
2380                                         }\r
2381                                 }\r
2382                         }\r
2383 #endif\r
2384                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))\r
2385                         {\r
2386                                 CString msg = m_logEntries[i].m_AuthorName;\r
2387                                 msg = msg.MakeLower();\r
2388                                 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))\r
2389                                 {\r
2390                                         pShownlist->Add(&m_logEntries[i]);\r
2391                                         continue;\r
2392                                 }\r
2393                         }\r
2394                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))\r
2395                         {\r
2396                                 sRev.Format(_T("%s"), m_logEntries[i].m_CommitHash);\r
2397                                 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))\r
2398                                 {\r
2399                                         pShownlist->Add(&m_logEntries[i]);\r
2400                                         continue;\r
2401                                 }\r
2402                         }\r
2403                 } // else (from if (bRegex))    \r
2404         } // for (DWORD i=0; i<m_logEntries.size(); ++i) \r
2405 \r
2406 }\r
2407 \r
2408 BOOL CGitLogListBase::IsEntryInDateRange(int i)\r
2409 {\r
2410         __time64_t time = m_logEntries[i].m_AuthorDate.GetTime();\r
2411         if ((time >= m_From.GetTime())&&(time <= m_To.GetTime()))\r
2412                 return TRUE;\r
2413 \r
2414         return FALSE;\r
2415 \r
2416 //      return TRUE;\r
2417 }\r
2418 void CGitLogListBase::StartFilter()\r
2419 {\r
2420         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
2421         RecalculateShownList(&m_arShownList);\r
2422         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2423 \r
2424 \r
2425         DeleteAllItems();\r
2426         SetItemCountEx(ShownCountWithStopped());\r
2427         RedrawItems(0, ShownCountWithStopped());\r
2428         SetRedraw(false);\r
2429         //ResizeAllListCtrlCols();\r
2430         SetRedraw(true);\r
2431         Invalidate();\r
2432 \r
2433 }\r
2434 void CGitLogListBase::RemoveFilter()\r
2435 {\r
2436 \r
2437         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
2438 \r
2439         m_arShownList.RemoveAll();\r
2440 \r
2441         // reset the time filter too\r
2442 #if 0\r
2443         m_timFrom = (__time64_t(m_tFrom));\r
2444         m_timTo = (__time64_t(m_tTo));\r
2445         m_DateFrom.SetTime(&m_timFrom);\r
2446         m_DateTo.SetTime(&m_timTo);\r
2447         m_DateFrom.SetRange(&m_timFrom, &m_timTo);\r
2448         m_DateTo.SetRange(&m_timFrom, &m_timTo);\r
2449 #endif\r
2450 \r
2451         for (DWORD i=0; i<m_logEntries.size(); ++i)\r
2452         {\r
2453                 if(this->m_IsOldFirst)\r
2454                 {\r
2455                         m_arShownList.Add(&m_logEntries[m_logEntries.size()-i-1]);\r
2456                 }else\r
2457                 {\r
2458                         m_arShownList.Add(&m_logEntries[i]);\r
2459                 }\r
2460         }\r
2461 //      InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2462         DeleteAllItems();\r
2463         SetItemCountEx(ShownCountWithStopped());\r
2464         RedrawItems(0, ShownCountWithStopped());\r
2465 //      SetRedraw(false);\r
2466 //      ResizeAllListCtrlCols();\r
2467 //      SetRedraw(true);\r
2468 \r
2469         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2470 }\r
2471 \r
2472 void CGitLogListBase::Clear()\r
2473 {\r
2474         m_arShownList.RemoveAll();\r
2475         DeleteAllItems();\r
2476 \r
2477         m_logEntries.ClearAll();\r
2478 \r
2479 }\r
2480 \r
2481 void CGitLogListBase::OnDestroy()\r
2482 {\r
2483         // save the column widths to the registry\r
2484         SaveColumnWidths();\r
2485 \r
2486         if(this->m_bThreadRunning)\r
2487         {\r
2488                 this->m_bExitThread=true;\r
2489                 DWORD ret =::WaitForSingleObject(m_LoadingThread->m_hThread,20000);\r
2490                 if(ret == WAIT_TIMEOUT)\r
2491                         TerminateThread();\r
2492         }\r
2493         while(m_LogCache.SaveCache())\r
2494         {\r
2495                 if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),\r
2496                                                         MB_YESNO) == IDNO)\r
2497                                                         break;\r
2498         }\r
2499         CHintListCtrl::OnDestroy();\r
2500 }\r
2501 \r
2502 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)\r
2503 {\r
2504         CRect rect;\r
2505         int i=(int)wParam;\r
2506         this->GetItemRect(i,&rect,LVIR_BOUNDS);\r
2507         this->InvalidateRect(rect);\r
2508 \r
2509         if(this->GetItemState(i,LVIF_STATE) & LVIS_SELECTED)\r
2510         {\r
2511                 int i=0;\r
2512         }\r
2513         return 0;\r
2514 }\r
2515 \r
2516 /**\r
2517  * Save column widths to the registry\r
2518  */\r
2519 void CGitLogListBase::SaveColumnWidths()\r
2520 {\r
2521         CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));\r
2522         if (pHdrCtrl)\r
2523         {\r
2524                 int numcols = pHdrCtrl->GetItemCount();\r
2525                 for (int col = 0; col < numcols; col++)\r
2526                 {\r
2527                         int width = GetColumnWidth( col );\r
2528                         CString regentry;\r
2529                         regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);\r
2530                         CRegDWORD regwidth(regentry, 0);\r
2531                         regwidth = width;       // this writes it to reg\r
2532                 }\r
2533         }\r
2534 }\r
2535 \r
2536 int CGitLogListBase::GetHeadIndex()\r
2537 {\r
2538         if(m_HeadHash.IsEmpty())\r
2539                 return -1;\r
2540 \r
2541         for(int i=0;i<m_arShownList.GetCount();i++)\r
2542         {\r
2543                 GitRev *pRev = (GitRev*)m_arShownList[i];\r
2544                 if(pRev)\r
2545                 {\r
2546                         if(pRev->m_CommitHash == m_HeadHash )\r
2547                                 return i;\r
2548                 }\r
2549         }\r
2550         return -1;\r
2551 }