OSDN Git Service

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