OSDN Git Service

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