OSDN Git Service

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