OSDN Git Service

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