OSDN Git Service

Add Show "No Merge" and "First Parent Only" Option at Show ALL menu button
[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 {\r
61         // use the default GUI font, create a copy of it and\r
62         // change the copy to BOLD (leave the rest of the font\r
63         // the same)\r
64         HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);\r
65         LOGFONT lf = {0};\r
66         GetObject(hFont, sizeof(LOGFONT), &lf);\r
67         lf.lfWeight = FW_BOLD;\r
68         m_boldFont = CreateFontIndirect(&lf);\r
69         \r
70         m_bShowBugtraqColumn=0;\r
71 \r
72         m_IsIDReplaceAction=FALSE;\r
73 \r
74         m_wcRev.m_CommitHash=GIT_REV_ZERO;\r
75         m_wcRev.m_Subject=_T("Working Copy");\r
76 \r
77         m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
78         m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
79         m_hAddedIcon    =  (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
80         m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
81 \r
82         m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);\r
83 \r
84         g_Git.GetMapHashToFriendName(m_HashMap);\r
85         m_CurrentBranch=g_Git.GetCurrentBranch();\r
86 \r
87         m_From=CTime(1970,1,2,0,0,0);\r
88         m_To=CTime::GetCurrentTime();\r
89     m_ShowMask = 0;\r
90         m_LoadingThread = NULL;\r
91 \r
92         m_bExitThread=FALSE;\r
93 \r
94         for(int i=0;i<Lanes::COLORS_NUM;i++)\r
95         {\r
96                 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));\r
97         }\r
98         // get short/long datetime setting from registry\r
99         DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);\r
100         if ( RegUseShortDateFormat )\r
101         {\r
102                 m_DateFormat = DATE_SHORTDATE;\r
103         }\r
104         else\r
105         {\r
106                 m_DateFormat = DATE_LONGDATE;\r
107         }\r
108 }\r
109 \r
110 CGitLogListBase::~CGitLogListBase()\r
111 {\r
112         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
113 \r
114         DestroyIcon(m_hModifiedIcon);\r
115         DestroyIcon(m_hReplacedIcon);\r
116         DestroyIcon(m_hAddedIcon);\r
117         DestroyIcon(m_hDeletedIcon);\r
118         m_logEntries.ClearAll();\r
119 \r
120         if (m_boldFont)\r
121                 DeleteObject(m_boldFont);\r
122 \r
123         if ( m_pStoreSelection )\r
124         {\r
125                 delete m_pStoreSelection;\r
126                 m_pStoreSelection = NULL;\r
127         }\r
128 \r
129         if(this->m_bThreadRunning)\r
130         {\r
131                 m_bExitThread=true;\r
132                 WaitForSingleObject(m_LoadingThread->m_hThread,1000);\r
133                 TerminateThread();\r
134         }\r
135 }\r
136 \r
137 \r
138 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)\r
139         ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)\r
140         ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)\r
141         ON_WM_CONTEXTMENU()\r
142         ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)\r
143         ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)\r
144         ON_WM_CREATE()\r
145         ON_WM_DESTROY()\r
146         ON_MESSAGE(MSG_LOADED,OnLoad)\r
147 END_MESSAGE_MAP()\r
148 \r
149 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)\r
150 {\r
151         PreSubclassWindow();\r
152         return CHintListCtrl::OnCreate(lpCreateStruct);\r
153 }\r
154 \r
155 void CGitLogListBase::PreSubclassWindow()\r
156 {\r
157         SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);\r
158         // load the icons for the action columns\r
159         m_Theme.SetWindowTheme(GetSafeHwnd(), L"Explorer", NULL);\r
160         CHintListCtrl::PreSubclassWindow();\r
161 }\r
162 \r
163 void CGitLogListBase::InsertGitColumn()\r
164 {\r
165         CString temp;\r
166 \r
167         int c = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;\r
168         \r
169         while (c>=0)\r
170                 DeleteColumn(c--);\r
171         temp.LoadString(IDS_LOG_GRAPH);\r
172 \r
173         InsertColumn(this->LOGLIST_GRAPH, temp);\r
174         \r
175 #if 0   \r
176         // make the revision column right aligned\r
177         LVCOLUMN Column;\r
178         Column.mask = LVCF_FMT;\r
179         Column.fmt = LVCFMT_RIGHT;\r
180         SetColumn(0, &Column); \r
181 #endif  \r
182 //      CString log;\r
183 //      g_Git.GetLog(log);\r
184 \r
185         if(m_IsIDReplaceAction)\r
186         {\r
187                 temp.LoadString(IDS_LOG_ID);\r
188                 InsertColumn(this->LOGLIST_ACTION, temp);\r
189         }\r
190         else\r
191         {\r
192                 temp.LoadString(IDS_LOG_ACTIONS);\r
193                 InsertColumn(this->LOGLIST_ACTION, temp);\r
194         }\r
195         temp.LoadString(IDS_LOG_MESSAGE);\r
196         InsertColumn(this->LOGLIST_MESSAGE, temp);\r
197         \r
198         temp.LoadString(IDS_LOG_AUTHOR);\r
199         InsertColumn(this->LOGLIST_AUTHOR, temp);\r
200         \r
201         temp.LoadString(IDS_LOG_DATE);\r
202         InsertColumn(this->LOGLIST_DATE, temp);\r
203         \r
204 \r
205         if (m_bShowBugtraqColumn)\r
206         {\r
207 //              temp = m_ProjectProperties.sLabel;\r
208                 if (temp.IsEmpty())\r
209                         temp.LoadString(IDS_LOG_BUGIDS);\r
210                 InsertColumn(this->LOGLIST_BUG, temp);\r
211 \r
212         }\r
213         \r
214         SetRedraw(false);\r
215         ResizeAllListCtrlCols();\r
216         SetRedraw(true);\r
217 \r
218 }\r
219 \r
220 /**\r
221  * Resizes all columns in a list control to values in registry.\r
222  */\r
223 void CGitLogListBase::ResizeAllListCtrlCols()\r
224 {\r
225         // column max and min widths to allow\r
226         static const int nMinimumWidth = 10;\r
227         static const int nMaximumWidth = 1000;\r
228         CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));\r
229         if (pHdrCtrl)\r
230         {\r
231                 int numcols = pHdrCtrl->GetItemCount();\r
232                 for (int col = 0; col < numcols; col++)\r
233                 {\r
234                         // get width for this col last time from registry\r
235                         CString regentry;\r
236                         regentry.Format( _T("Software\\TortoiseGit\\log\\ColWidth%d"), col);\r
237                         CRegDWORD regwidth(regentry, 0);\r
238                         int cx = regwidth;\r
239                         if (cx < nMinimumWidth)\r
240                         {\r
241                                 cx = nMinimumWidth;\r
242                         } else if (cx > nMaximumWidth)\r
243                         {\r
244                                 cx = nMaximumWidth;\r
245                         }\r
246 \r
247                         SetColumnWidth(col, cx);\r
248                 }\r
249         }\r
250 \r
251 }\r
252 \r
253 \r
254 BOOL CGitLogListBase::GetShortName(CString ref, CString &shortname,CString prefix)\r
255 {\r
256         TRACE(_T("%s %s\r\n"),ref,prefix);\r
257         if(ref.Left(prefix.GetLength()) ==  prefix)\r
258         {\r
259                 shortname = ref.Right(ref.GetLength()-prefix.GetLength());\r
260                 if(shortname.Right(3)==_T("^{}"))\r
261                         shortname=shortname.Left(shortname.GetLength()-3);\r
262                 return TRUE;\r
263         }\r
264         return FALSE;\r
265 }\r
266 void CGitLogListBase::FillBackGround(HDC hdc, int Index,CRect &rect)\r
267 {       \r
268 //      HBRUSH brush;\r
269         LVITEM   rItem;\r
270         SecureZeroMemory(&rItem, sizeof(LVITEM));\r
271         rItem.mask  = LVIF_STATE;\r
272         rItem.iItem = Index;\r
273         rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;\r
274         GetItem(&rItem);\r
275 \r
276         if (m_Theme.IsAppThemed() && m_bVista)\r
277         {\r
278                 m_Theme.Open(m_hWnd, L"Explorer");\r
279                 int state = LISS_NORMAL;\r
280                 if (rItem.state & LVIS_SELECTED)\r
281                 {\r
282                         if (::GetFocus() == m_hWnd)\r
283                                 state |= LISS_SELECTED;\r
284                         else\r
285                                 state |= LISS_SELECTEDNOTFOCUS;\r
286                 }\r
287                 else\r
288                 {\r
289 #if 0\r
290                         if (pLogEntry->bCopiedSelf)\r
291                         {\r
292                                 // unfortunately, the pLVCD->nmcd.uItemState does not contain valid\r
293                                 // information at this drawing stage. But we can check the whether the\r
294                                 // previous stage changed the background color of the item\r
295                                 if (pLVCD->clrTextBk == GetSysColor(COLOR_MENU))\r
296                                 {\r
297                                         HBRUSH brush;\r
298                                         brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));\r
299                                         if (brush)\r
300                                         {\r
301                                                 ::FillRect(pLVCD->nmcd.hdc, &rect, brush);\r
302                                                 ::DeleteObject(brush);\r
303                                         }\r
304                                 }\r
305                         }\r
306 #endif\r
307                 }\r
308 \r
309                 if (m_Theme.IsBackgroundPartiallyTransparent(LVP_LISTDETAIL, state))\r
310                         m_Theme.DrawParentBackground(m_hWnd, hdc, &rect);\r
311 \r
312                         m_Theme.DrawBackground(hdc, LVP_LISTDETAIL, state, &rect, NULL);\r
313         }\r
314         else\r
315         {\r
316                 HBRUSH brush;\r
317                 if (rItem.state & LVIS_SELECTED)\r
318                 {\r
319                         if (::GetFocus() == m_hWnd)\r
320                                 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));\r
321                         else\r
322                                 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));\r
323                 }\r
324                 else\r
325                 {\r
326                         //if (pLogEntry->bCopiedSelf)\r
327                         //      brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));\r
328                         //else\r
329                                 brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));\r
330                 }\r
331                 if (brush == NULL)\r
332                         return;\r
333 \r
334                 ::FillRect(hdc, &rect, brush);\r
335                 ::DeleteObject(brush);\r
336                 \r
337         }\r
338 }\r
339 \r
340 void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index)\r
341 {\r
342         GitRev* data = (GitRev*)m_arShownList.GetAt(index);\r
343         CRect rt=rect;\r
344         LVITEM   rItem;\r
345         SecureZeroMemory(&rItem, sizeof(LVITEM));\r
346         rItem.mask  = LVIF_STATE;\r
347         rItem.iItem = index;\r
348         rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;\r
349         GetItem(&rItem);\r
350 \r
351         for(unsigned int i=0;i<m_HashMap[data->m_CommitHash].size();i++)\r
352         {\r
353                 CString str;\r
354                 str=m_HashMap[data->m_CommitHash][i];\r
355                 \r
356                 CString shortname;\r
357                 HBRUSH brush=0;\r
358                 shortname=_T("");\r
359                 if(GetShortName(str,shortname,_T("refs/heads/")))\r
360                 {\r
361                         if( shortname == m_CurrentBranch )\r
362                                 brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::CurrentBranch));\r
363                         else\r
364                                 brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::LocalBranch));\r
365 \r
366                 }else if(GetShortName(str,shortname,_T("refs/remotes/")))\r
367                 {\r
368                         brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::RemoteBranch));\r
369                 }\r
370                 else if(GetShortName(str,shortname,_T("refs/tags/")))\r
371                 {\r
372                         brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::Tag));\r
373                 }\r
374 \r
375                 if(!shortname.IsEmpty())\r
376                 {\r
377                         SIZE size;\r
378                         memset(&size,0,sizeof(SIZE));\r
379                         GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);\r
380                 \r
381                         rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);\r
382                         rt.right+=4;\r
383                         ::FillRect(hdc, &rt, brush);\r
384                         if (rItem.state & LVIS_SELECTED)\r
385                         {\r
386                                 COLORREF   clrOld   = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));   \r
387                                 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER);\r
388                                 ::SetTextColor(hdc,clrOld);   \r
389                         }else\r
390                         {\r
391                                 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER);\r
392                         }\r
393 \r
394                         \r
395                         ::MoveToEx(hdc,rt.left,rt.top,NULL);\r
396                         ::LineTo(hdc,rt.right,rt.top);\r
397                         ::LineTo(hdc,rt.right,rt.bottom);\r
398                         ::LineTo(hdc,rt.left,rt.bottom);\r
399                         ::LineTo(hdc,rt.left,rt.top);\r
400                                 \r
401                         rt.left=rt.right+3;\r
402                 }\r
403                 if(brush)\r
404                         ::DeleteObject(brush);\r
405         }               \r
406         rt.right=rect.right;\r
407 \r
408         if (rItem.state & LVIS_SELECTED)\r
409         {\r
410                 COLORREF   clrOld   = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));   \r
411                 ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT);\r
412                 ::SetTextColor(hdc,clrOld);   \r
413         }else\r
414         {\r
415                 ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT);\r
416         }\r
417         \r
418 }\r
419 \r
420 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,\r
421                                       const COLORREF& col,int top\r
422                                                                           )  \r
423 {\r
424         int h = laneHeight / 2;\r
425         int m = (x1 + x2) / 2;\r
426         int r = (x2 - x1) / 3;\r
427         int d =  2 * r;\r
428 \r
429         #define P_CENTER m , h+top\r
430         #define P_0      x2, h+top\r
431         #define P_90     m , 0+top\r
432         #define P_180    x1, h+top\r
433         #define P_270    m , 2 * h+top\r
434         #define R_CENTER m - r, h - r+top, m - r+d, h - r+top+d\r
435 \r
436         //static QPen myPen(Qt::black, 2); // fast path here\r
437         CPen pen;\r
438         pen.CreatePen(PS_SOLID,2,col);\r
439         //myPen.setColor(col);\r
440         HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);\r
441 \r
442         //p->setPen(myPen);\r
443 \r
444         // vertical line\r
445         switch (type) {\r
446         case Lanes::ACTIVE:\r
447         case Lanes::NOT_ACTIVE:\r
448         case Lanes::MERGE_FORK:\r
449         case Lanes::MERGE_FORK_R:\r
450         case Lanes::MERGE_FORK_L:\r
451         case Lanes::JOIN:\r
452         case Lanes::JOIN_R:\r
453         case Lanes::JOIN_L:\r
454                 DrawLine(hdc,P_90,P_270);\r
455                 //p->drawLine(P_90, P_270);\r
456                 break;\r
457         case Lanes::HEAD:\r
458         case Lanes::HEAD_R:\r
459         case Lanes::HEAD_L:\r
460         case Lanes::BRANCH:\r
461                 DrawLine(hdc,P_CENTER,P_270);\r
462                 //p->drawLine(P_CENTER, P_270);\r
463                 break;\r
464         case Lanes::TAIL:\r
465         case Lanes::TAIL_R:\r
466         case Lanes::TAIL_L:\r
467         case Lanes::INITIAL:\r
468         case Lanes::BOUNDARY:\r
469         case Lanes::BOUNDARY_C:\r
470         case Lanes::BOUNDARY_R:\r
471         case Lanes::BOUNDARY_L:\r
472                 DrawLine(hdc,P_90, P_CENTER);\r
473                 //p->drawLine(P_90, P_CENTER);\r
474                 break;\r
475         default:\r
476                 break;\r
477         }\r
478 \r
479         // horizontal line\r
480         switch (type) {\r
481         case Lanes::MERGE_FORK:\r
482         case Lanes::JOIN:\r
483         case Lanes::HEAD:\r
484         case Lanes::TAIL:\r
485         case Lanes::CROSS:\r
486         case Lanes::CROSS_EMPTY:\r
487         case Lanes::BOUNDARY_C:\r
488                 DrawLine(hdc,P_180,P_0);\r
489                 //p->drawLine(P_180, P_0);\r
490                 break;\r
491         case Lanes::MERGE_FORK_R:\r
492         case Lanes::JOIN_R:\r
493         case Lanes::HEAD_R:\r
494         case Lanes::TAIL_R:\r
495         case Lanes::BOUNDARY_R:\r
496                 DrawLine(hdc,P_180,P_CENTER);\r
497                 //p->drawLine(P_180, P_CENTER);\r
498                 break;\r
499         case Lanes::MERGE_FORK_L:\r
500         case Lanes::JOIN_L:\r
501         case Lanes::HEAD_L:\r
502         case Lanes::TAIL_L:\r
503         case Lanes::BOUNDARY_L:\r
504                 DrawLine(hdc,P_CENTER,P_0);\r
505                 //p->drawLine(P_CENTER, P_0);\r
506                 break;\r
507         default:\r
508                 break;\r
509         }\r
510 \r
511         CBrush brush;\r
512         brush.CreateSolidBrush(col);\r
513         HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);\r
514         // center symbol, e.g. rect or ellipse\r
515         switch (type) {\r
516         case Lanes::ACTIVE:\r
517         case Lanes::INITIAL:\r
518         case Lanes::BRANCH:\r
519 \r
520                 //p->setPen(Qt::NoPen);\r
521                 //p->setBrush(col);\r
522                 ::Ellipse(hdc, R_CENTER);\r
523                 //p->drawEllipse(R_CENTER);\r
524                 break;\r
525         case Lanes::MERGE_FORK:\r
526         case Lanes::MERGE_FORK_R:\r
527         case Lanes::MERGE_FORK_L:\r
528                 //p->setPen(Qt::NoPen);\r
529                 //p->setBrush(col);\r
530                 //p->drawRect(R_CENTER);\r
531                 Rectangle(hdc,R_CENTER);\r
532                 break;\r
533         case Lanes::UNAPPLIED:\r
534                 // Red minus sign\r
535                 //p->setPen(Qt::NoPen);\r
536                 //p->setBrush(Qt::red);\r
537                 //p->drawRect(m - r, h - 1, d, 2);\r
538                 ::Rectangle(hdc,m-r,h-1,d,2);\r
539                 break;\r
540         case Lanes::APPLIED:\r
541                 // Green plus sign\r
542                 //p->setPen(Qt::NoPen);\r
543                 //p->setBrush(DARK_GREEN);\r
544                 //p->drawRect(m - r, h - 1, d, 2);\r
545                 //p->drawRect(m - 1, h - r, 2, d);\r
546                 ::Rectangle(hdc,m-r,h-1,d,2);\r
547                 ::Rectangle(hdc,m-1,h-r,2,d);\r
548                 break;\r
549         case Lanes::BOUNDARY:\r
550                 //p->setBrush(back);\r
551                 //p->drawEllipse(R_CENTER);\r
552                 ::Ellipse(hdc, R_CENTER);\r
553                 break;\r
554         case Lanes::BOUNDARY_C:\r
555         case Lanes::BOUNDARY_R:\r
556         case Lanes::BOUNDARY_L:\r
557                 //p->setBrush(back);\r
558                 //p->drawRect(R_CENTER);\r
559                 ::Rectangle(hdc,R_CENTER);\r
560                 break;\r
561         default:\r
562                 break;\r
563         }\r
564 \r
565         ::SelectObject(hdc,oldpen);\r
566         ::SelectObject(hdc,oldbrush);\r
567         #undef P_CENTER\r
568         #undef P_0\r
569         #undef P_90\r
570         #undef P_180\r
571         #undef P_270\r
572         #undef R_CENTER\r
573 }\r
574 \r
575 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)\r
576 {\r
577         //todo unfinished\r
578 //      return;\r
579         GitRev* data = (GitRev*)m_arShownList.GetAt(index);\r
580         CRect rt=rect;\r
581         LVITEM   rItem;\r
582         SecureZeroMemory(&rItem, sizeof(LVITEM));\r
583         rItem.mask  = LVIF_STATE;\r
584         rItem.iItem = index;\r
585         rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;\r
586         GetItem(&rItem);\r
587 \r
588         \r
589 //      p->translate(QPoint(opt.rect.left(), opt.rect.top()));\r
590 \r
591 \r
592 \r
593         if (data->m_Lanes.size() == 0)\r
594                 m_logEntries.setLane(data->m_CommitHash);\r
595 \r
596         std::vector<int>& lanes=data->m_Lanes;\r
597         UINT laneNum = lanes.size();\r
598         UINT mergeLane = 0;\r
599         for (UINT i = 0; i < laneNum; i++)\r
600                 if (Lanes::isMerge(lanes[i])) {\r
601                         mergeLane = i;\r
602                         break;\r
603                 }\r
604 \r
605         int x1 = 0, x2 = 0;\r
606         int maxWidth = rect.Width();\r
607         int lw = 3 * rect.Height() / 4; //laneWidth() \r
608         for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {\r
609 \r
610                 x1 = x2;\r
611                 x2 += lw;\r
612 \r
613                 int ln = lanes[i];\r
614                 if (ln == Lanes::EMPTY)\r
615                         continue;\r
616 \r
617                 UINT col = (  Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)\r
618                             || ln ==Lanes:: CROSS_EMPTY) ? mergeLane : i;\r
619 \r
620                 if (ln == Lanes::CROSS) {\r
621                         paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);\r
622                         paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[mergeLane % Lanes::COLORS_NUM],rect.top);\r
623                 } else\r
624                         paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);\r
625         }\r
626 \r
627         TRACE(_T("index %d %d\r\n"),index,data->m_Lanes.size());\r
628 }\r
629 \r
630 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
631 {\r
632 \r
633         NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );\r
634         // Take the default processing unless we set this to something else below.\r
635         *pResult = CDRF_DODEFAULT;\r
636 \r
637         if (m_bNoDispUpdates)\r
638                 return;\r
639 \r
640 \r
641 \r
642         switch (pLVCD->nmcd.dwDrawStage)\r
643         {\r
644         case CDDS_PREPAINT:\r
645                 {\r
646                         *pResult = CDRF_NOTIFYITEMDRAW;\r
647                         return;\r
648                 }\r
649                 break;\r
650         case CDDS_ITEMPREPAINT:\r
651                 {\r
652                         // This is the prepaint stage for an item. Here's where we set the\r
653                         // item's text color. \r
654                         \r
655                         // Tell Windows to send draw notifications for each subitem.\r
656                         *pResult = CDRF_NOTIFYSUBITEMDRAW;\r
657 \r
658                         COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);\r
659 \r
660                         if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
661                         {\r
662                                 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);\r
663                                 if (data)\r
664                                 {\r
665 #if 0\r
666                                         if (data->bCopiedSelf)\r
667                                         {\r
668                                                 // only change the background color if the item is not 'hot' (on vista with m_Themes enabled)\r
669                                                 if (!m_Theme.IsAppm_Themed() || !m_bVista || ((pLVCD->nmcd.uItemState & CDIS_HOT)==0))\r
670                                                         pLVCD->clrTextBk = GetSysColor(COLOR_MENU);\r
671                                         }\r
672 \r
673                                         if (data->bCopies)\r
674                                                 crText = m_Colors.GetColor(CColors::Modified);\r
675 #endif\r
676 //                                      if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))\r
677 //                                              crText = GetSysColor(COLOR_GRAYTEXT);\r
678 //                                      if (data->Rev == m_wcRev)\r
679 //                                      {\r
680 //                                              SelectObject(pLVCD->nmcd.hdc, m_boldFont);\r
681                                                 // We changed the font, so we're returning CDRF_NEWFONT. This\r
682                                                 // tells the control to recalculate the extent of the text.\r
683 //                                              *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;\r
684 //                                      }\r
685                                 }\r
686                         }\r
687                         if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
688                         {\r
689                                 if (m_bStrictStopped)\r
690                                         crText = GetSysColor(COLOR_GRAYTEXT);\r
691                         }\r
692                         // Store the color back in the NMLVCUSTOMDRAW struct.\r
693                         pLVCD->clrText = crText;\r
694                         return;\r
695                 }\r
696                 break;\r
697         case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:\r
698                 {\r
699                         if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))\r
700                         {\r
701                                 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);\r
702                         }\r
703 \r
704                         if (pLVCD->iSubItem == LOGLIST_GRAPH)\r
705                         {\r
706                                 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
707                                 {\r
708                                         CRect rect;\r
709                                         GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);\r
710                                         \r
711                                         FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);\r
712                                         DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);\r
713 \r
714                                         *pResult = CDRF_SKIPDEFAULT;\r
715                                         return;\r
716                                 \r
717                                 }\r
718                         }\r
719 \r
720                         if (pLVCD->iSubItem == LOGLIST_MESSAGE)\r
721                         {\r
722                                 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
723                                 {\r
724                                         GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);\r
725                                         //if(!data->m_IsFull)\r
726                                         //{\r
727                                                 //if(data->SafeFetchFullInfo(&g_Git))\r
728                                                 //      this->Invalidate();\r
729                                                 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);\r
730                                         //}\r
731 \r
732                                         if(m_HashMap[data->m_CommitHash].size()!=0)\r
733                                         {\r
734                                                 CRect rect;\r
735 \r
736                                                 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);\r
737                                         \r
738                                                 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);\r
739                                                 DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);\r
740 \r
741                                                 *pResult = CDRF_SKIPDEFAULT;\r
742                                                 return;\r
743 \r
744                                         }\r
745                                 }\r
746                         }\r
747                         \r
748                         if (pLVCD->iSubItem == 1)\r
749                         {\r
750                                 if(this->m_IsIDReplaceAction)\r
751                                 {\r
752                                         *pResult = CDRF_DODEFAULT;\r
753                                         return;\r
754                                 }\r
755                                 *pResult = CDRF_DODEFAULT;\r
756 \r
757                                 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
758                                         return;\r
759 \r
760                                 int             nIcons = 0;\r
761                                 int             iconwidth = ::GetSystemMetrics(SM_CXSMICON);\r
762                                 int             iconheight = ::GetSystemMetrics(SM_CYSMICON);\r
763 \r
764                                 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec));\r
765                                 CRect rect;\r
766                                 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);\r
767                                 // Get the selected state of the\r
768                                 // item being drawn.                                                    \r
769 \r
770                                 // Fill the background\r
771                                 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);\r
772                                 \r
773                                 // Draw the icon(s) into the compatible DC\r
774                                 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_MODIFIED)\r
775                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
776                                 nIcons++;\r
777 \r
778                                 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_ADDED)\r
779                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
780                                 nIcons++;\r
781 \r
782                                 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_DELETED)\r
783                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
784                                 nIcons++;\r
785 \r
786                                 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_REPLACED)\r
787                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
788                                 nIcons++;\r
789                                 *pResult = CDRF_SKIPDEFAULT;\r
790                                 return;\r
791                         }\r
792                 }\r
793                 break;\r
794         }\r
795         *pResult = CDRF_DODEFAULT;\r
796 \r
797 }\r
798 \r
799 // CGitLogListBase message handlers\r
800 \r
801 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
802 {\r
803         NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);\r
804 \r
805         // Create a pointer to the item\r
806         LV_ITEM* pItem = &(pDispInfo)->item;\r
807 \r
808         // Do the list need text information?\r
809         if (!(pItem->mask & LVIF_TEXT))\r
810                 return;\r
811 \r
812         // By default, clear text buffer.\r
813         lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);\r
814 \r
815         bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();\r
816         \r
817         *pResult = 0;\r
818         if (m_bNoDispUpdates || bOutOfRange)\r
819                 return;\r
820 \r
821         // Which item number?\r
822         int itemid = pItem->iItem;\r
823         GitRev * pLogEntry = NULL;\r
824         if (itemid < m_arShownList.GetCount())\r
825                 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(pItem->iItem));\r
826 \r
827         CString temp;\r
828         temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);\r
829             \r
830         // Which column?\r
831         switch (pItem->iSubItem)\r
832         {\r
833         case this->LOGLIST_GRAPH:       //Graphic\r
834                 if (pLogEntry)\r
835                 {\r
836                 }\r
837                 break;\r
838         case this->LOGLIST_ACTION: //action -- no text in the column\r
839                 if(this->m_IsIDReplaceAction)\r
840                         lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);\r
841                 break;\r
842         case this->LOGLIST_MESSAGE: //Message\r
843                 if (pLogEntry)\r
844                         lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_Subject, pItem->cchTextMax);\r
845                 break;\r
846         case this->LOGLIST_AUTHOR: //Author\r
847                 if (pLogEntry)\r
848                         lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_AuthorName, pItem->cchTextMax);\r
849                 break;\r
850         case this->LOGLIST_DATE: //Date\r
851                 if (pLogEntry)\r
852                         lstrcpyn(pItem->pszText,\r
853                                 CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat ), \r
854                                 pItem->cchTextMax);\r
855                 break;\r
856                 \r
857         case 5:\r
858 \r
859                 break;\r
860         default:\r
861                 ASSERT(false);\r
862         }\r
863 }\r
864 \r
865 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)\r
866 {\r
867 \r
868         int selIndex = GetSelectionMark();\r
869         if (selIndex < 0)\r
870                 return; // nothing selected, nothing to do with a context menu\r
871 \r
872         // if the user selected the info text telling about not all revisions shown due to\r
873         // the "stop on copy/rename" option, we also don't show the context menu\r
874         if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))\r
875                 return;\r
876 \r
877         // if the context menu is invoked through the keyboard, we have to use\r
878         // a calculated position on where to anchor the menu on\r
879         if ((point.x == -1) && (point.y == -1))\r
880         {\r
881                 CRect rect;\r
882                 GetItemRect(selIndex, &rect, LVIR_LABEL);\r
883                 ClientToScreen(&rect);\r
884                 point = rect.CenterPoint();\r
885         }\r
886         m_nSearchIndex = selIndex;\r
887         m_bCancelled = FALSE;\r
888 \r
889         // calculate some information the context menu commands can use\r
890 //      CString pathURL = GetURLFromPath(m_path);\r
891 \r
892         POSITION pos = GetFirstSelectedItemPosition();\r
893         int indexNext = GetNextSelectedItem(pos);\r
894         if (indexNext < 0)\r
895                 return;\r
896 \r
897         GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(indexNext));\r
898 #if 0\r
899         GitRev revSelected = pSelLogEntry->Rev;\r
900         GitRev revPrevious = git_revnum_t(revSelected)-1;\r
901         if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))\r
902         {\r
903                 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)\r
904                 {\r
905                         LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->GetAt(i);\r
906                         if (changedpath->lCopyFromRev)\r
907                                 revPrevious = changedpath->lCopyFromRev;\r
908                 }\r
909         }\r
910         GitRev revSelected2;\r
911         if (pos)\r
912         {\r
913                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));\r
914                 revSelected2 = pLogEntry->Rev;\r
915         }\r
916         bool bAllFromTheSameAuthor = true;\r
917         CString firstAuthor;\r
918         CLogDataVector selEntries;\r
919         GitRev revLowest, revHighest;\r
920         GitRevRangeArray revisionRanges;\r
921         {\r
922                 POSITION pos = GetFirstSelectedItemPosition();\r
923                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));\r
924                 revisionRanges.AddRevision(pLogEntry->Rev);\r
925                 selEntries.push_back(pLogEntry);\r
926                 firstAuthor = pLogEntry->sAuthor;\r
927                 revLowest = pLogEntry->Rev;\r
928                 revHighest = pLogEntry->Rev;\r
929                 while (pos)\r
930                 {\r
931                         pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));\r
932                         revisionRanges.AddRevision(pLogEntry->Rev);\r
933                         selEntries.push_back(pLogEntry);\r
934                         if (firstAuthor.Compare(pLogEntry->sAuthor))\r
935                                 bAllFromTheSameAuthor = false;\r
936                         revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);\r
937                         revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);\r
938                 }\r
939         }\r
940 \r
941 #endif\r
942 \r
943         int FirstSelect=-1, LastSelect=-1;\r
944         pos = GetFirstSelectedItemPosition();\r
945         FirstSelect = GetNextSelectedItem(pos);\r
946         while(pos)\r
947         {\r
948                 LastSelect = GetNextSelectedItem(pos);\r
949         }\r
950         //entry is selected, now show the popup menu\r
951         CIconMenu popup;\r
952         if (popup.CreatePopupMenu())\r
953         {\r
954                 if (GetSelectedCount() == 1)\r
955                 {\r
956 #if 0\r
957                         if (!m_path.IsDirectory())\r
958                         {\r
959                                 if (m_hasWC)\r
960                                 {\r
961                                         popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);\r
962                                         popup.AppendMenuIcon(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);\r
963                                 }\r
964                                 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);\r
965                                 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);\r
966                                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
967                                 popup.AppendMenuIcon(ID_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);\r
968                                 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);\r
969                                 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);\r
970                                 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);\r
971                                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
972                         }\r
973                         else\r
974 #endif \r
975                         {\r
976                                 if (m_hasWC)\r
977                                 {\r
978                                         popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);\r
979                                         // TODO:\r
980                                         // TortoiseMerge could be improved to take a /blame switch\r
981                                         // and then not 'cat' the files from a unified diff but\r
982                                         // blame then.\r
983                                         // But until that's implemented, the context menu entry for\r
984                                         // this feature is commented out.\r
985                                         //popup.AppendMenu(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);\r
986                                 }\r
987                                 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);\r
988                                 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);\r
989                                 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);\r
990                                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
991                         }\r
992 \r
993 //                      if (!m_ProjectProperties.sWebViewerRev.IsEmpty())\r
994 //                      {\r
995 //                              popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);\r
996 //                      }\r
997 //                      if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())\r
998 //                      {\r
999 //                              popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);\r
1000 //                      }\r
1001 //                      if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||\r
1002 //                              (!m_ProjectProperties.sWebViewerRev.IsEmpty()))\r
1003 //                      {\r
1004 //                              popup.AppendMenu(MF_SEPARATOR, NULL);\r
1005 //                      }\r
1006 \r
1007                         //if (m_hasWC)\r
1008                         //      popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);\r
1009                         //if (m_hasWC)\r
1010                         //      popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);\r
1011                         //if (m_hasWC)\r
1012                         //      popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREV, IDI_MERGE);\r
1013                         \r
1014                         CString str;\r
1015                         str.Format(_T("Reset %s to this"),g_Git.GetCurrentBranch());\r
1016                         popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);\r
1017                         popup.AppendMenuIcon(ID_SWITCHTOREV, _T("Switch/Checkout to this") , IDI_SWITCH);\r
1018                         popup.AppendMenuIcon(ID_CREATE_BRANCH, _T("Create Branch at this version") , IDI_COPY);\r
1019                         popup.AppendMenuIcon(ID_CREATE_TAG, _T("Create Tag at this version"), IDI_COPY);\r
1020                         popup.AppendMenuIcon(ID_CHERRY_PICK, _T("Cherry Pick this version"), IDI_EXPORT);\r
1021                         popup.AppendMenuIcon(ID_EXPORT, _T("Export this version"), IDI_EXPORT);\r
1022                         \r
1023 \r
1024                         popup.AppendMenu(MF_SEPARATOR, NULL);\r
1025                 }\r
1026                 else if (GetSelectedCount() >= 2)\r
1027                 {\r
1028                         bool bAddSeparator = false;\r
1029                         if (IsSelectionContinuous() || (GetSelectedCount() == 2))\r
1030                         {\r
1031                                 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);\r
1032                         }\r
1033                         if (GetSelectedCount() == 2)\r
1034                         {\r
1035                                 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);\r
1036                                 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);\r
1037                                 bAddSeparator = true;\r
1038                         }\r
1039                         if (m_hasWC)\r
1040                         {\r
1041                                 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);\r
1042 //                              if (m_hasWC)\r
1043 //                                      popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);\r
1044                                 bAddSeparator = true;\r
1045                         }\r
1046                         if (bAddSeparator)\r
1047                                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
1048                 }\r
1049 #if 0\r
1050 //              if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))\r
1051 //              {\r
1052 //                      popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);\r
1053 //              }\r
1054 //              if (GetSelectedCount() == 1)\r
1055 //              {\r
1056 //                      popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);\r
1057 //                      popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"\r
1058 //                      popup.AppendMenu(MF_SEPARATOR, NULL);\r
1059 //              }\r
1060 #endif\r
1061 \r
1062                 \r
1063                 if (GetSelectedCount() == 1)\r
1064                 {\r
1065                         popup.AppendMenuIcon(ID_COPYHASH, _T("Copy Commit Hash"));\r
1066                 }\r
1067                 if (GetSelectedCount() != 0)\r
1068                 {\r
1069                         popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD);\r
1070                 }\r
1071                 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND);\r
1072 \r
1073                 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);\r
1074 //              DialogEnableWindow(IDOK, FALSE);\r
1075 //              SetPromptApp(&theApp);\r
1076         \r
1077                 this->ContextMenuAction(cmd, FirstSelect, LastSelect);\r
1078                 \r
1079 //              EnableOKButton();\r
1080         } // if (popup.CreatePopupMenu())\r
1081 \r
1082 }\r
1083 \r
1084 bool CGitLogListBase::IsSelectionContinuous()\r
1085 {\r
1086         if ( GetSelectedCount()==1 )\r
1087         {\r
1088                 // if only one revision is selected, the selection is of course\r
1089                 // continuous\r
1090                 return true;\r
1091         }\r
1092 \r
1093         POSITION pos = GetFirstSelectedItemPosition();\r
1094         bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());\r
1095         if (bContinuous)\r
1096         {\r
1097                 int itemindex = GetNextSelectedItem(pos);\r
1098                 while (pos)\r
1099                 {\r
1100                         int nextindex = GetNextSelectedItem(pos);\r
1101                         if (nextindex - itemindex > 1)\r
1102                         {\r
1103                                 bContinuous = false;\r
1104                                 break;\r
1105                         }\r
1106                         itemindex = nextindex;\r
1107                 }\r
1108         }\r
1109         return bContinuous;\r
1110 }\r
1111 \r
1112 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly)\r
1113 {\r
1114 \r
1115         CString sClipdata;\r
1116         POSITION pos = GetFirstSelectedItemPosition();\r
1117         if (pos != NULL)\r
1118         {\r
1119                 CString sRev;\r
1120                 sRev.LoadString(IDS_LOG_REVISION);\r
1121                 CString sAuthor;\r
1122                 sAuthor.LoadString(IDS_LOG_AUTHOR);\r
1123                 CString sDate;\r
1124                 sDate.LoadString(IDS_LOG_DATE);\r
1125                 CString sMessage;\r
1126                 sMessage.LoadString(IDS_LOG_MESSAGE);\r
1127                 while (pos)\r
1128                 {\r
1129                         CString sLogCopyText;\r
1130                         CString sPaths;\r
1131                         GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(GetNextSelectedItem(pos)));\r
1132 \r
1133                         if(!HashOnly)\r
1134                         {\r
1135                                 //pLogEntry->m_Files\r
1136                                 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;\r
1137                         \r
1138                                 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->m_Files.GetCount(); ++cpPathIndex)\r
1139                                 {\r
1140                                         sPaths += ((CTGitPath&)pLogEntry->m_Files[cpPathIndex]).GetActionName() + _T(" : ") + pLogEntry->m_Files[cpPathIndex].GetGitPathString();\r
1141                                         sPaths += _T("\r\n");\r
1142                                 }\r
1143                                 sPaths.Trim();\r
1144                                 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
1145                                         (LPCTSTR)sRev, pLogEntry->m_CommitHash,\r
1146                                         (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->m_AuthorName,\r
1147                                         (LPCTSTR)sDate, (LPCTSTR)CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat ),\r
1148                                         (LPCTSTR)sMessage, pLogEntry->m_Subject+_T("\r\n")+pLogEntry->m_Body,\r
1149                                         (LPCTSTR)sPaths);\r
1150                                 sClipdata +=  sLogCopyText;\r
1151                         }else\r
1152                         {\r
1153                                 sClipdata += pLogEntry->m_CommitHash;\r
1154                                 break;\r
1155                         }\r
1156 \r
1157                 }\r
1158                 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());\r
1159         }\r
1160 \r
1161 }\r
1162 \r
1163 void CGitLogListBase::DiffSelectedRevWithPrevious()\r
1164 {\r
1165 #if 0\r
1166         if (m_bThreadRunning)\r
1167                 return;\r
1168         UpdateLogInfoLabel();\r
1169         int selIndex = m_LogList.GetSelectionMark();\r
1170         if (selIndex < 0)\r
1171                 return;\r
1172         int selCount = m_LogList.GetSelectedCount();\r
1173         if (selCount != 1)\r
1174                 return;\r
1175 \r
1176         // Find selected entry in the log list\r
1177         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1178         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1179         long rev1 = pLogEntry->Rev;\r
1180         long rev2 = rev1-1;\r
1181         CTGitPath path = m_path;\r
1182 \r
1183         // See how many files under the relative root were changed in selected revision\r
1184         int nChanged = 0;\r
1185         LogChangedPath * changed = NULL;\r
1186         for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)\r
1187         {\r
1188                 LogChangedPath * cpath = pLogEntry->pArChangedPaths->GetAt(c);\r
1189                 if (cpath  &&  cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)\r
1190                 {\r
1191                         ++nChanged;\r
1192                         changed = cpath;\r
1193                 }\r
1194         }\r
1195 \r
1196         if (m_path.IsDirectory() && nChanged == 1) \r
1197         {\r
1198                 // We're looking at the log for a directory and only one file under dir was changed in the revision\r
1199                 // Do diff on that file instead of whole directory\r
1200                 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));\r
1201         } \r
1202 \r
1203         m_bCancelled = FALSE;\r
1204         DialogEnableWindow(IDOK, FALSE);\r
1205         SetPromptApp(&theApp);\r
1206         theApp.DoWaitCursor(1);\r
1207 \r
1208         if (PromptShown())\r
1209         {\r
1210                 GitDiff diff(this, m_hWnd, true);\r
1211                 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1212                 diff.SetHEADPeg(m_LogRevision);\r
1213                 diff.ShowCompare(path, rev2, path, rev1);\r
1214         }\r
1215         else\r
1216         {\r
1217                 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1218         }\r
1219 \r
1220         theApp.DoWaitCursor(-1);\r
1221         EnableOKButton();\r
1222 #endif\r
1223 }\r
1224 \r
1225 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
1226 {\r
1227         LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);\r
1228         *pResult = -1;\r
1229         \r
1230         if (pFindInfo->lvfi.flags & LVFI_PARAM)\r
1231                 return; \r
1232         if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))\r
1233                 return;\r
1234         if (pFindInfo->lvfi.psz == 0)\r
1235                 return;\r
1236 #if 0\r
1237         CString sCmp = pFindInfo->lvfi.psz;\r
1238         CString sRev;   \r
1239         for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)\r
1240         {\r
1241                 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(i));\r
1242                 sRev.Format(_T("%ld"), pLogEntry->Rev);\r
1243                 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)\r
1244                 {\r
1245                         if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)\r
1246                         {\r
1247                                 *pResult = i;\r
1248                                 return;\r
1249                         }\r
1250                 }\r
1251                 else\r
1252                 {\r
1253                         if (sCmp.Compare(sRev)==0)\r
1254                         {\r
1255                                 *pResult = i;\r
1256                                 return;\r
1257                         }\r
1258                 }\r
1259         }\r
1260         if (pFindInfo->lvfi.flags & LVFI_WRAP)\r
1261         {\r
1262                 for (int i=0; i<pFindInfo->iStart; ++i)\r
1263                 {\r
1264                         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));\r
1265                         sRev.Format(_T("%ld"), pLogEntry->Rev);\r
1266                         if (pFindInfo->lvfi.flags & LVFI_PARTIAL)\r
1267                         {\r
1268                                 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)\r
1269                                 {\r
1270                                         *pResult = i;\r
1271                                         return;\r
1272                                 }\r
1273                         }\r
1274                         else\r
1275                         {\r
1276                                 if (sCmp.Compare(sRev)==0)\r
1277                                 {\r
1278                                         *pResult = i;\r
1279                                         return;\r
1280                                 }\r
1281                         }\r
1282                 }\r
1283         }\r
1284 #endif\r
1285         *pResult = -1;\r
1286 }\r
1287 \r
1288 int CGitLogListBase::FillGitLog(CTGitPath *path,int info)\r
1289 {\r
1290         ClearText();\r
1291 \r
1292         this->m_logEntries.ClearAll();\r
1293         this->m_logEntries.ParserFromLog(path,-1,info);\r
1294 \r
1295         //this->m_logEntries.ParserFromLog();\r
1296         SetItemCountEx(this->m_logEntries.size());\r
1297 \r
1298         this->m_arShownList.RemoveAll();\r
1299 \r
1300         for(unsigned int i=0;i<m_logEntries.size();i++)\r
1301         {\r
1302                 m_logEntries[i].m_IsFull=TRUE;\r
1303                 this->m_arShownList.Add(&m_logEntries[i]);\r
1304         }\r
1305 \r
1306     if(path)\r
1307         m_Path=*path;\r
1308         return 0;\r
1309 \r
1310 }\r
1311 \r
1312 int CGitLogListBase::FillGitShortLog()\r
1313 {\r
1314         ClearText();\r
1315 \r
1316         this->m_logEntries.ClearAll();\r
1317 \r
1318         m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);\r
1319 \r
1320     CTGitPath *path;\r
1321     if(this->m_Path.IsEmpty())\r
1322         path=NULL;\r
1323     else\r
1324         path=&this->m_Path;\r
1325 \r
1326         CString hash;\r
1327         int mask;\r
1328         mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;\r
1329 //      if(this->m_bAllBranch)\r
1330         mask |= m_ShowMask;\r
1331 \r
1332         this->m_logEntries.ParserShortLog(path,hash,-1,mask);\r
1333         \r
1334 \r
1335         //this->m_logEntries.ParserFromLog();\r
1336         if(IsInWorkingThread())\r
1337                 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);\r
1338         else\r
1339                 SetItemCountEx(this->m_logEntries.size());\r
1340 \r
1341         this->m_arShownList.RemoveAll();\r
1342 \r
1343         for(unsigned int i=0;i<m_logEntries.size();i++)\r
1344                 this->m_arShownList.Add(&m_logEntries[i]);\r
1345 \r
1346         return 0;\r
1347 }\r
1348 \r
1349 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)\r
1350 {\r
1351         // Skip Ctrl-C when copying text out of the log message or search filter\r
1352         BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );\r
1353         if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')\r
1354         {\r
1355                 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))\r
1356                 {\r
1357                         if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))\r
1358                         {\r
1359                                 DiffSelectedRevWithPrevious();\r
1360                                 return TRUE;\r
1361                         }\r
1362                 }\r
1363 #if 0\r
1364                 if (GetFocus()==GetDlgItem(IDC_LOGMSG))\r
1365                 {\r
1366                         DiffSelectedFile();\r
1367                         return TRUE;\r
1368                 }\r
1369 #endif\r
1370         }\r
1371 \r
1372 #if 0\r
1373         if (m_hAccel && !bSkipAccelerator)\r
1374         {\r
1375                 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);\r
1376                 if (ret)\r
1377                         return TRUE;\r
1378         }\r
1379         \r
1380 #endif\r
1381         //m_tooltips.RelayEvent(pMsg);\r
1382         return __super::PreTranslateMessage(pMsg);\r
1383 }\r
1384 \r
1385 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)\r
1386 {\r
1387         // a double click on an entry in the revision list has happened\r
1388         *pResult = 0;\r
1389 \r
1390   if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))\r
1391           DiffSelectedRevWithPrevious();\r
1392 }\r
1393 \r
1394 int CGitLogListBase::FetchLogAsync(void * data)\r
1395 {\r
1396         m_ProcData=data;\r
1397         m_bExitThread=FALSE;\r
1398         InterlockedExchange(&m_bThreadRunning, TRUE);\r
1399         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
1400         m_LoadingThread = AfxBeginThread(LogThreadEntry, this);\r
1401         if (m_LoadingThread ==NULL)\r
1402         {\r
1403                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
1404                 InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
1405                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
1406                 return -1;\r
1407         }\r
1408         return 0;\r
1409 }\r
1410 \r
1411 //this is the thread function which calls the subversion function\r
1412 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)\r
1413 {\r
1414         return ((CGitLogListBase*)pVoid)->LogThread();\r
1415 }\r
1416 \r
1417 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)\r
1418 {\r
1419         //CTime time;\r
1420         oldest=CTime::GetCurrentTime();\r
1421         latest=CTime(1971,1,2,0,0,0);\r
1422         for(unsigned int i=0;i<m_logEntries.size();i++)\r
1423         {\r
1424                 if(m_logEntries[i].m_AuthorDate.GetTime() < oldest.GetTime())\r
1425                         oldest = m_logEntries[i].m_AuthorDate.GetTime();\r
1426 \r
1427                 if(m_logEntries[i].m_AuthorDate.GetTime() > latest.GetTime())\r
1428                         latest = m_logEntries[i].m_AuthorDate.GetTime();\r
1429 \r
1430         }\r
1431 }\r
1432 \r
1433 UINT CGitLogListBase::LogThread()\r
1434 {\r
1435 \r
1436 //      if(m_ProcCallBack)\r
1437 //              m_ProcCallBack(m_ProcData,GITLOG_START);\r
1438         ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);\r
1439 \r
1440         InterlockedExchange(&m_bThreadRunning, TRUE);\r
1441         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
1442 \r
1443     //does the user force the cache to refresh (shift or control key down)?\r
1444     bool refresh =    (GetKeyState (VK_CONTROL) < 0) \r
1445                    || (GetKeyState (VK_SHIFT) < 0);\r
1446 \r
1447         //disable the "Get All" button while we're receiving\r
1448         //log messages.\r
1449 \r
1450         FillGitShortLog();\r
1451         \r
1452         if(this->m_bExitThread)\r
1453                 return 0;\r
1454 #if 0\r
1455         RedrawItems(0, m_arShownList.GetCount());\r
1456 //      SetRedraw(false);\r
1457 //      ResizeAllListCtrlCols();\r
1458 //      SetRedraw(true);\r
1459 \r
1460         if ( m_pStoreSelection )\r
1461         {\r
1462                 // Deleting the instance will restore the\r
1463                 // selection of the CLogDlg.\r
1464                 delete m_pStoreSelection;\r
1465                 m_pStoreSelection = NULL;\r
1466         }\r
1467         else\r
1468         {\r
1469                 // If no selection has been set then this must be the first time\r
1470                 // the revisions are shown. Let's preselect the topmost revision.\r
1471                 if ( GetItemCount()>0 )\r
1472                 {\r
1473                         SetSelectionMark(0);\r
1474                         SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);\r
1475                 }\r
1476         }\r
1477 #endif\r
1478         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
1479 \r
1480         int index=0;\r
1481         unsigned int updated=0;\r
1482         int percent=0;\r
1483         CRect rect;\r
1484         while(1)\r
1485         {\r
1486                 for(unsigned int i=0;i<m_logEntries.size();i++)\r
1487                 {\r
1488                         if(m_LogCache.GetCacheData(m_logEntries[i]))\r
1489                         {\r
1490                                 if(!m_logEntries.FetchFullInfo(i))\r
1491                                 {\r
1492                                         updated++;\r
1493                                 }\r
1494                                 m_LogCache.AddCacheEntry(m_logEntries[i]);\r
1495 \r
1496                         }else\r
1497                         {\r
1498                                 updated++;\r
1499                                 InterlockedExchange(&m_logEntries[i].m_IsUpdateing,FALSE);\r
1500                                 InterlockedExchange(&m_logEntries[i].m_IsFull,TRUE);\r
1501                         }\r
1502                         \r
1503                         ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);\r
1504 \r
1505                         if(m_bExitThread)\r
1506                                 return 0;\r
1507 \r
1508                         percent=updated*98/m_logEntries.size() + GITLOG_START+1;\r
1509                         if(percent == GITLOG_END)\r
1510                                 percent = GITLOG_END -1;\r
1511                         \r
1512                         ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);\r
1513 \r
1514                         \r
1515                 }\r
1516                 if(updated==m_logEntries.size())\r
1517                         break;\r
1518         }\r
1519 \r
1520         //RefreshCursor();\r
1521         // make sure the filter is applied (if any) now, after we refreshed/fetched\r
1522         // the log messages\r
1523 \r
1524         ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);\r
1525 \r
1526         InterlockedExchange(&m_bThreadRunning, FALSE);\r
1527 \r
1528         return 0;\r
1529 }\r
1530 \r
1531 void CGitLogListBase::Refresh()\r
1532 {\r
1533         if(!m_bThreadRunning)\r
1534         {\r
1535                 this->SetItemCountEx(0);\r
1536                 m_logEntries.clear();\r
1537                 InterlockedExchange(&m_bThreadRunning, TRUE);\r
1538                 InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
1539                 if (AfxBeginThread(LogThreadEntry, this)==NULL)\r
1540                 {\r
1541                         InterlockedExchange(&m_bThreadRunning, FALSE);\r
1542                         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
1543                         CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
1544                 }\r
1545                 m_sFilterText.Empty();\r
1546                 m_From=CTime(1970,1,2,0,0,0);\r
1547                 m_To=CTime::GetCurrentTime();\r
1548         }\r
1549 }\r
1550 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)\r
1551 {\r
1552         try\r
1553         {\r
1554                 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;\r
1555                 if (!bMatchCase)\r
1556                         type |= tr1::regex_constants::icase;\r
1557                 pat = tr1::wregex(regexp_str, type);\r
1558                 return true;\r
1559         }\r
1560         catch (exception) {}\r
1561         return false;\r
1562 }\r
1563 \r
1564 void CGitLogListBase::RecalculateShownList(CPtrArray * pShownlist)\r
1565 {\r
1566 \r
1567         pShownlist->RemoveAll();\r
1568         tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);\r
1569         bool bRegex = false;\r
1570         if (m_bFilterWithRegex)\r
1571                 bRegex = ValidateRegexp(m_sFilterText, pat, false);\r
1572 \r
1573         tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;\r
1574         CString sRev;\r
1575         for (DWORD i=0; i<m_logEntries.size(); ++i)\r
1576         {\r
1577                 if ((bRegex)&&(m_bFilterWithRegex))\r
1578                 {\r
1579 #if 0\r
1580                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))\r
1581                         {\r
1582                                 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);\r
1583                                 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))\r
1584                                 {\r
1585                                         pShownlist->Add(m_logEntries[i]);\r
1586                                         continue;\r
1587                                 }\r
1588                         }\r
1589 #endif\r
1590                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))\r
1591                         {\r
1592                                 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries[i].m_Subject);\r
1593                                 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_Subject), pat, flags)&&IsEntryInDateRange(i))\r
1594                                 {\r
1595                                         pShownlist->Add(&m_logEntries[i]);\r
1596                                         continue;\r
1597                                 }\r
1598 \r
1599                                 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries[i].m_Body);\r
1600                                 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_Body), pat, flags)&&IsEntryInDateRange(i))\r
1601                                 {\r
1602                                         pShownlist->Add(&m_logEntries[i]);\r
1603                                         continue;\r
1604                                 }\r
1605                         }\r
1606 #if 0\r
1607                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))\r
1608                         {\r
1609                                 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;\r
1610 \r
1611                                 bool bGoing = true;\r
1612                                 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)\r
1613                                 {\r
1614                                         LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
1615                                         if (regex_search(wstring((LPCTSTR)cpath->sCopyFromPath), pat, flags)&&IsEntryInDateRange(i))\r
1616                                         {\r
1617                                                 pShownlist->Add(m_logEntries[i]);\r
1618                                                 bGoing = false;\r
1619                                                 continue;\r
1620                                         }\r
1621                                         if (regex_search(wstring((LPCTSTR)cpath->sPath), pat, flags)&&IsEntryInDateRange(i))\r
1622                                         {\r
1623                                                 pShownlist->Add(m_logEntries[i]);\r
1624                                                 bGoing = false;\r
1625                                                 continue;\r
1626                                         }\r
1627                                         if (regex_search(wstring((LPCTSTR)cpath->GetAction()), pat, flags)&&IsEntryInDateRange(i))\r
1628                                         {\r
1629                                                 pShownlist->Add(m_logEntries[i]);\r
1630                                                 bGoing = false;\r
1631                                                 continue;\r
1632                                         }\r
1633                                 }\r
1634                                 if (!bGoing)\r
1635                                         continue;\r
1636                         }\r
1637 #endif\r
1638                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))\r
1639                         {\r
1640                                 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_AuthorName), pat, flags)&&IsEntryInDateRange(i))\r
1641                                 {\r
1642                                         pShownlist->Add(&m_logEntries[i]);\r
1643                                         continue;\r
1644                                 }\r
1645                         }\r
1646                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))\r
1647                         {\r
1648                                 sRev.Format(_T("%ld"), m_logEntries[i].m_CommitHash);\r
1649                                 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))\r
1650                                 {\r
1651                                         pShownlist->Add(&m_logEntries[i]);\r
1652                                         continue;\r
1653                                 }\r
1654                         }\r
1655                 } // if (bRegex)\r
1656                 else\r
1657                 {\r
1658                         CString find = m_sFilterText;\r
1659                         find.MakeLower();\r
1660 #if 0\r
1661                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))\r
1662                         {\r
1663                                 CString sBugIDs = m_logEntries[i]->sBugIDs;\r
1664 \r
1665                                 sBugIDs = sBugIDs.MakeLower();\r
1666                                 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))\r
1667                                 {\r
1668                                         pShownlist->Add(m_logEntries[i]);\r
1669                                         continue;\r
1670                                 }\r
1671                         }\r
1672 #endif\r
1673                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))\r
1674                         {\r
1675                                 CString msg = m_logEntries[i].m_Subject;\r
1676 \r
1677                                 msg = msg.MakeLower();\r
1678                                 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))\r
1679                                 {\r
1680                                         pShownlist->Add(&m_logEntries[i]);\r
1681                                         continue;\r
1682                                 }\r
1683                                 msg = m_logEntries[i].m_Body;\r
1684 \r
1685                                 msg = msg.MakeLower();\r
1686                                 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))\r
1687                                 {\r
1688                                         pShownlist->Add(&m_logEntries[i]);\r
1689                                         continue;\r
1690                                 }\r
1691                         }\r
1692 #if 0\r
1693                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))\r
1694                         {\r
1695                                 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;\r
1696 \r
1697                                 bool bGoing = true;\r
1698                                 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)\r
1699                                 {\r
1700                                         LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
1701                                         CString path = cpath->sCopyFromPath;\r
1702                                         path.MakeLower();\r
1703                                         if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))\r
1704                                         {\r
1705                                                 pShownlist->Add(m_logEntries[i]);\r
1706                                                 bGoing = false;\r
1707                                                 continue;\r
1708                                         }\r
1709                                         path = cpath->sPath;\r
1710                                         path.MakeLower();\r
1711                                         if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))\r
1712                                         {\r
1713                                                 pShownlist->Add(m_logEntries[i]);\r
1714                                                 bGoing = false;\r
1715                                                 continue;\r
1716                                         }\r
1717                                         path = cpath->GetAction();\r
1718                                         path.MakeLower();\r
1719                                         if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))\r
1720                                         {\r
1721                                                 pShownlist->Add(m_logEntries[i]);\r
1722                                                 bGoing = false;\r
1723                                                 continue;\r
1724                                         }\r
1725                                 }\r
1726                         }\r
1727 #endif\r
1728                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))\r
1729                         {\r
1730                                 CString msg = m_logEntries[i].m_AuthorName;\r
1731                                 msg = msg.MakeLower();\r
1732                                 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))\r
1733                                 {\r
1734                                         pShownlist->Add(&m_logEntries[i]);\r
1735                                         continue;\r
1736                                 }\r
1737                         }\r
1738                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))\r
1739                         {\r
1740                                 sRev.Format(_T("%ld"), m_logEntries[i].m_CommitHash);\r
1741                                 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))\r
1742                                 {\r
1743                                         pShownlist->Add(&m_logEntries[i]);\r
1744                                         continue;\r
1745                                 }\r
1746                         }\r
1747                 } // else (from if (bRegex))    \r
1748         } // for (DWORD i=0; i<m_logEntries.size(); ++i) \r
1749 \r
1750 }\r
1751 \r
1752 BOOL CGitLogListBase::IsEntryInDateRange(int i)\r
1753 {\r
1754         __time64_t time = m_logEntries[i].m_AuthorDate.GetTime();\r
1755         if ((time >= m_From.GetTime())&&(time <= m_To.GetTime()))\r
1756                 return TRUE;\r
1757 \r
1758         return FALSE;\r
1759 \r
1760 //      return TRUE;\r
1761 }\r
1762 void CGitLogListBase::StartFilter()\r
1763 {\r
1764         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
1765         RecalculateShownList(&m_arShownList);\r
1766         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
1767 \r
1768 \r
1769         DeleteAllItems();\r
1770         SetItemCountEx(ShownCountWithStopped());\r
1771         RedrawItems(0, ShownCountWithStopped());\r
1772         SetRedraw(false);\r
1773         //ResizeAllListCtrlCols();\r
1774         SetRedraw(true);\r
1775         Invalidate();\r
1776 \r
1777 }\r
1778 void CGitLogListBase::RemoveFilter()\r
1779 {\r
1780 \r
1781         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
1782 \r
1783         m_arShownList.RemoveAll();\r
1784 \r
1785         // reset the time filter too\r
1786 #if 0\r
1787         m_timFrom = (__time64_t(m_tFrom));\r
1788         m_timTo = (__time64_t(m_tTo));\r
1789         m_DateFrom.SetTime(&m_timFrom);\r
1790         m_DateTo.SetTime(&m_timTo);\r
1791         m_DateFrom.SetRange(&m_timFrom, &m_timTo);\r
1792         m_DateTo.SetRange(&m_timFrom, &m_timTo);\r
1793 #endif\r
1794 \r
1795         for (DWORD i=0; i<m_logEntries.size(); ++i)\r
1796         {\r
1797                 m_arShownList.Add(&m_logEntries[i]);\r
1798         }\r
1799 //      InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
1800         DeleteAllItems();\r
1801         SetItemCountEx(ShownCountWithStopped());\r
1802         RedrawItems(0, ShownCountWithStopped());\r
1803 //      SetRedraw(false);\r
1804 //      ResizeAllListCtrlCols();\r
1805 //      SetRedraw(true);\r
1806 \r
1807         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
1808 }\r
1809 \r
1810 void CGitLogListBase::Clear()\r
1811 {\r
1812         m_arShownList.RemoveAll();\r
1813         m_logEntries.clear();\r
1814         m_logEntries.m_HashMap.clear();\r
1815         DeleteAllItems();\r
1816         m_logEntries.m_Lns.clear();\r
1817 \r
1818         m_logEntries.m_FirstFreeLane=0;\r
1819         m_logEntries.m_Lns.clear();\r
1820 \r
1821 }\r
1822 \r
1823 void CGitLogListBase::OnDestroy()\r
1824 {\r
1825         // save the column widths to the registry\r
1826         SaveColumnWidths();\r
1827 \r
1828         if(this->m_bThreadRunning)\r
1829         {\r
1830                 this->m_bExitThread=true;\r
1831                 DWORD ret =::WaitForSingleObject(m_LoadingThread->m_hThread,20000);\r
1832                 if(ret == WAIT_TIMEOUT)\r
1833                         TerminateThread();\r
1834         }\r
1835         while(m_LogCache.SaveCache())\r
1836         {\r
1837                 if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk,click yes for retry, click no for give up"),_T("TortoiseGit"),\r
1838                                                         MB_YESNO) == IDNO)\r
1839                                                         break;\r
1840         }\r
1841         CHintListCtrl::OnDestroy();\r
1842 }\r
1843 \r
1844 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)\r
1845 {\r
1846         CRect rect;\r
1847         int i=(int)wParam;\r
1848         this->GetItemRect(i,&rect,LVIR_BOUNDS);\r
1849         this->InvalidateRect(rect);\r
1850         return 0;\r
1851 }\r
1852 \r
1853 /**\r
1854  * Save column widths to the registry\r
1855  */\r
1856 void CGitLogListBase::SaveColumnWidths()\r
1857 {\r
1858         CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));\r
1859         if (pHdrCtrl)\r
1860         {\r
1861                 int numcols = pHdrCtrl->GetItemCount();\r
1862                 for (int col = 0; col < numcols; col++)\r
1863                 {\r
1864                         int width = GetColumnWidth( col );\r
1865                         CString regentry;\r
1866                         regentry.Format( _T("Software\\TortoiseGit\\log\\ColWidth%d"), col);\r
1867                         CRegDWORD regwidth(regentry, 0);\r
1868                         regwidth = width;       // this writes it to reg\r
1869                 }\r
1870         }\r
1871 }\r