Fix init repos commit\show log problem.
[TortoiseGit.git] / src / TortoiseProc / LogDlg.cpp
blob2cf2f612a92651f663a8a11227925fd24b4b997a
1 // TortoiseGit - a Windows shell extension for easy version control
2 // Copyright (C) 2003-2008 - TortoiseGit
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License for more details.
12 // You should have received a copy of the GNU General Public License
13 // along with this program; if not, write to the Free Software Foundation,
14 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 #include "stdafx.h"
17 #include "TortoiseProc.h"
18 #include "cursor.h"
19 #include "InputDlg.h"
20 #include "PropDlg.h"
21 #include "SVNProgressDlg.h"
22 #include "ProgressDlg.h"
23 //#include "RepositoryBrowser.h"
24 //#include "CopyDlg.h"
25 #include "StatGraphDlg.h"
26 #include "Logdlg.h"
27 #include "MessageBox.h"
28 #include "Registry.h"
29 #include "AppUtils.h"
30 #include "PathUtils.h"
31 #include "StringUtils.h"
32 #include "UnicodeUtils.h"
33 #include "TempFile.h"
34 //#include "GitInfo.h"
35 //#include "GitDiff.h"
36 #include "IconMenu.h"
37 //#include "RevisionRangeDlg.h"
38 //#include "BrowseFolder.h"
39 //#include "BlameDlg.h"
40 //#include "Blame.h"
41 //#include "GitHelpers.h"
42 #include "GitStatus.h"
43 //#include "LogDlgHelper.h"
44 //#include "CachedLogInfo.h"
45 //#include "RepositoryInfo.h"
46 //#include "EditPropertiesDlg.h"
47 #include "FileDiffDlg.h"
50 const UINT CLogDlg::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
53 IMPLEMENT_DYNAMIC(CLogDlg, CResizableStandAloneDialog)
54 CLogDlg::CLogDlg(CWnd* pParent /*=NULL*/)
55 : CResizableStandAloneDialog(CLogDlg::IDD, pParent)
56 , m_logcounter(0)
57 , m_nSearchIndex(0)
58 , m_wParam(0)
59 , m_currentChangedArray(NULL)
60 , m_nSortColumn(0)
61 , m_bShowedAll(false)
62 , m_bSelect(false)
63 , m_regLastStrict(_T("Software\\TortoiseGit\\LastLogStrict"), FALSE)
65 , m_bSelectionMustBeContinuous(false)
66 , m_bShowBugtraqColumn(false)
67 , m_lowestRev(_T(""))
69 , m_sLogInfo(_T(""))
70 , m_pFindDialog(NULL)
71 , m_bCancelled(FALSE)
72 , m_pNotifyWindow(NULL)
74 , m_bAscending(FALSE)
76 , m_limit(0)
77 , m_childCounter(0)
78 , m_maxChild(0)
79 , m_bIncludeMerges(FALSE)
80 , m_hAccel(NULL)
81 , m_bVista(false)
83 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
87 CLogDlg::~CLogDlg()
90 m_CurrentFilteredChangedArray.RemoveAll();
94 void CLogDlg::DoDataExchange(CDataExchange* pDX)
96 CResizableStandAloneDialog::DoDataExchange(pDX);
97 DDX_Control(pDX, IDC_LOGLIST, m_LogList);
98 DDX_Control(pDX, IDC_LOGMSG, m_ChangedFileListCtrl);
99 DDX_Control(pDX, IDC_PROGRESS, m_LogProgress);
100 DDX_Control(pDX, IDC_SPLITTERTOP, m_wndSplitter1);
101 DDX_Control(pDX, IDC_SPLITTERBOTTOM, m_wndSplitter2);
102 DDX_Check(pDX, IDC_CHECK_STOPONCOPY, m_bStrict);
103 DDX_Text(pDX, IDC_SEARCHEDIT, m_LogList.m_sFilterText);
104 DDX_Control(pDX, IDC_DATEFROM, m_DateFrom);
105 DDX_Control(pDX, IDC_DATETO, m_DateTo);
106 DDX_Control(pDX, IDC_HIDEPATHS, m_cHidePaths);
107 DDX_Control(pDX, IDC_GETALL, m_btnShow);
108 DDX_Text(pDX, IDC_LOGINFO, m_sLogInfo);
109 DDX_Check(pDX, IDC_INCLUDEMERGE, m_bIncludeMerges);
110 DDX_Control(pDX, IDC_SEARCHEDIT, m_cFilter);
113 BEGIN_MESSAGE_MAP(CLogDlg, CResizableStandAloneDialog)
114 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
115 ON_BN_CLICKED(IDC_GETALL, OnBnClickedGetall)
116 //ON_NOTIFY(NM_DBLCLK, IDC_LOGMSG, OnNMDblclkChangedFileList)
117 ON_WM_CONTEXTMENU()
118 ON_WM_SETCURSOR()
119 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
120 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOGLIST, OnLvnItemchangedLoglist)
121 ON_NOTIFY(EN_LINK, IDC_MSGVIEW, OnEnLinkMsgview)
122 ON_BN_CLICKED(IDC_STATBUTTON, OnBnClickedStatbutton)
124 ON_MESSAGE(WM_FILTEREDIT_INFOCLICKED, OnClickedInfoIcon)
125 ON_MESSAGE(WM_FILTEREDIT_CANCELCLICKED, OnClickedCancelFilter)
127 ON_EN_CHANGE(IDC_SEARCHEDIT, OnEnChangeSearchedit)
128 ON_WM_TIMER()
129 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETO, OnDtnDatetimechangeDateto)
130 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATEFROM, OnDtnDatetimechangeDatefrom)
131 ON_BN_CLICKED(IDC_NEXTHUNDRED, OnBnClickedNexthundred)
132 //ON_NOTIFY(NM_CUSTOMDRAW, IDC_LOGMSG, OnNMCustomdrawChangedFileList)
133 //ON_NOTIFY(LVN_GETDISPINFO, IDC_LOGMSG, OnLvnGetdispinfoChangedFileList)
134 ON_NOTIFY(LVN_COLUMNCLICK,IDC_LOGLIST , OnLvnColumnclick)
135 //ON_NOTIFY(LVN_COLUMNCLICK, IDC_LOGMSG, OnLvnColumnclickChangedFileList)
136 ON_BN_CLICKED(IDC_HIDEPATHS, OnBnClickedHidepaths)
138 ON_BN_CLICKED(IDC_CHECK_STOPONCOPY, &CLogDlg::OnBnClickedCheckStoponcopy)
139 ON_NOTIFY(DTN_DROPDOWN, IDC_DATEFROM, &CLogDlg::OnDtnDropdownDatefrom)
140 ON_NOTIFY(DTN_DROPDOWN, IDC_DATETO, &CLogDlg::OnDtnDropdownDateto)
141 ON_WM_SIZE()
142 ON_BN_CLICKED(IDC_INCLUDEMERGE, &CLogDlg::OnBnClickedIncludemerge)
143 ON_BN_CLICKED(IDC_REFRESH, &CLogDlg::OnBnClickedRefresh)
144 ON_COMMAND(ID_LOGDLG_REFRESH,&CLogDlg::OnRefresh)
145 ON_COMMAND(ID_LOGDLG_FIND,&CLogDlg::OnFind)
146 ON_COMMAND(ID_LOGDLG_FOCUSFILTER,&CLogDlg::OnFocusFilter)
147 ON_COMMAND(ID_EDIT_COPY, &CLogDlg::OnEditCopy)
148 END_MESSAGE_MAP()
150 void CLogDlg::SetParams(const CTGitPath& path, GitRev pegrev, GitRev startrev, GitRev endrev, int limit, BOOL bStrict /* = FALSE */, BOOL bSaveStrict /* = TRUE */)
152 m_path = path;
153 m_pegrev = pegrev;
154 m_startrev = startrev;
155 m_LogRevision = startrev;
156 m_endrev = endrev;
157 m_hasWC = !path.IsUrl();
158 m_bStrict = bStrict;
159 m_bSaveStrict = bSaveStrict;
160 m_limit = limit;
161 if (::IsWindow(m_hWnd))
162 UpdateData(FALSE);
165 BOOL CLogDlg::OnInitDialog()
167 CResizableStandAloneDialog::OnInitDialog();
169 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_LOGDLG));
171 OSVERSIONINFOEX inf;
172 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
173 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
174 GetVersionEx((OSVERSIONINFO *)&inf);
175 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
176 m_bVista = (fullver >= 0x0600);
178 // use the state of the "stop on copy/rename" option from the last time
179 if (!m_bStrict)
180 m_bStrict = m_regLastStrict;
181 UpdateData(FALSE);
182 CString temp;
183 if (m_limit)
184 temp.Format(IDS_LOG_SHOWNEXT, m_limit);
185 else
186 temp.Format(IDS_LOG_SHOWNEXT, (int)(DWORD)CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100));
188 SetDlgItemText(IDC_NEXTHUNDRED, temp);
190 // set the font to use in the log message view, configured in the settings dialog
191 CAppUtils::CreateFontForLogs(m_logFont);
192 GetDlgItem(IDC_MSGVIEW)->SetFont(&m_logFont);
193 // automatically detect URLs in the log message and turn them into links
194 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_AUTOURLDETECT, TRUE, NULL);
195 // make the log message rich edit control send a message when the mouse pointer is over a link
196 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_SETEVENTMASK, NULL, ENM_LINK);
197 //m_LogList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_SUBITEMIMAGES);
199 // the "hide unrelated paths" checkbox should be indeterminate
200 m_cHidePaths.SetCheck(BST_INDETERMINATE);
203 // if there is a working copy, load the project properties
204 // to get information about the bugtraq: integration
205 if (m_hasWC)
206 m_ProjectProperties.ReadProps(m_path);
208 // the bugtraq issue id column is only shown if the bugtraq:url or bugtraq:regex is set
209 if ((!m_ProjectProperties.sUrl.IsEmpty())||(!m_ProjectProperties.sCheckRe.IsEmpty()))
210 m_bShowBugtraqColumn = true;
212 //theme.SetWindowTheme(m_LogList.GetSafeHwnd(), L"Explorer", NULL);
213 //theme.SetWindowTheme(m_ChangedFileListCtrl.GetSafeHwnd(), L"Explorer", NULL);
215 // set up the columns
216 m_LogList.DeleteAllItems();
217 m_LogList.InsertGitColumn();
219 m_ChangedFileListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |IDS_STATUSLIST_COLADD|IDS_STATUSLIST_COLDEL , _T("LogDlg"));
221 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
223 m_logcounter = 0;
224 m_sMessageBuf.Preallocate(100000);
226 // set the dialog title to "Log - path/to/whatever/we/show/the/log/for"
227 SetDlgTitle(false);
229 m_tooltips.Create(this);
230 CheckRegexpTooltip();
232 SetSplitterRange();
234 // the filter control has a 'cancel' button (the red 'X'), we need to load its bitmap
235 m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);
236 m_cFilter.SetInfoIcon(IDI_LOGFILTER);
237 m_cFilter.SetValidator(this);
239 AdjustControlSize(IDC_HIDEPATHS);
240 AdjustControlSize(IDC_CHECK_STOPONCOPY);
241 AdjustControlSize(IDC_INCLUDEMERGE);
243 GetClientRect(m_DlgOrigRect);
244 m_LogList.GetClientRect(m_LogListOrigRect);
245 GetDlgItem(IDC_MSGVIEW)->GetClientRect(m_MsgViewOrigRect);
246 m_ChangedFileListCtrl.GetClientRect(m_ChgOrigRect);
248 m_DateFrom.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
249 m_DateTo.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
251 // resizable stuff
252 AddAnchor(IDC_FROMLABEL, TOP_LEFT);
253 AddAnchor(IDC_DATEFROM, TOP_LEFT);
254 AddAnchor(IDC_TOLABEL, TOP_LEFT);
255 AddAnchor(IDC_DATETO, TOP_LEFT);
257 SetFilterCueText();
258 AddAnchor(IDC_SEARCHEDIT, TOP_LEFT, TOP_RIGHT);
260 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
261 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
262 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
263 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
264 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
266 AddAnchor(IDC_LOGINFO, BOTTOM_LEFT, BOTTOM_RIGHT);
267 AddAnchor(IDC_HIDEPATHS, BOTTOM_LEFT);
268 AddAnchor(IDC_CHECK_STOPONCOPY, BOTTOM_LEFT);
269 AddAnchor(IDC_INCLUDEMERGE, BOTTOM_LEFT);
270 AddAnchor(IDC_GETALL, BOTTOM_LEFT);
271 AddAnchor(IDC_NEXTHUNDRED, BOTTOM_LEFT);
272 AddAnchor(IDC_REFRESH, BOTTOM_LEFT);
273 AddAnchor(IDC_STATBUTTON, BOTTOM_RIGHT);
274 AddAnchor(IDC_PROGRESS, BOTTOM_LEFT, BOTTOM_RIGHT);
275 AddAnchor(IDOK, BOTTOM_RIGHT);
276 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
277 AddAnchor(IDHELP, BOTTOM_RIGHT);
279 // SetPromptParentWindow(m_hWnd);
281 if (hWndExplorer)
282 CenterWindow(CWnd::FromHandle(hWndExplorer));
283 EnableSaveRestore(_T("LogDlg"));
285 DWORD yPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
286 DWORD yPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
287 RECT rcDlg, rcLogList, rcChgMsg;
288 GetClientRect(&rcDlg);
289 m_LogList.GetWindowRect(&rcLogList);
290 ScreenToClient(&rcLogList);
291 m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg);
292 ScreenToClient(&rcChgMsg);
293 if (yPos1)
295 RECT rectSplitter;
296 m_wndSplitter1.GetWindowRect(&rectSplitter);
297 ScreenToClient(&rectSplitter);
298 int delta = yPos1 - rectSplitter.top;
300 if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30))
302 m_wndSplitter1.SetWindowPos(NULL, 0, yPos1, 0, 0, SWP_NOSIZE);
303 DoSizeV1(delta);
306 if (yPos2)
308 RECT rectSplitter;
309 m_wndSplitter2.GetWindowRect(&rectSplitter);
310 ScreenToClient(&rectSplitter);
311 int delta = yPos2 - rectSplitter.top;
313 if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30))
315 m_wndSplitter2.SetWindowPos(NULL, 0, yPos2, 0, 0, SWP_NOSIZE);
316 DoSizeV2(delta);
321 if (m_bSelect)
323 // the dialog is used to select revisions
324 if (m_bSelectionMustBeContinuous)
325 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));
326 else
327 DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);
329 else
331 // the dialog is used to just view log messages
332 GetDlgItemText(IDOK, temp);
333 SetDlgItemText(IDCANCEL, temp);
334 GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
337 // set the choices for the "Show All" button
338 temp.LoadString(IDS_LOG_SHOWALL);
339 m_btnShow.AddEntry(temp);
340 temp.LoadString(IDS_LOG_SHOWRANGE);
341 m_btnShow.AddEntry(temp);
342 m_btnShow.SetCurrentEntry((LONG)CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry")));
344 m_mergedRevs.clear();
346 // first start a thread to obtain the log messages without
347 // blocking the dialog
348 //m_tTo = 0;
349 //m_tFrom = (DWORD)-1;
351 m_LogList.FetchLogAsync(LogCallBack,this);
353 GetDlgItem(IDC_LOGLIST)->SetFocus();
354 return FALSE;
357 void CLogDlg::LogRunStatus(int cur)
359 if( cur == GITLOG_START )
361 CString temp;
362 temp.LoadString(IDS_PROGRESSWAIT);
364 // change the text of the close button to "Cancel" since now the thread
365 // is running, and simply closing the dialog doesn't work.
366 if (!GetDlgItem(IDOK)->IsWindowVisible())
368 temp.LoadString(IDS_MSGBOX_CANCEL);
369 SetDlgItemText(IDCANCEL, temp);
372 // We use a progress bar while getting the logs
373 m_LogProgress.SetRange32(0, 100);
374 m_LogProgress.SetPos(0);
376 GetDlgItem(IDC_PROGRESS)->ShowWindow(TRUE);
378 DialogEnableWindow(IDC_GETALL, FALSE);
379 DialogEnableWindow(IDC_NEXTHUNDRED, FALSE);
380 DialogEnableWindow(IDC_CHECK_STOPONCOPY, FALSE);
381 DialogEnableWindow(IDC_INCLUDEMERGE, FALSE);
382 DialogEnableWindow(IDC_STATBUTTON, FALSE);
383 DialogEnableWindow(IDC_REFRESH, FALSE);
384 DialogEnableWindow(IDC_HIDEPATHS,FALSE);
387 if( cur == GITLOG_END)
390 if (!m_bShowedAll)
391 DialogEnableWindow(IDC_NEXTHUNDRED, TRUE);
393 //DialogEnableWindow(IDC_CHECK_STOPONCOPY, TRUE);
394 //DialogEnableWindow(IDC_INCLUDEMERGE, TRUE);
395 DialogEnableWindow(IDC_STATBUTTON, TRUE);
396 DialogEnableWindow(IDC_REFRESH, TRUE);
398 PostMessage(WM_TIMER, LOGFILTER_TIMER);
400 //CTime time=m_LogList.GetOldestTime();
401 CTime begin,end;
402 m_LogList.GetTimeRange(begin,end);
403 m_DateFrom.SetTime(&begin);
404 m_DateTo.SetTime(&end);
407 m_LogProgress.SetPos(cur);
409 void CLogDlg::SetDlgTitle(bool bOffline)
411 if (m_sTitle.IsEmpty())
412 GetWindowText(m_sTitle);
414 if (bOffline)
416 CString sTemp;
417 if (m_path.IsUrl())
418 sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetUIPathString());
419 else if (m_path.IsDirectory())
420 sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetWinPathString());
421 else
422 sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetFilename());
423 SetWindowText(sTemp);
425 else
427 if (m_path.IsUrl())
428 SetWindowText(m_sTitle + _T(" - ") + m_path.GetUIPathString());
429 else if (m_path.IsDirectory())
430 SetWindowText(m_sTitle + _T(" - ") + m_path.GetWinPathString());
431 else
432 SetWindowText(m_sTitle + _T(" - ") + m_path.GetFilename());
436 void CLogDlg::CheckRegexpTooltip()
438 CWnd *pWnd = GetDlgItem(IDC_SEARCHEDIT);
439 // Since tooltip describes regexp features, show it only if regexps are enabled.
440 if (m_bFilterWithRegex)
442 m_tooltips.AddTool(pWnd, IDS_LOG_FILTER_REGEX_TT);
444 else
445 m_tooltips.DelTool(pWnd);
448 void CLogDlg::EnableOKButton()
450 if (m_bSelect)
452 // the dialog is used to select revisions
453 if (m_bSelectionMustBeContinuous)
454 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));
455 else
456 DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);
458 else
459 DialogEnableWindow(IDOK, TRUE);
462 void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)
464 // we fill here the log message rich edit control,
465 // and also populate the changed files list control
466 // according to the selected revision(s).
468 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
469 // empty the log message view
470 pMsgView->SetWindowText(_T(" "));
471 // empty the changed files list
472 m_ChangedFileListCtrl.SetRedraw(FALSE);
473 // InterlockedExchange(&m_bNoDispUpdates, TRUE);
474 m_currentChangedArray = NULL;
475 //m_ChangedFileListCtrl.SetExtendedStyle ( LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER );
476 m_ChangedFileListCtrl.DeleteAllItems();
478 // if we're not here to really show a selected revision, just
479 // get out of here after clearing the views, which is what is intended
480 // if that flag is not set.
481 if (!bShow)
483 // force a redraw
484 m_ChangedFileListCtrl.Invalidate();
485 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
486 m_ChangedFileListCtrl.SetRedraw(TRUE);
487 return;
490 // depending on how many revisions are selected, we have to do different
491 // tasks.
492 int selCount = m_LogList.GetSelectedCount();
493 if (selCount == 0)
495 // if nothing is selected, we have nothing more to do
496 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
497 m_ChangedFileListCtrl.SetRedraw(TRUE);
498 return;
500 else if (selCount == 1)
502 // if one revision is selected, we have to fill the log message view
503 // with the corresponding log message, and also fill the changed files
504 // list fully.
505 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
506 int selIndex = m_LogList.GetNextSelectedItem(pos);
507 if (selIndex >= m_LogList.m_arShownList.GetCount())
509 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
510 m_ChangedFileListCtrl.SetRedraw(TRUE);
511 return;
513 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.GetAt(selIndex));
515 if(!pLogEntry->m_IsFull)
517 pMsgView->SetWindowText(_T("load ..."));
518 }else
520 // set the log message text
521 pMsgView->SetWindowText(_T("Commit:")+pLogEntry->m_CommitHash+_T("\r\n\r\n*")+pLogEntry->m_Subject+_T("\n\n")+pLogEntry->m_Body);
522 // turn bug ID's into links if the bugtraq: properties have been set
523 // and we can find a match of those in the log message
524 m_ProjectProperties.FindBugID(pLogEntry->m_Body, pMsgView);
525 CAppUtils::FormatTextInRichEditControl(pMsgView);
527 m_ChangedFileListCtrl.UpdateWithGitPathList(pLogEntry->m_Files);
528 m_ChangedFileListCtrl.m_CurrentVersion=pLogEntry->m_CommitHash;
529 m_ChangedFileListCtrl.Show(SVNSLC_SHOWVERSIONED);
531 m_ChangedFileListCtrl.SetRedraw(TRUE);
532 return;
534 #if 0
535 // fill in the changed files list control
536 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
538 m_CurrentFilteredChangedArray.RemoveAll();
539 for (INT_PTR c = 0; c < m_currentChangedArray->GetCount(); ++c)
541 LogChangedPath * cpath = m_currentChangedArray->GetAt(c);
542 if (cpath == NULL)
543 continue;
544 if (m_currentChangedArray->GetAt(c)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
546 m_CurrentFilteredChangedArray.Add(cpath);
549 m_currentChangedArray = &m_CurrentFilteredChangedArray;
551 #endif
553 else
555 // more than one revision is selected:
556 // the log message view must be emptied
557 // the changed files list contains all the changed paths from all
558 // selected revisions, with 'doubles' removed
559 m_currentChangedPathList = GetChangedPathsFromSelectedRevisions(true);
562 // redraw the views
563 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
564 if (m_currentChangedArray)
566 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedArray->GetCount());
567 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedArray->GetCount());
569 else if (m_currentChangedPathList.GetCount())
571 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedPathList.GetCount());
572 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedPathList.GetCount());
574 else
576 m_ChangedFileListCtrl.SetItemCountEx(0);
577 m_ChangedFileListCtrl.Invalidate();
579 CAppUtils::ResizeAllListCtrlCols(&m_ChangedFileListCtrl);
580 // sort according to the settings
581 if (m_nSortColumnPathList > 0)
582 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
583 else
584 SetSortArrow(&m_ChangedFileListCtrl, -1, false);
585 m_ChangedFileListCtrl.SetRedraw(TRUE);
589 void CLogDlg::OnBnClickedGetall()
591 GetAll();
594 void CLogDlg::GetAll(bool bForceAll /* = false */)
596 #if 0
597 // fetch all requested log messages, either the specified range or
598 // really *all* available log messages.
599 UpdateData();
600 INT_PTR entry = m_btnShow.GetCurrentEntry();
601 if (bForceAll)
602 entry = 0;
604 switch (entry)
606 case 0: // show all
608 m_endrev = 0;
609 m_startrev = m_LogRevision;
610 if (m_bStrict)
611 m_bShowedAll = true;
613 break;
614 case 1: // show range
617 // ask for a revision range
618 CRevisionRangeDlg dlg;
619 dlg.SetStartRevision(m_startrev);
620 dlg.SetEndRevision( (m_endrev>=0) ? m_endrev : 0);
621 if (dlg.DoModal()!=IDOK)
623 return;
625 m_endrev = dlg.GetEndRevision();
626 m_startrev = dlg.GetStartRevision();
627 if (((m_endrev.IsNumber())&&(m_startrev.IsNumber()))||
628 (m_endrev.IsHead()||m_startrev.IsHead()))
630 if (((LONG)m_startrev < (LONG)m_endrev)||
631 (m_endrev.IsHead()))
633 git_revnum_t temp = m_startrev;
634 m_startrev = m_endrev;
635 m_endrev = temp;
638 m_bShowedAll = false;
641 break;
643 m_ChangedFileListCtrl.SetItemCountEx(0);
644 m_ChangedFileListCtrl.Invalidate();
645 // We need to create CStoreSelection on the heap or else
646 // the variable will run out of the scope before the
647 // thread ends. Therefore we let the thread delete
648 // the instance.
649 m_pStoreSelection = new CStoreSelection(this);
650 m_LogList.SetItemCountEx(0);
651 m_LogList.Invalidate();
652 InterlockedExchange(&m_bNoDispUpdates, TRUE);
653 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
654 pMsgView->SetWindowText(_T(""));
656 SetSortArrow(&m_LogList, -1, true);
658 m_LogList.DeleteAllItems();
659 m_arShownList.RemoveAll();
660 m_logEntries.ClearAll();
662 m_logcounter = 0;
663 m_bCancelled = FALSE;
664 m_tTo = 0;
665 m_tFrom = (DWORD)-1;
666 m_limit = 0;
668 InterlockedExchange(&m_bThreadRunning, TRUE);
669 if (AfxBeginThread(LogThreadEntry, this)==NULL)
671 InterlockedExchange(&m_bThreadRunning, FALSE);
672 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
674 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
675 InterlockedExchange(&m_bNoDispUpdates, FALSE);
676 #endif
679 void CLogDlg::OnBnClickedRefresh()
681 m_limit = 0;
682 Refresh (true);
685 void CLogDlg::Refresh (bool autoGoOnline)
687 m_LogList.Refresh();
690 void CLogDlg::OnBnClickedNexthundred()
692 #if 0
693 UpdateData();
694 // we have to fetch the next X log messages.
695 if (m_logEntries.size() < 1)
697 // since there weren't any log messages fetched before, just
698 // fetch all since we don't have an 'anchor' to fetch the 'next'
699 // messages from.
700 return GetAll(true);
702 git_revnum_t rev = m_logEntries[m_logEntries.size()-1]->Rev;
704 if (rev < 1)
705 return; // do nothing! No more revisions to get
707 m_startrev = rev;
708 m_endrev = 0;
709 m_bCancelled = FALSE;
711 // rev is is revision we already have and we will receive it again
712 // -> fetch one extra revision to get NumberOfLogs *new* revisions
714 m_limit = (int)(DWORD)CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100) +1;
715 InterlockedExchange(&m_bNoDispUpdates, TRUE);
716 SetSortArrow(&m_LogList, -1, true);
717 InterlockedExchange(&m_bThreadRunning, TRUE);
718 // We need to create CStoreSelection on the heap or else
719 // the variable will run out of the scope before the
720 // thread ends. Therefore we let the thread delete
721 // the instance.
722 m_pStoreSelection = new CStoreSelection(this);
724 // since we fetch the log from the last revision we already have,
725 // we have to remove that revision entry to avoid getting it twice
726 m_logEntries.pop_back();
727 if (AfxBeginThread(LogThreadEntry, this)==NULL)
729 InterlockedExchange(&m_bThreadRunning, FALSE);
730 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
732 InterlockedExchange(&m_bNoDispUpdates, TRUE);
733 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
734 #endif
737 BOOL CLogDlg::Cancel()
739 return m_bCancelled;
742 void CLogDlg::SaveSplitterPos()
744 if (!IsIconic())
746 CRegDWORD regPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
747 CRegDWORD regPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
748 RECT rectSplitter;
749 m_wndSplitter1.GetWindowRect(&rectSplitter);
750 ScreenToClient(&rectSplitter);
751 regPos1 = rectSplitter.top;
752 m_wndSplitter2.GetWindowRect(&rectSplitter);
753 ScreenToClient(&rectSplitter);
754 regPos2 = rectSplitter.top;
758 void CLogDlg::OnCancel()
760 // canceling means stopping the working thread if it's still running.
761 // we do this by using the Subversion cancel callback.
762 // But canceling can also mean just to close the dialog, depending on the
763 // text shown on the cancel button (it could simply read "OK").
764 CString temp, temp2;
765 GetDlgItemText(IDOK, temp);
766 temp2.LoadString(IDS_MSGBOX_CANCEL);
767 if ((temp.Compare(temp2)==0)||(this->IsThreadRunning()))
769 m_bCancelled = true;
770 return;
772 UpdateData();
773 if (m_bSaveStrict)
774 m_regLastStrict = m_bStrict;
775 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry"));
776 reg = m_btnShow.GetCurrentEntry();
777 SaveSplitterPos();
778 __super::OnCancel();
781 CString CLogDlg::MakeShortMessage(const CString& message)
783 bool bFoundShort = true;
784 CString sShortMessage = m_ProjectProperties.GetLogSummary(message);
785 if (sShortMessage.IsEmpty())
787 bFoundShort = false;
788 sShortMessage = message;
790 // Remove newlines and tabs 'cause those are not shown nicely in the list control
791 sShortMessage.Replace(_T("\r"), _T(""));
792 sShortMessage.Replace(_T("\t"), _T(" "));
794 // Suppose the first empty line separates 'summary' from the rest of the message.
795 int found = sShortMessage.Find(_T("\n\n"));
796 // To avoid too short 'short' messages
797 // (e.g. if the message looks something like "Bugfix:\n\n*done this\n*done that")
798 // only use the empty newline as a separator if it comes after at least 15 chars.
799 if ((!bFoundShort)&&(found >= 15))
801 sShortMessage = sShortMessage.Left(found);
803 sShortMessage.Replace('\n', ' ');
804 return sShortMessage;
807 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)
809 #if 0
810 if (rev == SVN_INVALID_REVNUM)
812 m_childCounter--;
813 return TRUE;
816 // this is the callback function which receives the data for every revision we ask the log for
817 // we store this information here one by one.
818 m_logcounter += 1;
819 if (m_startrev == -1)
820 m_startrev = rev;
821 if (m_limit != 0)
823 m_limitcounter--;
824 m_LogProgress.SetPos(m_limit - m_limitcounter);
826 else if (m_startrev.IsNumber() && m_startrev.IsNumber())
827 m_LogProgress.SetPos((git_revnum_t)m_startrev-rev+(git_revnum_t)m_endrev);
828 __time64_t ttime = time/1000000L;
829 if (m_tTo < (DWORD)ttime)
830 m_tTo = (DWORD)ttime;
831 if (m_tFrom > (DWORD)ttime)
832 m_tFrom = (DWORD)ttime;
833 if ((m_lowestRev > rev)||(m_lowestRev < 0))
834 m_lowestRev = rev;
835 // Add as many characters from the log message to the list control
836 PLOGENTRYDATA pLogItem = new LOGENTRYDATA;
837 pLogItem->bCopies = !!copies;
839 // find out if this item was copied in the revision
840 BOOL copiedself = FALSE;
841 if (copies)
843 for (INT_PTR cpPathIndex = 0; cpPathIndex < cpaths->GetCount(); ++cpPathIndex)
845 LogChangedPath * cpath = cpaths->GetAt(cpPathIndex);
846 if (!cpath->sCopyFromPath.IsEmpty() && (cpath->sPath.Compare(m_sSelfRelativeURL) == 0))
848 // note: this only works if the log is fetched top-to-bottom
849 // but since we do that, it shouldn't be a problem
850 m_sSelfRelativeURL = cpath->sCopyFromPath;
851 copiedself = TRUE;
852 break;
856 pLogItem->bCopiedSelf = copiedself;
857 pLogItem->tmDate = ttime;
858 pLogItem->sAuthor = author;
859 pLogItem->sDate = date;
860 pLogItem->sShortMessage = MakeShortMessage(message);
861 pLogItem->dwFileChanges = filechanges;
862 pLogItem->actions = actions;
863 pLogItem->haschildren = haschildren;
864 pLogItem->childStackDepth = m_childCounter;
865 m_maxChild = max(m_childCounter, m_maxChild);
866 if (haschildren)
867 m_childCounter++;
868 pLogItem->sBugIDs = m_ProjectProperties.FindBugID(message).Trim();
870 // split multi line log entries and concatenate them
871 // again but this time with \r\n as line separators
872 // so that the edit control recognizes them
875 if (message.GetLength()>0)
877 m_sMessageBuf = message;
878 m_sMessageBuf.Replace(_T("\n\r"), _T("\n"));
879 m_sMessageBuf.Replace(_T("\r\n"), _T("\n"));
880 if (m_sMessageBuf.Right(1).Compare(_T("\n"))==0)
881 m_sMessageBuf = m_sMessageBuf.Left(m_sMessageBuf.GetLength()-1);
883 else
884 m_sMessageBuf.Empty();
885 pLogItem->sMessage = m_sMessageBuf;
886 pLogItem->Rev = rev;
888 // move-construct path array
890 pLogItem->pArChangedPaths = new LogChangedPathArray (*cpaths);
891 cpaths->RemoveAll();
893 catch (CException * e)
895 ::MessageBox(NULL, _T("not enough memory!"), _T("TortoiseGit"), MB_ICONERROR);
896 e->Delete();
897 m_bCancelled = TRUE;
899 m_logEntries.push_back(pLogItem);
900 m_arShownList.Add(pLogItem);
901 #endif
902 return TRUE;
905 GitRev g_rev;
906 //this is the thread function which calls the subversion function
911 void CLogDlg::CopyChangedSelectionToClipBoard()
913 #if 0
914 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
915 if (pos == NULL)
916 return; // nothing is selected, get out of here
918 CString sPaths;
920 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
921 if (pos)
923 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
924 while (pos)
926 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
927 sPaths += m_currentChangedPathList[nItem].GetGitPathString();
928 sPaths += _T("\r\n");
931 else
933 // only one revision is selected in the log dialog top pane
934 // but multiple items could be selected in the changed items list
935 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
936 while (pos)
938 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
939 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->GetAt(nItem);
941 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
943 // some items are hidden! So find out which item the user really selected
944 INT_PTR selRealIndex = -1;
945 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
947 if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
948 selRealIndex++;
949 if (selRealIndex == nItem)
951 changedlogpath = pLogEntry->pArChangedPaths->GetAt(hiddenindex);
952 break;
956 if (changedlogpath)
958 sPaths += changedlogpath->sPath;
959 sPaths += _T("\r\n");
963 sPaths.Trim();
964 CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());
965 #endif
968 BOOL CLogDlg::IsDiffPossible(LogChangedPath * changedpath, git_revnum_t rev)
970 #if 0
971 CString added, deleted;
972 if (changedpath == NULL)
973 return false;
975 if ((rev > 1)&&(changedpath->action != LOGACTIONS_DELETED))
977 if (changedpath->action == LOGACTIONS_ADDED) // file is added
979 if (changedpath->lCopyFromRev == 0)
980 return FALSE; // but file was not added with history
982 return TRUE;
984 #endif
985 return FALSE;
988 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)
990 // we have two separate context menus:
991 // one shown on the log message list control,
992 // the other shown in the changed-files list control
993 int selCount = m_LogList.GetSelectedCount();
994 if (pWnd == &m_LogList)
996 //ShowContextMenuForRevisions(pWnd, point);
998 else if (pWnd == &m_ChangedFileListCtrl)
1000 //ShowContextMenuForChangedpaths(pWnd, point);
1002 else if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))
1004 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1005 int selIndex = -1;
1006 if (pos)
1007 selIndex = m_LogList.GetNextSelectedItem(pos);
1008 if ((point.x == -1) && (point.y == -1))
1010 CRect rect;
1011 GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);
1012 ClientToScreen(&rect);
1013 point = rect.CenterPoint();
1015 CString sMenuItemText;
1016 CMenu popup;
1017 if (popup.CreatePopupMenu())
1019 // add the 'default' entries
1020 sMenuItemText.LoadString(IDS_SCIEDIT_COPY);
1021 popup.AppendMenu(MF_STRING | MF_ENABLED, WM_COPY, sMenuItemText);
1022 sMenuItemText.LoadString(IDS_SCIEDIT_SELECTALL);
1023 popup.AppendMenu(MF_STRING | MF_ENABLED, EM_SETSEL, sMenuItemText);
1025 //if (selIndex >= 0)
1027 // popup.AppendMenu(MF_SEPARATOR);
1028 // sMenuItemText.LoadString(IDS_LOG_POPUP_EDITLOG);
1029 // popup.AppendMenu(MF_STRING | MF_ENABLED, CGitLogList::ID_EDITAUTHOR, sMenuItemText);
1032 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1033 switch (cmd)
1035 case 0:
1036 break; // no command selected
1037 case EM_SETSEL:
1038 case WM_COPY:
1039 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);
1040 break;
1041 case CGitLogList::ID_EDITAUTHOR:
1042 EditLogMessage(selIndex);
1043 break;
1050 LRESULT CLogDlg::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
1052 #if 0
1053 ASSERT(m_pFindDialog != NULL);
1055 if (m_pFindDialog->IsTerminating())
1057 // invalidate the handle identifying the dialog box.
1058 m_pFindDialog = NULL;
1059 return 0;
1062 if(m_pFindDialog->FindNext())
1064 //read data from dialog
1065 CString FindText = m_pFindDialog->GetFindString();
1066 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
1067 bool bFound = false;
1068 tr1::wregex pat;
1069 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
1071 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;
1073 int i;
1074 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)
1076 if (bRegex)
1078 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));
1080 if (regex_search(wstring((LPCTSTR)pLogEntry->sMessage), pat, flags))
1082 bFound = true;
1083 break;
1085 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1086 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
1088 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
1089 if (regex_search(wstring((LPCTSTR)cpath->sCopyFromPath), pat, flags))
1091 bFound = true;
1092 --i;
1093 break;
1095 if (regex_search(wstring((LPCTSTR)cpath->sPath), pat, flags))
1097 bFound = true;
1098 --i;
1099 break;
1103 else
1105 if (bMatchCase)
1107 if (m_logEntries[i]->sMessage.Find(FindText) >= 0)
1109 bFound = true;
1110 break;
1112 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));
1113 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1114 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
1116 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
1117 if (cpath->sCopyFromPath.Find(FindText)>=0)
1119 bFound = true;
1120 --i;
1121 break;
1123 if (cpath->sPath.Find(FindText)>=0)
1125 bFound = true;
1126 --i;
1127 break;
1131 else
1133 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));
1134 CString msg = pLogEntry->sMessage;
1135 msg = msg.MakeLower();
1136 CString find = FindText.MakeLower();
1137 if (msg.Find(find) >= 0)
1139 bFound = TRUE;
1140 break;
1142 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1143 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
1145 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
1146 CString lowerpath = cpath->sCopyFromPath;
1147 lowerpath.MakeLower();
1148 if (lowerpath.Find(find)>=0)
1150 bFound = TRUE;
1151 --i;
1152 break;
1154 lowerpath = cpath->sPath;
1155 lowerpath.MakeLower();
1156 if (lowerpath.Find(find)>=0)
1158 bFound = TRUE;
1159 --i;
1160 break;
1165 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
1166 if (bFound)
1168 this->m_nSearchIndex = (i+1);
1169 m_LogList.EnsureVisible(i, FALSE);
1170 m_LogList.SetItemState(m_LogList.GetSelectionMark(), 0, LVIS_SELECTED);
1171 m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1172 m_LogList.SetSelectionMark(i);
1173 FillLogMessageCtrl();
1174 UpdateData(FALSE);
1175 m_nSearchIndex++;
1176 if (m_nSearchIndex >= m_arShownList.GetCount())
1177 m_nSearchIndex = (int)m_arShownList.GetCount()-1;
1179 } // if(m_pFindDialog->FindNext())
1180 UpdateLogInfoLabel();
1181 #endif
1182 return 0;
1185 void CLogDlg::OnOK()
1187 #if 0
1188 // since the log dialog is also used to select revisions for other
1189 // dialogs, we have to do some work before closing this dialog
1190 if (GetFocus() != GetDlgItem(IDOK))
1191 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter
1192 if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))
1193 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.
1195 CString temp;
1196 CString buttontext;
1197 GetDlgItemText(IDOK, buttontext);
1198 temp.LoadString(IDS_MSGBOX_CANCEL);
1199 if (temp.Compare(buttontext) != 0)
1200 __super::OnOK(); // only exit if the button text matches, and that will match only if the thread isn't running anymore
1201 m_bCancelled = TRUE;
1202 m_selectedRevs.Clear();
1203 m_selectedRevsOneRange.Clear();
1204 if (m_pNotifyWindow)
1206 int selIndex = m_LogList.GetSelectionMark();
1207 if (selIndex >= 0)
1209 PLOGENTRYDATA pLogEntry = NULL;
1210 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1211 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
1212 m_selectedRevs.AddRevision(pLogEntry->Rev);
1213 git_revnum_t lowerRev = pLogEntry->Rev;
1214 git_revnum_t higherRev = lowerRev;
1215 while (pos)
1217 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
1218 git_revnum_t rev = pLogEntry->Rev;
1219 m_selectedRevs.AddRevision(pLogEntry->Rev);
1220 if (lowerRev > rev)
1221 lowerRev = rev;
1222 if (higherRev < rev)
1223 higherRev = rev;
1225 if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())
1227 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);
1229 BOOL bSentMessage = FALSE;
1230 if (m_LogList.GetSelectedCount() == 1)
1232 // if only one revision is selected, check if the path/url with which the dialog was started
1233 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.
1234 // if it was copied, use the copy from revision as lowerRev
1235 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))
1237 CString sUrl = m_path.GetGitPathString();
1238 if (!m_path.IsUrl())
1240 sUrl = GetURLFromPath(m_path);
1242 sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());
1243 for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)
1245 LogChangedPath * pData = pLogEntry->pArChangedPaths->GetAt(cp);
1246 if (pData)
1248 if (sUrl.Compare(pData->sPath) == 0)
1250 if (!pData->sCopyFromPath.IsEmpty())
1252 lowerRev = pData->lCopyFromRev;
1253 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);
1254 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);
1255 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1256 bSentMessage = TRUE;
1263 if ( !bSentMessage )
1265 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);
1266 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);
1267 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1268 if (m_selectedRevsOneRange.GetCount())
1269 m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);
1273 UpdateData();
1274 if (m_bSaveStrict)
1275 m_regLastStrict = m_bStrict;
1276 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry"));
1277 reg = m_btnShow.GetCurrentEntry();
1278 SaveSplitterPos();
1279 #endif
1282 void CLogDlg::OnNMDblclkChangedFileList(NMHDR * /*pNMHDR*/, LRESULT *pResult)
1284 // a double click on an entry in the changed-files list has happened
1285 *pResult = 0;
1287 DiffSelectedFile();
1290 void CLogDlg::DiffSelectedFile()
1292 #if 0
1293 if (m_bThreadRunning)
1294 return;
1295 UpdateLogInfoLabel();
1296 INT_PTR selIndex = m_ChangedFileListCtrl.GetSelectionMark();
1297 if (selIndex < 0)
1298 return;
1299 if (m_ChangedFileListCtrl.GetSelectedCount() == 0)
1300 return;
1301 // find out if there's an entry selected in the log list
1302 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1303 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
1304 git_revnum_t rev1 = pLogEntry->Rev;
1305 git_revnum_t rev2 = rev1;
1306 if (pos)
1308 while (pos)
1310 // there's at least a second entry selected in the log list: several revisions selected!
1311 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
1312 if (pLogEntry)
1314 rev1 = max(rev1,(long)pLogEntry->Rev);
1315 rev2 = min(rev2,(long)pLogEntry->Rev);
1318 rev2--;
1319 // now we have both revisions selected in the log list, so we can do a diff of the selected
1320 // entry in the changed files list with these two revisions.
1321 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1323 else
1325 rev2 = rev1-1;
1326 // nothing or only one revision selected in the log list
1327 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);
1329 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
1331 // some items are hidden! So find out which item the user really clicked on
1332 INT_PTR selRealIndex = -1;
1333 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
1335 if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1336 selRealIndex++;
1337 if (selRealIndex == selIndex)
1339 selIndex = hiddenindex;
1340 changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);
1341 break;
1346 if (IsDiffPossible(changedpath, rev1))
1348 // diffs with renamed files are possible
1349 if ((changedpath)&&(!changedpath->sCopyFromPath.IsEmpty()))
1350 rev2 = changedpath->lCopyFromRev;
1351 else
1353 // if the path was modified but the parent path was 'added with history'
1354 // then we have to use the copy from revision of the parent path
1355 CTGitPath cpath = CTGitPath(changedpath->sPath);
1356 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
1358 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->GetAt(flist)->sPath);
1359 if (p.IsAncestorOf(cpath))
1361 if (!pLogEntry->pArChangedPaths->GetAt(flist)->sCopyFromPath.IsEmpty())
1362 rev2 = pLogEntry->pArChangedPaths->GetAt(flist)->lCopyFromRev;
1366 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1368 else
1370 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1371 CTGitPath tempfile2 = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1372 GitRev r = rev1;
1373 // deleted files must be opened from the revision before the deletion
1374 if (changedpath->action == LOGACTIONS_DELETED)
1375 r = rev1-1;
1376 m_bCancelled = false;
1378 CProgressDlg progDlg;
1379 progDlg.SetTitle(IDS_APPNAME);
1380 progDlg.SetAnimation(IDR_DOWNLOAD);
1381 CString sInfoLine;
1382 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)(m_sRepositoryRoot + changedpath->sPath), (LPCTSTR)r.ToString());
1383 progDlg.SetLine(1, sInfoLine, true);
1384 SetAndClearProgressInfo(&progDlg);
1385 progDlg.ShowModeless(m_hWnd);
1387 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), r, r, tempfile))
1389 m_bCancelled = false;
1390 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), GitRev::REV_HEAD, r, tempfile))
1392 progDlg.Stop();
1393 SetAndClearProgressInfo((HWND)NULL);
1394 CMessageBox::Show(m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1395 return;
1398 progDlg.Stop();
1399 SetAndClearProgressInfo((HWND)NULL);
1401 CString sName1, sName2;
1402 sName1.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1);
1403 sName2.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1-1);
1404 CAppUtils::DiffFlags flags;
1405 flags.AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1406 if (changedpath->action == LOGACTIONS_DELETED)
1407 CAppUtils::StartExtDiff(tempfile, tempfile2, sName2, sName1, flags);
1408 else
1409 CAppUtils::StartExtDiff(tempfile2, tempfile, sName2, sName1, flags);
1412 #endif
1416 void CLogDlg::DoDiffFromLog(INT_PTR selIndex, GitRev* rev1, GitRev* rev2, bool blame, bool unified)
1418 DialogEnableWindow(IDOK, FALSE);
1419 // SetPromptApp(&theApp);
1420 theApp.DoWaitCursor(1);
1422 CString temppath;
1423 GetTempPath(temppath);
1425 CString file1;
1426 file1.Format(_T("%s%s_%s%s"),
1427 temppath,
1428 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1429 rev1->m_CommitHash.Left(6),
1430 (*m_currentChangedArray)[selIndex].GetFileExtension());
1432 CString file2;
1433 file2.Format(_T("%s\\%s_%s%s"),
1434 temppath,
1435 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1436 rev2->m_CommitHash.Left(6),
1437 (*m_currentChangedArray)[selIndex].GetFileExtension());
1439 CString cmd;
1441 cmd.Format(_T("git.exe cat-file -p %s:%s"),rev1->m_CommitHash,(*m_currentChangedArray)[selIndex].GetGitPathString());
1442 g_Git.RunLogFile(cmd,file1);
1443 cmd.Format(_T("git.exe cat-file -p %s:%s"),rev2->m_CommitHash,(*m_currentChangedArray)[selIndex].GetGitPathString());
1444 g_Git.RunLogFile(cmd,file2);
1446 CAppUtils::DiffFlags flags;
1447 CAppUtils::StartExtDiff(file1,file2,_T("A"),_T("B"),flags);
1449 #if 0
1450 //get the filename
1451 CString filepath;
1452 if (Git::PathIsURL(m_path))
1454 filepath = m_path.GetGitPathString();
1456 else
1458 filepath = GetURLFromPath(m_path);
1459 if (filepath.IsEmpty())
1461 theApp.DoWaitCursor(-1);
1462 CString temp;
1463 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1464 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1465 TRACE(_T("could not retrieve the URL of the file!\n"));
1466 EnableOKButton();
1467 theApp.DoWaitCursor(-11);
1468 return; //exit
1471 m_bCancelled = FALSE;
1472 filepath = GetRepositoryRoot(CTGitPath(filepath));
1474 CString firstfile, secondfile;
1475 if (m_LogList.GetSelectedCount()==1)
1477 int s = m_LogList.GetSelectionMark();
1478 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(s));
1479 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);
1480 firstfile = changedpath->sPath;
1481 secondfile = firstfile;
1482 if ((rev2 == rev1-1)&&(changedpath->lCopyFromRev > 0)) // is it an added file with history?
1484 secondfile = changedpath->sCopyFromPath;
1485 rev2 = changedpath->lCopyFromRev;
1488 else
1490 firstfile = m_currentChangedPathList[selIndex].GetGitPathString();
1491 secondfile = firstfile;
1494 firstfile = filepath + firstfile.Trim();
1495 secondfile = filepath + secondfile.Trim();
1497 GitDiff diff(this, this->m_hWnd, true);
1498 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1499 diff.SetHEADPeg(m_LogRevision);
1500 if (unified)
1502 if (PromptShown())
1503 diff.ShowUnifiedDiff(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1);
1504 else
1505 CAppUtils::StartShowUnifiedDiff(m_hWnd, CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), m_LogRevision);
1507 else
1509 if (diff.ShowCompare(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), false, blame))
1511 if (firstfile.Compare(secondfile)==0)
1513 git_revnum_t baseRev = 0;
1514 diff.DiffProps(CTGitPath(firstfile), rev2, rev1, baseRev);
1519 #endif
1521 theApp.DoWaitCursor(-1);
1522 EnableOKButton();
1525 BOOL CLogDlg::Open(bool bOpenWith,CString changedpath, git_revnum_t rev)
1527 #if 0
1528 DialogEnableWindow(IDOK, FALSE);
1529 SetPromptApp(&theApp);
1530 theApp.DoWaitCursor(1);
1531 CString filepath;
1532 if (Git::PathIsURL(m_path))
1534 filepath = m_path.GetGitPathString();
1536 else
1538 filepath = GetURLFromPath(m_path);
1539 if (filepath.IsEmpty())
1541 theApp.DoWaitCursor(-1);
1542 CString temp;
1543 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1544 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1545 TRACE(_T("could not retrieve the URL of the file!\n"));
1546 EnableOKButton();
1547 return FALSE;
1550 m_bCancelled = false;
1551 filepath = GetRepositoryRoot(CTGitPath(filepath));
1552 filepath += changedpath;
1554 CProgressDlg progDlg;
1555 progDlg.SetTitle(IDS_APPNAME);
1556 progDlg.SetAnimation(IDR_DOWNLOAD);
1557 CString sInfoLine;
1558 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)GitRev(rev).ToString());
1559 progDlg.SetLine(1, sInfoLine, true);
1560 SetAndClearProgressInfo(&progDlg);
1561 progDlg.ShowModeless(m_hWnd);
1563 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(filepath), rev);
1564 m_bCancelled = false;
1565 if (!Cat(CTGitPath(filepath), GitRev(rev), rev, tempfile))
1567 progDlg.Stop();
1568 SetAndClearProgressInfo((HWND)NULL);
1569 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1570 EnableOKButton();
1571 theApp.DoWaitCursor(-1);
1572 return FALSE;
1574 progDlg.Stop();
1575 SetAndClearProgressInfo((HWND)NULL);
1576 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1577 if (!bOpenWith)
1579 int ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1580 if (ret <= HINSTANCE_ERROR)
1581 bOpenWith = true;
1583 if (bOpenWith)
1585 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1586 cmd += tempfile.GetWinPathString() + _T(" ");
1587 CAppUtils::LaunchApplication(cmd, NULL, false);
1589 EnableOKButton();
1590 theApp.DoWaitCursor(-1);
1591 #endif
1592 return TRUE;
1595 void CLogDlg::EditAuthor(const CLogDataVector& logs)
1597 #if 0
1598 CString url;
1599 CString name;
1600 if (logs.size() == 0)
1601 return;
1602 DialogEnableWindow(IDOK, FALSE);
1603 SetPromptApp(&theApp);
1604 theApp.DoWaitCursor(1);
1605 if (Git::PathIsURL(m_path))
1606 url = m_path.GetGitPathString();
1607 else
1609 url = GetURLFromPath(m_path);
1611 name = Git_PROP_REVISION_AUTHOR;
1613 CString value = RevPropertyGet(name, CTGitPath(url), logs[0]->Rev);
1614 CString sOldValue = value;
1615 value.Replace(_T("\n"), _T("\r\n"));
1616 CInputDlg dlg(this);
1617 dlg.m_sHintText.LoadString(IDS_LOG_AUTHOR);
1618 dlg.m_sInputText = value;
1619 dlg.m_sTitle.LoadString(IDS_LOG_AUTHOREDITTITLE);
1620 dlg.m_pProjectProperties = &m_ProjectProperties;
1621 dlg.m_bUseLogWidth = false;
1622 if (dlg.DoModal() == IDOK)
1624 dlg.m_sInputText.Replace(_T("\r"), _T(""));
1626 LogCache::CCachedLogInfo* toUpdate
1627 = GetLogCache (CTGitPath (m_sRepositoryRoot));
1629 CProgressDlg progDlg;
1630 progDlg.SetTitle(IDS_APPNAME);
1631 progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));
1632 progDlg.SetTime(true);
1633 progDlg.SetShowProgressBar(true);
1634 progDlg.ShowModeless(m_hWnd);
1635 for (DWORD i=0; i<logs.size(); ++i)
1637 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), logs[i]->Rev))
1639 progDlg.Stop();
1640 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1641 break;
1643 else
1646 logs[i]->sAuthor = dlg.m_sInputText;
1647 m_LogList.Invalidate();
1649 // update the log cache
1651 if (toUpdate != NULL)
1653 // log caching is active
1655 LogCache::CCachedLogInfo newInfo;
1656 newInfo.Insert ( logs[i]->Rev
1657 , (const char*) CUnicodeUtils::GetUTF8 (logs[i]->sAuthor)
1658 , ""
1660 , LogCache::CRevisionInfoContainer::HAS_AUTHOR);
1662 toUpdate->Update (newInfo);
1665 progDlg.SetProgress64(i, logs.size());
1667 progDlg.Stop();
1669 theApp.DoWaitCursor(-1);
1670 EnableOKButton();
1671 #endif
1674 void CLogDlg::EditLogMessage(int index)
1676 #if 0
1677 CString url;
1678 CString name;
1679 DialogEnableWindow(IDOK, FALSE);
1680 SetPromptApp(&theApp);
1681 theApp.DoWaitCursor(1);
1682 if (Git::PathIsURL(m_path))
1683 url = m_path.GetGitPathString();
1684 else
1686 url = GetURLFromPath(m_path);
1688 name = Git_PROP_REVISION_LOG;
1690 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(index));
1691 m_bCancelled = FALSE;
1692 CString value = RevPropertyGet(name, CTGitPath(url), pLogEntry->Rev);
1693 CString sOldValue = value;
1694 value.Replace(_T("\n"), _T("\r\n"));
1695 CInputDlg dlg(this);
1696 dlg.m_sHintText.LoadString(IDS_LOG_MESSAGE);
1697 dlg.m_sInputText = value;
1698 dlg.m_sTitle.LoadString(IDS_LOG_MESSAGEEDITTITLE);
1699 dlg.m_pProjectProperties = &m_ProjectProperties;
1700 dlg.m_bUseLogWidth = true;
1701 if (dlg.DoModal() == IDOK)
1703 dlg.m_sInputText.Replace(_T("\r"), _T(""));
1704 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), pLogEntry->Rev))
1706 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1708 else
1710 pLogEntry->sShortMessage = MakeShortMessage(dlg.m_sInputText);
1711 // split multi line log entries and concatenate them
1712 // again but this time with \r\n as line separators
1713 // so that the edit control recognizes them
1714 if (dlg.m_sInputText.GetLength()>0)
1716 m_sMessageBuf = dlg.m_sInputText;
1717 dlg.m_sInputText.Replace(_T("\n\r"), _T("\n"));
1718 dlg.m_sInputText.Replace(_T("\r\n"), _T("\n"));
1719 if (dlg.m_sInputText.Right(1).Compare(_T("\n"))==0)
1720 dlg.m_sInputText = dlg.m_sInputText.Left(dlg.m_sInputText.GetLength()-1);
1722 else
1723 dlg.m_sInputText.Empty();
1724 pLogEntry->sMessage = dlg.m_sInputText;
1725 pLogEntry->sBugIDs = m_ProjectProperties.FindBugID(dlg.m_sInputText);
1726 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
1727 pMsgView->SetWindowText(_T(" "));
1728 pMsgView->SetWindowText(dlg.m_sInputText);
1729 m_ProjectProperties.FindBugID(dlg.m_sInputText, pMsgView);
1730 m_LogList.Invalidate();
1732 // update the log cache
1734 LogCache::CCachedLogInfo* toUpdate
1735 = GetLogCache (CTGitPath (m_sRepositoryRoot));
1736 if (toUpdate != NULL)
1738 // log caching is active
1740 LogCache::CCachedLogInfo newInfo;
1741 newInfo.Insert ( pLogEntry->Rev
1742 , ""
1743 , (const char*) CUnicodeUtils::GetUTF8 (pLogEntry->sMessage)
1745 , LogCache::CRevisionInfoContainer::HAS_COMMENT);
1747 toUpdate->Update (newInfo);
1751 theApp.DoWaitCursor(-1);
1752 EnableOKButton();
1753 #endif
1755 #if 0
1756 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)
1758 // Skip Ctrl-C when copying text out of the log message or search filter
1759 BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );
1760 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
1762 if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1764 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1766 DiffSelectedRevWithPrevious();
1767 return TRUE;
1770 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
1772 DiffSelectedFile();
1773 return TRUE;
1776 if (m_hAccel && !bSkipAccelerator)
1778 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1779 if (ret)
1780 return TRUE;
1783 m_tooltips.RelayEvent(pMsg);
1784 return __super::PreTranslateMessage(pMsg);
1786 #endif
1788 BOOL CLogDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1790 //if (this->IsThreadRunning())
1791 if(m_LogList.m_bNoDispUpdates)
1793 // only show the wait cursor over the list control
1794 if ((pWnd)&&
1795 ((pWnd == GetDlgItem(IDC_LOGLIST))||
1796 (pWnd == GetDlgItem(IDC_MSGVIEW))||
1797 (pWnd == GetDlgItem(IDC_LOGMSG))))
1799 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1800 SetCursor(hCur);
1801 return TRUE;
1804 if ((pWnd) && (pWnd == GetDlgItem(IDC_MSGVIEW)))
1805 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1807 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1808 SetCursor(hCur);
1809 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1812 void CLogDlg::OnBnClickedHelp()
1814 OnHelp();
1817 void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1819 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1820 *pResult = 0;
1821 //if (this->IsThreadRunning())
1822 if(m_LogList.m_bNoDispUpdates)
1823 return;
1824 if (pNMLV->iItem >= 0)
1826 m_nSearchIndex = pNMLV->iItem;
1827 if (pNMLV->iSubItem != 0)
1828 return;
1829 if ((pNMLV->iItem == m_LogList.m_arShownList.GetCount())&&(m_bStrict)&&(1/*m_bStrictStopped*/))
1831 // remove the selected state
1832 if (pNMLV->uChanged & LVIF_STATE)
1834 m_LogList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);
1835 FillLogMessageCtrl();
1836 UpdateData(FALSE);
1837 UpdateLogInfoLabel();
1839 return;
1841 if (pNMLV->uChanged & LVIF_STATE)
1843 FillLogMessageCtrl();
1844 UpdateData(FALSE);
1847 else
1849 FillLogMessageCtrl();
1850 UpdateData(FALSE);
1852 EnableOKButton();
1853 UpdateLogInfoLabel();
1856 void CLogDlg::OnEnLinkMsgview(NMHDR *pNMHDR, LRESULT *pResult)
1858 ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);
1859 if (pEnLink->msg == WM_LBUTTONUP)
1861 CString url, msg;
1862 GetDlgItemText(IDC_MSGVIEW, msg);
1863 msg.Replace(_T("\r\n"), _T("\n"));
1864 url = msg.Mid(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax-pEnLink->chrg.cpMin);
1865 if (!::PathIsURL(url))
1867 url = m_ProjectProperties.GetBugIDUrl(url);
1868 url = GetAbsoluteUrlFromRelativeUrl(url);
1870 if (!url.IsEmpty())
1871 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
1873 *pResult = 0;
1876 void CLogDlg::OnBnClickedStatbutton()
1879 if (this->IsThreadRunning())
1880 return;
1881 if (m_LogList.m_arShownList.IsEmpty())
1882 return; // nothing is shown, so no statistics.
1883 // the statistics dialog expects the log entries to be sorted by date
1884 SortByColumn(3, false);
1885 CPtrArray shownlist;
1886 m_LogList.RecalculateShownList(&shownlist);
1887 // create arrays which are aware of the current filter
1888 CStringArray m_arAuthorsFiltered;
1889 CDWordArray m_arDatesFiltered;
1890 CDWordArray m_arFileChangesFiltered;
1891 for (INT_PTR i=0; i<shownlist.GetCount(); ++i)
1893 GitRev* pLogEntry = reinterpret_cast<GitRev*>(shownlist.GetAt(i));
1894 CString strAuthor = pLogEntry->m_AuthorName;
1895 if ( strAuthor.IsEmpty() )
1897 strAuthor.LoadString(IDS_STATGRAPH_EMPTYAUTHOR);
1899 m_arAuthorsFiltered.Add(strAuthor);
1900 m_arDatesFiltered.Add(pLogEntry->m_AuthorDate.GetTime());
1901 m_arFileChangesFiltered.Add(pLogEntry->m_Files.GetCount());
1903 CStatGraphDlg dlg;
1904 dlg.m_parAuthors = &m_arAuthorsFiltered;
1905 dlg.m_parDates = &m_arDatesFiltered;
1906 dlg.m_parFileChanges = &m_arFileChangesFiltered;
1907 dlg.m_path = m_path;
1908 dlg.DoModal();
1909 // restore the previous sorting
1910 SortByColumn(m_nSortColumn, m_bAscending);
1911 OnTimer(LOGFILTER_TIMER);
1915 #if 0
1916 void CLogDlg::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1919 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1920 // Take the default processing unless we set this to something else below.
1921 *pResult = CDRF_DODEFAULT;
1923 if (m_bNoDispUpdates)
1924 return;
1926 switch (pLVCD->nmcd.dwDrawStage)
1928 case CDDS_PREPAINT:
1930 *pResult = CDRF_NOTIFYITEMDRAW;
1931 return;
1933 break;
1934 case CDDS_ITEMPREPAINT:
1936 // This is the prepaint stage for an item. Here's where we set the
1937 // item's text color.
1939 // Tell Windows to send draw notifications for each subitem.
1940 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1942 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1944 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1946 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);
1947 if (data)
1949 #if 0
1950 if (data->bCopiedSelf)
1952 // only change the background color if the item is not 'hot' (on vista with themes enabled)
1953 if (!theme.IsAppThemed() || !m_bVista || ((pLVCD->nmcd.uItemState & CDIS_HOT)==0))
1954 pLVCD->clrTextBk = GetSysColor(COLOR_MENU);
1957 if (data->bCopies)
1958 crText = m_Colors.GetColor(CColors::Modified);
1959 #endif
1960 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1961 // crText = GetSysColor(COLOR_GRAYTEXT);
1962 // if (data->Rev == m_wcRev)
1963 // {
1964 // SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1965 // We changed the font, so we're returning CDRF_NEWFONT. This
1966 // tells the control to recalculate the extent of the text.
1967 // *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1968 // }
1971 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1973 if (m_bStrictStopped)
1974 crText = GetSysColor(COLOR_GRAYTEXT);
1976 // Store the color back in the NMLVCUSTOMDRAW struct.
1977 pLVCD->clrText = crText;
1978 return;
1980 break;
1981 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1983 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1985 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1987 if (pLVCD->iSubItem == 1)
1989 *pResult = CDRF_DODEFAULT;
1991 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1992 return;
1994 int nIcons = 0;
1995 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1996 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1998 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec));
2000 // Get the selected state of the
2001 // item being drawn.
2002 LVITEM rItem;
2003 SecureZeroMemory(&rItem, sizeof(LVITEM));
2004 rItem.mask = LVIF_STATE;
2005 rItem.iItem = pLVCD->nmcd.dwItemSpec;
2006 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
2007 m_LogList.GetItem(&rItem);
2009 CRect rect;
2010 m_LogList.GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
2012 // Fill the background
2013 if (theme.IsAppThemed() && m_bVista)
2015 theme.Open(m_hWnd, L"Explorer");
2016 int state = LISS_NORMAL;
2017 if (rItem.state & LVIS_SELECTED)
2019 if (::GetFocus() == m_LogList.m_hWnd)
2020 state |= LISS_SELECTED;
2021 else
2022 state |= LISS_SELECTEDNOTFOCUS;
2024 else
2026 #if 0
2027 if (pLogEntry->bCopiedSelf)
2029 // unfortunately, the pLVCD->nmcd.uItemState does not contain valid
2030 // information at this drawing stage. But we can check the whether the
2031 // previous stage changed the background color of the item
2032 if (pLVCD->clrTextBk == GetSysColor(COLOR_MENU))
2034 HBRUSH brush;
2035 brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));
2036 if (brush)
2038 ::FillRect(pLVCD->nmcd.hdc, &rect, brush);
2039 ::DeleteObject(brush);
2043 #endif
2046 if (theme.IsBackgroundPartiallyTransparent(LVP_LISTDETAIL, state))
2047 theme.DrawParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
2049 theme.DrawBackground(pLVCD->nmcd.hdc, LVP_LISTDETAIL, state, &rect, NULL);
2051 else
2053 HBRUSH brush;
2054 if (rItem.state & LVIS_SELECTED)
2056 if (::GetFocus() == m_LogList.m_hWnd)
2057 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
2058 else
2059 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
2061 else
2063 //if (pLogEntry->bCopiedSelf)
2064 // brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));
2065 //else
2066 brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
2068 if (brush == NULL)
2069 return;
2071 ::FillRect(pLVCD->nmcd.hdc, &rect, brush);
2072 ::DeleteObject(brush);
2075 // Draw the icon(s) into the compatible DC
2076 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_MODIFIED)
2077 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
2078 nIcons++;
2080 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_ADDED)
2081 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
2082 nIcons++;
2084 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_DELETED)
2085 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
2086 nIcons++;
2088 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
2089 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
2090 nIcons++;
2091 *pResult = CDRF_SKIPDEFAULT;
2092 return;
2095 break;
2097 *pResult = CDRF_DODEFAULT;
2100 #endif
2102 void CLogDlg::OnNMCustomdrawChangedFileList(NMHDR *pNMHDR, LRESULT *pResult)
2105 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
2106 // Take the default processing unless we set this to something else below.
2107 *pResult = CDRF_DODEFAULT;
2109 // if (m_bNoDispUpdates)
2110 // return;
2112 // First thing - check the draw stage. If it's the control's prepaint
2113 // stage, then tell Windows we want messages for every item.
2115 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
2117 *pResult = CDRF_NOTIFYITEMDRAW;
2119 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
2121 // This is the prepaint stage for an item. Here's where we set the
2122 // item's text color. Our return value will tell Windows to draw the
2123 // item itself, but it will use the new color we set here.
2125 // Tell Windows to paint the control itself.
2126 *pResult = CDRF_DODEFAULT;
2128 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
2129 bool bGrayed = false;
2130 #if 0
2131 if ((m_cHidePaths.GetState() & 0x0003)==BST_INDETERMINATE)
2133 if ((m_currentChangedArray)&&((m_currentChangedArray->GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)))
2135 //if ((*m_currentChangedArray)[(pLVCD->nmcd.dwItemSpec)]sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)!=0)
2137 crText = GetSysColor(COLOR_GRAYTEXT);
2138 bGrayed = true;
2141 else if (m_currentChangedPathList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
2143 //if (m_currentChangedPathList[pLVCD->nmcd.dwItemSpec].GetGitPathString().Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)!=0)
2145 crText = GetSysColor(COLOR_GRAYTEXT);
2146 bGrayed = true;
2151 #endif
2152 if ((!bGrayed)&&(m_currentChangedArray)&&(m_currentChangedArray->GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec))
2154 DWORD action = ((*m_currentChangedArray)[pLVCD->nmcd.dwItemSpec]).m_Action;
2155 if (action == CTGitPath::LOGACTIONS_MODIFIED)
2156 crText = m_Colors.GetColor(CColors::Modified);
2157 if (action == CTGitPath::LOGACTIONS_REPLACED)
2158 crText = m_Colors.GetColor(CColors::Deleted);
2159 if (action == CTGitPath::LOGACTIONS_ADDED)
2160 crText = m_Colors.GetColor(CColors::Added);
2161 if (action == CTGitPath::LOGACTIONS_DELETED)
2162 crText = m_Colors.GetColor(CColors::Deleted);
2165 // Store the color back in the NMLVCUSTOMDRAW struct.
2166 pLVCD->clrText = crText;
2170 void CLogDlg::DoSizeV1(int delta)
2173 RemoveAnchor(IDC_LOGLIST);
2174 RemoveAnchor(IDC_SPLITTERTOP);
2175 RemoveAnchor(IDC_MSGVIEW);
2176 RemoveAnchor(IDC_SPLITTERBOTTOM);
2177 RemoveAnchor(IDC_LOGMSG);
2178 CSplitterControl::ChangeHeight(&m_LogList, delta, CW_TOPALIGN);
2179 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), -delta, CW_BOTTOMALIGN);
2180 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
2181 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
2182 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
2183 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
2184 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
2185 ArrangeLayout();
2186 AdjustMinSize();
2187 SetSplitterRange();
2188 m_LogList.Invalidate();
2189 GetDlgItem(IDC_MSGVIEW)->Invalidate();
2193 void CLogDlg::DoSizeV2(int delta)
2196 RemoveAnchor(IDC_LOGLIST);
2197 RemoveAnchor(IDC_SPLITTERTOP);
2198 RemoveAnchor(IDC_MSGVIEW);
2199 RemoveAnchor(IDC_SPLITTERBOTTOM);
2200 RemoveAnchor(IDC_LOGMSG);
2201 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), delta, CW_TOPALIGN);
2202 CSplitterControl::ChangeHeight(&m_ChangedFileListCtrl, -delta, CW_BOTTOMALIGN);
2203 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
2204 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
2205 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
2206 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
2207 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
2208 ArrangeLayout();
2209 AdjustMinSize();
2210 SetSplitterRange();
2211 GetDlgItem(IDC_MSGVIEW)->Invalidate();
2212 m_ChangedFileListCtrl.Invalidate();
2216 void CLogDlg::AdjustMinSize()
2218 // adjust the minimum size of the dialog to prevent the resizing from
2219 // moving the list control too far down.
2220 CRect rcChgListView;
2221 m_ChangedFileListCtrl.GetClientRect(rcChgListView);
2222 CRect rcLogList;
2223 m_LogList.GetClientRect(rcLogList);
2225 SetMinTrackSize(CSize(m_DlgOrigRect.Width(),
2226 m_DlgOrigRect.Height()-m_ChgOrigRect.Height()-m_LogListOrigRect.Height()-m_MsgViewOrigRect.Height()
2227 +rcChgListView.Height()+rcLogList.Height()+60));
2230 LRESULT CLogDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
2232 switch (message) {
2233 case WM_NOTIFY:
2234 if (wParam == IDC_SPLITTERTOP)
2236 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
2237 DoSizeV1(pHdr->delta);
2239 else if (wParam == IDC_SPLITTERBOTTOM)
2241 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
2242 DoSizeV2(pHdr->delta);
2244 break;
2247 return CResizableDialog::DefWindowProc(message, wParam, lParam);
2250 void CLogDlg::SetSplitterRange()
2252 if ((m_LogList)&&(m_ChangedFileListCtrl))
2254 CRect rcTop;
2255 m_LogList.GetWindowRect(rcTop);
2256 ScreenToClient(rcTop);
2257 CRect rcMiddle;
2258 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(rcMiddle);
2259 ScreenToClient(rcMiddle);
2260 m_wndSplitter1.SetRange(rcTop.top+30, rcMiddle.bottom-20);
2261 CRect rcBottom;
2262 m_ChangedFileListCtrl.GetWindowRect(rcBottom);
2263 ScreenToClient(rcBottom);
2264 m_wndSplitter2.SetRange(rcMiddle.top+30, rcBottom.bottom-20);
2268 LRESULT CLogDlg::OnClickedInfoIcon(WPARAM /*wParam*/, LPARAM lParam)
2270 RECT * rect = (LPRECT)lParam;
2271 CPoint point;
2272 CString temp;
2273 point = CPoint(rect->left, rect->bottom);
2274 #define LOGMENUFLAGS(x) (MF_STRING | MF_ENABLED | (m_LogList.m_nSelectedFilter == x ? MF_CHECKED : MF_UNCHECKED))
2275 CMenu popup;
2276 if (popup.CreatePopupMenu())
2278 temp.LoadString(IDS_LOG_FILTER_ALL);
2279 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_ALL), LOGFILTER_ALL, temp);
2281 popup.AppendMenu(MF_SEPARATOR, NULL);
2283 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2284 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_MESSAGES), LOGFILTER_MESSAGES, temp);
2285 temp.LoadString(IDS_LOG_FILTER_PATHS);
2286 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_PATHS), LOGFILTER_PATHS, temp);
2287 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2288 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_AUTHORS), LOGFILTER_AUTHORS, temp);
2289 temp.LoadString(IDS_LOG_FILTER_REVS);
2290 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REVS), LOGFILTER_REVS, temp);
2291 temp.LoadString(IDS_LOG_FILTER_BUGIDS);
2292 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_BUGID), LOGFILTER_BUGID, temp);
2294 popup.AppendMenu(MF_SEPARATOR, NULL);
2296 temp.LoadString(IDS_LOG_FILTER_REGEX);
2297 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterWithRegex ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_REGEX, temp);
2299 m_tooltips.Pop();
2300 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2301 if (selection != 0)
2304 if (selection == LOGFILTER_REGEX)
2306 m_bFilterWithRegex = !m_bFilterWithRegex;
2307 CRegDWORD b = CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
2308 b = m_bFilterWithRegex;
2309 CheckRegexpTooltip();
2311 else
2313 m_LogList.m_nSelectedFilter = selection;
2314 SetFilterCueText();
2316 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2319 return 0L;
2322 LRESULT CLogDlg::OnClickedCancelFilter(WPARAM /*wParam*/, LPARAM /*lParam*/)
2325 KillTimer(LOGFILTER_TIMER);
2327 m_LogList.m_sFilterText.Empty();
2328 UpdateData(FALSE);
2329 theApp.DoWaitCursor(1);
2330 CStoreSelection storeselection(this);
2331 FillLogMessageCtrl(false);
2333 m_LogList.RemoveFilter();
2335 CTime begin,end;
2336 m_LogList.GetTimeRange(begin,end);
2337 m_DateFrom.SetTime(&begin);
2338 m_DateTo.SetTime(&end);
2340 theApp.DoWaitCursor(-1);
2341 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2342 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2343 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2344 UpdateLogInfoLabel();
2346 return 0L;
2350 void CLogDlg::SetFilterCueText()
2352 CString temp;
2353 switch (m_LogList.m_nSelectedFilter)
2355 case LOGFILTER_ALL:
2356 temp.LoadString(IDS_LOG_FILTER_ALL);
2357 break;
2358 case LOGFILTER_MESSAGES:
2359 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2360 break;
2361 case LOGFILTER_PATHS:
2362 temp.LoadString(IDS_LOG_FILTER_PATHS);
2363 break;
2364 case LOGFILTER_AUTHORS:
2365 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2366 break;
2367 case LOGFILTER_REVS:
2368 temp.LoadString(IDS_LOG_FILTER_REVS);
2369 break;
2371 // to make the cue banner text appear more to the right of the edit control
2372 temp = _T(" ")+temp;
2373 m_cFilter.SetCueBanner(temp);
2376 bool CLogDlg::Validate(LPCTSTR string)
2378 if (!m_bFilterWithRegex)
2379 return true;
2380 tr1::wregex pat;
2381 return m_LogList.ValidateRegexp(string, pat, false);
2385 void CLogDlg::OnTimer(UINT_PTR nIDEvent)
2387 if (nIDEvent == LOGFILTER_TIMER)
2389 if (this->IsThreadRunning())
2391 // thread still running! So just restart the timer.
2392 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2393 return;
2395 CWnd * focusWnd = GetFocus();
2396 bool bSetFocusToFilterControl = ((focusWnd != GetDlgItem(IDC_DATEFROM))&&(focusWnd != GetDlgItem(IDC_DATETO))
2397 && (focusWnd != GetDlgItem(IDC_LOGLIST)));
2398 if (m_LogList.m_sFilterText.IsEmpty())
2400 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2401 // do not return here!
2402 // we also need to run the filter if the filter text is empty:
2403 // 1. to clear an existing filter
2404 // 2. to rebuild the m_arShownList after sorting
2406 theApp.DoWaitCursor(1);
2407 CStoreSelection storeselection(this);
2408 KillTimer(LOGFILTER_TIMER);
2409 FillLogMessageCtrl(false);
2411 // now start filter the log list
2412 m_LogList.StartFilter();
2414 if ( m_LogList.GetItemCount()==1 )
2416 m_LogList.SetSelectionMark(0);
2417 m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
2419 theApp.DoWaitCursor(-1);
2420 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2421 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2422 if (bSetFocusToFilterControl)
2423 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2424 UpdateLogInfoLabel();
2425 } // if (nIDEvent == LOGFILTER_TIMER)
2426 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2427 __super::OnTimer(nIDEvent);
2430 void CLogDlg::OnDtnDatetimechangeDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2432 CTime _time;
2433 m_DateTo.GetTime(_time);
2436 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 23, 59, 59);
2437 if (time.GetTime() != m_LogList.m_To.GetTime())
2439 m_LogList.m_To = (DWORD)time.GetTime();
2440 SetTimer(LOGFILTER_TIMER, 10, NULL);
2443 catch (CAtlException)
2447 *pResult = 0;
2450 void CLogDlg::OnDtnDatetimechangeDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2452 CTime _time;
2453 m_DateFrom.GetTime(_time);
2456 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 0, 0, 0);
2457 if (time.GetTime() != m_LogList.m_From.GetTime())
2459 m_LogList.m_From = (DWORD)time.GetTime();
2460 SetTimer(LOGFILTER_TIMER, 10, NULL);
2463 catch (CAtlException)
2467 *pResult = 0;
2472 CTGitPathList CLogDlg::GetChangedPathsFromSelectedRevisions(bool bRelativePaths /* = false */, bool bUseFilter /* = true */)
2474 CTGitPathList pathList;
2475 #if 0
2477 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2479 m_sRepositoryRoot = GetRepositoryRoot(m_path);
2481 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2482 return pathList;
2484 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2485 if (pos != NULL)
2487 while (pos)
2489 int nextpos = m_LogList.GetNextSelectedItem(pos);
2490 if (nextpos >= m_arShownList.GetCount())
2491 continue;
2492 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(nextpos));
2493 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2494 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
2496 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
2497 if (cpath == NULL)
2498 continue;
2499 CTGitPath path;
2500 if (!bRelativePaths)
2501 path.SetFromGit(m_sRepositoryRoot);
2502 path.AppendPathString(cpath->sPath);
2503 if ((!bUseFilter)||
2504 ((m_cHidePaths.GetState() & 0x0003)!=BST_CHECKED)||
2505 (cpath->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0))
2506 pathList.AddPath(path);
2511 pathList.RemoveDuplicates();
2512 #endif
2513 return pathList;
2516 void CLogDlg::SortByColumn(int nSortColumn, bool bAscending)
2518 #if 0
2519 switch(nSortColumn)
2521 case 0: // Revision
2523 if(bAscending)
2524 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscRevSort());
2525 else
2526 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescRevSort());
2528 break;
2529 case 1: // action
2531 if(bAscending)
2532 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscActionSort());
2533 else
2534 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescActionSort());
2536 break;
2537 case 2: // Author
2539 if(bAscending)
2540 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscAuthorSort());
2541 else
2542 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescAuthorSort());
2544 break;
2545 case 3: // Date
2547 if(bAscending)
2548 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscDateSort());
2549 else
2550 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescDateSort());
2552 break;
2553 case 4: // Message or bug id
2554 if (m_bShowBugtraqColumn)
2556 if(bAscending)
2557 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscBugIDSort());
2558 else
2559 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescBugIDSort());
2560 break;
2562 // fall through here
2563 case 5: // Message
2565 if(bAscending)
2566 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscMessageSort());
2567 else
2568 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescMessageSort());
2570 break;
2571 default:
2572 ATLASSERT(0);
2573 break;
2575 #endif
2578 void CLogDlg::OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult)
2580 if (this->IsThreadRunning())
2581 return; //no sorting while the arrays are filled
2582 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2583 const int nColumn = pNMLV->iSubItem;
2584 m_bAscending = nColumn == m_nSortColumn ? !m_bAscending : TRUE;
2585 m_nSortColumn = nColumn;
2586 SortByColumn(m_nSortColumn, m_bAscending);
2587 SetSortArrow(&m_LogList, m_nSortColumn, !!m_bAscending);
2588 SortShownListArray();
2589 m_LogList.Invalidate();
2590 UpdateLogInfoLabel();
2591 // the "next 100" button only makes sense if the log messages
2592 // are sorted by revision in descending order
2593 if ((m_nSortColumn)||(m_bAscending))
2595 DialogEnableWindow(IDC_NEXTHUNDRED, false);
2597 else
2599 DialogEnableWindow(IDC_NEXTHUNDRED, true);
2601 *pResult = 0;
2604 void CLogDlg::SortShownListArray()
2606 // make sure the shown list still matches the filter after sorting.
2607 OnTimer(LOGFILTER_TIMER);
2608 // clear the selection states
2609 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2610 while (pos)
2612 m_LogList.SetItemState(m_LogList.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
2614 m_LogList.SetSelectionMark(-1);
2617 void CLogDlg::SetSortArrow(CListCtrl * control, int nColumn, bool bAscending)
2619 if (control == NULL)
2620 return;
2621 // set the sort arrow
2622 CHeaderCtrl * pHeader = control->GetHeaderCtrl();
2623 HDITEM HeaderItem = {0};
2624 HeaderItem.mask = HDI_FORMAT;
2625 for (int i=0; i<pHeader->GetItemCount(); ++i)
2627 pHeader->GetItem(i, &HeaderItem);
2628 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
2629 pHeader->SetItem(i, &HeaderItem);
2631 if (nColumn >= 0)
2633 pHeader->GetItem(nColumn, &HeaderItem);
2634 HeaderItem.fmt |= (bAscending ? HDF_SORTUP : HDF_SORTDOWN);
2635 pHeader->SetItem(nColumn, &HeaderItem);
2638 void CLogDlg::OnLvnColumnclickChangedFileList(NMHDR *pNMHDR, LRESULT *pResult)
2640 #if 0
2641 if (this->IsThreadRunning())
2642 return; //no sorting while the arrays are filled
2643 if (m_currentChangedArray == NULL)
2644 return;
2645 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2646 const int nColumn = pNMLV->iSubItem;
2647 m_bAscendingPathList = nColumn == m_nSortColumnPathList ? !m_bAscendingPathList : TRUE;
2648 m_nSortColumnPathList = nColumn;
2649 // qsort(m_currentChangedArray->GetData(), m_currentChangedArray->GetSize(), sizeof(LogChangedPath*), (GENERICCOMPAREFN)SortCompare);
2651 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
2652 m_ChangedFileListCtrl.Invalidate();
2653 *pResult = 0;
2654 #endif
2657 int CLogDlg::m_nSortColumnPathList = 0;
2658 bool CLogDlg::m_bAscendingPathList = false;
2660 int CLogDlg::SortCompare(const void * pElem1, const void * pElem2)
2662 #if 0
2663 LogChangedPath * cpath1 = *((LogChangedPath**)pElem1);
2664 LogChangedPath * cpath2 = *((LogChangedPath**)pElem2);
2666 if (m_bAscendingPathList)
2667 std::swap (cpath1, cpath2);
2669 int cmp = 0;
2670 switch (m_nSortColumnPathList)
2672 case 0: // action
2673 cmp = cpath2->GetAction().Compare(cpath1->GetAction());
2674 if (cmp)
2675 return cmp;
2676 // fall through
2677 case 1: // path
2678 cmp = cpath2->sPath.CompareNoCase(cpath1->sPath);
2679 if (cmp)
2680 return cmp;
2681 // fall through
2682 case 2: // copy from path
2683 cmp = cpath2->sCopyFromPath.Compare(cpath1->sCopyFromPath);
2684 if (cmp)
2685 return cmp;
2686 // fall through
2687 case 3: // copy from revision
2688 return cpath2->lCopyFromRev > cpath1->lCopyFromRev;
2690 #endif
2691 return 0;
2694 #if 0
2695 void CLogDlg::ResizeAllListCtrlCols()
2698 const int nMinimumWidth = ICONITEMBORDER+16*4;
2699 int maxcol = ((CHeaderCtrl*)(m_LogList.GetDlgItem(0)))->GetItemCount()-1;
2700 int nItemCount = m_LogList.GetItemCount();
2701 TCHAR textbuf[MAX_PATH];
2702 CHeaderCtrl * pHdrCtrl = (CHeaderCtrl*)(m_LogList.GetDlgItem(0));
2703 if (pHdrCtrl)
2705 for (int col = 0; col <= maxcol; col++)
2707 HDITEM hdi = {0};
2708 hdi.mask = HDI_TEXT;
2709 hdi.pszText = textbuf;
2710 hdi.cchTextMax = sizeof(textbuf);
2711 pHdrCtrl->GetItem(col, &hdi);
2712 int cx = m_LogList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
2713 for (int index = 0; index<nItemCount; ++index)
2715 // get the width of the string and add 14 pixels for the column separator and margins
2716 int linewidth = m_LogList.GetStringWidth(m_LogList.GetItemText(index, col)) + 14;
2717 if (index < m_arShownList.GetCount())
2719 GitRev * pCurLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(index));
2720 if ((pCurLogEntry)&&(pCurLogEntry->m_CommitHash == m_wcRev.m_CommitHash))
2722 // set the bold font and ask for the string width again
2723 m_LogList.SendMessage(WM_SETFONT, (WPARAM)m_boldFont, NULL);
2724 linewidth = m_LogList.GetStringWidth(m_LogList.GetItemText(index, col)) + 14;
2725 // restore the system font
2726 m_LogList.SendMessage(WM_SETFONT, NULL, NULL);
2729 if (index == 0)
2731 // add the image size
2732 CImageList * pImgList = m_LogList.GetImageList(LVSIL_SMALL);
2733 if ((pImgList)&&(pImgList->GetImageCount()))
2735 IMAGEINFO imginfo;
2736 pImgList->GetImageInfo(0, &imginfo);
2737 linewidth += (imginfo.rcImage.right - imginfo.rcImage.left);
2738 linewidth += 3; // 3 pixels between icon and text
2741 if (cx < linewidth)
2742 cx = linewidth;
2744 // Adjust columns "Actions" containing icons
2745 if (col == this->LOGLIST_ACTION)
2747 if (cx < nMinimumWidth)
2749 cx = nMinimumWidth;
2753 if (col == this->LOGLIST_MESSAGE)
2755 if (cx > LOGLIST_MESSAGE_MAX)
2757 cx = LOGLIST_MESSAGE_MAX;
2761 // keep the bug id column small
2762 if ((col == 4)&&(m_bShowBugtraqColumn))
2764 if (cx > (int)(DWORD)m_regMaxBugIDColWidth)
2766 cx = (int)(DWORD)m_regMaxBugIDColWidth;
2770 m_LogList.SetColumnWidth(col, cx);
2775 #endif
2777 void CLogDlg::OnBnClickedHidepaths()
2779 FillLogMessageCtrl();
2780 m_ChangedFileListCtrl.Invalidate();
2785 void CLogDlg::OnBnClickedCheckStoponcopy()
2787 #if 0
2788 if (!GetDlgItem(IDC_GETALL)->IsWindowEnabled())
2789 return;
2791 // ignore old fetch limits when switching
2792 // between copy-following and stop-on-copy
2793 // (otherwise stop-on-copy will limit what
2794 // we see immediately after switching to
2795 // copy-following)
2797 m_endrev = 0;
2799 // now, restart the query
2800 #endif
2801 Refresh();
2804 void CLogDlg::OnBnClickedIncludemerge()
2806 #if 0
2807 m_endrev = 0;
2809 m_limit = 0;
2810 #endif
2811 Refresh();
2814 void CLogDlg::UpdateLogInfoLabel()
2817 git_revnum_t rev1 ;
2818 git_revnum_t rev2 ;
2819 long selectedrevs ;
2820 int count =m_LogList.m_arShownList.GetCount();
2821 if (count)
2823 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.GetAt(0)))->m_CommitHash;
2824 //pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_arShownList.GetCount()-1));
2825 rev2 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.GetAt(count-1)))->m_CommitHash;
2826 selectedrevs = m_LogList.GetSelectedCount();
2828 CString sTemp;
2829 sTemp.Format(_T("Showing %ld revision(s), from revision %s to revision %s - %ld revision(s) selected"), count, rev2.Left(6), rev1.Left(6), selectedrevs);
2830 m_sLogInfo = sTemp;
2832 UpdateData(FALSE);
2835 #if 0
2836 void CLogDlg::ShowContextMenuForChangedpaths(CWnd* /*pWnd*/, CPoint point)
2839 int selIndex = m_ChangedFileListCtrl.GetSelectionMark();
2840 if ((point.x == -1) && (point.y == -1))
2842 CRect rect;
2843 m_ChangedFileListCtrl.GetItemRect(selIndex, &rect, LVIR_LABEL);
2844 m_ChangedFileListCtrl.ClientToScreen(&rect);
2845 point = rect.CenterPoint();
2847 if (selIndex < 0)
2848 return;
2849 int s = m_LogList.GetSelectionMark();
2850 if (s < 0)
2851 return;
2852 std::vector<CString> changedpaths;
2853 std::vector<LogChangedPath*> changedlogpaths;
2854 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2855 if (pos == NULL)
2856 return; // nothing is selected, get out of here
2858 bool bOneRev = true;
2859 int sel=m_LogList.GetNextSelectedItem(pos);
2860 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.GetAt(sel));
2861 GitRev * rev1 = pLogEntry;
2862 GitRev * rev2 = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.GetAt(sel+1));
2863 #if 0
2864 bool bOneRev = true;
2865 if (pos)
2867 while (pos)
2869 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
2870 if (pLogEntry)
2872 rev1 = max(rev1,(git_revnum_t)pLogEntry->Rev);
2873 rev2 = min(rev2,(git_revnum_t)pLogEntry->Rev);
2874 bOneRev = false;
2877 if (!bOneRev)
2878 rev2--;
2879 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
2880 while (pos)
2882 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
2883 changedpaths.push_back(m_currentChangedPathList[nItem].GetGitPathString());
2886 else
2888 // only one revision is selected in the log dialog top pane
2889 // but multiple items could be selected in the changed items list
2890 rev2 = rev1-1;
2892 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
2893 while (pos)
2895 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
2896 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->GetAt(nItem);
2898 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
2900 if ((changedlogpath)&&(!changedlogpath->sCopyFromPath.IsEmpty()))
2901 rev2 = changedlogpath->lCopyFromRev;
2902 else
2904 // if the path was modified but the parent path was 'added with history'
2905 // then we have to use the copy from revision of the parent path
2906 CTGitPath cpath = CTGitPath(changedlogpath->sPath);
2907 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
2909 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->GetAt(flist)->sPath);
2910 if (p.IsAncestorOf(cpath))
2912 if (!pLogEntry->pArChangedPaths->GetAt(flist)->sCopyFromPath.IsEmpty())
2913 rev2 = pLogEntry->pArChangedPaths->GetAt(flist)->lCopyFromRev;
2918 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
2920 // some items are hidden! So find out which item the user really clicked on
2921 INT_PTR selRealIndex = -1;
2922 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
2924 if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2925 selRealIndex++;
2926 if (selRealIndex == nItem)
2928 selIndex = hiddenindex;
2929 changedlogpath = pLogEntry->pArChangedPaths->GetAt(selIndex);
2930 break;
2934 if (changedlogpath)
2936 changedpaths.push_back(changedlogpath->sPath);
2937 changedlogpaths.push_back(changedlogpath);
2941 #endif
2942 //entry is selected, now show the popup menu
2943 CIconMenu popup;
2944 if (popup.CreatePopupMenu())
2946 bool bEntryAdded = false;
2947 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
2949 // if ((!bOneRev)||(IsDiffPossible(changedlogpaths[0], rev1)))
2951 popup.AppendMenuIcon(CGitLogList::ID_DIFF, IDS_LOG_POPUP_DIFF, IDI_DIFF);
2952 popup.AppendMenuIcon(CGitLogList::ID_BLAMEDIFF, IDS_LOG_POPUP_BLAMEDIFF, IDI_BLAME);
2953 popup.SetDefaultItem(CGitLogList::ID_DIFF, FALSE);
2954 popup.AppendMenuIcon(CGitLogList::ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
2955 bEntryAdded = true;
2957 // if (rev2 == rev1-1)
2959 if (bEntryAdded)
2960 popup.AppendMenu(MF_SEPARATOR, NULL);
2961 popup.AppendMenuIcon(CGitLogList::ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
2962 popup.AppendMenuIcon(CGitLogList::ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
2963 popup.AppendMenuIcon(CGitLogList::ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
2964 popup.AppendMenu(MF_SEPARATOR, NULL);
2965 if (m_hasWC)
2966 popup.AppendMenuIcon(CGitLogList::ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2967 popup.AppendMenuIcon(CGitLogList::ID_POPPROPS, IDS_REPOBROWSE_SHOWPROP, IDI_PROPERTIES); // "Show Properties"
2968 popup.AppendMenuIcon(CGitLogList::ID_LOG, IDS_MENULOG, IDI_LOG); // "Show Log"
2969 popup.AppendMenuIcon(CGitLogList::ID_GETMERGELOGS, IDS_LOG_POPUP_GETMERGELOGS, IDI_LOG); // "Show merge log"
2970 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
2971 bEntryAdded = true;
2972 if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2974 popup.AppendMenu(MF_SEPARATOR, NULL);
2975 popup.AppendMenuIcon(CGitLogList::ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2977 if (popup.GetDefaultItem(0,FALSE)==-1)
2978 popup.SetDefaultItem(CGitLogList::ID_OPEN, FALSE);
2981 else if (changedlogpaths.size())
2983 // more than one entry is selected
2984 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE);
2985 bEntryAdded = true;
2988 if (!bEntryAdded)
2989 return;
2990 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2991 bool bOpenWith = false;
2992 bool bMergeLog = false;
2993 m_bCancelled = false;
2995 switch (cmd)
2997 case CGitLogList::ID_DIFF:
2999 DoDiffFromLog(selIndex, rev1, rev2, false, false);
3001 break;
3002 #if 0
3003 case ID_BLAMEDIFF:
3005 DoDiffFromLog(selIndex, rev1, rev2, true, false);
3007 break;
3008 case ID_GNUDIFF1:
3010 DoDiffFromLog(selIndex, rev1, rev2, false, true);
3012 break;
3013 case ID_REVERTREV:
3015 SetPromptApp(&theApp);
3016 theApp.DoWaitCursor(1);
3017 CString sUrl;
3018 if (Git::PathIsURL(m_path))
3020 sUrl = m_path.GetGitPathString();
3022 else
3024 sUrl = GetURLFromPath(m_path);
3025 if (sUrl.IsEmpty())
3027 theApp.DoWaitCursor(-1);
3028 CString temp;
3029 temp.Format(IDS_ERR_NOURLOFFILE, m_path.GetWinPath());
3030 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3031 EnableOKButton();
3032 theApp.DoWaitCursor(-1);
3033 break; //exit
3036 // find the working copy path of the selected item from the URL
3037 m_bCancelled = false;
3038 CString sUrlRoot = GetRepositoryRoot(CTGitPath(sUrl));
3040 CString fileURL = changedpaths[0];
3041 fileURL = sUrlRoot + fileURL.Trim();
3042 // firstfile = (e.g.) http://mydomain.com/repos/trunk/folder/file1
3043 // sUrl = http://mydomain.com/repos/trunk/folder
3044 CString sUnescapedUrl = CPathUtils::PathUnescape(sUrl);
3045 // find out until which char the urls are identical
3046 int i=0;
3047 while ((i<fileURL.GetLength())&&(i<sUnescapedUrl.GetLength())&&(fileURL[i]==sUnescapedUrl[i]))
3048 i++;
3049 int leftcount = m_path.GetWinPathString().GetLength()-(sUnescapedUrl.GetLength()-i);
3050 CString wcPath = m_path.GetWinPathString().Left(leftcount);
3051 wcPath += fileURL.Mid(i);
3052 wcPath.Replace('/', '\\');
3053 CGitProgressDlg dlg;
3054 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
3056 // a deleted path! Since the path isn't there anymore, merge
3057 // won't work. So just do a copy url->wc
3058 dlg.SetCommand(CGitProgressDlg::GitProgress_Copy);
3059 dlg.SetPathList(CTGitPathList(CTGitPath(fileURL)));
3060 dlg.SetUrl(wcPath);
3061 dlg.SetRevision(rev2);
3063 else
3065 if (!PathFileExists(wcPath))
3067 // seems the path got renamed
3068 // tell the user how to work around this.
3069 CMessageBox::Show(this->m_hWnd, IDS_LOG_REVERTREV_ERROR, IDS_APPNAME, MB_ICONERROR);
3070 EnableOKButton();
3071 theApp.DoWaitCursor(-1);
3072 break; //exit
3074 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
3075 dlg.SetPathList(CTGitPathList(CTGitPath(wcPath)));
3076 dlg.SetUrl(fileURL);
3077 dlg.SetSecondUrl(fileURL);
3078 GitRevRangeArray revarray;
3079 revarray.AddRevRange(rev1, rev2);
3080 dlg.SetRevisionRanges(revarray);
3082 CString msg;
3083 msg.Format(IDS_LOG_REVERT_CONFIRM, (LPCTSTR)wcPath);
3084 if (CMessageBox::Show(this->m_hWnd, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
3086 dlg.DoModal();
3088 theApp.DoWaitCursor(-1);
3090 break;
3091 case ID_POPPROPS:
3093 DialogEnableWindow(IDOK, FALSE);
3094 SetPromptApp(&theApp);
3095 theApp.DoWaitCursor(1);
3096 CString filepath;
3097 if (Git::PathIsURL(m_path))
3099 filepath = m_path.GetGitPathString();
3101 else
3103 filepath = GetURLFromPath(m_path);
3104 if (filepath.IsEmpty())
3106 theApp.DoWaitCursor(-1);
3107 CString temp;
3108 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
3109 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3110 TRACE(_T("could not retrieve the URL of the file!\n"));
3111 EnableOKButton();
3112 break;
3115 filepath = GetRepositoryRoot(CTGitPath(filepath));
3116 filepath += changedpaths[0];
3117 CPropDlg dlg;
3118 dlg.m_rev = rev1;
3119 dlg.m_Path = CTGitPath(filepath);
3120 dlg.DoModal();
3121 EnableOKButton();
3122 theApp.DoWaitCursor(-1);
3124 break;
3125 case ID_SAVEAS:
3127 DialogEnableWindow(IDOK, FALSE);
3128 SetPromptApp(&theApp);
3129 theApp.DoWaitCursor(1);
3130 CString filepath;
3131 if (Git::PathIsURL(m_path))
3133 filepath = m_path.GetGitPathString();
3135 else
3137 filepath = GetURLFromPath(m_path);
3138 if (filepath.IsEmpty())
3140 theApp.DoWaitCursor(-1);
3141 CString temp;
3142 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
3143 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3144 TRACE(_T("could not retrieve the URL of the file!\n"));
3145 EnableOKButton();
3146 break;
3149 m_bCancelled = false;
3150 CString sRoot = GetRepositoryRoot(CTGitPath(filepath));
3151 // if more than one entry is selected, we save them
3152 // one by one into a folder the user has selected
3153 bool bTargetSelected = false;
3154 CTGitPath TargetPath;
3155 if (m_ChangedFileListCtrl.GetSelectedCount() > 1)
3157 CBrowseFolder browseFolder;
3158 browseFolder.SetInfo(CString(MAKEINTRESOURCE(IDS_LOG_SAVEFOLDERTOHINT)));
3159 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
3160 CString strSaveAsDirectory;
3161 if (browseFolder.Show(GetSafeHwnd(), strSaveAsDirectory) == CBrowseFolder::OK)
3163 TargetPath = CTGitPath(strSaveAsDirectory);
3164 bTargetSelected = true;
3167 else
3169 // Display the Open dialog box.
3170 CString revFilename;
3171 CString temp;
3172 temp = CPathUtils::GetFileNameFromPath(changedpaths[0]);
3173 int rfind = temp.ReverseFind('.');
3174 if (rfind > 0)
3175 revFilename.Format(_T("%s-%ld%s"), (LPCTSTR)temp.Left(rfind), rev1, (LPCTSTR)temp.Mid(rfind));
3176 else
3177 revFilename.Format(_T("%s-%ld"), (LPCTSTR)temp, rev1);
3178 bTargetSelected = CAppUtils::FileOpenSave(revFilename, NULL, IDS_LOG_POPUP_SAVE, IDS_COMMONFILEFILTER, false, m_hWnd);
3179 TargetPath.SetFromWin(revFilename);
3181 if (bTargetSelected)
3183 CProgressDlg progDlg;
3184 progDlg.SetTitle(IDS_APPNAME);
3185 progDlg.SetAnimation(IDR_DOWNLOAD);
3186 for (std::vector<LogChangedPath*>::iterator it = changedlogpaths.begin(); it!= changedlogpaths.end(); ++it)
3188 GitRev getrev = ((*it)->action == LOGACTIONS_DELETED) ? rev2 : rev1;
3190 CString sInfoLine;
3191 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)getrev.ToString());
3192 progDlg.SetLine(1, sInfoLine, true);
3193 SetAndClearProgressInfo(&progDlg);
3194 progDlg.ShowModeless(m_hWnd);
3196 CTGitPath tempfile = TargetPath;
3197 if (changedpaths.size() > 1)
3199 // if multiple items are selected, then the TargetPath
3200 // points to a folder and we have to append the filename
3201 // to save to to that folder.
3202 CString sName = (*it)->sPath;
3203 int slashpos = sName.ReverseFind('/');
3204 if (slashpos >= 0)
3205 sName = sName.Mid(slashpos);
3206 tempfile.AppendPathString(sName);
3207 // one problem here:
3208 // a user could have selected multiple items which
3209 // have the same filename but reside in different
3210 // directories, e.g.
3211 // /folder1/file1
3212 // /folder2/file1
3213 // in that case, the second 'file1' will overwrite
3214 // the already saved 'file1'.
3216 // we could maybe find the common root of all selected
3217 // items and then create sub folders to save those files
3218 // there.
3219 // But I think we should just leave it that way: to check
3220 // out multiple items at once, the better way is still to
3221 // use the export command from the top pane of the log dialog.
3223 filepath = sRoot + (*it)->sPath;
3224 if (!Cat(CTGitPath(filepath), getrev, getrev, tempfile))
3226 progDlg.Stop();
3227 SetAndClearProgressInfo((HWND)NULL);
3228 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3229 EnableOKButton();
3230 theApp.DoWaitCursor(-1);
3231 break;
3234 progDlg.Stop();
3235 SetAndClearProgressInfo((HWND)NULL);
3237 EnableOKButton();
3238 theApp.DoWaitCursor(-1);
3240 break;
3241 case ID_OPENWITH:
3242 bOpenWith = true;
3243 case ID_OPEN:
3245 GitRev getrev = pLogEntry->pArChangedPaths->GetAt(selIndex)->action == LOGACTIONS_DELETED ? rev2 : rev1;
3246 Open(bOpenWith,changedpaths[0],getrev);
3248 break;
3249 case ID_BLAME:
3251 CString filepath;
3252 if (Git::PathIsURL(m_path))
3254 filepath = m_path.GetGitPathString();
3256 else
3258 filepath = GetURLFromPath(m_path);
3259 if (filepath.IsEmpty())
3261 theApp.DoWaitCursor(-1);
3262 CString temp;
3263 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
3264 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3265 TRACE(_T("could not retrieve the URL of the file!\n"));
3266 EnableOKButton();
3267 break;
3270 filepath = GetRepositoryRoot(CTGitPath(filepath));
3271 filepath += changedpaths[0];
3272 CBlameDlg dlg;
3273 dlg.EndRev = rev1;
3274 if (dlg.DoModal() == IDOK)
3276 CBlame blame;
3277 CString tempfile;
3278 CString logfile;
3279 tempfile = blame.BlameToTempFile(CTGitPath(filepath), dlg.StartRev, dlg.EndRev, dlg.EndRev, logfile, _T(""), dlg.m_bIncludeMerge, TRUE, TRUE);
3280 if (!tempfile.IsEmpty())
3282 if (dlg.m_bTextView)
3284 //open the default text editor for the result file
3285 CAppUtils::StartTextViewer(tempfile);
3287 else
3289 CString sParams = _T("/path:\"") + filepath + _T("\" ");
3290 if(!CAppUtils::LaunchTortoiseBlame(tempfile, logfile, CPathUtils::GetFileNameFromPath(filepath),sParams))
3292 break;
3296 else
3298 CMessageBox::Show(this->m_hWnd, blame.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3302 break;
3303 case ID_GETMERGELOGS:
3304 bMergeLog = true;
3305 // fall through
3306 case ID_LOG:
3308 DialogEnableWindow(IDOK, FALSE);
3309 SetPromptApp(&theApp);
3310 theApp.DoWaitCursor(1);
3311 CString filepath;
3312 if (Git::PathIsURL(m_path))
3314 filepath = m_path.GetGitPathString();
3316 else
3318 filepath = GetURLFromPath(m_path);
3319 if (filepath.IsEmpty())
3321 theApp.DoWaitCursor(-1);
3322 CString temp;
3323 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
3324 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3325 TRACE(_T("could not retrieve the URL of the file!\n"));
3326 EnableOKButton();
3327 break;
3330 m_bCancelled = false;
3331 filepath = GetRepositoryRoot(CTGitPath(filepath));
3332 filepath += changedpaths[0];
3333 git_revnum_t logrev = rev1;
3334 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
3336 // if the item got deleted in this revision,
3337 // fetch the log from the previous revision where it
3338 // still existed.
3339 logrev--;
3341 CString sCmd;
3342 sCmd.Format(_T("\"%s\" /command:log /path:\"%s\" /startrev:%ld"), (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)filepath, logrev);
3343 if (bMergeLog)
3344 sCmd += _T(" /merge");
3345 CAppUtils::LaunchApplication(sCmd, NULL, false);
3346 EnableOKButton();
3347 theApp.DoWaitCursor(-1);
3349 break;
3350 case ID_VIEWPATHREV:
3352 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetSelectionMark()));
3353 GitRev rev = pLogEntry->Rev;
3354 CString relurl = changedpaths[0];
3355 CString url = m_ProjectProperties.sWebViewerPathRev;
3356 url.Replace(_T("%REVISION%"), rev.ToString());
3357 url.Replace(_T("%PATH%"), relurl);
3358 relurl = relurl.Mid(relurl.Find('/'));
3359 url.Replace(_T("%PATH1%"), relurl);
3360 if (!url.IsEmpty())
3361 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
3363 break;
3364 #endif
3365 default:
3366 break;
3367 } // switch (cmd)
3369 } // if (popup.CreatePopupMenu())
3371 #endif
3373 void CLogDlg::OnDtnDropdownDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3375 // the date control should not show the "today" button
3376 CMonthCalCtrl * pCtrl = m_DateFrom.GetMonthCalCtrl();
3377 if (pCtrl)
3378 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3379 *pResult = 0;
3382 void CLogDlg::OnDtnDropdownDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3384 // the date control should not show the "today" button
3385 CMonthCalCtrl * pCtrl = m_DateTo.GetMonthCalCtrl();
3386 if (pCtrl)
3387 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3388 *pResult = 0;
3391 void CLogDlg::OnSize(UINT nType, int cx, int cy)
3393 __super::OnSize(nType, cx, cy);
3394 //set range
3395 SetSplitterRange();
3398 void CLogDlg::OnRefresh()
3400 if (GetDlgItem(IDC_GETALL)->IsWindowEnabled())
3402 m_limit = 0;
3403 Refresh (true);
3407 void CLogDlg::OnFind()
3409 if (!m_pFindDialog)
3411 m_pFindDialog = new CFindReplaceDialog();
3412 m_pFindDialog->Create(TRUE, NULL, NULL, FR_HIDEUPDOWN | FR_HIDEWHOLEWORD, this);
3416 void CLogDlg::OnFocusFilter()
3418 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3421 void CLogDlg::OnEditCopy()
3423 if (GetFocus() == &m_ChangedFileListCtrl)
3424 CopyChangedSelectionToClipBoard();
3425 else
3426 m_LogList.CopySelectionToClipBoard();
3429 CString CLogDlg::GetAbsoluteUrlFromRelativeUrl(const CString& url)
3431 // is the URL a relative one?
3432 if (url.Left(2).Compare(_T("^/")) == 0)
3434 // URL is relative to the repository root
3435 CString url1 = m_sRepositoryRoot + url.Mid(1);
3436 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3437 DWORD len = url.GetLength();
3438 if (UrlCanonicalize((LPCTSTR)url1, buf, &len, 0) == S_OK)
3439 return CString(buf, len);
3440 return url1;
3442 else if (url[0] == '/')
3444 // URL is relative to the server's hostname
3445 CString sHost;
3446 // find the server's hostname
3447 int schemepos = m_sRepositoryRoot.Find(_T("//"));
3448 if (schemepos >= 0)
3450 sHost = m_sRepositoryRoot.Left(m_sRepositoryRoot.Find('/', schemepos+3));
3451 CString url1 = sHost + url;
3452 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3453 DWORD len = url.GetLength();
3454 if (UrlCanonicalize((LPCTSTR)url, buf, &len, 0) == S_OK)
3455 return CString(buf, len);
3456 return url1;
3459 return url;
3463 void CLogDlg::OnEnChangeSearchedit()
3465 UpdateData();
3466 if (m_LogList.m_sFilterText.IsEmpty())
3468 CStoreSelection storeselection(this);
3469 // clear the filter, i.e. make all entries appear
3470 theApp.DoWaitCursor(1);
3471 KillTimer(LOGFILTER_TIMER);
3472 FillLogMessageCtrl(false);
3473 m_LogList.StartFilter();
3474 #if 0
3475 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3476 m_arShownList.RemoveAll();
3477 for (DWORD i=0; i<m_logEntries.size(); ++i)
3479 if (IsEntryInDateRange(i))
3480 m_arShownList.Add(m_logEntries[i]);
3482 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3483 m_LogList.DeleteAllItems();
3484 m_LogList.SetItemCountEx(ShownCountWithStopped());
3485 m_LogList.RedrawItems(0, ShownCountWithStopped());
3486 m_LogList.SetRedraw(false);
3487 ResizeAllListCtrlCols();
3488 m_LogList.SetRedraw(true);
3489 #endif
3490 theApp.DoWaitCursor(-1);
3491 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
3492 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
3493 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3494 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
3495 return;
3497 if (Validate(m_LogList.m_sFilterText))
3498 SetTimer(LOGFILTER_TIMER, 1000, NULL);
3499 else
3500 KillTimer(LOGFILTER_TIMER);