OSDN Git Service

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