OSDN Git Service

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