OSDN Git Service

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