OSDN Git Service

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