OSDN Git Service

Add multi-thread protection and correct log info label
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / LogDlg.cpp
1 // TortoiseGit - a Windows shell extension for easy version control\r
2 // Copyright (C) 2003-2008 - TortoiseGit\r
3 // This program is free software; you can redistribute it and/or\r
4 // modify it under the terms of the GNU General Public License\r
5 // as published by the Free Software Foundation; either version 2\r
6 // of the License, or (at your option) any later version.\r
7 // This program is distributed in the hope that it will be useful,\r
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
10 // GNU General Public License for more details.\r
11 \r
12 // You should have received a copy of the GNU General Public License\r
13 // along with this program; if not, write to the Free Software Foundation,\r
14 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
15 //\r
16 #include "stdafx.h"\r
17 #include "TortoiseProc.h"\r
18 #include "cursor.h"\r
19 #include "InputDlg.h"\r
20 #include "PropDlg.h"\r
21 #include "SVNProgressDlg.h"\r
22 #include "ProgressDlg.h"\r
23 //#include "RepositoryBrowser.h"\r
24 //#include "CopyDlg.h"\r
25 #include "StatGraphDlg.h"\r
26 #include "Logdlg.h"\r
27 #include "MessageBox.h"\r
28 #include "Registry.h"\r
29 #include "AppUtils.h"\r
30 #include "PathUtils.h"\r
31 #include "StringUtils.h"\r
32 #include "UnicodeUtils.h"\r
33 #include "TempFile.h"\r
34 //#include "GitInfo.h"\r
35 //#include "GitDiff.h"\r
36 #include "IconMenu.h"\r
37 //#include "RevisionRangeDlg.h"\r
38 //#include "BrowseFolder.h"\r
39 //#include "BlameDlg.h"\r
40 //#include "Blame.h"\r
41 //#include "GitHelpers.h"\r
42 #include "GitStatus.h"\r
43 //#include "LogDlgHelper.h"\r
44 //#include "CachedLogInfo.h"\r
45 //#include "RepositoryInfo.h"\r
46 //#include "EditPropertiesDlg.h"\r
47 #include "FileDiffDlg.h"\r
48 #include "BrowseRefsDlg.h"\r
49 \r
50 const UINT CLogDlg::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);\r
51 \r
52 \r
53 IMPLEMENT_DYNAMIC(CLogDlg, CResizableStandAloneDialog)\r
54 CLogDlg::CLogDlg(CWnd* pParent /*=NULL*/)\r
55         : CResizableStandAloneDialog(CLogDlg::IDD, pParent)\r
56         , m_logcounter(0)\r
57         , m_nSearchIndex(0)\r
58         , m_wParam(0)\r
59         , m_currentChangedArray(NULL)\r
60         , m_nSortColumn(0)\r
61         , m_bShowedAll(false)\r
62         , m_bSelect(false)\r
63         \r
64         , m_bSelectionMustBeContinuous(false)\r
65         , m_bShowBugtraqColumn(false)\r
66         , m_lowestRev(_T(""))\r
67         \r
68         , m_sLogInfo(_T(""))\r
69         , m_pFindDialog(NULL)\r
70         , m_bCancelled(FALSE)\r
71         , m_pNotifyWindow(NULL)\r
72         \r
73         , m_bAscending(FALSE)\r
74 \r
75         , m_limit(0)\r
76         , m_childCounter(0)\r
77         , m_maxChild(0)\r
78         , m_bIncludeMerges(FALSE)\r
79         , m_hAccel(NULL)\r
80 {\r
81         m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);\r
82         m_bAllBranch=FALSE;\r
83         m_bFirstParent=FALSE;\r
84         m_bWholeProject=FALSE;\r
85 }\r
86 \r
87 CLogDlg::~CLogDlg()\r
88 {\r
89         \r
90     m_CurrentFilteredChangedArray.RemoveAll();\r
91         \r
92 }\r
93 \r
94 void CLogDlg::DoDataExchange(CDataExchange* pDX)\r
95 {\r
96         CResizableStandAloneDialog::DoDataExchange(pDX);\r
97         DDX_Control(pDX, IDC_LOGLIST, m_LogList);\r
98         DDX_Control(pDX, IDC_LOGMSG, m_ChangedFileListCtrl);\r
99         DDX_Control(pDX, IDC_PROGRESS, m_LogProgress);\r
100         DDX_Control(pDX, IDC_SPLITTERTOP, m_wndSplitter1);\r
101         DDX_Control(pDX, IDC_SPLITTERBOTTOM, m_wndSplitter2);\r
102         DDX_Text(pDX, IDC_SEARCHEDIT, m_LogList.m_sFilterText);\r
103         DDX_Control(pDX, IDC_DATEFROM, m_DateFrom);\r
104         DDX_Control(pDX, IDC_DATETO, m_DateTo);\r
105         DDX_Control(pDX, IDC_HIDEPATHS, m_cHidePaths);\r
106         DDX_Text(pDX, IDC_LOGINFO, m_sLogInfo);\r
107         DDX_Check(pDX, IDC_LOG_FIRSTPARENT, m_bFirstParent);\r
108         DDX_Check(pDX, IDC_LOG_ALLBRANCH,m_bAllBranch);\r
109         DDX_Check(pDX, IDC_SHOWWHOLEPROJECT,m_bWholeProject);\r
110         DDX_Control(pDX, IDC_SEARCHEDIT, m_cFilter);\r
111         DDX_Control(pDX, IDC_STATIC_REF, m_staticRef);\r
112 }\r
113 \r
114 BEGIN_MESSAGE_MAP(CLogDlg, CResizableStandAloneDialog)\r
115         ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage) \r
116         //ON_BN_CLICKED(IDC_GETALL, OnBnClickedGetall)\r
117         //ON_NOTIFY(NM_DBLCLK, IDC_LOGMSG, OnNMDblclkChangedFileList)\r
118         ON_WM_CONTEXTMENU()\r
119         ON_WM_SETCURSOR()\r
120         ON_BN_CLICKED(IDHELP, OnBnClickedHelp)\r
121         ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOGLIST, OnLvnItemchangedLoglist)\r
122         ON_NOTIFY(EN_LINK, IDC_MSGVIEW, OnEnLinkMsgview)\r
123         ON_BN_CLICKED(IDC_STATBUTTON, OnBnClickedStatbutton)\r
124 \r
125         \r
126         ON_MESSAGE(WM_FILTEREDIT_INFOCLICKED, OnClickedInfoIcon)\r
127         ON_MESSAGE(WM_FILTEREDIT_CANCELCLICKED, OnClickedCancelFilter)\r
128 \r
129         ON_MESSAGE(MSG_LOAD_PERCENTAGE,OnLogListLoading)\r
130         \r
131         ON_EN_CHANGE(IDC_SEARCHEDIT, OnEnChangeSearchedit)\r
132         ON_WM_TIMER()\r
133         ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETO, OnDtnDatetimechangeDateto)\r
134         ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATEFROM, OnDtnDatetimechangeDatefrom)\r
135         ON_BN_CLICKED(IDC_SHOWWHOLEPROJECT, OnBnClickShowWholeProject)\r
136         //ON_NOTIFY(NM_CUSTOMDRAW, IDC_LOGMSG, OnNMCustomdrawChangedFileList)\r
137         //ON_NOTIFY(LVN_GETDISPINFO, IDC_LOGMSG, OnLvnGetdispinfoChangedFileList)\r
138         ON_NOTIFY(LVN_COLUMNCLICK,IDC_LOGLIST   , OnLvnColumnclick)\r
139         //ON_NOTIFY(LVN_COLUMNCLICK, IDC_LOGMSG, OnLvnColumnclickChangedFileList)\r
140         ON_BN_CLICKED(IDC_HIDEPATHS, OnBnClickedHidepaths)\r
141         ON_BN_CLICKED(IDC_LOG_ALLBRANCH,OnBnClickedAllBranch)\r
142         \r
143         ON_NOTIFY(DTN_DROPDOWN, IDC_DATEFROM, &CLogDlg::OnDtnDropdownDatefrom)\r
144         ON_NOTIFY(DTN_DROPDOWN, IDC_DATETO, &CLogDlg::OnDtnDropdownDateto)\r
145         ON_WM_SIZE()\r
146         ON_BN_CLICKED(IDC_LOG_FIRSTPARENT, &CLogDlg::OnBnClickedFirstParent)\r
147         ON_BN_CLICKED(IDC_REFRESH, &CLogDlg::OnBnClickedRefresh)\r
148 //      ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CLogDlg::OnBnClickedBrowseRef)\r
149         ON_STN_CLICKED(IDC_STATIC_REF, &CLogDlg::OnBnClickedBrowseRef)\r
150         ON_COMMAND(ID_LOGDLG_REFRESH,&CLogDlg::OnRefresh)\r
151         ON_COMMAND(ID_LOGDLG_FIND,&CLogDlg::OnFind)\r
152         ON_COMMAND(ID_LOGDLG_FOCUSFILTER,&CLogDlg::OnFocusFilter)\r
153         ON_COMMAND(ID_EDIT_COPY, &CLogDlg::OnEditCopy)\r
154 END_MESSAGE_MAP()\r
155 \r
156 void CLogDlg::SetParams(const CTGitPath& path, GitRev pegrev, GitRev startrev, GitRev endrev, int limit /* = FALSE */)\r
157 {\r
158         m_path = path;\r
159         m_pegrev = pegrev;\r
160         m_startrev = startrev;\r
161         m_LogRevision = startrev;\r
162         m_endrev = endrev;\r
163         m_hasWC = !path.IsUrl();\r
164         m_limit = limit;\r
165         if (::IsWindow(m_hWnd))\r
166                 UpdateData(FALSE);\r
167 }\r
168 \r
169 BOOL CLogDlg::OnInitDialog()\r
170 {\r
171         CString temp;\r
172         CResizableStandAloneDialog::OnInitDialog();\r
173 \r
174         m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_LOGDLG));\r
175 \r
176 \r
177         // use the state of the "stop on copy/rename" option from the last time\r
178         UpdateData(FALSE);\r
179         \r
180         // set the font to use in the log message view, configured in the settings dialog\r
181         CAppUtils::CreateFontForLogs(m_logFont);\r
182         GetDlgItem(IDC_MSGVIEW)->SetFont(&m_logFont);\r
183         // automatically detect URLs in the log message and turn them into links\r
184         GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_AUTOURLDETECT, TRUE, NULL);\r
185         // make the log message rich edit control send a message when the mouse pointer is over a link\r
186         GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_SETEVENTMASK, NULL, ENM_LINK);\r
187         //m_LogList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_SUBITEMIMAGES);\r
188 \r
189         // the "hide unrelated paths" checkbox should be indeterminate\r
190         m_cHidePaths.SetCheck(BST_INDETERMINATE);\r
191 \r
192         \r
193         // if there is a working copy, load the project properties\r
194         // to get information about the bugtraq: integration\r
195         if (m_hasWC)\r
196                 m_ProjectProperties.ReadProps(m_path);\r
197 \r
198         // the bugtraq issue id column is only shown if the bugtraq:url or bugtraq:regex is set\r
199         if ((!m_ProjectProperties.sUrl.IsEmpty())||(!m_ProjectProperties.sCheckRe.IsEmpty()))\r
200                 m_bShowBugtraqColumn = true;\r
201 \r
202         //theme.SetWindowTheme(m_LogList.GetSafeHwnd(), L"Explorer", NULL);\r
203         //theme.SetWindowTheme(m_ChangedFileListCtrl.GetSafeHwnd(), L"Explorer", NULL);\r
204 \r
205         // set up the columns\r
206         m_LogList.DeleteAllItems();\r
207         m_LogList.InsertGitColumn();\r
208 \r
209         m_ChangedFileListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("LogDlg"),(SVNSLC_POPALL ^ (SVNSLC_POPCOMMIT|SVNSLC_POPREVERT)),false);\r
210 \r
211         GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);\r
212 \r
213         m_logcounter = 0;\r
214         m_sMessageBuf.Preallocate(100000);\r
215 \r
216         // set the dialog title to "Log - path/to/whatever/we/show/the/log/for"\r
217         SetDlgTitle(false);\r
218 \r
219         m_tooltips.Create(this);\r
220         CheckRegexpTooltip();\r
221 \r
222         SetSplitterRange();\r
223         \r
224         // the filter control has a 'cancel' button (the red 'X'), we need to load its bitmap\r
225         m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);\r
226         m_cFilter.SetInfoIcon(IDI_LOGFILTER);\r
227         m_cFilter.SetValidator(this);\r
228         \r
229         AdjustControlSize(IDC_HIDEPATHS);\r
230         AdjustControlSize(IDC_LOG_FIRSTPARENT);\r
231         AdjustControlSize(IDC_LOG_ALLBRANCH);\r
232 \r
233         GetClientRect(m_DlgOrigRect);\r
234         m_LogList.GetClientRect(m_LogListOrigRect);\r
235         GetDlgItem(IDC_MSGVIEW)->GetClientRect(m_MsgViewOrigRect);\r
236         m_ChangedFileListCtrl.GetClientRect(m_ChgOrigRect);\r
237 \r
238         m_DateFrom.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);\r
239         m_DateTo.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);\r
240 \r
241         m_staticRef.SetURL(CString());\r
242 \r
243         // resizable stuff\r
244         AddAnchor(IDC_STATIC_REF, TOP_LEFT);\r
245         //AddAnchor(IDC_BUTTON_BROWSE_REF, TOP_LEFT);\r
246         AddAnchor(IDC_FROMLABEL, TOP_LEFT);\r
247         AddAnchor(IDC_DATEFROM, TOP_LEFT);\r
248         AddAnchor(IDC_TOLABEL, TOP_LEFT);\r
249         AddAnchor(IDC_DATETO, TOP_LEFT);\r
250 \r
251         SetFilterCueText();\r
252         AddAnchor(IDC_SEARCHEDIT, TOP_LEFT, TOP_RIGHT);\r
253         \r
254         AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);\r
255         AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);\r
256         AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);\r
257         AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);\r
258         AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);\r
259 \r
260         AddAnchor(IDC_LOGINFO, BOTTOM_LEFT, BOTTOM_RIGHT);      \r
261         AddAnchor(IDC_HIDEPATHS, BOTTOM_LEFT);  \r
262         AddAnchor(IDC_LOG_ALLBRANCH,BOTTOM_LEFT);\r
263         AddAnchor(IDC_LOG_FIRSTPARENT, BOTTOM_LEFT);\r
264         //AddAnchor(IDC_GETALL, BOTTOM_LEFT);\r
265         AddAnchor(IDC_SHOWWHOLEPROJECT, BOTTOM_LEFT);\r
266         AddAnchor(IDC_REFRESH, BOTTOM_LEFT);\r
267         AddAnchor(IDC_STATBUTTON, BOTTOM_RIGHT);\r
268         AddAnchor(IDC_PROGRESS, BOTTOM_LEFT, BOTTOM_RIGHT);\r
269         AddAnchor(IDOK, BOTTOM_RIGHT);\r
270         AddAnchor(IDCANCEL, BOTTOM_RIGHT);\r
271         AddAnchor(IDHELP, BOTTOM_RIGHT);\r
272 \r
273 //      SetPromptParentWindow(m_hWnd);\r
274 \r
275         if (hWndExplorer)\r
276                 CenterWindow(CWnd::FromHandle(hWndExplorer));\r
277         EnableSaveRestore(_T("LogDlg"));\r
278 \r
279         DWORD yPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));\r
280         DWORD yPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));\r
281         RECT rcDlg, rcLogList, rcChgMsg;\r
282         GetClientRect(&rcDlg);\r
283         m_LogList.GetWindowRect(&rcLogList);\r
284         ScreenToClient(&rcLogList);\r
285         m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg);\r
286         ScreenToClient(&rcChgMsg);\r
287         if (yPos1)\r
288         {\r
289                 RECT rectSplitter;\r
290                 m_wndSplitter1.GetWindowRect(&rectSplitter);\r
291                 ScreenToClient(&rectSplitter);\r
292                 int delta = yPos1 - rectSplitter.top;\r
293 \r
294                 if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30))\r
295                 {\r
296                         m_wndSplitter1.SetWindowPos(NULL, 0, yPos1, 0, 0, SWP_NOSIZE);\r
297                         DoSizeV1(delta);\r
298                 }\r
299         }\r
300         if (yPos2)\r
301         {\r
302                 RECT rectSplitter;\r
303                 m_wndSplitter2.GetWindowRect(&rectSplitter);\r
304                 ScreenToClient(&rectSplitter);\r
305                 int delta = yPos2 - rectSplitter.top;\r
306 \r
307                 if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30))\r
308                 {\r
309                         m_wndSplitter2.SetWindowPos(NULL, 0, yPos2, 0, 0, SWP_NOSIZE);\r
310                         DoSizeV2(delta);\r
311                 }\r
312         }\r
313 \r
314         \r
315         if (m_bSelect)\r
316         {\r
317                 // the dialog is used to select revisions\r
318                 // enable the OK button if appropriate\r
319                 EnableOKButton();\r
320         }\r
321         else\r
322         {\r
323                 // the dialog is used to just view log messages\r
324                 // hide the OK button and set text on Cancel button to OK\r
325                 GetDlgItemText(IDOK, temp);\r
326                 SetDlgItemText(IDCANCEL, temp);\r
327                 GetDlgItem(IDOK)->ShowWindow(SW_HIDE);\r
328         }\r
329         \r
330         m_mergedRevs.clear();\r
331 \r
332         // first start a thread to obtain the log messages without\r
333         // blocking the dialog\r
334         //m_tTo = 0;\r
335         //m_tFrom = (DWORD)-1;\r
336 \r
337         m_LogList.m_Path=m_path;\r
338         m_LogList.m_bShowWC = true;\r
339         m_LogList.FetchLogAsync(this);\r
340 \r
341         GetDlgItem(IDC_LOGLIST)->SetFocus();\r
342 \r
343         ShowStartRef();\r
344         return FALSE;\r
345 }\r
346 \r
347 LRESULT CLogDlg::OnLogListLoading(WPARAM wParam, LPARAM /*lParam*/)\r
348 {\r
349         int cur=(int)wParam;\r
350 \r
351         if( cur == GITLOG_START )\r
352         {\r
353                 CString temp;\r
354                 temp.LoadString(IDS_PROGRESSWAIT);\r
355 \r
356                 this->m_LogList.ShowText(temp, true);\r
357 \r
358                 // We use a progress bar while getting the logs \r
359                 m_LogProgress.SetRange32(0, 100);\r
360                 m_LogProgress.SetPos(0);\r
361 \r
362                 GetDlgItem(IDC_PROGRESS)->ShowWindow(TRUE);\r
363 \r
364                 //DialogEnableWindow(IDC_GETALL, FALSE);\r
365                 //DialogEnableWindow(IDC_SHOWWHOLEPROJECT, FALSE);\r
366                 //DialogEnableWindow(IDC_LOG_FIRSTPARENT, FALSE);\r
367                 DialogEnableWindow(IDC_STATBUTTON, FALSE);\r
368                 DialogEnableWindow(IDC_REFRESH, FALSE);\r
369                 DialogEnableWindow(IDC_HIDEPATHS,FALSE);\r
370                 \r
371 \r
372         }else if( cur == GITLOG_END)\r
373         {\r
374                 \r
375                 if(this->m_LogList.HasText())\r
376                 {\r
377                         this->m_LogList.ClearText();\r
378                         \r
379                 }\r
380                 UpdateLogInfoLabel();\r
381 \r
382 #if 0\r
383                 //if (!m_bShowedAll)\r
384                 DialogEnableWindow(IDC_SHOWWHOLEPROJECT, TRUE);\r
385 \r
386                 //DialogEnableWindow(IDC_GETALL, TRUE);\r
387                 DialogEnableWindow(IDC_LOG_FIRSTPARENT, TRUE);\r
388                 DialogEnableWindow(IDC_STATBUTTON, TRUE);\r
389                 DialogEnableWindow(IDC_REFRESH, TRUE);\r
390                 DialogEnableWindow(IDC_HIDEPATHS,TRUE);\r
391 \r
392 //              PostMessage(WM_TIMER, LOGFILTER_TIMER);\r
393                 GetDlgItem(IDC_PROGRESS)->ShowWindow(FALSE);\r
394                 //CTime time=m_LogList.GetOldestTime();\r
395                 CTime begin,end;\r
396                 m_LogList.GetTimeRange(begin,end);\r
397                 m_DateFrom.SetTime(&begin);\r
398                 m_DateTo.SetTime(&end);\r
399 #endif\r
400 \r
401         }else\r
402         {\r
403                 if(this->m_LogList.HasText())\r
404                 {\r
405                         this->m_LogList.ClearText();\r
406                         UpdateLogInfoLabel();\r
407                 }\r
408                 m_LogProgress.SetPos(cur);\r
409         }\r
410         return 0;\r
411 }\r
412 void CLogDlg::SetDlgTitle(bool bOffline)\r
413 {\r
414         if (m_sTitle.IsEmpty())\r
415                 GetWindowText(m_sTitle);\r
416 \r
417         if (bOffline)\r
418         {\r
419                 CString sTemp;\r
420                 if (m_path.IsUrl())\r
421                         sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetUIPathString());\r
422                 else if (m_path.IsDirectory())\r
423                         sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetWinPathString());\r
424                 else\r
425                         sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetFilename());\r
426                 SetWindowText(sTemp);\r
427         }\r
428         else\r
429         {\r
430                 if (m_path.IsUrl())\r
431                         SetWindowText(m_sTitle + _T(" - ") + m_path.GetUIPathString());\r
432                 else if (m_path.IsEmpty())\r
433                         SetWindowText(m_sTitle + _T(" - ") + CString(_T("Whole Project")));\r
434                 else if (m_path.IsDirectory())\r
435                         SetWindowText(m_sTitle + _T(" - ") + m_path.GetWinPathString());\r
436                 else\r
437                         SetWindowText(m_sTitle + _T(" - ") + m_path.GetFilename());\r
438         }\r
439 }\r
440 \r
441 void CLogDlg::CheckRegexpTooltip()\r
442 {\r
443         CWnd *pWnd = GetDlgItem(IDC_SEARCHEDIT);\r
444         // Since tooltip describes regexp features, show it only if regexps are enabled.\r
445         if (m_bFilterWithRegex)\r
446         {\r
447                 m_tooltips.AddTool(pWnd, IDS_LOG_FILTER_REGEX_TT);\r
448         }\r
449         else\r
450                 m_tooltips.DelTool(pWnd);\r
451 }\r
452 \r
453 void CLogDlg::EnableOKButton()\r
454 {\r
455         if (m_bSelect)\r
456         {\r
457                 // the dialog is used to select revisions\r
458                 if (m_bSelectionMustBeSingle)\r
459                 {\r
460                         // enable OK button if only a single revision is selected\r
461                         DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()==1));\r
462                 }\r
463                 else if (m_bSelectionMustBeContinuous)\r
464                         DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));\r
465                 else\r
466                         DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);\r
467         }\r
468         else\r
469                 DialogEnableWindow(IDOK, TRUE);\r
470 }\r
471 \r
472 void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)\r
473 {\r
474         // we fill here the log message rich edit control,\r
475         // and also populate the changed files list control\r
476         // according to the selected revision(s).\r
477 \r
478         CRichEditCtrl * pMsgView = (CRichEditCtrl*)GetDlgItem(IDC_MSGVIEW);\r
479         // empty the log message view\r
480         pMsgView->SetWindowText(_T(" "));\r
481         // empty the changed files list\r
482         m_ChangedFileListCtrl.SetRedraw(FALSE);\r
483 //      InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
484         m_currentChangedArray = NULL;\r
485         //m_ChangedFileListCtrl.SetExtendedStyle ( LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER );\r
486         m_ChangedFileListCtrl.DeleteAllItems();\r
487         \r
488         // if we're not here to really show a selected revision, just\r
489         // get out of here after clearing the views, which is what is intended\r
490         // if that flag is not set.\r
491         if (!bShow)\r
492         {\r
493                 // force a redraw\r
494                 m_ChangedFileListCtrl.Invalidate();\r
495 //              InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
496                 m_ChangedFileListCtrl.SetRedraw(TRUE);\r
497                 return;\r
498         }\r
499 \r
500         // depending on how many revisions are selected, we have to do different\r
501         // tasks.\r
502         int selCount = m_LogList.GetSelectedCount();\r
503         if (selCount == 0)\r
504         {\r
505                 // if nothing is selected, we have nothing more to do\r
506 //              InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
507                 m_ChangedFileListCtrl.SetRedraw(TRUE);\r
508                 return;\r
509         }\r
510         else if (selCount == 1)\r
511         {\r
512                 // if one revision is selected, we have to fill the log message view\r
513                 // with the corresponding log message, and also fill the changed files\r
514                 // list fully.\r
515                 POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
516                 int selIndex = m_LogList.GetNextSelectedItem(pos);\r
517                 if (selIndex >= m_LogList.m_arShownList.GetCount())\r
518                 {\r
519 //                      InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
520                         m_ChangedFileListCtrl.SetRedraw(TRUE);\r
521                         return;\r
522                 }\r
523                 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.GetAt(selIndex));\r
524 \r
525                 if(!pLogEntry->m_IsFull)\r
526                 {\r
527                         pMsgView->SetWindowText(_T("load ..."));\r
528                 }else\r
529                 {\r
530                         // set the log message text\r
531                         pMsgView->SetWindowText(_T("Commit:")+pLogEntry->m_CommitHash.ToString()+_T("\r\n\r\n"));\r
532                         // turn bug ID's into links if the bugtraq: properties have been set\r
533                         // and we can find a match of those in the log message\r
534                         \r
535                         pMsgView->SetSel(-1,-1);\r
536                         CHARFORMAT2 format;\r
537                         SecureZeroMemory(&format, sizeof(CHARFORMAT2));\r
538                         format.cbSize = sizeof(CHARFORMAT2);\r
539                         format.dwMask = CFM_BOLD;\r
540                         format.dwEffects = CFE_BOLD;\r
541                         pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);\r
542                         \r
543                         CString msg=_T("* ");\r
544                         msg+=pLogEntry->m_Subject;\r
545                         pMsgView->ReplaceSel(msg);\r
546 \r
547                         pMsgView->SetSel(-1,-1);\r
548                         format.dwEffects = 0;\r
549                         pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);\r
550                         \r
551                         msg=_T("\n\n");\r
552                         msg+=pLogEntry->m_Body;\r
553                         pMsgView->ReplaceSel(msg);\r
554 \r
555                         CString text;\r
556                         pMsgView->GetWindowText(text);\r
557                         // the rich edit control doesn't count the CR char!\r
558                         // to be exact: CRLF is treated as one char.\r
559                         text.Replace(_T("\r"), _T(""));\r
560 \r
561                         m_ProjectProperties.FindBugID(text, pMsgView);\r
562                         CAppUtils::FormatTextInRichEditControl(pMsgView);\r
563 \r
564                         int HidePaths=m_cHidePaths.GetState() & 0x0003;\r
565                         CString matchpath=this->m_path.GetGitPathString();\r
566 \r
567                         for(int i=0;i<pLogEntry->m_Files.GetCount() && (!matchpath.IsEmpty());i++)\r
568                         {\r
569                                 if( m_bWholeProject )\r
570                                         break;\r
571 \r
572                                 ((CTGitPath&)pLogEntry->m_Files[i]).m_Action &= ~(CTGitPath::LOGACTIONS_HIDE|CTGitPath::LOGACTIONS_GRAY);\r
573                                 \r
574                                 if(pLogEntry->m_Files[i].GetGitPathString().Left(matchpath.GetLength()) != matchpath)\r
575                                 {\r
576                                         if(HidePaths==BST_CHECKED)\r
577                                                 ((CTGitPath&)pLogEntry->m_Files[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;\r
578                                         if(HidePaths==BST_INDETERMINATE)\r
579                                                 ((CTGitPath&)pLogEntry->m_Files[i]).m_Action |= CTGitPath::LOGACTIONS_GRAY;\r
580                                 }\r
581                         }\r
582                         m_ChangedFileListCtrl.UpdateWithGitPathList(pLogEntry->m_Files);\r
583                         m_ChangedFileListCtrl.m_CurrentVersion=pLogEntry->m_CommitHash;\r
584                         m_ChangedFileListCtrl.Show(SVNSLC_SHOWVERSIONED);\r
585 \r
586                         m_ChangedFileListCtrl.SetRedraw(TRUE);\r
587                         return;\r
588                 }\r
589 \r
590         }\r
591         else\r
592         {\r
593                 // more than one revision is selected:\r
594                 // the log message view must be emptied\r
595                 // the changed files list contains all the changed paths from all\r
596                 // selected revisions, with 'doubles' removed\r
597                 m_currentChangedPathList = GetChangedPathsFromSelectedRevisions(true);\r
598         }\r
599         \r
600         // redraw the views\r
601 //      InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
602 #if 0\r
603         if (m_currentChangedArray)\r
604         {\r
605                 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedArray->GetCount());\r
606                 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedArray->GetCount());\r
607         }\r
608         else if (m_currentChangedPathList.GetCount())\r
609         {\r
610                 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedPathList.GetCount());\r
611                 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedPathList.GetCount());\r
612         }\r
613         else\r
614         {\r
615                 m_ChangedFileListCtrl.SetItemCountEx(0);\r
616                 m_ChangedFileListCtrl.Invalidate();\r
617         }\r
618 #endif\r
619         // sort according to the settings\r
620         if (m_nSortColumnPathList > 0)\r
621                 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);\r
622         else\r
623                 SetSortArrow(&m_ChangedFileListCtrl, -1, false);\r
624         m_ChangedFileListCtrl.SetRedraw(TRUE);\r
625 \r
626 }\r
627 \r
628 void CLogDlg::OnBnClickedRefresh()\r
629 {\r
630         \r
631         Refresh (true);\r
632 }\r
633 \r
634 void CLogDlg::Refresh (bool /*autoGoOnline*/)\r
635 {\r
636         m_limit = 0;\r
637         m_LogList.Refresh();\r
638         FillLogMessageCtrl(false);\r
639 }\r
640 \r
641 \r
642 \r
643 BOOL CLogDlg::Cancel()\r
644 {\r
645         return m_bCancelled;\r
646 }\r
647 \r
648 void CLogDlg::SaveSplitterPos()\r
649 {\r
650         if (!IsIconic())\r
651         {\r
652                 CRegDWORD regPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));\r
653                 CRegDWORD regPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));\r
654                 RECT rectSplitter;\r
655                 m_wndSplitter1.GetWindowRect(&rectSplitter);\r
656                 ScreenToClient(&rectSplitter);\r
657                 regPos1 = rectSplitter.top;\r
658                 m_wndSplitter2.GetWindowRect(&rectSplitter);\r
659                 ScreenToClient(&rectSplitter);\r
660                 regPos2 = rectSplitter.top;\r
661         }\r
662 }\r
663 \r
664 void CLogDlg::OnCancel()\r
665 {\r
666         // canceling means stopping the working thread if it's still running.\r
667         if (this->IsThreadRunning())\r
668         {\r
669                 m_LogList.TerminateThread();\r
670         }\r
671         UpdateData();\r
672         \r
673         SaveSplitterPos();\r
674         __super::OnCancel();\r
675 }\r
676 \r
677 CString CLogDlg::MakeShortMessage(const CString& message)\r
678 {\r
679         bool bFoundShort = true;\r
680         CString sShortMessage = m_ProjectProperties.GetLogSummary(message);\r
681         if (sShortMessage.IsEmpty())\r
682         {\r
683                 bFoundShort = false;\r
684                 sShortMessage = message;\r
685         }\r
686         // Remove newlines and tabs 'cause those are not shown nicely in the list control\r
687         sShortMessage.Replace(_T("\r"), _T(""));\r
688         sShortMessage.Replace(_T("\t"), _T(" "));\r
689         \r
690         // Suppose the first empty line separates 'summary' from the rest of the message.\r
691         int found = sShortMessage.Find(_T("\n\n"));\r
692         // To avoid too short 'short' messages \r
693         // (e.g. if the message looks something like "Bugfix:\n\n*done this\n*done that")\r
694         // only use the empty newline as a separator if it comes after at least 15 chars.\r
695         if ((!bFoundShort)&&(found >= 15))\r
696         {\r
697                 sShortMessage = sShortMessage.Left(found);\r
698         }\r
699         sShortMessage.Replace('\n', ' ');\r
700         return sShortMessage;\r
701 }\r
702 \r
703 BOOL CLogDlg::Log(git_revnum_t /*rev*/, const CString& /*author*/, const CString& /*date*/, const CString& /*message*/, LogChangedPathArray * /*cpaths*/,  int /*filechanges*/, BOOL /*copies*/, DWORD /*actions*/, BOOL /*haschildren*/)\r
704 {\r
705 #if 0\r
706         if (rev == SVN_INVALID_REVNUM)\r
707         {\r
708                 m_childCounter--;\r
709                 return TRUE;\r
710         }\r
711 \r
712         // this is the callback function which receives the data for every revision we ask the log for\r
713         // we store this information here one by one.\r
714         m_logcounter += 1;\r
715         if (m_startrev == -1)\r
716                 m_startrev = rev;\r
717         if (m_limit != 0)\r
718         {\r
719                 m_limitcounter--;\r
720                 m_LogProgress.SetPos(m_limit - m_limitcounter);\r
721         }\r
722         else if (m_startrev.IsNumber() && m_startrev.IsNumber())\r
723                 m_LogProgress.SetPos((git_revnum_t)m_startrev-rev+(git_revnum_t)m_endrev);\r
724         __time64_t ttime = time/1000000L;\r
725         if (m_tTo < (DWORD)ttime)\r
726                 m_tTo = (DWORD)ttime;\r
727         if (m_tFrom > (DWORD)ttime)\r
728                 m_tFrom = (DWORD)ttime;\r
729         if ((m_lowestRev > rev)||(m_lowestRev < 0))\r
730                 m_lowestRev = rev;\r
731         // Add as many characters from the log message to the list control\r
732         PLOGENTRYDATA pLogItem = new LOGENTRYDATA;\r
733         pLogItem->bCopies = !!copies;\r
734         \r
735         // find out if this item was copied in the revision\r
736         BOOL copiedself = FALSE;\r
737         if (copies)\r
738         {\r
739                 for (INT_PTR cpPathIndex = 0; cpPathIndex < cpaths->GetCount(); ++cpPathIndex)\r
740                 {\r
741                         LogChangedPath * cpath = cpaths->GetAt(cpPathIndex);\r
742                         if (!cpath->sCopyFromPath.IsEmpty() && (cpath->sPath.Compare(m_sSelfRelativeURL) == 0))\r
743                         {\r
744                                 // note: this only works if the log is fetched top-to-bottom\r
745                                 // but since we do that, it shouldn't be a problem\r
746                                 m_sSelfRelativeURL = cpath->sCopyFromPath;\r
747                                 copiedself = TRUE;\r
748                                 break;\r
749                         }\r
750                 }\r
751         }\r
752         pLogItem->bCopiedSelf = copiedself;\r
753         pLogItem->tmDate = ttime;\r
754         pLogItem->sAuthor = author;\r
755         pLogItem->sDate = date;\r
756         pLogItem->sShortMessage = MakeShortMessage(message);\r
757         pLogItem->dwFileChanges = filechanges;\r
758         pLogItem->actions = actions;\r
759         pLogItem->haschildren = haschildren;\r
760         pLogItem->childStackDepth = m_childCounter;\r
761         m_maxChild = max(m_childCounter, m_maxChild);\r
762         if (haschildren)\r
763                 m_childCounter++;\r
764         pLogItem->sBugIDs = m_ProjectProperties.FindBugID(message).Trim();\r
765         \r
766         // split multi line log entries and concatenate them\r
767         // again but this time with \r\n as line separators\r
768         // so that the edit control recognizes them\r
769         try\r
770         {\r
771                 if (message.GetLength()>0)\r
772                 {\r
773                         m_sMessageBuf = message;\r
774                         m_sMessageBuf.Replace(_T("\n\r"), _T("\n"));\r
775                         m_sMessageBuf.Replace(_T("\r\n"), _T("\n"));\r
776                         if (m_sMessageBuf.Right(1).Compare(_T("\n"))==0)\r
777                                 m_sMessageBuf = m_sMessageBuf.Left(m_sMessageBuf.GetLength()-1);\r
778                 }\r
779                 else\r
780                         m_sMessageBuf.Empty();\r
781         pLogItem->sMessage = m_sMessageBuf;\r
782         pLogItem->Rev = rev;\r
783 \r
784         // move-construct path array\r
785 \r
786         pLogItem->pArChangedPaths = new LogChangedPathArray (*cpaths);\r
787         cpaths->RemoveAll();\r
788         }\r
789         catch (CException * e)\r
790         {\r
791                 ::MessageBox(NULL, _T("not enough memory!"), _T("TortoiseGit"), MB_ICONERROR);\r
792                 e->Delete();\r
793                 m_bCancelled = TRUE;\r
794         }\r
795         m_logEntries.push_back(pLogItem);\r
796         m_arShownList.Add(pLogItem);\r
797 #endif\r
798         return TRUE;\r
799 }\r
800 \r
801 GitRev g_rev;\r
802 //this is the thread function which calls the subversion function\r
803 \r
804 \r
805 \r
806 \r
807 void CLogDlg::CopyChangedSelectionToClipBoard()\r
808 {\r
809 \r
810         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
811         if (pos == NULL)\r
812                 return; // nothing is selected, get out of here\r
813 \r
814         CString sPaths;\r
815 \r
816 //      CGitRev* pLogEntry = reinterpret_cast<CGitRev* >(m_LogList.m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
817 //      if (pos)\r
818         {\r
819                 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();\r
820                 while (pos)\r
821                 {\r
822                         int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);\r
823                         CTGitPath *path = (CTGitPath*)m_ChangedFileListCtrl.GetItemData(nItem);\r
824                         if(path)\r
825                                 sPaths += path->GetGitPathString();\r
826                         sPaths += _T("\r\n");\r
827                 }\r
828         }\r
829 #if 0\r
830         else\r
831         {\r
832                 // only one revision is selected in the log dialog top pane\r
833                 // but multiple items could be selected  in the changed items list\r
834                 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();\r
835                 while (pos)\r
836                 {\r
837                         int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);\r
838                         LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->GetAt(nItem);\r
839 \r
840                         if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)\r
841                         {\r
842                                 // some items are hidden! So find out which item the user really selected\r
843                                 INT_PTR selRealIndex = -1;\r
844                                 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)\r
845                                 {\r
846                                         if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)\r
847                                                 selRealIndex++;\r
848                                         if (selRealIndex == nItem)\r
849                                         {\r
850                                                 changedlogpath = pLogEntry->pArChangedPaths->GetAt(hiddenindex);\r
851                                                 break;\r
852                                         }\r
853                                 }\r
854                         }\r
855                         if (changedlogpath)\r
856                         {\r
857                                 sPaths += changedlogpath->sPath;\r
858                                 sPaths += _T("\r\n");\r
859                         }\r
860                 }\r
861         }\r
862 #endif\r
863         sPaths.Trim();\r
864         CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());\r
865 \r
866 }\r
867 \r
868 BOOL CLogDlg::IsDiffPossible(LogChangedPath * /*changedpath*/, git_revnum_t rev)\r
869 {\r
870 #if 0\r
871         CString added, deleted;\r
872         if (changedpath == NULL)\r
873                 return false;\r
874 \r
875         if ((rev > 1)&&(changedpath->action != LOGACTIONS_DELETED))\r
876         {\r
877                 if (changedpath->action == LOGACTIONS_ADDED) // file is added\r
878                 {\r
879                         if (changedpath->lCopyFromRev == 0)\r
880                                 return FALSE; // but file was not added with history\r
881                 }\r
882                 return TRUE;\r
883         }\r
884 #endif\r
885         return FALSE;\r
886 }\r
887 \r
888 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)\r
889 {\r
890         // we have two separate context menus:\r
891         // one shown on the log message list control,\r
892         // the other shown in the changed-files list control\r
893         int selCount = m_LogList.GetSelectedCount();\r
894         if (pWnd == &m_LogList)\r
895         {\r
896                 //ShowContextMenuForRevisions(pWnd, point);\r
897         }\r
898         else if (pWnd == &m_ChangedFileListCtrl)\r
899         {\r
900                 //ShowContextMenuForChangedpaths(pWnd, point);\r
901         }\r
902         else if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))\r
903         {\r
904                 POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
905                 int selIndex = -1;\r
906                 if (pos)\r
907                         selIndex = m_LogList.GetNextSelectedItem(pos);\r
908                 if ((point.x == -1) && (point.y == -1))\r
909                 {\r
910                         CRect rect;\r
911                         GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);\r
912                         ClientToScreen(&rect);\r
913                         point = rect.CenterPoint();\r
914                 }\r
915                 CString sMenuItemText;\r
916                 CMenu popup;\r
917                 if (popup.CreatePopupMenu())\r
918                 {\r
919                         // add the 'default' entries\r
920                         sMenuItemText.LoadString(IDS_SCIEDIT_COPY);\r
921                         popup.AppendMenu(MF_STRING | MF_ENABLED, WM_COPY, sMenuItemText);\r
922                         sMenuItemText.LoadString(IDS_SCIEDIT_SELECTALL);\r
923                         popup.AppendMenu(MF_STRING | MF_ENABLED, EM_SETSEL, sMenuItemText);\r
924 \r
925                         //if (selIndex >= 0)\r
926                         //{\r
927                         //      popup.AppendMenu(MF_SEPARATOR);\r
928                         //      sMenuItemText.LoadString(IDS_LOG_POPUP_EDITLOG);\r
929                         //      popup.AppendMenu(MF_STRING | MF_ENABLED, CGitLogList::ID_EDITAUTHOR, sMenuItemText);\r
930                         //}\r
931 \r
932                         int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);\r
933                         switch (cmd)\r
934                         {\r
935                         case 0:\r
936                                 break;  // no command selected\r
937                         case EM_SETSEL:\r
938                         case WM_COPY:\r
939                                 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);\r
940                                 break;\r
941                         case CGitLogList::ID_EDITAUTHOR:\r
942                                 EditLogMessage(selIndex);\r
943                                 break;\r
944                         }\r
945                 }\r
946         }\r
947 }\r
948 \r
949 \r
950 LRESULT CLogDlg::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)\r
951 {\r
952 #if 0\r
953     ASSERT(m_pFindDialog != NULL);\r
954 \r
955     if (m_pFindDialog->IsTerminating())\r
956     {\r
957             // invalidate the handle identifying the dialog box.\r
958         m_pFindDialog = NULL;\r
959         return 0;\r
960     }\r
961 \r
962     if(m_pFindDialog->FindNext())\r
963     {\r
964         //read data from dialog\r
965         CString FindText = m_pFindDialog->GetFindString();\r
966         bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);\r
967                 bool bFound = false;\r
968                 tr1::wregex pat;\r
969                 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);\r
970 \r
971                 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;\r
972 \r
973                 int i;\r
974                 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)\r
975                 {\r
976                         if (bRegex)\r
977                         {\r
978                                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));\r
979 \r
980                                 if (regex_search(wstring((LPCTSTR)pLogEntry->sMessage), pat, flags))\r
981                                 {\r
982                                         bFound = true;\r
983                                         break;\r
984                                 }\r
985                                 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;\r
986                                 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)\r
987                                 {\r
988                                         LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
989                                         if (regex_search(wstring((LPCTSTR)cpath->sCopyFromPath), pat, flags))\r
990                                         {\r
991                                                 bFound = true;\r
992                                                 --i;\r
993                                                 break;\r
994                                         }\r
995                                         if (regex_search(wstring((LPCTSTR)cpath->sPath), pat, flags))\r
996                                         {\r
997                                                 bFound = true;\r
998                                                 --i;\r
999                                                 break;\r
1000                                         }\r
1001                                 }\r
1002                         }\r
1003                         else\r
1004                         {\r
1005                                 if (bMatchCase)\r
1006                                 {\r
1007                                         if (m_logEntries[i]->sMessage.Find(FindText) >= 0)\r
1008                                         {\r
1009                                                 bFound = true;\r
1010                                                 break;\r
1011                                         }\r
1012                                         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));\r
1013                                         LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;\r
1014                                         for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)\r
1015                                         {\r
1016                                                 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
1017                                                 if (cpath->sCopyFromPath.Find(FindText)>=0)\r
1018                                                 {\r
1019                                                         bFound = true;\r
1020                                                         --i;\r
1021                                                         break;\r
1022                                                 }\r
1023                                                 if (cpath->sPath.Find(FindText)>=0)\r
1024                                                 {\r
1025                                                         bFound = true;\r
1026                                                         --i;\r
1027                                                         break;\r
1028                                                 }\r
1029                                         }\r
1030                                 }\r
1031                                 else\r
1032                                 {\r
1033                                     PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));\r
1034                                         CString msg = pLogEntry->sMessage;\r
1035                                         msg = msg.MakeLower();\r
1036                                         CString find = FindText.MakeLower();\r
1037                                         if (msg.Find(find) >= 0)\r
1038                                         {\r
1039                                                 bFound = TRUE;\r
1040                                                 break;\r
1041                                         }\r
1042                                         LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;\r
1043                                         for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)\r
1044                                         {\r
1045                                                 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
1046                                                 CString lowerpath = cpath->sCopyFromPath;\r
1047                                                 lowerpath.MakeLower();\r
1048                                                 if (lowerpath.Find(find)>=0)\r
1049                                                 {\r
1050                                                         bFound = TRUE;\r
1051                                                         --i;\r
1052                                                         break;\r
1053                                                 }\r
1054                                                 lowerpath = cpath->sPath;\r
1055                                                 lowerpath.MakeLower();\r
1056                                                 if (lowerpath.Find(find)>=0)\r
1057                                                 {\r
1058                                                         bFound = TRUE;\r
1059                                                         --i;\r
1060                                                         break;\r
1061                                                 }\r
1062                                         }\r
1063                                 } \r
1064                         }\r
1065                 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)\r
1066                 if (bFound)\r
1067                 {\r
1068                         this->m_nSearchIndex = (i+1);\r
1069                         m_LogList.EnsureVisible(i, FALSE);\r
1070                         m_LogList.SetItemState(m_LogList.GetSelectionMark(), 0, LVIS_SELECTED);\r
1071                         m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);\r
1072                         m_LogList.SetSelectionMark(i);\r
1073                         FillLogMessageCtrl();\r
1074                         UpdateData(FALSE);\r
1075                         m_nSearchIndex++;\r
1076                         if (m_nSearchIndex >= m_arShownList.GetCount())\r
1077                                 m_nSearchIndex = (int)m_arShownList.GetCount()-1;\r
1078                 }\r
1079     } // if(m_pFindDialog->FindNext()) \r
1080         UpdateLogInfoLabel();\r
1081 #endif\r
1082     return 0;\r
1083 }\r
1084 \r
1085 void CLogDlg::OnOK()\r
1086 {\r
1087         // since the log dialog is also used to select revisions for other\r
1088         // dialogs, we have to do some work before closing this dialog\r
1089         if (GetFocus() != GetDlgItem(IDOK))\r
1090                 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter\r
1091 \r
1092         \r
1093         if (this->IsThreadRunning())\r
1094         {\r
1095                 m_LogList.TerminateThread();\r
1096         }\r
1097         UpdateData();\r
1098         // check that one and only one row is selected\r
1099         if (m_LogList.GetSelectedCount() == 1)\r
1100         {\r
1101                 // get the selected row\r
1102                 POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1103                 int selIndex = m_LogList.GetNextSelectedItem(pos);\r
1104                 if (selIndex < m_LogList.m_arShownList.GetCount())\r
1105                 {\r
1106                         // all ok, pick up the revision\r
1107                         GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.GetAt(selIndex));\r
1108                         // extract the hash\r
1109                         m_sSelectedHash = pLogEntry->m_CommitHash;\r
1110                 }\r
1111         }\r
1112         UpdateData(FALSE);\r
1113         SaveSplitterPos();\r
1114         __super::OnOK();\r
1115         \r
1116         #if 0 \r
1117         if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))\r
1118                 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.\r
1119 \r
1120         CString temp;\r
1121         CString buttontext;\r
1122         GetDlgItemText(IDOK, buttontext);\r
1123         temp.LoadString(IDS_MSGBOX_CANCEL);\r
1124         if (temp.Compare(buttontext) != 0)\r
1125                 __super::OnOK();        // only exit if the button text matches, and that will match only if the thread isn't running anymore\r
1126         m_bCancelled = TRUE;\r
1127         m_selectedRevs.Clear();\r
1128         m_selectedRevsOneRange.Clear();\r
1129         if (m_pNotifyWindow)\r
1130         {\r
1131                 int selIndex = m_LogList.GetSelectionMark();\r
1132                 if (selIndex >= 0)\r
1133                 {       \r
1134                     PLOGENTRYDATA pLogEntry = NULL;\r
1135                         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1136                         pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1137                         m_selectedRevs.AddRevision(pLogEntry->Rev);\r
1138                         git_revnum_t lowerRev = pLogEntry->Rev;\r
1139                         git_revnum_t higherRev = lowerRev;\r
1140                         while (pos)\r
1141                         {\r
1142                             pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1143                                 git_revnum_t rev = pLogEntry->Rev;\r
1144                                 m_selectedRevs.AddRevision(pLogEntry->Rev);\r
1145                                 if (lowerRev > rev)\r
1146                                         lowerRev = rev;\r
1147                                 if (higherRev < rev)\r
1148                                         higherRev = rev;\r
1149                         }\r
1150                         if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())\r
1151                         {\r
1152                                 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);\r
1153                         }\r
1154                         BOOL bSentMessage = FALSE;\r
1155                         if (m_LogList.GetSelectedCount() == 1)\r
1156                         {\r
1157                                 // if only one revision is selected, check if the path/url with which the dialog was started\r
1158                                 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.\r
1159                                 // if it was copied, use the copy from revision as lowerRev\r
1160                                 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))\r
1161                                 {\r
1162                                         CString sUrl = m_path.GetGitPathString();\r
1163                                         if (!m_path.IsUrl())\r
1164                                         {\r
1165                                                 sUrl = GetURLFromPath(m_path);\r
1166                                         }\r
1167                                         sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());\r
1168                                         for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)\r
1169                                         {\r
1170                                                 LogChangedPath * pData = pLogEntry->pArChangedPaths->GetAt(cp);\r
1171                                                 if (pData)\r
1172                                                 {\r
1173                                                         if (sUrl.Compare(pData->sPath) == 0)\r
1174                                                         {\r
1175                                                                 if (!pData->sCopyFromPath.IsEmpty())\r
1176                                                                 {\r
1177                                                                         lowerRev = pData->lCopyFromRev;\r
1178                                                                         m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);\r
1179                                                                         m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);\r
1180                                                                         m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);\r
1181                                                                         bSentMessage = TRUE;\r
1182                                                                 }\r
1183                                                         }\r
1184                                                 }\r
1185                                         }\r
1186                                 }\r
1187                         }\r
1188                         if ( !bSentMessage )\r
1189                         {\r
1190                                 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);\r
1191                                 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);\r
1192                                 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);\r
1193                                 if (m_selectedRevsOneRange.GetCount())\r
1194                                         m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);\r
1195                         }\r
1196                 }\r
1197         }\r
1198         UpdateData();\r
1199         CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry"));\r
1200         reg = m_btnShow.GetCurrentEntry();\r
1201         SaveSplitterPos();\r
1202 #endif \r
1203 }\r
1204 \r
1205 void CLogDlg::OnNMDblclkChangedFileList(NMHDR * /*pNMHDR*/, LRESULT *pResult)\r
1206 {\r
1207         // a double click on an entry in the changed-files list has happened\r
1208         *pResult = 0;\r
1209 \r
1210         DiffSelectedFile();\r
1211 }\r
1212 \r
1213 void CLogDlg::DiffSelectedFile()\r
1214 {\r
1215 #if 0\r
1216         if (m_bThreadRunning)\r
1217                 return;\r
1218         UpdateLogInfoLabel();\r
1219         INT_PTR selIndex = m_ChangedFileListCtrl.GetSelectionMark();\r
1220         if (selIndex < 0)\r
1221                 return;\r
1222         if (m_ChangedFileListCtrl.GetSelectedCount() == 0)\r
1223                 return;\r
1224         // find out if there's an entry selected in the log list\r
1225         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1226         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1227         git_revnum_t rev1 = pLogEntry->Rev;\r
1228         git_revnum_t rev2 = rev1;\r
1229         if (pos)\r
1230         {\r
1231                 while (pos)\r
1232                 {\r
1233                         // there's at least a second entry selected in the log list: several revisions selected!\r
1234                         pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1235                         if (pLogEntry)\r
1236                         {\r
1237                                 rev1 = max(rev1,(long)pLogEntry->Rev);\r
1238                                 rev2 = min(rev2,(long)pLogEntry->Rev);\r
1239                         }\r
1240                 }\r
1241                 rev2--;\r
1242                 // now we have both revisions selected in the log list, so we can do a diff of the selected\r
1243                 // entry in the changed files list with these two revisions.\r
1244                 DoDiffFromLog(selIndex, rev1, rev2, false, false);\r
1245         }\r
1246         else\r
1247         {\r
1248                 rev2 = rev1-1;\r
1249                 // nothing or only one revision selected in the log list\r
1250                 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);\r
1251 \r
1252                 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)\r
1253                 {\r
1254                         // some items are hidden! So find out which item the user really clicked on\r
1255                         INT_PTR selRealIndex = -1;\r
1256                         for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)\r
1257                         {\r
1258                                 if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)\r
1259                                         selRealIndex++;\r
1260                                 if (selRealIndex == selIndex)\r
1261                                 {\r
1262                                         selIndex = hiddenindex;\r
1263                                         changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);\r
1264                                         break;\r
1265                                 }\r
1266                         }\r
1267                 }\r
1268 \r
1269                 if (IsDiffPossible(changedpath, rev1))\r
1270                 {\r
1271                         // diffs with renamed files are possible\r
1272                         if ((changedpath)&&(!changedpath->sCopyFromPath.IsEmpty()))\r
1273                                 rev2 = changedpath->lCopyFromRev;\r
1274                         else\r
1275                         {\r
1276                                 // if the path was modified but the parent path was 'added with history'\r
1277                                 // then we have to use the copy from revision of the parent path\r
1278                                 CTGitPath cpath = CTGitPath(changedpath->sPath);\r
1279                                 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)\r
1280                                 {\r
1281                                         CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->GetAt(flist)->sPath);\r
1282                                         if (p.IsAncestorOf(cpath))\r
1283                                         {\r
1284                                                 if (!pLogEntry->pArChangedPaths->GetAt(flist)->sCopyFromPath.IsEmpty())\r
1285                                                         rev2 = pLogEntry->pArChangedPaths->GetAt(flist)->lCopyFromRev;\r
1286                                         }\r
1287                                 }\r
1288                         }\r
1289                         DoDiffFromLog(selIndex, rev1, rev2, false, false);\r
1290                 }\r
1291                 else \r
1292                 {\r
1293                         CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));\r
1294                         CTGitPath tempfile2 = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));\r
1295                         GitRev r = rev1;\r
1296                         // deleted files must be opened from the revision before the deletion\r
1297                         if (changedpath->action == LOGACTIONS_DELETED)\r
1298                                 r = rev1-1;\r
1299                         m_bCancelled = false;\r
1300 \r
1301                         CProgressDlg progDlg;\r
1302                         progDlg.SetTitle(IDS_APPNAME);\r
1303                         progDlg.SetAnimation(IDR_DOWNLOAD);\r
1304                         CString sInfoLine;\r
1305                         sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)(m_sRepositoryRoot + changedpath->sPath), (LPCTSTR)r.ToString());\r
1306                         progDlg.SetLine(1, sInfoLine, true);\r
1307                         SetAndClearProgressInfo(&progDlg);\r
1308                         progDlg.ShowModeless(m_hWnd);\r
1309 \r
1310                         if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), r, r, tempfile))\r
1311                         {\r
1312                                 m_bCancelled = false;\r
1313                                 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), GitRev::REV_HEAD, r, tempfile))\r
1314                                 {\r
1315                                         progDlg.Stop();\r
1316                                         SetAndClearProgressInfo((HWND)NULL);\r
1317                                         CMessageBox::Show(m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
1318                                         return;\r
1319                                 }\r
1320                         }\r
1321                         progDlg.Stop();\r
1322                         SetAndClearProgressInfo((HWND)NULL);\r
1323 \r
1324                         CString sName1, sName2;\r
1325                         sName1.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1);\r
1326                         sName2.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1-1);\r
1327                         CAppUtils::DiffFlags flags;\r
1328                         flags.AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1329                         if (changedpath->action == LOGACTIONS_DELETED)\r
1330                                 CAppUtils::StartExtDiff(tempfile, tempfile2, sName2, sName1, flags);\r
1331                         else\r
1332                                 CAppUtils::StartExtDiff(tempfile2, tempfile, sName2, sName1, flags);\r
1333                 }\r
1334         }\r
1335 #endif \r
1336 }\r
1337 \r
1338 \r
1339 void CLogDlg::DoDiffFromLog(INT_PTR selIndex, GitRev* rev1, GitRev* rev2, bool blame, bool unified)\r
1340 {\r
1341         DialogEnableWindow(IDOK, FALSE);\r
1342 //      SetPromptApp(&theApp);\r
1343         theApp.DoWaitCursor(1);\r
1344 \r
1345         CString temppath;\r
1346         GetTempPath(temppath);\r
1347         \r
1348         CString file1;\r
1349         file1.Format(_T("%s%s_%s%s"),\r
1350                                 temppath,                                               \r
1351                                 (*m_currentChangedArray)[selIndex].GetBaseFilename(),\r
1352                                 rev1->m_CommitHash.ToString().Left(6),\r
1353                                 (*m_currentChangedArray)[selIndex].GetFileExtension());\r
1354 \r
1355         CString file2;\r
1356         file2.Format(_T("%s\\%s_%s%s"),\r
1357                                 temppath,                                               \r
1358                                 (*m_currentChangedArray)[selIndex].GetBaseFilename(),\r
1359                                 rev2->m_CommitHash.ToString().Left(6),\r
1360                                 (*m_currentChangedArray)[selIndex].GetFileExtension());\r
1361 \r
1362         CString cmd;\r
1363 \r
1364         cmd.Format(_T("git.exe cat-file -p %s:%s"),rev1->m_CommitHash,(*m_currentChangedArray)[selIndex].GetGitPathString());\r
1365         g_Git.RunLogFile(cmd,file1);\r
1366         cmd.Format(_T("git.exe cat-file -p %s:%s"),rev2->m_CommitHash,(*m_currentChangedArray)[selIndex].GetGitPathString());\r
1367         g_Git.RunLogFile(cmd,file2);\r
1368 \r
1369         CAppUtils::DiffFlags flags;\r
1370         CAppUtils::StartExtDiff(file1,file2,_T("A"),_T("B"),flags);\r
1371 \r
1372 #if 0\r
1373         //get the filename\r
1374         CString filepath;\r
1375         if (Git::PathIsURL(m_path))\r
1376         {\r
1377                 filepath = m_path.GetGitPathString();\r
1378         }\r
1379         else\r
1380         {\r
1381                 filepath = GetURLFromPath(m_path);\r
1382                 if (filepath.IsEmpty())\r
1383                 {\r
1384                         theApp.DoWaitCursor(-1);\r
1385                         CString temp;\r
1386                         temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);\r
1387                         CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);\r
1388                         TRACE(_T("could not retrieve the URL of the file!\n"));\r
1389                         EnableOKButton();\r
1390                         theApp.DoWaitCursor(-11);\r
1391                         return;         //exit\r
1392                 }\r
1393         }\r
1394         m_bCancelled = FALSE;\r
1395         filepath = GetRepositoryRoot(CTGitPath(filepath));\r
1396 \r
1397         CString firstfile, secondfile;\r
1398         if (m_LogList.GetSelectedCount()==1)\r
1399         {\r
1400                 int s = m_LogList.GetSelectionMark();\r
1401                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(s));\r
1402                 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);\r
1403                 firstfile = changedpath->sPath;\r
1404                 secondfile = firstfile;\r
1405                 if ((rev2 == rev1-1)&&(changedpath->lCopyFromRev > 0)) // is it an added file with history?\r
1406                 {\r
1407                         secondfile = changedpath->sCopyFromPath;\r
1408                         rev2 = changedpath->lCopyFromRev;\r
1409                 }\r
1410         }\r
1411         else\r
1412         {\r
1413                 firstfile = m_currentChangedPathList[selIndex].GetGitPathString();\r
1414                 secondfile = firstfile;\r
1415         }\r
1416 \r
1417         firstfile = filepath + firstfile.Trim();\r
1418         secondfile = filepath + secondfile.Trim();\r
1419 \r
1420         GitDiff diff(this, this->m_hWnd, true);\r
1421         diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1422         diff.SetHEADPeg(m_LogRevision);\r
1423         if (unified)\r
1424         {\r
1425                 if (PromptShown())\r
1426                         diff.ShowUnifiedDiff(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1);\r
1427                 else\r
1428                         CAppUtils::StartShowUnifiedDiff(m_hWnd, CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), m_LogRevision);\r
1429         }\r
1430         else\r
1431         {\r
1432                 if (diff.ShowCompare(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), false, blame))\r
1433                 {\r
1434                         if (firstfile.Compare(secondfile)==0)\r
1435                         {\r
1436                                 git_revnum_t baseRev = 0;\r
1437                                 diff.DiffProps(CTGitPath(firstfile), rev2, rev1, baseRev);\r
1438                         }\r
1439                 }\r
1440         }\r
1441 \r
1442 #endif\r
1443 \r
1444         theApp.DoWaitCursor(-1);\r
1445         EnableOKButton();\r
1446 }\r
1447 \r
1448 BOOL CLogDlg::Open(bool /*bOpenWith*/,CString changedpath, git_revnum_t rev)\r
1449 {\r
1450 #if 0\r
1451         DialogEnableWindow(IDOK, FALSE);\r
1452         SetPromptApp(&theApp);\r
1453         theApp.DoWaitCursor(1);\r
1454         CString filepath;\r
1455         if (Git::PathIsURL(m_path))\r
1456         {\r
1457                 filepath = m_path.GetGitPathString();\r
1458         }\r
1459         else\r
1460         {\r
1461                 filepath = GetURLFromPath(m_path);\r
1462                 if (filepath.IsEmpty())\r
1463                 {\r
1464                         theApp.DoWaitCursor(-1);\r
1465                         CString temp;\r
1466                         temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);\r
1467                         CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);\r
1468                         TRACE(_T("could not retrieve the URL of the file!\n"));\r
1469                         EnableOKButton();\r
1470                         return FALSE;\r
1471                 }\r
1472         }\r
1473         m_bCancelled = false;\r
1474         filepath = GetRepositoryRoot(CTGitPath(filepath));\r
1475         filepath += changedpath;\r
1476 \r
1477         CProgressDlg progDlg;\r
1478         progDlg.SetTitle(IDS_APPNAME);\r
1479         progDlg.SetAnimation(IDR_DOWNLOAD);\r
1480         CString sInfoLine;\r
1481         sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)GitRev(rev).ToString());\r
1482         progDlg.SetLine(1, sInfoLine, true);\r
1483         SetAndClearProgressInfo(&progDlg);\r
1484         progDlg.ShowModeless(m_hWnd);\r
1485 \r
1486         CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(filepath), rev);\r
1487         m_bCancelled = false;\r
1488         if (!Cat(CTGitPath(filepath), GitRev(rev), rev, tempfile))\r
1489         {\r
1490                 progDlg.Stop();\r
1491                 SetAndClearProgressInfo((HWND)NULL);\r
1492                 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
1493                 EnableOKButton();\r
1494                 theApp.DoWaitCursor(-1);\r
1495                 return FALSE;\r
1496         }\r
1497         progDlg.Stop();\r
1498         SetAndClearProgressInfo((HWND)NULL);\r
1499         SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);\r
1500         if (!bOpenWith)\r
1501         {\r
1502                 int ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);\r
1503                 if (ret <= HINSTANCE_ERROR)\r
1504                         bOpenWith = true;\r
1505         }\r
1506         if (bOpenWith)\r
1507         {\r
1508                 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");\r
1509                 cmd += tempfile.GetWinPathString() + _T(" ");\r
1510                 CAppUtils::LaunchApplication(cmd, NULL, false);\r
1511         }\r
1512         EnableOKButton();\r
1513         theApp.DoWaitCursor(-1);\r
1514 #endif\r
1515         return TRUE;\r
1516 }\r
1517 \r
1518 void CLogDlg::EditAuthor(const CLogDataVector& /*logs*/)\r
1519 {\r
1520 #if 0\r
1521         CString url;\r
1522         CString name;\r
1523         if (logs.size() == 0)\r
1524                 return;\r
1525         DialogEnableWindow(IDOK, FALSE);\r
1526         SetPromptApp(&theApp);\r
1527         theApp.DoWaitCursor(1);\r
1528         if (Git::PathIsURL(m_path))\r
1529                 url = m_path.GetGitPathString();\r
1530         else\r
1531         {\r
1532                 url = GetURLFromPath(m_path);\r
1533         }\r
1534         name = Git_PROP_REVISION_AUTHOR;\r
1535 \r
1536         CString value = RevPropertyGet(name, CTGitPath(url), logs[0]->Rev);\r
1537         CString sOldValue = value;\r
1538         value.Replace(_T("\n"), _T("\r\n"));\r
1539         CInputDlg dlg(this);\r
1540         dlg.m_sHintText.LoadString(IDS_LOG_AUTHOR);\r
1541         dlg.m_sInputText = value;\r
1542         dlg.m_sTitle.LoadString(IDS_LOG_AUTHOREDITTITLE);\r
1543         dlg.m_pProjectProperties = &m_ProjectProperties;\r
1544         dlg.m_bUseLogWidth = false;\r
1545         if (dlg.DoModal() == IDOK)\r
1546         {\r
1547                 dlg.m_sInputText.Replace(_T("\r"), _T(""));\r
1548 \r
1549                 LogCache::CCachedLogInfo* toUpdate \r
1550                         = GetLogCache (CTGitPath (m_sRepositoryRoot));\r
1551 \r
1552                 CProgressDlg progDlg;\r
1553                 progDlg.SetTitle(IDS_APPNAME);\r
1554                 progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));\r
1555                 progDlg.SetTime(true);\r
1556                 progDlg.SetShowProgressBar(true);\r
1557                 progDlg.ShowModeless(m_hWnd);\r
1558                 for (DWORD i=0; i<logs.size(); ++i)\r
1559                 {\r
1560                         if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), logs[i]->Rev))\r
1561                         {\r
1562                                 progDlg.Stop();\r
1563                                 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
1564                                 break;\r
1565                         }\r
1566                         else\r
1567                         {\r
1568 \r
1569                                 logs[i]->sAuthor = dlg.m_sInputText;\r
1570                                 m_LogList.Invalidate();\r
1571 \r
1572                                 // update the log cache \r
1573 \r
1574                                 if (toUpdate != NULL)\r
1575                                 {\r
1576                                         // log caching is active\r
1577 \r
1578                                         LogCache::CCachedLogInfo newInfo;\r
1579                                         newInfo.Insert ( logs[i]->Rev\r
1580                                                 , (const char*) CUnicodeUtils::GetUTF8 (logs[i]->sAuthor)\r
1581                                                 , ""\r
1582                                                 , 0\r
1583                                                 , LogCache::CRevisionInfoContainer::HAS_AUTHOR);\r
1584 \r
1585                                         toUpdate->Update (newInfo);\r
1586                                 }\r
1587                         }\r
1588                         progDlg.SetProgress64(i, logs.size());\r
1589                 }\r
1590                 progDlg.Stop();\r
1591         }\r
1592         theApp.DoWaitCursor(-1);\r
1593         EnableOKButton();\r
1594 #endif\r
1595 }\r
1596 \r
1597 void CLogDlg::EditLogMessage(int /*index*/)\r
1598 {\r
1599 #if 0\r
1600         CString url;\r
1601         CString name;\r
1602         DialogEnableWindow(IDOK, FALSE);\r
1603         SetPromptApp(&theApp);\r
1604         theApp.DoWaitCursor(1);\r
1605         if (Git::PathIsURL(m_path))\r
1606                 url = m_path.GetGitPathString();\r
1607         else\r
1608         {\r
1609                 url = GetURLFromPath(m_path);\r
1610         }\r
1611         name = Git_PROP_REVISION_LOG;\r
1612 \r
1613         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(index));\r
1614         m_bCancelled = FALSE;\r
1615         CString value = RevPropertyGet(name, CTGitPath(url), pLogEntry->Rev);\r
1616         CString sOldValue = value;\r
1617         value.Replace(_T("\n"), _T("\r\n"));\r
1618         CInputDlg dlg(this);\r
1619         dlg.m_sHintText.LoadString(IDS_LOG_MESSAGE);\r
1620         dlg.m_sInputText = value;\r
1621         dlg.m_sTitle.LoadString(IDS_LOG_MESSAGEEDITTITLE);\r
1622         dlg.m_pProjectProperties = &m_ProjectProperties;\r
1623         dlg.m_bUseLogWidth = true;\r
1624         if (dlg.DoModal() == IDOK)\r
1625         {\r
1626                 dlg.m_sInputText.Replace(_T("\r"), _T(""));\r
1627                 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), pLogEntry->Rev))\r
1628                 {\r
1629                         CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
1630                 }\r
1631                 else\r
1632                 {\r
1633                         pLogEntry->sShortMessage = MakeShortMessage(dlg.m_sInputText);\r
1634                         // split multi line log entries and concatenate them\r
1635                         // again but this time with \r\n as line separators\r
1636                         // so that the edit control recognizes them\r
1637                         if (dlg.m_sInputText.GetLength()>0)\r
1638                         {\r
1639                                 m_sMessageBuf = dlg.m_sInputText;\r
1640                                 dlg.m_sInputText.Replace(_T("\n\r"), _T("\n"));\r
1641                                 dlg.m_sInputText.Replace(_T("\r\n"), _T("\n"));\r
1642                                 if (dlg.m_sInputText.Right(1).Compare(_T("\n"))==0)\r
1643                                         dlg.m_sInputText = dlg.m_sInputText.Left(dlg.m_sInputText.GetLength()-1);\r
1644                         } \r
1645                         else\r
1646                                 dlg.m_sInputText.Empty();\r
1647                         pLogEntry->sMessage = dlg.m_sInputText;\r
1648                         pLogEntry->sBugIDs = m_ProjectProperties.FindBugID(dlg.m_sInputText);\r
1649                         CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);\r
1650                         pMsgView->SetWindowText(_T(" "));\r
1651                         pMsgView->SetWindowText(dlg.m_sInputText);\r
1652                         m_ProjectProperties.FindBugID(dlg.m_sInputText, pMsgView);\r
1653                         m_LogList.Invalidate();\r
1654         \r
1655             // update the log cache \r
1656 \r
1657             LogCache::CCachedLogInfo* toUpdate \r
1658                 = GetLogCache (CTGitPath (m_sRepositoryRoot));\r
1659             if (toUpdate != NULL)\r
1660             {\r
1661                 // log caching is active\r
1662 \r
1663                 LogCache::CCachedLogInfo newInfo;\r
1664                 newInfo.Insert ( pLogEntry->Rev\r
1665                                , ""\r
1666                                , (const char*) CUnicodeUtils::GetUTF8 (pLogEntry->sMessage)\r
1667                                , 0\r
1668                                , LogCache::CRevisionInfoContainer::HAS_COMMENT);\r
1669 \r
1670                 toUpdate->Update (newInfo);\r
1671             }\r
1672         }\r
1673         }\r
1674         theApp.DoWaitCursor(-1);\r
1675         EnableOKButton();\r
1676 #endif\r
1677 }\r
1678 \r
1679 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)\r
1680 {\r
1681         // Skip Ctrl-C when copying text out of the log message or search filter\r
1682         BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );\r
1683         if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')\r
1684         {\r
1685                 if (GetFocus()==GetDlgItem(IDC_LOGLIST))\r
1686                 {\r
1687                         if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))\r
1688                         {\r
1689                                 m_LogList.DiffSelectedRevWithPrevious();\r
1690                                 return TRUE;\r
1691                         }\r
1692                 }\r
1693                 if (GetFocus()==GetDlgItem(IDC_LOGMSG))\r
1694                 {\r
1695                         DiffSelectedFile();\r
1696                         return TRUE;\r
1697                 }\r
1698         }\r
1699         if (m_hAccel && !bSkipAccelerator)\r
1700         {\r
1701                 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);\r
1702                 if (ret)\r
1703                         return TRUE;\r
1704         }\r
1705         \r
1706         if(::IsWindow(m_tooltips.m_hWnd))\r
1707                 m_tooltips.RelayEvent(pMsg);\r
1708         return __super::PreTranslateMessage(pMsg);\r
1709 }\r
1710 \r
1711 \r
1712 BOOL CLogDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)\r
1713 {\r
1714         //if (this->IsThreadRunning())\r
1715         if(m_LogList.m_bNoDispUpdates)\r
1716         {\r
1717                 // only show the wait cursor over the list control\r
1718                 if ((pWnd)&&\r
1719                         ((pWnd == GetDlgItem(IDC_LOGLIST))||\r
1720                         (pWnd == GetDlgItem(IDC_MSGVIEW))||\r
1721                         (pWnd == GetDlgItem(IDC_LOGMSG))))\r
1722                 {\r
1723                         HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));\r
1724                         SetCursor(hCur);\r
1725                         return TRUE;\r
1726                 }\r
1727         }\r
1728         if ((pWnd) && (pWnd == GetDlgItem(IDC_MSGVIEW)))\r
1729                 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);\r
1730 \r
1731         HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));\r
1732         SetCursor(hCur);\r
1733         return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);\r
1734 }\r
1735 \r
1736 void CLogDlg::OnBnClickedHelp()\r
1737 {\r
1738         OnHelp();\r
1739 }\r
1740 \r
1741 void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
1742 {\r
1743         LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);\r
1744         *pResult = 0;\r
1745         //if (this->IsThreadRunning())\r
1746         if(m_LogList.m_bNoDispUpdates)\r
1747                 return;\r
1748         if (pNMLV->iItem >= 0)\r
1749         {\r
1750                 m_nSearchIndex = pNMLV->iItem;\r
1751                 if (pNMLV->iSubItem != 0)\r
1752                         return;\r
1753                 if ((pNMLV->iItem == m_LogList.m_arShownList.GetCount()))\r
1754                 {\r
1755                         // remove the selected state\r
1756                         if (pNMLV->uChanged & LVIF_STATE)\r
1757                         {\r
1758                                 m_LogList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);\r
1759                                 FillLogMessageCtrl();\r
1760                                 UpdateData(FALSE);\r
1761                                 UpdateLogInfoLabel();\r
1762                         }\r
1763                         return;\r
1764                 }\r
1765                 if (pNMLV->uChanged & LVIF_STATE)\r
1766                 {\r
1767                         FillLogMessageCtrl();\r
1768                         UpdateData(FALSE);\r
1769                 }\r
1770         }\r
1771         else\r
1772         {\r
1773                 FillLogMessageCtrl();\r
1774                 UpdateData(FALSE);\r
1775         }\r
1776         EnableOKButton();\r
1777         UpdateLogInfoLabel();\r
1778 }\r
1779 \r
1780 void CLogDlg::OnEnLinkMsgview(NMHDR *pNMHDR, LRESULT *pResult)\r
1781 {\r
1782         ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);\r
1783         if (pEnLink->msg == WM_LBUTTONUP)\r
1784         {\r
1785                 CString url, msg;\r
1786                 GetDlgItemText(IDC_MSGVIEW, msg);\r
1787                 msg.Replace(_T("\r\n"), _T("\n"));\r
1788                 url = msg.Mid(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax-pEnLink->chrg.cpMin);\r
1789                 if (!::PathIsURL(url))\r
1790                 {\r
1791                         url = m_ProjectProperties.GetBugIDUrl(url);\r
1792                         url = GetAbsoluteUrlFromRelativeUrl(url);\r
1793                 }\r
1794                 if (!url.IsEmpty())\r
1795                         ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);\r
1796         }\r
1797         *pResult = 0;\r
1798 }\r
1799 \r
1800 class CDateSorter\r
1801 {\r
1802 public:\r
1803         class CCommitPointer\r
1804         {\r
1805         public:\r
1806                 CCommitPointer():m_cont(NULL){}\r
1807                 CCommitPointer(const CCommitPointer& P_Right)\r
1808                 : m_cont(NULL)\r
1809                 {\r
1810                         *this = P_Right;\r
1811                 }\r
1812 \r
1813                 CCommitPointer& operator = (const CCommitPointer& P_Right)\r
1814                 {\r
1815                         if(IsPointer())\r
1816                         {\r
1817                                 (*m_cont->m_parDates)[m_place]                  = P_Right.GetDate();\r
1818                                 (*m_cont->m_parFileChanges)[m_place]    = P_Right.GetChanges();\r
1819                                 (*m_cont->m_parAuthors)[m_place]                = P_Right.GetAuthor();\r
1820                         }\r
1821                         else \r
1822                         {\r
1823                                 m_Date                                                          = P_Right.GetDate();\r
1824                                 m_Changes                                                       = P_Right.GetChanges();\r
1825                                 m_csAuthor                                                      = P_Right.GetAuthor();\r
1826                         }\r
1827                         return *this;\r
1828                 }\r
1829 \r
1830                 void Clone(const CCommitPointer& P_Right)\r
1831                 {\r
1832                         m_cont = P_Right.m_cont;\r
1833                         m_place = P_Right.m_place;\r
1834                         m_Date = P_Right.m_Date;\r
1835                         m_Changes = P_Right.m_Changes;\r
1836                         m_csAuthor = P_Right.m_csAuthor;\r
1837                 }\r
1838 \r
1839                 DWORD            GetDate()              const {return IsPointer() ? (*m_cont->m_parDates)[m_place] : m_Date;}\r
1840                 DWORD            GetChanges()   const {return IsPointer() ? (*m_cont->m_parFileChanges)[m_place] : m_Changes;}\r
1841                 CString          GetAuthor()    const {return IsPointer() ? (*m_cont->m_parAuthors)[m_place] : m_csAuthor;}\r
1842 \r
1843                 bool            IsPointer() const {return m_cont != NULL;}\r
1844                 //When pointer\r
1845                 CDateSorter* m_cont;\r
1846                 int                      m_place;\r
1847 \r
1848                 //When element\r
1849                 DWORD            m_Date;\r
1850                 DWORD            m_Changes;\r
1851                 CString          m_csAuthor;\r
1852 \r
1853         };\r
1854         class iterator : public std::iterator<std::random_access_iterator_tag, CCommitPointer>\r
1855         {\r
1856         public:\r
1857                 CCommitPointer m_ptr;\r
1858 \r
1859                 iterator(){}\r
1860                 iterator(const iterator& P_Right){*this = P_Right;}\r
1861                 iterator& operator=(const iterator& P_Right)\r
1862                 {\r
1863                         m_ptr.Clone(P_Right.m_ptr);\r
1864                         return *this;\r
1865                 }\r
1866 \r
1867                 CCommitPointer& operator*(){return m_ptr;}\r
1868                 CCommitPointer* operator->(){return &m_ptr;}\r
1869                 const CCommitPointer& operator*()const{return m_ptr;}\r
1870                 const CCommitPointer* operator->()const{return &m_ptr;}\r
1871 \r
1872                 iterator& operator+=(size_t P_iOffset){m_ptr.m_place += P_iOffset;return *this;}\r
1873                 iterator& operator-=(size_t P_iOffset){m_ptr.m_place -= P_iOffset;return *this;}\r
1874                 iterator operator+(size_t P_iOffset)const{iterator it(*this); it += P_iOffset;return it;}\r
1875                 iterator operator-(size_t P_iOffset)const{iterator it(*this); it -= P_iOffset;return it;}\r
1876 \r
1877                 iterator& operator++(){++m_ptr.m_place;return *this;}\r
1878                 iterator& operator--(){--m_ptr.m_place;return *this;}\r
1879                 iterator operator++(int){iterator it(*this);++*this;return it;}\r
1880                 iterator operator--(int){iterator it(*this);--*this;return it;}\r
1881 \r
1882                 size_t operator-(const iterator& P_itRight)const{return m_ptr.m_place - P_itRight->m_place;}\r
1883 \r
1884                 bool operator<(const iterator& P_itRight)const{return m_ptr.m_place < P_itRight->m_place;}\r
1885                 bool operator!=(const iterator& P_itRight)const{return m_ptr.m_place != P_itRight->m_place;}\r
1886                 bool operator==(const iterator& P_itRight)const{return m_ptr.m_place == P_itRight->m_place;}\r
1887                 bool operator>(const iterator& P_itRight)const{return m_ptr.m_place > P_itRight->m_place;}\r
1888         };\r
1889         iterator begin()\r
1890         {\r
1891                 iterator it;\r
1892                 it->m_place = 0;\r
1893                 it->m_cont = this;\r
1894                 return it;\r
1895         }\r
1896         iterator end()\r
1897         {\r
1898                 iterator it;\r
1899                 it->m_place = m_parDates->GetCount();\r
1900                 it->m_cont = this;\r
1901                 return it;\r
1902         }\r
1903 \r
1904         CDWordArray     *       m_parDates;\r
1905         CDWordArray     *       m_parFileChanges;\r
1906         CStringArray *  m_parAuthors;\r
1907 };\r
1908 \r
1909 class CDateSorterLess\r
1910 {\r
1911 public:\r
1912         bool operator () (const CDateSorter::CCommitPointer& P_Left, const CDateSorter::CCommitPointer& P_Right) const\r
1913         {\r
1914                 return P_Left.GetDate() > P_Right.GetDate(); //Last date first\r
1915         }\r
1916 \r
1917 };\r
1918 \r
1919 \r
1920 \r
1921 void CLogDlg::OnBnClickedStatbutton()\r
1922 {\r
1923 \r
1924         if (this->IsThreadRunning())\r
1925                 return;\r
1926         if (m_LogList.m_arShownList.IsEmpty())\r
1927                 return;         // nothing is shown, so no statistics.\r
1928         // the statistics dialog expects the log entries to be sorted by date\r
1929         SortByColumn(3, false);\r
1930         CPtrArray shownlist;\r
1931         m_LogList.RecalculateShownList(&shownlist);\r
1932         // create arrays which are aware of the current filter\r
1933         CStringArray m_arAuthorsFiltered;\r
1934         CDWordArray m_arDatesFiltered;\r
1935         CDWordArray m_arFileChangesFiltered;\r
1936         for (INT_PTR i=0; i<shownlist.GetCount(); ++i)\r
1937         {\r
1938                 GitRev* pLogEntry = reinterpret_cast<GitRev*>(shownlist.GetAt(i));\r
1939                 CString strAuthor = pLogEntry->m_AuthorName;\r
1940                 if ( strAuthor.IsEmpty() )\r
1941                 {\r
1942                         strAuthor.LoadString(IDS_STATGRAPH_EMPTYAUTHOR);\r
1943                 }\r
1944                 m_arAuthorsFiltered.Add(strAuthor);\r
1945                 m_arDatesFiltered.Add(pLogEntry->m_AuthorDate.GetTime());\r
1946                 m_arFileChangesFiltered.Add(pLogEntry->m_Files.GetCount());\r
1947         }\r
1948 \r
1949         CDateSorter W_Sorter;\r
1950         W_Sorter.m_parAuthors           = &m_arAuthorsFiltered;\r
1951         W_Sorter.m_parDates                     = &m_arDatesFiltered;\r
1952         W_Sorter.m_parFileChanges       = &m_arFileChangesFiltered;\r
1953         std::sort(W_Sorter.begin(), W_Sorter.end(), CDateSorterLess());\r
1954 \r
1955         CStatGraphDlg dlg;\r
1956         dlg.m_parAuthors = &m_arAuthorsFiltered;\r
1957         dlg.m_parDates = &m_arDatesFiltered;\r
1958         dlg.m_parFileChanges = &m_arFileChangesFiltered;\r
1959         dlg.m_path = m_path;\r
1960         dlg.DoModal();\r
1961         // restore the previous sorting\r
1962         SortByColumn(m_nSortColumn, m_bAscending);\r
1963         OnTimer(LOGFILTER_TIMER);\r
1964 \r
1965 }\r
1966 \r
1967 void CLogDlg::DoSizeV1(int delta)\r
1968 {\r
1969 \r
1970         RemoveAnchor(IDC_LOGLIST);\r
1971         RemoveAnchor(IDC_SPLITTERTOP);\r
1972         RemoveAnchor(IDC_MSGVIEW);\r
1973         RemoveAnchor(IDC_SPLITTERBOTTOM);\r
1974         RemoveAnchor(IDC_LOGMSG);\r
1975         CSplitterControl::ChangeHeight(&m_LogList, delta, CW_TOPALIGN);\r
1976         CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), -delta, CW_BOTTOMALIGN);\r
1977         AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);\r
1978         AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);\r
1979         AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);\r
1980         AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);\r
1981         AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);\r
1982         ArrangeLayout();\r
1983         AdjustMinSize();\r
1984         SetSplitterRange();\r
1985         m_LogList.Invalidate();\r
1986         GetDlgItem(IDC_MSGVIEW)->Invalidate();\r
1987 \r
1988 }\r
1989 \r
1990 void CLogDlg::DoSizeV2(int delta)\r
1991 {\r
1992 \r
1993         RemoveAnchor(IDC_LOGLIST);\r
1994         RemoveAnchor(IDC_SPLITTERTOP);\r
1995         RemoveAnchor(IDC_MSGVIEW);\r
1996         RemoveAnchor(IDC_SPLITTERBOTTOM);\r
1997         RemoveAnchor(IDC_LOGMSG);\r
1998         CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), delta, CW_TOPALIGN);\r
1999         CSplitterControl::ChangeHeight(&m_ChangedFileListCtrl, -delta, CW_BOTTOMALIGN);\r
2000         AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);\r
2001         AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);\r
2002         AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);\r
2003         AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);\r
2004         AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);\r
2005         ArrangeLayout();\r
2006         AdjustMinSize();\r
2007         SetSplitterRange();\r
2008         GetDlgItem(IDC_MSGVIEW)->Invalidate();\r
2009         m_ChangedFileListCtrl.Invalidate();\r
2010 \r
2011 }\r
2012 \r
2013 void CLogDlg::AdjustMinSize()\r
2014 {\r
2015         // adjust the minimum size of the dialog to prevent the resizing from\r
2016         // moving the list control too far down.\r
2017         CRect rcChgListView;\r
2018         m_ChangedFileListCtrl.GetClientRect(rcChgListView);\r
2019         CRect rcLogList;\r
2020         m_LogList.GetClientRect(rcLogList);\r
2021 \r
2022         SetMinTrackSize(CSize(m_DlgOrigRect.Width(), \r
2023                 m_DlgOrigRect.Height()-m_ChgOrigRect.Height()-m_LogListOrigRect.Height()-m_MsgViewOrigRect.Height()\r
2024                 +rcChgListView.Height()+rcLogList.Height()+60));\r
2025 }\r
2026 \r
2027 LRESULT CLogDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) \r
2028 {\r
2029         switch (message) {\r
2030         case WM_NOTIFY:\r
2031                 if (wParam == IDC_SPLITTERTOP)\r
2032                 { \r
2033                         SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;\r
2034                         DoSizeV1(pHdr->delta);\r
2035                 }\r
2036                 else if (wParam == IDC_SPLITTERBOTTOM)\r
2037                 { \r
2038                         SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;\r
2039                         DoSizeV2(pHdr->delta);\r
2040                 }\r
2041                 break;\r
2042         }\r
2043 \r
2044         return CResizableDialog::DefWindowProc(message, wParam, lParam);\r
2045 }\r
2046 \r
2047 void CLogDlg::SetSplitterRange()\r
2048 {\r
2049         if ((m_LogList)&&(m_ChangedFileListCtrl))\r
2050         {\r
2051                 CRect rcTop;\r
2052                 m_LogList.GetWindowRect(rcTop);\r
2053                 ScreenToClient(rcTop);\r
2054                 CRect rcMiddle;\r
2055                 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(rcMiddle);\r
2056                 ScreenToClient(rcMiddle);\r
2057                 m_wndSplitter1.SetRange(rcTop.top+30, rcMiddle.bottom-20);\r
2058                 CRect rcBottom;\r
2059                 m_ChangedFileListCtrl.GetWindowRect(rcBottom);\r
2060                 ScreenToClient(rcBottom);\r
2061                 m_wndSplitter2.SetRange(rcMiddle.top+30, rcBottom.bottom-20);\r
2062         }\r
2063 }\r
2064 \r
2065 LRESULT CLogDlg::OnClickedInfoIcon(WPARAM /*wParam*/, LPARAM lParam)\r
2066 {\r
2067         // FIXME: x64 version would get this function called with unexpected parameters.\r
2068         if (!lParam)\r
2069                 return 0;\r
2070 \r
2071         RECT * rect = (LPRECT)lParam;\r
2072         CPoint point;\r
2073         CString temp;\r
2074         point = CPoint(rect->left, rect->bottom);\r
2075 #define LOGMENUFLAGS(x) (MF_STRING | MF_ENABLED | (m_LogList.m_nSelectedFilter == x ? MF_CHECKED : MF_UNCHECKED))\r
2076         CMenu popup;\r
2077         if (popup.CreatePopupMenu())\r
2078         {\r
2079                 temp.LoadString(IDS_LOG_FILTER_ALL);\r
2080                 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_ALL), LOGFILTER_ALL, temp);\r
2081 \r
2082                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
2083                 \r
2084                 temp.LoadString(IDS_LOG_FILTER_MESSAGES);\r
2085                 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_MESSAGES), LOGFILTER_MESSAGES, temp);\r
2086                 temp.LoadString(IDS_LOG_FILTER_PATHS);\r
2087                 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_PATHS), LOGFILTER_PATHS, temp);\r
2088                 temp.LoadString(IDS_LOG_FILTER_AUTHORS);\r
2089                 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_AUTHORS), LOGFILTER_AUTHORS, temp);\r
2090                 temp.LoadString(IDS_LOG_FILTER_REVS);\r
2091                 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REVS), LOGFILTER_REVS, temp);\r
2092                 temp.LoadString(IDS_LOG_FILTER_BUGIDS);\r
2093                 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_BUGID), LOGFILTER_BUGID, temp);\r
2094                 \r
2095                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
2096 \r
2097                 temp.LoadString(IDS_LOG_FILTER_REGEX);\r
2098                 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterWithRegex ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_REGEX, temp);\r
2099 \r
2100                 m_tooltips.Pop();\r
2101                 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);\r
2102                 if (selection != 0)\r
2103                 {\r
2104 \r
2105                         if (selection == LOGFILTER_REGEX)\r
2106                         {\r
2107                                 m_bFilterWithRegex = !m_bFilterWithRegex;\r
2108                                 CRegDWORD b = CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);\r
2109                                 b = m_bFilterWithRegex;\r
2110                                 CheckRegexpTooltip();\r
2111                         }\r
2112                         else\r
2113                         {\r
2114                                 m_LogList.m_nSelectedFilter = selection;\r
2115                                 SetFilterCueText();\r
2116                         }\r
2117                         SetTimer(LOGFILTER_TIMER, 1000, NULL);\r
2118                 }\r
2119         }\r
2120         return 0L;\r
2121 }\r
2122 \r
2123 LRESULT CLogDlg::OnClickedCancelFilter(WPARAM /*wParam*/, LPARAM /*lParam*/)\r
2124 {\r
2125 \r
2126         KillTimer(LOGFILTER_TIMER);\r
2127 \r
2128         m_LogList.m_sFilterText.Empty();\r
2129         UpdateData(FALSE);\r
2130         theApp.DoWaitCursor(1);\r
2131         CStoreSelection storeselection(this);\r
2132         FillLogMessageCtrl(false);\r
2133 \r
2134         m_LogList.RemoveFilter();\r
2135 \r
2136         CTime begin,end;\r
2137         m_LogList.GetTimeRange(begin,end);\r
2138         m_DateFrom.SetTime(&begin);\r
2139         m_DateTo.SetTime(&end);\r
2140 \r
2141         theApp.DoWaitCursor(-1);\r
2142         GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);\r
2143         GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);\r
2144         GetDlgItem(IDC_SEARCHEDIT)->SetFocus();\r
2145         UpdateLogInfoLabel();\r
2146 \r
2147         return 0L;      \r
2148 }\r
2149 \r
2150 \r
2151 void CLogDlg::SetFilterCueText()\r
2152 {\r
2153         CString temp;\r
2154         switch (m_LogList.m_nSelectedFilter)\r
2155         {\r
2156         case LOGFILTER_ALL:\r
2157                 temp.LoadString(IDS_LOG_FILTER_ALL);\r
2158                 break;\r
2159         case LOGFILTER_MESSAGES:\r
2160                 temp.LoadString(IDS_LOG_FILTER_MESSAGES);\r
2161                 break;\r
2162         case LOGFILTER_PATHS:\r
2163                 temp.LoadString(IDS_LOG_FILTER_PATHS);\r
2164                 break;\r
2165         case LOGFILTER_AUTHORS:\r
2166                 temp.LoadString(IDS_LOG_FILTER_AUTHORS);\r
2167                 break;\r
2168         case LOGFILTER_REVS:\r
2169                 temp.LoadString(IDS_LOG_FILTER_REVS);\r
2170                 break;\r
2171         }\r
2172         // to make the cue banner text appear more to the right of the edit control\r
2173         temp = _T("   ")+temp;\r
2174         m_cFilter.SetCueBanner(temp);\r
2175 }\r
2176 \r
2177 bool CLogDlg::Validate(LPCTSTR string)\r
2178 {\r
2179         if (!m_bFilterWithRegex)\r
2180                 return true;\r
2181         tr1::wregex pat;\r
2182         return m_LogList.ValidateRegexp(string, pat, false);\r
2183 }\r
2184 \r
2185 \r
2186 void CLogDlg::OnTimer(UINT_PTR nIDEvent)\r
2187 {\r
2188         if (nIDEvent == LOGFILTER_TIMER)\r
2189         {\r
2190                 if (this->IsThreadRunning())\r
2191                 {\r
2192                         // thread still running! So just restart the timer.\r
2193                         SetTimer(LOGFILTER_TIMER, 1000, NULL);\r
2194                         return;\r
2195                 }\r
2196                 CWnd * focusWnd = GetFocus();\r
2197                 bool bSetFocusToFilterControl = ((focusWnd != GetDlgItem(IDC_DATEFROM))&&(focusWnd != GetDlgItem(IDC_DATETO))\r
2198                         && (focusWnd != GetDlgItem(IDC_LOGLIST)));\r
2199                 if (m_LogList.m_sFilterText.IsEmpty())\r
2200                 {\r
2201                         DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));\r
2202                         // do not return here!\r
2203                         // we also need to run the filter if the filter text is empty:\r
2204                         // 1. to clear an existing filter\r
2205                         // 2. to rebuild the m_arShownList after sorting\r
2206                 }\r
2207                 theApp.DoWaitCursor(1);\r
2208                 CStoreSelection storeselection(this);\r
2209                 KillTimer(LOGFILTER_TIMER);\r
2210                 FillLogMessageCtrl(false);\r
2211 \r
2212                 // now start filter the log list\r
2213                 m_LogList.StartFilter();\r
2214 \r
2215                 if ( m_LogList.GetItemCount()==1 )\r
2216                 {\r
2217                         m_LogList.SetSelectionMark(0);\r
2218                         m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);\r
2219                 }\r
2220                 theApp.DoWaitCursor(-1);\r
2221                 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);\r
2222                 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);\r
2223                 if (bSetFocusToFilterControl)\r
2224                         GetDlgItem(IDC_SEARCHEDIT)->SetFocus();\r
2225                 UpdateLogInfoLabel();\r
2226         } // if (nIDEvent == LOGFILTER_TIMER)\r
2227         DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));\r
2228         __super::OnTimer(nIDEvent);\r
2229 }\r
2230 \r
2231 void CLogDlg::OnDtnDatetimechangeDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)\r
2232 {\r
2233         CTime _time;\r
2234         m_DateTo.GetTime(_time);\r
2235         try\r
2236         {\r
2237                 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 23, 59, 59);\r
2238                 if (time.GetTime() != m_LogList.m_To.GetTime())\r
2239                 {\r
2240                         m_LogList.m_To = (DWORD)time.GetTime();\r
2241                         SetTimer(LOGFILTER_TIMER, 10, NULL);\r
2242                 }\r
2243         }\r
2244         catch (CAtlException)\r
2245         {\r
2246         }\r
2247         \r
2248         *pResult = 0;\r
2249 }\r
2250 \r
2251 void CLogDlg::OnDtnDatetimechangeDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)\r
2252 {\r
2253         CTime _time;\r
2254         m_DateFrom.GetTime(_time);\r
2255         try\r
2256         {\r
2257                 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 0, 0, 0);\r
2258                 if (time.GetTime() != m_LogList.m_From.GetTime())\r
2259                 {\r
2260                         m_LogList.m_From = (DWORD)time.GetTime();\r
2261                         SetTimer(LOGFILTER_TIMER, 10, NULL);\r
2262                 }\r
2263         }\r
2264         catch (CAtlException)\r
2265         {\r
2266         }\r
2267         \r
2268         *pResult = 0;\r
2269 }\r
2270 \r
2271 \r
2272 \r
2273 CTGitPathList CLogDlg::GetChangedPathsFromSelectedRevisions(bool /*bRelativePaths*/ /* = false */, bool /*bUseFilter*/ /* = true */)\r
2274 {\r
2275         CTGitPathList pathList;\r
2276 #if 0\r
2277         \r
2278         if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))\r
2279         {\r
2280                 m_sRepositoryRoot = GetRepositoryRoot(m_path);\r
2281         }\r
2282         if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))\r
2283                 return pathList;\r
2284         \r
2285         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
2286         if (pos != NULL)\r
2287         {\r
2288                 while (pos)\r
2289                 {\r
2290                         int nextpos = m_LogList.GetNextSelectedItem(pos);\r
2291                         if (nextpos >= m_arShownList.GetCount())\r
2292                                 continue;\r
2293                         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(nextpos));\r
2294                         LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;\r
2295                         for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)\r
2296                         {\r
2297                                 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
2298                                 if (cpath == NULL)\r
2299                                         continue;\r
2300                                 CTGitPath path;\r
2301                                 if (!bRelativePaths)\r
2302                                         path.SetFromGit(m_sRepositoryRoot);\r
2303                                 path.AppendPathString(cpath->sPath);\r
2304                                 if ((!bUseFilter)||\r
2305                                         ((m_cHidePaths.GetState() & 0x0003)!=BST_CHECKED)||\r
2306                                         (cpath->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0))\r
2307                                         pathList.AddPath(path);\r
2308                                 \r
2309                         }\r
2310                 }\r
2311         }\r
2312         pathList.RemoveDuplicates();\r
2313 #endif\r
2314         return pathList;\r
2315 }\r
2316 \r
2317 void CLogDlg::SortByColumn(int /*nSortColumn*/, bool /*bAscending*/)\r
2318 {\r
2319 #if 0\r
2320         switch(nSortColumn)\r
2321         {\r
2322         case 0: // Revision\r
2323                 {\r
2324                         if(bAscending)\r
2325                                 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscRevSort());\r
2326                         else\r
2327                                 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescRevSort());\r
2328                 }\r
2329                 break;\r
2330         case 1: // action\r
2331                 {\r
2332                         if(bAscending)\r
2333                                 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscActionSort());\r
2334                         else\r
2335                                 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescActionSort());\r
2336                 }\r
2337                 break;\r
2338         case 2: // Author\r
2339                 {\r
2340                         if(bAscending)\r
2341                                 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscAuthorSort());\r
2342                         else\r
2343                                 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescAuthorSort());\r
2344                 }\r
2345                 break;\r
2346         case 3: // Date\r
2347                 {\r
2348                         if(bAscending)\r
2349                                 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscDateSort());\r
2350                         else\r
2351                                 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescDateSort());\r
2352                 }\r
2353                 break;\r
2354         case 4: // Message or bug id\r
2355                 if (m_bShowBugtraqColumn)\r
2356                 {\r
2357                         if(bAscending)\r
2358                                 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscBugIDSort());\r
2359                         else\r
2360                                 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescBugIDSort());\r
2361                         break;\r
2362                 }\r
2363                 // fall through here\r
2364         case 5: // Message\r
2365                 {\r
2366                         if(bAscending)\r
2367                                 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscMessageSort());\r
2368                         else\r
2369                                 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescMessageSort());\r
2370                 }\r
2371                 break;\r
2372         default:\r
2373                 ATLASSERT(0);\r
2374                 break;\r
2375         }\r
2376 #endif\r
2377 }\r
2378 \r
2379 void CLogDlg::OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult)\r
2380 {\r
2381         if (this->IsThreadRunning())\r
2382                 return;         //no sorting while the arrays are filled\r
2383 #if 0\r
2384         LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);\r
2385         const int nColumn = pNMLV->iSubItem;\r
2386         m_bAscending = nColumn == m_nSortColumn ? !m_bAscending : TRUE;\r
2387         m_nSortColumn = nColumn;\r
2388         SortByColumn(m_nSortColumn, m_bAscending);\r
2389         SetSortArrow(&m_LogList, m_nSortColumn, !!m_bAscending);\r
2390         SortShownListArray();\r
2391         m_LogList.Invalidate();\r
2392         UpdateLogInfoLabel();\r
2393 #endif\r
2394         *pResult = 0;\r
2395 }\r
2396 \r
2397 void CLogDlg::SortShownListArray()\r
2398 {\r
2399         // make sure the shown list still matches the filter after sorting.\r
2400     OnTimer(LOGFILTER_TIMER);\r
2401     // clear the selection states\r
2402         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
2403         while (pos)\r
2404         {\r
2405                 m_LogList.SetItemState(m_LogList.GetNextSelectedItem(pos), 0, LVIS_SELECTED);\r
2406         }    \r
2407         m_LogList.SetSelectionMark(-1);\r
2408 }\r
2409 \r
2410 void CLogDlg::SetSortArrow(CListCtrl * control, int nColumn, bool bAscending)\r
2411 {\r
2412         if (control == NULL)\r
2413                 return;\r
2414         // set the sort arrow\r
2415         CHeaderCtrl * pHeader = control->GetHeaderCtrl();\r
2416         HDITEM HeaderItem = {0};\r
2417         HeaderItem.mask = HDI_FORMAT;\r
2418         for (int i=0; i<pHeader->GetItemCount(); ++i)\r
2419         {\r
2420                 pHeader->GetItem(i, &HeaderItem);\r
2421                 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);\r
2422                 pHeader->SetItem(i, &HeaderItem);\r
2423         }\r
2424         if (nColumn >= 0)\r
2425         {\r
2426                 pHeader->GetItem(nColumn, &HeaderItem);\r
2427                 HeaderItem.fmt |= (bAscending ? HDF_SORTUP : HDF_SORTDOWN);\r
2428                 pHeader->SetItem(nColumn, &HeaderItem);\r
2429         }\r
2430 }\r
2431 void CLogDlg::OnLvnColumnclickChangedFileList(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)\r
2432 {\r
2433 #if 0\r
2434         if (this->IsThreadRunning())\r
2435                 return;         //no sorting while the arrays are filled\r
2436         if (m_currentChangedArray == NULL)\r
2437                 return;\r
2438         LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);\r
2439         const int nColumn = pNMLV->iSubItem;\r
2440         m_bAscendingPathList = nColumn == m_nSortColumnPathList ? !m_bAscendingPathList : TRUE;\r
2441         m_nSortColumnPathList = nColumn;\r
2442 //      qsort(m_currentChangedArray->GetData(), m_currentChangedArray->GetSize(), sizeof(LogChangedPath*), (GENERICCOMPAREFN)SortCompare);\r
2443 \r
2444         SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);\r
2445         m_ChangedFileListCtrl.Invalidate();\r
2446         *pResult = 0;\r
2447 #endif\r
2448 }\r
2449 \r
2450 int CLogDlg::m_nSortColumnPathList = 0;\r
2451 bool CLogDlg::m_bAscendingPathList = false;\r
2452 \r
2453 int CLogDlg::SortCompare(const void * /*pElem1*/, const void * /*pElem2*/)\r
2454 {\r
2455 #if 0\r
2456         LogChangedPath * cpath1 = *((LogChangedPath**)pElem1);\r
2457         LogChangedPath * cpath2 = *((LogChangedPath**)pElem2);\r
2458 \r
2459         if (m_bAscendingPathList)\r
2460                 std::swap (cpath1, cpath2);\r
2461 \r
2462         int cmp = 0;\r
2463         switch (m_nSortColumnPathList)\r
2464         {\r
2465         case 0: // action\r
2466                         cmp = cpath2->GetAction().Compare(cpath1->GetAction());\r
2467                         if (cmp)\r
2468                                 return cmp;\r
2469                         // fall through\r
2470         case 1: // path\r
2471                         cmp = cpath2->sPath.CompareNoCase(cpath1->sPath);\r
2472                         if (cmp)\r
2473                                 return cmp;\r
2474                         // fall through\r
2475         case 2: // copy from path\r
2476                         cmp = cpath2->sCopyFromPath.Compare(cpath1->sCopyFromPath);\r
2477                         if (cmp)\r
2478                                 return cmp;\r
2479                         // fall through\r
2480         case 3: // copy from revision\r
2481                         return cpath2->lCopyFromRev > cpath1->lCopyFromRev;\r
2482         }\r
2483 #endif\r
2484         return 0;\r
2485 }\r
2486 \r
2487 void CLogDlg::OnBnClickedHidepaths()\r
2488 {\r
2489         FillLogMessageCtrl();\r
2490         m_ChangedFileListCtrl.Invalidate();\r
2491 }\r
2492 \r
2493 \r
2494 \r
2495 void CLogDlg::OnBnClickedCheckStoponcopy()\r
2496 {\r
2497 #if 0\r
2498         if (!GetDlgItem(IDC_GETALL)->IsWindowEnabled())\r
2499                 return;\r
2500 \r
2501         // ignore old fetch limits when switching\r
2502         // between copy-following and stop-on-copy\r
2503         // (otherwise stop-on-copy will limit what\r
2504         // we see immediately after switching to\r
2505         // copy-following)\r
2506 \r
2507         m_endrev = 0;\r
2508 \r
2509         // now, restart the query\r
2510 #endif\r
2511         Refresh();\r
2512 }\r
2513 \r
2514 \r
2515 void CLogDlg::UpdateLogInfoLabel()\r
2516 {\r
2517 \r
2518         git_revnum_t rev1 ;\r
2519         git_revnum_t rev2 ;\r
2520         long selectedrevs = 0;\r
2521         int count =m_LogList.m_arShownList.GetCount();\r
2522         int start = 0;\r
2523         if (count)\r
2524         {\r
2525                 if(this->m_LogList.m_bShowWC)\r
2526                         start = 1;\r
2527                 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.GetAt(start)))->m_CommitHash;\r
2528                 //pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_arShownList.GetCount()-1));\r
2529                 rev2 =  (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.GetAt(count-1)))->m_CommitHash;\r
2530                 selectedrevs = m_LogList.GetSelectedCount();\r
2531         }\r
2532         CString sTemp;\r
2533         sTemp.Format(_T("Showing %ld revision(s), from revision %s to revision %s - %ld revision(s) selected"), count - start, rev2.Left(6), rev1.Left(6), selectedrevs);\r
2534         m_sLogInfo = sTemp;\r
2535 \r
2536         UpdateData(FALSE);\r
2537 }\r
2538 \r
2539 #if 0\r
2540 void CLogDlg::ShowContextMenuForChangedpaths(CWnd* /*pWnd*/, CPoint point)\r
2541 {\r
2542 \r
2543         int selIndex = m_ChangedFileListCtrl.GetSelectionMark();\r
2544         if ((point.x == -1) && (point.y == -1))\r
2545         {\r
2546                 CRect rect;\r
2547                 m_ChangedFileListCtrl.GetItemRect(selIndex, &rect, LVIR_LABEL);\r
2548                 m_ChangedFileListCtrl.ClientToScreen(&rect);\r
2549                 point = rect.CenterPoint();\r
2550         }\r
2551         if (selIndex < 0)\r
2552                 return;\r
2553         int s = m_LogList.GetSelectionMark();\r
2554         if (s < 0)\r
2555                 return;\r
2556         std::vector<CString> changedpaths;\r
2557         std::vector<LogChangedPath*> changedlogpaths;\r
2558         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
2559         if (pos == NULL)\r
2560                 return; // nothing is selected, get out of here\r
2561 \r
2562         bool bOneRev = true;\r
2563         int sel=m_LogList.GetNextSelectedItem(pos);\r
2564         GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.GetAt(sel));\r
2565         GitRev * rev1 = pLogEntry;\r
2566         GitRev * rev2 = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.GetAt(sel+1));\r
2567 #if 0\r
2568         bool bOneRev = true;\r
2569         if (pos)\r
2570         {\r
2571                 while (pos)\r
2572                 {\r
2573                         pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
2574                         if (pLogEntry)\r
2575                         {\r
2576                                 rev1 = max(rev1,(git_revnum_t)pLogEntry->Rev);\r
2577                                 rev2 = min(rev2,(git_revnum_t)pLogEntry->Rev);\r
2578                                 bOneRev = false;\r
2579                         }                               \r
2580                 }\r
2581                 if (!bOneRev)\r
2582                         rev2--;\r
2583                 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();\r
2584                 while (pos)\r
2585                 {\r
2586                         int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);\r
2587                         changedpaths.push_back(m_currentChangedPathList[nItem].GetGitPathString());\r
2588                 }\r
2589         }\r
2590         else\r
2591         {\r
2592                 // only one revision is selected in the log dialog top pane\r
2593                 // but multiple items could be selected  in the changed items list\r
2594                 rev2 = rev1-1;\r
2595 \r
2596                 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();\r
2597                 while (pos)\r
2598                 {\r
2599                         int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);\r
2600                         LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->GetAt(nItem);\r
2601 \r
2602                         if (m_ChangedFileListCtrl.GetSelectedCount() == 1)\r
2603                         {\r
2604                                 if ((changedlogpath)&&(!changedlogpath->sCopyFromPath.IsEmpty()))\r
2605                                         rev2 = changedlogpath->lCopyFromRev;\r
2606                                 else\r
2607                                 {\r
2608                                         // if the path was modified but the parent path was 'added with history'\r
2609                                         // then we have to use the copy from revision of the parent path\r
2610                                         CTGitPath cpath = CTGitPath(changedlogpath->sPath);\r
2611                                         for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)\r
2612                                         {\r
2613                                                 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->GetAt(flist)->sPath);\r
2614                                                 if (p.IsAncestorOf(cpath))\r
2615                                                 {\r
2616                                                         if (!pLogEntry->pArChangedPaths->GetAt(flist)->sCopyFromPath.IsEmpty())\r
2617                                                                 rev2 = pLogEntry->pArChangedPaths->GetAt(flist)->lCopyFromRev;\r
2618                                                 }\r
2619                                         }\r
2620                                 }\r
2621                         }\r
2622                         if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)\r
2623                         {\r
2624                                 // some items are hidden! So find out which item the user really clicked on\r
2625                                 INT_PTR selRealIndex = -1;\r
2626                                 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)\r
2627                                 {\r
2628                                         if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)\r
2629                                                 selRealIndex++;\r
2630                                         if (selRealIndex == nItem)\r
2631                                         {\r
2632                                                 selIndex = hiddenindex;\r
2633                                                 changedlogpath = pLogEntry->pArChangedPaths->GetAt(selIndex);\r
2634                                                 break;\r
2635                                         }\r
2636                                 }\r
2637                         }\r
2638                         if (changedlogpath)\r
2639                         {\r
2640                                 changedpaths.push_back(changedlogpath->sPath);\r
2641                                 changedlogpaths.push_back(changedlogpath);\r
2642                         }\r
2643                 }\r
2644         }\r
2645 #endif\r
2646         //entry is selected, now show the popup menu\r
2647         CIconMenu popup;\r
2648         if (popup.CreatePopupMenu())\r
2649         {\r
2650                 bool bEntryAdded = false;\r
2651                 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)\r
2652                 {\r
2653 //                      if ((!bOneRev)||(IsDiffPossible(changedlogpaths[0], rev1)))\r
2654                         {\r
2655                                 popup.AppendMenuIcon(CGitLogList::ID_DIFF, IDS_LOG_POPUP_DIFF, IDI_DIFF);\r
2656                                 popup.AppendMenuIcon(CGitLogList::ID_BLAMEDIFF, IDS_LOG_POPUP_BLAMEDIFF, IDI_BLAME);\r
2657                                 popup.SetDefaultItem(CGitLogList::ID_DIFF, FALSE);\r
2658                                 popup.AppendMenuIcon(CGitLogList::ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);\r
2659                                 bEntryAdded = true;\r
2660                         }\r
2661 //                      if (rev2 == rev1-1)\r
2662                         {\r
2663                                 if (bEntryAdded)\r
2664                                         popup.AppendMenu(MF_SEPARATOR, NULL);\r
2665                                 popup.AppendMenuIcon(CGitLogList::ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);\r
2666                                 popup.AppendMenuIcon(CGitLogList::ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);\r
2667                                 popup.AppendMenuIcon(CGitLogList::ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);\r
2668                                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
2669                                 if (m_hasWC)\r
2670                                         popup.AppendMenuIcon(CGitLogList::ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);\r
2671                                 popup.AppendMenuIcon(CGitLogList::ID_POPPROPS, IDS_REPOBROWSE_SHOWPROP, IDI_PROPERTIES);                        // "Show Properties"\r
2672                                 popup.AppendMenuIcon(CGitLogList::ID_LOG, IDS_MENULOG, IDI_LOG);                                                // "Show Log"                           \r
2673                                 popup.AppendMenuIcon(CGitLogList::ID_GETMERGELOGS, IDS_LOG_POPUP_GETMERGELOGS, IDI_LOG);                // "Show merge log"\r
2674                                 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);\r
2675                                 bEntryAdded = true;\r
2676                                 if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())\r
2677                                 {\r
2678                                         popup.AppendMenu(MF_SEPARATOR, NULL);\r
2679                                         popup.AppendMenuIcon(CGitLogList::ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);\r
2680                                 }\r
2681                                 if (popup.GetDefaultItem(0,FALSE)==-1)\r
2682                                         popup.SetDefaultItem(CGitLogList::ID_OPEN, FALSE);\r
2683                         }\r
2684                 }\r
2685                 else if (changedlogpaths.size())\r
2686                 {\r
2687                         // more than one entry is selected\r
2688                         popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE);\r
2689                         bEntryAdded = true;\r
2690                 }\r
2691 \r
2692                 if (!bEntryAdded)\r
2693         &nb