do not show "Restore after commit" in Changed Files, Rebase or Log Dialog
[TortoiseGit.git] / src / TortoiseProc / LogDlg.cpp
blob5aeb854955a201695a4746e84fe1a8f3cef52fff
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"
52 #include "SmartHandle.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 CAutoLibrary 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);
207 m_pTaskbarList.Release();
208 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
210 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_LOGDLG));
212 // use the state of the "stop on copy/rename" option from the last time
213 UpdateData(FALSE);
215 // set the font to use in the log message view, configured in the settings dialog
216 CAppUtils::CreateFontForLogs(m_logFont);
217 GetDlgItem(IDC_MSGVIEW)->SetFont(&m_logFont);
218 // automatically detect URLs in the log message and turn them into links
219 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_AUTOURLDETECT, TRUE, NULL);
220 // make the log message rich edit control send a message when the mouse pointer is over a link
221 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_SETEVENTMASK, NULL, ENM_LINK);
222 //m_LogList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_SUBITEMIMAGES);
224 // the "hide unrelated paths" checkbox should be indeterminate
225 m_cHidePaths.SetCheck(BST_INDETERMINATE);
228 //SetWindowTheme(m_LogList.GetSafeHwnd(), L"Explorer", NULL);
229 //SetWindowTheme(m_ChangedFileListCtrl.GetSafeHwnd(), L"Explorer", NULL);
231 // set up the columns
232 m_LogList.DeleteAllItems();
234 m_LogList.m_Path=m_path;
235 m_LogList.m_hasWC = m_LogList.m_bShowWC = !g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir);
236 m_LogList.InsertGitColumn();
238 m_ChangedFileListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS |GITSLC_COLADD|GITSLC_COLDEL, _T("LogDlg"), (GITSLC_POPALL ^ (GITSLC_POPCOMMIT|GITSLC_POPIGNORE|GITSLC_POPRESTORE)), false, m_LogList.m_hasWC);
240 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
242 m_logcounter = 0;
243 m_sMessageBuf.Preallocate(100000);
245 SetDlgTitle();
247 m_tooltips.Create(this);
248 CheckRegexpTooltip();
250 SetSplitterRange();
252 // the filter control has a 'cancel' button (the red 'X'), we need to load its bitmap
253 m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);
254 m_cFilter.SetInfoIcon(IDI_LOGFILTER);
255 m_cFilter.SetValidator(this);
257 AdjustControlSize(IDC_HIDEPATHS);
258 AdjustControlSize(IDC_LOG_FIRSTPARENT);
259 AdjustControlSize(IDC_LOG_ALLBRANCH);
261 GetClientRect(m_DlgOrigRect);
262 m_LogList.GetClientRect(m_LogListOrigRect);
263 GetDlgItem(IDC_MSGVIEW)->GetClientRect(m_MsgViewOrigRect);
264 m_ChangedFileListCtrl.GetClientRect(m_ChgOrigRect);
266 m_DateFrom.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
267 m_DateTo.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
269 m_staticRef.SetURL(CString());
271 // resizable stuff
272 AddAnchor(IDC_STATIC_REF, TOP_LEFT);
273 //AddAnchor(IDC_BUTTON_BROWSE_REF, TOP_LEFT);
274 AddAnchor(IDC_FROMLABEL, TOP_LEFT);
275 AddAnchor(IDC_DATEFROM, TOP_LEFT);
276 AddAnchor(IDC_TOLABEL, TOP_LEFT);
277 AddAnchor(IDC_DATETO, TOP_LEFT);
279 SetFilterCueText();
280 AddAnchor(IDC_SEARCHEDIT, TOP_LEFT, TOP_RIGHT);
282 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
283 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
284 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
285 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
286 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
288 AddAnchor(IDC_LOGINFO, BOTTOM_LEFT, BOTTOM_RIGHT);
289 AddAnchor(IDC_HIDEPATHS, BOTTOM_LEFT);
290 AddAnchor(IDC_LOG_ALLBRANCH,BOTTOM_LEFT);
291 AddAnchor(IDC_LOG_FIRSTPARENT, BOTTOM_LEFT);
292 //AddAnchor(IDC_GETALL, BOTTOM_LEFT);
293 AddAnchor(IDC_SHOWWHOLEPROJECT, BOTTOM_LEFT);
294 AddAnchor(IDC_REFRESH, BOTTOM_LEFT);
295 AddAnchor(IDC_STATBUTTON, BOTTOM_RIGHT);
296 AddAnchor(IDC_PROGRESS, BOTTOM_LEFT, BOTTOM_RIGHT);
297 AddAnchor(IDOK, BOTTOM_RIGHT);
298 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
299 AddAnchor(IDHELP, BOTTOM_RIGHT);
301 if(this->m_bAllBranch)
302 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
303 else
304 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
306 // SetPromptParentWindow(m_hWnd);
308 if (hWndExplorer)
309 CenterWindow(CWnd::FromHandle(hWndExplorer));
310 EnableSaveRestore(_T("LogDlg"));
312 DWORD yPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
313 DWORD yPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
314 RECT rcDlg, rcLogList, rcChgMsg;
315 GetClientRect(&rcDlg);
316 m_LogList.GetWindowRect(&rcLogList);
317 ScreenToClient(&rcLogList);
318 m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg);
319 ScreenToClient(&rcChgMsg);
320 if (yPos1)
322 RECT rectSplitter;
323 m_wndSplitter1.GetWindowRect(&rectSplitter);
324 ScreenToClient(&rectSplitter);
325 int delta = yPos1 - rectSplitter.top;
327 if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30))
329 m_wndSplitter1.SetWindowPos(NULL, 0, yPos1, 0, 0, SWP_NOSIZE);
330 DoSizeV1(delta);
333 if (yPos2)
335 RECT rectSplitter;
336 m_wndSplitter2.GetWindowRect(&rectSplitter);
337 ScreenToClient(&rectSplitter);
338 int delta = yPos2 - rectSplitter.top;
340 if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30))
342 m_wndSplitter2.SetWindowPos(NULL, 0, yPos2, 0, 0, SWP_NOSIZE);
343 DoSizeV2(delta);
348 if (m_bSelect)
350 // the dialog is used to select revisions
351 // enable the OK button if appropriate
352 EnableOKButton();
354 else
356 // the dialog is used to just view log messages
357 // hide the OK button and set text on Cancel button to OK
358 GetDlgItemText(IDOK, temp);
359 SetDlgItemText(IDCANCEL, temp);
360 GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
363 m_mergedRevs.clear();
365 // first start a thread to obtain the log messages without
366 // blocking the dialog
367 //m_tTo = 0;
368 //m_tFrom = (DWORD)-1;
370 // scroll to user selected or current revision
371 if (!m_hightlightRevision.IsEmpty() && m_hightlightRevision.GetLength() >= GIT_HASH_SIZE)
372 m_LogList.m_lastSelectedHash = m_hightlightRevision;
373 else if (!m_LogList.m_endrev.IsEmpty() && m_LogList.m_endrev.GetLength() >= GIT_HASH_SIZE)
374 m_LogList.m_lastSelectedHash = m_hightlightRevision;
375 else
376 m_LogList.m_lastSelectedHash = g_Git.GetHash(_T("HEAD"));
378 m_LogList.FetchLogAsync(this);
380 GetDlgItem(IDC_LOGLIST)->SetFocus();
382 ShowStartRef();
383 return FALSE;
386 LRESULT CLogDlg::OnLogListLoading(WPARAM wParam, LPARAM /*lParam*/)
388 int cur=(int)wParam;
390 if( cur == GITLOG_START )
392 CString temp;
393 temp.LoadString(IDS_PROGRESSWAIT);
395 this->m_LogList.ShowText(temp, true);
397 // We use a progress bar while getting the logs
398 m_LogProgress.SetRange32(0, 100);
399 m_LogProgress.SetPos(0);
400 if (m_pTaskbarList)
402 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
403 m_pTaskbarList->SetProgressValue(m_hWnd, 0, 100);
406 GetDlgItem(IDC_PROGRESS)->ShowWindow(TRUE);
408 //DialogEnableWindow(IDC_GETALL, FALSE);
409 //DialogEnableWindow(IDC_SHOWWHOLEPROJECT, FALSE);
410 //DialogEnableWindow(IDC_LOG_FIRSTPARENT, FALSE);
411 DialogEnableWindow(IDC_STATBUTTON, FALSE);
412 //DialogEnableWindow(IDC_REFRESH, FALSE);
413 DialogEnableWindow(IDC_HIDEPATHS,FALSE);
416 else if( cur == GITLOG_END)
418 if(this->m_LogList.HasText())
420 this->m_LogList.ClearText();
422 UpdateLogInfoLabel();
424 if (m_pTaskbarList)
425 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
427 //if (!m_bShowedAll)
428 DialogEnableWindow(IDC_SHOWWHOLEPROJECT, TRUE);
430 //DialogEnableWindow(IDC_GETALL, TRUE);
431 DialogEnableWindow(IDC_STATBUTTON, !(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC));
432 DialogEnableWindow(IDC_REFRESH, TRUE);
433 DialogEnableWindow(IDC_HIDEPATHS,TRUE);
435 // PostMessage(WM_TIMER, LOGFILTER_TIMER);
436 GetDlgItem(IDC_PROGRESS)->ShowWindow(FALSE);
437 //CTime time=m_LogList.GetOldestTime();
438 CTime begin,end;
439 m_LogList.GetTimeRange(begin,end);
441 if(m_LogList.m_From == -1)
442 m_DateFrom.SetTime(&begin);
444 if(m_LogList.m_To == -1)
445 m_DateTo.SetTime(&end);
449 else
451 if(this->m_LogList.HasText())
453 this->m_LogList.ClearText();
454 this->m_LogList.Invalidate();
456 UpdateLogInfoLabel();
457 m_LogProgress.SetPos(cur);
458 if (m_pTaskbarList)
460 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
461 m_pTaskbarList->SetProgressValue(m_hWnd, cur, 100);
464 return 0;
466 void CLogDlg::SetDlgTitle()
468 if (m_sTitle.IsEmpty())
469 GetWindowText(m_sTitle);
471 if (m_LogList.m_Path.IsEmpty() || m_orgPath.GetWinPathString().IsEmpty())
473 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
475 else
476 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);
479 void CLogDlg::CheckRegexpTooltip()
481 CWnd *pWnd = GetDlgItem(IDC_SEARCHEDIT);
482 // Since tooltip describes regexp features, show it only if regexps are enabled.
483 if (m_bFilterWithRegex)
485 m_tooltips.AddTool(pWnd, IDS_LOG_FILTER_REGEX_TT);
487 else
488 m_tooltips.DelTool(pWnd);
491 void CLogDlg::EnableOKButton()
493 if (m_bSelect)
495 // the dialog is used to select revisions
496 if (m_bSelectionMustBeSingle)
498 // enable OK button if only a single revision is selected
499 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()==1));
501 else if (m_bSelectionMustBeContinuous)
502 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));
503 else
504 DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);
506 else
507 DialogEnableWindow(IDOK, TRUE);
510 CString CLogDlg::GetTagInfo(GitRev* pLogEntry)
512 CString cmd;
513 CString output;
515 if(m_LogList.m_HashMap.find(pLogEntry->m_CommitHash) != m_LogList.m_HashMap.end())
517 STRING_VECTOR &vector = m_LogList.m_HashMap[pLogEntry->m_CommitHash];
518 for(int i=0;i<vector.size();i++)
520 if(vector[i].Find(_T("refs/tags/")) == 0 )
522 CString tag= vector[i];
523 int start = vector[i].Find(_T("^{}"));
524 if(start>0)
525 tag=tag.Left(start);
526 else
527 continue;
529 cmd.Format(_T("git.exe cat-file tag %s"), tag);
531 if(g_Git.Run(cmd, &output, NULL, CP_UTF8) == 0 )
532 output+=_T("\n");
537 if(!output.IsEmpty())
539 output = _T("\n*Tag Info*\n\n") + output;
542 return output;
545 void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)
547 // we fill here the log message rich edit control,
548 // and also populate the changed files list control
549 // according to the selected revision(s).
551 CRichEditCtrl * pMsgView = (CRichEditCtrl*)GetDlgItem(IDC_MSGVIEW);
552 // empty the log message view
553 pMsgView->SetWindowText(_T(" "));
554 // empty the changed files list
555 m_ChangedFileListCtrl.SetRedraw(FALSE);
556 // InterlockedExchange(&m_bNoDispUpdates, TRUE);
557 m_currentChangedArray = NULL;
558 //m_ChangedFileListCtrl.SetExtendedStyle ( LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER );
559 m_ChangedFileListCtrl.DeleteAllItems();
561 // if we're not here to really show a selected revision, just
562 // get out of here after clearing the views, which is what is intended
563 // if that flag is not set.
564 if (!bShow)
566 // force a redraw
567 m_ChangedFileListCtrl.Invalidate();
568 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
569 m_ChangedFileListCtrl.SetRedraw(TRUE);
570 return;
573 // depending on how many revisions are selected, we have to do different
574 // tasks.
575 int selCount = m_LogList.GetSelectedCount();
576 if (selCount == 0)
578 // if nothing is selected, we have nothing more to do
579 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
580 m_ChangedFileListCtrl.SetRedraw(TRUE);
581 return;
583 else if (selCount == 1)
585 // if one revision is selected, we have to fill the log message view
586 // with the corresponding log message, and also fill the changed files
587 // list fully.
588 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
589 int selIndex = m_LogList.GetNextSelectedItem(pos);
590 if (selIndex >= m_LogList.m_arShownList.GetCount())
592 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
593 m_ChangedFileListCtrl.SetRedraw(TRUE);
594 return;
596 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
599 // set the log message text
600 pMsgView->SetWindowText(_T("Commit:")+pLogEntry->m_CommitHash.ToString()+_T("\r\n\r\n"));
601 // turn bug ID's into links if the bugtraq: properties have been set
602 // and we can find a match of those in the log message
604 pMsgView->SetSel(-1,-1);
605 CHARFORMAT2 format;
606 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
607 format.cbSize = sizeof(CHARFORMAT2);
608 format.dwMask = CFM_BOLD;
609 format.dwEffects = CFE_BOLD;
610 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
612 CString msg=_T("* ");
613 msg+=pLogEntry->GetSubject();
614 pMsgView->ReplaceSel(msg);
616 pMsgView->SetSel(-1,-1);
617 format.dwEffects = 0;
618 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
620 msg=_T("\n");
621 msg+=pLogEntry->GetBody();
623 if(!pLogEntry->m_Notes.IsEmpty())
625 msg+= _T("\n*Notes* ");
626 msg+= pLogEntry->m_Notes;
627 msg+= _T("\n\n");
630 msg+=GetTagInfo(pLogEntry);
632 pMsgView->ReplaceSel(msg);
634 CString text;
635 pMsgView->GetWindowText(text);
636 // the rich edit control doesn't count the CR char!
637 // to be exact: CRLF is treated as one char.
638 text.Remove('\r');
640 m_LogList.m_ProjectProperties.FindBugID(text, pMsgView);
641 CAppUtils::FormatTextInRichEditControl(pMsgView);
643 int HidePaths=m_cHidePaths.GetState() & 0x0003;
644 CString matchpath=this->m_path.GetGitPathString();
646 int count = pLogEntry->GetFiles(&m_LogList).GetCount();
647 for(int i=0;i<count && (!matchpath.IsEmpty());i++)
649 if( m_bWholeProject )
650 break;
652 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action &= ~(CTGitPath::LOGACTIONS_HIDE|CTGitPath::LOGACTIONS_GRAY);
654 if(pLogEntry->GetFiles(&m_LogList)[i].GetGitPathString().Left(matchpath.GetLength()) != matchpath)
656 if(HidePaths==BST_CHECKED)
657 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;
658 if(HidePaths==BST_INDETERMINATE)
659 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_GRAY;
663 m_ChangedFileListCtrl.UpdateWithGitPathList(pLogEntry->GetFiles(&m_LogList));
664 m_ChangedFileListCtrl.m_CurrentVersion=pLogEntry->m_CommitHash;
665 m_ChangedFileListCtrl.Show(GITSLC_SHOWVERSIONED);
667 m_ChangedFileListCtrl.SetBusyString(_T("Fetch Changed File..."));
669 if(!pLogEntry->m_IsDiffFiles)
670 m_ChangedFileListCtrl.SetBusy(TRUE);
671 else
672 m_ChangedFileListCtrl.SetBusy(FALSE);
674 m_ChangedFileListCtrl.SetRedraw(TRUE);
675 return;
679 else
681 // more than one revision is selected:
682 // the log message view must be emptied
683 // the changed files list contains all the changed paths from all
684 // selected revisions, with 'doubles' removed
685 m_currentChangedPathList = GetChangedPathsFromSelectedRevisions(true);
688 // redraw the views
689 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
690 #if 0
691 if (m_currentChangedArray)
693 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedArray->GetCount());
694 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedArray->GetCount());
696 else if (m_currentChangedPathList.GetCount())
698 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedPathList.GetCount());
699 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedPathList.GetCount());
701 else
703 m_ChangedFileListCtrl.SetItemCountEx(0);
704 m_ChangedFileListCtrl.Invalidate();
706 #endif
707 // sort according to the settings
708 if (m_nSortColumnPathList > 0)
709 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
710 else
711 SetSortArrow(&m_ChangedFileListCtrl, -1, false);
712 m_ChangedFileListCtrl.SetRedraw(TRUE);
716 void CLogDlg::OnBnClickedRefresh()
718 Refresh (true);
721 void CLogDlg::Refresh (bool clearfilter /*autoGoOnline*/)
723 m_limit = 0;
724 m_LogList.Refresh(clearfilter);
725 FillLogMessageCtrl(false);
730 BOOL CLogDlg::Cancel()
732 return m_bCancelled;
735 void CLogDlg::SaveSplitterPos()
737 if (!IsIconic())
739 CRegDWORD regPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
740 CRegDWORD regPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
741 RECT rectSplitter;
742 m_wndSplitter1.GetWindowRect(&rectSplitter);
743 ScreenToClient(&rectSplitter);
744 regPos1 = rectSplitter.top;
745 m_wndSplitter2.GetWindowRect(&rectSplitter);
746 ScreenToClient(&rectSplitter);
747 regPos2 = rectSplitter.top;
751 void CLogDlg::OnCancel()
753 this->ShowWindow(SW_HIDE);
755 // canceling means stopping the working thread if it's still running.
756 m_LogList.SafeTerminateAsyncDiffThread();
757 if (this->IsThreadRunning())
759 m_LogList.SafeTerminateThread();
761 UpdateData();
763 SaveSplitterPos();
764 __super::OnCancel();
767 CString CLogDlg::MakeShortMessage(const CString& message)
769 bool bFoundShort = true;
770 CString sShortMessage = m_LogList.m_ProjectProperties.GetLogSummary(message);
771 if (sShortMessage.IsEmpty())
773 bFoundShort = false;
774 sShortMessage = message;
776 // Remove newlines and tabs 'cause those are not shown nicely in the list control
777 sShortMessage.Remove('\r');
778 sShortMessage.Replace(_T('\t'), _T(' '));
780 // Suppose the first empty line separates 'summary' from the rest of the message.
781 int found = sShortMessage.Find(_T("\n\n"));
782 // To avoid too short 'short' messages
783 // (e.g. if the message looks something like "Bugfix:\n\n*done this\n*done that")
784 // only use the empty newline as a separator if it comes after at least 15 chars.
785 if ((!bFoundShort)&&(found >= 15))
787 sShortMessage = sShortMessage.Left(found);
789 sShortMessage.Replace('\n', ' ');
790 return sShortMessage;
793 BOOL CLogDlg::Log(git_revnum_t /*rev*/, const CString& /*author*/, const CString& /*date*/, const CString& /*message*/, LogChangedPathArray * /*cpaths*/, int /*filechanges*/, BOOL /*copies*/, DWORD /*actions*/, BOOL /*haschildren*/)
795 #if 0
796 if (rev == SVN_INVALID_REVNUM)
798 m_childCounter--;
799 return TRUE;
802 // this is the callback function which receives the data for every revision we ask the log for
803 // we store this information here one by one.
804 m_logcounter += 1;
805 if (m_startrev == -1)
806 m_startrev = rev;
807 if (m_limit != 0)
809 m_limitcounter--;
810 m_LogProgress.SetPos(m_limit - m_limitcounter);
812 else if (m_startrev.IsNumber() && m_startrev.IsNumber())
813 m_LogProgress.SetPos((git_revnum_t)m_startrev-rev+(git_revnum_t)m_endrev);
814 __time64_t ttime = time/1000000L;
815 if (m_tTo < (DWORD)ttime)
816 m_tTo = (DWORD)ttime;
817 if (m_tFrom > (DWORD)ttime)
818 m_tFrom = (DWORD)ttime;
819 if ((m_lowestRev > rev)||(m_lowestRev < 0))
820 m_lowestRev = rev;
821 // Add as many characters from the log message to the list control
822 PLOGENTRYDATA pLogItem = new LOGENTRYDATA;
823 pLogItem->bCopies = !!copies;
825 // find out if this item was copied in the revision
826 BOOL copiedself = FALSE;
827 if (copies)
829 for (INT_PTR cpPathIndex = 0; cpPathIndex < cpaths->GetCount(); ++cpPathIndex)
831 LogChangedPath * cpath = cpaths->SafeGetAt(cpPathIndex);
832 if (!cpath->sCopyFromPath.IsEmpty() && (cpath->sPath.Compare(m_sSelfRelativeURL) == 0))
834 // note: this only works if the log is fetched top-to-bottom
835 // but since we do that, it shouldn't be a problem
836 m_sSelfRelativeURL = cpath->sCopyFromPath;
837 copiedself = TRUE;
838 break;
842 pLogItem->bCopiedSelf = copiedself;
843 pLogItem->tmDate = ttime;
844 pLogItem->sAuthor = author;
845 pLogItem->sDate = date;
846 pLogItem->sShortMessage = MakeShortMessage(message);
847 pLogItem->dwFileChanges = filechanges;
848 pLogItem->actions = actions;
849 pLogItem->haschildren = haschildren;
850 pLogItem->childStackDepth = m_childCounter;
851 m_maxChild = max(m_childCounter, m_maxChild);
852 if (haschildren)
853 m_childCounter++;
854 pLogItem->sBugIDs = m_ProjectProperties.FindBugID(message).Trim();
856 // split multi line log entries and concatenate them
857 // again but this time with \r\n as line separators
858 // so that the edit control recognizes them
861 if (message.GetLength()>0)
863 m_sMessageBuf = message;
864 m_sMessageBuf.Replace(_T("\n\r"), _T("\n"));
865 m_sMessageBuf.Replace(_T("\r\n"), _T("\n"));
866 if (m_sMessageBuf.Right(1).Compare(_T("\n"))==0)
867 m_sMessageBuf = m_sMessageBuf.Left(m_sMessageBuf.GetLength()-1);
869 else
870 m_sMessageBuf.Empty();
871 pLogItem->sMessage = m_sMessageBuf;
872 pLogItem->Rev = rev;
874 // move-construct path array
876 pLogItem->pArChangedPaths = new LogChangedPathArray (*cpaths);
877 cpaths->RemoveAll();
879 catch (CException * e)
881 ::MessageBox(NULL, _T("not enough memory!"), _T("TortoiseGit"), MB_ICONERROR);
882 e->Delete();
883 m_bCancelled = TRUE;
885 m_logEntries.push_back(pLogItem);
886 m_arShownList.Add(pLogItem);
887 #endif
888 return TRUE;
891 GitRev g_rev;
892 //this is the thread function which calls the subversion function
897 void CLogDlg::CopyChangedSelectionToClipBoard()
900 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
901 if (pos == NULL)
902 return; // nothing is selected, get out of here
904 CString sPaths;
906 // CGitRev* pLogEntry = reinterpret_cast<CGitRev* >(m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
907 // if (pos)
909 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
910 while (pos)
912 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
913 CTGitPath *path = (CTGitPath*)m_ChangedFileListCtrl.GetItemData(nItem);
914 if(path)
915 sPaths += path->GetGitPathString();
916 sPaths += _T("\r\n");
919 #if 0
920 else
922 // only one revision is selected in the log dialog top pane
923 // but multiple items could be selected in the changed items list
924 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
925 while (pos)
927 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
928 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(nItem);
930 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
932 // some items are hidden! So find out which item the user really selected
933 INT_PTR selRealIndex = -1;
934 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
936 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
937 selRealIndex++;
938 if (selRealIndex == nItem)
940 changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex);
941 break;
945 if (changedlogpath)
947 sPaths += changedlogpath->sPath;
948 sPaths += _T("\r\n");
952 #endif
953 sPaths.Trim();
954 CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());
958 BOOL CLogDlg::IsDiffPossible(LogChangedPath * /*changedpath*/, git_revnum_t rev)
960 #if 0
961 CString added, deleted;
962 if (changedpath == NULL)
963 return false;
965 if ((rev > 1)&&(changedpath->action != LOGACTIONS_DELETED))
967 if (changedpath->action == LOGACTIONS_ADDED) // file is added
969 if (changedpath->lCopyFromRev == 0)
970 return FALSE; // but file was not added with history
972 return TRUE;
974 #endif
975 return FALSE;
978 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)
980 // we have two separate context menus:
981 // one shown on the log message list control,
982 // the other shown in the changed-files list control
983 int selCount = m_LogList.GetSelectedCount();
984 if (pWnd == &m_LogList)
986 //ShowContextMenuForRevisions(pWnd, point);
988 else if (pWnd == &m_ChangedFileListCtrl)
990 //ShowContextMenuForChangedpaths(pWnd, point);
992 else if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))
994 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
995 int selIndex = -1;
996 if (pos)
997 selIndex = m_LogList.GetNextSelectedItem(pos);
999 GitRev *pRev = ((GitRev*)m_LogList.m_arShownList[selIndex]);
1001 if ((point.x == -1) && (point.y == -1))
1003 CRect rect;
1004 GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);
1005 ClientToScreen(&rect);
1006 point = rect.CenterPoint();
1008 CString sMenuItemText;
1009 CIconMenu popup;
1010 if (popup.CreatePopupMenu())
1012 // add the 'default' entries
1013 sMenuItemText.LoadString(IDS_SCIEDIT_COPY);
1014 popup.AppendMenu(MF_STRING | MF_ENABLED, WM_COPY, sMenuItemText);
1015 sMenuItemText.LoadString(IDS_SCIEDIT_SELECTALL);
1016 popup.AppendMenu(MF_STRING | MF_ENABLED, EM_SETSEL, sMenuItemText);
1017 sMenuItemText.LoadString(IDS_EDIT_NOTES);
1018 popup.AppendMenuIcon( CGitLogList::ID_EDITNOTE, sMenuItemText, IDI_EDIT);
1020 //if (selIndex >= 0)
1022 // popup.AppendMenu(MF_SEPARATOR);
1023 // sMenuItemText.LoadString(IDS_LOG_POPUP_EDITLOG);
1024 // popup.AppendMenu(MF_STRING | MF_ENABLED, CGitLogList::ID_EDITAUTHOR, sMenuItemText);
1027 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1028 switch (cmd)
1030 case 0:
1031 break; // no command selected
1032 case EM_SETSEL:
1033 case WM_COPY:
1034 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);
1035 break;
1036 case CGitLogList::ID_EDITNOTE:
1037 CAppUtils::EditNote(pRev);
1038 this->FillLogMessageCtrl(true);
1039 break;
1045 void CLogDlg::OnOK()
1047 // since the log dialog is also used to select revisions for other
1048 // dialogs, we have to do some work before closing this dialog
1049 if (GetFocus() != GetDlgItem(IDOK))
1050 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter
1052 m_LogList.SafeTerminateAsyncDiffThread();
1053 if (this->IsThreadRunning())
1055 m_LogList.SafeTerminateThread();
1057 UpdateData();
1058 // check that one and only one row is selected
1059 if (m_LogList.GetSelectedCount() == 1)
1061 // get the selected row
1062 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1063 int selIndex = m_LogList.GetNextSelectedItem(pos);
1064 if (selIndex < m_LogList.m_arShownList.GetCount())
1066 // all ok, pick up the revision
1067 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
1068 // extract the hash
1069 m_sSelectedHash = pLogEntry->m_CommitHash;
1072 UpdateData(FALSE);
1073 SaveSplitterPos();
1074 __super::OnOK();
1076 #if 0
1077 if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))
1078 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.
1080 CString temp;
1081 CString buttontext;
1082 GetDlgItemText(IDOK, buttontext);
1083 temp.LoadString(IDS_MSGBOX_CANCEL);
1084 if (temp.Compare(buttontext) != 0)
1085 __super::OnOK(); // only exit if the button text matches, and that will match only if the thread isn't running anymore
1086 m_bCancelled = TRUE;
1087 m_selectedRevs.Clear();
1088 m_selectedRevsOneRange.Clear();
1089 if (m_pNotifyWindow)
1091 int selIndex = m_LogList.GetSelectionMark();
1092 if (selIndex >= 0)
1094 PLOGENTRYDATA pLogEntry = NULL;
1095 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1096 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1097 m_selectedRevs.AddRevision(pLogEntry->Rev);
1098 git_revnum_t lowerRev = pLogEntry->Rev;
1099 git_revnum_t higherRev = lowerRev;
1100 while (pos)
1102 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1103 git_revnum_t rev = pLogEntry->Rev;
1104 m_selectedRevs.AddRevision(pLogEntry->Rev);
1105 if (lowerRev > rev)
1106 lowerRev = rev;
1107 if (higherRev < rev)
1108 higherRev = rev;
1110 if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())
1112 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);
1114 BOOL bSentMessage = FALSE;
1115 if (m_LogList.GetSelectedCount() == 1)
1117 // if only one revision is selected, check if the path/url with which the dialog was started
1118 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.
1119 // if it was copied, use the copy from revision as lowerRev
1120 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))
1122 CString sUrl = m_path.GetGitPathString();
1123 if (!m_path.IsUrl())
1125 sUrl = GetURLFromPath(m_path);
1127 sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());
1128 for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)
1130 LogChangedPath * pData = pLogEntry->pArChangedPaths->SafeGetAt(cp);
1131 if (pData)
1133 if (sUrl.Compare(pData->sPath) == 0)
1135 if (!pData->sCopyFromPath.IsEmpty())
1137 lowerRev = pData->lCopyFromRev;
1138 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);
1139 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);
1140 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1141 bSentMessage = TRUE;
1148 if ( !bSentMessage )
1150 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);
1151 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);
1152 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1153 if (m_selectedRevsOneRange.GetCount())
1154 m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);
1158 UpdateData();
1159 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry"));
1160 reg = m_btnShow.GetCurrentEntry();
1161 SaveSplitterPos();
1162 #endif
1165 void CLogDlg::OnNMDblclkChangedFileList(NMHDR * /*pNMHDR*/, LRESULT *pResult)
1167 // a double click on an entry in the changed-files list has happened
1168 *pResult = 0;
1170 DiffSelectedFile();
1173 void CLogDlg::DiffSelectedFile()
1175 #if 0
1176 if (m_bThreadRunning)
1177 return;
1178 UpdateLogInfoLabel();
1179 INT_PTR selIndex = m_ChangedFileListCtrl.GetSelectionMark();
1180 if (selIndex < 0)
1181 return;
1182 if (m_ChangedFileListCtrl.GetSelectedCount() == 0)
1183 return;
1184 // find out if there's an entry selected in the log list
1185 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1186 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1187 git_revnum_t rev1 = pLogEntry->Rev;
1188 git_revnum_t rev2 = rev1;
1189 if (pos)
1191 while (pos)
1193 // there's at least a second entry selected in the log list: several revisions selected!
1194 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1195 if (pLogEntry)
1197 rev1 = max(rev1,(long)pLogEntry->Rev);
1198 rev2 = min(rev2,(long)pLogEntry->Rev);
1201 rev2--;
1202 // now we have both revisions selected in the log list, so we can do a diff of the selected
1203 // entry in the changed files list with these two revisions.
1204 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1206 else
1208 rev2 = rev1-1;
1209 // nothing or only one revision selected in the log list
1210 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
1212 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
1214 // some items are hidden! So find out which item the user really clicked on
1215 INT_PTR selRealIndex = -1;
1216 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
1218 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1219 selRealIndex++;
1220 if (selRealIndex == selIndex)
1222 selIndex = hiddenindex;
1223 changedpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
1224 break;
1229 if (IsDiffPossible(changedpath, rev1))
1231 // diffs with renamed files are possible
1232 if ((changedpath)&&(!changedpath->sCopyFromPath.IsEmpty()))
1233 rev2 = changedpath->lCopyFromRev;
1234 else
1236 // if the path was modified but the parent path was 'added with history'
1237 // then we have to use the copy from revision of the parent path
1238 CTGitPath cpath = CTGitPath(changedpath->sPath);
1239 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
1241 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->SafeGetAt(flist)->sPath);
1242 if (p.IsAncestorOf(cpath))
1244 if (!pLogEntry->pArChangedPaths->SafeGetAt(flist)->sCopyFromPath.IsEmpty())
1245 rev2 = pLogEntry->pArChangedPaths->SafeGetAt(flist)->lCopyFromRev;
1249 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1251 else
1253 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1254 CTGitPath tempfile2 = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1255 GitRev r = rev1;
1256 // deleted files must be opened from the revision before the deletion
1257 if (changedpath->action == LOGACTIONS_DELETED)
1258 r = rev1-1;
1259 m_bCancelled = false;
1261 CProgressDlg progDlg;
1262 progDlg.SetTitle(IDS_APPNAME);
1263 progDlg.SetAnimation(IDR_DOWNLOAD);
1264 CString sInfoLine;
1265 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)(m_sRepositoryRoot + changedpath->sPath), (LPCTSTR)r.ToString());
1266 progDlg.SetLine(1, sInfoLine, true);
1267 SetAndClearProgressInfo(&progDlg);
1268 progDlg.ShowModeless(m_hWnd);
1270 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), r, r, tempfile))
1272 m_bCancelled = false;
1273 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), GitRev::REV_HEAD, r, tempfile))
1275 progDlg.Stop();
1276 SetAndClearProgressInfo((HWND)NULL);
1277 CMessageBox::Show(m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1278 return;
1281 progDlg.Stop();
1282 SetAndClearProgressInfo((HWND)NULL);
1284 CString sName1, sName2;
1285 sName1.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1);
1286 sName2.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1-1);
1287 CAppUtils::DiffFlags flags;
1288 flags.AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1289 if (changedpath->action == LOGACTIONS_DELETED)
1290 CAppUtils::StartExtDiff(tempfile, tempfile2, sName2, sName1, flags);
1291 else
1292 CAppUtils::StartExtDiff(tempfile2, tempfile, sName2, sName1, flags);
1295 #endif
1299 void CLogDlg::DoDiffFromLog(INT_PTR selIndex, GitRev* rev1, GitRev* rev2, bool /*blame*/, bool /*unified*/)
1301 DialogEnableWindow(IDOK, FALSE);
1302 // SetPromptApp(&theApp);
1303 theApp.DoWaitCursor(1);
1305 CString temppath;
1306 GetTempPath(temppath);
1308 CString file1;
1309 file1.Format(_T("%s%s_%s%s"),
1310 temppath,
1311 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1312 rev1->m_CommitHash.ToString().Left(6),
1313 (*m_currentChangedArray)[selIndex].GetFileExtension());
1315 CString file2;
1316 file2.Format(_T("%s\\%s_%s%s"),
1317 temppath,
1318 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1319 rev2->m_CommitHash.ToString().Left(6),
1320 (*m_currentChangedArray)[selIndex].GetFileExtension());
1322 CString cmd;
1324 g_Git.GetOneFile(rev1->m_CommitHash.ToString(), (CTGitPath &)(*m_currentChangedArray)[selIndex],file1);
1326 g_Git.GetOneFile(rev2->m_CommitHash.ToString(), (CTGitPath &)(*m_currentChangedArray)[selIndex],file2);
1328 CAppUtils::DiffFlags flags;
1329 CAppUtils::StartExtDiff(file1,file2,_T("A"),_T("B"),flags);
1331 #if 0
1332 //get the filename
1333 CString filepath;
1334 if (Git::PathIsURL(m_path))
1336 filepath = m_path.GetGitPathString();
1338 else
1340 filepath = GetURLFromPath(m_path);
1341 if (filepath.IsEmpty())
1343 theApp.DoWaitCursor(-1);
1344 CString temp;
1345 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1346 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1347 TRACE(_T("could not retrieve the URL of the file!\n"));
1348 EnableOKButton();
1349 theApp.DoWaitCursor(-11);
1350 return; //exit
1353 m_bCancelled = FALSE;
1354 filepath = GetRepositoryRoot(CTGitPath(filepath));
1356 CString firstfile, secondfile;
1357 if (m_LogList.GetSelectedCount()==1)
1359 int s = m_LogList.GetSelectionMark();
1360 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(s));
1361 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
1362 firstfile = changedpath->sPath;
1363 secondfile = firstfile;
1364 if ((rev2 == rev1-1)&&(changedpath->lCopyFromRev > 0)) // is it an added file with history?
1366 secondfile = changedpath->sCopyFromPath;
1367 rev2 = changedpath->lCopyFromRev;
1370 else
1372 firstfile = m_currentChangedPathList[selIndex].GetGitPathString();
1373 secondfile = firstfile;
1376 firstfile = filepath + firstfile.Trim();
1377 secondfile = filepath + secondfile.Trim();
1379 GitDiff diff(this, this->m_hWnd, true);
1380 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1381 diff.SetHEADPeg(m_LogRevision);
1382 if (unified)
1384 if (PromptShown())
1385 diff.ShowUnifiedDiff(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1);
1386 else
1387 CAppUtils::StartShowUnifiedDiff(m_hWnd, CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), m_LogRevision);
1389 else
1391 if (diff.ShowCompare(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), false, blame))
1393 if (firstfile.Compare(secondfile)==0)
1395 git_revnum_t baseRev = 0;
1396 diff.DiffProps(CTGitPath(firstfile), rev2, rev1, baseRev);
1401 #endif
1403 theApp.DoWaitCursor(-1);
1404 EnableOKButton();
1407 BOOL CLogDlg::Open(bool /*bOpenWith*/,CString changedpath, git_revnum_t rev)
1409 #if 0
1410 DialogEnableWindow(IDOK, FALSE);
1411 SetPromptApp(&theApp);
1412 theApp.DoWaitCursor(1);
1413 CString filepath;
1414 if (Git::PathIsURL(m_path))
1416 filepath = m_path.GetGitPathString();
1418 else
1420 filepath = GetURLFromPath(m_path);
1421 if (filepath.IsEmpty())
1423 theApp.DoWaitCursor(-1);
1424 CString temp;
1425 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1426 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1427 TRACE(_T("could not retrieve the URL of the file!\n"));
1428 EnableOKButton();
1429 return FALSE;
1432 m_bCancelled = false;
1433 filepath = GetRepositoryRoot(CTGitPath(filepath));
1434 filepath += changedpath;
1436 CProgressDlg progDlg;
1437 progDlg.SetTitle(IDS_APPNAME);
1438 progDlg.SetAnimation(IDR_DOWNLOAD);
1439 CString sInfoLine;
1440 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)GitRev(rev).ToString());
1441 progDlg.SetLine(1, sInfoLine, true);
1442 SetAndClearProgressInfo(&progDlg);
1443 progDlg.ShowModeless(m_hWnd);
1445 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(filepath), rev);
1446 m_bCancelled = false;
1447 if (!Cat(CTGitPath(filepath), GitRev(rev), rev, tempfile))
1449 progDlg.Stop();
1450 SetAndClearProgressInfo((HWND)NULL);
1451 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1452 EnableOKButton();
1453 theApp.DoWaitCursor(-1);
1454 return FALSE;
1456 progDlg.Stop();
1457 SetAndClearProgressInfo((HWND)NULL);
1458 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1459 if (!bOpenWith)
1461 int ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1462 if (ret <= HINSTANCE_ERROR)
1463 bOpenWith = true;
1465 if (bOpenWith)
1467 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1468 cmd += tempfile.GetWinPathString() + _T(" ");
1469 CAppUtils::LaunchApplication(cmd, NULL, false);
1471 EnableOKButton();
1472 theApp.DoWaitCursor(-1);
1473 #endif
1474 return TRUE;
1477 void CLogDlg::EditAuthor(const CLogDataVector& /*logs*/)
1479 #if 0
1480 CString url;
1481 CString name;
1482 if (logs.size() == 0)
1483 return;
1484 DialogEnableWindow(IDOK, FALSE);
1485 SetPromptApp(&theApp);
1486 theApp.DoWaitCursor(1);
1487 if (Git::PathIsURL(m_path))
1488 url = m_path.GetGitPathString();
1489 else
1491 url = GetURLFromPath(m_path);
1493 name = Git_PROP_REVISION_AUTHOR;
1495 CString value = RevPropertyGet(name, CTGitPath(url), logs[0]->Rev);
1496 CString sOldValue = value;
1497 value.Replace(_T("\n"), _T("\r\n"));
1498 CInputDlg dlg(this);
1499 dlg.m_sHintText.LoadString(IDS_LOG_AUTHOR);
1500 dlg.m_sInputText = value;
1501 dlg.m_sTitle.LoadString(IDS_LOG_AUTHOREDITTITLE);
1502 dlg.m_pProjectProperties = &m_ProjectProperties;
1503 dlg.m_bUseLogWidth = false;
1504 if (dlg.DoModal() == IDOK)
1506 dlg.m_sInputText.Remove('\r');
1508 LogCache::CCachedLogInfo* toUpdate = GetLogCache (CTGitPath (m_sRepositoryRoot));
1510 CProgressDlg progDlg;
1511 progDlg.SetTitle(IDS_APPNAME);
1512 progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));
1513 progDlg.SetTime(true);
1514 progDlg.SetShowProgressBar(true);
1515 progDlg.ShowModeless(m_hWnd);
1516 for (DWORD i=0; i<logs.size(); ++i)
1518 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), logs[i]->Rev))
1520 progDlg.Stop();
1521 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1522 break;
1524 else
1527 logs[i]->sAuthor = dlg.m_sInputText;
1528 m_LogList.Invalidate();
1530 // update the log cache
1532 if (toUpdate != NULL)
1534 // log caching is active
1536 LogCache::CCachedLogInfo newInfo;
1537 newInfo.Insert ( logs[i]->Rev
1538 , (const char*) CUnicodeUtils::GetUTF8 (logs[i]->sAuthor)
1539 , ""
1541 , LogCache::CRevisionInfoContainer::HAS_AUTHOR);
1543 toUpdate->Update (newInfo);
1546 progDlg.SetProgress64(i, logs.size());
1548 progDlg.Stop();
1550 theApp.DoWaitCursor(-1);
1551 EnableOKButton();
1552 #endif
1555 void CLogDlg::EditLogMessage(int /*index*/)
1558 #if 0
1559 CString url;
1560 CString name;
1561 DialogEnableWindow(IDOK, FALSE);
1562 SetPromptApp(&theApp);
1563 theApp.DoWaitCursor(1);
1564 if (Git::PathIsURL(m_path))
1565 url = m_path.GetGitPathString();
1566 else
1568 url = GetURLFromPath(m_path);
1570 name = Git_PROP_REVISION_LOG;
1572 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(index));
1573 m_bCancelled = FALSE;
1574 CString value = RevPropertyGet(name, CTGitPath(url), pLogEntry->Rev);
1575 CString sOldValue = value;
1576 value.Replace(_T("\n"), _T("\r\n"));
1577 CInputDlg dlg(this);
1578 dlg.m_sHintText.LoadString(IDS_LOG_MESSAGE);
1579 dlg.m_sInputText = value;
1580 dlg.m_sTitle.LoadString(IDS_LOG_MESSAGEEDITTITLE);
1581 dlg.m_pProjectProperties = &m_ProjectProperties;
1582 dlg.m_bUseLogWidth = true;
1583 if (dlg.DoModal() == IDOK)
1585 dlg.m_sInputText.Remove('\r');
1586 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), pLogEntry->Rev))
1588 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1590 else
1592 pLogEntry->sShortMessage = MakeShortMessage(dlg.m_sInputText);
1593 // split multi line log entries and concatenate them
1594 // again but this time with \r\n as line separators
1595 // so that the edit control recognizes them
1596 if (dlg.m_sInputText.GetLength()>0)
1598 m_sMessageBuf = dlg.m_sInputText;
1599 dlg.m_sInputText.Replace(_T("\n\r"), _T("\n"));
1600 dlg.m_sInputText.Replace(_T("\r\n"), _T("\n"));
1601 if (dlg.m_sInputText.Right(1).Compare(_T("\n"))==0)
1602 dlg.m_sInputText = dlg.m_sInputText.Left(dlg.m_sInputText.GetLength()-1);
1604 else
1605 dlg.m_sInputText.Empty();
1606 pLogEntry->sMessage = dlg.m_sInputText;
1607 pLogEntry->sBugIDs = m_ProjectProperties.FindBugID(dlg.m_sInputText);
1608 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
1609 pMsgView->SetWindowText(_T(" "));
1610 pMsgView->SetWindowText(dlg.m_sInputText);
1611 m_ProjectProperties.FindBugID(dlg.m_sInputText, pMsgView);
1612 m_LogList.Invalidate();
1614 // update the log cache
1615 LogCache::CCachedLogInfo* toUpdate = GetLogCache(CTGitPath (m_sRepositoryRoot));
1616 if (toUpdate != NULL)
1618 // log caching is active
1620 LogCache::CCachedLogInfo newInfo;
1621 newInfo.Insert( pLogEntry->Rev
1622 , ""
1623 , (const char*) CUnicodeUtils::GetUTF8 (pLogEntry->sMessage)
1625 , LogCache::CRevisionInfoContainer::HAS_COMMENT);
1627 toUpdate->Update(newInfo);
1631 theApp.DoWaitCursor(-1);
1632 EnableOKButton();
1633 #endif
1636 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)
1638 // Skip Ctrl-C when copying text out of the log message or search filter
1639 bool bSkipAccelerator = (pMsg->message == WM_KEYDOWN && (pMsg->wParam == 'C' || pMsg->wParam == VK_INSERT) && (GetFocus() == GetDlgItem(IDC_MSGVIEW) || GetFocus() == GetDlgItem(IDC_SEARCHEDIT)) && GetKeyState(VK_CONTROL) & 0x8000);
1640 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
1642 if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1644 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1646 m_LogList.DiffSelectedRevWithPrevious();
1647 return TRUE;
1651 if (m_hAccel && !bSkipAccelerator)
1653 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1654 if (ret)
1655 return TRUE;
1658 if(::IsWindow(m_tooltips.m_hWnd))
1659 m_tooltips.RelayEvent(pMsg);
1660 return __super::PreTranslateMessage(pMsg);
1664 BOOL CLogDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1666 //if (this->IsThreadRunning())
1667 if(m_LogList.m_bNoDispUpdates)
1669 // only show the wait cursor over the list control
1670 if ((pWnd)&&
1671 ((pWnd == GetDlgItem(IDC_LOGLIST))||
1672 (pWnd == GetDlgItem(IDC_MSGVIEW))||
1673 (pWnd == GetDlgItem(IDC_LOGMSG))))
1675 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1676 SetCursor(hCur);
1677 return TRUE;
1680 if ((pWnd) && (pWnd == GetDlgItem(IDC_MSGVIEW)))
1681 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1683 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1684 SetCursor(hCur);
1685 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1688 void CLogDlg::OnBnClickedHelp()
1690 OnHelp();
1693 void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1695 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1696 *pResult = 0;
1697 //if (this->IsThreadRunning())
1698 if(m_LogList.m_bNoDispUpdates)
1699 return;
1700 if (pNMLV->iItem >= 0)
1702 this->m_LogList.m_nSearchIndex = pNMLV->iItem;
1703 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(pNMLV->iItem));
1704 m_LogList.m_lastSelectedHash = pLogEntry->m_CommitHash;
1705 if (pNMLV->iSubItem != 0)
1706 return;
1707 if ((pNMLV->iItem == m_LogList.m_arShownList.GetCount()))
1709 // remove the selected state
1710 if (pNMLV->uChanged & LVIF_STATE)
1712 m_LogList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);
1713 FillLogMessageCtrl();
1714 UpdateData(FALSE);
1715 UpdateLogInfoLabel();
1717 return;
1719 if (pNMLV->uChanged & LVIF_STATE)
1721 FillLogMessageCtrl();
1722 UpdateData(FALSE);
1725 else
1727 m_LogList.m_lastSelectedHash.Empty();
1728 FillLogMessageCtrl();
1729 UpdateData(FALSE);
1731 EnableOKButton();
1732 UpdateLogInfoLabel();
1735 void CLogDlg::OnEnLinkMsgview(NMHDR *pNMHDR, LRESULT *pResult)
1737 ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);
1738 if (pEnLink->msg == WM_LBUTTONUP)
1740 CString url, msg;
1741 GetDlgItemText(IDC_MSGVIEW, msg);
1742 msg.Replace(_T("\r\n"), _T("\n"));
1743 url = msg.Mid(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax-pEnLink->chrg.cpMin);
1744 if (!::PathIsURL(url))
1746 url = m_LogList.m_ProjectProperties.GetBugIDUrl(url);
1747 url = GetAbsoluteUrlFromRelativeUrl(url);
1749 if (!url.IsEmpty())
1750 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
1752 *pResult = 0;
1755 class CDateSorter
1757 public:
1758 class CCommitPointer
1760 public:
1761 CCommitPointer():m_cont(NULL){}
1762 CCommitPointer(const CCommitPointer& P_Right)
1763 : m_cont(NULL)
1765 *this = P_Right;
1768 CCommitPointer& operator = (const CCommitPointer& P_Right)
1770 if(IsPointer())
1772 (*m_cont->m_parDates)[m_place] = P_Right.GetDate();
1773 (*m_cont->m_parFileChanges)[m_place] = P_Right.GetChanges();
1774 (*m_cont->m_parAuthors)[m_place] = P_Right.GetAuthor();
1776 else
1778 m_Date = P_Right.GetDate();
1779 m_Changes = P_Right.GetChanges();
1780 m_csAuthor = P_Right.GetAuthor();
1782 return *this;
1785 void Clone(const CCommitPointer& P_Right)
1787 m_cont = P_Right.m_cont;
1788 m_place = P_Right.m_place;
1789 m_Date = P_Right.m_Date;
1790 m_Changes = P_Right.m_Changes;
1791 m_csAuthor = P_Right.m_csAuthor;
1794 DWORD GetDate() const {return IsPointer() ? (*m_cont->m_parDates)[m_place] : m_Date;}
1795 DWORD GetChanges() const {return IsPointer() ? (*m_cont->m_parFileChanges)[m_place] : m_Changes;}
1796 CString GetAuthor() const {return IsPointer() ? (*m_cont->m_parAuthors)[m_place] : m_csAuthor;}
1798 bool IsPointer() const {return m_cont != NULL;}
1799 //When pointer
1800 CDateSorter* m_cont;
1801 int m_place;
1803 //When element
1804 DWORD m_Date;
1805 DWORD m_Changes;
1806 CString m_csAuthor;
1809 class iterator : public std::iterator<std::random_access_iterator_tag, CCommitPointer>
1811 public:
1812 CCommitPointer m_ptr;
1814 iterator(){}
1815 iterator(const iterator& P_Right){*this = P_Right;}
1816 iterator& operator=(const iterator& P_Right)
1818 m_ptr.Clone(P_Right.m_ptr);
1819 return *this;
1822 CCommitPointer& operator*(){return m_ptr;}
1823 CCommitPointer* operator->(){return &m_ptr;}
1824 const CCommitPointer& operator*()const{return m_ptr;}
1825 const CCommitPointer* operator->()const{return &m_ptr;}
1827 iterator& operator+=(size_t P_iOffset){m_ptr.m_place += P_iOffset;return *this;}
1828 iterator& operator-=(size_t P_iOffset){m_ptr.m_place -= P_iOffset;return *this;}
1829 iterator operator+(size_t P_iOffset)const{iterator it(*this); it += P_iOffset;return it;}
1830 iterator operator-(size_t P_iOffset)const{iterator it(*this); it -= P_iOffset;return it;}
1832 iterator& operator++(){++m_ptr.m_place;return *this;}
1833 iterator& operator--(){--m_ptr.m_place;return *this;}
1834 iterator operator++(int){iterator it(*this);++*this;return it;}
1835 iterator operator--(int){iterator it(*this);--*this;return it;}
1837 size_t operator-(const iterator& P_itRight)const{return m_ptr.m_place - P_itRight->m_place;}
1839 bool operator<(const iterator& P_itRight)const{return m_ptr.m_place < P_itRight->m_place;}
1840 bool operator!=(const iterator& P_itRight)const{return m_ptr.m_place != P_itRight->m_place;}
1841 bool operator==(const iterator& P_itRight)const{return m_ptr.m_place == P_itRight->m_place;}
1842 bool operator>(const iterator& P_itRight)const{return m_ptr.m_place > P_itRight->m_place;}
1844 iterator begin()
1846 iterator it;
1847 it->m_place = 0;
1848 it->m_cont = this;
1849 return it;
1851 iterator end()
1853 iterator it;
1854 it->m_place = m_parDates->GetCount();
1855 it->m_cont = this;
1856 return it;
1859 CDWordArray * m_parDates;
1860 CDWordArray * m_parFileChanges;
1861 CStringArray * m_parAuthors;
1864 class CDateSorterLess
1866 public:
1867 bool operator () (const CDateSorter::CCommitPointer& P_Left, const CDateSorter::CCommitPointer& P_Right) const
1869 return P_Left.GetDate() > P_Right.GetDate(); //Last date first
1876 void CLogDlg::OnBnClickedStatbutton()
1878 if (this->IsThreadRunning())
1879 return;
1880 if (m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC)
1881 return; // nothing or just the working copy changes are shown, so no statistics.
1882 // the statistics dialog expects the log entries to be sorted by date
1883 SortByColumn(3, false);
1884 CThreadSafePtrArray shownlist(NULL);
1885 m_LogList.RecalculateShownList(&shownlist);
1886 // create arrays which are aware of the current filter
1887 CStringArray m_arAuthorsFiltered;
1888 CDWordArray m_arDatesFiltered;
1889 CDWordArray m_arFileChangesFiltered;
1890 for (INT_PTR i=0; i<shownlist.GetCount(); ++i)
1892 GitRev* pLogEntry = reinterpret_cast<GitRev*>(shownlist.SafeGetAt(i));
1894 // do not take working dir changes into statistics
1895 if (pLogEntry->m_CommitHash.IsEmpty()) {
1896 continue;
1899 CString strAuthor = pLogEntry->GetAuthorName();
1900 if ( strAuthor.IsEmpty() )
1902 strAuthor.LoadString(IDS_STATGRAPH_EMPTYAUTHOR);
1904 m_arAuthorsFiltered.Add(strAuthor);
1905 m_arDatesFiltered.Add(pLogEntry->GetCommitterDate().GetTime());
1906 m_arFileChangesFiltered.Add(pLogEntry->GetFiles(&m_LogList).GetCount());
1909 CDateSorter W_Sorter;
1910 W_Sorter.m_parAuthors = &m_arAuthorsFiltered;
1911 W_Sorter.m_parDates = &m_arDatesFiltered;
1912 W_Sorter.m_parFileChanges = &m_arFileChangesFiltered;
1913 std::sort(W_Sorter.begin(), W_Sorter.end(), CDateSorterLess());
1915 CStatGraphDlg dlg;
1916 dlg.m_parAuthors = &m_arAuthorsFiltered;
1917 dlg.m_parDates = &m_arDatesFiltered;
1918 dlg.m_parFileChanges = &m_arFileChangesFiltered;
1919 dlg.m_path = m_orgPath;
1920 dlg.DoModal();
1921 // restore the previous sorting
1922 SortByColumn(m_nSortColumn, m_bAscending);
1923 OnTimer(LOGFILTER_TIMER);
1926 void CLogDlg::DoSizeV1(int delta)
1929 RemoveAnchor(IDC_LOGLIST);
1930 RemoveAnchor(IDC_SPLITTERTOP);
1931 RemoveAnchor(IDC_MSGVIEW);
1932 RemoveAnchor(IDC_SPLITTERBOTTOM);
1933 RemoveAnchor(IDC_LOGMSG);
1934 CSplitterControl::ChangeHeight(&m_LogList, delta, CW_TOPALIGN);
1935 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), -delta, CW_BOTTOMALIGN);
1936 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1937 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1938 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1939 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1940 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1941 ArrangeLayout();
1942 AdjustMinSize();
1943 SetSplitterRange();
1944 m_LogList.Invalidate();
1945 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1949 void CLogDlg::DoSizeV2(int delta)
1952 RemoveAnchor(IDC_LOGLIST);
1953 RemoveAnchor(IDC_SPLITTERTOP);
1954 RemoveAnchor(IDC_MSGVIEW);
1955 RemoveAnchor(IDC_SPLITTERBOTTOM);
1956 RemoveAnchor(IDC_LOGMSG);
1957 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), delta, CW_TOPALIGN);
1958 CSplitterControl::ChangeHeight(&m_ChangedFileListCtrl, -delta, CW_BOTTOMALIGN);
1959 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1960 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1961 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1962 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1963 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1964 ArrangeLayout();
1965 AdjustMinSize();
1966 SetSplitterRange();
1967 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1968 m_ChangedFileListCtrl.Invalidate();
1972 void CLogDlg::AdjustMinSize()
1974 // adjust the minimum size of the dialog to prevent the resizing from
1975 // moving the list control too far down.
1976 CRect rcChgListView;
1977 m_ChangedFileListCtrl.GetClientRect(rcChgListView);
1978 CRect rcLogList;
1979 m_LogList.GetClientRect(rcLogList);
1981 SetMinTrackSize(CSize(m_DlgOrigRect.Width(),
1982 m_DlgOrigRect.Height()-m_ChgOrigRect.Height()-m_LogListOrigRect.Height()-m_MsgViewOrigRect.Height()
1983 +rcChgListView.Height()+rcLogList.Height()+60));
1986 LRESULT CLogDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1988 switch (message) {
1989 case WM_NOTIFY:
1990 if (wParam == IDC_SPLITTERTOP)
1992 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1993 DoSizeV1(pHdr->delta);
1995 else if (wParam == IDC_SPLITTERBOTTOM)
1997 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1998 DoSizeV2(pHdr->delta);
2000 break;
2003 return CResizableDialog::DefWindowProc(message, wParam, lParam);
2006 void CLogDlg::SetSplitterRange()
2008 if ((m_LogList)&&(m_ChangedFileListCtrl))
2010 CRect rcTop;
2011 m_LogList.GetWindowRect(rcTop);
2012 ScreenToClient(rcTop);
2013 CRect rcMiddle;
2014 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(rcMiddle);
2015 ScreenToClient(rcMiddle);
2016 m_wndSplitter1.SetRange(rcTop.top+30, rcMiddle.bottom-20);
2017 CRect rcBottom;
2018 m_ChangedFileListCtrl.GetWindowRect(rcBottom);
2019 ScreenToClient(rcBottom);
2020 m_wndSplitter2.SetRange(rcMiddle.top+30, rcBottom.bottom-20);
2024 LRESULT CLogDlg::OnClickedInfoIcon(WPARAM /*wParam*/, LPARAM lParam)
2026 // FIXME: x64 version would get this function called with unexpected parameters.
2027 if (!lParam)
2028 return 0;
2030 RECT * rect = (LPRECT)lParam;
2031 CPoint point;
2032 CString temp;
2033 point = CPoint(rect->left, rect->bottom);
2034 #define LOGMENUFLAGS(x) (MF_STRING | MF_ENABLED | (m_LogList.m_nSelectedFilter == x ? MF_CHECKED : MF_UNCHECKED))
2035 CMenu popup;
2036 if (popup.CreatePopupMenu())
2038 temp.LoadString(IDS_LOG_FILTER_ALL);
2039 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_ALL), LOGFILTER_ALL, temp);
2041 popup.AppendMenu(MF_SEPARATOR, NULL);
2043 temp.LoadString(IDS_LOG_FILTER_SUBJECT);
2044 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_SUBJECT), LOGFILTER_SUBJECT, temp);
2046 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2047 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_MESSAGES), LOGFILTER_MESSAGES, temp);
2049 temp.LoadString(IDS_LOG_FILTER_PATHS);
2050 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_PATHS), LOGFILTER_PATHS, temp);
2052 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2053 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_AUTHORS), LOGFILTER_AUTHORS, temp);
2055 temp.LoadString(IDS_LOG_FILTER_REVS);
2056 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REVS), LOGFILTER_REVS, temp);
2058 if (m_LogList.m_bShowBugtraqColumn == TRUE) {
2059 temp.LoadString(IDS_LOG_FILTER_BUGIDS);
2060 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_BUGID), LOGFILTER_BUGID, temp);
2063 popup.AppendMenu(MF_SEPARATOR, NULL);
2065 temp.LoadString(IDS_LOG_FILTER_REGEX);
2066 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterWithRegex ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_REGEX, temp);
2068 m_tooltips.Pop();
2069 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2070 if (selection != 0)
2073 if (selection == LOGFILTER_REGEX)
2075 m_bFilterWithRegex = !m_bFilterWithRegex;
2076 CRegDWORD b = CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
2077 b = m_bFilterWithRegex;
2078 m_LogList.m_bFilterWithRegex = m_bFilterWithRegex;
2079 SetFilterCueText();
2080 CheckRegexpTooltip();
2082 else
2084 m_LogList.m_nSelectedFilter = selection;
2085 SetFilterCueText();
2087 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2090 return 0L;
2093 LRESULT CLogDlg::OnClickedCancelFilter(WPARAM /*wParam*/, LPARAM /*lParam*/)
2096 KillTimer(LOGFILTER_TIMER);
2098 m_LogList.m_sFilterText.Empty();
2099 UpdateData(FALSE);
2100 theApp.DoWaitCursor(1);
2101 CStoreSelection storeselection(this);
2102 FillLogMessageCtrl(false);
2104 m_LogList.RemoveFilter();
2106 Refresh();
2108 CTime begin,end;
2109 m_LogList.GetTimeRange(begin,end);
2110 m_DateFrom.SetTime(&begin);
2111 m_DateTo.SetTime(&end);
2113 theApp.DoWaitCursor(-1);
2114 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2115 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2116 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2117 UpdateLogInfoLabel();
2119 return 0L;
2123 void CLogDlg::SetFilterCueText()
2125 CString temp;
2126 switch (m_LogList.m_nSelectedFilter)
2128 case LOGFILTER_ALL:
2129 temp.LoadString(IDS_LOG_FILTER_ALL);
2130 break;
2131 case LOGFILTER_SUBJECT:
2132 temp.LoadString(IDS_LOG_FILTER_SUBJECT);
2133 break;
2134 case LOGFILTER_MESSAGES:
2135 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2136 break;
2137 case LOGFILTER_PATHS:
2138 temp.LoadString(IDS_LOG_FILTER_PATHS);
2139 break;
2140 case LOGFILTER_AUTHORS:
2141 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2142 break;
2143 case LOGFILTER_REVS:
2144 temp.LoadString(IDS_LOG_FILTER_REVS);
2145 break;
2147 // to make the cue banner text appear more to the right of the edit control
2148 temp = _T(" ")+temp;
2149 m_cFilter.SetCueBanner(temp);
2152 bool CLogDlg::Validate(LPCTSTR string)
2154 if (!m_bFilterWithRegex)
2155 return true;
2156 tr1::wregex pat;
2157 return m_LogList.ValidateRegexp(string, pat, false);
2161 void CLogDlg::OnTimer(UINT_PTR nIDEvent)
2163 if (nIDEvent == LOGFTIME_TIMER)
2165 KillTimer(LOGFTIME_TIMER);
2166 m_limit = 0;
2167 m_LogList.Refresh(FALSE);
2168 FillLogMessageCtrl(false);
2171 if (nIDEvent == LOGFILTER_TIMER)
2173 KillTimer(LOGFILTER_TIMER);
2174 m_limit = 0;
2175 m_LogList.Refresh(FALSE);
2176 FillLogMessageCtrl(false);
2178 #if 0
2179 /* we will use git built-in grep to filter log */
2180 if (this->IsThreadRunning())
2182 // thread still running! So just restart the timer.
2183 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2184 return;
2186 CWnd * focusWnd = GetFocus();
2187 bool bSetFocusToFilterControl = ((focusWnd != GetDlgItem(IDC_DATEFROM))&&(focusWnd != GetDlgItem(IDC_DATETO))
2188 && (focusWnd != GetDlgItem(IDC_LOGLIST)));
2189 if (m_LogList.m_sFilterText.IsEmpty())
2191 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2192 // do not return here!
2193 // we also need to run the filter if the filter text is empty:
2194 // 1. to clear an existing filter
2195 // 2. to rebuild the m_arShownList after sorting
2197 theApp.DoWaitCursor(1);
2198 CStoreSelection storeselection(this);
2199 KillTimer(LOGFILTER_TIMER);
2200 FillLogMessageCtrl(false);
2202 // now start filter the log list
2203 m_LogList.StartFilter();
2205 if ( m_LogList.GetItemCount()==1 )
2207 m_LogList.SetSelectionMark(0);
2208 m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
2210 theApp.DoWaitCursor(-1);
2211 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2212 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2213 if (bSetFocusToFilterControl)
2214 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2215 UpdateLogInfoLabel();
2216 #endif
2217 } // if (nIDEvent == LOGFILTER_TIMER)
2218 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC))));
2219 __super::OnTimer(nIDEvent);
2222 void CLogDlg::OnDtnDatetimechangeDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2226 CTime _time;
2227 m_DateTo.GetTime(_time);
2229 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 23, 59, 59);
2230 if (time.GetTime() != m_LogList.m_To)
2232 m_LogList.m_To = (DWORD)time.GetTime();
2233 SetTimer(LOGFTIME_TIMER, 10, NULL);
2236 catch (...)
2238 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2241 *pResult = 0;
2244 void CLogDlg::OnDtnDatetimechangeDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2249 CTime _time;
2250 m_DateFrom.GetTime(_time);
2252 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 0, 0, 0);
2253 if (time.GetTime() != m_LogList.m_From)
2255 m_LogList.m_From = (DWORD)time.GetTime();
2256 SetTimer(LOGFTIME_TIMER, 10, NULL);
2259 catch (...)
2261 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2264 *pResult = 0;
2269 CTGitPathList CLogDlg::GetChangedPathsFromSelectedRevisions(bool /*bRelativePaths*/ /* = false */, bool /*bUseFilter*/ /* = true */)
2271 CTGitPathList pathList;
2272 #if 0
2274 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2276 m_sRepositoryRoot = GetRepositoryRoot(m_path);
2278 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2279 return pathList;
2281 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2282 if (pos != NULL)
2284 while (pos)
2286 int nextpos = m_LogList.GetNextSelectedItem(pos);
2287 if (nextpos >= m_arShownList.GetCount())
2288 continue;
2289 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(nextpos));
2290 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2291 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
2293 LogChangedPath * cpath = cpatharray->SafeGetAt(cpPathIndex);
2294 if (cpath == NULL)
2295 continue;
2296 CTGitPath path;
2297 if (!bRelativePaths)
2298 path.SetFromGit(m_sRepositoryRoot);
2299 path.AppendPathString(cpath->sPath);
2300 if ((!bUseFilter)||
2301 ((m_cHidePaths.GetState() & 0x0003)!=BST_CHECKED)||
2302 (cpath->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0))
2303 pathList.AddPath(path);
2308 pathList.RemoveDuplicates();
2309 #endif
2310 return pathList;
2313 void CLogDlg::SortByColumn(int /*nSortColumn*/, bool /*bAscending*/)
2315 #if 0
2316 switch(nSortColumn)
2318 case 0: // Revision
2320 if(bAscending)
2321 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscRevSort());
2322 else
2323 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescRevSort());
2325 break;
2326 case 1: // action
2328 if(bAscending)
2329 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscActionSort());
2330 else
2331 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescActionSort());
2333 break;
2334 case 2: // Author
2336 if(bAscending)
2337 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscAuthorSort());
2338 else
2339 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescAuthorSort());
2341 break;
2342 case 3: // Date
2344 if(bAscending)
2345 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscDateSort());
2346 else
2347 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescDateSort());
2349 break;
2350 case 4: // Message or bug id
2351 if (m_bShowBugtraqColumn)
2353 if(bAscending)
2354 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscBugIDSort());
2355 else
2356 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescBugIDSort());
2357 break;
2359 // fall through here
2360 case 5: // Message
2362 if(bAscending)
2363 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscMessageSort());
2364 else
2365 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescMessageSort());
2367 break;
2368 default:
2369 ATLASSERT(0);
2370 break;
2372 #endif
2375 void CLogDlg::OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult)
2377 if (this->IsThreadRunning())
2378 return; //no sorting while the arrays are filled
2379 #if 0
2380 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2381 const int nColumn = pNMLV->iSubItem;
2382 m_bAscending = nColumn == m_nSortColumn ? !m_bAscending : TRUE;
2383 m_nSortColumn = nColumn;
2384 SortByColumn(m_nSortColumn, m_bAscending);
2385 SetSortArrow(&m_LogList, m_nSortColumn, !!m_bAscending);
2386 SortShownListArray();
2387 m_LogList.Invalidate();
2388 UpdateLogInfoLabel();
2389 #else
2390 UNREFERENCED_PARAMETER(pNMHDR);
2391 #endif
2392 *pResult = 0;
2395 void CLogDlg::SortShownListArray()
2397 // make sure the shown list still matches the filter after sorting.
2398 OnTimer(LOGFILTER_TIMER);
2399 // clear the selection states
2400 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2401 while (pos)
2403 m_LogList.SetItemState(m_LogList.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
2405 m_LogList.SetSelectionMark(-1);
2408 void CLogDlg::SetSortArrow(CListCtrl * control, int nColumn, bool bAscending)
2410 if (control == NULL)
2411 return;
2412 // set the sort arrow
2413 CHeaderCtrl * pHeader = control->GetHeaderCtrl();
2414 HDITEM HeaderItem = {0};
2415 HeaderItem.mask = HDI_FORMAT;
2416 for (int i=0; i<pHeader->GetItemCount(); ++i)
2418 pHeader->GetItem(i, &HeaderItem);
2419 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
2420 pHeader->SetItem(i, &HeaderItem);
2422 if (nColumn >= 0)
2424 pHeader->GetItem(nColumn, &HeaderItem);
2425 HeaderItem.fmt |= (bAscending ? HDF_SORTUP : HDF_SORTDOWN);
2426 pHeader->SetItem(nColumn, &HeaderItem);
2429 void CLogDlg::OnLvnColumnclickChangedFileList(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
2431 #if 0
2432 if (this->IsThreadRunning())
2433 return; //no sorting while the arrays are filled
2434 if (m_currentChangedArray == NULL)
2435 return;
2436 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2437 const int nColumn = pNMLV->iSubItem;
2438 m_bAscendingPathList = nColumn == m_nSortColumnPathList ? !m_bAscendingPathList : TRUE;
2439 m_nSortColumnPathList = nColumn;
2440 // qsort(m_currentChangedArray->GetData(), m_currentChangedArray->GetSize(), sizeof(LogChangedPath*), (GENERICCOMPAREFN)SortCompare);
2442 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
2443 m_ChangedFileListCtrl.Invalidate();
2444 *pResult = 0;
2445 #endif
2448 int CLogDlg::m_nSortColumnPathList = 0;
2449 bool CLogDlg::m_bAscendingPathList = false;
2451 int CLogDlg::SortCompare(const void * /*pElem1*/, const void * /*pElem2*/)
2453 #if 0
2454 LogChangedPath * cpath1 = *((LogChangedPath**)pElem1);
2455 LogChangedPath * cpath2 = *((LogChangedPath**)pElem2);
2457 if (m_bAscendingPathList)
2458 std::swap (cpath1, cpath2);
2460 int cmp = 0;
2461 switch (m_nSortColumnPathList)
2463 case 0: // action
2464 cmp = cpath2->GetAction().Compare(cpath1->GetAction());
2465 if (cmp)
2466 return cmp;
2467 // fall through
2468 case 1: // path
2469 cmp = cpath2->sPath.CompareNoCase(cpath1->sPath);
2470 if (cmp)
2471 return cmp;
2472 // fall through
2473 case 2: // copy from path
2474 cmp = cpath2->sCopyFromPath.Compare(cpath1->sCopyFromPath);
2475 if (cmp)
2476 return cmp;
2477 // fall through
2478 case 3: // copy from revision
2479 return cpath2->lCopyFromRev > cpath1->lCopyFromRev;
2481 #endif
2482 return 0;
2485 void CLogDlg::OnBnClickedHidepaths()
2487 FillLogMessageCtrl();
2488 m_ChangedFileListCtrl.Invalidate();
2493 void CLogDlg::OnBnClickedCheckStoponcopy()
2495 #if 0
2496 if (!GetDlgItem(IDC_GETALL)->IsWindowEnabled())
2497 return;
2499 // ignore old fetch limits when switching
2500 // between copy-following and stop-on-copy
2501 // (otherwise stop-on-copy will limit what
2502 // we see immediately after switching to
2503 // copy-following)
2505 m_endrev = 0;
2507 // now, restart the query
2508 #endif
2509 Refresh();
2513 void CLogDlg::UpdateLogInfoLabel()
2516 CGitHash rev1 ;
2517 CGitHash rev2 ;
2518 long selectedrevs = 0;
2519 int count =m_LogList.m_arShownList.GetCount();
2520 int start = 0;
2521 if (count)
2523 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(0)))->m_CommitHash;
2524 if(this->m_LogList.m_bShowWC && rev1.IsEmpty()&&(count>1))
2525 start = 1;
2526 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(start)))->m_CommitHash;
2527 //pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_arShownList.GetCount()-1));
2528 rev2 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(count-1)))->m_CommitHash;
2529 selectedrevs = m_LogList.GetSelectedCount();
2531 CString sTemp;
2532 sTemp.Format(_T("Showing %ld revision(s), from revision %s to revision %s - %ld revision(s) selected\r\n"),
2533 count - start,
2534 rev2.ToString().Left(6), rev1.ToString().Left(6), selectedrevs);
2536 if(selectedrevs == 1)
2538 CString str=m_ChangedFileListCtrl.GetStatisticsString(true);
2539 str.Replace(_T('\n'), _T(' '));
2540 sTemp += str;
2542 m_sLogInfo = sTemp;
2544 UpdateData(FALSE);
2547 #if 0
2548 void CLogDlg::ShowContextMenuForChangedpaths(CWnd* /*pWnd*/, CPoint point)
2551 int selIndex = m_ChangedFileListCtrl.GetSelectionMark();
2552 if ((point.x == -1) && (point.y == -1))
2554 CRect rect;
2555 m_ChangedFileListCtrl.GetItemRect(selIndex, &rect, LVIR_LABEL);
2556 m_ChangedFileListCtrl.ClientToScreen(&rect);
2557 point = rect.CenterPoint();
2559 if (selIndex < 0)
2560 return;
2561 int s = m_LogList.GetSelectionMark();
2562 if (s < 0)
2563 return;
2564 std::vector<CString> changedpaths;
2565 std::vector<LogChangedPath*> changedlogpaths;
2566 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2567 if (pos == NULL)
2568 return; // nothing is selected, get out of here
2570 bool bOneRev = true;
2571 int sel=m_LogList.GetNextSelectedItem(pos);
2572 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(sel));
2573 GitRev * rev1 = pLogEntry;
2574 GitRev * rev2 = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(sel+1));
2575 #if 0
2576 bool bOneRev = true;
2577 if (pos)
2579 while (pos)
2581 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2582 if (pLogEntry)
2584 rev1 = max(rev1,(git_revnum_t)pLogEntry->Rev);
2585 rev2 = min(rev2,(git_revnum_t)pLogEntry->Rev);
2586 bOneRev = false;
2589 if (!bOneRev)
2590 rev2--;
2591 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
2592 while (pos)
2594 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
2595 changedpaths.push_back(m_currentChangedPathList[nItem].GetGitPathString());
2598 else
2600 // only one revision is selected in the log dialog top pane
2601 // but multiple items could be selected in the changed items list
2602 rev2 = rev1-1;
2604 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
2605 while (pos)
2607 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
2608 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(nItem);
2610 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
2612 if ((changedlogpath)&&(!changedlogpath->sCopyFromPath.IsEmpty()))
2613 rev2 = changedlogpath->lCopyFromRev;
2614 else
2616 // if the path was modified but the parent path was 'added with history'
2617 // then we have to use the copy from revision of the parent path
2618 CTGitPath cpath = CTGitPath(changedlogpath->sPath);
2619 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
2621 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->SafeGetAt(flist)->sPath);
2622 if (p.IsAncestorOf(cpath))
2624 if (!pLogEntry->pArChangedPaths->SafeGetAt(flist)->sCopyFromPath.IsEmpty())
2625 rev2 = pLogEntry->pArChangedPaths->SafeGetAt(flist)->lCopyFromRev;
2630 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
2632 // some items are hidden! So find out which item the user really clicked on
2633 INT_PTR selRealIndex = -1;
2634 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
2636 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2637 selRealIndex++;
2638 if (selRealIndex == nItem)
2640 selIndex = hiddenindex;
2641 changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
2642 break;
2646 if (changedlogpath)
2648 changedpaths.push_back(changedlogpath->sPath);
2649 changedlogpaths.push_back(changedlogpath);
2653 #endif
2654 //entry is selected, now show the popup menu
2655 CIconMenu popup;
2656 if (popup.CreatePopupMenu())
2658 bool bEntryAdded = false;
2659 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
2661 // if ((!bOneRev)||(IsDiffPossible(changedlogpaths[0], rev1)))
2663 popup.AppendMenuIcon(CGitLogList::ID_DIFF, IDS_LOG_POPUP_DIFF, IDI_DIFF);
2664 popup.AppendMenuIcon(CGitLogList::ID_BLAMEDIFF, IDS_LOG_POPUP_BLAMEDIFF, IDI_BLAME);
2665 popup.SetDefaultItem(CGitLogList::ID_DIFF, FALSE);
2666 popup.AppendMenuIcon(CGitLogList::ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
2667 bEntryAdded = true;
2669 // if (rev2 == rev1-1)
2671 if (bEntryAdded)
2672 popup.AppendMenu(MF_SEPARATOR, NULL);
2673 popup.AppendMenuIcon(CGitLogList::ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
2674 popup.AppendMenuIcon(CGitLogList::ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
2675 popup.AppendMenuIcon(CGitLogList::ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
2676 popup.AppendMenu(MF_SEPARATOR, NULL);
2677 if (m_hasWC)
2678 popup.AppendMenuIcon(CGitLogList::ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2679 popup.AppendMenuIcon(CGitLogList::ID_POPPROPS, IDS_REPOBROWSE_SHOWPROP, IDI_PROPERTIES); // "Show Properties"
2680 popup.AppendMenuIcon(CGitLogList::ID_LOG, IDS_MENULOG, IDI_LOG); // "Show Log"
2681 popup.AppendMenuIcon(CGitLogList::ID_GETMERGELOGS, IDS_LOG_POPUP_GETMERGELOGS, IDI_LOG); // "Show merge log"
2682 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
2683 bEntryAdded = true;
2684 if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2686 popup.AppendMenu(MF_SEPARATOR, NULL);
2687 popup.AppendMenuIcon(CGitLogList::ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2689 if (popup.GetDefaultItem(0,FALSE)==-1)
2690 popup.SetDefaultItem(CGitLogList::ID_OPEN, FALSE);
2693 else if (changedlogpaths.size())
2695 // more than one entry is selected
2696 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE);
2697 bEntryAdded = true;
2700 if (!bEntryAdded)
2701 return;
2702 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2703 bool bOpenWith = false;
2704 bool bMergeLog = false;
2705 m_bCancelled = false;
2707 switch (cmd)
2709 case CGitLogList::ID_DIFF:
2711 DoDiffFromLog(selIndex, rev1, rev2, false, false);
2713 break;
2714 #if 0
2715 case ID_BLAMEDIFF:
2717 DoDiffFromLog(selIndex, rev1, rev2, true, false);
2719 break;
2720 case ID_GNUDIFF1:
2722 DoDiffFromLog(selIndex, rev1, rev2, false, true);
2724 break;
2725 case ID_REVERTREV:
2727 SetPromptApp(&theApp);
2728 theApp.DoWaitCursor(1);
2729 CString sUrl;
2730 if (Git::PathIsURL(m_path))
2732 sUrl = m_path.GetGitPathString();
2734 else
2736 sUrl = GetURLFromPath(m_path);
2737 if (sUrl.IsEmpty())
2739 theApp.DoWaitCursor(-1);
2740 CString temp;
2741 temp.Format(IDS_ERR_NOURLOFFILE, m_path.GetWinPath());
2742 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2743 EnableOKButton();
2744 theApp.DoWaitCursor(-1);
2745 break; //exit
2748 // find the working copy path of the selected item from the URL
2749 m_bCancelled = false;
2750 CString sUrlRoot = GetRepositoryRoot(CTGitPath(sUrl));
2752 CString fileURL = changedpaths[0];
2753 fileURL = sUrlRoot + fileURL.Trim();
2754 // firstfile = (e.g.) http://mydomain.com/repos/trunk/folder/file1
2755 // sUrl = http://mydomain.com/repos/trunk/folder
2756 CString sUnescapedUrl = CPathUtils::PathUnescape(sUrl);
2757 // find out until which char the urls are identical
2758 int i=0;
2759 while ((i<fileURL.GetLength())&&(i<sUnescapedUrl.GetLength())&&(fileURL[i]==sUnescapedUrl[i]))
2760 i++;
2761 int leftcount = m_path.GetWinPathString().GetLength()-(sUnescapedUrl.GetLength()-i);
2762 CString wcPath = m_path.GetWinPathString().Left(leftcount);
2763 wcPath += fileURL.Mid(i);
2764 wcPath.Replace('/', '\\');
2765 CGitProgressDlg dlg;
2766 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
2768 // a deleted path! Since the path isn't there anymore, merge
2769 // won't work. So just do a copy url->wc
2770 dlg.SetCommand(CGitProgressDlg::GitProgress_Copy);
2771 dlg.SetPathList(CTGitPathList(CTGitPath(fileURL)));
2772 dlg.SetUrl(wcPath);
2773 dlg.SetRevision(rev2);
2775 else
2777 if (!PathFileExists(wcPath))
2779 // seems the path got renamed
2780 // tell the user how to work around this.
2781 CMessageBox::Show(this->m_hWnd, IDS_LOG_REVERTREV_ERROR, IDS_APPNAME, MB_ICONERROR);
2782 EnableOKButton();
2783 theApp.DoWaitCursor(-1);
2784 break; //exit
2786 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
2787 dlg.SetPathList(CTGitPathList(CTGitPath(wcPath)));
2788 dlg.SetUrl(fileURL);
2789 dlg.SetSecondUrl(fileURL);
2790 GitRevRangeArray revarray;
2791 revarray.AddRevRange(rev1, rev2);
2792 dlg.SetRevisionRanges(revarray);
2794 CString msg;
2795 msg.Format(IDS_LOG_REVERT_CONFIRM, (LPCTSTR)wcPath);
2796 if (CMessageBox::Show(this->m_hWnd, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
2798 dlg.DoModal();
2800 theApp.DoWaitCursor(-1);
2802 break;
2803 case ID_POPPROPS:
2805 DialogEnableWindow(IDOK, FALSE);
2806 SetPromptApp(&theApp);
2807 theApp.DoWaitCursor(1);
2808 CString filepath;
2809 if (Git::PathIsURL(m_path))
2811 filepath = m_path.GetGitPathString();
2813 else
2815 filepath = GetURLFromPath(m_path);
2816 if (filepath.IsEmpty())
2818 theApp.DoWaitCursor(-1);
2819 CString temp;
2820 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2821 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2822 TRACE(_T("could not retrieve the URL of the file!\n"));
2823 EnableOKButton();
2824 break;
2827 filepath = GetRepositoryRoot(CTGitPath(filepath));
2828 filepath += changedpaths[0];
2829 CPropDlg dlg;
2830 dlg.m_rev = rev1;
2831 dlg.m_Path = CTGitPath(filepath);
2832 dlg.DoModal();
2833 EnableOKButton();
2834 theApp.DoWaitCursor(-1);
2836 break;
2837 case ID_SAVEAS:
2839 DialogEnableWindow(IDOK, FALSE);
2840 SetPromptApp(&theApp);
2841 theApp.DoWaitCursor(1);
2842 CString filepath;
2843 if (Git::PathIsURL(m_path))
2845 filepath = m_path.GetGitPathString();
2847 else
2849 filepath = GetURLFromPath(m_path);
2850 if (filepath.IsEmpty())
2852 theApp.DoWaitCursor(-1);
2853 CString temp;
2854 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2855 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2856 TRACE(_T("could not retrieve the URL of the file!\n"));
2857 EnableOKButton();
2858 break;
2861 m_bCancelled = false;
2862 CString sRoot = GetRepositoryRoot(CTGitPath(filepath));
2863 // if more than one entry is selected, we save them
2864 // one by one into a folder the user has selected
2865 bool bTargetSelected = false;
2866 CTGitPath TargetPath;
2867 if (m_ChangedFileListCtrl.GetSelectedCount() > 1)
2869 CBrowseFolder browseFolder;
2870 browseFolder.SetInfo(CString(MAKEINTRESOURCE(IDS_LOG_SAVEFOLDERTOHINT)));
2871 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
2872 CString strSaveAsDirectory;
2873 if (browseFolder.Show(GetSafeHwnd(), strSaveAsDirectory) == CBrowseFolder::OK)
2875 TargetPath = CTGitPath(strSaveAsDirectory);
2876 bTargetSelected = true;
2879 else
2881 // Display the Open dialog box.
2882 CString revFilename;
2883 CString temp;
2884 temp = CPathUtils::GetFileNameFromPath(changedpaths[0]);
2885 int rfind = temp.ReverseFind('.');
2886 if (rfind > 0)
2887 revFilename.Format(_T("%s-%ld%s"), (LPCTSTR)temp.Left(rfind), rev1, (LPCTSTR)temp.Mid(rfind));
2888 else
2889 revFilename.Format(_T("%s-%ld"), (LPCTSTR)temp, rev1);
2890 bTargetSelected = CAppUtils::FileOpenSave(revFilename, NULL, IDS_LOG_POPUP_SAVE, IDS_COMMONFILEFILTER, false, m_hWnd);
2891 TargetPath.SetFromWin(revFilename);
2893 if (bTargetSelected)
2895 CProgressDlg progDlg;
2896 progDlg.SetTitle(IDS_APPNAME);
2897 progDlg.SetAnimation(IDR_DOWNLOAD);
2898 for (std::vector<LogChangedPath*>::iterator it = changedlogpaths.begin(); it!= changedlogpaths.end(); ++it)
2900 GitRev getrev = ((*it)->action == LOGACTIONS_DELETED) ? rev2 : rev1;
2902 CString sInfoLine;
2903 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)getrev.ToString());
2904 progDlg.SetLine(1, sInfoLine, true);
2905 SetAndClearProgressInfo(&progDlg);
2906 progDlg.ShowModeless(m_hWnd);
2908 CTGitPath tempfile = TargetPath;
2909 if (changedpaths.size() > 1)
2911 // if multiple items are selected, then the TargetPath
2912 // points to a folder and we have to append the filename
2913 // to save to to that folder.
2914 CString sName = (*it)->sPath;
2915 int slashpos = sName.ReverseFind('/');
2916 if (slashpos >= 0)
2917 sName = sName.Mid(slashpos);
2918 tempfile.AppendPathString(sName);
2919 // one problem here:
2920 // a user could have selected multiple items which
2921 // have the same filename but reside in different
2922 // directories, e.g.
2923 // /folder1/file1
2924 // /folder2/file1
2925 // in that case, the second 'file1' will overwrite
2926 // the already saved 'file1'.
2928 // we could maybe find the common root of all selected
2929 // items and then create sub folders to save those files
2930 // there.
2931 // But I think we should just leave it that way: to check
2932 // out multiple items at once, the better way is still to
2933 // use the export command from the top pane of the log dialog.
2935 filepath = sRoot + (*it)->sPath;
2936 if (!Cat(CTGitPath(filepath), getrev, getrev, tempfile))
2938 progDlg.Stop();
2939 SetAndClearProgressInfo((HWND)NULL);
2940 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
2941 EnableOKButton();
2942 theApp.DoWaitCursor(-1);
2943 break;
2946 progDlg.Stop();
2947 SetAndClearProgressInfo((HWND)NULL);
2949 EnableOKButton();
2950 theApp.DoWaitCursor(-1);
2952 break;
2953 case ID_OPENWITH:
2954 bOpenWith = true;
2955 case ID_OPEN:
2957 GitRev getrev = pLogEntry->pArChangedPaths->SafeGetAt(selIndex)->action == LOGACTIONS_DELETED ? rev2 : rev1;
2958 Open(bOpenWith,changedpaths[0],getrev);
2960 break;
2961 case ID_BLAME:
2963 CString filepath;
2964 if (Git::PathIsURL(m_path))
2966 filepath = m_path.GetGitPathString();
2968 else
2970 filepath = GetURLFromPath(m_path);
2971 if (filepath.IsEmpty())
2973 theApp.DoWaitCursor(-1);
2974 CString temp;
2975 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2976 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2977 TRACE(_T("could not retrieve the URL of the file!\n"));
2978 EnableOKButton();
2979 break;
2982 filepath = GetRepositoryRoot(CTGitPath(filepath));
2983 filepath += changedpaths[0];
2984 CBlameDlg dlg;
2985 dlg.EndRev = rev1;
2986 if (dlg.DoModal() == IDOK)
2988 CBlame blame;
2989 CString tempfile;
2990 CString logfile;
2991 tempfile = blame.BlameToTempFile(CTGitPath(filepath), dlg.StartRev, dlg.EndRev, dlg.EndRev, logfile, _T(""), dlg.m_bIncludeMerge, TRUE, TRUE);
2992 if (!tempfile.IsEmpty())
2994 if (dlg.m_bTextView)
2996 //open the default text editor for the result file
2997 CAppUtils::StartTextViewer(tempfile);
2999 else
3001 CString sParams = _T("/path:\"") + filepath + _T("\" ");
3002 if(!CAppUtils::LaunchTortoiseBlame(tempfile, logfile, CPathUtils::GetFileNameFromPath(filepath),sParams))
3004 break;
3008 else
3010 CMessageBox::Show(this->m_hWnd, blame.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3014 break;
3015 case ID_GETMERGELOGS:
3016 bMergeLog = true;
3017 // fall through
3018 case ID_LOG:
3020 DialogEnableWindow(IDOK, FALSE);
3021 SetPromptApp(&theApp);
3022 theApp.DoWaitCursor(1);
3023 CString filepath;
3024 if (Git::PathIsURL(m_path))
3026 filepath = m_path.GetGitPathString();
3028 else
3030 filepath = GetURLFromPath(m_path);
3031 if (filepath.IsEmpty())
3033 theApp.DoWaitCursor(-1);
3034 CString temp;
3035 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
3036 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3037 TRACE(_T("could not retrieve the URL of the file!\n"));
3038 EnableOKButton();
3039 break;
3042 m_bCancelled = false;
3043 filepath = GetRepositoryRoot(CTGitPath(filepath));
3044 filepath += changedpaths[0];
3045 git_revnum_t logrev = rev1;
3046 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
3048 // if the item got deleted in this revision,
3049 // fetch the log from the previous revision where it
3050 // still existed.
3051 logrev--;
3053 CString sCmd;
3054 sCmd.Format(_T("\"%s\" /command:log /path:\"%s\" /startrev:%ld"), (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)filepath, logrev);
3055 if (bMergeLog)
3056 sCmd += _T(" /merge");
3057 CAppUtils::LaunchApplication(sCmd, NULL, false);
3058 EnableOKButton();
3059 theApp.DoWaitCursor(-1);
3061 break;
3062 case ID_VIEWPATHREV:
3064 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetSelectionMark()));
3065 GitRev rev = pLogEntry->Rev;
3066 CString relurl = changedpaths[0];
3067 CString url = m_ProjectProperties.sWebViewerPathRev;
3068 url.Replace(_T("%REVISION%"), rev.ToString());
3069 url.Replace(_T("%PATH%"), relurl);
3070 relurl = relurl.Mid(relurl.Find('/'));
3071 url.Replace(_T("%PATH1%"), relurl);
3072 if (!url.IsEmpty())
3073 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
3075 break;
3076 #endif
3077 default:
3078 break;
3079 } // switch (cmd)
3081 } // if (popup.CreatePopupMenu())
3083 #endif
3085 void CLogDlg::OnDtnDropdownDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3087 // the date control should not show the "today" button
3088 CMonthCalCtrl * pCtrl = m_DateFrom.GetMonthCalCtrl();
3089 if (pCtrl)
3090 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3091 *pResult = 0;
3094 void CLogDlg::OnDtnDropdownDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3096 // the date control should not show the "today" button
3097 CMonthCalCtrl * pCtrl = m_DateTo.GetMonthCalCtrl();
3098 if (pCtrl)
3099 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3100 *pResult = 0;
3103 void CLogDlg::OnSize(UINT nType, int cx, int cy)
3105 __super::OnSize(nType, cx, cy);
3106 //set range
3107 SetSplitterRange();
3110 void CLogDlg::OnRefresh()
3112 //if (GetDlgItem(IDC_GETALL)->IsWindowEnabled())
3113 ShowStartRef();
3115 m_limit = 0;
3116 this->m_LogProgress.SetPos(0);
3118 Refresh (false);
3124 void CLogDlg::OnFocusFilter()
3126 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3129 void CLogDlg::OnEditCopy()
3131 if (GetFocus() == &m_ChangedFileListCtrl)
3132 CopyChangedSelectionToClipBoard();
3133 else
3134 m_LogList.CopySelectionToClipBoard();
3137 CString CLogDlg::GetAbsoluteUrlFromRelativeUrl(const CString& url)
3139 // is the URL a relative one?
3140 if (url.Left(2).Compare(_T("^/")) == 0)
3142 // URL is relative to the repository root
3143 CString url1 = m_sRepositoryRoot + url.Mid(1);
3144 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3145 DWORD len = url.GetLength();
3146 if (UrlCanonicalize((LPCTSTR)url1, buf, &len, 0) == S_OK)
3147 return CString(buf, len);
3148 return url1;
3150 else if (url[0] == '/')
3152 // URL is relative to the server's hostname
3153 CString sHost;
3154 // find the server's hostname
3155 int schemepos = m_sRepositoryRoot.Find(_T("//"));
3156 if (schemepos >= 0)
3158 sHost = m_sRepositoryRoot.Left(m_sRepositoryRoot.Find('/', schemepos+3));
3159 CString url1 = sHost + url;
3160 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3161 DWORD len = url.GetLength();
3162 if (UrlCanonicalize((LPCTSTR)url, buf, &len, 0) == S_OK)
3163 return CString(buf, len);
3164 return url1;
3167 return url;
3171 void CLogDlg::OnEnChangeSearchedit()
3173 UpdateData();
3174 if (m_LogList.m_sFilterText.IsEmpty())
3176 CStoreSelection storeselection(this);
3177 // clear the filter, i.e. make all entries appear
3178 theApp.DoWaitCursor(1);
3179 KillTimer(LOGFILTER_TIMER);
3180 FillLogMessageCtrl(false);
3182 Refresh();
3183 //m_LogList.StartFilter();
3184 #if 0
3185 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3186 m_arShownList.RemoveAll();
3187 for (DWORD i=0; i<m_logEntries.size(); ++i)
3189 if (IsEntryInDateRange(i))
3190 m_arShownList.Add(m_logEntries[i]);
3192 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3193 m_LogList.DeleteAllItems();
3194 m_LogList.SetItemCountEx(ShownCountWithStopped());
3195 m_LogList.RedrawItems(0, ShownCountWithStopped());
3196 m_LogList.SetRedraw(false);
3197 ResizeAllListCtrlCols();
3198 m_LogList.SetRedraw(true);
3199 #endif
3200 theApp.DoWaitCursor(-1);
3201 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
3202 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
3203 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3204 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
3205 return;
3207 if (Validate(m_LogList.m_sFilterText))
3208 SetTimer(LOGFILTER_TIMER, 1000, NULL);
3209 else
3210 KillTimer(LOGFILTER_TIMER);
3214 void CLogDlg::OnBnClickedAllBranch()
3216 this->UpdateData();
3218 if(this->m_bAllBranch)
3219 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
3220 else
3221 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
3223 OnRefresh();
3225 FillLogMessageCtrl(false);
3228 void CLogDlg::OnBnClickedBrowseRef()
3230 CString newRef = CBrowseRefsDlg::PickRef(false,m_LogList.GetStartRef());
3231 if(newRef.IsEmpty())
3232 return;
3234 SetStartRef(newRef);
3235 ((CButton*)GetDlgItem(IDC_LOG_ALLBRANCH))->SetCheck(0);
3237 OnBnClickedAllBranch();
3240 void CLogDlg::ShowStartRef()
3242 //Show ref name on top
3243 if(!::IsWindow(m_hWnd))
3244 return;
3245 if(m_bAllBranch)
3247 m_staticRef.SetWindowText(L"<All Branches>");
3248 m_staticRef.Invalidate(TRUE);
3249 return;
3252 CString showStartRef = m_LogList.GetStartRef();
3253 if(showStartRef.IsEmpty())
3255 //Ref name is HEAD
3256 if (g_Git.Run(L"git symbolic-ref HEAD", &showStartRef, NULL, CP_UTF8))
3257 showStartRef = _T("<No branch>");
3258 showStartRef.Trim(L"\r\n\t ");
3262 if(wcsncmp(showStartRef,L"refs/",5) == 0)
3263 showStartRef = showStartRef.Mid(5);
3264 if(wcsncmp(showStartRef,L"heads/",6) == 0)
3265 showStartRef = showStartRef.Mid(6);
3267 m_staticRef.SetWindowText(showStartRef);
3268 m_staticRef.Invalidate(TRUE);
3271 void CLogDlg::SetStartRef(const CString& StartRef)
3273 m_LogList.SetStartRef(StartRef);
3275 if (m_hightlightRevision.IsEmpty())
3277 m_hightlightRevision = g_Git.GetHash(StartRef);
3278 m_LogList.m_lastSelectedHash = m_hightlightRevision;
3281 ShowStartRef();
3285 void CLogDlg::OnBnClickedFirstParent()
3287 this->UpdateData();
3289 if(this->m_bFirstParent)
3290 m_LogList.m_ShowMask|=CGit::LOG_INFO_FIRST_PARENT;
3291 else
3292 m_LogList.m_ShowMask&=~CGit::LOG_INFO_FIRST_PARENT;
3294 OnRefresh();
3296 FillLogMessageCtrl(false);
3300 void CLogDlg::OnBnClickShowWholeProject()
3302 this->UpdateData();
3304 if(this->m_bWholeProject)
3306 m_LogList.m_Path.Reset();
3307 SetDlgTitle();
3309 else
3311 m_LogList.m_Path=m_path;
3314 SetDlgTitle();
3316 OnRefresh();
3318 FillLogMessageCtrl(false);
3322 LRESULT CLogDlg::OnRefLogChanged(WPARAM wParam, LPARAM lParam)
3324 UNREFERENCED_PARAMETER(wParam);
3325 UNREFERENCED_PARAMETER(lParam);
3326 ShowStartRef();
3327 return 0;
3330 LRESULT CLogDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
3332 m_pTaskbarList.Release();
3333 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
3334 return 0;