OSDN Git Service

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