OSDN Git Service

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