scroll log to current revision if not requested differently
[TortoiseGit.git] / src / TortoiseProc / LogDlg.cpp
blobc48ebf8ca203f8bde3f166875377daffcd262de8
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2011 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "cursor.h"
23 #include "InputDlg.h"
24 #include "PropDlg.h"
25 #include "SVNProgressDlg.h"
26 #include "ProgressDlg.h"
27 //#include "RepositoryBrowser.h"
28 //#include "CopyDlg.h"
29 #include "StatGraphDlg.h"
30 #include "Logdlg.h"
31 #include "MessageBox.h"
32 #include "Registry.h"
33 #include "AppUtils.h"
34 #include "PathUtils.h"
35 #include "StringUtils.h"
36 #include "UnicodeUtils.h"
37 #include "TempFile.h"
38 //#include "GitInfo.h"
39 //#include "GitDiff.h"
40 #include "IconMenu.h"
41 //#include "RevisionRangeDlg.h"
42 //#include "BrowseFolder.h"
43 //#include "BlameDlg.h"
44 //#include "Blame.h"
45 //#include "GitHelpers.h"
46 #include "GitStatus.h"
47 //#include "LogDlgHelper.h"
48 //#include "CachedLogInfo.h"
49 //#include "RepositoryInfo.h"
50 //#include "EditPropertiesDlg.h"
51 #include "FileDiffDlg.h"
52 #include "BrowseRefsDlg.h"
55 IMPLEMENT_DYNAMIC(CLogDlg, CResizableStandAloneDialog)
56 CLogDlg::CLogDlg(CWnd* pParent /*=NULL*/)
57 : CResizableStandAloneDialog(CLogDlg::IDD, pParent)
58 , m_logcounter(0)
59 , m_wParam(0)
60 , m_currentChangedArray(NULL)
61 , m_nSortColumn(0)
62 , m_bShowedAll(false)
63 , m_bSelect(false)
65 , m_bSelectionMustBeContinuous(false)
66 , m_lowestRev(_T(""))
68 , m_sLogInfo(_T(""))
70 , m_bCancelled(FALSE)
71 , m_pNotifyWindow(NULL)
73 , m_bAscending(FALSE)
75 , m_limit(0)
76 , m_childCounter(0)
77 , m_maxChild(0)
78 , m_bIncludeMerges(FALSE)
79 , m_hAccel(NULL)
81 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
83 CString str;
84 str=g_Git.m_CurrentDir;
85 str.Replace(_T(":"),_T("_"));
86 str=CString(_T("Software\\TortoiseGit\\LogDialog\\AllBranch\\"))+str;
88 m_regbAllBranch=CRegDWORD(str,FALSE);
90 m_bAllBranch=m_regbAllBranch;
92 m_bFirstParent=FALSE;
93 m_bWholeProject=FALSE;
96 CLogDlg::~CLogDlg()
99 m_regbAllBranch=m_bAllBranch;
101 m_CurrentFilteredChangedArray.RemoveAll();
105 void CLogDlg::DoDataExchange(CDataExchange* pDX)
107 CResizableStandAloneDialog::DoDataExchange(pDX);
108 DDX_Control(pDX, IDC_LOGLIST, m_LogList);
109 DDX_Control(pDX, IDC_LOGMSG, m_ChangedFileListCtrl);
110 DDX_Control(pDX, IDC_PROGRESS, m_LogProgress);
111 DDX_Control(pDX, IDC_SPLITTERTOP, m_wndSplitter1);
112 DDX_Control(pDX, IDC_SPLITTERBOTTOM, m_wndSplitter2);
113 DDX_Text(pDX, IDC_SEARCHEDIT, m_LogList.m_sFilterText);
114 DDX_Control(pDX, IDC_DATEFROM, m_DateFrom);
115 DDX_Control(pDX, IDC_DATETO, m_DateTo);
116 DDX_Control(pDX, IDC_HIDEPATHS, m_cHidePaths);
117 DDX_Text(pDX, IDC_LOGINFO, m_sLogInfo);
118 DDX_Check(pDX, IDC_LOG_FIRSTPARENT, m_bFirstParent);
119 DDX_Check(pDX, IDC_LOG_ALLBRANCH,m_bAllBranch);
120 DDX_Check(pDX, IDC_SHOWWHOLEPROJECT,m_bWholeProject);
121 DDX_Control(pDX, IDC_SEARCHEDIT, m_cFilter);
122 DDX_Control(pDX, IDC_STATIC_REF, m_staticRef);
125 BEGIN_MESSAGE_MAP(CLogDlg, CResizableStandAloneDialog)
126 //ON_BN_CLICKED(IDC_GETALL, OnBnClickedGetall)
127 //ON_NOTIFY(NM_DBLCLK, IDC_LOGMSG, OnNMDblclkChangedFileList)
128 ON_WM_CONTEXTMENU()
129 ON_WM_SETCURSOR()
130 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
131 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOGLIST, OnLvnItemchangedLoglist)
132 ON_NOTIFY(EN_LINK, IDC_MSGVIEW, OnEnLinkMsgview)
133 ON_BN_CLICKED(IDC_STATBUTTON, OnBnClickedStatbutton)
136 ON_MESSAGE(WM_FILTEREDIT_INFOCLICKED, OnClickedInfoIcon)
137 ON_MESSAGE(WM_FILTEREDIT_CANCELCLICKED, OnClickedCancelFilter)
139 ON_MESSAGE(MSG_LOAD_PERCENTAGE,OnLogListLoading)
141 ON_EN_CHANGE(IDC_SEARCHEDIT, OnEnChangeSearchedit)
142 ON_WM_TIMER()
143 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETO, OnDtnDatetimechangeDateto)
144 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATEFROM, OnDtnDatetimechangeDatefrom)
145 ON_BN_CLICKED(IDC_SHOWWHOLEPROJECT, OnBnClickShowWholeProject)
146 //ON_NOTIFY(NM_CUSTOMDRAW, IDC_LOGMSG, OnNMCustomdrawChangedFileList)
147 //ON_NOTIFY(LVN_GETDISPINFO, IDC_LOGMSG, OnLvnGetdispinfoChangedFileList)
148 ON_NOTIFY(LVN_COLUMNCLICK,IDC_LOGLIST, OnLvnColumnclick)
149 //ON_NOTIFY(LVN_COLUMNCLICK, IDC_LOGMSG, OnLvnColumnclickChangedFileList)
150 ON_BN_CLICKED(IDC_HIDEPATHS, OnBnClickedHidepaths)
151 ON_COMMAND(MSG_FETCHED_DIFF, OnBnClickedHidepaths)
152 ON_BN_CLICKED(IDC_LOG_ALLBRANCH, OnBnClickedAllBranch)
154 ON_NOTIFY(DTN_DROPDOWN, IDC_DATEFROM, &CLogDlg::OnDtnDropdownDatefrom)
155 ON_NOTIFY(DTN_DROPDOWN, IDC_DATETO, &CLogDlg::OnDtnDropdownDateto)
156 ON_WM_SIZE()
157 ON_BN_CLICKED(IDC_LOG_FIRSTPARENT, &CLogDlg::OnBnClickedFirstParent)
158 ON_BN_CLICKED(IDC_REFRESH, &CLogDlg::OnBnClickedRefresh)
159 // ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CLogDlg::OnBnClickedBrowseRef)
160 ON_STN_CLICKED(IDC_STATIC_REF, &CLogDlg::OnBnClickedBrowseRef)
161 ON_COMMAND(ID_LOGDLG_REFRESH, &CLogDlg::OnBnClickedRefresh)
162 ON_COMMAND(ID_LOGDLG_FIND, &CLogDlg::OnFind)
163 ON_COMMAND(ID_LOGDLG_FOCUSFILTER, &CLogDlg::OnFocusFilter)
164 ON_COMMAND(ID_EDIT_COPY, &CLogDlg::OnEditCopy)
165 ON_MESSAGE(MSG_REFLOG_CHANGED, OnRefLogChanged)
166 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
167 END_MESSAGE_MAP()
169 void CLogDlg::SetParams(const CTGitPath& orgPath, const CTGitPath& path, CString hightlightRevision, CString startrev, CString endrev, int limit /* = FALSE */)
171 m_orgPath = orgPath;
172 m_path = path;
173 m_hightlightRevision = hightlightRevision;
174 this->m_LogList.m_startrev = startrev;
175 m_LogRevision = startrev;
176 this->m_LogList.m_endrev = endrev;
178 if(!endrev.IsEmpty())
179 this->SetStartRef(endrev);
181 m_hasWC = !path.IsUrl();
182 m_limit = limit;
183 if (::IsWindow(m_hWnd))
184 UpdateData(FALSE);
187 BOOL CLogDlg::OnInitDialog()
189 CString temp;
190 CResizableStandAloneDialog::OnInitDialog();
191 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
193 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
194 // do this, Explorer would be unable to send that message to our window if we
195 // were running elevated. It's OK to make the call all the time, since if we're
196 // not elevated, this is a no-op.
197 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
198 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
199 HMODULE hUser = ::LoadLibrary(_T("user32.dll"));
200 if (hUser)
202 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
203 if (pfnChangeWindowMessageFilterEx)
205 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
207 FreeLibrary(hUser);
209 m_pTaskbarList.Release();
210 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
212 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_LOGDLG));
214 // use the state of the "stop on copy/rename" option from the last time
215 UpdateData(FALSE);
217 // set the font to use in the log message view, configured in the settings dialog
218 CAppUtils::CreateFontForLogs(m_logFont);
219 GetDlgItem(IDC_MSGVIEW)->SetFont(&m_logFont);
220 // automatically detect URLs in the log message and turn them into links
221 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_AUTOURLDETECT, TRUE, NULL);
222 // make the log message rich edit control send a message when the mouse pointer is over a link
223 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_SETEVENTMASK, NULL, ENM_LINK);
224 //m_LogList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_SUBITEMIMAGES);
226 // the "hide unrelated paths" checkbox should be indeterminate
227 m_cHidePaths.SetCheck(BST_INDETERMINATE);
230 //SetWindowTheme(m_LogList.GetSafeHwnd(), L"Explorer", NULL);
231 //SetWindowTheme(m_ChangedFileListCtrl.GetSafeHwnd(), L"Explorer", NULL);
233 // set up the columns
234 m_LogList.DeleteAllItems();
236 m_LogList.m_Path=m_path;
237 m_LogList.m_bShowWC = true;
238 m_LogList.InsertGitColumn();
240 m_ChangedFileListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("LogDlg"),(SVNSLC_POPALL ^ (SVNSLC_POPCOMMIT|SVNSLC_POPIGNORE)),false);
242 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
244 m_logcounter = 0;
245 m_sMessageBuf.Preallocate(100000);
247 SetDlgTitle();
249 m_tooltips.Create(this);
250 CheckRegexpTooltip();
252 SetSplitterRange();
254 // the filter control has a 'cancel' button (the red 'X'), we need to load its bitmap
255 m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);
256 m_cFilter.SetInfoIcon(IDI_LOGFILTER);
257 m_cFilter.SetValidator(this);
259 AdjustControlSize(IDC_HIDEPATHS);
260 AdjustControlSize(IDC_LOG_FIRSTPARENT);
261 AdjustControlSize(IDC_LOG_ALLBRANCH);
263 GetClientRect(m_DlgOrigRect);
264 m_LogList.GetClientRect(m_LogListOrigRect);
265 GetDlgItem(IDC_MSGVIEW)->GetClientRect(m_MsgViewOrigRect);
266 m_ChangedFileListCtrl.GetClientRect(m_ChgOrigRect);
268 m_DateFrom.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
269 m_DateTo.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
271 m_staticRef.SetURL(CString());
273 // resizable stuff
274 AddAnchor(IDC_STATIC_REF, TOP_LEFT);
275 //AddAnchor(IDC_BUTTON_BROWSE_REF, TOP_LEFT);
276 AddAnchor(IDC_FROMLABEL, TOP_LEFT);
277 AddAnchor(IDC_DATEFROM, TOP_LEFT);
278 AddAnchor(IDC_TOLABEL, TOP_LEFT);
279 AddAnchor(IDC_DATETO, TOP_LEFT);
281 SetFilterCueText();
282 AddAnchor(IDC_SEARCHEDIT, TOP_LEFT, TOP_RIGHT);
284 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
285 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
286 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
287 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
288 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
290 AddAnchor(IDC_LOGINFO, BOTTOM_LEFT, BOTTOM_RIGHT);
291 AddAnchor(IDC_HIDEPATHS, BOTTOM_LEFT);
292 AddAnchor(IDC_LOG_ALLBRANCH,BOTTOM_LEFT);
293 AddAnchor(IDC_LOG_FIRSTPARENT, BOTTOM_LEFT);
294 //AddAnchor(IDC_GETALL, BOTTOM_LEFT);
295 AddAnchor(IDC_SHOWWHOLEPROJECT, BOTTOM_LEFT);
296 AddAnchor(IDC_REFRESH, BOTTOM_LEFT);
297 AddAnchor(IDC_STATBUTTON, BOTTOM_RIGHT);
298 AddAnchor(IDC_PROGRESS, BOTTOM_LEFT, BOTTOM_RIGHT);
299 AddAnchor(IDOK, BOTTOM_RIGHT);
300 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
301 AddAnchor(IDHELP, BOTTOM_RIGHT);
303 if(this->m_bAllBranch)
304 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
305 else
306 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
308 // SetPromptParentWindow(m_hWnd);
310 if (hWndExplorer)
311 CenterWindow(CWnd::FromHandle(hWndExplorer));
312 EnableSaveRestore(_T("LogDlg"));
314 DWORD yPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
315 DWORD yPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
316 RECT rcDlg, rcLogList, rcChgMsg;
317 GetClientRect(&rcDlg);
318 m_LogList.GetWindowRect(&rcLogList);
319 ScreenToClient(&rcLogList);
320 m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg);
321 ScreenToClient(&rcChgMsg);
322 if (yPos1)
324 RECT rectSplitter;
325 m_wndSplitter1.GetWindowRect(&rectSplitter);
326 ScreenToClient(&rectSplitter);
327 int delta = yPos1 - rectSplitter.top;
329 if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30))
331 m_wndSplitter1.SetWindowPos(NULL, 0, yPos1, 0, 0, SWP_NOSIZE);
332 DoSizeV1(delta);
335 if (yPos2)
337 RECT rectSplitter;
338 m_wndSplitter2.GetWindowRect(&rectSplitter);
339 ScreenToClient(&rectSplitter);
340 int delta = yPos2 - rectSplitter.top;
342 if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30))
344 m_wndSplitter2.SetWindowPos(NULL, 0, yPos2, 0, 0, SWP_NOSIZE);
345 DoSizeV2(delta);
350 if (m_bSelect)
352 // the dialog is used to select revisions
353 // enable the OK button if appropriate
354 EnableOKButton();
356 else
358 // the dialog is used to just view log messages
359 // hide the OK button and set text on Cancel button to OK
360 GetDlgItemText(IDOK, temp);
361 SetDlgItemText(IDCANCEL, temp);
362 GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
365 m_mergedRevs.clear();
367 // first start a thread to obtain the log messages without
368 // blocking the dialog
369 //m_tTo = 0;
370 //m_tFrom = (DWORD)-1;
372 // scroll to user selected or current revision
373 if (!m_hightlightRevision.IsEmpty() && m_hightlightRevision.GetLength() >= GIT_HASH_SIZE)
374 m_LogList.m_lastSelectedHash = m_hightlightRevision;
375 else
376 m_LogList.m_lastSelectedHash = g_Git.GetHash(_T("HEAD"));
378 m_LogList.FetchLogAsync(this);
380 GetDlgItem(IDC_LOGLIST)->SetFocus();
382 ShowStartRef();
383 return FALSE;
386 LRESULT CLogDlg::OnLogListLoading(WPARAM wParam, LPARAM /*lParam*/)
388 int cur=(int)wParam;
390 if( cur == GITLOG_START )
392 CString temp;
393 temp.LoadString(IDS_PROGRESSWAIT);
395 this->m_LogList.ShowText(temp, true);
397 // We use a progress bar while getting the logs
398 m_LogProgress.SetRange32(0, 100);
399 m_LogProgress.SetPos(0);
400 if (m_pTaskbarList)
402 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
403 m_pTaskbarList->SetProgressValue(m_hWnd, 0, 100);
406 GetDlgItem(IDC_PROGRESS)->ShowWindow(TRUE);
408 //DialogEnableWindow(IDC_GETALL, FALSE);
409 //DialogEnableWindow(IDC_SHOWWHOLEPROJECT, FALSE);
410 //DialogEnableWindow(IDC_LOG_FIRSTPARENT, FALSE);
411 DialogEnableWindow(IDC_STATBUTTON, FALSE);
412 //DialogEnableWindow(IDC_REFRESH, FALSE);
413 DialogEnableWindow(IDC_HIDEPATHS,FALSE);
416 else if( cur == GITLOG_END)
418 if(this->m_LogList.HasText())
420 this->m_LogList.ClearText();
422 UpdateLogInfoLabel();
424 if (m_pTaskbarList)
425 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
427 //if (!m_bShowedAll)
428 DialogEnableWindow(IDC_SHOWWHOLEPROJECT, TRUE);
430 //DialogEnableWindow(IDC_GETALL, TRUE);
431 DialogEnableWindow(IDC_STATBUTTON, TRUE);
432 DialogEnableWindow(IDC_REFRESH, TRUE);
433 DialogEnableWindow(IDC_HIDEPATHS,TRUE);
435 // PostMessage(WM_TIMER, LOGFILTER_TIMER);
436 GetDlgItem(IDC_PROGRESS)->ShowWindow(FALSE);
437 //CTime time=m_LogList.GetOldestTime();
438 CTime begin,end;
439 m_LogList.GetTimeRange(begin,end);
441 if(m_LogList.m_From == -1)
442 m_DateFrom.SetTime(&begin);
444 if(m_LogList.m_To == -1)
445 m_DateTo.SetTime(&end);
449 else
451 if(this->m_LogList.HasText())
453 this->m_LogList.ClearText();
454 this->m_LogList.Invalidate();
456 UpdateLogInfoLabel();
457 m_LogProgress.SetPos(cur);
458 if (m_pTaskbarList)
460 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
461 m_pTaskbarList->SetProgressValue(m_hWnd, cur, 100);
464 return 0;
466 void CLogDlg::SetDlgTitle()
468 if (m_sTitle.IsEmpty())
469 GetWindowText(m_sTitle);
471 if (m_LogList.m_Path.IsEmpty() || m_orgPath.GetWinPathString().IsEmpty())
473 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
475 else
476 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);
479 void CLogDlg::CheckRegexpTooltip()
481 CWnd *pWnd = GetDlgItem(IDC_SEARCHEDIT);
482 // Since tooltip describes regexp features, show it only if regexps are enabled.
483 if (m_bFilterWithRegex)
485 m_tooltips.AddTool(pWnd, IDS_LOG_FILTER_REGEX_TT);
487 else
488 m_tooltips.DelTool(pWnd);
491 void CLogDlg::EnableOKButton()
493 if (m_bSelect)
495 // the dialog is used to select revisions
496 if (m_bSelectionMustBeSingle)
498 // enable OK button if only a single revision is selected
499 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()==1));
501 else if (m_bSelectionMustBeContinuous)
502 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));
503 else
504 DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);
506 else
507 DialogEnableWindow(IDOK, TRUE);
510 CString CLogDlg::GetTagInfo(GitRev* pLogEntry)
512 CString cmd;
513 CString output;
515 if(m_LogList.m_HashMap.find(pLogEntry->m_CommitHash) != m_LogList.m_HashMap.end())
517 STRING_VECTOR &vector = m_LogList.m_HashMap[pLogEntry->m_CommitHash];
518 for(int i=0;i<vector.size();i++)
520 if(vector[i].Find(_T("refs/tags/")) == 0 )
522 CString tag= vector[i];
523 int start = vector[i].Find(_T("^{}"));
524 if(start>0)
525 tag=tag.Left(start);
526 else
527 continue;
529 cmd.Format(_T("git.exe cat-file tag %s"), tag);
531 if(g_Git.Run(cmd, &output, CP_UTF8) == 0 )
532 output+=_T("\n");
537 if(!output.IsEmpty())
539 output = _T("\n*Tag Info*\n\n") + output;
542 return output;
545 void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)
547 // we fill here the log message rich edit control,
548 // and also populate the changed files list control
549 // according to the selected revision(s).
551 CRichEditCtrl * pMsgView = (CRichEditCtrl*)GetDlgItem(IDC_MSGVIEW);
552 // empty the log message view
553 pMsgView->SetWindowText(_T(" "));
554 // empty the changed files list
555 m_ChangedFileListCtrl.SetRedraw(FALSE);
556 // InterlockedExchange(&m_bNoDispUpdates, TRUE);
557 m_currentChangedArray = NULL;
558 //m_ChangedFileListCtrl.SetExtendedStyle ( LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER );
559 m_ChangedFileListCtrl.DeleteAllItems();
561 // if we're not here to really show a selected revision, just
562 // get out of here after clearing the views, which is what is intended
563 // if that flag is not set.
564 if (!bShow)
566 // force a redraw
567 m_ChangedFileListCtrl.Invalidate();
568 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
569 m_ChangedFileListCtrl.SetRedraw(TRUE);
570 return;
573 // depending on how many revisions are selected, we have to do different
574 // tasks.
575 int selCount = m_LogList.GetSelectedCount();
576 if (selCount == 0)
578 // if nothing is selected, we have nothing more to do
579 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
580 m_ChangedFileListCtrl.SetRedraw(TRUE);
581 return;
583 else if (selCount == 1)
585 // if one revision is selected, we have to fill the log message view
586 // with the corresponding log message, and also fill the changed files
587 // list fully.
588 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
589 int selIndex = m_LogList.GetNextSelectedItem(pos);
590 if (selIndex >= m_LogList.m_arShownList.GetCount())
592 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
593 m_ChangedFileListCtrl.SetRedraw(TRUE);
594 return;
596 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
599 // set the log message text
600 pMsgView->SetWindowText(_T("Commit:")+pLogEntry->m_CommitHash.ToString()+_T("\r\n\r\n"));
601 // turn bug ID's into links if the bugtraq: properties have been set
602 // and we can find a match of those in the log message
604 pMsgView->SetSel(-1,-1);
605 CHARFORMAT2 format;
606 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
607 format.cbSize = sizeof(CHARFORMAT2);
608 format.dwMask = CFM_BOLD;
609 format.dwEffects = CFE_BOLD;
610 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
612 CString msg=_T("* ");
613 msg+=pLogEntry->GetSubject();
614 pMsgView->ReplaceSel(msg);
616 pMsgView->SetSel(-1,-1);
617 format.dwEffects = 0;
618 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
620 msg=_T("\n");
621 msg+=pLogEntry->GetBody();
623 if(!pLogEntry->m_Notes.IsEmpty())
625 msg+= _T("\n*Notes* ");
626 msg+= pLogEntry->m_Notes;
627 msg+= _T("\n\n");
630 msg+=GetTagInfo(pLogEntry);
632 pMsgView->ReplaceSel(msg);
634 CString text;
635 pMsgView->GetWindowText(text);
636 // the rich edit control doesn't count the CR char!
637 // to be exact: CRLF is treated as one char.
638 text.Remove('\r');
640 m_LogList.m_ProjectProperties.FindBugID(text, pMsgView);
641 CAppUtils::FormatTextInRichEditControl(pMsgView);
643 int HidePaths=m_cHidePaths.GetState() & 0x0003;
644 CString matchpath=this->m_path.GetGitPathString();
646 int count = pLogEntry->GetFiles(&m_LogList).GetCount();
647 for(int i=0;i<count && (!matchpath.IsEmpty());i++)
649 if( m_bWholeProject )
650 break;
652 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action &= ~(CTGitPath::LOGACTIONS_HIDE|CTGitPath::LOGACTIONS_GRAY);
654 if(pLogEntry->GetFiles(&m_LogList)[i].GetGitPathString().Left(matchpath.GetLength()) != matchpath)
656 if(HidePaths==BST_CHECKED)
657 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;
658 if(HidePaths==BST_INDETERMINATE)
659 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_GRAY;
663 m_ChangedFileListCtrl.UpdateWithGitPathList(pLogEntry->GetFiles(&m_LogList));
664 m_ChangedFileListCtrl.m_CurrentVersion=pLogEntry->m_CommitHash;
665 m_ChangedFileListCtrl.Show(SVNSLC_SHOWVERSIONED);
667 m_ChangedFileListCtrl.SetBusyString(_T("Fetch Changed File..."));
669 if(!pLogEntry->m_IsDiffFiles)
670 m_ChangedFileListCtrl.SetBusy(TRUE);
671 else
672 m_ChangedFileListCtrl.SetBusy(FALSE);
674 m_ChangedFileListCtrl.SetRedraw(TRUE);
675 return;
679 else
681 // more than one revision is selected:
682 // the log message view must be emptied
683 // the changed files list contains all the changed paths from all
684 // selected revisions, with 'doubles' removed
685 m_currentChangedPathList = GetChangedPathsFromSelectedRevisions(true);
688 // redraw the views
689 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
690 #if 0
691 if (m_currentChangedArray)
693 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedArray->GetCount());
694 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedArray->GetCount());
696 else if (m_currentChangedPathList.GetCount())
698 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedPathList.GetCount());
699 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedPathList.GetCount());
701 else
703 m_ChangedFileListCtrl.SetItemCountEx(0);
704 m_ChangedFileListCtrl.Invalidate();
706 #endif
707 // sort according to the settings
708 if (m_nSortColumnPathList > 0)
709 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
710 else
711 SetSortArrow(&m_ChangedFileListCtrl, -1, false);
712 m_ChangedFileListCtrl.SetRedraw(TRUE);
716 void CLogDlg::OnBnClickedRefresh()
718 Refresh (true);
721 void CLogDlg::Refresh (bool clearfilter /*autoGoOnline*/)
723 m_limit = 0;
724 m_LogList.Refresh(clearfilter);
725 FillLogMessageCtrl(false);
730 BOOL CLogDlg::Cancel()
732 return m_bCancelled;
735 void CLogDlg::SaveSplitterPos()
737 if (!IsIconic())
739 CRegDWORD regPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
740 CRegDWORD regPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
741 RECT rectSplitter;
742 m_wndSplitter1.GetWindowRect(&rectSplitter);
743 ScreenToClient(&rectSplitter);
744 regPos1 = rectSplitter.top;
745 m_wndSplitter2.GetWindowRect(&rectSplitter);
746 ScreenToClient(&rectSplitter);
747 regPos2 = rectSplitter.top;
751 void CLogDlg::OnCancel()
753 this->ShowWindow(SW_HIDE);
755 // canceling means stopping the working thread if it's still running.
756 m_LogList.SafeTerminateAsyncDiffThread();
757 if (this->IsThreadRunning())
759 m_LogList.SafeTerminateThread();
761 UpdateData();
763 SaveSplitterPos();
764 __super::OnCancel();
767 CString CLogDlg::MakeShortMessage(const CString& message)
769 bool bFoundShort = true;
770 CString sShortMessage = m_LogList.m_ProjectProperties.GetLogSummary(message);
771 if (sShortMessage.IsEmpty())
773 bFoundShort = false;
774 sShortMessage = message;
776 // Remove newlines and tabs 'cause those are not shown nicely in the list control
777 sShortMessage.Remove('\r');
778 sShortMessage.Replace(_T('\t'), _T(' '));
780 // Suppose the first empty line separates 'summary' from the rest of the message.
781 int found = sShortMessage.Find(_T("\n\n"));
782 // To avoid too short 'short' messages
783 // (e.g. if the message looks something like "Bugfix:\n\n*done this\n*done that")
784 // only use the empty newline as a separator if it comes after at least 15 chars.
785 if ((!bFoundShort)&&(found >= 15))
787 sShortMessage = sShortMessage.Left(found);
789 sShortMessage.Replace('\n', ' ');
790 return sShortMessage;
793 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*/)
795 #if 0
796 if (rev == SVN_INVALID_REVNUM)
798 m_childCounter--;
799 return TRUE;
802 // this is the callback function which receives the data for every revision we ask the log for
803 // we store this information here one by one.
804 m_logcounter += 1;
805 if (m_startrev == -1)
806 m_startrev = rev;
807 if (m_limit != 0)
809 m_limitcounter--;
810 m_LogProgress.SetPos(m_limit - m_limitcounter);
812 else if (m_startrev.IsNumber() && m_startrev.IsNumber())
813 m_LogProgress.SetPos((git_revnum_t)m_startrev-rev+(git_revnum_t)m_endrev);
814 __time64_t ttime = time/1000000L;
815 if (m_tTo < (DWORD)ttime)
816 m_tTo = (DWORD)ttime;
817 if (m_tFrom > (DWORD)ttime)
818 m_tFrom = (DWORD)ttime;
819 if ((m_lowestRev > rev)||(m_lowestRev < 0))
820 m_lowestRev = rev;
821 // Add as many characters from the log message to the list control
822 PLOGENTRYDATA pLogItem = new LOGENTRYDATA;
823 pLogItem->bCopies = !!copies;
825 // find out if this item was copied in the revision
826 BOOL copiedself = FALSE;
827 if (copies)
829 for (INT_PTR cpPathIndex = 0; cpPathIndex < cpaths->GetCount(); ++cpPathIndex)
831 LogChangedPath * cpath = cpaths->SafeGetAt(cpPathIndex);
832 if (!cpath->sCopyFromPath.IsEmpty() && (cpath->sPath.Compare(m_sSelfRelativeURL) == 0))
834 // note: this only works if the log is fetched top-to-bottom
835 // but since we do that, it shouldn't be a problem
836 m_sSelfRelativeURL = cpath->sCopyFromPath;
837 copiedself = TRUE;
838 break;
842 pLogItem->bCopiedSelf = copiedself;
843 pLogItem->tmDate = ttime;
844 pLogItem->sAuthor = author;
845 pLogItem->sDate = date;
846 pLogItem->sShortMessage = MakeShortMessage(message);
847 pLogItem->dwFileChanges = filechanges;
848 pLogItem->actions = actions;
849 pLogItem->haschildren = haschildren;
850 pLogItem->childStackDepth = m_childCounter;
851 m_maxChild = max(m_childCounter, m_maxChild);
852 if (haschildren)
853 m_childCounter++;
854 pLogItem->sBugIDs = m_ProjectProperties.FindBugID(message).Trim();
856 // split multi line log entries and concatenate them
857 // again but this time with \r\n as line separators
858 // so that the edit control recognizes them
861 if (message.GetLength()>0)
863 m_sMessageBuf = message;
864 m_sMessageBuf.Replace(_T("\n\r"), _T("\n"));
865 m_sMessageBuf.Replace(_T("\r\n"), _T("\n"));
866 if (m_sMessageBuf.Right(1).Compare(_T("\n"))==0)
867 m_sMessageBuf = m_sMessageBuf.Left(m_sMessageBuf.GetLength()-1);
869 else
870 m_sMessageBuf.Empty();
871 pLogItem->sMessage = m_sMessageBuf;
872 pLogItem->Rev = rev;
874 // move-construct path array
876 pLogItem->pArChangedPaths = new LogChangedPathArray (*cpaths);
877 cpaths->RemoveAll();
879 catch (CException * e)
881 ::MessageBox(NULL, _T("not enough memory!"), _T("TortoiseGit"), MB_ICONERROR);
882 e->Delete();
883 m_bCancelled = TRUE;
885 m_logEntries.push_back(pLogItem);
886 m_arShownList.Add(pLogItem);
887 #endif
888 return TRUE;
891 GitRev g_rev;
892 //this is the thread function which calls the subversion function
897 void CLogDlg::CopyChangedSelectionToClipBoard()
900 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
901 if (pos == NULL)
902 return; // nothing is selected, get out of here
904 CString sPaths;
906 // CGitRev* pLogEntry = reinterpret_cast<CGitRev* >(m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
907 // if (pos)
909 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
910 while (pos)
912 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
913 CTGitPath *path = (CTGitPath*)m_ChangedFileListCtrl.GetItemData(nItem);
914 if(path)
915 sPaths += path->GetGitPathString();
916 sPaths += _T("\r\n");
919 #if 0
920 else
922 // only one revision is selected in the log dialog top pane
923 // but multiple items could be selected in the changed items list
924 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
925 while (pos)
927 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
928 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(nItem);
930 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
932 // some items are hidden! So find out which item the user really selected
933 INT_PTR selRealIndex = -1;
934 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
936 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
937 selRealIndex++;
938 if (selRealIndex == nItem)
940 changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex);
941 break;
945 if (changedlogpath)
947 sPaths += changedlogpath->sPath;
948 sPaths += _T("\r\n");
952 #endif
953 sPaths.Trim();
954 CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());
958 BOOL CLogDlg::IsDiffPossible(LogChangedPath * /*changedpath*/, git_revnum_t rev)
960 #if 0
961 CString added, deleted;
962 if (changedpath == NULL)
963 return false;
965 if ((rev > 1)&&(changedpath->action != LOGACTIONS_DELETED))
967 if (changedpath->action == LOGACTIONS_ADDED) // file is added
969 if (changedpath->lCopyFromRev == 0)
970 return FALSE; // but file was not added with history
972 return TRUE;
974 #endif
975 return FALSE;
978 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)
980 // we have two separate context menus:
981 // one shown on the log message list control,
982 // the other shown in the changed-files list control
983 int selCount = m_LogList.GetSelectedCount();
984 if (pWnd == &m_LogList)
986 //ShowContextMenuForRevisions(pWnd, point);
988 else if (pWnd == &m_ChangedFileListCtrl)
990 //ShowContextMenuForChangedpaths(pWnd, point);
992 else if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))
994 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
995 int selIndex = -1;
996 if (pos)
997 selIndex = m_LogList.GetNextSelectedItem(pos);
999 GitRev *pRev = ((GitRev*)m_LogList.m_arShownList[selIndex]);
1001 if ((point.x == -1) && (point.y == -1))
1003 CRect rect;
1004 GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);
1005 ClientToScreen(&rect);
1006 point = rect.CenterPoint();
1008 CString sMenuItemText;
1009 CIconMenu popup;
1010 if (popup.CreatePopupMenu())
1012 // add the 'default' entries
1013 sMenuItemText.LoadString(IDS_SCIEDIT_COPY);
1014 popup.AppendMenu(MF_STRING | MF_ENABLED, WM_COPY, sMenuItemText);
1015 sMenuItemText.LoadString(IDS_SCIEDIT_SELECTALL);
1016 popup.AppendMenu(MF_STRING | MF_ENABLED, EM_SETSEL, sMenuItemText);
1017 sMenuItemText.LoadString(IDS_EDIT_NOTES);
1018 popup.AppendMenuIcon( CGitLogList::ID_EDITNOTE, sMenuItemText, IDI_EDIT);
1020 //if (selIndex >= 0)
1022 // popup.AppendMenu(MF_SEPARATOR);
1023 // sMenuItemText.LoadString(IDS_LOG_POPUP_EDITLOG);
1024 // popup.AppendMenu(MF_STRING | MF_ENABLED, CGitLogList::ID_EDITAUTHOR, sMenuItemText);
1027 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1028 switch (cmd)
1030 case 0:
1031 break; // no command selected
1032 case EM_SETSEL:
1033 case WM_COPY:
1034 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);
1035 break;
1036 case CGitLogList::ID_EDITNOTE:
1037 CAppUtils::EditNote(pRev);
1038 this->FillLogMessageCtrl(true);
1039 break;
1045 void CLogDlg::OnOK()
1047 // since the log dialog is also used to select revisions for other
1048 // dialogs, we have to do some work before closing this dialog
1049 if (GetFocus() != GetDlgItem(IDOK))
1050 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter
1052 m_LogList.SafeTerminateAsyncDiffThread();
1053 if (this->IsThreadRunning())
1055 m_LogList.SafeTerminateThread();
1057 UpdateData();
1058 // check that one and only one row is selected
1059 if (m_LogList.GetSelectedCount() == 1)
1061 // get the selected row
1062 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1063 int selIndex = m_LogList.GetNextSelectedItem(pos);
1064 if (selIndex < m_LogList.m_arShownList.GetCount())
1066 // all ok, pick up the revision
1067 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
1068 // extract the hash
1069 m_sSelectedHash = pLogEntry->m_CommitHash;
1072 UpdateData(FALSE);
1073 SaveSplitterPos();
1074 __super::OnOK();
1076 #if 0
1077 if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))
1078 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.
1080 CString temp;
1081 CString buttontext;
1082 GetDlgItemText(IDOK, buttontext);
1083 temp.LoadString(IDS_MSGBOX_CANCEL);
1084 if (temp.Compare(buttontext) != 0)
1085 __super::OnOK(); // only exit if the button text matches, and that will match only if the thread isn't running anymore
1086 m_bCancelled = TRUE;
1087 m_selectedRevs.Clear();
1088 m_selectedRevsOneRange.Clear();
1089 if (m_pNotifyWindow)
1091 int selIndex = m_LogList.GetSelectionMark();
1092 if (selIndex >= 0)
1094 PLOGENTRYDATA pLogEntry = NULL;
1095 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1096 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1097 m_selectedRevs.AddRevision(pLogEntry->Rev);
1098 git_revnum_t lowerRev = pLogEntry->Rev;
1099 git_revnum_t higherRev = lowerRev;
1100 while (pos)
1102 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1103 git_revnum_t rev = pLogEntry->Rev;
1104 m_selectedRevs.AddRevision(pLogEntry->Rev);
1105 if (lowerRev > rev)
1106 lowerRev = rev;
1107 if (higherRev < rev)
1108 higherRev = rev;
1110 if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())
1112 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);
1114 BOOL bSentMessage = FALSE;
1115 if (m_LogList.GetSelectedCount() == 1)
1117 // if only one revision is selected, check if the path/url with which the dialog was started
1118 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.
1119 // if it was copied, use the copy from revision as lowerRev
1120 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))
1122 CString sUrl = m_path.GetGitPathString();
1123 if (!m_path.IsUrl())
1125 sUrl = GetURLFromPath(m_path);
1127 sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());
1128 for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)
1130 LogChangedPath * pData = pLogEntry->pArChangedPaths->SafeGetAt(cp);
1131 if (pData)
1133 if (sUrl.Compare(pData->sPath) == 0)
1135 if (!pData->sCopyFromPath.IsEmpty())
1137 lowerRev = pData->lCopyFromRev;
1138 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);
1139 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);
1140 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1141 bSentMessage = TRUE;
1148 if ( !bSentMessage )
1150 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);
1151 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);
1152 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1153 if (m_selectedRevsOneRange.GetCount())
1154 m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);
1158 UpdateData();
1159 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry"));
1160 reg = m_btnShow.GetCurrentEntry();
1161 SaveSplitterPos();
1162 #endif
1165 void CLogDlg::OnNMDblclkChangedFileList(NMHDR * /*pNMHDR*/, LRESULT *pResult)
1167 // a double click on an entry in the changed-files list has happened
1168 *pResult = 0;
1170 DiffSelectedFile();
1173 void CLogDlg::DiffSelectedFile()
1175 #if 0
1176 if (m_bThreadRunning)
1177 return;
1178 UpdateLogInfoLabel();
1179 INT_PTR selIndex = m_ChangedFileListCtrl.GetSelectionMark();
1180 if (selIndex < 0)
1181 return;
1182 if (m_ChangedFileListCtrl.GetSelectedCount() == 0)
1183 return;
1184 // find out if there's an entry selected in the log list
1185 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1186 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1187 git_revnum_t rev1 = pLogEntry->Rev;
1188 git_revnum_t rev2 = rev1;
1189 if (pos)
1191 while (pos)
1193 // there's at least a second entry selected in the log list: several revisions selected!
1194 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1195 if (pLogEntry)
1197 rev1 = max(rev1,(long)pLogEntry->Rev);
1198 rev2 = min(rev2,(long)pLogEntry->Rev);
1201 rev2--;
1202 // now we have both revisions selected in the log list, so we can do a diff of the selected
1203 // entry in the changed files list with these two revisions.
1204 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1206 else
1208 rev2 = rev1-1;
1209 // nothing or only one revision selected in the log list
1210 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
1212 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
1214 // some items are hidden! So find out which item the user really clicked on
1215 INT_PTR selRealIndex = -1;
1216 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
1218 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1219 selRealIndex++;
1220 if (selRealIndex == selIndex)
1222 selIndex = hiddenindex;
1223 changedpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
1224 break;
1229 if (IsDiffPossible(changedpath, rev1))
1231 // diffs with renamed files are possible
1232 if ((changedpath)&&(!changedpath->sCopyFromPath.IsEmpty()))
1233 rev2 = changedpath->lCopyFromRev;
1234 else
1236 // if the path was modified but the parent path was 'added with history'
1237 // then we have to use the copy from revision of the parent path
1238 CTGitPath cpath = CTGitPath(changedpath->sPath);
1239 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
1241 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->SafeGetAt(flist)->sPath);
1242 if (p.IsAncestorOf(cpath))
1244 if (!pLogEntry->pArChangedPaths->SafeGetAt(flist)->sCopyFromPath.IsEmpty())
1245 rev2 = pLogEntry->pArChangedPaths->SafeGetAt(flist)->lCopyFromRev;
1249 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1251 else
1253 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1254 CTGitPath tempfile2 = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1255 GitRev r = rev1;
1256 // deleted files must be opened from the revision before the deletion
1257 if (changedpath->action == LOGACTIONS_DELETED)
1258 r = rev1-1;
1259 m_bCancelled = false;
1261 CProgressDlg progDlg;
1262 progDlg.SetTitle(IDS_APPNAME);
1263 progDlg.SetAnimation(IDR_DOWNLOAD);
1264 CString sInfoLine;
1265 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)(m_sRepositoryRoot + changedpath->sPath), (LPCTSTR)r.ToString());
1266 progDlg.SetLine(1, sInfoLine, true);
1267 SetAndClearProgressInfo(&progDlg);
1268 progDlg.ShowModeless(m_hWnd);
1270 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), r, r, tempfile))
1272 m_bCancelled = false;
1273 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), GitRev::REV_HEAD, r, tempfile))
1275 progDlg.Stop();
1276 SetAndClearProgressInfo((HWND)NULL);
1277 CMessageBox::Show(m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1278 return;
1281 progDlg.Stop();
1282 SetAndClearProgressInfo((HWND)NULL);
1284 CString sName1, sName2;
1285 sName1.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1);
1286 sName2.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1-1);
1287 CAppUtils::DiffFlags flags;
1288 flags.AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1289 if (changedpath->action == LOGACTIONS_DELETED)
1290 CAppUtils::StartExtDiff(tempfile, tempfile2, sName2, sName1, flags);
1291 else
1292 CAppUtils::StartExtDiff(tempfile2, tempfile, sName2, sName1, flags);
1295 #endif
1299 void CLogDlg::DoDiffFromLog(INT_PTR selIndex, GitRev* rev1, GitRev* rev2, bool /*blame*/, bool /*unified*/)
1301 DialogEnableWindow(IDOK, FALSE);
1302 // SetPromptApp(&theApp);
1303 theApp.DoWaitCursor(1);
1305 CString temppath;
1306 GetTempPath(temppath);
1308 CString file1;
1309 file1.Format(_T("%s%s_%s%s"),
1310 temppath,
1311 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1312 rev1->m_CommitHash.ToString().Left(6),
1313 (*m_currentChangedArray)[selIndex].GetFileExtension());
1315 CString file2;
1316 file2.Format(_T("%s\\%s_%s%s"),
1317 temppath,
1318 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1319 rev2->m_CommitHash.ToString().Left(6),
1320 (*m_currentChangedArray)[selIndex].GetFileExtension());
1322 CString cmd;
1324 g_Git.GetOneFile(rev1->m_CommitHash.ToString(), (CTGitPath &)(*m_currentChangedArray)[selIndex],file1);
1326 g_Git.GetOneFile(rev2->m_CommitHash.ToString(), (CTGitPath &)(*m_currentChangedArray)[selIndex],file2);
1328 CAppUtils::DiffFlags flags;
1329 CAppUtils::StartExtDiff(file1,file2,_T("A"),_T("B"),flags);
1331 #if 0
1332 //get the filename
1333 CString filepath;
1334 if (Git::PathIsURL(m_path))
1336 filepath = m_path.GetGitPathString();
1338 else
1340 filepath = GetURLFromPath(m_path);
1341 if (filepath.IsEmpty())
1343 theApp.DoWaitCursor(-1);
1344 CString temp;
1345 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1346 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1347 TRACE(_T("could not retrieve the URL of the file!\n"));
1348 EnableOKButton();
1349 theApp.DoWaitCursor(-11);
1350 return; //exit
1353 m_bCancelled = FALSE;
1354 filepath = GetRepositoryRoot(CTGitPath(filepath));
1356 CString firstfile, secondfile;
1357 if (m_LogList.GetSelectedCount()==1)
1359 int s = m_LogList.GetSelectionMark();
1360 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(s));
1361 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
1362 firstfile = changedpath->sPath;
1363 secondfile = firstfile;
1364 if ((rev2 == rev1-1)&&(changedpath->lCopyFromRev > 0)) // is it an added file with history?
1366 secondfile = changedpath->sCopyFromPath;
1367 rev2 = changedpath->lCopyFromRev;
1370 else
1372 firstfile = m_currentChangedPathList[selIndex].GetGitPathString();
1373 secondfile = firstfile;
1376 firstfile = filepath + firstfile.Trim();
1377 secondfile = filepath + secondfile.Trim();
1379 GitDiff diff(this, this->m_hWnd, true);
1380 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1381 diff.SetHEADPeg(m_LogRevision);
1382 if (unified)
1384 if (PromptShown())
1385 diff.ShowUnifiedDiff(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1);
1386 else
1387 CAppUtils::StartShowUnifiedDiff(m_hWnd, CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), m_LogRevision);
1389 else
1391 if (diff.ShowCompare(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), false, blame))
1393 if (firstfile.Compare(secondfile)==0)
1395 git_revnum_t baseRev = 0;
1396 diff.DiffProps(CTGitPath(firstfile), rev2, rev1, baseRev);
1401 #endif
1403 theApp.DoWaitCursor(-1);
1404 EnableOKButton();
1407 BOOL CLogDlg::Open(bool /*bOpenWith*/,CString changedpath, git_revnum_t rev)
1409 #if 0
1410 DialogEnableWindow(IDOK, FALSE);
1411 SetPromptApp(&theApp);
1412 theApp.DoWaitCursor(1);
1413 CString filepath;
1414 if (Git::PathIsURL(m_path))
1416 filepath = m_path.GetGitPathString();
1418 else
1420 filepath = GetURLFromPath(m_path);
1421 if (filepath.IsEmpty())
1423 theApp.DoWaitCursor(-1);
1424 CString temp;
1425 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1426 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1427 TRACE(_T("could not retrieve the URL of the file!\n"));
1428 EnableOKButton();
1429 return FALSE;
1432 m_bCancelled = false;
1433 filepath = GetRepositoryRoot(CTGitPath(filepath));
1434 filepath += changedpath;
1436 CProgressDlg progDlg;
1437 progDlg.SetTitle(IDS_APPNAME);
1438 progDlg.SetAnimation(IDR_DOWNLOAD);
1439 CString sInfoLine;
1440 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)GitRev(rev).ToString());
1441 progDlg.SetLine(1, sInfoLine, true);
1442 SetAndClearProgressInfo(&progDlg);
1443 progDlg.ShowModeless(m_hWnd);
1445 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(filepath), rev);
1446 m_bCancelled = false;
1447 if (!Cat(CTGitPath(filepath), GitRev(rev), rev, tempfile))
1449 progDlg.Stop();
1450 SetAndClearProgressInfo((HWND)NULL);
1451 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1452 EnableOKButton();
1453 theApp.DoWaitCursor(-1);
1454 return FALSE;
1456 progDlg.Stop();
1457 SetAndClearProgressInfo((HWND)NULL);
1458 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1459 if (!bOpenWith)
1461 int ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1462 if (ret <= HINSTANCE_ERROR)
1463 bOpenWith = true;
1465 if (bOpenWith)
1467 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1468 cmd += tempfile.GetWinPathString() + _T(" ");
1469 CAppUtils::LaunchApplication(cmd, NULL, false);
1471 EnableOKButton();
1472 theApp.DoWaitCursor(-1);
1473 #endif
1474 return TRUE;
1477 void CLogDlg::EditAuthor(const CLogDataVector& /*logs*/)
1479 #if 0
1480 CString url;
1481 CString name;
1482 if (logs.size() == 0)
1483 return;
1484 DialogEnableWindow(IDOK, FALSE);
1485 SetPromptApp(&theApp);
1486 theApp.DoWaitCursor(1);
1487 if (Git::PathIsURL(m_path))
1488 url = m_path.GetGitPathString();
1489 else
1491 url = GetURLFromPath(m_path);
1493 name = Git_PROP_REVISION_AUTHOR;
1495 CString value = RevPropertyGet(name, CTGitPath(url), logs[0]->Rev);
1496 CString sOldValue = value;
1497 value.Replace(_T("\n"), _T("\r\n"));
1498 CInputDlg dlg(this);
1499 dlg.m_sHintText.LoadString(IDS_LOG_AUTHOR);
1500 dlg.m_sInputText = value;
1501 dlg.m_sTitle.LoadString(IDS_LOG_AUTHOREDITTITLE);
1502 dlg.m_pProjectProperties = &m_ProjectProperties;
1503 dlg.m_bUseLogWidth = false;
1504 if (dlg.DoModal() == IDOK)
1506 dlg.m_sInputText.Remove('\r');
1508 LogCache::CCachedLogInfo* toUpdate = GetLogCache (CTGitPath (m_sRepositoryRoot));
1510 CProgressDlg progDlg;
1511 progDlg.SetTitle(IDS_APPNAME);
1512 progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));
1513 progDlg.SetTime(true);
1514 progDlg.SetShowProgressBar(true);
1515 progDlg.ShowModeless(m_hWnd);
1516 for (DWORD i=0; i<logs.size(); ++i)
1518 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), logs[i]->Rev))
1520 progDlg.Stop();
1521 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1522 break;
1524 else
1527 logs[i]->sAuthor = dlg.m_sInputText;
1528 m_LogList.Invalidate();
1530 // update the log cache
1532 if (toUpdate != NULL)
1534 // log caching is active
1536 LogCache::CCachedLogInfo newInfo;
1537 newInfo.Insert ( logs[i]->Rev
1538 , (const char*) CUnicodeUtils::GetUTF8 (logs[i]->sAuthor)
1539 , ""
1541 , LogCache::CRevisionInfoContainer::HAS_AUTHOR);
1543 toUpdate->Update (newInfo);
1546 progDlg.SetProgress64(i, logs.size());
1548 progDlg.Stop();
1550 theApp.DoWaitCursor(-1);
1551 EnableOKButton();
1552 #endif
1555 void CLogDlg::EditLogMessage(int /*index*/)
1558 #if 0
1559 CString url;
1560 CString name;
1561 DialogEnableWindow(IDOK, FALSE);
1562 SetPromptApp(&theApp);
1563 theApp.DoWaitCursor(1);
1564 if (Git::PathIsURL(m_path))
1565 url = m_path.GetGitPathString();
1566 else
1568 url = GetURLFromPath(m_path);
1570 name = Git_PROP_REVISION_LOG;
1572 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(index));
1573 m_bCancelled = FALSE;
1574 CString value = RevPropertyGet(name, CTGitPath(url), pLogEntry->Rev);
1575 CString sOldValue = value;
1576 value.Replace(_T("\n"), _T("\r\n"));
1577 CInputDlg dlg(this);
1578 dlg.m_sHintText.LoadString(IDS_LOG_MESSAGE);
1579 dlg.m_sInputText = value;
1580 dlg.m_sTitle.LoadString(IDS_LOG_MESSAGEEDITTITLE);
1581 dlg.m_pProjectProperties = &m_ProjectProperties;
1582 dlg.m_bUseLogWidth = true;
1583 if (dlg.DoModal() == IDOK)
1585 dlg.m_sInputText.Remove('\r');
1586 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), pLogEntry->Rev))
1588 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1590 else
1592 pLogEntry->sShortMessage = MakeShortMessage(dlg.m_sInputText);
1593 // split multi line log entries and concatenate them
1594 // again but this time with \r\n as line separators
1595 // so that the edit control recognizes them
1596 if (dlg.m_sInputText.GetLength()>0)
1598 m_sMessageBuf = dlg.m_sInputText;
1599 dlg.m_sInputText.Replace(_T("\n\r"), _T("\n"));
1600 dlg.m_sInputText.Replace(_T("\r\n"), _T("\n"));
1601 if (dlg.m_sInputText.Right(1).Compare(_T("\n"))==0)
1602 dlg.m_sInputText = dlg.m_sInputText.Left(dlg.m_sInputText.GetLength()-1);
1604 else
1605 dlg.m_sInputText.Empty();
1606 pLogEntry->sMessage = dlg.m_sInputText;
1607 pLogEntry->sBugIDs = m_ProjectProperties.FindBugID(dlg.m_sInputText);
1608 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
1609 pMsgView->SetWindowText(_T(" "));
1610 pMsgView->SetWindowText(dlg.m_sInputText);
1611 m_ProjectProperties.FindBugID(dlg.m_sInputText, pMsgView);
1612 m_LogList.Invalidate();
1614 // update the log cache
1615 LogCache::CCachedLogInfo* toUpdate = GetLogCache(CTGitPath (m_sRepositoryRoot));
1616 if (toUpdate != NULL)
1618 // log caching is active
1620 LogCache::CCachedLogInfo newInfo;
1621 newInfo.Insert( pLogEntry->Rev
1622 , ""
1623 , (const char*) CUnicodeUtils::GetUTF8 (pLogEntry->sMessage)
1625 , LogCache::CRevisionInfoContainer::HAS_COMMENT);
1627 toUpdate->Update(newInfo);
1631 theApp.DoWaitCursor(-1);
1632 EnableOKButton();
1633 #endif
1636 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)
1638 // Skip Ctrl-C when copying text out of the log message or search filter
1639 BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );
1640 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
1642 if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1644 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1646 m_LogList.DiffSelectedRevWithPrevious();
1647 return TRUE;
1651 if (m_hAccel && !bSkipAccelerator)
1653 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1654 if (ret)
1655 return TRUE;
1658 if(::IsWindow(m_tooltips.m_hWnd))
1659 m_tooltips.RelayEvent(pMsg);
1660 return __super::PreTranslateMessage(pMsg);
1664 BOOL CLogDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1666 //if (this->IsThreadRunning())
1667 if(m_LogList.m_bNoDispUpdates)
1669 // only show the wait cursor over the list control
1670 if ((pWnd)&&
1671 ((pWnd == GetDlgItem(IDC_LOGLIST))||
1672 (pWnd == GetDlgItem(IDC_MSGVIEW))||
1673 (pWnd == GetDlgItem(IDC_LOGMSG))))
1675 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1676 SetCursor(hCur);
1677 return TRUE;
1680 if ((pWnd) && (pWnd == GetDlgItem(IDC_MSGVIEW)))
1681 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1683 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1684 SetCursor(hCur);
1685 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1688 void CLogDlg::OnBnClickedHelp()
1690 OnHelp();
1693 void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1695 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1696 *pResult = 0;
1697 //if (this->IsThreadRunning())
1698 if(m_LogList.m_bNoDispUpdates)
1699 return;
1700 if (pNMLV->iItem >= 0)
1702 this->m_LogList.m_nSearchIndex = pNMLV->iItem;
1703 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(pNMLV->iItem));
1704 m_LogList.m_lastSelectedHash = pLogEntry->m_CommitHash;
1705 if (pNMLV->iSubItem != 0)
1706 return;
1707 if ((pNMLV->iItem == m_LogList.m_arShownList.GetCount()))
1709 // remove the selected state
1710 if (pNMLV->uChanged & LVIF_STATE)
1712 m_LogList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);
1713 FillLogMessageCtrl();
1714 UpdateData(FALSE);
1715 UpdateLogInfoLabel();
1717 return;
1719 if (pNMLV->uChanged & LVIF_STATE)
1721 FillLogMessageCtrl();
1722 UpdateData(FALSE);
1725 else
1727 m_LogList.m_lastSelectedHash.Empty();
1728 FillLogMessageCtrl();
1729 UpdateData(FALSE);
1731 EnableOKButton();
1732 UpdateLogInfoLabel();
1735 void CLogDlg::OnEnLinkMsgview(NMHDR *pNMHDR, LRESULT *pResult)
1737 ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);
1738 if (pEnLink->msg == WM_LBUTTONUP)
1740 CString url, msg;
1741 GetDlgItemText(IDC_MSGVIEW, msg);
1742 msg.Replace(_T("\r\n"), _T("\n"));
1743 url = msg.Mid(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax-pEnLink->chrg.cpMin);
1744 if (!::PathIsURL(url))
1746 url = m_LogList.m_ProjectProperties.GetBugIDUrl(url);
1747 url = GetAbsoluteUrlFromRelativeUrl(url);
1749 if (!url.IsEmpty())
1750 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
1752 *pResult = 0;
1755 class CDateSorter
1757 public:
1758 class CCommitPointer
1760 public:
1761 CCommitPointer():m_cont(NULL){}
1762 CCommitPointer(const CCommitPointer& P_Right)
1763 : m_cont(NULL)
1765 *this = P_Right;
1768 CCommitPointer& operator = (const CCommitPointer& P_Right)
1770 if(IsPointer())
1772 (*m_cont->m_parDates)[m_place] = P_Right.GetDate();
1773 (*m_cont->m_parFileChanges)[m_place] = P_Right.GetChanges();
1774 (*m_cont->m_parAuthors)[m_place] = P_Right.GetAuthor();
1776 else
1778 m_Date = P_Right.GetDate();
1779 m_Changes = P_Right.GetChanges();
1780 m_csAuthor = P_Right.GetAuthor();
1782 return *this;
1785 void Clone(const CCommitPointer& P_Right)
1787 m_cont = P_Right.m_cont;
1788 m_place = P_Right.m_place;
1789 m_Date = P_Right.m_Date;
1790 m_Changes = P_Right.m_Changes;
1791 m_csAuthor = P_Right.m_csAuthor;
1794 DWORD GetDate() const {return IsPointer() ? (*m_cont->m_parDates)[m_place] : m_Date;}
1795 DWORD GetChanges() const {return IsPointer() ? (*m_cont->m_parFileChanges)[m_place] : m_Changes;}
1796 CString GetAuthor() const {return IsPointer() ? (*m_cont->m_parAuthors)[m_place] : m_csAuthor;}
1798 bool IsPointer() const {return m_cont != NULL;}
1799 //When pointer
1800 CDateSorter* m_cont;
1801 int m_place;
1803 //When element
1804 DWORD m_Date;
1805 DWORD m_Changes;
1806 CString m_csAuthor;
1809 class iterator : public std::iterator<std::random_access_iterator_tag, CCommitPointer>
1811 public:
1812 CCommitPointer m_ptr;
1814 iterator(){}
1815 iterator(const iterator& P_Right){*this = P_Right;}
1816 iterator& operator=(const iterator& P_Right)
1818 m_ptr.Clone(P_Right.m_ptr);
1819 return *this;
1822 CCommitPointer& operator*(){return m_ptr;}
1823 CCommitPointer* operator->(){return &m_ptr;}
1824 const CCommitPointer& operator*()const{return m_ptr;}
1825 const CCommitPointer* operator->()const{return &m_ptr;}
1827 iterator& operator+=(size_t P_iOffset){m_ptr.m_place += P_iOffset;return *this;}
1828 iterator& operator-=(size_t P_iOffset){m_ptr.m_place -= P_iOffset;return *this;}
1829 iterator operator+(size_t P_iOffset)const{iterator it(*this); it += P_iOffset;return it;}
1830 iterator operator-(size_t P_iOffset)const{iterator it(*this); it -= P_iOffset;return it;}
1832 iterator& operator++(){++m_ptr.m_place;return *this;}
1833 iterator& operator--(){--m_ptr.m_place;return *this;}
1834 iterator operator++(int){iterator it(*this);++*this;return it;}
1835 iterator operator--(int){iterator it(*this);--*this;return it;}
1837 size_t operator-(const iterator& P_itRight)const{return m_ptr.m_place - P_itRight->m_place;}
1839 bool operator<(const iterator& P_itRight)const{return m_ptr.m_place < P_itRight->m_place;}
1840 bool operator!=(const iterator& P_itRight)const{return m_ptr.m_place != P_itRight->m_place;}
1841 bool operator==(const iterator& P_itRight)const{return m_ptr.m_place == P_itRight->m_place;}
1842 bool operator>(const iterator& P_itRight)const{return m_ptr.m_place > P_itRight->m_place;}
1844 iterator begin()
1846 iterator it;
1847 it->m_place = 0;
1848 it->m_cont = this;
1849 return it;
1851 iterator end()
1853 iterator it;
1854 it->m_place = m_parDates->GetCount();
1855 it->m_cont = this;
1856 return it;
1859 CDWordArray * m_parDates;
1860 CDWordArray * m_parFileChanges;
1861 CStringArray * m_parAuthors;
1864 class CDateSorterLess
1866 public:
1867 bool operator () (const CDateSorter::CCommitPointer& P_Left, const CDateSorter::CCommitPointer& P_Right) const
1869 return P_Left.GetDate() > P_Right.GetDate(); //Last date first
1876 void CLogDlg::OnBnClickedStatbutton()
1878 if (this->IsThreadRunning())
1879 return;
1880 if (m_LogList.m_arShownList.IsEmpty())
1881 return; // nothing is shown, so no statistics.
1882 // the statistics dialog expects the log entries to be sorted by date
1883 SortByColumn(3, false);
1884 CThreadSafePtrArray shownlist(NULL);
1885 m_LogList.RecalculateShownList(&shownlist);
1886 // create arrays which are aware of the current filter
1887 CStringArray m_arAuthorsFiltered;
1888 CDWordArray m_arDatesFiltered;
1889 CDWordArray m_arFileChangesFiltered;
1890 for (INT_PTR i=0; i<shownlist.GetCount(); ++i)
1892 GitRev* pLogEntry = reinterpret_cast<GitRev*>(shownlist.SafeGetAt(i));
1894 // do not take working dir changes into statistics
1895 if (pLogEntry->m_CommitHash.IsEmpty()) {
1896 continue;
1899 CString strAuthor = pLogEntry->GetAuthorName();
1900 if ( strAuthor.IsEmpty() )
1902 strAuthor.LoadString(IDS_STATGRAPH_EMPTYAUTHOR);
1904 m_arAuthorsFiltered.Add(strAuthor);
1905 m_arDatesFiltered.Add(pLogEntry->GetAuthorDate().GetTime());
1906 m_arFileChangesFiltered.Add(pLogEntry->GetFiles(&m_LogList).GetCount());
1909 CDateSorter W_Sorter;
1910 W_Sorter.m_parAuthors = &m_arAuthorsFiltered;
1911 W_Sorter.m_parDates = &m_arDatesFiltered;
1912 W_Sorter.m_parFileChanges = &m_arFileChangesFiltered;
1913 std::sort(W_Sorter.begin(), W_Sorter.end(), CDateSorterLess());
1915 CStatGraphDlg dlg;
1916 dlg.m_parAuthors = &m_arAuthorsFiltered;
1917 dlg.m_parDates = &m_arDatesFiltered;
1918 dlg.m_parFileChanges = &m_arFileChangesFiltered;
1919 dlg.m_path = m_orgPath;
1920 dlg.DoModal();
1921 // restore the previous sorting
1922 SortByColumn(m_nSortColumn, m_bAscending);
1923 OnTimer(LOGFILTER_TIMER);
1926 void CLogDlg::DoSizeV1(int delta)
1929 RemoveAnchor(IDC_LOGLIST);
1930 RemoveAnchor(IDC_SPLITTERTOP);
1931 RemoveAnchor(IDC_MSGVIEW);
1932 RemoveAnchor(IDC_SPLITTERBOTTOM);
1933 RemoveAnchor(IDC_LOGMSG);
1934 CSplitterControl::ChangeHeight(&m_LogList, delta, CW_TOPALIGN);
1935 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), -delta, CW_BOTTOMALIGN);
1936 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1937 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1938 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1939 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1940 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1941 ArrangeLayout();
1942 AdjustMinSize();
1943 SetSplitterRange();
1944 m_LogList.Invalidate();
1945 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1949 void CLogDlg::DoSizeV2(int delta)
1952 RemoveAnchor(IDC_LOGLIST);
1953 RemoveAnchor(IDC_SPLITTERTOP);
1954 RemoveAnchor(IDC_MSGVIEW);
1955 RemoveAnchor(IDC_SPLITTERBOTTOM);
1956 RemoveAnchor(IDC_LOGMSG);
1957 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), delta, CW_TOPALIGN);
1958 CSplitterControl::ChangeHeight(&m_ChangedFileListCtrl, -delta, CW_BOTTOMALIGN);
1959 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1960 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1961 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1962 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1963 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1964 ArrangeLayout();
1965 AdjustMinSize();
1966 SetSplitterRange();
1967 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1968 m_ChangedFileListCtrl.Invalidate();
1972 void CLogDlg::AdjustMinSize()
1974 // adjust the minimum size of the dialog to prevent the resizing from
1975 // moving the list control too far down.
1976 CRect rcChgListView;
1977 m_ChangedFileListCtrl.GetClientRect(rcChgListView);
1978 CRect rcLogList;
1979 m_LogList.GetClientRect(rcLogList);
1981 SetMinTrackSize(CSize(m_DlgOrigRect.Width(),
1982 m_DlgOrigRect.Height()-m_ChgOrigRect.Height()-m_LogListOrigRect.Height()-m_MsgViewOrigRect.Height()
1983 +rcChgListView.Height()+rcLogList.Height()+60));
1986 LRESULT CLogDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1988 switch (message) {
1989 case WM_NOTIFY:
1990 if (wParam == IDC_SPLITTERTOP)
1992 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1993 DoSizeV1(pHdr->delta);
1995 else if (wParam == IDC_SPLITTERBOTTOM)
1997 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1998 DoSizeV2(pHdr->delta);
2000 break;
2003 return CResizableDialog::DefWindowProc(message, wParam, lParam);
2006 void CLogDlg::SetSplitterRange()
2008 if ((m_LogList)&&(m_ChangedFileListCtrl))
2010 CRect rcTop;
2011 m_LogList.GetWindowRect(rcTop);
2012 ScreenToClient(rcTop);
2013 CRect rcMiddle;
2014 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(rcMiddle);
2015 ScreenToClient(rcMiddle);
2016 m_wndSplitter1.SetRange(rcTop.top+30, rcMiddle.bottom-20);
2017 CRect rcBottom;
2018 m_ChangedFileListCtrl.GetWindowRect(rcBottom);
2019 ScreenToClient(rcBottom);
2020 m_wndSplitter2.SetRange(rcMiddle.top+30, rcBottom.bottom-20);
2024 LRESULT CLogDlg::OnClickedInfoIcon(WPARAM /*wParam*/, LPARAM lParam)
2026 // FIXME: x64 version would get this function called with unexpected parameters.
2027 if (!lParam)
2028 return 0;
2030 RECT * rect = (LPRECT)lParam;
2031 CPoint point;
2032 CString temp;
2033 point = CPoint(rect->left, rect->bottom);
2034 #define LOGMENUFLAGS(x) (MF_STRING | MF_ENABLED | (m_LogList.m_nSelectedFilter == x ? MF_CHECKED : MF_UNCHECKED))
2035 CMenu popup;
2036 if (popup.CreatePopupMenu())
2038 temp.LoadString(IDS_LOG_FILTER_ALL);
2039 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_ALL), LOGFILTER_ALL, temp);
2041 popup.AppendMenu(MF_SEPARATOR, NULL);
2043 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2044 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_MESSAGES), LOGFILTER_MESSAGES, temp);
2046 temp.LoadString(IDS_LOG_FILTER_PATHS);
2047 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_PATHS), LOGFILTER_PATHS, temp);
2049 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2050 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_AUTHORS), LOGFILTER_AUTHORS, temp);
2052 temp.LoadString(IDS_LOG_FILTER_REVS);
2053 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REVS), LOGFILTER_REVS, temp);
2055 if (m_LogList.m_bShowBugtraqColumn == true) {
2056 temp.LoadString(IDS_LOG_FILTER_BUGIDS);
2057 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_BUGID), LOGFILTER_BUGID, temp);
2060 popup.AppendMenu(MF_SEPARATOR, NULL);
2062 temp.LoadString(IDS_LOG_FILTER_REGEX);
2063 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterWithRegex ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_REGEX, temp);
2065 m_tooltips.Pop();
2066 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2067 if (selection != 0)
2070 if (selection == LOGFILTER_REGEX)
2072 m_bFilterWithRegex = !m_bFilterWithRegex;
2073 CRegDWORD b = CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
2074 b = m_bFilterWithRegex;
2075 m_LogList.m_bFilterWithRegex = m_bFilterWithRegex;
2076 SetFilterCueText();
2077 CheckRegexpTooltip();
2079 else
2081 m_LogList.m_nSelectedFilter = selection;
2082 SetFilterCueText();
2084 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2087 return 0L;
2090 LRESULT CLogDlg::OnClickedCancelFilter(WPARAM /*wParam*/, LPARAM /*lParam*/)
2093 KillTimer(LOGFILTER_TIMER);
2095 m_LogList.m_sFilterText.Empty();
2096 UpdateData(FALSE);
2097 theApp.DoWaitCursor(1);
2098 CStoreSelection storeselection(this);
2099 FillLogMessageCtrl(false);
2101 m_LogList.RemoveFilter();
2103 Refresh();
2105 CTime begin,end;
2106 m_LogList.GetTimeRange(begin,end);
2107 m_DateFrom.SetTime(&begin);
2108 m_DateTo.SetTime(&end);
2110 theApp.DoWaitCursor(-1);
2111 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2112 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2113 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2114 UpdateLogInfoLabel();
2116 return 0L;
2120 void CLogDlg::SetFilterCueText()
2122 CString temp;
2123 switch (m_LogList.m_nSelectedFilter)
2125 case LOGFILTER_ALL:
2126 temp.LoadString(IDS_LOG_FILTER_ALL);
2127 break;
2128 case LOGFILTER_MESSAGES:
2129 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2130 break;
2131 case LOGFILTER_PATHS:
2132 temp.LoadString(IDS_LOG_FILTER_PATHS);
2133 break;
2134 case LOGFILTER_AUTHORS:
2135 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2136 break;
2137 case LOGFILTER_REVS:
2138 temp.LoadString(IDS_LOG_FILTER_REVS);
2139 break;
2141 // to make the cue banner text appear more to the right of the edit control
2142 temp = _T(" ")+temp;
2143 m_cFilter.SetCueBanner(temp);
2146 bool CLogDlg::Validate(LPCTSTR string)
2148 if (!m_bFilterWithRegex)
2149 return true;
2150 tr1::wregex pat;
2151 return m_LogList.ValidateRegexp(string, pat, false);
2155 void CLogDlg::OnTimer(UINT_PTR nIDEvent)
2157 if (nIDEvent == LOGFTIME_TIMER)
2159 KillTimer(LOGFTIME_TIMER);
2160 m_limit = 0;
2161 m_LogList.Refresh(FALSE);
2162 FillLogMessageCtrl(false);
2165 if (nIDEvent == LOGFILTER_TIMER)
2167 KillTimer(LOGFILTER_TIMER);
2168 m_limit = 0;
2169 m_LogList.Refresh(FALSE);
2170 FillLogMessageCtrl(false);
2172 #if 0
2173 /* we will use git built-in grep to filter log */
2174 if (this->IsThreadRunning())
2176 // thread still running! So just restart the timer.
2177 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2178 return;
2180 CWnd * focusWnd = GetFocus();
2181 bool bSetFocusToFilterControl = ((focusWnd != GetDlgItem(IDC_DATEFROM))&&(focusWnd != GetDlgItem(IDC_DATETO))
2182 && (focusWnd != GetDlgItem(IDC_LOGLIST)));
2183 if (m_LogList.m_sFilterText.IsEmpty())
2185 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2186 // do not return here!
2187 // we also need to run the filter if the filter text is empty:
2188 // 1. to clear an existing filter
2189 // 2. to rebuild the m_arShownList after sorting
2191 theApp.DoWaitCursor(1);
2192 CStoreSelection storeselection(this);
2193 KillTimer(LOGFILTER_TIMER);
2194 FillLogMessageCtrl(false);
2196 // now start filter the log list
2197 m_LogList.StartFilter();
2199 if ( m_LogList.GetItemCount()==1 )
2201 m_LogList.SetSelectionMark(0);
2202 m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
2204 theApp.DoWaitCursor(-1);
2205 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2206 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2207 if (bSetFocusToFilterControl)
2208 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2209 UpdateLogInfoLabel();
2210 #endif
2211 } // if (nIDEvent == LOGFILTER_TIMER)
2212 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2213 __super::OnTimer(nIDEvent);
2216 void CLogDlg::OnDtnDatetimechangeDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2220 CTime _time;
2221 m_DateTo.GetTime(_time);
2223 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 23, 59, 59);
2224 if (time.GetTime() != m_LogList.m_To)
2226 m_LogList.m_To = (DWORD)time.GetTime();
2227 SetTimer(LOGFTIME_TIMER, 10, NULL);
2230 catch (...)
2232 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2235 *pResult = 0;
2238 void CLogDlg::OnDtnDatetimechangeDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2243 CTime _time;
2244 m_DateFrom.GetTime(_time);
2246 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 0, 0, 0);
2247 if (time.GetTime() != m_LogList.m_From)
2249 m_LogList.m_From = (DWORD)time.GetTime();
2250 SetTimer(LOGFTIME_TIMER, 10, NULL);
2253 catch (...)
2255 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2258 *pResult = 0;
2263 CTGitPathList CLogDlg::GetChangedPathsFromSelectedRevisions(bool /*bRelativePaths*/ /* = false */, bool /*bUseFilter*/ /* = true */)
2265 CTGitPathList pathList;
2266 #if 0
2268 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2270 m_sRepositoryRoot = GetRepositoryRoot(m_path);
2272 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2273 return pathList;
2275 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2276 if (pos != NULL)
2278 while (pos)
2280 int nextpos = m_LogList.GetNextSelectedItem(pos);
2281 if (nextpos >= m_arShownList.GetCount())
2282 continue;
2283 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(nextpos));
2284 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2285 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
2287 LogChangedPath * cpath = cpatharray->SafeGetAt(cpPathIndex);
2288 if (cpath == NULL)
2289 continue;
2290 CTGitPath path;
2291 if (!bRelativePaths)
2292 path.SetFromGit(m_sRepositoryRoot);
2293 path.AppendPathString(cpath->sPath);
2294 if ((!bUseFilter)||
2295 ((m_cHidePaths.GetState() & 0x0003)!=BST_CHECKED)||
2296 (cpath->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0))
2297 pathList.AddPath(path);
2302 pathList.RemoveDuplicates();
2303 #endif
2304 return pathList;
2307 void CLogDlg::SortByColumn(int /*nSortColumn*/, bool /*bAscending*/)
2309 #if 0
2310 switch(nSortColumn)
2312 case 0: // Revision
2314 if(bAscending)
2315 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscRevSort());
2316 else
2317 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescRevSort());
2319 break;
2320 case 1: // action
2322 if(bAscending)
2323 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscActionSort());
2324 else
2325 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescActionSort());
2327 break;
2328 case 2: // Author
2330 if(bAscending)
2331 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscAuthorSort());
2332 else
2333 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescAuthorSort());
2335 break;
2336 case 3: // Date
2338 if(bAscending)
2339 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscDateSort());
2340 else
2341 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescDateSort());
2343 break;
2344 case 4: // Message or bug id
2345 if (m_bShowBugtraqColumn)
2347 if(bAscending)
2348 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscBugIDSort());
2349 else
2350 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescBugIDSort());
2351 break;
2353 // fall through here
2354 case 5: // Message
2356 if(bAscending)
2357 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscMessageSort());
2358 else
2359 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescMessageSort());
2361 break;
2362 default:
2363 ATLASSERT(0);
2364 break;
2366 #endif
2369 void CLogDlg::OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult)
2371 if (this->IsThreadRunning())
2372 return; //no sorting while the arrays are filled
2373 #if 0
2374 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2375 const int nColumn = pNMLV->iSubItem;
2376 m_bAscending = nColumn == m_nSortColumn ? !m_bAscending : TRUE;
2377 m_nSortColumn = nColumn;
2378 SortByColumn(m_nSortColumn, m_bAscending);
2379 SetSortArrow(&m_LogList, m_nSortColumn, !!m_bAscending);
2380 SortShownListArray();
2381 m_LogList.Invalidate();
2382 UpdateLogInfoLabel();
2383 #else
2384 UNREFERENCED_PARAMETER(pNMHDR);
2385 #endif
2386 *pResult = 0;
2389 void CLogDlg::SortShownListArray()
2391 // make sure the shown list still matches the filter after sorting.
2392 OnTimer(LOGFILTER_TIMER);
2393 // clear the selection states
2394 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2395 while (pos)
2397 m_LogList.SetItemState(m_LogList.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
2399 m_LogList.SetSelectionMark(-1);
2402 void CLogDlg::SetSortArrow(CListCtrl * control, int nColumn, bool bAscending)
2404 if (control == NULL)
2405 return;
2406 // set the sort arrow
2407 CHeaderCtrl * pHeader = control->GetHeaderCtrl();
2408 HDITEM HeaderItem = {0};
2409 HeaderItem.mask = HDI_FORMAT;
2410 for (int i=0; i<pHeader->GetItemCount(); ++i)
2412 pHeader->GetItem(i, &HeaderItem);
2413 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
2414 pHeader->SetItem(i, &HeaderItem);
2416 if (nColumn >= 0)
2418 pHeader->GetItem(nColumn, &HeaderItem);
2419 HeaderItem.fmt |= (bAscending ? HDF_SORTUP : HDF_SORTDOWN);
2420 pHeader->SetItem(nColumn, &HeaderItem);
2423 void CLogDlg::OnLvnColumnclickChangedFileList(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
2425 #if 0
2426 if (this->IsThreadRunning())
2427 return; //no sorting while the arrays are filled
2428 if (m_currentChangedArray == NULL)
2429 return;
2430 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2431 const int nColumn = pNMLV->iSubItem;
2432 m_bAscendingPathList = nColumn == m_nSortColumnPathList ? !m_bAscendingPathList : TRUE;
2433 m_nSortColumnPathList = nColumn;
2434 // qsort(m_currentChangedArray->GetData(), m_currentChangedArray->GetSize(), sizeof(LogChangedPath*), (GENERICCOMPAREFN)SortCompare);
2436 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
2437 m_ChangedFileListCtrl.Invalidate();
2438 *pResult = 0;
2439 #endif
2442 int CLogDlg::m_nSortColumnPathList = 0;
2443 bool CLogDlg::m_bAscendingPathList = false;
2445 int CLogDlg::SortCompare(const void * /*pElem1*/, const void * /*pElem2*/)
2447 #if 0
2448 LogChangedPath * cpath1 = *((LogChangedPath**)pElem1);
2449 LogChangedPath * cpath2 = *((LogChangedPath**)pElem2);
2451 if (m_bAscendingPathList)
2452 std::swap (cpath1, cpath2);
2454 int cmp = 0;
2455 switch (m_nSortColumnPathList)
2457 case 0: // action
2458 cmp = cpath2->GetAction().Compare(cpath1->GetAction());
2459 if (cmp)
2460 return cmp;
2461 // fall through
2462 case 1: // path
2463 cmp = cpath2->sPath.CompareNoCase(cpath1->sPath);
2464 if (cmp)
2465 return cmp;
2466 // fall through
2467 case 2: // copy from path
2468 cmp = cpath2->sCopyFromPath.Compare(cpath1->sCopyFromPath);
2469 if (cmp)
2470 return cmp;
2471 // fall through
2472 case 3: // copy from revision
2473 return cpath2->lCopyFromRev > cpath1->lCopyFromRev;
2475 #endif
2476 return 0;
2479 void CLogDlg::OnBnClickedHidepaths()
2481 FillLogMessageCtrl();
2482 m_ChangedFileListCtrl.Invalidate();
2487 void CLogDlg::OnBnClickedCheckStoponcopy()
2489 #if 0
2490 if (!GetDlgItem(IDC_GETALL)->IsWindowEnabled())
2491 return;
2493 // ignore old fetch limits when switching
2494 // between copy-following and stop-on-copy
2495 // (otherwise stop-on-copy will limit what
2496 // we see immediately after switching to
2497 // copy-following)
2499 m_endrev = 0;
2501 // now, restart the query
2502 #endif
2503 Refresh();
2507 void CLogDlg::UpdateLogInfoLabel()
2510 CGitHash rev1 ;
2511 CGitHash rev2 ;
2512 long selectedrevs = 0;
2513 int count =m_LogList.m_arShownList.GetCount();
2514 int start = 0;
2515 if (count)
2517 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(0)))->m_CommitHash;
2518 if(this->m_LogList.m_bShowWC && rev1.IsEmpty()&&(count>1))
2519 start = 1;
2520 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(start)))->m_CommitHash;
2521 //pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_arShownList.GetCount()-1));
2522 rev2 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(count-1)))->m_CommitHash;
2523 selectedrevs = m_LogList.GetSelectedCount();
2525 CString sTemp;
2526 sTemp.Format(_T("Showing %ld revision(s), from revision %s to revision %s - %ld revision(s) selected\r\n"),
2527 count - start,
2528 rev2.ToString().Left(6), rev1.ToString().Left(6), selectedrevs);
2530 if(selectedrevs == 1)
2532 CString str=m_ChangedFileListCtrl.GetStatisticsString(true);
2533 str.Replace(_T('\n'), _T(' '));
2534 sTemp += str;
2536 m_sLogInfo = sTemp;
2538 UpdateData(FALSE);
2541 #if 0
2542 void CLogDlg::ShowContextMenuForChangedpaths(CWnd* /*pWnd*/, CPoint point)
2545 int selIndex = m_ChangedFileListCtrl.GetSelectionMark();
2546 if ((point.x == -1) && (point.y == -1))
2548 CRect rect;
2549 m_ChangedFileListCtrl.GetItemRect(selIndex, &rect, LVIR_LABEL);
2550 m_ChangedFileListCtrl.ClientToScreen(&rect);
2551 point = rect.CenterPoint();
2553 if (selIndex < 0)
2554 return;
2555 int s = m_LogList.GetSelectionMark();
2556 if (s < 0)
2557 return;
2558 std::vector<CString> changedpaths;
2559 std::vector<LogChangedPath*> changedlogpaths;
2560 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2561 if (pos == NULL)
2562 return; // nothing is selected, get out of here
2564 bool bOneRev = true;
2565 int sel=m_LogList.GetNextSelectedItem(pos);
2566 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(sel));
2567 GitRev * rev1 = pLogEntry;
2568 GitRev * rev2 = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(sel+1));
2569 #if 0
2570 bool bOneRev = true;
2571 if (pos)
2573 while (pos)
2575 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2576 if (pLogEntry)
2578 rev1 = max(rev1,(git_revnum_t)pLogEntry->Rev);
2579 rev2 = min(rev2,(git_revnum_t)pLogEntry->Rev);
2580 bOneRev = false;
2583 if (!bOneRev)
2584 rev2--;
2585 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
2586 while (pos)
2588 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
2589 changedpaths.push_back(m_currentChangedPathList[nItem].GetGitPathString());
2592 else
2594 // only one revision is selected in the log dialog top pane
2595 // but multiple items could be selected in the changed items list
2596 rev2 = rev1-1;
2598 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
2599 while (pos)
2601 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
2602 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(nItem);
2604 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
2606 if ((changedlogpath)&&(!changedlogpath->sCopyFromPath.IsEmpty()))
2607 rev2 = changedlogpath->lCopyFromRev;
2608 else
2610 // if the path was modified but the parent path was 'added with history'
2611 // then we have to use the copy from revision of the parent path
2612 CTGitPath cpath = CTGitPath(changedlogpath->sPath);
2613 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
2615 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->SafeGetAt(flist)->sPath);
2616 if (p.IsAncestorOf(cpath))
2618 if (!pLogEntry->pArChangedPaths->SafeGetAt(flist)->sCopyFromPath.IsEmpty())
2619 rev2 = pLogEntry->pArChangedPaths->SafeGetAt(flist)->lCopyFromRev;
2624 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
2626 // some items are hidden! So find out which item the user really clicked on
2627 INT_PTR selRealIndex = -1;
2628 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
2630 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2631 selRealIndex++;
2632 if (selRealIndex == nItem)
2634 selIndex = hiddenindex;
2635 changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
2636 break;
2640 if (changedlogpath)
2642 changedpaths.push_back(changedlogpath->sPath);
2643 changedlogpaths.push_back(changedlogpath);
2647 #endif
2648 //entry is selected, now show the popup menu
2649 CIconMenu popup;
2650 if (popup.CreatePopupMenu())
2652 bool bEntryAdded = false;
2653 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
2655 // if ((!bOneRev)||(IsDiffPossible(changedlogpaths[0], rev1)))
2657 popup.AppendMenuIcon(CGitLogList::ID_DIFF, IDS_LOG_POPUP_DIFF, IDI_DIFF);
2658 popup.AppendMenuIcon(CGitLogList::ID_BLAMEDIFF, IDS_LOG_POPUP_BLAMEDIFF, IDI_BLAME);
2659 popup.SetDefaultItem(CGitLogList::ID_DIFF, FALSE);
2660 popup.AppendMenuIcon(CGitLogList::ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
2661 bEntryAdded = true;
2663 // if (rev2 == rev1-1)
2665 if (bEntryAdded)
2666 popup.AppendMenu(MF_SEPARATOR, NULL);
2667 popup.AppendMenuIcon(CGitLogList::ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
2668 popup.AppendMenuIcon(CGitLogList::ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
2669 popup.AppendMenuIcon(CGitLogList::ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
2670 popup.AppendMenu(MF_SEPARATOR, NULL);
2671 if (m_hasWC)
2672 popup.AppendMenuIcon(CGitLogList::ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2673 popup.AppendMenuIcon(CGitLogList::ID_POPPROPS, IDS_REPOBROWSE_SHOWPROP, IDI_PROPERTIES); // "Show Properties"
2674 popup.AppendMenuIcon(CGitLogList::ID_LOG, IDS_MENULOG, IDI_LOG); // "Show Log"
2675 popup.AppendMenuIcon(CGitLogList::ID_GETMERGELOGS, IDS_LOG_POPUP_GETMERGELOGS, IDI_LOG); // "Show merge log"
2676 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
2677 bEntryAdded = true;
2678 if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2680 popup.AppendMenu(MF_SEPARATOR, NULL);
2681 popup.AppendMenuIcon(CGitLogList::ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2683 if (popup.GetDefaultItem(0,FALSE)==-1)
2684 popup.SetDefaultItem(CGitLogList::ID_OPEN, FALSE);
2687 else if (changedlogpaths.size())
2689 // more than one entry is selected
2690 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE);
2691 bEntryAdded = true;
2694 if (!bEntryAdded)
2695 return;
2696 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2697 bool bOpenWith = false;
2698 bool bMergeLog = false;
2699 m_bCancelled = false;
2701 switch (cmd)
2703 case CGitLogList::ID_DIFF:
2705 DoDiffFromLog(selIndex, rev1, rev2, false, false);
2707 break;
2708 #if 0
2709 case ID_BLAMEDIFF:
2711 DoDiffFromLog(selIndex, rev1, rev2, true, false);
2713 break;
2714 case ID_GNUDIFF1:
2716 DoDiffFromLog(selIndex, rev1, rev2, false, true);
2718 break;
2719 case ID_REVERTREV:
2721 SetPromptApp(&theApp);
2722 theApp.DoWaitCursor(1);
2723 CString sUrl;
2724 if (Git::PathIsURL(m_path))
2726 sUrl = m_path.GetGitPathString();
2728 else
2730 sUrl = GetURLFromPath(m_path);
2731 if (sUrl.IsEmpty())
2733 theApp.DoWaitCursor(-1);
2734 CString temp;
2735 temp.Format(IDS_ERR_NOURLOFFILE, m_path.GetWinPath());
2736 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2737 EnableOKButton();
2738 theApp.DoWaitCursor(-1);
2739 break; //exit
2742 // find the working copy path of the selected item from the URL
2743 m_bCancelled = false;
2744 CString sUrlRoot = GetRepositoryRoot(CTGitPath(sUrl));
2746 CString fileURL = changedpaths[0];
2747 fileURL = sUrlRoot + fileURL.Trim();
2748 // firstfile = (e.g.) http://mydomain.com/repos/trunk/folder/file1
2749 // sUrl = http://mydomain.com/repos/trunk/folder
2750 CString sUnescapedUrl = CPathUtils::PathUnescape(sUrl);
2751 // find out until which char the urls are identical
2752 int i=0;
2753 while ((i<fileURL.GetLength())&&(i<sUnescapedUrl.GetLength())&&(fileURL[i]==sUnescapedUrl[i]))
2754 i++;
2755 int leftcount = m_path.GetWinPathString().GetLength()-(sUnescapedUrl.GetLength()-i);
2756 CString wcPath = m_path.GetWinPathString().Left(leftcount);
2757 wcPath += fileURL.Mid(i);
2758 wcPath.Replace('/', '\\');
2759 CGitProgressDlg dlg;
2760 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
2762 // a deleted path! Since the path isn't there anymore, merge
2763 // won't work. So just do a copy url->wc
2764 dlg.SetCommand(CGitProgressDlg::GitProgress_Copy);
2765 dlg.SetPathList(CTGitPathList(CTGitPath(fileURL)));
2766 dlg.SetUrl(wcPath);
2767 dlg.SetRevision(rev2);
2769 else
2771 if (!PathFileExists(wcPath))
2773 // seems the path got renamed
2774 // tell the user how to work around this.
2775 CMessageBox::Show(this->m_hWnd, IDS_LOG_REVERTREV_ERROR, IDS_APPNAME, MB_ICONERROR);
2776 EnableOKButton();
2777 theApp.DoWaitCursor(-1);
2778 break; //exit
2780 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
2781 dlg.SetPathList(CTGitPathList(CTGitPath(wcPath)));
2782 dlg.SetUrl(fileURL);
2783 dlg.SetSecondUrl(fileURL);
2784 GitRevRangeArray revarray;
2785 revarray.AddRevRange(rev1, rev2);
2786 dlg.SetRevisionRanges(revarray);
2788 CString msg;
2789 msg.Format(IDS_LOG_REVERT_CONFIRM, (LPCTSTR)wcPath);
2790 if (CMessageBox::Show(this->m_hWnd, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
2792 dlg.DoModal();
2794 theApp.DoWaitCursor(-1);
2796 break;
2797 case ID_POPPROPS:
2799 DialogEnableWindow(IDOK, FALSE);
2800 SetPromptApp(&theApp);
2801 theApp.DoWaitCursor(1);
2802 CString filepath;
2803 if (Git::PathIsURL(m_path))
2805 filepath = m_path.GetGitPathString();
2807 else
2809 filepath = GetURLFromPath(m_path);
2810 if (filepath.IsEmpty())
2812 theApp.DoWaitCursor(-1);
2813 CString temp;
2814 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2815 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2816 TRACE(_T("could not retrieve the URL of the file!\n"));
2817 EnableOKButton();
2818 break;
2821 filepath = GetRepositoryRoot(CTGitPath(filepath));
2822 filepath += changedpaths[0];
2823 CPropDlg dlg;
2824 dlg.m_rev = rev1;
2825 dlg.m_Path = CTGitPath(filepath);
2826 dlg.DoModal();
2827 EnableOKButton();
2828 theApp.DoWaitCursor(-1);
2830 break;
2831 case ID_SAVEAS:
2833 DialogEnableWindow(IDOK, FALSE);
2834 SetPromptApp(&theApp);
2835 theApp.DoWaitCursor(1);
2836 CString filepath;
2837 if (Git::PathIsURL(m_path))
2839 filepath = m_path.GetGitPathString();
2841 else
2843 filepath = GetURLFromPath(m_path);
2844 if (filepath.IsEmpty())
2846 theApp.DoWaitCursor(-1);
2847 CString temp;
2848 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2849 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2850 TRACE(_T("could not retrieve the URL of the file!\n"));
2851 EnableOKButton();
2852 break;
2855 m_bCancelled = false;
2856 CString sRoot = GetRepositoryRoot(CTGitPath(filepath));
2857 // if more than one entry is selected, we save them
2858 // one by one into a folder the user has selected
2859 bool bTargetSelected = false;
2860 CTGitPath TargetPath;
2861 if (m_ChangedFileListCtrl.GetSelectedCount() > 1)
2863 CBrowseFolder browseFolder;
2864 browseFolder.SetInfo(CString(MAKEINTRESOURCE(IDS_LOG_SAVEFOLDERTOHINT)));
2865 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
2866 CString strSaveAsDirectory;
2867 if (browseFolder.Show(GetSafeHwnd(), strSaveAsDirectory) == CBrowseFolder::OK)
2869 TargetPath = CTGitPath(strSaveAsDirectory);
2870 bTargetSelected = true;
2873 else
2875 // Display the Open dialog box.
2876 CString revFilename;
2877 CString temp;
2878 temp = CPathUtils::GetFileNameFromPath(changedpaths[0]);
2879 int rfind = temp.ReverseFind('.');
2880 if (rfind > 0)
2881 revFilename.Format(_T("%s-%ld%s"), (LPCTSTR)temp.Left(rfind), rev1, (LPCTSTR)temp.Mid(rfind));
2882 else
2883 revFilename.Format(_T("%s-%ld"), (LPCTSTR)temp, rev1);
2884 bTargetSelected = CAppUtils::FileOpenSave(revFilename, NULL, IDS_LOG_POPUP_SAVE, IDS_COMMONFILEFILTER, false, m_hWnd);
2885 TargetPath.SetFromWin(revFilename);
2887 if (bTargetSelected)
2889 CProgressDlg progDlg;
2890 progDlg.SetTitle(IDS_APPNAME);
2891 progDlg.SetAnimation(IDR_DOWNLOAD);
2892 for (std::vector<LogChangedPath*>::iterator it = changedlogpaths.begin(); it!= changedlogpaths.end(); ++it)
2894 GitRev getrev = ((*it)->action == LOGACTIONS_DELETED) ? rev2 : rev1;
2896 CString sInfoLine;
2897 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)getrev.ToString());
2898 progDlg.SetLine(1, sInfoLine, true);
2899 SetAndClearProgressInfo(&progDlg);
2900 progDlg.ShowModeless(m_hWnd);
2902 CTGitPath tempfile = TargetPath;
2903 if (changedpaths.size() > 1)
2905 // if multiple items are selected, then the TargetPath
2906 // points to a folder and we have to append the filename
2907 // to save to to that folder.
2908 CString sName = (*it)->sPath;
2909 int slashpos = sName.ReverseFind('/');
2910 if (slashpos >= 0)
2911 sName = sName.Mid(slashpos);
2912 tempfile.AppendPathString(sName);
2913 // one problem here:
2914 // a user could have selected multiple items which
2915 // have the same filename but reside in different
2916 // directories, e.g.
2917 // /folder1/file1
2918 // /folder2/file1
2919 // in that case, the second 'file1' will overwrite
2920 // the already saved 'file1'.
2922 // we could maybe find the common root of all selected
2923 // items and then create sub folders to save those files
2924 // there.
2925 // But I think we should just leave it that way: to check
2926 // out multiple items at once, the better way is still to
2927 // use the export command from the top pane of the log dialog.
2929 filepath = sRoot + (*it)->sPath;
2930 if (!Cat(CTGitPath(filepath), getrev, getrev, tempfile))
2932 progDlg.Stop();
2933 SetAndClearProgressInfo((HWND)NULL);
2934 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
2935 EnableOKButton();
2936 theApp.DoWaitCursor(-1);
2937 break;
2940 progDlg.Stop();
2941 SetAndClearProgressInfo((HWND)NULL);
2943 EnableOKButton();
2944 theApp.DoWaitCursor(-1);
2946 break;
2947 case ID_OPENWITH:
2948 bOpenWith = true;
2949 case ID_OPEN:
2951 GitRev getrev = pLogEntry->pArChangedPaths->SafeGetAt(selIndex)->action == LOGACTIONS_DELETED ? rev2 : rev1;
2952 Open(bOpenWith,changedpaths[0],getrev);
2954 break;
2955 case ID_BLAME:
2957 CString filepath;
2958 if (Git::PathIsURL(m_path))
2960 filepath = m_path.GetGitPathString();
2962 else
2964 filepath = GetURLFromPath(m_path);
2965 if (filepath.IsEmpty())
2967 theApp.DoWaitCursor(-1);
2968 CString temp;
2969 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2970 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2971 TRACE(_T("could not retrieve the URL of the file!\n"));
2972 EnableOKButton();
2973 break;
2976 filepath = GetRepositoryRoot(CTGitPath(filepath));
2977 filepath += changedpaths[0];
2978 CBlameDlg dlg;
2979 dlg.EndRev = rev1;
2980 if (dlg.DoModal() == IDOK)
2982 CBlame blame;
2983 CString tempfile;
2984 CString logfile;
2985 tempfile = blame.BlameToTempFile(CTGitPath(filepath), dlg.StartRev, dlg.EndRev, dlg.EndRev, logfile, _T(""), dlg.m_bIncludeMerge, TRUE, TRUE);
2986 if (!tempfile.IsEmpty())
2988 if (dlg.m_bTextView)
2990 //open the default text editor for the result file
2991 CAppUtils::StartTextViewer(tempfile);
2993 else
2995 CString sParams = _T("/path:\"") + filepath + _T("\" ");
2996 if(!CAppUtils::LaunchTortoiseBlame(tempfile, logfile, CPathUtils::GetFileNameFromPath(filepath),sParams))
2998 break;
3002 else
3004 CMessageBox::Show(this->m_hWnd, blame.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3008 break;
3009 case ID_GETMERGELOGS:
3010 bMergeLog = true;
3011 // fall through
3012 case ID_LOG:
3014 DialogEnableWindow(IDOK, FALSE);
3015 SetPromptApp(&theApp);
3016 theApp.DoWaitCursor(1);
3017 CString filepath;
3018 if (Git::PathIsURL(m_path))
3020 filepath = m_path.GetGitPathString();
3022 else
3024 filepath = GetURLFromPath(m_path);
3025 if (filepath.IsEmpty())
3027 theApp.DoWaitCursor(-1);
3028 CString temp;
3029 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
3030 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3031 TRACE(_T("could not retrieve the URL of the file!\n"));
3032 EnableOKButton();
3033 break;
3036 m_bCancelled = false;
3037 filepath = GetRepositoryRoot(CTGitPath(filepath));
3038 filepath += changedpaths[0];
3039 git_revnum_t logrev = rev1;
3040 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
3042 // if the item got deleted in this revision,
3043 // fetch the log from the previous revision where it
3044 // still existed.
3045 logrev--;
3047 CString sCmd;
3048 sCmd.Format(_T("\"%s\" /command:log /path:\"%s\" /startrev:%ld"), (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)filepath, logrev);
3049 if (bMergeLog)
3050 sCmd += _T(" /merge");
3051 CAppUtils::LaunchApplication(sCmd, NULL, false);
3052 EnableOKButton();
3053 theApp.DoWaitCursor(-1);
3055 break;
3056 case ID_VIEWPATHREV:
3058 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetSelectionMark()));
3059 GitRev rev = pLogEntry->Rev;
3060 CString relurl = changedpaths[0];
3061 CString url = m_ProjectProperties.sWebViewerPathRev;
3062 url.Replace(_T("%REVISION%"), rev.ToString());
3063 url.Replace(_T("%PATH%"), relurl);
3064 relurl = relurl.Mid(relurl.Find('/'));
3065 url.Replace(_T("%PATH1%"), relurl);
3066 if (!url.IsEmpty())
3067 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
3069 break;
3070 #endif
3071 default:
3072 break;
3073 } // switch (cmd)
3075 } // if (popup.CreatePopupMenu())
3077 #endif
3079 void CLogDlg::OnDtnDropdownDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3081 // the date control should not show the "today" button
3082 CMonthCalCtrl * pCtrl = m_DateFrom.GetMonthCalCtrl();
3083 if (pCtrl)
3084 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3085 *pResult = 0;
3088 void CLogDlg::OnDtnDropdownDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3090 // the date control should not show the "today" button
3091 CMonthCalCtrl * pCtrl = m_DateTo.GetMonthCalCtrl();
3092 if (pCtrl)
3093 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3094 *pResult = 0;
3097 void CLogDlg::OnSize(UINT nType, int cx, int cy)
3099 __super::OnSize(nType, cx, cy);
3100 //set range
3101 SetSplitterRange();
3104 void CLogDlg::OnRefresh()
3106 //if (GetDlgItem(IDC_GETALL)->IsWindowEnabled())
3107 ShowStartRef();
3109 m_limit = 0;
3110 this->m_LogProgress.SetPos(0);
3112 Refresh (false);
3118 void CLogDlg::OnFocusFilter()
3120 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3123 void CLogDlg::OnEditCopy()
3125 if (GetFocus() == &m_ChangedFileListCtrl)
3126 CopyChangedSelectionToClipBoard();
3127 else
3128 m_LogList.CopySelectionToClipBoard();
3131 CString CLogDlg::GetAbsoluteUrlFromRelativeUrl(const CString& url)
3133 // is the URL a relative one?
3134 if (url.Left(2).Compare(_T("^/")) == 0)
3136 // URL is relative to the repository root
3137 CString url1 = m_sRepositoryRoot + url.Mid(1);
3138 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3139 DWORD len = url.GetLength();
3140 if (UrlCanonicalize((LPCTSTR)url1, buf, &len, 0) == S_OK)
3141 return CString(buf, len);
3142 return url1;
3144 else if (url[0] == '/')
3146 // URL is relative to the server's hostname
3147 CString sHost;
3148 // find the server's hostname
3149 int schemepos = m_sRepositoryRoot.Find(_T("//"));
3150 if (schemepos >= 0)
3152 sHost = m_sRepositoryRoot.Left(m_sRepositoryRoot.Find('/', schemepos+3));
3153 CString url1 = sHost + url;
3154 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3155 DWORD len = url.GetLength();
3156 if (UrlCanonicalize((LPCTSTR)url, buf, &len, 0) == S_OK)
3157 return CString(buf, len);
3158 return url1;
3161 return url;
3165 void CLogDlg::OnEnChangeSearchedit()
3167 UpdateData();
3168 if (m_LogList.m_sFilterText.IsEmpty())
3170 CStoreSelection storeselection(this);
3171 // clear the filter, i.e. make all entries appear
3172 theApp.DoWaitCursor(1);
3173 KillTimer(LOGFILTER_TIMER);
3174 FillLogMessageCtrl(false);
3176 Refresh();
3177 //m_LogList.StartFilter();
3178 #if 0
3179 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3180 m_arShownList.RemoveAll();
3181 for (DWORD i=0; i<m_logEntries.size(); ++i)
3183 if (IsEntryInDateRange(i))
3184 m_arShownList.Add(m_logEntries[i]);
3186 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3187 m_LogList.DeleteAllItems();
3188 m_LogList.SetItemCountEx(ShownCountWithStopped());
3189 m_LogList.RedrawItems(0, ShownCountWithStopped());
3190 m_LogList.SetRedraw(false);
3191 ResizeAllListCtrlCols();
3192 m_LogList.SetRedraw(true);
3193 #endif
3194 theApp.DoWaitCursor(-1);
3195 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
3196 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
3197 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3198 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
3199 return;
3201 if (Validate(m_LogList.m_sFilterText))
3202 SetTimer(LOGFILTER_TIMER, 1000, NULL);
3203 else
3204 KillTimer(LOGFILTER_TIMER);
3208 void CLogDlg::OnBnClickedAllBranch()
3210 this->UpdateData();
3212 if(this->m_bAllBranch)
3213 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
3214 else
3215 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
3217 OnRefresh();
3219 FillLogMessageCtrl(false);
3222 void CLogDlg::OnBnClickedBrowseRef()
3224 CString newRef = CBrowseRefsDlg::PickRef(false,m_LogList.GetStartRef());
3225 if(newRef.IsEmpty())
3226 return;
3228 SetStartRef(newRef);
3229 ((CButton*)GetDlgItem(IDC_LOG_ALLBRANCH))->SetCheck(0);
3231 OnBnClickedAllBranch();
3234 void CLogDlg::ShowStartRef()
3236 //Show ref name on top
3237 if(!::IsWindow(m_hWnd))
3238 return;
3239 if(m_bAllBranch)
3241 m_staticRef.SetWindowText(L"<All Branches>");
3242 m_staticRef.Invalidate(TRUE);
3243 return;
3246 CString showStartRef = m_LogList.GetStartRef();
3247 if(showStartRef.IsEmpty())
3249 //Ref name is HEAD
3250 if( g_Git.Run(L"git symbolic-ref HEAD",&showStartRef,CP_UTF8) )
3251 showStartRef = _T("<No branch>");
3252 showStartRef.Trim(L"\r\n\t ");
3256 if(wcsncmp(showStartRef,L"refs/",5) == 0)
3257 showStartRef = showStartRef.Mid(5);
3258 if(wcsncmp(showStartRef,L"heads/",6) == 0)
3259 showStartRef = showStartRef.Mid(6);
3261 m_staticRef.SetWindowText(showStartRef);
3262 m_staticRef.Invalidate(TRUE);
3265 void CLogDlg::SetStartRef(const CString& StartRef)
3267 m_LogList.SetStartRef(StartRef);
3269 ShowStartRef();
3274 void CLogDlg::OnBnClickedFirstParent()
3276 this->UpdateData();
3278 if(this->m_bFirstParent)
3279 m_LogList.m_ShowMask|=CGit::LOG_INFO_FIRST_PARENT;
3280 else
3281 m_LogList.m_ShowMask&=~CGit::LOG_INFO_FIRST_PARENT;
3283 OnRefresh();
3285 FillLogMessageCtrl(false);
3289 void CLogDlg::OnBnClickShowWholeProject()
3291 this->UpdateData();
3293 if(this->m_bWholeProject)
3295 m_LogList.m_Path.Reset();
3296 SetDlgTitle();
3298 else
3300 m_LogList.m_Path=m_path;
3303 SetDlgTitle();
3305 OnRefresh();
3307 FillLogMessageCtrl(false);
3311 LRESULT CLogDlg::OnRefLogChanged(WPARAM wParam, LPARAM lParam)
3313 UNREFERENCED_PARAMETER(wParam);
3314 UNREFERENCED_PARAMETER(lParam);
3315 ShowStartRef();
3316 return 0;
3319 LRESULT CLogDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
3321 m_pTaskbarList.Release();
3322 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
3323 return 0;