OSDN Git Service

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