OSDN Git Service

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