OSDN Git Service

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