OSDN Git Service

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