OSDN Git Service

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