OSDN Git Service

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