dropped unused TSVN settings
[TortoiseGit.git] / src / TortoiseProc / LogDlg.cpp
blob43b81a0ea0aac1c3d46092bc79da1c5c89bdcc45
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 "GITProgressDlg.h"
25 #include "ProgressDlg.h"
26 //#include "RepositoryBrowser.h"
27 //#include "CopyDlg.h"
28 #include "StatGraphDlg.h"
29 #include "Logdlg.h"
30 #include "MessageBox.h"
31 #include "Registry.h"
32 #include "AppUtils.h"
33 #include "PathUtils.h"
34 #include "StringUtils.h"
35 #include "UnicodeUtils.h"
36 #include "TempFile.h"
37 //#include "GitInfo.h"
38 //#include "GitDiff.h"
39 #include "IconMenu.h"
40 //#include "RevisionRangeDlg.h"
41 //#include "BrowseFolder.h"
42 //#include "BlameDlg.h"
43 //#include "Blame.h"
44 //#include "GitHelpers.h"
45 #include "GitStatus.h"
46 //#include "LogDlgHelper.h"
47 //#include "CachedLogInfo.h"
48 //#include "RepositoryInfo.h"
49 //#include "EditPropertiesDlg.h"
50 #include "FileDiffDlg.h"
51 #include "BrowseRefsDlg.h"
54 IMPLEMENT_DYNAMIC(CLogDlg, CResizableStandAloneDialog)
55 CLogDlg::CLogDlg(CWnd* pParent /*=NULL*/)
56 : CResizableStandAloneDialog(CLogDlg::IDD, pParent)
57 , m_logcounter(0)
58 , m_wParam(0)
59 , m_currentChangedArray(NULL)
60 , m_nSortColumn(0)
61 , m_bShowedAll(false)
62 , m_bSelect(false)
64 , m_bSelectionMustBeContinuous(false)
65 , m_lowestRev(_T(""))
67 , m_sLogInfo(_T(""))
69 , m_bCancelled(FALSE)
70 , m_pNotifyWindow(NULL)
72 , m_bAscending(FALSE)
74 , m_limit(0)
75 , m_childCounter(0)
76 , m_maxChild(0)
77 , m_bIncludeMerges(FALSE)
78 , m_hAccel(NULL)
80 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
82 CString str;
83 str=g_Git.m_CurrentDir;
84 str.Replace(_T(":"),_T("_"));
85 str=CString(_T("Software\\TortoiseGit\\LogDialog\\AllBranch\\"))+str;
87 m_regbAllBranch=CRegDWORD(str,FALSE);
89 m_bAllBranch=m_regbAllBranch;
91 m_bFirstParent=FALSE;
92 m_bWholeProject=FALSE;
95 CLogDlg::~CLogDlg()
98 m_regbAllBranch=m_bAllBranch;
100 m_CurrentFilteredChangedArray.RemoveAll();
104 void CLogDlg::DoDataExchange(CDataExchange* pDX)
106 CResizableStandAloneDialog::DoDataExchange(pDX);
107 DDX_Control(pDX, IDC_LOGLIST, m_LogList);
108 DDX_Control(pDX, IDC_LOGMSG, m_ChangedFileListCtrl);
109 DDX_Control(pDX, IDC_PROGRESS, m_LogProgress);
110 DDX_Control(pDX, IDC_SPLITTERTOP, m_wndSplitter1);
111 DDX_Control(pDX, IDC_SPLITTERBOTTOM, m_wndSplitter2);
112 DDX_Text(pDX, IDC_SEARCHEDIT, m_LogList.m_sFilterText);
113 DDX_Control(pDX, IDC_DATEFROM, m_DateFrom);
114 DDX_Control(pDX, IDC_DATETO, m_DateTo);
115 DDX_Control(pDX, IDC_HIDEPATHS, m_cHidePaths);
116 DDX_Text(pDX, IDC_LOGINFO, m_sLogInfo);
117 DDX_Check(pDX, IDC_LOG_FIRSTPARENT, m_bFirstParent);
118 DDX_Check(pDX, IDC_LOG_ALLBRANCH,m_bAllBranch);
119 DDX_Check(pDX, IDC_SHOWWHOLEPROJECT,m_bWholeProject);
120 DDX_Control(pDX, IDC_SEARCHEDIT, m_cFilter);
121 DDX_Control(pDX, IDC_STATIC_REF, m_staticRef);
124 BEGIN_MESSAGE_MAP(CLogDlg, CResizableStandAloneDialog)
125 //ON_BN_CLICKED(IDC_GETALL, OnBnClickedGetall)
126 //ON_NOTIFY(NM_DBLCLK, IDC_LOGMSG, OnNMDblclkChangedFileList)
127 ON_WM_CONTEXTMENU()
128 ON_WM_SETCURSOR()
129 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
130 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOGLIST, OnLvnItemchangedLoglist)
131 ON_NOTIFY(EN_LINK, IDC_MSGVIEW, OnEnLinkMsgview)
132 ON_BN_CLICKED(IDC_STATBUTTON, OnBnClickedStatbutton)
135 ON_MESSAGE(WM_FILTEREDIT_INFOCLICKED, OnClickedInfoIcon)
136 ON_MESSAGE(WM_FILTEREDIT_CANCELCLICKED, OnClickedCancelFilter)
138 ON_MESSAGE(MSG_LOAD_PERCENTAGE,OnLogListLoading)
140 ON_EN_CHANGE(IDC_SEARCHEDIT, OnEnChangeSearchedit)
141 ON_WM_TIMER()
142 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETO, OnDtnDatetimechangeDateto)
143 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATEFROM, OnDtnDatetimechangeDatefrom)
144 ON_BN_CLICKED(IDC_SHOWWHOLEPROJECT, OnBnClickShowWholeProject)
145 //ON_NOTIFY(NM_CUSTOMDRAW, IDC_LOGMSG, OnNMCustomdrawChangedFileList)
146 //ON_NOTIFY(LVN_GETDISPINFO, IDC_LOGMSG, OnLvnGetdispinfoChangedFileList)
147 ON_NOTIFY(LVN_COLUMNCLICK,IDC_LOGLIST, OnLvnColumnclick)
148 //ON_NOTIFY(LVN_COLUMNCLICK, IDC_LOGMSG, OnLvnColumnclickChangedFileList)
149 ON_BN_CLICKED(IDC_HIDEPATHS, OnBnClickedHidepaths)
150 ON_COMMAND(MSG_FETCHED_DIFF, OnBnClickedHidepaths)
151 ON_BN_CLICKED(IDC_LOG_ALLBRANCH, OnBnClickedAllBranch)
153 ON_NOTIFY(DTN_DROPDOWN, IDC_DATEFROM, &CLogDlg::OnDtnDropdownDatefrom)
154 ON_NOTIFY(DTN_DROPDOWN, IDC_DATETO, &CLogDlg::OnDtnDropdownDateto)
155 ON_WM_SIZE()
156 ON_BN_CLICKED(IDC_LOG_FIRSTPARENT, &CLogDlg::OnBnClickedFirstParent)
157 ON_BN_CLICKED(IDC_REFRESH, &CLogDlg::OnBnClickedRefresh)
158 // ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CLogDlg::OnBnClickedBrowseRef)
159 ON_STN_CLICKED(IDC_STATIC_REF, &CLogDlg::OnBnClickedBrowseRef)
160 ON_COMMAND(ID_LOGDLG_REFRESH, &CLogDlg::OnBnClickedRefresh)
161 ON_COMMAND(ID_LOGDLG_FIND, &CLogDlg::OnFind)
162 ON_COMMAND(ID_LOGDLG_FOCUSFILTER, &CLogDlg::OnFocusFilter)
163 ON_COMMAND(ID_EDIT_COPY, &CLogDlg::OnEditCopy)
164 ON_MESSAGE(MSG_REFLOG_CHANGED, OnRefLogChanged)
165 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
166 END_MESSAGE_MAP()
168 void CLogDlg::SetParams(const CTGitPath& orgPath, const CTGitPath& path, CString hightlightRevision, CString startrev, CString endrev, int limit /* = FALSE */)
170 m_orgPath = orgPath;
171 m_path = path;
172 m_hightlightRevision = hightlightRevision;
173 this->m_LogList.m_startrev = startrev;
174 m_LogRevision = startrev;
175 this->m_LogList.m_endrev = endrev;
177 if(!endrev.IsEmpty())
178 this->SetStartRef(endrev);
180 m_hasWC = !path.IsUrl();
181 m_limit = limit;
182 if (::IsWindow(m_hWnd))
183 UpdateData(FALSE);
186 BOOL CLogDlg::OnInitDialog()
188 CString temp;
189 CResizableStandAloneDialog::OnInitDialog();
190 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
192 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
193 // do this, Explorer would be unable to send that message to our window if we
194 // were running elevated. It's OK to make the call all the time, since if we're
195 // not elevated, this is a no-op.
196 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
197 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
198 HMODULE hUser = ::LoadLibrary(_T("user32.dll"));
199 if (hUser)
201 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
202 if (pfnChangeWindowMessageFilterEx)
204 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
206 FreeLibrary(hUser);
208 m_pTaskbarList.Release();
209 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
211 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_LOGDLG));
213 // use the state of the "stop on copy/rename" option from the last time
214 UpdateData(FALSE);
216 // set the font to use in the log message view, configured in the settings dialog
217 CAppUtils::CreateFontForLogs(m_logFont);
218 GetDlgItem(IDC_MSGVIEW)->SetFont(&m_logFont);
219 // automatically detect URLs in the log message and turn them into links
220 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_AUTOURLDETECT, TRUE, NULL);
221 // make the log message rich edit control send a message when the mouse pointer is over a link
222 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_SETEVENTMASK, NULL, ENM_LINK);
223 //m_LogList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_SUBITEMIMAGES);
225 // the "hide unrelated paths" checkbox should be indeterminate
226 m_cHidePaths.SetCheck(BST_INDETERMINATE);
229 //SetWindowTheme(m_LogList.GetSafeHwnd(), L"Explorer", NULL);
230 //SetWindowTheme(m_ChangedFileListCtrl.GetSafeHwnd(), L"Explorer", NULL);
232 // set up the columns
233 m_LogList.DeleteAllItems();
235 m_LogList.m_Path=m_path;
236 m_LogList.m_bShowWC = true;
237 m_LogList.InsertGitColumn();
239 m_ChangedFileListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS |GITSLC_COLADD|GITSLC_COLDEL , _T("LogDlg"),(GITSLC_POPALL ^ (GITSLC_POPCOMMIT|GITSLC_POPIGNORE)),false);
241 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
243 m_logcounter = 0;
244 m_sMessageBuf.Preallocate(100000);
246 SetDlgTitle();
248 m_tooltips.Create(this);
249 CheckRegexpTooltip();
251 SetSplitterRange();
253 // the filter control has a 'cancel' button (the red 'X'), we need to load its bitmap
254 m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);
255 m_cFilter.SetInfoIcon(IDI_LOGFILTER);
256 m_cFilter.SetValidator(this);
258 AdjustControlSize(IDC_HIDEPATHS);
259 AdjustControlSize(IDC_LOG_FIRSTPARENT);
260 AdjustControlSize(IDC_LOG_ALLBRANCH);
262 GetClientRect(m_DlgOrigRect);
263 m_LogList.GetClientRect(m_LogListOrigRect);
264 GetDlgItem(IDC_MSGVIEW)->GetClientRect(m_MsgViewOrigRect);
265 m_ChangedFileListCtrl.GetClientRect(m_ChgOrigRect);
267 m_DateFrom.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
268 m_DateTo.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
270 m_staticRef.SetURL(CString());
272 // resizable stuff
273 AddAnchor(IDC_STATIC_REF, TOP_LEFT);
274 //AddAnchor(IDC_BUTTON_BROWSE_REF, TOP_LEFT);
275 AddAnchor(IDC_FROMLABEL, TOP_LEFT);
276 AddAnchor(IDC_DATEFROM, TOP_LEFT);
277 AddAnchor(IDC_TOLABEL, TOP_LEFT);
278 AddAnchor(IDC_DATETO, TOP_LEFT);
280 SetFilterCueText();
281 AddAnchor(IDC_SEARCHEDIT, TOP_LEFT, TOP_RIGHT);
283 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
284 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
285 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
286 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
287 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
289 AddAnchor(IDC_LOGINFO, BOTTOM_LEFT, BOTTOM_RIGHT);
290 AddAnchor(IDC_HIDEPATHS, BOTTOM_LEFT);
291 AddAnchor(IDC_LOG_ALLBRANCH,BOTTOM_LEFT);
292 AddAnchor(IDC_LOG_FIRSTPARENT, BOTTOM_LEFT);
293 //AddAnchor(IDC_GETALL, BOTTOM_LEFT);
294 AddAnchor(IDC_SHOWWHOLEPROJECT, BOTTOM_LEFT);
295 AddAnchor(IDC_REFRESH, BOTTOM_LEFT);
296 AddAnchor(IDC_STATBUTTON, BOTTOM_RIGHT);
297 AddAnchor(IDC_PROGRESS, BOTTOM_LEFT, BOTTOM_RIGHT);
298 AddAnchor(IDOK, BOTTOM_RIGHT);
299 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
300 AddAnchor(IDHELP, BOTTOM_RIGHT);
302 if(this->m_bAllBranch)
303 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
304 else
305 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
307 // SetPromptParentWindow(m_hWnd);
309 if (hWndExplorer)
310 CenterWindow(CWnd::FromHandle(hWndExplorer));
311 EnableSaveRestore(_T("LogDlg"));
313 DWORD yPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
314 DWORD yPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
315 RECT rcDlg, rcLogList, rcChgMsg;
316 GetClientRect(&rcDlg);
317 m_LogList.GetWindowRect(&rcLogList);
318 ScreenToClient(&rcLogList);
319 m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg);
320 ScreenToClient(&rcChgMsg);
321 if (yPos1)
323 RECT rectSplitter;
324 m_wndSplitter1.GetWindowRect(&rectSplitter);
325 ScreenToClient(&rectSplitter);
326 int delta = yPos1 - rectSplitter.top;
328 if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30))
330 m_wndSplitter1.SetWindowPos(NULL, 0, yPos1, 0, 0, SWP_NOSIZE);
331 DoSizeV1(delta);
334 if (yPos2)
336 RECT rectSplitter;
337 m_wndSplitter2.GetWindowRect(&rectSplitter);
338 ScreenToClient(&rectSplitter);
339 int delta = yPos2 - rectSplitter.top;
341 if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30))
343 m_wndSplitter2.SetWindowPos(NULL, 0, yPos2, 0, 0, SWP_NOSIZE);
344 DoSizeV2(delta);
349 if (m_bSelect)
351 // the dialog is used to select revisions
352 // enable the OK button if appropriate
353 EnableOKButton();
355 else
357 // the dialog is used to just view log messages
358 // hide the OK button and set text on Cancel button to OK
359 GetDlgItemText(IDOK, temp);
360 SetDlgItemText(IDCANCEL, temp);
361 GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
364 m_mergedRevs.clear();
366 // first start a thread to obtain the log messages without
367 // blocking the dialog
368 //m_tTo = 0;
369 //m_tFrom = (DWORD)-1;
371 // scroll to user selected or current revision
372 if (!m_hightlightRevision.IsEmpty() && m_hightlightRevision.GetLength() >= GIT_HASH_SIZE)
373 m_LogList.m_lastSelectedHash = m_hightlightRevision;
374 else if (!m_LogList.m_endrev.IsEmpty() && m_LogList.m_endrev.GetLength() >= GIT_HASH_SIZE)
375 m_LogList.m_lastSelectedHash = m_hightlightRevision;
376 else
377 m_LogList.m_lastSelectedHash = g_Git.GetHash(_T("HEAD"));
379 m_LogList.FetchLogAsync(this);
381 GetDlgItem(IDC_LOGLIST)->SetFocus();
383 ShowStartRef();
384 return FALSE;
387 LRESULT CLogDlg::OnLogListLoading(WPARAM wParam, LPARAM /*lParam*/)
389 int cur=(int)wParam;
391 if( cur == GITLOG_START )
393 CString temp;
394 temp.LoadString(IDS_PROGRESSWAIT);
396 this->m_LogList.ShowText(temp, true);
398 // We use a progress bar while getting the logs
399 m_LogProgress.SetRange32(0, 100);
400 m_LogProgress.SetPos(0);
401 if (m_pTaskbarList)
403 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
404 m_pTaskbarList->SetProgressValue(m_hWnd, 0, 100);
407 GetDlgItem(IDC_PROGRESS)->ShowWindow(TRUE);
409 //DialogEnableWindow(IDC_GETALL, FALSE);
410 //DialogEnableWindow(IDC_SHOWWHOLEPROJECT, FALSE);
411 //DialogEnableWindow(IDC_LOG_FIRSTPARENT, FALSE);
412 DialogEnableWindow(IDC_STATBUTTON, FALSE);
413 //DialogEnableWindow(IDC_REFRESH, FALSE);
414 DialogEnableWindow(IDC_HIDEPATHS,FALSE);
417 else if( cur == GITLOG_END)
419 if(this->m_LogList.HasText())
421 this->m_LogList.ClearText();
423 UpdateLogInfoLabel();
425 if (m_pTaskbarList)
426 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
428 //if (!m_bShowedAll)
429 DialogEnableWindow(IDC_SHOWWHOLEPROJECT, TRUE);
431 //DialogEnableWindow(IDC_GETALL, TRUE);
432 DialogEnableWindow(IDC_STATBUTTON, !(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1));
433 DialogEnableWindow(IDC_REFRESH, TRUE);
434 DialogEnableWindow(IDC_HIDEPATHS,TRUE);
436 // PostMessage(WM_TIMER, LOGFILTER_TIMER);
437 GetDlgItem(IDC_PROGRESS)->ShowWindow(FALSE);
438 //CTime time=m_LogList.GetOldestTime();
439 CTime begin,end;
440 m_LogList.GetTimeRange(begin,end);
442 if(m_LogList.m_From == -1)
443 m_DateFrom.SetTime(&begin);
445 if(m_LogList.m_To == -1)
446 m_DateTo.SetTime(&end);
450 else
452 if(this->m_LogList.HasText())
454 this->m_LogList.ClearText();
455 this->m_LogList.Invalidate();
457 UpdateLogInfoLabel();
458 m_LogProgress.SetPos(cur);
459 if (m_pTaskbarList)
461 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
462 m_pTaskbarList->SetProgressValue(m_hWnd, cur, 100);
465 return 0;
467 void CLogDlg::SetDlgTitle()
469 if (m_sTitle.IsEmpty())
470 GetWindowText(m_sTitle);
472 if (m_LogList.m_Path.IsEmpty() || m_orgPath.GetWinPathString().IsEmpty())
474 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
476 else
477 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);
480 void CLogDlg::CheckRegexpTooltip()
482 CWnd *pWnd = GetDlgItem(IDC_SEARCHEDIT);
483 // Since tooltip describes regexp features, show it only if regexps are enabled.
484 if (m_bFilterWithRegex)
486 m_tooltips.AddTool(pWnd, IDS_LOG_FILTER_REGEX_TT);
488 else
489 m_tooltips.DelTool(pWnd);
492 void CLogDlg::EnableOKButton()
494 if (m_bSelect)
496 // the dialog is used to select revisions
497 if (m_bSelectionMustBeSingle)
499 // enable OK button if only a single revision is selected
500 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()==1));
502 else if (m_bSelectionMustBeContinuous)
503 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));
504 else
505 DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);
507 else
508 DialogEnableWindow(IDOK, TRUE);
511 CString CLogDlg::GetTagInfo(GitRev* pLogEntry)
513 CString cmd;
514 CString output;
516 if(m_LogList.m_HashMap.find(pLogEntry->m_CommitHash) != m_LogList.m_HashMap.end())
518 STRING_VECTOR &vector = m_LogList.m_HashMap[pLogEntry->m_CommitHash];
519 for(int i=0;i<vector.size();i++)
521 if(vector[i].Find(_T("refs/tags/")) == 0 )
523 CString tag= vector[i];
524 int start = vector[i].Find(_T("^{}"));
525 if(start>0)
526 tag=tag.Left(start);
527 else
528 continue;
530 cmd.Format(_T("git.exe cat-file tag %s"), tag);
532 if(g_Git.Run(cmd, &output, NULL, CP_UTF8) == 0 )
533 output+=_T("\n");
538 if(!output.IsEmpty())
540 output = _T("\n*Tag Info*\n\n") + output;
543 return output;
546 void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)
548 // we fill here the log message rich edit control,
549 // and also populate the changed files list control
550 // according to the selected revision(s).
552 CRichEditCtrl * pMsgView = (CRichEditCtrl*)GetDlgItem(IDC_MSGVIEW);
553 // empty the log message view
554 pMsgView->SetWindowText(_T(" "));
555 // empty the changed files list
556 m_ChangedFileListCtrl.SetRedraw(FALSE);
557 // InterlockedExchange(&m_bNoDispUpdates, TRUE);
558 m_currentChangedArray = NULL;
559 //m_ChangedFileListCtrl.SetExtendedStyle ( LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER );
560 m_ChangedFileListCtrl.DeleteAllItems();
562 // if we're not here to really show a selected revision, just
563 // get out of here after clearing the views, which is what is intended
564 // if that flag is not set.
565 if (!bShow)
567 // force a redraw
568 m_ChangedFileListCtrl.Invalidate();
569 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
570 m_ChangedFileListCtrl.SetRedraw(TRUE);
571 return;
574 // depending on how many revisions are selected, we have to do different
575 // tasks.
576 int selCount = m_LogList.GetSelectedCount();
577 if (selCount == 0)
579 // if nothing is selected, we have nothing more to do
580 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
581 m_ChangedFileListCtrl.SetRedraw(TRUE);
582 return;
584 else if (selCount == 1)
586 // if one revision is selected, we have to fill the log message view
587 // with the corresponding log message, and also fill the changed files
588 // list fully.
589 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
590 int selIndex = m_LogList.GetNextSelectedItem(pos);
591 if (selIndex >= m_LogList.m_arShownList.GetCount())
593 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
594 m_ChangedFileListCtrl.SetRedraw(TRUE);
595 return;
597 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
600 // set the log message text
601 pMsgView->SetWindowText(_T("Commit:")+pLogEntry->m_CommitHash.ToString()+_T("\r\n\r\n"));
602 // turn bug ID's into links if the bugtraq: properties have been set
603 // and we can find a match of those in the log message
605 pMsgView->SetSel(-1,-1);
606 CHARFORMAT2 format;
607 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
608 format.cbSize = sizeof(CHARFORMAT2);
609 format.dwMask = CFM_BOLD;
610 format.dwEffects = CFE_BOLD;
611 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
613 CString msg=_T("* ");
614 msg+=pLogEntry->GetSubject();
615 pMsgView->ReplaceSel(msg);
617 pMsgView->SetSel(-1,-1);
618 format.dwEffects = 0;
619 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
621 msg=_T("\n");
622 msg+=pLogEntry->GetBody();
624 if(!pLogEntry->m_Notes.IsEmpty())
626 msg+= _T("\n*Notes* ");
627 msg+= pLogEntry->m_Notes;
628 msg+= _T("\n\n");
631 msg+=GetTagInfo(pLogEntry);
633 pMsgView->ReplaceSel(msg);
635 CString text;
636 pMsgView->GetWindowText(text);
637 // the rich edit control doesn't count the CR char!
638 // to be exact: CRLF is treated as one char.
639 text.Remove('\r');
641 m_LogList.m_ProjectProperties.FindBugID(text, pMsgView);
642 CAppUtils::FormatTextInRichEditControl(pMsgView);
644 int HidePaths=m_cHidePaths.GetState() & 0x0003;
645 CString matchpath=this->m_path.GetGitPathString();
647 int count = pLogEntry->GetFiles(&m_LogList).GetCount();
648 for(int i=0;i<count && (!matchpath.IsEmpty());i++)
650 if( m_bWholeProject )
651 break;
653 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action &= ~(CTGitPath::LOGACTIONS_HIDE|CTGitPath::LOGACTIONS_GRAY);
655 if(pLogEntry->GetFiles(&m_LogList)[i].GetGitPathString().Left(matchpath.GetLength()) != matchpath)
657 if(HidePaths==BST_CHECKED)
658 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;
659 if(HidePaths==BST_INDETERMINATE)
660 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_GRAY;
664 m_ChangedFileListCtrl.UpdateWithGitPathList(pLogEntry->GetFiles(&m_LogList));
665 m_ChangedFileListCtrl.m_CurrentVersion=pLogEntry->m_CommitHash;
666 m_ChangedFileListCtrl.Show(GITSLC_SHOWVERSIONED);
668 m_ChangedFileListCtrl.SetBusyString(_T("Fetch Changed File..."));
670 if(!pLogEntry->m_IsDiffFiles)
671 m_ChangedFileListCtrl.SetBusy(TRUE);
672 else
673 m_ChangedFileListCtrl.SetBusy(FALSE);
675 m_ChangedFileListCtrl.SetRedraw(TRUE);
676 return;
680 else
682 // more than one revision is selected:
683 // the log message view must be emptied
684 // the changed files list contains all the changed paths from all
685 // selected revisions, with 'doubles' removed
686 m_currentChangedPathList = GetChangedPathsFromSelectedRevisions(true);
689 // redraw the views
690 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
691 #if 0
692 if (m_currentChangedArray)
694 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedArray->GetCount());
695 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedArray->GetCount());
697 else if (m_currentChangedPathList.GetCount())
699 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedPathList.GetCount());
700 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedPathList.GetCount());
702 else
704 m_ChangedFileListCtrl.SetItemCountEx(0);
705 m_ChangedFileListCtrl.Invalidate();
707 #endif
708 // sort according to the settings
709 if (m_nSortColumnPathList > 0)
710 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
711 else
712 SetSortArrow(&m_ChangedFileListCtrl, -1, false);
713 m_ChangedFileListCtrl.SetRedraw(TRUE);
717 void CLogDlg::OnBnClickedRefresh()
719 Refresh (true);
722 void CLogDlg::Refresh (bool clearfilter /*autoGoOnline*/)
724 m_limit = 0;
725 m_LogList.Refresh(clearfilter);
726 FillLogMessageCtrl(false);
731 BOOL CLogDlg::Cancel()
733 return m_bCancelled;
736 void CLogDlg::SaveSplitterPos()
738 if (!IsIconic())
740 CRegDWORD regPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
741 CRegDWORD regPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
742 RECT rectSplitter;
743 m_wndSplitter1.GetWindowRect(&rectSplitter);
744 ScreenToClient(&rectSplitter);
745 regPos1 = rectSplitter.top;
746 m_wndSplitter2.GetWindowRect(&rectSplitter);
747 ScreenToClient(&rectSplitter);
748 regPos2 = rectSplitter.top;
752 void CLogDlg::OnCancel()
754 this->ShowWindow(SW_HIDE);
756 // canceling means stopping the working thread if it's still running.
757 m_LogList.SafeTerminateAsyncDiffThread();
758 if (this->IsThreadRunning())
760 m_LogList.SafeTerminateThread();
762 UpdateData();
764 SaveSplitterPos();
765 __super::OnCancel();
768 CString CLogDlg::MakeShortMessage(const CString& message)
770 bool bFoundShort = true;
771 CString sShortMessage = m_LogList.m_ProjectProperties.GetLogSummary(message);
772 if (sShortMessage.IsEmpty())
774 bFoundShort = false;
775 sShortMessage = message;
777 // Remove newlines and tabs 'cause those are not shown nicely in the list control
778 sShortMessage.Remove('\r');
779 sShortMessage.Replace(_T('\t'), _T(' '));
781 // Suppose the first empty line separates 'summary' from the rest of the message.
782 int found = sShortMessage.Find(_T("\n\n"));
783 // To avoid too short 'short' messages
784 // (e.g. if the message looks something like "Bugfix:\n\n*done this\n*done that")
785 // only use the empty newline as a separator if it comes after at least 15 chars.
786 if ((!bFoundShort)&&(found >= 15))
788 sShortMessage = sShortMessage.Left(found);
790 sShortMessage.Replace('\n', ' ');
791 return sShortMessage;
794 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*/)
796 #if 0
797 if (rev == SVN_INVALID_REVNUM)
799 m_childCounter--;
800 return TRUE;
803 // this is the callback function which receives the data for every revision we ask the log for
804 // we store this information here one by one.
805 m_logcounter += 1;
806 if (m_startrev == -1)
807 m_startrev = rev;
808 if (m_limit != 0)
810 m_limitcounter--;
811 m_LogProgress.SetPos(m_limit - m_limitcounter);
813 else if (m_startrev.IsNumber() && m_startrev.IsNumber())
814 m_LogProgress.SetPos((git_revnum_t)m_startrev-rev+(git_revnum_t)m_endrev);
815 __time64_t ttime = time/1000000L;
816 if (m_tTo < (DWORD)ttime)
817 m_tTo = (DWORD)ttime;
818 if (m_tFrom > (DWORD)ttime)
819 m_tFrom = (DWORD)ttime;
820 if ((m_lowestRev > rev)||(m_lowestRev < 0))
821 m_lowestRev = rev;
822 // Add as many characters from the log message to the list control
823 PLOGENTRYDATA pLogItem = new LOGENTRYDATA;
824 pLogItem->bCopies = !!copies;
826 // find out if this item was copied in the revision
827 BOOL copiedself = FALSE;
828 if (copies)
830 for (INT_PTR cpPathIndex = 0; cpPathIndex < cpaths->GetCount(); ++cpPathIndex)
832 LogChangedPath * cpath = cpaths->SafeGetAt(cpPathIndex);
833 if (!cpath->sCopyFromPath.IsEmpty() && (cpath->sPath.Compare(m_sSelfRelativeURL) == 0))
835 // note: this only works if the log is fetched top-to-bottom
836 // but since we do that, it shouldn't be a problem
837 m_sSelfRelativeURL = cpath->sCopyFromPath;
838 copiedself = TRUE;
839 break;
843 pLogItem->bCopiedSelf = copiedself;
844 pLogItem->tmDate = ttime;
845 pLogItem->sAuthor = author;
846 pLogItem->sDate = date;
847 pLogItem->sShortMessage = MakeShortMessage(message);
848 pLogItem->dwFileChanges = filechanges;
849 pLogItem->actions = actions;
850 pLogItem->haschildren = haschildren;
851 pLogItem->childStackDepth = m_childCounter;
852 m_maxChild = max(m_childCounter, m_maxChild);
853 if (haschildren)
854 m_childCounter++;
855 pLogItem->sBugIDs = m_ProjectProperties.FindBugID(message).Trim();
857 // split multi line log entries and concatenate them
858 // again but this time with \r\n as line separators
859 // so that the edit control recognizes them
862 if (message.GetLength()>0)
864 m_sMessageBuf = message;
865 m_sMessageBuf.Replace(_T("\n\r"), _T("\n"));
866 m_sMessageBuf.Replace(_T("\r\n"), _T("\n"));
867 if (m_sMessageBuf.Right(1).Compare(_T("\n"))==0)
868 m_sMessageBuf = m_sMessageBuf.Left(m_sMessageBuf.GetLength()-1);
870 else
871 m_sMessageBuf.Empty();
872 pLogItem->sMessage = m_sMessageBuf;
873 pLogItem->Rev = rev;
875 // move-construct path array
877 pLogItem->pArChangedPaths = new LogChangedPathArray (*cpaths);
878 cpaths->RemoveAll();
880 catch (CException * e)
882 ::MessageBox(NULL, _T("not enough memory!"), _T("TortoiseGit"), MB_ICONERROR);
883 e->Delete();
884 m_bCancelled = TRUE;
886 m_logEntries.push_back(pLogItem);
887 m_arShownList.Add(pLogItem);
888 #endif
889 return TRUE;
892 GitRev g_rev;
893 //this is the thread function which calls the subversion function
898 void CLogDlg::CopyChangedSelectionToClipBoard()
901 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
902 if (pos == NULL)
903 return; // nothing is selected, get out of here
905 CString sPaths;
907 // CGitRev* pLogEntry = reinterpret_cast<CGitRev* >(m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
908 // if (pos)
910 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
911 while (pos)
913 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
914 CTGitPath *path = (CTGitPath*)m_ChangedFileListCtrl.GetItemData(nItem);
915 if(path)
916 sPaths += path->GetGitPathString();
917 sPaths += _T("\r\n");
920 #if 0
921 else
923 // only one revision is selected in the log dialog top pane
924 // but multiple items could be selected in the changed items list
925 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
926 while (pos)
928 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
929 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(nItem);
931 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
933 // some items are hidden! So find out which item the user really selected
934 INT_PTR selRealIndex = -1;
935 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
937 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
938 selRealIndex++;
939 if (selRealIndex == nItem)
941 changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex);
942 break;
946 if (changedlogpath)
948 sPaths += changedlogpath->sPath;
949 sPaths += _T("\r\n");
953 #endif
954 sPaths.Trim();
955 CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());
959 BOOL CLogDlg::IsDiffPossible(LogChangedPath * /*changedpath*/, git_revnum_t rev)
961 #if 0
962 CString added, deleted;
963 if (changedpath == NULL)
964 return false;
966 if ((rev > 1)&&(changedpath->action != LOGACTIONS_DELETED))
968 if (changedpath->action == LOGACTIONS_ADDED) // file is added
970 if (changedpath->lCopyFromRev == 0)
971 return FALSE; // but file was not added with history
973 return TRUE;
975 #endif
976 return FALSE;
979 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)
981 // we have two separate context menus:
982 // one shown on the log message list control,
983 // the other shown in the changed-files list control
984 int selCount = m_LogList.GetSelectedCount();
985 if (pWnd == &m_LogList)
987 //ShowContextMenuForRevisions(pWnd, point);
989 else if (pWnd == &m_ChangedFileListCtrl)
991 //ShowContextMenuForChangedpaths(pWnd, point);
993 else if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))
995 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
996 int selIndex = -1;
997 if (pos)
998 selIndex = m_LogList.GetNextSelectedItem(pos);
1000 GitRev *pRev = ((GitRev*)m_LogList.m_arShownList[selIndex]);
1002 if ((point.x == -1) && (point.y == -1))
1004 CRect rect;
1005 GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);
1006 ClientToScreen(&rect);
1007 point = rect.CenterPoint();
1009 CString sMenuItemText;
1010 CIconMenu popup;
1011 if (popup.CreatePopupMenu())
1013 // add the 'default' entries
1014 sMenuItemText.LoadString(IDS_SCIEDIT_COPY);
1015 popup.AppendMenu(MF_STRING | MF_ENABLED, WM_COPY, sMenuItemText);
1016 sMenuItemText.LoadString(IDS_SCIEDIT_SELECTALL);
1017 popup.AppendMenu(MF_STRING | MF_ENABLED, EM_SETSEL, sMenuItemText);
1018 sMenuItemText.LoadString(IDS_EDIT_NOTES);
1019 popup.AppendMenuIcon( CGitLogList::ID_EDITNOTE, sMenuItemText, IDI_EDIT);
1021 //if (selIndex >= 0)
1023 // popup.AppendMenu(MF_SEPARATOR);
1024 // sMenuItemText.LoadString(IDS_LOG_POPUP_EDITLOG);
1025 // popup.AppendMenu(MF_STRING | MF_ENABLED, CGitLogList::ID_EDITAUTHOR, sMenuItemText);
1028 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1029 switch (cmd)
1031 case 0:
1032 break; // no command selected
1033 case EM_SETSEL:
1034 case WM_COPY:
1035 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);
1036 break;
1037 case CGitLogList::ID_EDITNOTE:
1038 CAppUtils::EditNote(pRev);
1039 this->FillLogMessageCtrl(true);
1040 break;
1046 void CLogDlg::OnOK()
1048 // since the log dialog is also used to select revisions for other
1049 // dialogs, we have to do some work before closing this dialog
1050 if (GetFocus() != GetDlgItem(IDOK))
1051 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter
1053 m_LogList.SafeTerminateAsyncDiffThread();
1054 if (this->IsThreadRunning())
1056 m_LogList.SafeTerminateThread();
1058 UpdateData();
1059 // check that one and only one row is selected
1060 if (m_LogList.GetSelectedCount() == 1)
1062 // get the selected row
1063 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1064 int selIndex = m_LogList.GetNextSelectedItem(pos);
1065 if (selIndex < m_LogList.m_arShownList.GetCount())
1067 // all ok, pick up the revision
1068 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
1069 // extract the hash
1070 m_sSelectedHash = pLogEntry->m_CommitHash;
1073 UpdateData(FALSE);
1074 SaveSplitterPos();
1075 __super::OnOK();
1077 #if 0
1078 if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))
1079 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.
1081 CString temp;
1082 CString buttontext;
1083 GetDlgItemText(IDOK, buttontext);
1084 temp.LoadString(IDS_MSGBOX_CANCEL);
1085 if (temp.Compare(buttontext) != 0)
1086 __super::OnOK(); // only exit if the button text matches, and that will match only if the thread isn't running anymore
1087 m_bCancelled = TRUE;
1088 m_selectedRevs.Clear();
1089 m_selectedRevsOneRange.Clear();
1090 if (m_pNotifyWindow)
1092 int selIndex = m_LogList.GetSelectionMark();
1093 if (selIndex >= 0)
1095 PLOGENTRYDATA pLogEntry = NULL;
1096 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1097 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1098 m_selectedRevs.AddRevision(pLogEntry->Rev);
1099 git_revnum_t lowerRev = pLogEntry->Rev;
1100 git_revnum_t higherRev = lowerRev;
1101 while (pos)
1103 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1104 git_revnum_t rev = pLogEntry->Rev;
1105 m_selectedRevs.AddRevision(pLogEntry->Rev);
1106 if (lowerRev > rev)
1107 lowerRev = rev;
1108 if (higherRev < rev)
1109 higherRev = rev;
1111 if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())
1113 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);
1115 BOOL bSentMessage = FALSE;
1116 if (m_LogList.GetSelectedCount() == 1)
1118 // if only one revision is selected, check if the path/url with which the dialog was started
1119 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.
1120 // if it was copied, use the copy from revision as lowerRev
1121 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))
1123 CString sUrl = m_path.GetGitPathString();
1124 if (!m_path.IsUrl())
1126 sUrl = GetURLFromPath(m_path);
1128 sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());
1129 for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)
1131 LogChangedPath * pData = pLogEntry->pArChangedPaths->SafeGetAt(cp);
1132 if (pData)
1134 if (sUrl.Compare(pData->sPath) == 0)
1136 if (!pData->sCopyFromPath.IsEmpty())
1138 lowerRev = pData->lCopyFromRev;
1139 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);
1140 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);
1141 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1142 bSentMessage = TRUE;
1149 if ( !bSentMessage )
1151 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);
1152 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);
1153 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1154 if (m_selectedRevsOneRange.GetCount())
1155 m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);
1159 UpdateData();
1160 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry"));
1161 reg = m_btnShow.GetCurrentEntry();
1162 SaveSplitterPos();
1163 #endif
1166 void CLogDlg::OnNMDblclkChangedFileList(NMHDR * /*pNMHDR*/, LRESULT *pResult)
1168 // a double click on an entry in the changed-files list has happened
1169 *pResult = 0;
1171 DiffSelectedFile();
1174 void CLogDlg::DiffSelectedFile()
1176 #if 0
1177 if (m_bThreadRunning)
1178 return;
1179 UpdateLogInfoLabel();
1180 INT_PTR selIndex = m_ChangedFileListCtrl.GetSelectionMark();
1181 if (selIndex < 0)
1182 return;
1183 if (m_ChangedFileListCtrl.GetSelectedCount() == 0)
1184 return;
1185 // find out if there's an entry selected in the log list
1186 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1187 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1188 git_revnum_t rev1 = pLogEntry->Rev;
1189 git_revnum_t rev2 = rev1;
1190 if (pos)
1192 while (pos)
1194 // there's at least a second entry selected in the log list: several revisions selected!
1195 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1196 if (pLogEntry)
1198 rev1 = max(rev1,(long)pLogEntry->Rev);
1199 rev2 = min(rev2,(long)pLogEntry->Rev);
1202 rev2--;
1203 // now we have both revisions selected in the log list, so we can do a diff of the selected
1204 // entry in the changed files list with these two revisions.
1205 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1207 else
1209 rev2 = rev1-1;
1210 // nothing or only one revision selected in the log list
1211 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
1213 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
1215 // some items are hidden! So find out which item the user really clicked on
1216 INT_PTR selRealIndex = -1;
1217 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
1219 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1220 selRealIndex++;
1221 if (selRealIndex == selIndex)
1223 selIndex = hiddenindex;
1224 changedpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
1225 break;
1230 if (IsDiffPossible(changedpath, rev1))
1232 // diffs with renamed files are possible
1233 if ((changedpath)&&(!changedpath->sCopyFromPath.IsEmpty()))
1234 rev2 = changedpath->lCopyFromRev;
1235 else
1237 // if the path was modified but the parent path was 'added with history'
1238 // then we have to use the copy from revision of the parent path
1239 CTGitPath cpath = CTGitPath(changedpath->sPath);
1240 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
1242 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->SafeGetAt(flist)->sPath);
1243 if (p.IsAncestorOf(cpath))
1245 if (!pLogEntry->pArChangedPaths->SafeGetAt(flist)->sCopyFromPath.IsEmpty())
1246 rev2 = pLogEntry->pArChangedPaths->SafeGetAt(flist)->lCopyFromRev;
1250 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1252 else
1254 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1255 CTGitPath tempfile2 = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1256 GitRev r = rev1;
1257 // deleted files must be opened from the revision before the deletion
1258 if (changedpath->action == LOGACTIONS_DELETED)
1259 r = rev1-1;
1260 m_bCancelled = false;
1262 CProgressDlg progDlg;
1263 progDlg.SetTitle(IDS_APPNAME);
1264 progDlg.SetAnimation(IDR_DOWNLOAD);
1265 CString sInfoLine;
1266 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)(m_sRepositoryRoot + changedpath->sPath), (LPCTSTR)r.ToString());
1267 progDlg.SetLine(1, sInfoLine, true);
1268 SetAndClearProgressInfo(&progDlg);
1269 progDlg.ShowModeless(m_hWnd);
1271 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), r, r, tempfile))
1273 m_bCancelled = false;
1274 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), GitRev::REV_HEAD, r, tempfile))
1276 progDlg.Stop();
1277 SetAndClearProgressInfo((HWND)NULL);
1278 CMessageBox::Show(m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1279 return;
1282 progDlg.Stop();
1283 SetAndClearProgressInfo((HWND)NULL);
1285 CString sName1, sName2;
1286 sName1.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1);
1287 sName2.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1-1);
1288 CAppUtils::DiffFlags flags;
1289 flags.AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1290 if (changedpath->action == LOGACTIONS_DELETED)
1291 CAppUtils::StartExtDiff(tempfile, tempfile2, sName2, sName1, flags);
1292 else
1293 CAppUtils::StartExtDiff(tempfile2, tempfile, sName2, sName1, flags);
1296 #endif
1300 void CLogDlg::DoDiffFromLog(INT_PTR selIndex, GitRev* rev1, GitRev* rev2, bool /*blame*/, bool /*unified*/)
1302 DialogEnableWindow(IDOK, FALSE);
1303 // SetPromptApp(&theApp);
1304 theApp.DoWaitCursor(1);
1306 CString temppath;
1307 GetTempPath(temppath);
1309 CString file1;
1310 file1.Format(_T("%s%s_%s%s"),
1311 temppath,
1312 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1313 rev1->m_CommitHash.ToString().Left(6),
1314 (*m_currentChangedArray)[selIndex].GetFileExtension());
1316 CString file2;
1317 file2.Format(_T("%s\\%s_%s%s"),
1318 temppath,
1319 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1320 rev2->m_CommitHash.ToString().Left(6),
1321 (*m_currentChangedArray)[selIndex].GetFileExtension());
1323 CString cmd;
1325 g_Git.GetOneFile(rev1->m_CommitHash.ToString(), (CTGitPath &)(*m_currentChangedArray)[selIndex],file1);
1327 g_Git.GetOneFile(rev2->m_CommitHash.ToString(), (CTGitPath &)(*m_currentChangedArray)[selIndex],file2);
1329 CAppUtils::DiffFlags flags;
1330 CAppUtils::StartExtDiff(file1,file2,_T("A"),_T("B"),flags);
1332 #if 0
1333 //get the filename
1334 CString filepath;
1335 if (Git::PathIsURL(m_path))
1337 filepath = m_path.GetGitPathString();
1339 else
1341 filepath = GetURLFromPath(m_path);
1342 if (filepath.IsEmpty())
1344 theApp.DoWaitCursor(-1);
1345 CString temp;
1346 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1347 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1348 TRACE(_T("could not retrieve the URL of the file!\n"));
1349 EnableOKButton();
1350 theApp.DoWaitCursor(-11);
1351 return; //exit
1354 m_bCancelled = FALSE;
1355 filepath = GetRepositoryRoot(CTGitPath(filepath));
1357 CString firstfile, secondfile;
1358 if (m_LogList.GetSelectedCount()==1)
1360 int s = m_LogList.GetSelectionMark();
1361 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(s));
1362 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
1363 firstfile = changedpath->sPath;
1364 secondfile = firstfile;
1365 if ((rev2 == rev1-1)&&(changedpath->lCopyFromRev > 0)) // is it an added file with history?
1367 secondfile = changedpath->sCopyFromPath;
1368 rev2 = changedpath->lCopyFromRev;
1371 else
1373 firstfile = m_currentChangedPathList[selIndex].GetGitPathString();
1374 secondfile = firstfile;
1377 firstfile = filepath + firstfile.Trim();
1378 secondfile = filepath + secondfile.Trim();
1380 GitDiff diff(this, this->m_hWnd, true);
1381 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1382 diff.SetHEADPeg(m_LogRevision);
1383 if (unified)
1385 if (PromptShown())
1386 diff.ShowUnifiedDiff(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1);
1387 else
1388 CAppUtils::StartShowUnifiedDiff(m_hWnd, CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), m_LogRevision);
1390 else
1392 if (diff.ShowCompare(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), false, blame))
1394 if (firstfile.Compare(secondfile)==0)
1396 git_revnum_t baseRev = 0;
1397 diff.DiffProps(CTGitPath(firstfile), rev2, rev1, baseRev);
1402 #endif
1404 theApp.DoWaitCursor(-1);
1405 EnableOKButton();
1408 BOOL CLogDlg::Open(bool /*bOpenWith*/,CString changedpath, git_revnum_t rev)
1410 #if 0
1411 DialogEnableWindow(IDOK, FALSE);
1412 SetPromptApp(&theApp);
1413 theApp.DoWaitCursor(1);
1414 CString filepath;
1415 if (Git::PathIsURL(m_path))
1417 filepath = m_path.GetGitPathString();
1419 else
1421 filepath = GetURLFromPath(m_path);
1422 if (filepath.IsEmpty())
1424 theApp.DoWaitCursor(-1);
1425 CString temp;
1426 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1427 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1428 TRACE(_T("could not retrieve the URL of the file!\n"));
1429 EnableOKButton();
1430 return FALSE;
1433 m_bCancelled = false;
1434 filepath = GetRepositoryRoot(CTGitPath(filepath));
1435 filepath += changedpath;
1437 CProgressDlg progDlg;
1438 progDlg.SetTitle(IDS_APPNAME);
1439 progDlg.SetAnimation(IDR_DOWNLOAD);
1440 CString sInfoLine;
1441 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)GitRev(rev).ToString());
1442 progDlg.SetLine(1, sInfoLine, true);
1443 SetAndClearProgressInfo(&progDlg);
1444 progDlg.ShowModeless(m_hWnd);
1446 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(filepath), rev);
1447 m_bCancelled = false;
1448 if (!Cat(CTGitPath(filepath), GitRev(rev), rev, tempfile))
1450 progDlg.Stop();
1451 SetAndClearProgressInfo((HWND)NULL);
1452 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1453 EnableOKButton();
1454 theApp.DoWaitCursor(-1);
1455 return FALSE;
1457 progDlg.Stop();
1458 SetAndClearProgressInfo((HWND)NULL);
1459 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1460 if (!bOpenWith)
1462 int ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1463 if (ret <= HINSTANCE_ERROR)
1464 bOpenWith = true;
1466 if (bOpenWith)
1468 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1469 cmd += tempfile.GetWinPathString() + _T(" ");
1470 CAppUtils::LaunchApplication(cmd, NULL, false);
1472 EnableOKButton();
1473 theApp.DoWaitCursor(-1);
1474 #endif
1475 return TRUE;
1478 void CLogDlg::EditAuthor(const CLogDataVector& /*logs*/)
1480 #if 0
1481 CString url;
1482 CString name;
1483 if (logs.size() == 0)
1484 return;
1485 DialogEnableWindow(IDOK, FALSE);
1486 SetPromptApp(&theApp);
1487 theApp.DoWaitCursor(1);
1488 if (Git::PathIsURL(m_path))
1489 url = m_path.GetGitPathString();
1490 else
1492 url = GetURLFromPath(m_path);
1494 name = Git_PROP_REVISION_AUTHOR;
1496 CString value = RevPropertyGet(name, CTGitPath(url), logs[0]->Rev);
1497 CString sOldValue = value;
1498 value.Replace(_T("\n"), _T("\r\n"));
1499 CInputDlg dlg(this);
1500 dlg.m_sHintText.LoadString(IDS_LOG_AUTHOR);
1501 dlg.m_sInputText = value;
1502 dlg.m_sTitle.LoadString(IDS_LOG_AUTHOREDITTITLE);
1503 dlg.m_pProjectProperties = &m_ProjectProperties;
1504 dlg.m_bUseLogWidth = false;
1505 if (dlg.DoModal() == IDOK)
1507 dlg.m_sInputText.Remove('\r');
1509 LogCache::CCachedLogInfo* toUpdate = GetLogCache (CTGitPath (m_sRepositoryRoot));
1511 CProgressDlg progDlg;
1512 progDlg.SetTitle(IDS_APPNAME);
1513 progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));
1514 progDlg.SetTime(true);
1515 progDlg.SetShowProgressBar(true);
1516 progDlg.ShowModeless(m_hWnd);
1517 for (DWORD i=0; i<logs.size(); ++i)
1519 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), logs[i]->Rev))
1521 progDlg.Stop();
1522 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1523 break;
1525 else
1528 logs[i]->sAuthor = dlg.m_sInputText;
1529 m_LogList.Invalidate();
1531 // update the log cache
1533 if (toUpdate != NULL)
1535 // log caching is active
1537 LogCache::CCachedLogInfo newInfo;
1538 newInfo.Insert ( logs[i]->Rev
1539 , (const char*) CUnicodeUtils::GetUTF8 (logs[i]->sAuthor)
1540 , ""
1542 , LogCache::CRevisionInfoContainer::HAS_AUTHOR);
1544 toUpdate->Update (newInfo);
1547 progDlg.SetProgress64(i, logs.size());
1549 progDlg.Stop();
1551 theApp.DoWaitCursor(-1);
1552 EnableOKButton();
1553 #endif
1556 void CLogDlg::EditLogMessage(int /*index*/)
1559 #if 0
1560 CString url;
1561 CString name;
1562 DialogEnableWindow(IDOK, FALSE);
1563 SetPromptApp(&theApp);
1564 theApp.DoWaitCursor(1);
1565 if (Git::PathIsURL(m_path))
1566 url = m_path.GetGitPathString();
1567 else
1569 url = GetURLFromPath(m_path);
1571 name = Git_PROP_REVISION_LOG;
1573 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(index));
1574 m_bCancelled = FALSE;
1575 CString value = RevPropertyGet(name, CTGitPath(url), pLogEntry->Rev);
1576 CString sOldValue = value;
1577 value.Replace(_T("\n"), _T("\r\n"));
1578 CInputDlg dlg(this);
1579 dlg.m_sHintText.LoadString(IDS_LOG_MESSAGE);
1580 dlg.m_sInputText = value;
1581 dlg.m_sTitle.LoadString(IDS_LOG_MESSAGEEDITTITLE);
1582 dlg.m_pProjectProperties = &m_ProjectProperties;
1583 dlg.m_bUseLogWidth = true;
1584 if (dlg.DoModal() == IDOK)
1586 dlg.m_sInputText.Remove('\r');
1587 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), pLogEntry->Rev))
1589 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1591 else
1593 pLogEntry->sShortMessage = MakeShortMessage(dlg.m_sInputText);
1594 // split multi line log entries and concatenate them
1595 // again but this time with \r\n as line separators
1596 // so that the edit control recognizes them
1597 if (dlg.m_sInputText.GetLength()>0)
1599 m_sMessageBuf = dlg.m_sInputText;
1600 dlg.m_sInputText.Replace(_T("\n\r"), _T("\n"));
1601 dlg.m_sInputText.Replace(_T("\r\n"), _T("\n"));
1602 if (dlg.m_sInputText.Right(1).Compare(_T("\n"))==0)
1603 dlg.m_sInputText = dlg.m_sInputText.Left(dlg.m_sInputText.GetLength()-1);
1605 else
1606 dlg.m_sInputText.Empty();
1607 pLogEntry->sMessage = dlg.m_sInputText;
1608 pLogEntry->sBugIDs = m_ProjectProperties.FindBugID(dlg.m_sInputText);
1609 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
1610 pMsgView->SetWindowText(_T(" "));
1611 pMsgView->SetWindowText(dlg.m_sInputText);
1612 m_ProjectProperties.FindBugID(dlg.m_sInputText, pMsgView);
1613 m_LogList.Invalidate();
1615 // update the log cache
1616 LogCache::CCachedLogInfo* toUpdate = GetLogCache(CTGitPath (m_sRepositoryRoot));
1617 if (toUpdate != NULL)
1619 // log caching is active
1621 LogCache::CCachedLogInfo newInfo;
1622 newInfo.Insert( pLogEntry->Rev
1623 , ""
1624 , (const char*) CUnicodeUtils::GetUTF8 (pLogEntry->sMessage)
1626 , LogCache::CRevisionInfoContainer::HAS_COMMENT);
1628 toUpdate->Update(newInfo);
1632 theApp.DoWaitCursor(-1);
1633 EnableOKButton();
1634 #endif
1637 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)
1639 // Skip Ctrl-C when copying text out of the log message or search filter
1640 BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );
1641 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
1643 if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1645 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1647 m_LogList.DiffSelectedRevWithPrevious();
1648 return TRUE;
1652 if (m_hAccel && !bSkipAccelerator)
1654 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1655 if (ret)
1656 return TRUE;
1659 if(::IsWindow(m_tooltips.m_hWnd))
1660 m_tooltips.RelayEvent(pMsg);
1661 return __super::PreTranslateMessage(pMsg);
1665 BOOL CLogDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1667 //if (this->IsThreadRunning())
1668 if(m_LogList.m_bNoDispUpdates)
1670 // only show the wait cursor over the list control
1671 if ((pWnd)&&
1672 ((pWnd == GetDlgItem(IDC_LOGLIST))||
1673 (pWnd == GetDlgItem(IDC_MSGVIEW))||
1674 (pWnd == GetDlgItem(IDC_LOGMSG))))
1676 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1677 SetCursor(hCur);
1678 return TRUE;
1681 if ((pWnd) && (pWnd == GetDlgItem(IDC_MSGVIEW)))
1682 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1684 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1685 SetCursor(hCur);
1686 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1689 void CLogDlg::OnBnClickedHelp()
1691 OnHelp();
1694 void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1696 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1697 *pResult = 0;
1698 //if (this->IsThreadRunning())
1699 if(m_LogList.m_bNoDispUpdates)
1700 return;
1701 if (pNMLV->iItem >= 0)
1703 this->m_LogList.m_nSearchIndex = pNMLV->iItem;
1704 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(pNMLV->iItem));
1705 m_LogList.m_lastSelectedHash = pLogEntry->m_CommitHash;
1706 if (pNMLV->iSubItem != 0)
1707 return;
1708 if ((pNMLV->iItem == m_LogList.m_arShownList.GetCount()))
1710 // remove the selected state
1711 if (pNMLV->uChanged & LVIF_STATE)
1713 m_LogList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);
1714 FillLogMessageCtrl();
1715 UpdateData(FALSE);
1716 UpdateLogInfoLabel();
1718 return;
1720 if (pNMLV->uChanged & LVIF_STATE)
1722 FillLogMessageCtrl();
1723 UpdateData(FALSE);
1726 else
1728 m_LogList.m_lastSelectedHash.Empty();
1729 FillLogMessageCtrl();
1730 UpdateData(FALSE);
1732 EnableOKButton();
1733 UpdateLogInfoLabel();
1736 void CLogDlg::OnEnLinkMsgview(NMHDR *pNMHDR, LRESULT *pResult)
1738 ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);
1739 if (pEnLink->msg == WM_LBUTTONUP)
1741 CString url, msg;
1742 GetDlgItemText(IDC_MSGVIEW, msg);
1743 msg.Replace(_T("\r\n"), _T("\n"));
1744 url = msg.Mid(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax-pEnLink->chrg.cpMin);
1745 if (!::PathIsURL(url))
1747 url = m_LogList.m_ProjectProperties.GetBugIDUrl(url);
1748 url = GetAbsoluteUrlFromRelativeUrl(url);
1750 if (!url.IsEmpty())
1751 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
1753 *pResult = 0;
1756 class CDateSorter
1758 public:
1759 class CCommitPointer
1761 public:
1762 CCommitPointer():m_cont(NULL){}
1763 CCommitPointer(const CCommitPointer& P_Right)
1764 : m_cont(NULL)
1766 *this = P_Right;
1769 CCommitPointer& operator = (const CCommitPointer& P_Right)
1771 if(IsPointer())
1773 (*m_cont->m_parDates)[m_place] = P_Right.GetDate();
1774 (*m_cont->m_parFileChanges)[m_place] = P_Right.GetChanges();
1775 (*m_cont->m_parAuthors)[m_place] = P_Right.GetAuthor();
1777 else
1779 m_Date = P_Right.GetDate();
1780 m_Changes = P_Right.GetChanges();
1781 m_csAuthor = P_Right.GetAuthor();
1783 return *this;
1786 void Clone(const CCommitPointer& P_Right)
1788 m_cont = P_Right.m_cont;
1789 m_place = P_Right.m_place;
1790 m_Date = P_Right.m_Date;
1791 m_Changes = P_Right.m_Changes;
1792 m_csAuthor = P_Right.m_csAuthor;
1795 DWORD GetDate() const {return IsPointer() ? (*m_cont->m_parDates)[m_place] : m_Date;}
1796 DWORD GetChanges() const {return IsPointer() ? (*m_cont->m_parFileChanges)[m_place] : m_Changes;}
1797 CString GetAuthor() const {return IsPointer() ? (*m_cont->m_parAuthors)[m_place] : m_csAuthor;}
1799 bool IsPointer() const {return m_cont != NULL;}
1800 //When pointer
1801 CDateSorter* m_cont;
1802 int m_place;
1804 //When element
1805 DWORD m_Date;
1806 DWORD m_Changes;
1807 CString m_csAuthor;
1810 class iterator : public std::iterator<std::random_access_iterator_tag, CCommitPointer>
1812 public:
1813 CCommitPointer m_ptr;
1815 iterator(){}
1816 iterator(const iterator& P_Right){*this = P_Right;}
1817 iterator& operator=(const iterator& P_Right)
1819 m_ptr.Clone(P_Right.m_ptr);
1820 return *this;
1823 CCommitPointer& operator*(){return m_ptr;}
1824 CCommitPointer* operator->(){return &m_ptr;}
1825 const CCommitPointer& operator*()const{return m_ptr;}
1826 const CCommitPointer* operator->()const{return &m_ptr;}
1828 iterator& operator+=(size_t P_iOffset){m_ptr.m_place += P_iOffset;return *this;}
1829 iterator& operator-=(size_t P_iOffset){m_ptr.m_place -= P_iOffset;return *this;}
1830 iterator operator+(size_t P_iOffset)const{iterator it(*this); it += P_iOffset;return it;}
1831 iterator operator-(size_t P_iOffset)const{iterator it(*this); it -= P_iOffset;return it;}
1833 iterator& operator++(){++m_ptr.m_place;return *this;}
1834 iterator& operator--(){--m_ptr.m_place;return *this;}
1835 iterator operator++(int){iterator it(*this);++*this;return it;}
1836 iterator operator--(int){iterator it(*this);--*this;return it;}
1838 size_t 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;}
1843 bool operator>(const iterator& P_itRight)const{return m_ptr.m_place > P_itRight->m_place;}
1845 iterator begin()
1847 iterator it;
1848 it->m_place = 0;
1849 it->m_cont = this;
1850 return it;
1852 iterator end()
1854 iterator it;
1855 it->m_place = m_parDates->GetCount();
1856 it->m_cont = this;
1857 return it;
1860 CDWordArray * m_parDates;
1861 CDWordArray * m_parFileChanges;
1862 CStringArray * m_parAuthors;
1865 class CDateSorterLess
1867 public:
1868 bool operator () (const CDateSorter::CCommitPointer& P_Left, const CDateSorter::CCommitPointer& P_Right) const
1870 return P_Left.GetDate() > P_Right.GetDate(); //Last date first
1877 void CLogDlg::OnBnClickedStatbutton()
1879 if (this->IsThreadRunning())
1880 return;
1881 if (m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1)
1882 return; // nothing or just the working copy changes are shown, so no statistics.
1883 // the statistics dialog expects the log entries to be sorted by date
1884 SortByColumn(3, false);
1885 CThreadSafePtrArray shownlist(NULL);
1886 m_LogList.RecalculateShownList(&shownlist);
1887 // create arrays which are aware of the current filter
1888 CStringArray m_arAuthorsFiltered;
1889 CDWordArray m_arDatesFiltered;
1890 CDWordArray m_arFileChangesFiltered;
1891 for (INT_PTR i=0; i<shownlist.GetCount(); ++i)
1893 GitRev* pLogEntry = reinterpret_cast<GitRev*>(shownlist.SafeGetAt(i));
1895 // do not take working dir changes into statistics
1896 if (pLogEntry->m_CommitHash.IsEmpty()) {
1897 continue;
1900 CString strAuthor = pLogEntry->GetAuthorName();
1901 if ( strAuthor.IsEmpty() )
1903 strAuthor.LoadString(IDS_STATGRAPH_EMPTYAUTHOR);
1905 m_arAuthorsFiltered.Add(strAuthor);
1906 m_arDatesFiltered.Add(pLogEntry->GetCommitterDate().GetTime());
1907 m_arFileChangesFiltered.Add(pLogEntry->GetFiles(&m_LogList).GetCount());
1910 CDateSorter W_Sorter;
1911 W_Sorter.m_parAuthors = &m_arAuthorsFiltered;
1912 W_Sorter.m_parDates = &m_arDatesFiltered;
1913 W_Sorter.m_parFileChanges = &m_arFileChangesFiltered;
1914 std::sort(W_Sorter.begin(), W_Sorter.end(), CDateSorterLess());
1916 CStatGraphDlg dlg;
1917 dlg.m_parAuthors = &m_arAuthorsFiltered;
1918 dlg.m_parDates = &m_arDatesFiltered;
1919 dlg.m_parFileChanges = &m_arFileChangesFiltered;
1920 dlg.m_path = m_orgPath;
1921 dlg.DoModal();
1922 // restore the previous sorting
1923 SortByColumn(m_nSortColumn, m_bAscending);
1924 OnTimer(LOGFILTER_TIMER);
1927 void CLogDlg::DoSizeV1(int delta)
1930 RemoveAnchor(IDC_LOGLIST);
1931 RemoveAnchor(IDC_SPLITTERTOP);
1932 RemoveAnchor(IDC_MSGVIEW);
1933 RemoveAnchor(IDC_SPLITTERBOTTOM);
1934 RemoveAnchor(IDC_LOGMSG);
1935 CSplitterControl::ChangeHeight(&m_LogList, delta, CW_TOPALIGN);
1936 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), -delta, CW_BOTTOMALIGN);
1937 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1938 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1939 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1940 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1941 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1942 ArrangeLayout();
1943 AdjustMinSize();
1944 SetSplitterRange();
1945 m_LogList.Invalidate();
1946 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1950 void CLogDlg::DoSizeV2(int delta)
1953 RemoveAnchor(IDC_LOGLIST);
1954 RemoveAnchor(IDC_SPLITTERTOP);
1955 RemoveAnchor(IDC_MSGVIEW);
1956 RemoveAnchor(IDC_SPLITTERBOTTOM);
1957 RemoveAnchor(IDC_LOGMSG);
1958 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), delta, CW_TOPALIGN);
1959 CSplitterControl::ChangeHeight(&m_ChangedFileListCtrl, -delta, CW_BOTTOMALIGN);
1960 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1961 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1962 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1963 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1964 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1965 ArrangeLayout();
1966 AdjustMinSize();
1967 SetSplitterRange();
1968 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1969 m_ChangedFileListCtrl.Invalidate();
1973 void CLogDlg::AdjustMinSize()
1975 // adjust the minimum size of the dialog to prevent the resizing from
1976 // moving the list control too far down.
1977 CRect rcChgListView;
1978 m_ChangedFileListCtrl.GetClientRect(rcChgListView);
1979 CRect rcLogList;
1980 m_LogList.GetClientRect(rcLogList);
1982 SetMinTrackSize(CSize(m_DlgOrigRect.Width(),
1983 m_DlgOrigRect.Height()-m_ChgOrigRect.Height()-m_LogListOrigRect.Height()-m_MsgViewOrigRect.Height()
1984 +rcChgListView.Height()+rcLogList.Height()+60));
1987 LRESULT CLogDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1989 switch (message) {
1990 case WM_NOTIFY:
1991 if (wParam == IDC_SPLITTERTOP)
1993 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1994 DoSizeV1(pHdr->delta);
1996 else if (wParam == IDC_SPLITTERBOTTOM)
1998 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1999 DoSizeV2(pHdr->delta);
2001 break;
2004 return CResizableDialog::DefWindowProc(message, wParam, lParam);
2007 void CLogDlg::SetSplitterRange()
2009 if ((m_LogList)&&(m_ChangedFileListCtrl))
2011 CRect rcTop;
2012 m_LogList.GetWindowRect(rcTop);
2013 ScreenToClient(rcTop);
2014 CRect rcMiddle;
2015 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(rcMiddle);
2016 ScreenToClient(rcMiddle);
2017 m_wndSplitter1.SetRange(rcTop.top+30, rcMiddle.bottom-20);
2018 CRect rcBottom;
2019 m_ChangedFileListCtrl.GetWindowRect(rcBottom);
2020 ScreenToClient(rcBottom);
2021 m_wndSplitter2.SetRange(rcMiddle.top+30, rcBottom.bottom-20);
2025 LRESULT CLogDlg::OnClickedInfoIcon(WPARAM /*wParam*/, LPARAM lParam)
2027 // FIXME: x64 version would get this function called with unexpected parameters.
2028 if (!lParam)
2029 return 0;
2031 RECT * rect = (LPRECT)lParam;
2032 CPoint point;
2033 CString temp;
2034 point = CPoint(rect->left, rect->bottom);
2035 #define LOGMENUFLAGS(x) (MF_STRING | MF_ENABLED | (m_LogList.m_nSelectedFilter == x ? MF_CHECKED : MF_UNCHECKED))
2036 CMenu popup;
2037 if (popup.CreatePopupMenu())
2039 temp.LoadString(IDS_LOG_FILTER_ALL);
2040 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_ALL), LOGFILTER_ALL, temp);
2042 popup.AppendMenu(MF_SEPARATOR, NULL);
2044 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2045 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_MESSAGES), LOGFILTER_MESSAGES, temp);
2047 temp.LoadString(IDS_LOG_FILTER_PATHS);
2048 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_PATHS), LOGFILTER_PATHS, temp);
2050 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2051 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_AUTHORS), LOGFILTER_AUTHORS, temp);
2053 temp.LoadString(IDS_LOG_FILTER_REVS);
2054 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REVS), LOGFILTER_REVS, temp);
2056 if (m_LogList.m_bShowBugtraqColumn == true) {
2057 temp.LoadString(IDS_LOG_FILTER_BUGIDS);
2058 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_BUGID), LOGFILTER_BUGID, temp);
2061 popup.AppendMenu(MF_SEPARATOR, NULL);
2063 temp.LoadString(IDS_LOG_FILTER_REGEX);
2064 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterWithRegex ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_REGEX, temp);
2066 m_tooltips.Pop();
2067 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2068 if (selection != 0)
2071 if (selection == LOGFILTER_REGEX)
2073 m_bFilterWithRegex = !m_bFilterWithRegex;
2074 CRegDWORD b = CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
2075 b = m_bFilterWithRegex;
2076 m_LogList.m_bFilterWithRegex = m_bFilterWithRegex;
2077 SetFilterCueText();
2078 CheckRegexpTooltip();
2080 else
2082 m_LogList.m_nSelectedFilter = selection;
2083 SetFilterCueText();
2085 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2088 return 0L;
2091 LRESULT CLogDlg::OnClickedCancelFilter(WPARAM /*wParam*/, LPARAM /*lParam*/)
2094 KillTimer(LOGFILTER_TIMER);
2096 m_LogList.m_sFilterText.Empty();
2097 UpdateData(FALSE);
2098 theApp.DoWaitCursor(1);
2099 CStoreSelection storeselection(this);
2100 FillLogMessageCtrl(false);
2102 m_LogList.RemoveFilter();
2104 Refresh();
2106 CTime begin,end;
2107 m_LogList.GetTimeRange(begin,end);
2108 m_DateFrom.SetTime(&begin);
2109 m_DateTo.SetTime(&end);
2111 theApp.DoWaitCursor(-1);
2112 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2113 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2114 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2115 UpdateLogInfoLabel();
2117 return 0L;
2121 void CLogDlg::SetFilterCueText()
2123 CString temp;
2124 switch (m_LogList.m_nSelectedFilter)
2126 case LOGFILTER_ALL:
2127 temp.LoadString(IDS_LOG_FILTER_ALL);
2128 break;
2129 case LOGFILTER_MESSAGES:
2130 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2131 break;
2132 case LOGFILTER_PATHS:
2133 temp.LoadString(IDS_LOG_FILTER_PATHS);
2134 break;
2135 case LOGFILTER_AUTHORS:
2136 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2137 break;
2138 case LOGFILTER_REVS:
2139 temp.LoadString(IDS_LOG_FILTER_REVS);
2140 break;
2142 // to make the cue banner text appear more to the right of the edit control
2143 temp = _T(" ")+temp;
2144 m_cFilter.SetCueBanner(temp);
2147 bool CLogDlg::Validate(LPCTSTR string)
2149 if (!m_bFilterWithRegex)
2150 return true;
2151 tr1::wregex pat;
2152 return m_LogList.ValidateRegexp(string, pat, false);
2156 void CLogDlg::OnTimer(UINT_PTR nIDEvent)
2158 if (nIDEvent == LOGFTIME_TIMER)
2160 KillTimer(LOGFTIME_TIMER);
2161 m_limit = 0;
2162 m_LogList.Refresh(FALSE);
2163 FillLogMessageCtrl(false);
2166 if (nIDEvent == LOGFILTER_TIMER)
2168 KillTimer(LOGFILTER_TIMER);
2169 m_limit = 0;
2170 m_LogList.Refresh(FALSE);
2171 FillLogMessageCtrl(false);
2173 #if 0
2174 /* we will use git built-in grep to filter log */
2175 if (this->IsThreadRunning())
2177 // thread still running! So just restart the timer.
2178 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2179 return;
2181 CWnd * focusWnd = GetFocus();
2182 bool bSetFocusToFilterControl = ((focusWnd != GetDlgItem(IDC_DATEFROM))&&(focusWnd != GetDlgItem(IDC_DATETO))
2183 && (focusWnd != GetDlgItem(IDC_LOGLIST)));
2184 if (m_LogList.m_sFilterText.IsEmpty())
2186 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2187 // do not return here!
2188 // we also need to run the filter if the filter text is empty:
2189 // 1. to clear an existing filter
2190 // 2. to rebuild the m_arShownList after sorting
2192 theApp.DoWaitCursor(1);
2193 CStoreSelection storeselection(this);
2194 KillTimer(LOGFILTER_TIMER);
2195 FillLogMessageCtrl(false);
2197 // now start filter the log list
2198 m_LogList.StartFilter();
2200 if ( m_LogList.GetItemCount()==1 )
2202 m_LogList.SetSelectionMark(0);
2203 m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
2205 theApp.DoWaitCursor(-1);
2206 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2207 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2208 if (bSetFocusToFilterControl)
2209 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2210 UpdateLogInfoLabel();
2211 #endif
2212 } // if (nIDEvent == LOGFILTER_TIMER)
2213 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1))));
2214 __super::OnTimer(nIDEvent);
2217 void CLogDlg::OnDtnDatetimechangeDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2221 CTime _time;
2222 m_DateTo.GetTime(_time);
2224 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 23, 59, 59);
2225 if (time.GetTime() != m_LogList.m_To)
2227 m_LogList.m_To = (DWORD)time.GetTime();
2228 SetTimer(LOGFTIME_TIMER, 10, NULL);
2231 catch (...)
2233 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2236 *pResult = 0;
2239 void CLogDlg::OnDtnDatetimechangeDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2244 CTime _time;
2245 m_DateFrom.GetTime(_time);
2247 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 0, 0, 0);
2248 if (time.GetTime() != m_LogList.m_From)
2250 m_LogList.m_From = (DWORD)time.GetTime();
2251 SetTimer(LOGFTIME_TIMER, 10, NULL);
2254 catch (...)
2256 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2259 *pResult = 0;
2264 CTGitPathList CLogDlg::GetChangedPathsFromSelectedRevisions(bool /*bRelativePaths*/ /* = false */, bool /*bUseFilter*/ /* = true */)
2266 CTGitPathList pathList;
2267 #if 0
2269 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2271 m_sRepositoryRoot = GetRepositoryRoot(m_path);
2273 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2274 return pathList;
2276 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2277 if (pos != NULL)
2279 while (pos)
2281 int nextpos = m_LogList.GetNextSelectedItem(pos);
2282 if (nextpos >= m_arShownList.GetCount())
2283 continue;
2284 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(nextpos));
2285 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2286 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
2288 LogChangedPath * cpath = cpatharray->SafeGetAt(cpPathIndex);
2289 if (cpath == NULL)
2290 continue;
2291 CTGitPath path;
2292 if (!bRelativePaths)
2293 path.SetFromGit(m_sRepositoryRoot);
2294 path.AppendPathString(cpath->sPath);
2295 if ((!bUseFilter)||
2296 ((m_cHidePaths.GetState() & 0x0003)!=BST_CHECKED)||
2297 (cpath->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0))
2298 pathList.AddPath(path);
2303 pathList.RemoveDuplicates();
2304 #endif
2305 return pathList;
2308 void CLogDlg::SortByColumn(int /*nSortColumn*/, bool /*bAscending*/)
2310 #if 0
2311 switch(nSortColumn)
2313 case 0: // Revision
2315 if(bAscending)
2316 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscRevSort());
2317 else
2318 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescRevSort());
2320 break;
2321 case 1: // action
2323 if(bAscending)
2324 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscActionSort());
2325 else
2326 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescActionSort());
2328 break;
2329 case 2: // Author
2331 if(bAscending)
2332 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscAuthorSort());
2333 else
2334 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescAuthorSort());
2336 break;
2337 case 3: // Date
2339 if(bAscending)
2340 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscDateSort());
2341 else
2342 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescDateSort());
2344 break;
2345 case 4: // Message or bug id
2346 if (m_bShowBugtraqColumn)
2348 if(bAscending)
2349 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscBugIDSort());
2350 else
2351 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescBugIDSort());
2352 break;
2354 // fall through here
2355 case 5: // Message
2357 if(bAscending)
2358 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscMessageSort());
2359 else
2360 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescMessageSort());
2362 break;
2363 default:
2364 ATLASSERT(0);
2365 break;
2367 #endif
2370 void CLogDlg::OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult)
2372 if (this->IsThreadRunning())
2373 return; //no sorting while the arrays are filled
2374 #if 0
2375 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2376 const int nColumn = pNMLV->iSubItem;
2377 m_bAscending = nColumn == m_nSortColumn ? !m_bAscending : TRUE;
2378 m_nSortColumn = nColumn;
2379 SortByColumn(m_nSortColumn, m_bAscending);
2380 SetSortArrow(&m_LogList, m_nSortColumn, !!m_bAscending);
2381 SortShownListArray();
2382 m_LogList.Invalidate();
2383 UpdateLogInfoLabel();
2384 #else
2385 UNREFERENCED_PARAMETER(pNMHDR);
2386 #endif
2387 *pResult = 0;
2390 void CLogDlg::SortShownListArray()
2392 // make sure the shown list still matches the filter after sorting.
2393 OnTimer(LOGFILTER_TIMER);
2394 // clear the selection states
2395 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2396 while (pos)
2398 m_LogList.SetItemState(m_LogList.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
2400 m_LogList.SetSelectionMark(-1);
2403 void CLogDlg::SetSortArrow(CListCtrl * control, int nColumn, bool bAscending)
2405 if (control == NULL)
2406 return;
2407 // set the sort arrow
2408 CHeaderCtrl * pHeader = control->GetHeaderCtrl();
2409 HDITEM HeaderItem = {0};
2410 HeaderItem.mask = HDI_FORMAT;
2411 for (int i=0; i<pHeader->GetItemCount(); ++i)
2413 pHeader->GetItem(i, &HeaderItem);
2414 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
2415 pHeader->SetItem(i, &HeaderItem);
2417 if (nColumn >= 0)
2419 pHeader->GetItem(nColumn, &HeaderItem);
2420 HeaderItem.fmt |= (bAscending ? HDF_SORTUP : HDF_SORTDOWN);
2421 pHeader->SetItem(nColumn, &HeaderItem);
2424 void CLogDlg::OnLvnColumnclickChangedFileList(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
2426 #if 0
2427 if (this->IsThreadRunning())
2428 return; //no sorting while the arrays are filled
2429 if (m_currentChangedArray == NULL)
2430 return;
2431 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2432 const int nColumn = pNMLV->iSubItem;
2433 m_bAscendingPathList = nColumn == m_nSortColumnPathList ? !m_bAscendingPathList : TRUE;
2434 m_nSortColumnPathList = nColumn;
2435 // qsort(m_currentChangedArray->GetData(), m_currentChangedArray->GetSize(), sizeof(LogChangedPath*), (GENERICCOMPAREFN)SortCompare);
2437 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
2438 m_ChangedFileListCtrl.Invalidate();
2439 *pResult = 0;
2440 #endif
2443 int CLogDlg::m_nSortColumnPathList = 0;
2444 bool CLogDlg::m_bAscendingPathList = false;
2446 int CLogDlg::SortCompare(const void * /*pElem1*/, const void * /*pElem2*/)
2448 #if 0
2449 LogChangedPath * cpath1 = *((LogChangedPath**)pElem1);
2450 LogChangedPath * cpath2 = *((LogChangedPath**)pElem2);
2452 if (m_bAscendingPathList)
2453 std::swap (cpath1, cpath2);
2455 int cmp = 0;
2456 switch (m_nSortColumnPathList)
2458 case 0: // action
2459 cmp = cpath2->GetAction().Compare(cpath1->GetAction());
2460 if (cmp)
2461 return cmp;
2462 // fall through
2463 case 1: // path
2464 cmp = cpath2->sPath.CompareNoCase(cpath1->sPath);
2465 if (cmp)
2466 return cmp;
2467 // fall through
2468 case 2: // copy from path
2469 cmp = cpath2->sCopyFromPath.Compare(cpath1->sCopyFromPath);
2470 if (cmp)
2471 return cmp;
2472 // fall through
2473 case 3: // copy from revision
2474 return cpath2->lCopyFromRev > cpath1->lCopyFromRev;
2476 #endif
2477 return 0;
2480 void CLogDlg::OnBnClickedHidepaths()
2482 FillLogMessageCtrl();
2483 m_ChangedFileListCtrl.Invalidate();
2488 void CLogDlg::OnBnClickedCheckStoponcopy()
2490 #if 0
2491 if (!GetDlgItem(IDC_GETALL)->IsWindowEnabled())
2492 return;
2494 // ignore old fetch limits when switching
2495 // between copy-following and stop-on-copy
2496 // (otherwise stop-on-copy will limit what
2497 // we see immediately after switching to
2498 // copy-following)
2500 m_endrev = 0;
2502 // now, restart the query
2503 #endif
2504 Refresh();
2508 void CLogDlg::UpdateLogInfoLabel()
2511 CGitHash rev1 ;
2512 CGitHash rev2 ;
2513 long selectedrevs = 0;
2514 int count =m_LogList.m_arShownList.GetCount();
2515 int start = 0;
2516 if (count)
2518 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(0)))->m_CommitHash;
2519 if(this->m_LogList.m_bShowWC && rev1.IsEmpty()&&(count>1))
2520 start = 1;
2521 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(start)))->m_CommitHash;
2522 //pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_arShownList.GetCount()-1));
2523 rev2 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(count-1)))->m_CommitHash;
2524 selectedrevs = m_LogList.GetSelectedCount();
2526 CString sTemp;
2527 sTemp.Format(_T("Showing %ld revision(s), from revision %s to revision %s - %ld revision(s) selected\r\n"),
2528 count - start,
2529 rev2.ToString().Left(6), rev1.ToString().Left(6), selectedrevs);
2531 if(selectedrevs == 1)
2533 CString str=m_ChangedFileListCtrl.GetStatisticsString(true);
2534 str.Replace(_T('\n'), _T(' '));
2535 sTemp += str;
2537 m_sLogInfo = sTemp;
2539 UpdateData(FALSE);
2542 #if 0
2543 void CLogDlg::ShowContextMenuForChangedpaths(CWnd* /*pWnd*/, CPoint point)
2546 int selIndex = m_ChangedFileListCtrl.GetSelectionMark();
2547 if ((point.x == -1) && (point.y == -1))
2549 CRect rect;
2550 m_ChangedFileListCtrl.GetItemRect(selIndex, &rect, LVIR_LABEL);
2551 m_ChangedFileListCtrl.ClientToScreen(&rect);
2552 point = rect.CenterPoint();
2554 if (selIndex < 0)
2555 return;
2556 int s = m_LogList.GetSelectionMark();
2557 if (s < 0)
2558 return;
2559 std::vector<CString> changedpaths;
2560 std::vector<LogChangedPath*> changedlogpaths;
2561 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2562 if (pos == NULL)
2563 return; // nothing is selected, get out of here
2565 bool bOneRev = true;
2566 int sel=m_LogList.GetNextSelectedItem(pos);
2567 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(sel));
2568 GitRev * rev1 = pLogEntry;
2569 GitRev * rev2 = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(sel+1));
2570 #if 0
2571 bool bOneRev = true;
2572 if (pos)
2574 while (pos)
2576 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2577 if (pLogEntry)
2579 rev1 = max(rev1,(git_revnum_t)pLogEntry->Rev);
2580 rev2 = min(rev2,(git_revnum_t)pLogEntry->Rev);
2581 bOneRev = false;
2584 if (!bOneRev)
2585 rev2--;
2586 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
2587 while (pos)
2589 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
2590 changedpaths.push_back(m_currentChangedPathList[nItem].GetGitPathString());
2593 else
2595 // only one revision is selected in the log dialog top pane
2596 // but multiple items could be selected in the changed items list
2597 rev2 = rev1-1;
2599 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
2600 while (pos)
2602 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
2603 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(nItem);
2605 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
2607 if ((changedlogpath)&&(!changedlogpath->sCopyFromPath.IsEmpty()))
2608 rev2 = changedlogpath->lCopyFromRev;
2609 else
2611 // if the path was modified but the parent path was 'added with history'
2612 // then we have to use the copy from revision of the parent path
2613 CTGitPath cpath = CTGitPath(changedlogpath->sPath);
2614 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
2616 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->SafeGetAt(flist)->sPath);
2617 if (p.IsAncestorOf(cpath))
2619 if (!pLogEntry->pArChangedPaths->SafeGetAt(flist)->sCopyFromPath.IsEmpty())
2620 rev2 = pLogEntry->pArChangedPaths->SafeGetAt(flist)->lCopyFromRev;
2625 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
2627 // some items are hidden! So find out which item the user really clicked on
2628 INT_PTR selRealIndex = -1;
2629 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
2631 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2632 selRealIndex++;
2633 if (selRealIndex == nItem)
2635 selIndex = hiddenindex;
2636 changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
2637 break;
2641 if (changedlogpath)
2643 changedpaths.push_back(changedlogpath->sPath);
2644 changedlogpaths.push_back(changedlogpath);
2648 #endif
2649 //entry is selected, now show the popup menu
2650 CIconMenu popup;
2651 if (popup.CreatePopupMenu())
2653 bool bEntryAdded = false;
2654 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
2656 // if ((!bOneRev)||(IsDiffPossible(changedlogpaths[0], rev1)))
2658 popup.AppendMenuIcon(CGitLogList::ID_DIFF, IDS_LOG_POPUP_DIFF, IDI_DIFF);
2659 popup.AppendMenuIcon(CGitLogList::ID_BLAMEDIFF, IDS_LOG_POPUP_BLAMEDIFF, IDI_BLAME);
2660 popup.SetDefaultItem(CGitLogList::ID_DIFF, FALSE);
2661 popup.AppendMenuIcon(CGitLogList::ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
2662 bEntryAdded = true;
2664 // if (rev2 == rev1-1)
2666 if (bEntryAdded)
2667 popup.AppendMenu(MF_SEPARATOR, NULL);
2668 popup.AppendMenuIcon(CGitLogList::ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
2669 popup.AppendMenuIcon(CGitLogList::ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
2670 popup.AppendMenuIcon(CGitLogList::ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
2671 popup.AppendMenu(MF_SEPARATOR, NULL);
2672 if (m_hasWC)
2673 popup.AppendMenuIcon(CGitLogList::ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2674 popup.AppendMenuIcon(CGitLogList::ID_POPPROPS, IDS_REPOBROWSE_SHOWPROP, IDI_PROPERTIES); // "Show Properties"
2675 popup.AppendMenuIcon(CGitLogList::ID_LOG, IDS_MENULOG, IDI_LOG); // "Show Log"
2676 popup.AppendMenuIcon(CGitLogList::ID_GETMERGELOGS, IDS_LOG_POPUP_GETMERGELOGS, IDI_LOG); // "Show merge log"
2677 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
2678 bEntryAdded = true;
2679 if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2681 popup.AppendMenu(MF_SEPARATOR, NULL);
2682 popup.AppendMenuIcon(CGitLogList::ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2684 if (popup.GetDefaultItem(0,FALSE)==-1)
2685 popup.SetDefaultItem(CGitLogList::ID_OPEN, FALSE);
2688 else if (changedlogpaths.size())
2690 // more than one entry is selected
2691 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE);
2692 bEntryAdded = true;
2695 if (!bEntryAdded)
2696 return;
2697 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2698 bool bOpenWith = false;
2699 bool bMergeLog = false;
2700 m_bCancelled = false;
2702 switch (cmd)
2704 case CGitLogList::ID_DIFF:
2706 DoDiffFromLog(selIndex, rev1, rev2, false, false);
2708 break;
2709 #if 0
2710 case ID_BLAMEDIFF:
2712 DoDiffFromLog(selIndex, rev1, rev2, true, false);
2714 break;
2715 case ID_GNUDIFF1:
2717 DoDiffFromLog(selIndex, rev1, rev2, false, true);
2719 break;
2720 case ID_REVERTREV:
2722 SetPromptApp(&theApp);
2723 theApp.DoWaitCursor(1);
2724 CString sUrl;
2725 if (Git::PathIsURL(m_path))
2727 sUrl = m_path.GetGitPathString();
2729 else
2731 sUrl = GetURLFromPath(m_path);
2732 if (sUrl.IsEmpty())
2734 theApp.DoWaitCursor(-1);
2735 CString temp;
2736 temp.Format(IDS_ERR_NOURLOFFILE, m_path.GetWinPath());
2737 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2738 EnableOKButton();
2739 theApp.DoWaitCursor(-1);
2740 break; //exit
2743 // find the working copy path of the selected item from the URL
2744 m_bCancelled = false;
2745 CString sUrlRoot = GetRepositoryRoot(CTGitPath(sUrl));
2747 CString fileURL = changedpaths[0];
2748 fileURL = sUrlRoot + fileURL.Trim();
2749 // firstfile = (e.g.) http://mydomain.com/repos/trunk/folder/file1
2750 // sUrl = http://mydomain.com/repos/trunk/folder
2751 CString sUnescapedUrl = CPathUtils::PathUnescape(sUrl);
2752 // find out until which char the urls are identical
2753 int i=0;
2754 while ((i<fileURL.GetLength())&&(i<sUnescapedUrl.GetLength())&&(fileURL[i]==sUnescapedUrl[i]))
2755 i++;
2756 int leftcount = m_path.GetWinPathString().GetLength()-(sUnescapedUrl.GetLength()-i);
2757 CString wcPath = m_path.GetWinPathString().Left(leftcount);
2758 wcPath += fileURL.Mid(i);
2759 wcPath.Replace('/', '\\');
2760 CGitProgressDlg dlg;
2761 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
2763 // a deleted path! Since the path isn't there anymore, merge
2764 // won't work. So just do a copy url->wc
2765 dlg.SetCommand(CGitProgressDlg::GitProgress_Copy);
2766 dlg.SetPathList(CTGitPathList(CTGitPath(fileURL)));
2767 dlg.SetUrl(wcPath);
2768 dlg.SetRevision(rev2);
2770 else
2772 if (!PathFileExists(wcPath))
2774 // seems the path got renamed
2775 // tell the user how to work around this.
2776 CMessageBox::Show(this->m_hWnd, IDS_LOG_REVERTREV_ERROR, IDS_APPNAME, MB_ICONERROR);
2777 EnableOKButton();
2778 theApp.DoWaitCursor(-1);
2779 break; //exit
2781 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
2782 dlg.SetPathList(CTGitPathList(CTGitPath(wcPath)));
2783 dlg.SetUrl(fileURL);
2784 dlg.SetSecondUrl(fileURL);
2785 GitRevRangeArray revarray;
2786 revarray.AddRevRange(rev1, rev2);
2787 dlg.SetRevisionRanges(revarray);
2789 CString msg;
2790 msg.Format(IDS_LOG_REVERT_CONFIRM, (LPCTSTR)wcPath);
2791 if (CMessageBox::Show(this->m_hWnd, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
2793 dlg.DoModal();
2795 theApp.DoWaitCursor(-1);
2797 break;
2798 case ID_POPPROPS:
2800 DialogEnableWindow(IDOK, FALSE);
2801 SetPromptApp(&theApp);
2802 theApp.DoWaitCursor(1);
2803 CString filepath;
2804 if (Git::PathIsURL(m_path))
2806 filepath = m_path.GetGitPathString();
2808 else
2810 filepath = GetURLFromPath(m_path);
2811 if (filepath.IsEmpty())
2813 theApp.DoWaitCursor(-1);
2814 CString temp;
2815 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2816 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2817 TRACE(_T("could not retrieve the URL of the file!\n"));
2818 EnableOKButton();
2819 break;
2822 filepath = GetRepositoryRoot(CTGitPath(filepath));
2823 filepath += changedpaths[0];
2824 CPropDlg dlg;
2825 dlg.m_rev = rev1;
2826 dlg.m_Path = CTGitPath(filepath);
2827 dlg.DoModal();
2828 EnableOKButton();
2829 theApp.DoWaitCursor(-1);
2831 break;
2832 case ID_SAVEAS:
2834 DialogEnableWindow(IDOK, FALSE);
2835 SetPromptApp(&theApp);
2836 theApp.DoWaitCursor(1);
2837 CString filepath;
2838 if (Git::PathIsURL(m_path))
2840 filepath = m_path.GetGitPathString();
2842 else
2844 filepath = GetURLFromPath(m_path);
2845 if (filepath.IsEmpty())
2847 theApp.DoWaitCursor(-1);
2848 CString temp;
2849 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2850 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2851 TRACE(_T("could not retrieve the URL of the file!\n"));
2852 EnableOKButton();
2853 break;
2856 m_bCancelled = false;
2857 CString sRoot = GetRepositoryRoot(CTGitPath(filepath));
2858 // if more than one entry is selected, we save them
2859 // one by one into a folder the user has selected
2860 bool bTargetSelected = false;
2861 CTGitPath TargetPath;
2862 if (m_ChangedFileListCtrl.GetSelectedCount() > 1)
2864 CBrowseFolder browseFolder;
2865 browseFolder.SetInfo(CString(MAKEINTRESOURCE(IDS_LOG_SAVEFOLDERTOHINT)));
2866 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
2867 CString strSaveAsDirectory;
2868 if (browseFolder.Show(GetSafeHwnd(), strSaveAsDirectory) == CBrowseFolder::OK)
2870 TargetPath = CTGitPath(strSaveAsDirectory);
2871 bTargetSelected = true;
2874 else
2876 // Display the Open dialog box.
2877 CString revFilename;
2878 CString temp;
2879 temp = CPathUtils::GetFileNameFromPath(changedpaths[0]);
2880 int rfind = temp.ReverseFind('.');
2881 if (rfind > 0)
2882 revFilename.Format(_T("%s-%ld%s"), (LPCTSTR)temp.Left(rfind), rev1, (LPCTSTR)temp.Mid(rfind));
2883 else
2884 revFilename.Format(_T("%s-%ld"), (LPCTSTR)temp, rev1);
2885 bTargetSelected = CAppUtils::FileOpenSave(revFilename, NULL, IDS_LOG_POPUP_SAVE, IDS_COMMONFILEFILTER, false, m_hWnd);
2886 TargetPath.SetFromWin(revFilename);
2888 if (bTargetSelected)
2890 CProgressDlg progDlg;
2891 progDlg.SetTitle(IDS_APPNAME);
2892 progDlg.SetAnimation(IDR_DOWNLOAD);
2893 for (std::vector<LogChangedPath*>::iterator it = changedlogpaths.begin(); it!= changedlogpaths.end(); ++it)
2895 GitRev getrev = ((*it)->action == LOGACTIONS_DELETED) ? rev2 : rev1;
2897 CString sInfoLine;
2898 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)getrev.ToString());
2899 progDlg.SetLine(1, sInfoLine, true);
2900 SetAndClearProgressInfo(&progDlg);
2901 progDlg.ShowModeless(m_hWnd);
2903 CTGitPath tempfile = TargetPath;
2904 if (changedpaths.size() > 1)
2906 // if multiple items are selected, then the TargetPath
2907 // points to a folder and we have to append the filename
2908 // to save to to that folder.
2909 CString sName = (*it)->sPath;
2910 int slashpos = sName.ReverseFind('/');
2911 if (slashpos >= 0)
2912 sName = sName.Mid(slashpos);
2913 tempfile.AppendPathString(sName);
2914 // one problem here:
2915 // a user could have selected multiple items which
2916 // have the same filename but reside in different
2917 // directories, e.g.
2918 // /folder1/file1
2919 // /folder2/file1
2920 // in that case, the second 'file1' will overwrite
2921 // the already saved 'file1'.
2923 // we could maybe find the common root of all selected
2924 // items and then create sub folders to save those files
2925 // there.
2926 // But I think we should just leave it that way: to check
2927 // out multiple items at once, the better way is still to
2928 // use the export command from the top pane of the log dialog.
2930 filepath = sRoot + (*it)->sPath;
2931 if (!Cat(CTGitPath(filepath), getrev, getrev, tempfile))
2933 progDlg.Stop();
2934 SetAndClearProgressInfo((HWND)NULL);
2935 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
2936 EnableOKButton();
2937 theApp.DoWaitCursor(-1);
2938 break;
2941 progDlg.Stop();
2942 SetAndClearProgressInfo((HWND)NULL);
2944 EnableOKButton();
2945 theApp.DoWaitCursor(-1);
2947 break;
2948 case ID_OPENWITH:
2949 bOpenWith = true;
2950 case ID_OPEN:
2952 GitRev getrev = pLogEntry->pArChangedPaths->SafeGetAt(selIndex)->action == LOGACTIONS_DELETED ? rev2 : rev1;
2953 Open(bOpenWith,changedpaths[0],getrev);
2955 break;
2956 case ID_BLAME:
2958 CString filepath;
2959 if (Git::PathIsURL(m_path))
2961 filepath = m_path.GetGitPathString();
2963 else
2965 filepath = GetURLFromPath(m_path);
2966 if (filepath.IsEmpty())
2968 theApp.DoWaitCursor(-1);
2969 CString temp;
2970 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2971 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2972 TRACE(_T("could not retrieve the URL of the file!\n"));
2973 EnableOKButton();
2974 break;
2977 filepath = GetRepositoryRoot(CTGitPath(filepath));
2978 filepath += changedpaths[0];
2979 CBlameDlg dlg;
2980 dlg.EndRev = rev1;
2981 if (dlg.DoModal() == IDOK)
2983 CBlame blame;
2984 CString tempfile;
2985 CString logfile;
2986 tempfile = blame.BlameToTempFile(CTGitPath(filepath), dlg.StartRev, dlg.EndRev, dlg.EndRev, logfile, _T(""), dlg.m_bIncludeMerge, TRUE, TRUE);
2987 if (!tempfile.IsEmpty())
2989 if (dlg.m_bTextView)
2991 //open the default text editor for the result file
2992 CAppUtils::StartTextViewer(tempfile);
2994 else
2996 CString sParams = _T("/path:\"") + filepath + _T("\" ");
2997 if(!CAppUtils::LaunchTortoiseBlame(tempfile, logfile, CPathUtils::GetFileNameFromPath(filepath),sParams))
2999 break;
3003 else
3005 CMessageBox::Show(this->m_hWnd, blame.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3009 break;
3010 case ID_GETMERGELOGS:
3011 bMergeLog = true;
3012 // fall through
3013 case ID_LOG:
3015 DialogEnableWindow(IDOK, FALSE);
3016 SetPromptApp(&theApp);
3017 theApp.DoWaitCursor(1);
3018 CString filepath;
3019 if (Git::PathIsURL(m_path))
3021 filepath = m_path.GetGitPathString();
3023 else
3025 filepath = GetURLFromPath(m_path);
3026 if (filepath.IsEmpty())
3028 theApp.DoWaitCursor(-1);
3029 CString temp;
3030 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
3031 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3032 TRACE(_T("could not retrieve the URL of the file!\n"));
3033 EnableOKButton();
3034 break;
3037 m_bCancelled = false;
3038 filepath = GetRepositoryRoot(CTGitPath(filepath));
3039 filepath += changedpaths[0];
3040 git_revnum_t logrev = rev1;
3041 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
3043 // if the item got deleted in this revision,
3044 // fetch the log from the previous revision where it
3045 // still existed.
3046 logrev--;
3048 CString sCmd;
3049 sCmd.Format(_T("\"%s\" /command:log /path:\"%s\" /startrev:%ld"), (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)filepath, logrev);
3050 if (bMergeLog)
3051 sCmd += _T(" /merge");
3052 CAppUtils::LaunchApplication(sCmd, NULL, false);
3053 EnableOKButton();
3054 theApp.DoWaitCursor(-1);
3056 break;
3057 case ID_VIEWPATHREV:
3059 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetSelectionMark()));
3060 GitRev rev = pLogEntry->Rev;
3061 CString relurl = changedpaths[0];
3062 CString url = m_ProjectProperties.sWebViewerPathRev;
3063 url.Replace(_T("%REVISION%"), rev.ToString());
3064 url.Replace(_T("%PATH%"), relurl);
3065 relurl = relurl.Mid(relurl.Find('/'));
3066 url.Replace(_T("%PATH1%"), relurl);
3067 if (!url.IsEmpty())
3068 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
3070 break;
3071 #endif
3072 default:
3073 break;
3074 } // switch (cmd)
3076 } // if (popup.CreatePopupMenu())
3078 #endif
3080 void CLogDlg::OnDtnDropdownDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3082 // the date control should not show the "today" button
3083 CMonthCalCtrl * pCtrl = m_DateFrom.GetMonthCalCtrl();
3084 if (pCtrl)
3085 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3086 *pResult = 0;
3089 void CLogDlg::OnDtnDropdownDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3091 // the date control should not show the "today" button
3092 CMonthCalCtrl * pCtrl = m_DateTo.GetMonthCalCtrl();
3093 if (pCtrl)
3094 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3095 *pResult = 0;
3098 void CLogDlg::OnSize(UINT nType, int cx, int cy)
3100 __super::OnSize(nType, cx, cy);
3101 //set range
3102 SetSplitterRange();
3105 void CLogDlg::OnRefresh()
3107 //if (GetDlgItem(IDC_GETALL)->IsWindowEnabled())
3108 ShowStartRef();
3110 m_limit = 0;
3111 this->m_LogProgress.SetPos(0);
3113 Refresh (false);
3119 void CLogDlg::OnFocusFilter()
3121 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3124 void CLogDlg::OnEditCopy()
3126 if (GetFocus() == &m_ChangedFileListCtrl)
3127 CopyChangedSelectionToClipBoard();
3128 else
3129 m_LogList.CopySelectionToClipBoard();
3132 CString CLogDlg::GetAbsoluteUrlFromRelativeUrl(const CString& url)
3134 // is the URL a relative one?
3135 if (url.Left(2).Compare(_T("^/")) == 0)
3137 // URL is relative to the repository root
3138 CString url1 = m_sRepositoryRoot + url.Mid(1);
3139 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3140 DWORD len = url.GetLength();
3141 if (UrlCanonicalize((LPCTSTR)url1, buf, &len, 0) == S_OK)
3142 return CString(buf, len);
3143 return url1;
3145 else if (url[0] == '/')
3147 // URL is relative to the server's hostname
3148 CString sHost;
3149 // find the server's hostname
3150 int schemepos = m_sRepositoryRoot.Find(_T("//"));
3151 if (schemepos >= 0)
3153 sHost = m_sRepositoryRoot.Left(m_sRepositoryRoot.Find('/', schemepos+3));
3154 CString url1 = sHost + url;
3155 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3156 DWORD len = url.GetLength();
3157 if (UrlCanonicalize((LPCTSTR)url, buf, &len, 0) == S_OK)
3158 return CString(buf, len);
3159 return url1;
3162 return url;
3166 void CLogDlg::OnEnChangeSearchedit()
3168 UpdateData();
3169 if (m_LogList.m_sFilterText.IsEmpty())
3171 CStoreSelection storeselection(this);
3172 // clear the filter, i.e. make all entries appear
3173 theApp.DoWaitCursor(1);
3174 KillTimer(LOGFILTER_TIMER);
3175 FillLogMessageCtrl(false);
3177 Refresh();
3178 //m_LogList.StartFilter();
3179 #if 0
3180 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3181 m_arShownList.RemoveAll();
3182 for (DWORD i=0; i<m_logEntries.size(); ++i)
3184 if (IsEntryInDateRange(i))
3185 m_arShownList.Add(m_logEntries[i]);
3187 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3188 m_LogList.DeleteAllItems();
3189 m_LogList.SetItemCountEx(ShownCountWithStopped());
3190 m_LogList.RedrawItems(0, ShownCountWithStopped());
3191 m_LogList.SetRedraw(false);
3192 ResizeAllListCtrlCols();
3193 m_LogList.SetRedraw(true);
3194 #endif
3195 theApp.DoWaitCursor(-1);
3196 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
3197 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
3198 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3199 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
3200 return;
3202 if (Validate(m_LogList.m_sFilterText))
3203 SetTimer(LOGFILTER_TIMER, 1000, NULL);
3204 else
3205 KillTimer(LOGFILTER_TIMER);
3209 void CLogDlg::OnBnClickedAllBranch()
3211 this->UpdateData();
3213 if(this->m_bAllBranch)
3214 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
3215 else
3216 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
3218 OnRefresh();
3220 FillLogMessageCtrl(false);
3223 void CLogDlg::OnBnClickedBrowseRef()
3225 CString newRef = CBrowseRefsDlg::PickRef(false,m_LogList.GetStartRef());
3226 if(newRef.IsEmpty())
3227 return;
3229 SetStartRef(newRef);
3230 ((CButton*)GetDlgItem(IDC_LOG_ALLBRANCH))->SetCheck(0);
3232 OnBnClickedAllBranch();
3235 void CLogDlg::ShowStartRef()
3237 //Show ref name on top
3238 if(!::IsWindow(m_hWnd))
3239 return;
3240 if(m_bAllBranch)
3242 m_staticRef.SetWindowText(L"<All Branches>");
3243 m_staticRef.Invalidate(TRUE);
3244 return;
3247 CString showStartRef = m_LogList.GetStartRef();
3248 if(showStartRef.IsEmpty())
3250 //Ref name is HEAD
3251 if (g_Git.Run(L"git symbolic-ref HEAD", &showStartRef, NULL, CP_UTF8))
3252 showStartRef = _T("<No branch>");
3253 showStartRef.Trim(L"\r\n\t ");
3257 if(wcsncmp(showStartRef,L"refs/",5) == 0)
3258 showStartRef = showStartRef.Mid(5);
3259 if(wcsncmp(showStartRef,L"heads/",6) == 0)
3260 showStartRef = showStartRef.Mid(6);
3262 m_staticRef.SetWindowText(showStartRef);
3263 m_staticRef.Invalidate(TRUE);
3266 void CLogDlg::SetStartRef(const CString& StartRef)
3268 m_LogList.SetStartRef(StartRef);
3270 if (m_hightlightRevision.IsEmpty())
3272 m_hightlightRevision = g_Git.GetHash(StartRef);
3273 m_LogList.m_lastSelectedHash = m_hightlightRevision;
3276 ShowStartRef();
3280 void CLogDlg::OnBnClickedFirstParent()
3282 this->UpdateData();
3284 if(this->m_bFirstParent)
3285 m_LogList.m_ShowMask|=CGit::LOG_INFO_FIRST_PARENT;
3286 else
3287 m_LogList.m_ShowMask&=~CGit::LOG_INFO_FIRST_PARENT;
3289 OnRefresh();
3291 FillLogMessageCtrl(false);
3295 void CLogDlg::OnBnClickShowWholeProject()
3297 this->UpdateData();
3299 if(this->m_bWholeProject)
3301 m_LogList.m_Path.Reset();
3302 SetDlgTitle();
3304 else
3306 m_LogList.m_Path=m_path;
3309 SetDlgTitle();
3311 OnRefresh();
3313 FillLogMessageCtrl(false);
3317 LRESULT CLogDlg::OnRefLogChanged(WPARAM wParam, LPARAM lParam)
3319 UNREFERENCED_PARAMETER(wParam);
3320 UNREFERENCED_PARAMETER(lParam);
3321 ShowStartRef();
3322 return 0;
3325 LRESULT CLogDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
3327 m_pTaskbarList.Release();
3328 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
3329 return 0;