OSDN Git Service

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