Refactored IgnoreFile method
[TortoiseGit.git] / src / TortoiseProc / LogDlg.cpp
blob818e71b4fa787b76d45ae2c85da79a3e6f356bb2
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2012 - 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_bFollowRenames(FALSE)
63 , m_bSelect(false)
65 , m_bSelectionMustBeContinuous(false)
66 , m_lowestRev(_T(""))
68 , m_sLogInfo(_T(""))
70 , m_bCancelled(FALSE)
71 , m_pNotifyWindow(NULL)
73 , m_bAscending(FALSE)
75 , m_limit(0)
76 , m_childCounter(0)
77 , m_maxChild(0)
78 , m_bIncludeMerges(FALSE)
79 , m_hAccel(NULL)
81 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
83 CString str;
84 str=g_Git.m_CurrentDir;
85 str.Replace(_T(":"),_T("_"));
86 str=CString(_T("Software\\TortoiseGit\\LogDialog\\AllBranch\\"))+str;
88 m_regbAllBranch=CRegDWORD(str,FALSE);
90 m_bAllBranch=m_regbAllBranch;
92 m_bFirstParent=FALSE;
93 m_bWholeProject=FALSE;
96 CLogDlg::~CLogDlg()
99 m_regbAllBranch=m_bAllBranch;
101 m_CurrentFilteredChangedArray.RemoveAll();
105 void CLogDlg::DoDataExchange(CDataExchange* pDX)
107 CResizableStandAloneDialog::DoDataExchange(pDX);
108 DDX_Control(pDX, IDC_LOGLIST, m_LogList);
109 DDX_Control(pDX, IDC_LOGMSG, m_ChangedFileListCtrl);
110 DDX_Control(pDX, IDC_PROGRESS, m_LogProgress);
111 DDX_Control(pDX, IDC_SPLITTERTOP, m_wndSplitter1);
112 DDX_Control(pDX, IDC_SPLITTERBOTTOM, m_wndSplitter2);
113 DDX_Text(pDX, IDC_SEARCHEDIT, m_LogList.m_sFilterText);
114 DDX_Control(pDX, IDC_DATEFROM, m_DateFrom);
115 DDX_Control(pDX, IDC_DATETO, m_DateTo);
116 DDX_Control(pDX, IDC_HIDEPATHS, m_cHidePaths);
117 DDX_Text(pDX, IDC_LOGINFO, m_sLogInfo);
118 DDX_Check(pDX, IDC_LOG_FIRSTPARENT, m_bFirstParent);
119 DDX_Check(pDX, IDC_LOG_ALLBRANCH,m_bAllBranch);
120 DDX_Check(pDX, IDC_LOG_FOLLOWRENAMES, m_bFollowRenames);
121 DDX_Check(pDX, IDC_SHOWWHOLEPROJECT,m_bWholeProject);
122 DDX_Control(pDX, IDC_SEARCHEDIT, m_cFilter);
123 DDX_Control(pDX, IDC_STATIC_REF, m_staticRef);
126 BEGIN_MESSAGE_MAP(CLogDlg, CResizableStandAloneDialog)
127 //ON_BN_CLICKED(IDC_GETALL, OnBnClickedGetall)
128 //ON_NOTIFY(NM_DBLCLK, IDC_LOGMSG, OnNMDblclkChangedFileList)
129 ON_WM_CONTEXTMENU()
130 ON_WM_SETCURSOR()
131 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
132 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOGLIST, OnLvnItemchangedLoglist)
133 ON_NOTIFY(EN_LINK, IDC_MSGVIEW, OnEnLinkMsgview)
134 ON_BN_CLICKED(IDC_STATBUTTON, OnBnClickedStatbutton)
137 ON_MESSAGE(WM_FILTEREDIT_INFOCLICKED, OnClickedInfoIcon)
138 ON_MESSAGE(WM_FILTEREDIT_CANCELCLICKED, OnClickedCancelFilter)
140 ON_MESSAGE(MSG_LOAD_PERCENTAGE,OnLogListLoading)
142 ON_EN_CHANGE(IDC_SEARCHEDIT, OnEnChangeSearchedit)
143 ON_WM_TIMER()
144 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETO, OnDtnDatetimechangeDateto)
145 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATEFROM, OnDtnDatetimechangeDatefrom)
146 ON_BN_CLICKED(IDC_SHOWWHOLEPROJECT, OnBnClickShowWholeProject)
147 //ON_NOTIFY(NM_CUSTOMDRAW, IDC_LOGMSG, OnNMCustomdrawChangedFileList)
148 //ON_NOTIFY(LVN_GETDISPINFO, IDC_LOGMSG, OnLvnGetdispinfoChangedFileList)
149 ON_NOTIFY(LVN_COLUMNCLICK,IDC_LOGLIST, OnLvnColumnclick)
150 //ON_NOTIFY(LVN_COLUMNCLICK, IDC_LOGMSG, OnLvnColumnclickChangedFileList)
151 ON_BN_CLICKED(IDC_HIDEPATHS, OnBnClickedHidepaths)
152 ON_COMMAND(MSG_FETCHED_DIFF, OnBnClickedHidepaths)
153 ON_BN_CLICKED(IDC_LOG_ALLBRANCH, OnBnClickedAllBranch)
154 ON_BN_CLICKED(IDC_LOG_FOLLOWRENAMES, OnBnClickedFollowRenames)
156 ON_NOTIFY(DTN_DROPDOWN, IDC_DATEFROM, &CLogDlg::OnDtnDropdownDatefrom)
157 ON_NOTIFY(DTN_DROPDOWN, IDC_DATETO, &CLogDlg::OnDtnDropdownDateto)
158 ON_WM_SIZE()
159 ON_BN_CLICKED(IDC_LOG_FIRSTPARENT, &CLogDlg::OnBnClickedFirstParent)
160 ON_BN_CLICKED(IDC_REFRESH, &CLogDlg::OnBnClickedRefresh)
161 // ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CLogDlg::OnBnClickedBrowseRef)
162 ON_STN_CLICKED(IDC_STATIC_REF, &CLogDlg::OnBnClickedBrowseRef)
163 ON_COMMAND(ID_LOGDLG_REFRESH, &CLogDlg::OnBnClickedRefresh)
164 ON_COMMAND(ID_LOGDLG_FIND, &CLogDlg::OnFind)
165 ON_COMMAND(ID_LOGDLG_FOCUSFILTER, &CLogDlg::OnFocusFilter)
166 ON_COMMAND(ID_EDIT_COPY, &CLogDlg::OnEditCopy)
167 ON_MESSAGE(MSG_REFLOG_CHANGED, OnRefLogChanged)
168 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
169 END_MESSAGE_MAP()
171 void CLogDlg::SetParams(const CTGitPath& orgPath, const CTGitPath& path, CString hightlightRevision, CString startrev, CString endrev, int limit /* = FALSE */)
173 m_orgPath = orgPath;
174 m_path = path;
175 m_hightlightRevision = hightlightRevision;
177 if (startrev == GIT_REV_ZERO)
178 startrev.Empty();
179 if (endrev == GIT_REV_ZERO)
180 endrev.Empty();
182 this->m_LogList.m_startrev = startrev;
183 m_LogRevision = startrev;
184 this->m_LogList.m_endrev = endrev;
186 if(!endrev.IsEmpty())
187 this->SetStartRef(endrev);
189 m_hasWC = !path.IsUrl();
190 m_limit = limit;
191 if (::IsWindow(m_hWnd))
192 UpdateData(FALSE);
195 void CLogDlg::SetFilter(const CString& findstr, LONG findtype, bool findregex)
197 m_LogList.m_sFilterText = findstr;
198 if (findtype)
199 m_LogList.m_SelectedFilters = findtype;
200 m_LogList.m_bFilterWithRegex = m_bFilterWithRegex = findregex;
203 BOOL CLogDlg::OnInitDialog()
205 CString temp;
206 CResizableStandAloneDialog::OnInitDialog();
207 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
209 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
210 // do this, Explorer would be unable to send that message to our window if we
211 // were running elevated. It's OK to make the call all the time, since if we're
212 // not elevated, this is a no-op.
213 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
214 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
215 CAutoLibrary hUser = ::LoadLibrary(_T("user32.dll"));
216 if (hUser)
218 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
219 if (pfnChangeWindowMessageFilterEx)
221 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
224 m_pTaskbarList.Release();
225 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
227 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_LOGDLG));
229 // use the state of the "stop on copy/rename" option from the last time
230 UpdateData(FALSE);
232 // set the font to use in the log message view, configured in the settings dialog
233 CAppUtils::CreateFontForLogs(m_logFont);
234 GetDlgItem(IDC_MSGVIEW)->SetFont(&m_logFont);
235 // automatically detect URLs in the log message and turn them into links
236 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_AUTOURLDETECT, TRUE, NULL);
237 // make the log message rich edit control send a message when the mouse pointer is over a link
238 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_SETEVENTMASK, NULL, ENM_LINK);
239 //m_LogList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_SUBITEMIMAGES);
241 // the "hide unrelated paths" checkbox should be indeterminate
242 m_cHidePaths.SetCheck(BST_INDETERMINATE);
245 //SetWindowTheme(m_LogList.GetSafeHwnd(), L"Explorer", NULL);
246 //SetWindowTheme(m_ChangedFileListCtrl.GetSafeHwnd(), L"Explorer", NULL);
248 // set up the columns
249 m_LogList.DeleteAllItems();
251 m_LogList.m_Path=m_path;
252 m_LogList.m_hasWC = m_LogList.m_bShowWC = !g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir);
253 m_LogList.InsertGitColumn();
255 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);
257 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
259 m_logcounter = 0;
260 m_sMessageBuf.Preallocate(100000);
262 SetDlgTitle();
264 m_tooltips.Create(this);
265 CheckRegexpTooltip();
267 SetSplitterRange();
269 // the filter control has a 'cancel' button (the red 'X'), we need to load its bitmap
270 m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);
271 m_cFilter.SetInfoIcon(IDI_LOGFILTER);
272 m_cFilter.SetValidator(this);
274 AdjustControlSize(IDC_HIDEPATHS);
275 AdjustControlSize(IDC_LOG_FIRSTPARENT);
276 AdjustControlSize(IDC_LOG_ALLBRANCH);
277 AdjustControlSize(IDC_SHOWWHOLEPROJECT);
278 AdjustControlSize(IDC_LOG_FOLLOWRENAMES);
280 GetClientRect(m_DlgOrigRect);
281 m_LogList.GetClientRect(m_LogListOrigRect);
282 GetDlgItem(IDC_MSGVIEW)->GetClientRect(m_MsgViewOrigRect);
283 m_ChangedFileListCtrl.GetClientRect(m_ChgOrigRect);
285 m_DateFrom.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
286 m_DateTo.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
288 m_staticRef.SetURL(CString());
290 // resizable stuff
291 AddAnchor(IDC_STATIC_REF, TOP_LEFT);
292 //AddAnchor(IDC_BUTTON_BROWSE_REF, TOP_LEFT);
293 AddAnchor(IDC_FROMLABEL, TOP_LEFT);
294 AddAnchor(IDC_DATEFROM, TOP_LEFT);
295 AddAnchor(IDC_TOLABEL, TOP_LEFT);
296 AddAnchor(IDC_DATETO, TOP_LEFT);
298 SetFilterCueText();
299 AddAnchor(IDC_SEARCHEDIT, TOP_LEFT, TOP_RIGHT);
301 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
302 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
303 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
304 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
305 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
307 AddAnchor(IDC_LOGINFO, BOTTOM_LEFT, BOTTOM_RIGHT);
308 AddAnchor(IDC_HIDEPATHS, BOTTOM_LEFT);
309 AddAnchor(IDC_LOG_ALLBRANCH,BOTTOM_LEFT);
310 AddAnchor(IDC_LOG_FOLLOWRENAMES, BOTTOM_LEFT);
311 AddAnchor(IDC_LOG_FIRSTPARENT, BOTTOM_LEFT);
312 //AddAnchor(IDC_GETALL, BOTTOM_LEFT);
313 AddAnchor(IDC_SHOWWHOLEPROJECT, BOTTOM_LEFT);
314 AddAnchor(IDC_REFRESH, BOTTOM_LEFT);
315 AddAnchor(IDC_STATBUTTON, BOTTOM_RIGHT);
316 AddAnchor(IDC_PROGRESS, BOTTOM_LEFT, BOTTOM_RIGHT);
317 AddAnchor(IDOK, BOTTOM_RIGHT);
318 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
319 AddAnchor(IDHELP, BOTTOM_RIGHT);
321 if(this->m_bAllBranch)
322 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
323 else
324 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
326 // SetPromptParentWindow(m_hWnd);
328 if (hWndExplorer)
329 CenterWindow(CWnd::FromHandle(hWndExplorer));
330 EnableSaveRestore(_T("LogDlg"));
332 DWORD yPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
333 DWORD yPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
334 RECT rcDlg, rcLogList, rcChgMsg;
335 GetClientRect(&rcDlg);
336 m_LogList.GetWindowRect(&rcLogList);
337 ScreenToClient(&rcLogList);
338 m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg);
339 ScreenToClient(&rcChgMsg);
340 if (yPos1)
342 RECT rectSplitter;
343 m_wndSplitter1.GetWindowRect(&rectSplitter);
344 ScreenToClient(&rectSplitter);
345 int delta = yPos1 - rectSplitter.top;
347 if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30))
349 m_wndSplitter1.SetWindowPos(NULL, 0, yPos1, 0, 0, SWP_NOSIZE);
350 DoSizeV1(delta);
353 if (yPos2)
355 RECT rectSplitter;
356 m_wndSplitter2.GetWindowRect(&rectSplitter);
357 ScreenToClient(&rectSplitter);
358 int delta = yPos2 - rectSplitter.top;
360 if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30))
362 m_wndSplitter2.SetWindowPos(NULL, 0, yPos2, 0, 0, SWP_NOSIZE);
363 DoSizeV2(delta);
368 if (m_bSelect)
370 // the dialog is used to select revisions
371 // enable the OK button if appropriate
372 EnableOKButton();
374 else
376 // the dialog is used to just view log messages
377 // hide the OK button and set text on Cancel button to OK
378 GetDlgItemText(IDOK, temp);
379 SetDlgItemText(IDCANCEL, temp);
380 GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
383 m_mergedRevs.clear();
385 // first start a thread to obtain the log messages without
386 // blocking the dialog
387 //m_tTo = 0;
388 //m_tFrom = (DWORD)-1;
390 // scroll to user selected or current revision
391 if (!m_hightlightRevision.IsEmpty() && m_hightlightRevision.GetLength() >= GIT_HASH_SIZE)
392 m_LogList.m_lastSelectedHash = m_hightlightRevision;
393 else if (!m_LogList.m_endrev.IsEmpty() && m_LogList.m_endrev.GetLength() >= GIT_HASH_SIZE)
394 m_LogList.m_lastSelectedHash = m_hightlightRevision;
395 else
396 m_LogList.m_lastSelectedHash = g_Git.GetHash(_T("HEAD"));
398 if (m_path.IsEmpty() || m_path.IsDirectory())
399 DialogEnableWindow(IDC_LOG_FOLLOWRENAMES, FALSE);
401 m_LogList.FetchLogAsync(this);
403 GetDlgItem(IDC_LOGLIST)->SetFocus();
405 ShowStartRef();
406 return FALSE;
409 LRESULT CLogDlg::OnLogListLoading(WPARAM wParam, LPARAM /*lParam*/)
411 int cur=(int)wParam;
413 if( cur == GITLOG_START )
415 CString temp;
416 temp.LoadString(IDS_PROGRESSWAIT);
418 this->m_LogList.ShowText(temp, true);
420 // We use a progress bar while getting the logs
421 m_LogProgress.SetRange32(0, 100);
422 m_LogProgress.SetPos(0);
423 if (m_pTaskbarList)
425 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
426 m_pTaskbarList->SetProgressValue(m_hWnd, 0, 100);
429 GetDlgItem(IDC_PROGRESS)->ShowWindow(TRUE);
431 //DialogEnableWindow(IDC_GETALL, FALSE);
432 //DialogEnableWindow(IDC_SHOWWHOLEPROJECT, FALSE);
433 //DialogEnableWindow(IDC_LOG_FIRSTPARENT, FALSE);
434 DialogEnableWindow(IDC_STATBUTTON, FALSE);
435 //DialogEnableWindow(IDC_REFRESH, FALSE);
436 DialogEnableWindow(IDC_HIDEPATHS,FALSE);
439 else if( cur == GITLOG_END)
441 if(this->m_LogList.HasText())
443 this->m_LogList.ClearText();
445 UpdateLogInfoLabel();
447 if (m_pTaskbarList)
448 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
450 DialogEnableWindow(IDC_SHOWWHOLEPROJECT, !m_bFollowRenames);
452 //DialogEnableWindow(IDC_GETALL, TRUE);
453 DialogEnableWindow(IDC_STATBUTTON, !(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC));
454 DialogEnableWindow(IDC_REFRESH, TRUE);
455 DialogEnableWindow(IDC_HIDEPATHS,TRUE);
457 // PostMessage(WM_TIMER, LOGFILTER_TIMER);
458 GetDlgItem(IDC_PROGRESS)->ShowWindow(FALSE);
459 //CTime time=m_LogList.GetOldestTime();
460 CTime begin,end;
461 m_LogList.GetTimeRange(begin,end);
463 if(m_LogList.m_From == -1)
464 m_DateFrom.SetTime(&begin);
466 if(m_LogList.m_To == -1)
467 m_DateTo.SetTime(&end);
471 else
473 if(this->m_LogList.HasText())
475 this->m_LogList.ClearText();
476 this->m_LogList.Invalidate();
478 UpdateLogInfoLabel();
479 m_LogProgress.SetPos(cur);
480 if (m_pTaskbarList)
482 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
483 m_pTaskbarList->SetProgressValue(m_hWnd, cur, 100);
486 return 0;
488 void CLogDlg::SetDlgTitle()
490 if (m_sTitle.IsEmpty())
491 GetWindowText(m_sTitle);
493 if (m_LogList.m_Path.IsEmpty() || m_orgPath.GetWinPathString().IsEmpty())
495 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
497 else
498 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);
501 void CLogDlg::CheckRegexpTooltip()
503 CWnd *pWnd = GetDlgItem(IDC_SEARCHEDIT);
504 // Since tooltip describes regexp features, show it only if regexps are enabled.
505 if (m_bFilterWithRegex)
507 m_tooltips.AddTool(pWnd, IDS_LOG_FILTER_REGEX_TT);
509 else
510 m_tooltips.DelTool(pWnd);
513 void CLogDlg::EnableOKButton()
515 if (m_bSelect)
517 // the dialog is used to select revisions
518 if (m_bSelectionMustBeSingle)
520 // enable OK button if only a single revision is selected
521 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()==1));
523 else if (m_bSelectionMustBeContinuous)
524 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));
525 else
526 DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);
528 else
529 DialogEnableWindow(IDOK, TRUE);
532 CString CLogDlg::GetTagInfo(GitRev* pLogEntry)
534 CString cmd;
535 CString output;
537 if(m_LogList.m_HashMap.find(pLogEntry->m_CommitHash) != m_LogList.m_HashMap.end())
539 STRING_VECTOR &vector = m_LogList.m_HashMap[pLogEntry->m_CommitHash];
540 for(int i=0;i<vector.size();i++)
542 if(vector[i].Find(_T("refs/tags/")) == 0 )
544 CString tag= vector[i];
545 int start = vector[i].Find(_T("^{}"));
546 if(start>0)
547 tag=tag.Left(start);
548 else
549 continue;
551 cmd.Format(_T("git.exe cat-file tag %s"), tag);
553 if(g_Git.Run(cmd, &output, NULL, CP_UTF8) == 0 )
554 output+=_T("\n");
559 if(!output.IsEmpty())
561 output = _T("\n*") + CString(MAKEINTRESOURCE(IDS_PROC_LOG_TAGINFO)) + _T("*\n\n") + output;
564 return output;
567 void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)
569 // we fill here the log message rich edit control,
570 // and also populate the changed files list control
571 // according to the selected revision(s).
573 CRichEditCtrl * pMsgView = (CRichEditCtrl*)GetDlgItem(IDC_MSGVIEW);
574 // empty the log message view
575 pMsgView->SetWindowText(_T(" "));
576 // empty the changed files list
577 m_ChangedFileListCtrl.SetRedraw(FALSE);
578 // InterlockedExchange(&m_bNoDispUpdates, TRUE);
579 m_currentChangedArray = NULL;
580 //m_ChangedFileListCtrl.SetExtendedStyle ( LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER );
581 m_ChangedFileListCtrl.DeleteAllItems();
583 // if we're not here to really show a selected revision, just
584 // get out of here after clearing the views, which is what is intended
585 // if that flag is not set.
586 if (!bShow)
588 // force a redraw
589 m_ChangedFileListCtrl.Invalidate();
590 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
591 m_ChangedFileListCtrl.SetRedraw(TRUE);
592 return;
595 // depending on how many revisions are selected, we have to do different
596 // tasks.
597 int selCount = m_LogList.GetSelectedCount();
598 if (selCount == 0)
600 // if nothing is selected, we have nothing more to do
601 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
602 m_ChangedFileListCtrl.SetRedraw(TRUE);
603 return;
605 else if (selCount == 1)
607 // if one revision is selected, we have to fill the log message view
608 // with the corresponding log message, and also fill the changed files
609 // list fully.
610 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
611 int selIndex = m_LogList.GetNextSelectedItem(pos);
612 if (selIndex >= m_LogList.m_arShownList.GetCount())
614 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
615 m_ChangedFileListCtrl.SetRedraw(TRUE);
616 return;
618 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
621 // set the log message text
622 pMsgView->SetWindowText(CString(MAKEINTRESOURCE(IDS_HASH)) + _T(": ") + pLogEntry->m_CommitHash.ToString() + _T("\r\n\r\n"));
623 // turn bug ID's into links if the bugtraq: properties have been set
624 // and we can find a match of those in the log message
626 pMsgView->SetSel(-1,-1);
627 CHARFORMAT2 format;
628 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
629 format.cbSize = sizeof(CHARFORMAT2);
630 format.dwMask = CFM_BOLD;
631 format.dwEffects = CFE_BOLD;
632 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
634 CString msg=_T("* ");
635 msg+=pLogEntry->GetSubject();
636 pMsgView->ReplaceSel(msg);
638 pMsgView->SetSel(-1,-1);
639 format.dwEffects = 0;
640 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
642 msg=_T("\n");
643 msg+=pLogEntry->GetBody();
645 if(!pLogEntry->m_Notes.IsEmpty())
647 msg+= _T("\n*") + CString(MAKEINTRESOURCE(IDS_NOTES)) + _T("* ");
648 msg+= pLogEntry->m_Notes;
649 msg+= _T("\n\n");
652 msg+=GetTagInfo(pLogEntry);
654 pMsgView->ReplaceSel(msg);
656 CString text;
657 pMsgView->GetWindowText(text);
658 // the rich edit control doesn't count the CR char!
659 // to be exact: CRLF is treated as one char.
660 text.Remove('\r');
662 m_LogList.m_ProjectProperties.FindBugID(text, pMsgView);
663 CAppUtils::FormatTextInRichEditControl(pMsgView);
665 int HidePaths=m_cHidePaths.GetState() & 0x0003;
666 CString matchpath=this->m_path.GetGitPathString();
668 int count = pLogEntry->GetFiles(&m_LogList).GetCount();
669 for(int i=0;i<count && (!matchpath.IsEmpty());i++)
671 if( m_bWholeProject )
672 break;
674 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action &= ~(CTGitPath::LOGACTIONS_HIDE|CTGitPath::LOGACTIONS_GRAY);
676 if(pLogEntry->GetFiles(&m_LogList)[i].GetGitPathString().Left(matchpath.GetLength()) != matchpath && pLogEntry->GetFiles(&m_LogList)[i].GetGitOldPathString().Left(matchpath.GetLength()) != matchpath)
678 if(HidePaths==BST_CHECKED)
679 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;
680 if(HidePaths==BST_INDETERMINATE)
681 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_GRAY;
685 m_ChangedFileListCtrl.UpdateWithGitPathList(pLogEntry->GetFiles(&m_LogList));
686 m_ChangedFileListCtrl.m_CurrentVersion=pLogEntry->m_CommitHash;
687 m_ChangedFileListCtrl.Show(GITSLC_SHOWVERSIONED);
689 m_ChangedFileListCtrl.SetBusyString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES)));
691 if(!pLogEntry->m_IsDiffFiles)
692 m_ChangedFileListCtrl.SetBusy(TRUE);
693 else
694 m_ChangedFileListCtrl.SetBusy(FALSE);
696 m_ChangedFileListCtrl.SetRedraw(TRUE);
697 return;
701 else
703 // more than one revision is selected:
704 // the log message view must be emptied
705 // the changed files list contains all the changed paths from all
706 // selected revisions, with 'doubles' removed
707 m_currentChangedPathList = GetChangedPathsFromSelectedRevisions(true);
710 // redraw the views
711 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
712 #if 0
713 if (m_currentChangedArray)
715 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedArray->GetCount());
716 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedArray->GetCount());
718 else if (m_currentChangedPathList.GetCount())
720 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedPathList.GetCount());
721 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedPathList.GetCount());
723 else
725 m_ChangedFileListCtrl.SetItemCountEx(0);
726 m_ChangedFileListCtrl.Invalidate();
728 #endif
729 // sort according to the settings
730 if (m_nSortColumnPathList > 0)
731 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
732 else
733 SetSortArrow(&m_ChangedFileListCtrl, -1, false);
734 m_ChangedFileListCtrl.SetRedraw(TRUE);
738 void CLogDlg::OnBnClickedRefresh()
740 Refresh (true);
743 void CLogDlg::Refresh (bool clearfilter /*autoGoOnline*/)
745 m_limit = 0;
746 m_LogList.Refresh(clearfilter);
747 ShowStartRef();
748 FillLogMessageCtrl(false);
753 BOOL CLogDlg::Cancel()
755 return m_bCancelled;
758 void CLogDlg::SaveSplitterPos()
760 if (!IsIconic())
762 CRegDWORD regPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
763 CRegDWORD regPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
764 RECT rectSplitter;
765 m_wndSplitter1.GetWindowRect(&rectSplitter);
766 ScreenToClient(&rectSplitter);
767 regPos1 = rectSplitter.top;
768 m_wndSplitter2.GetWindowRect(&rectSplitter);
769 ScreenToClient(&rectSplitter);
770 regPos2 = rectSplitter.top;
774 void CLogDlg::OnCancel()
776 this->ShowWindow(SW_HIDE);
778 // canceling means stopping the working thread if it's still running.
779 m_LogList.SafeTerminateAsyncDiffThread();
780 if (this->IsThreadRunning())
782 m_LogList.SafeTerminateThread();
784 UpdateData();
786 SaveSplitterPos();
787 __super::OnCancel();
790 CString CLogDlg::MakeShortMessage(const CString& message)
792 bool bFoundShort = true;
793 CString sShortMessage = m_LogList.m_ProjectProperties.GetLogSummary(message);
794 if (sShortMessage.IsEmpty())
796 bFoundShort = false;
797 sShortMessage = message;
799 // Remove newlines and tabs 'cause those are not shown nicely in the list control
800 sShortMessage.Remove('\r');
801 sShortMessage.Replace(_T('\t'), _T(' '));
803 // Suppose the first empty line separates 'summary' from the rest of the message.
804 int found = sShortMessage.Find(_T("\n\n"));
805 // To avoid too short 'short' messages
806 // (e.g. if the message looks something like "Bugfix:\n\n*done this\n*done that")
807 // only use the empty newline as a separator if it comes after at least 15 chars.
808 if ((!bFoundShort)&&(found >= 15))
810 sShortMessage = sShortMessage.Left(found);
812 sShortMessage.Replace('\n', ' ');
813 return sShortMessage;
816 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*/)
818 #if 0
819 if (rev == SVN_INVALID_REVNUM)
821 m_childCounter--;
822 return TRUE;
825 // this is the callback function which receives the data for every revision we ask the log for
826 // we store this information here one by one.
827 m_logcounter += 1;
828 if (m_startrev == -1)
829 m_startrev = rev;
830 if (m_limit != 0)
832 m_limitcounter--;
833 m_LogProgress.SetPos(m_limit - m_limitcounter);
835 else if (m_startrev.IsNumber() && m_startrev.IsNumber())
836 m_LogProgress.SetPos((git_revnum_t)m_startrev-rev+(git_revnum_t)m_endrev);
837 __time64_t ttime = time/1000000L;
838 if (m_tTo < (DWORD)ttime)
839 m_tTo = (DWORD)ttime;
840 if (m_tFrom > (DWORD)ttime)
841 m_tFrom = (DWORD)ttime;
842 if ((m_lowestRev > rev)||(m_lowestRev < 0))
843 m_lowestRev = rev;
844 // Add as many characters from the log message to the list control
845 PLOGENTRYDATA pLogItem = new LOGENTRYDATA;
846 pLogItem->bCopies = !!copies;
848 // find out if this item was copied in the revision
849 BOOL copiedself = FALSE;
850 if (copies)
852 for (INT_PTR cpPathIndex = 0; cpPathIndex < cpaths->GetCount(); ++cpPathIndex)
854 LogChangedPath * cpath = cpaths->SafeGetAt(cpPathIndex);
855 if (!cpath->sCopyFromPath.IsEmpty() && (cpath->sPath.Compare(m_sSelfRelativeURL) == 0))
857 // note: this only works if the log is fetched top-to-bottom
858 // but since we do that, it shouldn't be a problem
859 m_sSelfRelativeURL = cpath->sCopyFromPath;
860 copiedself = TRUE;
861 break;
865 pLogItem->bCopiedSelf = copiedself;
866 pLogItem->tmDate = ttime;
867 pLogItem->sAuthor = author;
868 pLogItem->sDate = date;
869 pLogItem->sShortMessage = MakeShortMessage(message);
870 pLogItem->dwFileChanges = filechanges;
871 pLogItem->actions = actions;
872 pLogItem->haschildren = haschildren;
873 pLogItem->childStackDepth = m_childCounter;
874 m_maxChild = max(m_childCounter, m_maxChild);
875 if (haschildren)
876 m_childCounter++;
877 pLogItem->sBugIDs = m_ProjectProperties.FindBugID(message).Trim();
879 // split multi line log entries and concatenate them
880 // again but this time with \r\n as line separators
881 // so that the edit control recognizes them
884 if (message.GetLength()>0)
886 m_sMessageBuf = message;
887 m_sMessageBuf.Replace(_T("\n\r"), _T("\n"));
888 m_sMessageBuf.Replace(_T("\r\n"), _T("\n"));
889 if (m_sMessageBuf.Right(1).Compare(_T("\n"))==0)
890 m_sMessageBuf = m_sMessageBuf.Left(m_sMessageBuf.GetLength()-1);
892 else
893 m_sMessageBuf.Empty();
894 pLogItem->sMessage = m_sMessageBuf;
895 pLogItem->Rev = rev;
897 // move-construct path array
899 pLogItem->pArChangedPaths = new LogChangedPathArray (*cpaths);
900 cpaths->RemoveAll();
902 catch (CException * e)
904 CMessageBox::Show(NULL, IDS_ERR_NOTENOUGHMEMORY, IDS_APPNAME, MB_ICONERROR);
905 e->Delete();
906 m_bCancelled = TRUE;
908 m_logEntries.push_back(pLogItem);
909 m_arShownList.Add(pLogItem);
910 #endif
911 return TRUE;
914 GitRev g_rev;
915 //this is the thread function which calls the subversion function
920 void CLogDlg::CopyChangedSelectionToClipBoard()
923 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
924 if (pos == NULL)
925 return; // nothing is selected, get out of here
927 CString sPaths;
929 // CGitRev* pLogEntry = reinterpret_cast<CGitRev* >(m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
930 // if (pos)
932 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
933 while (pos)
935 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
936 CTGitPath *path = (CTGitPath*)m_ChangedFileListCtrl.GetItemData(nItem);
937 if(path)
938 sPaths += path->GetGitPathString();
939 sPaths += _T("\r\n");
942 #if 0
943 else
945 // only one revision is selected in the log dialog top pane
946 // but multiple items could be selected in the changed items list
947 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
948 while (pos)
950 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
951 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(nItem);
953 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
955 // some items are hidden! So find out which item the user really selected
956 INT_PTR selRealIndex = -1;
957 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
959 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
960 selRealIndex++;
961 if (selRealIndex == nItem)
963 changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex);
964 break;
968 if (changedlogpath)
970 sPaths += changedlogpath->sPath;
971 sPaths += _T("\r\n");
975 #endif
976 sPaths.Trim();
977 CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());
981 BOOL CLogDlg::IsDiffPossible(LogChangedPath * /*changedpath*/, git_revnum_t rev)
983 #if 0
984 CString added, deleted;
985 if (changedpath == NULL)
986 return false;
988 if ((rev > 1)&&(changedpath->action != LOGACTIONS_DELETED))
990 if (changedpath->action == LOGACTIONS_ADDED) // file is added
992 if (changedpath->lCopyFromRev == 0)
993 return FALSE; // but file was not added with history
995 return TRUE;
997 #endif
998 return FALSE;
1001 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)
1003 // we have two separate context menus:
1004 // one shown on the log message list control,
1005 // the other shown in the changed-files list control
1006 int selCount = m_LogList.GetSelectedCount();
1007 if (pWnd == &m_LogList)
1009 //ShowContextMenuForRevisions(pWnd, point);
1011 else if (pWnd == &m_ChangedFileListCtrl)
1013 //ShowContextMenuForChangedpaths(pWnd, point);
1015 else if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))
1017 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1018 int selIndex = -1;
1019 if (pos)
1020 selIndex = m_LogList.GetNextSelectedItem(pos);
1022 GitRev *pRev = ((GitRev*)m_LogList.m_arShownList[selIndex]);
1024 if ((point.x == -1) && (point.y == -1))
1026 CRect rect;
1027 GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);
1028 ClientToScreen(&rect);
1029 point = rect.CenterPoint();
1031 CString sMenuItemText;
1032 CIconMenu popup;
1033 if (popup.CreatePopupMenu())
1035 // add the 'default' entries
1036 sMenuItemText.LoadString(IDS_SCIEDIT_COPY);
1037 popup.AppendMenu(MF_STRING | MF_ENABLED, WM_COPY, sMenuItemText);
1038 sMenuItemText.LoadString(IDS_SCIEDIT_SELECTALL);
1039 popup.AppendMenu(MF_STRING | MF_ENABLED, EM_SETSEL, sMenuItemText);
1040 sMenuItemText.LoadString(IDS_EDIT_NOTES);
1041 popup.AppendMenuIcon( CGitLogList::ID_EDITNOTE, sMenuItemText, IDI_EDIT);
1043 //if (selIndex >= 0)
1045 // popup.AppendMenu(MF_SEPARATOR);
1046 // sMenuItemText.LoadString(IDS_LOG_POPUP_EDITLOG);
1047 // popup.AppendMenu(MF_STRING | MF_ENABLED, CGitLogList::ID_EDITAUTHOR, sMenuItemText);
1050 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1051 switch (cmd)
1053 case 0:
1054 break; // no command selected
1055 case EM_SETSEL:
1056 case WM_COPY:
1057 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);
1058 break;
1059 case CGitLogList::ID_EDITNOTE:
1060 CAppUtils::EditNote(pRev);
1061 this->FillLogMessageCtrl(true);
1062 break;
1068 void CLogDlg::OnOK()
1070 // since the log dialog is also used to select revisions for other
1071 // dialogs, we have to do some work before closing this dialog
1072 if (GetFocus() != GetDlgItem(IDOK))
1073 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter
1075 m_LogList.SafeTerminateAsyncDiffThread();
1076 if (this->IsThreadRunning())
1078 m_LogList.SafeTerminateThread();
1080 UpdateData();
1081 // check that one and only one row is selected
1082 if (m_LogList.GetSelectedCount() == 1)
1084 // get the selected row
1085 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1086 int selIndex = m_LogList.GetNextSelectedItem(pos);
1087 if (selIndex < m_LogList.m_arShownList.GetCount())
1089 // all ok, pick up the revision
1090 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
1091 // extract the hash
1092 m_sSelectedHash = pLogEntry->m_CommitHash;
1095 UpdateData(FALSE);
1096 SaveSplitterPos();
1097 __super::OnOK();
1099 #if 0
1100 if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))
1101 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.
1103 CString temp;
1104 CString buttontext;
1105 GetDlgItemText(IDOK, buttontext);
1106 temp.LoadString(IDS_MSGBOX_CANCEL);
1107 if (temp.Compare(buttontext) != 0)
1108 __super::OnOK(); // only exit if the button text matches, and that will match only if the thread isn't running anymore
1109 m_bCancelled = TRUE;
1110 m_selectedRevs.Clear();
1111 m_selectedRevsOneRange.Clear();
1112 if (m_pNotifyWindow)
1114 int selIndex = m_LogList.GetSelectionMark();
1115 if (selIndex >= 0)
1117 PLOGENTRYDATA pLogEntry = NULL;
1118 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1119 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1120 m_selectedRevs.AddRevision(pLogEntry->Rev);
1121 git_revnum_t lowerRev = pLogEntry->Rev;
1122 git_revnum_t higherRev = lowerRev;
1123 while (pos)
1125 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1126 git_revnum_t rev = pLogEntry->Rev;
1127 m_selectedRevs.AddRevision(pLogEntry->Rev);
1128 if (lowerRev > rev)
1129 lowerRev = rev;
1130 if (higherRev < rev)
1131 higherRev = rev;
1133 if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())
1135 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);
1137 BOOL bSentMessage = FALSE;
1138 if (m_LogList.GetSelectedCount() == 1)
1140 // if only one revision is selected, check if the path/url with which the dialog was started
1141 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.
1142 // if it was copied, use the copy from revision as lowerRev
1143 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))
1145 CString sUrl = m_path.GetGitPathString();
1146 if (!m_path.IsUrl())
1148 sUrl = GetURLFromPath(m_path);
1150 sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());
1151 for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)
1153 LogChangedPath * pData = pLogEntry->pArChangedPaths->SafeGetAt(cp);
1154 if (pData)
1156 if (sUrl.Compare(pData->sPath) == 0)
1158 if (!pData->sCopyFromPath.IsEmpty())
1160 lowerRev = pData->lCopyFromRev;
1161 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);
1162 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);
1163 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1164 bSentMessage = TRUE;
1171 if ( !bSentMessage )
1173 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);
1174 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);
1175 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1176 if (m_selectedRevsOneRange.GetCount())
1177 m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);
1181 UpdateData();
1182 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry"));
1183 reg = m_btnShow.GetCurrentEntry();
1184 SaveSplitterPos();
1185 #endif
1188 void CLogDlg::OnNMDblclkChangedFileList(NMHDR * /*pNMHDR*/, LRESULT *pResult)
1190 // a double click on an entry in the changed-files list has happened
1191 *pResult = 0;
1193 DiffSelectedFile();
1196 void CLogDlg::DiffSelectedFile()
1198 #if 0
1199 if (m_bThreadRunning)
1200 return;
1201 UpdateLogInfoLabel();
1202 INT_PTR selIndex = m_ChangedFileListCtrl.GetSelectionMark();
1203 if (selIndex < 0)
1204 return;
1205 if (m_ChangedFileListCtrl.GetSelectedCount() == 0)
1206 return;
1207 // find out if there's an entry selected in the log list
1208 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1209 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1210 git_revnum_t rev1 = pLogEntry->Rev;
1211 git_revnum_t rev2 = rev1;
1212 if (pos)
1214 while (pos)
1216 // there's at least a second entry selected in the log list: several revisions selected!
1217 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1218 if (pLogEntry)
1220 rev1 = max(rev1,(long)pLogEntry->Rev);
1221 rev2 = min(rev2,(long)pLogEntry->Rev);
1224 rev2--;
1225 // now we have both revisions selected in the log list, so we can do a diff of the selected
1226 // entry in the changed files list with these two revisions.
1227 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1229 else
1231 rev2 = rev1-1;
1232 // nothing or only one revision selected in the log list
1233 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
1235 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
1237 // some items are hidden! So find out which item the user really clicked on
1238 INT_PTR selRealIndex = -1;
1239 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
1241 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1242 selRealIndex++;
1243 if (selRealIndex == selIndex)
1245 selIndex = hiddenindex;
1246 changedpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
1247 break;
1252 if (IsDiffPossible(changedpath, rev1))
1254 // diffs with renamed files are possible
1255 if ((changedpath)&&(!changedpath->sCopyFromPath.IsEmpty()))
1256 rev2 = changedpath->lCopyFromRev;
1257 else
1259 // if the path was modified but the parent path was 'added with history'
1260 // then we have to use the copy from revision of the parent path
1261 CTGitPath cpath = CTGitPath(changedpath->sPath);
1262 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
1264 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->SafeGetAt(flist)->sPath);
1265 if (p.IsAncestorOf(cpath))
1267 if (!pLogEntry->pArChangedPaths->SafeGetAt(flist)->sCopyFromPath.IsEmpty())
1268 rev2 = pLogEntry->pArChangedPaths->SafeGetAt(flist)->lCopyFromRev;
1272 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1274 else
1276 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1277 CTGitPath tempfile2 = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1278 GitRev r = rev1;
1279 // deleted files must be opened from the revision before the deletion
1280 if (changedpath->action == LOGACTIONS_DELETED)
1281 r = rev1-1;
1282 m_bCancelled = false;
1284 CProgressDlg progDlg;
1285 progDlg.SetTitle(IDS_APPNAME);
1286 progDlg.SetAnimation(IDR_DOWNLOAD);
1287 CString sInfoLine;
1288 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)(m_sRepositoryRoot + changedpath->sPath), (LPCTSTR)r.ToString());
1289 progDlg.SetLine(1, sInfoLine, true);
1290 SetAndClearProgressInfo(&progDlg);
1291 progDlg.ShowModeless(m_hWnd);
1293 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), r, r, tempfile))
1295 m_bCancelled = false;
1296 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), GitRev::REV_HEAD, r, tempfile))
1298 progDlg.Stop();
1299 SetAndClearProgressInfo((HWND)NULL);
1300 CMessageBox::Show(m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1301 return;
1304 progDlg.Stop();
1305 SetAndClearProgressInfo((HWND)NULL);
1307 CString sName1, sName2;
1308 sName1.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1);
1309 sName2.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1-1);
1310 CAppUtils::DiffFlags flags;
1311 flags.AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1312 if (changedpath->action == LOGACTIONS_DELETED)
1313 CAppUtils::StartExtDiff(tempfile, tempfile2, sName2, sName1, flags);
1314 else
1315 CAppUtils::StartExtDiff(tempfile2, tempfile, sName2, sName1, flags);
1318 #endif
1322 void CLogDlg::DoDiffFromLog(INT_PTR selIndex, GitRev* rev1, GitRev* rev2, bool /*blame*/, bool /*unified*/)
1324 DialogEnableWindow(IDOK, FALSE);
1325 // SetPromptApp(&theApp);
1326 theApp.DoWaitCursor(1);
1328 CString temppath;
1329 GetTempPath(temppath);
1331 CString file1;
1332 file1.Format(_T("%s%s_%s%s"),
1333 temppath,
1334 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1335 rev1->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength()),
1336 (*m_currentChangedArray)[selIndex].GetFileExtension());
1338 CString file2;
1339 file2.Format(_T("%s\\%s_%s%s"),
1340 temppath,
1341 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1342 rev2->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength()),
1343 (*m_currentChangedArray)[selIndex].GetFileExtension());
1345 CString cmd;
1347 g_Git.GetOneFile(rev1->m_CommitHash.ToString(), (CTGitPath &)(*m_currentChangedArray)[selIndex],file1);
1349 g_Git.GetOneFile(rev2->m_CommitHash.ToString(), (CTGitPath &)(*m_currentChangedArray)[selIndex],file2);
1351 CAppUtils::DiffFlags flags;
1352 CAppUtils::StartExtDiff(file1,file2,_T("A"),_T("B"),flags);
1354 #if 0
1355 //get the filename
1356 CString filepath;
1357 if (Git::PathIsURL(m_path))
1359 filepath = m_path.GetGitPathString();
1361 else
1363 filepath = GetURLFromPath(m_path);
1364 if (filepath.IsEmpty())
1366 theApp.DoWaitCursor(-1);
1367 CString temp;
1368 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1369 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1370 TRACE(_T("could not retrieve the URL of the file!\n"));
1371 EnableOKButton();
1372 theApp.DoWaitCursor(-11);
1373 return; //exit
1376 m_bCancelled = FALSE;
1377 filepath = GetRepositoryRoot(CTGitPath(filepath));
1379 CString firstfile, secondfile;
1380 if (m_LogList.GetSelectedCount()==1)
1382 int s = m_LogList.GetSelectionMark();
1383 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(s));
1384 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
1385 firstfile = changedpath->sPath;
1386 secondfile = firstfile;
1387 if ((rev2 == rev1-1)&&(changedpath->lCopyFromRev > 0)) // is it an added file with history?
1389 secondfile = changedpath->sCopyFromPath;
1390 rev2 = changedpath->lCopyFromRev;
1393 else
1395 firstfile = m_currentChangedPathList[selIndex].GetGitPathString();
1396 secondfile = firstfile;
1399 firstfile = filepath + firstfile.Trim();
1400 secondfile = filepath + secondfile.Trim();
1402 GitDiff diff(this, this->m_hWnd, true);
1403 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1404 diff.SetHEADPeg(m_LogRevision);
1405 if (unified)
1407 if (PromptShown())
1408 diff.ShowUnifiedDiff(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1);
1409 else
1410 CAppUtils::StartShowUnifiedDiff(m_hWnd, CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), m_LogRevision);
1412 else
1414 if (diff.ShowCompare(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), false, blame))
1416 if (firstfile.Compare(secondfile)==0)
1418 git_revnum_t baseRev = 0;
1419 diff.DiffProps(CTGitPath(firstfile), rev2, rev1, baseRev);
1424 #endif
1426 theApp.DoWaitCursor(-1);
1427 EnableOKButton();
1430 BOOL CLogDlg::Open(bool /*bOpenWith*/,CString changedpath, git_revnum_t rev)
1432 #if 0
1433 DialogEnableWindow(IDOK, FALSE);
1434 SetPromptApp(&theApp);
1435 theApp.DoWaitCursor(1);
1436 CString filepath;
1437 if (Git::PathIsURL(m_path))
1439 filepath = m_path.GetGitPathString();
1441 else
1443 filepath = GetURLFromPath(m_path);
1444 if (filepath.IsEmpty())
1446 theApp.DoWaitCursor(-1);
1447 CString temp;
1448 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1449 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1450 TRACE(_T("could not retrieve the URL of the file!\n"));
1451 EnableOKButton();
1452 return FALSE;
1455 m_bCancelled = false;
1456 filepath = GetRepositoryRoot(CTGitPath(filepath));
1457 filepath += changedpath;
1459 CProgressDlg progDlg;
1460 progDlg.SetTitle(IDS_APPNAME);
1461 progDlg.SetAnimation(IDR_DOWNLOAD);
1462 CString sInfoLine;
1463 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)GitRev(rev).ToString());
1464 progDlg.SetLine(1, sInfoLine, true);
1465 SetAndClearProgressInfo(&progDlg);
1466 progDlg.ShowModeless(m_hWnd);
1468 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(filepath), rev);
1469 m_bCancelled = false;
1470 if (!Cat(CTGitPath(filepath), GitRev(rev), rev, tempfile))
1472 progDlg.Stop();
1473 SetAndClearProgressInfo((HWND)NULL);
1474 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1475 EnableOKButton();
1476 theApp.DoWaitCursor(-1);
1477 return FALSE;
1479 progDlg.Stop();
1480 SetAndClearProgressInfo((HWND)NULL);
1481 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1482 if (!bOpenWith)
1484 int ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1485 if (ret <= HINSTANCE_ERROR)
1486 bOpenWith = true;
1488 if (bOpenWith)
1490 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1491 cmd += tempfile.GetWinPathString() + _T(" ");
1492 CAppUtils::LaunchApplication(cmd, NULL, false);
1494 EnableOKButton();
1495 theApp.DoWaitCursor(-1);
1496 #endif
1497 return TRUE;
1500 void CLogDlg::EditAuthor(const CLogDataVector& /*logs*/)
1502 #if 0
1503 CString url;
1504 CString name;
1505 if (logs.size() == 0)
1506 return;
1507 DialogEnableWindow(IDOK, FALSE);
1508 SetPromptApp(&theApp);
1509 theApp.DoWaitCursor(1);
1510 if (Git::PathIsURL(m_path))
1511 url = m_path.GetGitPathString();
1512 else
1514 url = GetURLFromPath(m_path);
1516 name = Git_PROP_REVISION_AUTHOR;
1518 CString value = RevPropertyGet(name, CTGitPath(url), logs[0]->Rev);
1519 CString sOldValue = value;
1520 value.Replace(_T("\n"), _T("\r\n"));
1521 CInputDlg dlg(this);
1522 dlg.m_sHintText.LoadString(IDS_LOG_AUTHOR);
1523 dlg.m_sInputText = value;
1524 dlg.m_sTitle.LoadString(IDS_LOG_AUTHOREDITTITLE);
1525 dlg.m_pProjectProperties = &m_ProjectProperties;
1526 dlg.m_bUseLogWidth = false;
1527 if (dlg.DoModal() == IDOK)
1529 dlg.m_sInputText.Remove('\r');
1531 LogCache::CCachedLogInfo* toUpdate = GetLogCache (CTGitPath (m_sRepositoryRoot));
1533 CProgressDlg progDlg;
1534 progDlg.SetTitle(IDS_APPNAME);
1535 progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));
1536 progDlg.SetTime(true);
1537 progDlg.SetShowProgressBar(true);
1538 progDlg.ShowModeless(m_hWnd);
1539 for (DWORD i=0; i<logs.size(); ++i)
1541 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), logs[i]->Rev))
1543 progDlg.Stop();
1544 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1545 break;
1547 else
1550 logs[i]->sAuthor = dlg.m_sInputText;
1551 m_LogList.Invalidate();
1553 // update the log cache
1555 if (toUpdate != NULL)
1557 // log caching is active
1559 LogCache::CCachedLogInfo newInfo;
1560 newInfo.Insert ( logs[i]->Rev
1561 , (const char*) CUnicodeUtils::GetUTF8 (logs[i]->sAuthor)
1562 , ""
1564 , LogCache::CRevisionInfoContainer::HAS_AUTHOR);
1566 toUpdate->Update (newInfo);
1569 progDlg.SetProgress64(i, logs.size());
1571 progDlg.Stop();
1573 theApp.DoWaitCursor(-1);
1574 EnableOKButton();
1575 #endif
1578 void CLogDlg::EditLogMessage(int /*index*/)
1581 #if 0
1582 CString url;
1583 CString name;
1584 DialogEnableWindow(IDOK, FALSE);
1585 SetPromptApp(&theApp);
1586 theApp.DoWaitCursor(1);
1587 if (Git::PathIsURL(m_path))
1588 url = m_path.GetGitPathString();
1589 else
1591 url = GetURLFromPath(m_path);
1593 name = Git_PROP_REVISION_LOG;
1595 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(index));
1596 m_bCancelled = FALSE;
1597 CString value = RevPropertyGet(name, CTGitPath(url), pLogEntry->Rev);
1598 CString sOldValue = value;
1599 value.Replace(_T("\n"), _T("\r\n"));
1600 CInputDlg dlg(this);
1601 dlg.m_sHintText.LoadString(IDS_LOG_MESSAGE);
1602 dlg.m_sInputText = value;
1603 dlg.m_sTitle.LoadString(IDS_LOG_MESSAGEEDITTITLE);
1604 dlg.m_pProjectProperties = &m_ProjectProperties;
1605 dlg.m_bUseLogWidth = true;
1606 if (dlg.DoModal() == IDOK)
1608 dlg.m_sInputText.Remove('\r');
1609 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), pLogEntry->Rev))
1611 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1613 else
1615 pLogEntry->sShortMessage = MakeShortMessage(dlg.m_sInputText);
1616 // split multi line log entries and concatenate them
1617 // again but this time with \r\n as line separators
1618 // so that the edit control recognizes them
1619 if (dlg.m_sInputText.GetLength()>0)
1621 m_sMessageBuf = dlg.m_sInputText;
1622 dlg.m_sInputText.Replace(_T("\n\r"), _T("\n"));
1623 dlg.m_sInputText.Replace(_T("\r\n"), _T("\n"));
1624 if (dlg.m_sInputText.Right(1).Compare(_T("\n"))==0)
1625 dlg.m_sInputText = dlg.m_sInputText.Left(dlg.m_sInputText.GetLength()-1);
1627 else
1628 dlg.m_sInputText.Empty();
1629 pLogEntry->sMessage = dlg.m_sInputText;
1630 pLogEntry->sBugIDs = m_ProjectProperties.FindBugID(dlg.m_sInputText);
1631 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
1632 pMsgView->SetWindowText(_T(" "));
1633 pMsgView->SetWindowText(dlg.m_sInputText);
1634 m_ProjectProperties.FindBugID(dlg.m_sInputText, pMsgView);
1635 m_LogList.Invalidate();
1637 // update the log cache
1638 LogCache::CCachedLogInfo* toUpdate = GetLogCache(CTGitPath (m_sRepositoryRoot));
1639 if (toUpdate != NULL)
1641 // log caching is active
1643 LogCache::CCachedLogInfo newInfo;
1644 newInfo.Insert( pLogEntry->Rev
1645 , ""
1646 , (const char*) CUnicodeUtils::GetUTF8 (pLogEntry->sMessage)
1648 , LogCache::CRevisionInfoContainer::HAS_COMMENT);
1650 toUpdate->Update(newInfo);
1654 theApp.DoWaitCursor(-1);
1655 EnableOKButton();
1656 #endif
1659 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)
1661 // Skip Ctrl-C when copying text out of the log message or search filter
1662 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);
1663 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
1665 if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1667 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1669 m_LogList.DiffSelectedRevWithPrevious();
1670 return TRUE;
1674 if (m_hAccel && !bSkipAccelerator)
1676 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1677 if (ret)
1678 return TRUE;
1681 if(::IsWindow(m_tooltips.m_hWnd))
1682 m_tooltips.RelayEvent(pMsg);
1683 return __super::PreTranslateMessage(pMsg);
1687 BOOL CLogDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1689 //if (this->IsThreadRunning())
1690 if(m_LogList.m_bNoDispUpdates)
1692 // only show the wait cursor over the list control
1693 if ((pWnd)&&
1694 ((pWnd == GetDlgItem(IDC_LOGLIST))||
1695 (pWnd == GetDlgItem(IDC_MSGVIEW))||
1696 (pWnd == GetDlgItem(IDC_LOGMSG))))
1698 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1699 SetCursor(hCur);
1700 return TRUE;
1703 if ((pWnd) && (pWnd == GetDlgItem(IDC_MSGVIEW)))
1704 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1706 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1707 SetCursor(hCur);
1708 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1711 void CLogDlg::OnBnClickedHelp()
1713 OnHelp();
1716 void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1718 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1719 *pResult = 0;
1720 //if (this->IsThreadRunning())
1721 if(m_LogList.m_bNoDispUpdates)
1722 return;
1723 if (pNMLV->iItem >= 0)
1725 this->m_LogList.m_nSearchIndex = pNMLV->iItem;
1726 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(pNMLV->iItem));
1727 m_LogList.m_lastSelectedHash = pLogEntry->m_CommitHash;
1728 if (pNMLV->iSubItem != 0)
1729 return;
1730 if ((pNMLV->iItem == m_LogList.m_arShownList.GetCount()))
1732 // remove the selected state
1733 if (pNMLV->uChanged & LVIF_STATE)
1735 m_LogList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);
1736 FillLogMessageCtrl();
1737 UpdateData(FALSE);
1738 UpdateLogInfoLabel();
1740 return;
1742 if (pNMLV->uChanged & LVIF_STATE)
1744 FillLogMessageCtrl();
1745 UpdateData(FALSE);
1748 else
1750 m_LogList.m_lastSelectedHash.Empty();
1751 FillLogMessageCtrl();
1752 UpdateData(FALSE);
1754 EnableOKButton();
1755 UpdateLogInfoLabel();
1758 void CLogDlg::OnEnLinkMsgview(NMHDR *pNMHDR, LRESULT *pResult)
1760 ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);
1761 if (pEnLink->msg == WM_LBUTTONUP)
1763 CString url, msg;
1764 GetDlgItemText(IDC_MSGVIEW, msg);
1765 msg.Replace(_T("\r\n"), _T("\n"));
1766 url = msg.Mid(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax-pEnLink->chrg.cpMin);
1767 if (!::PathIsURL(url))
1769 url = m_LogList.m_ProjectProperties.GetBugIDUrl(url);
1770 url = GetAbsoluteUrlFromRelativeUrl(url);
1772 if (!url.IsEmpty())
1773 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
1775 *pResult = 0;
1778 class CDateSorter
1780 public:
1781 class CCommitPointer
1783 public:
1784 CCommitPointer():m_cont(NULL){}
1785 CCommitPointer(const CCommitPointer& P_Right)
1786 : m_cont(NULL)
1788 *this = P_Right;
1791 CCommitPointer& operator = (const CCommitPointer& P_Right)
1793 if(IsPointer())
1795 (*m_cont->m_parDates)[m_place] = P_Right.GetDate();
1796 (*m_cont->m_parFileChanges)[m_place] = P_Right.GetChanges();
1797 (*m_cont->m_parAuthors)[m_place] = P_Right.GetAuthor();
1799 else
1801 m_Date = P_Right.GetDate();
1802 m_Changes = P_Right.GetChanges();
1803 m_csAuthor = P_Right.GetAuthor();
1805 return *this;
1808 void Clone(const CCommitPointer& P_Right)
1810 m_cont = P_Right.m_cont;
1811 m_place = P_Right.m_place;
1812 m_Date = P_Right.m_Date;
1813 m_Changes = P_Right.m_Changes;
1814 m_csAuthor = P_Right.m_csAuthor;
1817 DWORD GetDate() const {return IsPointer() ? (*m_cont->m_parDates)[m_place] : m_Date;}
1818 DWORD GetChanges() const {return IsPointer() ? (*m_cont->m_parFileChanges)[m_place] : m_Changes;}
1819 CString GetAuthor() const {return IsPointer() ? (*m_cont->m_parAuthors)[m_place] : m_csAuthor;}
1821 bool IsPointer() const {return m_cont != NULL;}
1822 //When pointer
1823 CDateSorter* m_cont;
1824 int m_place;
1826 //When element
1827 DWORD m_Date;
1828 DWORD m_Changes;
1829 CString m_csAuthor;
1832 class iterator : public std::iterator<std::random_access_iterator_tag, CCommitPointer>
1834 public:
1835 CCommitPointer m_ptr;
1837 iterator(){}
1838 iterator(const iterator& P_Right){*this = P_Right;}
1839 iterator& operator=(const iterator& P_Right)
1841 m_ptr.Clone(P_Right.m_ptr);
1842 return *this;
1845 CCommitPointer& operator*(){return m_ptr;}
1846 CCommitPointer* operator->(){return &m_ptr;}
1847 const CCommitPointer& operator*()const{return m_ptr;}
1848 const CCommitPointer* operator->()const{return &m_ptr;}
1850 iterator& operator+=(size_t P_iOffset){m_ptr.m_place += P_iOffset;return *this;}
1851 iterator& operator-=(size_t P_iOffset){m_ptr.m_place -= P_iOffset;return *this;}
1852 iterator operator+(size_t P_iOffset)const{iterator it(*this); it += P_iOffset;return it;}
1853 iterator operator-(size_t P_iOffset)const{iterator it(*this); it -= P_iOffset;return it;}
1855 iterator& operator++(){++m_ptr.m_place;return *this;}
1856 iterator& operator--(){--m_ptr.m_place;return *this;}
1857 iterator operator++(int){iterator it(*this);++*this;return it;}
1858 iterator operator--(int){iterator it(*this);--*this;return it;}
1860 size_t operator-(const iterator& P_itRight)const{return m_ptr.m_place - P_itRight->m_place;}
1862 bool operator<(const iterator& P_itRight)const{return m_ptr.m_place < P_itRight->m_place;}
1863 bool operator!=(const iterator& P_itRight)const{return m_ptr.m_place != P_itRight->m_place;}
1864 bool operator==(const iterator& P_itRight)const{return m_ptr.m_place == P_itRight->m_place;}
1865 bool operator>(const iterator& P_itRight)const{return m_ptr.m_place > P_itRight->m_place;}
1867 iterator begin()
1869 iterator it;
1870 it->m_place = 0;
1871 it->m_cont = this;
1872 return it;
1874 iterator end()
1876 iterator it;
1877 it->m_place = m_parDates->GetCount();
1878 it->m_cont = this;
1879 return it;
1882 CDWordArray * m_parDates;
1883 CDWordArray * m_parFileChanges;
1884 CStringArray * m_parAuthors;
1887 class CDateSorterLess
1889 public:
1890 bool operator () (const CDateSorter::CCommitPointer& P_Left, const CDateSorter::CCommitPointer& P_Right) const
1892 return P_Left.GetDate() > P_Right.GetDate(); //Last date first
1899 void CLogDlg::OnBnClickedStatbutton()
1901 if (this->IsThreadRunning())
1902 return;
1903 if (m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC)
1904 return; // nothing or just the working copy changes are shown, so no statistics.
1905 // the statistics dialog expects the log entries to be sorted by date
1906 SortByColumn(3, false);
1907 CThreadSafePtrArray shownlist(NULL);
1908 m_LogList.RecalculateShownList(&shownlist);
1909 // create arrays which are aware of the current filter
1910 CStringArray m_arAuthorsFiltered;
1911 CDWordArray m_arDatesFiltered;
1912 CDWordArray m_arFileChangesFiltered;
1913 for (INT_PTR i=0; i<shownlist.GetCount(); ++i)
1915 GitRev* pLogEntry = reinterpret_cast<GitRev*>(shownlist.SafeGetAt(i));
1917 // do not take working dir changes into statistics
1918 if (pLogEntry->m_CommitHash.IsEmpty()) {
1919 continue;
1922 CString strAuthor = pLogEntry->GetAuthorName();
1923 if ( strAuthor.IsEmpty() )
1925 strAuthor.LoadString(IDS_STATGRAPH_EMPTYAUTHOR);
1927 m_arAuthorsFiltered.Add(strAuthor);
1928 m_arDatesFiltered.Add(pLogEntry->GetCommitterDate().GetTime());
1929 m_arFileChangesFiltered.Add(pLogEntry->GetFiles(&m_LogList).GetCount());
1932 CDateSorter W_Sorter;
1933 W_Sorter.m_parAuthors = &m_arAuthorsFiltered;
1934 W_Sorter.m_parDates = &m_arDatesFiltered;
1935 W_Sorter.m_parFileChanges = &m_arFileChangesFiltered;
1936 std::sort(W_Sorter.begin(), W_Sorter.end(), CDateSorterLess());
1938 CStatGraphDlg dlg;
1939 dlg.m_parAuthors = &m_arAuthorsFiltered;
1940 dlg.m_parDates = &m_arDatesFiltered;
1941 dlg.m_parFileChanges = &m_arFileChangesFiltered;
1942 dlg.m_path = m_orgPath;
1943 dlg.DoModal();
1944 // restore the previous sorting
1945 SortByColumn(m_nSortColumn, m_bAscending);
1946 OnTimer(LOGFILTER_TIMER);
1949 void CLogDlg::DoSizeV1(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(&m_LogList, delta, CW_TOPALIGN);
1958 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), -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 m_LogList.Invalidate();
1968 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1972 void CLogDlg::DoSizeV2(int delta)
1975 RemoveAnchor(IDC_LOGLIST);
1976 RemoveAnchor(IDC_SPLITTERTOP);
1977 RemoveAnchor(IDC_MSGVIEW);
1978 RemoveAnchor(IDC_SPLITTERBOTTOM);
1979 RemoveAnchor(IDC_LOGMSG);
1980 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), delta, CW_TOPALIGN);
1981 CSplitterControl::ChangeHeight(&m_ChangedFileListCtrl, -delta, CW_BOTTOMALIGN);
1982 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1983 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1984 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1985 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1986 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1987 ArrangeLayout();
1988 AdjustMinSize();
1989 SetSplitterRange();
1990 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1991 m_ChangedFileListCtrl.Invalidate();
1995 void CLogDlg::AdjustMinSize()
1997 // adjust the minimum size of the dialog to prevent the resizing from
1998 // moving the list control too far down.
1999 CRect rcChgListView;
2000 m_ChangedFileListCtrl.GetClientRect(rcChgListView);
2001 CRect rcLogList;
2002 m_LogList.GetClientRect(rcLogList);
2004 SetMinTrackSize(CSize(m_DlgOrigRect.Width(),
2005 m_DlgOrigRect.Height()-m_ChgOrigRect.Height()-m_LogListOrigRect.Height()-m_MsgViewOrigRect.Height()
2006 +rcChgListView.Height()+rcLogList.Height()+60));
2009 LRESULT CLogDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
2011 switch (message) {
2012 case WM_NOTIFY:
2013 if (wParam == IDC_SPLITTERTOP)
2015 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
2016 DoSizeV1(pHdr->delta);
2018 else if (wParam == IDC_SPLITTERBOTTOM)
2020 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
2021 DoSizeV2(pHdr->delta);
2023 break;
2026 return CResizableDialog::DefWindowProc(message, wParam, lParam);
2029 void CLogDlg::SetSplitterRange()
2031 if ((m_LogList)&&(m_ChangedFileListCtrl))
2033 CRect rcTop;
2034 m_LogList.GetWindowRect(rcTop);
2035 ScreenToClient(rcTop);
2036 CRect rcMiddle;
2037 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(rcMiddle);
2038 ScreenToClient(rcMiddle);
2039 m_wndSplitter1.SetRange(rcTop.top+30, rcMiddle.bottom-20);
2040 CRect rcBottom;
2041 m_ChangedFileListCtrl.GetWindowRect(rcBottom);
2042 ScreenToClient(rcBottom);
2043 m_wndSplitter2.SetRange(rcMiddle.top+30, rcBottom.bottom-20);
2047 LRESULT CLogDlg::OnClickedInfoIcon(WPARAM /*wParam*/, LPARAM lParam)
2049 // FIXME: x64 version would get this function called with unexpected parameters.
2050 if (!lParam)
2051 return 0;
2053 RECT * rect = (LPRECT)lParam;
2054 CPoint point;
2055 CString temp;
2056 point = CPoint(rect->left, rect->bottom);
2057 #define LOGMENUFLAGS(x) (MF_STRING | MF_ENABLED | (m_LogList.m_SelectedFilters & x ? MF_CHECKED : MF_UNCHECKED))
2058 CMenu popup;
2059 if (popup.CreatePopupMenu())
2061 temp.LoadString(IDS_LOG_FILTER_SUBJECT);
2062 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_SUBJECT), LOGFILTER_SUBJECT, temp);
2064 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2065 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_MESSAGES), LOGFILTER_MESSAGES, temp);
2067 temp.LoadString(IDS_LOG_FILTER_PATHS);
2068 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_PATHS), LOGFILTER_PATHS, temp);
2070 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2071 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_AUTHORS), LOGFILTER_AUTHORS, temp);
2073 temp.LoadString(IDS_LOG_FILTER_REVS);
2074 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REVS), LOGFILTER_REVS, temp);
2076 if (m_LogList.m_bShowBugtraqColumn == TRUE) {
2077 temp.LoadString(IDS_LOG_FILTER_BUGIDS);
2078 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_BUGID), LOGFILTER_BUGID, temp);
2081 popup.AppendMenu(MF_SEPARATOR, NULL);
2083 temp.LoadString(IDS_LOG_FILTER_REGEX);
2084 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterWithRegex ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_REGEX, temp);
2086 m_tooltips.Pop();
2087 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2088 if (selection != 0)
2091 if (selection == LOGFILTER_REGEX)
2093 m_bFilterWithRegex = !m_bFilterWithRegex;
2094 CRegDWORD b = CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
2095 b = m_bFilterWithRegex;
2096 m_LogList.m_bFilterWithRegex = m_bFilterWithRegex;
2097 SetFilterCueText();
2098 CheckRegexpTooltip();
2100 else
2102 m_LogList.m_SelectedFilters ^= selection;
2103 SetFilterCueText();
2105 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2108 return 0L;
2111 LRESULT CLogDlg::OnClickedCancelFilter(WPARAM /*wParam*/, LPARAM /*lParam*/)
2114 KillTimer(LOGFILTER_TIMER);
2116 m_LogList.m_sFilterText.Empty();
2117 UpdateData(FALSE);
2118 theApp.DoWaitCursor(1);
2119 CStoreSelection storeselection(this);
2120 FillLogMessageCtrl(false);
2122 m_LogList.RemoveFilter();
2124 Refresh();
2126 CTime begin,end;
2127 m_LogList.GetTimeRange(begin,end);
2128 m_DateFrom.SetTime(&begin);
2129 m_DateTo.SetTime(&end);
2131 theApp.DoWaitCursor(-1);
2132 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2133 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2134 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2135 UpdateLogInfoLabel();
2137 return 0L;
2141 void CLogDlg::SetFilterCueText()
2143 CString temp(MAKEINTRESOURCE(IDS_LOG_FILTER_BY));
2144 temp += _T(" ");
2146 if (m_LogList.m_SelectedFilters & LOGFILTER_SUBJECT)
2148 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_SUBJECT));
2151 if (m_LogList.m_SelectedFilters & LOGFILTER_MESSAGES)
2153 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2154 temp += _T(", ");
2155 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_MESSAGES));
2158 if (m_LogList.m_SelectedFilters & LOGFILTER_PATHS)
2160 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2161 temp += _T(", ");
2162 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_PATHS));
2165 if (m_LogList.m_SelectedFilters & LOGFILTER_AUTHORS)
2167 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2168 temp += _T(", ");
2169 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_AUTHORS));
2172 if (m_LogList.m_SelectedFilters & LOGFILTER_REVS)
2174 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2175 temp += _T(", ");
2176 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_REVS));
2179 if (m_LogList.m_SelectedFilters & LOGFILTER_BUGID)
2181 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2182 temp += _T(", ");
2183 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_BUGIDS));
2186 // to make the cue banner text appear more to the right of the edit control
2187 temp = _T(" ")+temp;
2188 m_cFilter.SetCueBanner(temp.TrimRight());
2191 bool CLogDlg::Validate(LPCTSTR string)
2193 if (!m_bFilterWithRegex)
2194 return true;
2195 tr1::wregex pat;
2196 return m_LogList.ValidateRegexp(string, pat, false);
2200 void CLogDlg::OnTimer(UINT_PTR nIDEvent)
2202 if (nIDEvent == LOGFTIME_TIMER)
2204 KillTimer(LOGFTIME_TIMER);
2205 m_limit = 0;
2206 m_LogList.Refresh(FALSE);
2207 FillLogMessageCtrl(false);
2210 if (nIDEvent == LOGFILTER_TIMER)
2212 KillTimer(LOGFILTER_TIMER);
2213 m_limit = 0;
2214 m_LogList.Refresh(FALSE);
2215 FillLogMessageCtrl(false);
2217 #if 0
2218 /* we will use git built-in grep to filter log */
2219 if (this->IsThreadRunning())
2221 // thread still running! So just restart the timer.
2222 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2223 return;
2225 CWnd * focusWnd = GetFocus();
2226 bool bSetFocusToFilterControl = ((focusWnd != GetDlgItem(IDC_DATEFROM))&&(focusWnd != GetDlgItem(IDC_DATETO))
2227 && (focusWnd != GetDlgItem(IDC_LOGLIST)));
2228 if (m_LogList.m_sFilterText.IsEmpty())
2230 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2231 // do not return here!
2232 // we also need to run the filter if the filter text is empty:
2233 // 1. to clear an existing filter
2234 // 2. to rebuild the m_arShownList after sorting
2236 theApp.DoWaitCursor(1);
2237 CStoreSelection storeselection(this);
2238 KillTimer(LOGFILTER_TIMER);
2239 FillLogMessageCtrl(false);
2241 // now start filter the log list
2242 m_LogList.StartFilter();
2244 if ( m_LogList.GetItemCount()==1 )
2246 m_LogList.SetSelectionMark(0);
2247 m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
2249 theApp.DoWaitCursor(-1);
2250 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2251 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2252 if (bSetFocusToFilterControl)
2253 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2254 UpdateLogInfoLabel();
2255 #endif
2256 } // if (nIDEvent == LOGFILTER_TIMER)
2257 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC))));
2258 __super::OnTimer(nIDEvent);
2261 void CLogDlg::OnDtnDatetimechangeDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2265 CTime _time;
2266 m_DateTo.GetTime(_time);
2268 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 23, 59, 59);
2269 if (time.GetTime() != m_LogList.m_To)
2271 m_LogList.m_To = (DWORD)time.GetTime();
2272 SetTimer(LOGFTIME_TIMER, 10, NULL);
2275 catch (...)
2277 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2280 *pResult = 0;
2283 void CLogDlg::OnDtnDatetimechangeDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2288 CTime _time;
2289 m_DateFrom.GetTime(_time);
2291 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 0, 0, 0);
2292 if (time.GetTime() != m_LogList.m_From)
2294 m_LogList.m_From = (DWORD)time.GetTime();
2295 SetTimer(LOGFTIME_TIMER, 10, NULL);
2298 catch (...)
2300 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2303 *pResult = 0;
2308 CTGitPathList CLogDlg::GetChangedPathsFromSelectedRevisions(bool /*bRelativePaths*/ /* = false */, bool /*bUseFilter*/ /* = true */)
2310 CTGitPathList pathList;
2311 #if 0
2313 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2315 m_sRepositoryRoot = GetRepositoryRoot(m_path);
2317 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2318 return pathList;
2320 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2321 if (pos != NULL)
2323 while (pos)
2325 int nextpos = m_LogList.GetNextSelectedItem(pos);
2326 if (nextpos >= m_arShownList.GetCount())
2327 continue;
2328 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(nextpos));
2329 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2330 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
2332 LogChangedPath * cpath = cpatharray->SafeGetAt(cpPathIndex);
2333 if (cpath == NULL)
2334 continue;
2335 CTGitPath path;
2336 if (!bRelativePaths)
2337 path.SetFromGit(m_sRepositoryRoot);
2338 path.AppendPathString(cpath->sPath);
2339 if ((!bUseFilter)||
2340 ((m_cHidePaths.GetState() & 0x0003)!=BST_CHECKED)||
2341 (cpath->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0))
2342 pathList.AddPath(path);
2347 pathList.RemoveDuplicates();
2348 #endif
2349 return pathList;
2352 void CLogDlg::SortByColumn(int /*nSortColumn*/, bool /*bAscending*/)
2354 #if 0
2355 switch(nSortColumn)
2357 case 0: // Revision
2359 if(bAscending)
2360 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscRevSort());
2361 else
2362 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescRevSort());
2364 break;
2365 case 1: // action
2367 if(bAscending)
2368 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscActionSort());
2369 else
2370 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescActionSort());
2372 break;
2373 case 2: // Author
2375 if(bAscending)
2376 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscAuthorSort());
2377 else
2378 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescAuthorSort());
2380 break;
2381 case 3: // Date
2383 if(bAscending)
2384 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscDateSort());
2385 else
2386 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescDateSort());
2388 break;
2389 case 4: // Message or bug id
2390 if (m_bShowBugtraqColumn)
2392 if(bAscending)
2393 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscBugIDSort());
2394 else
2395 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescBugIDSort());
2396 break;
2398 // fall through here
2399 case 5: // Message
2401 if(bAscending)
2402 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscMessageSort());
2403 else
2404 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescMessageSort());
2406 break;
2407 default:
2408 ATLASSERT(0);
2409 break;
2411 #endif
2414 void CLogDlg::OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult)
2416 if (this->IsThreadRunning())
2417 return; //no sorting while the arrays are filled
2418 #if 0
2419 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2420 const int nColumn = pNMLV->iSubItem;
2421 m_bAscending = nColumn == m_nSortColumn ? !m_bAscending : TRUE;
2422 m_nSortColumn = nColumn;
2423 SortByColumn(m_nSortColumn, m_bAscending);
2424 SetSortArrow(&m_LogList, m_nSortColumn, !!m_bAscending);
2425 SortShownListArray();
2426 m_LogList.Invalidate();
2427 UpdateLogInfoLabel();
2428 #else
2429 UNREFERENCED_PARAMETER(pNMHDR);
2430 #endif
2431 *pResult = 0;
2434 void CLogDlg::SortShownListArray()
2436 // make sure the shown list still matches the filter after sorting.
2437 OnTimer(LOGFILTER_TIMER);
2438 // clear the selection states
2439 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2440 while (pos)
2442 m_LogList.SetItemState(m_LogList.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
2444 m_LogList.SetSelectionMark(-1);
2447 void CLogDlg::SetSortArrow(CListCtrl * control, int nColumn, bool bAscending)
2449 if (control == NULL)
2450 return;
2451 // set the sort arrow
2452 CHeaderCtrl * pHeader = control->GetHeaderCtrl();
2453 HDITEM HeaderItem = {0};
2454 HeaderItem.mask = HDI_FORMAT;
2455 for (int i=0; i<pHeader->GetItemCount(); ++i)
2457 pHeader->GetItem(i, &HeaderItem);
2458 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
2459 pHeader->SetItem(i, &HeaderItem);
2461 if (nColumn >= 0)
2463 pHeader->GetItem(nColumn, &HeaderItem);
2464 HeaderItem.fmt |= (bAscending ? HDF_SORTUP : HDF_SORTDOWN);
2465 pHeader->SetItem(nColumn, &HeaderItem);
2468 void CLogDlg::OnLvnColumnclickChangedFileList(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
2470 #if 0
2471 if (this->IsThreadRunning())
2472 return; //no sorting while the arrays are filled
2473 if (m_currentChangedArray == NULL)
2474 return;
2475 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2476 const int nColumn = pNMLV->iSubItem;
2477 m_bAscendingPathList = nColumn == m_nSortColumnPathList ? !m_bAscendingPathList : TRUE;
2478 m_nSortColumnPathList = nColumn;
2479 // qsort(m_currentChangedArray->GetData(), m_currentChangedArray->GetSize(), sizeof(LogChangedPath*), (GENERICCOMPAREFN)SortCompare);
2481 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
2482 m_ChangedFileListCtrl.Invalidate();
2483 *pResult = 0;
2484 #endif
2487 int CLogDlg::m_nSortColumnPathList = 0;
2488 bool CLogDlg::m_bAscendingPathList = false;
2490 int CLogDlg::SortCompare(const void * /*pElem1*/, const void * /*pElem2*/)
2492 #if 0
2493 LogChangedPath * cpath1 = *((LogChangedPath**)pElem1);
2494 LogChangedPath * cpath2 = *((LogChangedPath**)pElem2);
2496 if (m_bAscendingPathList)
2497 std::swap (cpath1, cpath2);
2499 int cmp = 0;
2500 switch (m_nSortColumnPathList)
2502 case 0: // action
2503 cmp = cpath2->GetAction().Compare(cpath1->GetAction());
2504 if (cmp)
2505 return cmp;
2506 // fall through
2507 case 1: // path
2508 cmp = cpath2->sPath.CompareNoCase(cpath1->sPath);
2509 if (cmp)
2510 return cmp;
2511 // fall through
2512 case 2: // copy from path
2513 cmp = cpath2->sCopyFromPath.Compare(cpath1->sCopyFromPath);
2514 if (cmp)
2515 return cmp;
2516 // fall through
2517 case 3: // copy from revision
2518 return cpath2->lCopyFromRev > cpath1->lCopyFromRev;
2520 #endif
2521 return 0;
2524 void CLogDlg::OnBnClickedHidepaths()
2526 FillLogMessageCtrl();
2527 m_ChangedFileListCtrl.Invalidate();
2532 void CLogDlg::OnBnClickedCheckStoponcopy()
2534 #if 0
2535 if (!GetDlgItem(IDC_GETALL)->IsWindowEnabled())
2536 return;
2538 // ignore old fetch limits when switching
2539 // between copy-following and stop-on-copy
2540 // (otherwise stop-on-copy will limit what
2541 // we see immediately after switching to
2542 // copy-following)
2544 m_endrev = 0;
2546 // now, restart the query
2547 #endif
2548 Refresh();
2552 void CLogDlg::UpdateLogInfoLabel()
2555 CGitHash rev1 ;
2556 CGitHash rev2 ;
2557 long selectedrevs = 0;
2558 int count =m_LogList.m_arShownList.GetCount();
2559 int start = 0;
2560 if (count)
2562 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(0)))->m_CommitHash;
2563 if(this->m_LogList.m_bShowWC && rev1.IsEmpty()&&(count>1))
2564 start = 1;
2565 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(start)))->m_CommitHash;
2566 //pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_arShownList.GetCount()-1));
2567 rev2 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(count-1)))->m_CommitHash;
2568 selectedrevs = m_LogList.GetSelectedCount();
2570 CString sTemp;
2571 sTemp.Format(IDS_PROC_LOG_STATS,
2572 count - start,
2573 rev2.ToString().Left(g_Git.GetShortHASHLength()), rev1.ToString().Left(g_Git.GetShortHASHLength()), selectedrevs);
2575 if(selectedrevs == 1)
2577 CString str=m_ChangedFileListCtrl.GetStatisticsString(true);
2578 str.Replace(_T('\n'), _T(' '));
2579 sTemp += _T("\r\n") + str;
2581 m_sLogInfo = sTemp;
2583 UpdateData(FALSE);
2586 #if 0
2587 void CLogDlg::ShowContextMenuForChangedpaths(CWnd* /*pWnd*/, CPoint point)
2590 int selIndex = m_ChangedFileListCtrl.GetSelectionMark();
2591 if ((point.x == -1) && (point.y == -1))
2593 CRect rect;
2594 m_ChangedFileListCtrl.GetItemRect(selIndex, &rect, LVIR_LABEL);
2595 m_ChangedFileListCtrl.ClientToScreen(&rect);
2596 point = rect.CenterPoint();
2598 if (selIndex < 0)
2599 return;
2600 int s = m_LogList.GetSelectionMark();
2601 if (s < 0)
2602 return;
2603 std::vector<CString> changedpaths;
2604 std::vector<LogChangedPath*> changedlogpaths;
2605 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2606 if (pos == NULL)
2607 return; // nothing is selected, get out of here
2609 bool bOneRev = true;
2610 int sel=m_LogList.GetNextSelectedItem(pos);
2611 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(sel));
2612 GitRev * rev1 = pLogEntry;
2613 GitRev * rev2 = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(sel+1));
2614 #if 0
2615 bool bOneRev = true;
2616 if (pos)
2618 while (pos)
2620 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2621 if (pLogEntry)
2623 rev1 = max(rev1,(git_revnum_t)pLogEntry->Rev);
2624 rev2 = min(rev2,(git_revnum_t)pLogEntry->Rev);
2625 bOneRev = false;
2628 if (!bOneRev)
2629 rev2--;
2630 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
2631 while (pos)
2633 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
2634 changedpaths.push_back(m_currentChangedPathList[nItem].GetGitPathString());
2637 else
2639 // only one revision is selected in the log dialog top pane
2640 // but multiple items could be selected in the changed items list
2641 rev2 = rev1-1;
2643 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
2644 while (pos)
2646 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
2647 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(nItem);
2649 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
2651 if ((changedlogpath)&&(!changedlogpath->sCopyFromPath.IsEmpty()))
2652 rev2 = changedlogpath->lCopyFromRev;
2653 else
2655 // if the path was modified but the parent path was 'added with history'
2656 // then we have to use the copy from revision of the parent path
2657 CTGitPath cpath = CTGitPath(changedlogpath->sPath);
2658 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
2660 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->SafeGetAt(flist)->sPath);
2661 if (p.IsAncestorOf(cpath))
2663 if (!pLogEntry->pArChangedPaths->SafeGetAt(flist)->sCopyFromPath.IsEmpty())
2664 rev2 = pLogEntry->pArChangedPaths->SafeGetAt(flist)->lCopyFromRev;
2669 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
2671 // some items are hidden! So find out which item the user really clicked on
2672 INT_PTR selRealIndex = -1;
2673 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
2675 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2676 selRealIndex++;
2677 if (selRealIndex == nItem)
2679 selIndex = hiddenindex;
2680 changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
2681 break;
2685 if (changedlogpath)
2687 changedpaths.push_back(changedlogpath->sPath);
2688 changedlogpaths.push_back(changedlogpath);
2692 #endif
2693 //entry is selected, now show the popup menu
2694 CIconMenu popup;
2695 if (popup.CreatePopupMenu())
2697 bool bEntryAdded = false;
2698 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
2700 // if ((!bOneRev)||(IsDiffPossible(changedlogpaths[0], rev1)))
2702 popup.AppendMenuIcon(CGitLogList::ID_DIFF, IDS_LOG_POPUP_DIFF, IDI_DIFF);
2703 popup.AppendMenuIcon(CGitLogList::ID_BLAMEDIFF, IDS_LOG_POPUP_BLAMEDIFF, IDI_BLAME);
2704 popup.SetDefaultItem(CGitLogList::ID_DIFF, FALSE);
2705 popup.AppendMenuIcon(CGitLogList::ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
2706 bEntryAdded = true;
2708 // if (rev2 == rev1-1)
2710 if (bEntryAdded)
2711 popup.AppendMenu(MF_SEPARATOR, NULL);
2712 popup.AppendMenuIcon(CGitLogList::ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
2713 popup.AppendMenuIcon(CGitLogList::ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
2714 popup.AppendMenuIcon(CGitLogList::ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
2715 popup.AppendMenu(MF_SEPARATOR, NULL);
2716 if (m_hasWC)
2717 popup.AppendMenuIcon(CGitLogList::ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2718 popup.AppendMenuIcon(CGitLogList::ID_POPPROPS, IDS_REPOBROWSE_SHOWPROP, IDI_PROPERTIES); // "Show Properties"
2719 popup.AppendMenuIcon(CGitLogList::ID_LOG, IDS_MENULOG, IDI_LOG); // "Show Log"
2720 popup.AppendMenuIcon(CGitLogList::ID_GETMERGELOGS, IDS_LOG_POPUP_GETMERGELOGS, IDI_LOG); // "Show merge log"
2721 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
2722 bEntryAdded = true;
2723 if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2725 popup.AppendMenu(MF_SEPARATOR, NULL);
2726 popup.AppendMenuIcon(CGitLogList::ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2728 if (popup.GetDefaultItem(0,FALSE)==-1)
2729 popup.SetDefaultItem(CGitLogList::ID_OPEN, FALSE);
2732 else if (changedlogpaths.size())
2734 // more than one entry is selected
2735 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE);
2736 bEntryAdded = true;
2739 if (!bEntryAdded)
2740 return;
2741 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2742 bool bOpenWith = false;
2743 bool bMergeLog = false;
2744 m_bCancelled = false;
2746 switch (cmd)
2748 case CGitLogList::ID_DIFF:
2750 DoDiffFromLog(selIndex, rev1, rev2, false, false);
2752 break;
2753 #if 0
2754 case ID_BLAMEDIFF:
2756 DoDiffFromLog(selIndex, rev1, rev2, true, false);
2758 break;
2759 case ID_GNUDIFF1:
2761 DoDiffFromLog(selIndex, rev1, rev2, false, true);
2763 break;
2764 case ID_REVERTREV:
2766 SetPromptApp(&theApp);
2767 theApp.DoWaitCursor(1);
2768 CString sUrl;
2769 if (Git::PathIsURL(m_path))
2771 sUrl = m_path.GetGitPathString();
2773 else
2775 sUrl = GetURLFromPath(m_path);
2776 if (sUrl.IsEmpty())
2778 theApp.DoWaitCursor(-1);
2779 CString temp;
2780 temp.Format(IDS_ERR_NOURLOFFILE, m_path.GetWinPath());
2781 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2782 EnableOKButton();
2783 theApp.DoWaitCursor(-1);
2784 break; //exit
2787 // find the working copy path of the selected item from the URL
2788 m_bCancelled = false;
2789 CString sUrlRoot = GetRepositoryRoot(CTGitPath(sUrl));
2791 CString fileURL = changedpaths[0];
2792 fileURL = sUrlRoot + fileURL.Trim();
2793 // firstfile = (e.g.) http://mydomain.com/repos/trunk/folder/file1
2794 // sUrl = http://mydomain.com/repos/trunk/folder
2795 CString sUnescapedUrl = CPathUtils::PathUnescape(sUrl);
2796 // find out until which char the urls are identical
2797 int i=0;
2798 while ((i<fileURL.GetLength())&&(i<sUnescapedUrl.GetLength())&&(fileURL[i]==sUnescapedUrl[i]))
2799 i++;
2800 int leftcount = m_path.GetWinPathString().GetLength()-(sUnescapedUrl.GetLength()-i);
2801 CString wcPath = m_path.GetWinPathString().Left(leftcount);
2802 wcPath += fileURL.Mid(i);
2803 wcPath.Replace('/', '\\');
2804 CGitProgressDlg dlg;
2805 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
2807 // a deleted path! Since the path isn't there anymore, merge
2808 // won't work. So just do a copy url->wc
2809 dlg.SetCommand(CGitProgressDlg::GitProgress_Copy);
2810 dlg.SetPathList(CTGitPathList(CTGitPath(fileURL)));
2811 dlg.SetUrl(wcPath);
2812 dlg.SetRevision(rev2);
2814 else
2816 if (!PathFileExists(wcPath))
2818 // seems the path got renamed
2819 // tell the user how to work around this.
2820 CMessageBox::Show(this->m_hWnd, IDS_LOG_REVERTREV_ERROR, IDS_APPNAME, MB_ICONERROR);
2821 EnableOKButton();
2822 theApp.DoWaitCursor(-1);
2823 break; //exit
2825 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
2826 dlg.SetPathList(CTGitPathList(CTGitPath(wcPath)));
2827 dlg.SetUrl(fileURL);
2828 dlg.SetSecondUrl(fileURL);
2829 GitRevRangeArray revarray;
2830 revarray.AddRevRange(rev1, rev2);
2831 dlg.SetRevisionRanges(revarray);
2833 CString msg;
2834 msg.Format(IDS_LOG_REVERT_CONFIRM, (LPCTSTR)wcPath);
2835 if (CMessageBox::Show(this->m_hWnd, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
2837 dlg.DoModal();
2839 theApp.DoWaitCursor(-1);
2841 break;
2842 case ID_POPPROPS:
2844 DialogEnableWindow(IDOK, FALSE);
2845 SetPromptApp(&theApp);
2846 theApp.DoWaitCursor(1);
2847 CString filepath;
2848 if (Git::PathIsURL(m_path))
2850 filepath = m_path.GetGitPathString();
2852 else
2854 filepath = GetURLFromPath(m_path);
2855 if (filepath.IsEmpty())
2857 theApp.DoWaitCursor(-1);
2858 CString temp;
2859 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2860 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2861 TRACE(_T("could not retrieve the URL of the file!\n"));
2862 EnableOKButton();
2863 break;
2866 filepath = GetRepositoryRoot(CTGitPath(filepath));
2867 filepath += changedpaths[0];
2868 CPropDlg dlg;
2869 dlg.m_rev = rev1;
2870 dlg.m_Path = CTGitPath(filepath);
2871 dlg.DoModal();
2872 EnableOKButton();
2873 theApp.DoWaitCursor(-1);
2875 break;
2876 case ID_SAVEAS:
2878 DialogEnableWindow(IDOK, FALSE);
2879 SetPromptApp(&theApp);
2880 theApp.DoWaitCursor(1);
2881 CString filepath;
2882 if (Git::PathIsURL(m_path))
2884 filepath = m_path.GetGitPathString();
2886 else
2888 filepath = GetURLFromPath(m_path);
2889 if (filepath.IsEmpty())
2891 theApp.DoWaitCursor(-1);
2892 CString temp;
2893 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2894 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2895 TRACE(_T("could not retrieve the URL of the file!\n"));
2896 EnableOKButton();
2897 break;
2900 m_bCancelled = false;
2901 CString sRoot = GetRepositoryRoot(CTGitPath(filepath));
2902 // if more than one entry is selected, we save them
2903 // one by one into a folder the user has selected
2904 bool bTargetSelected = false;
2905 CTGitPath TargetPath;
2906 if (m_ChangedFileListCtrl.GetSelectedCount() > 1)
2908 CBrowseFolder browseFolder;
2909 browseFolder.SetInfo(CString(MAKEINTRESOURCE(IDS_LOG_SAVEFOLDERTOHINT)));
2910 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
2911 CString strSaveAsDirectory;
2912 if (browseFolder.Show(GetSafeHwnd(), strSaveAsDirectory) == CBrowseFolder::OK)
2914 TargetPath = CTGitPath(strSaveAsDirectory);
2915 bTargetSelected = true;
2918 else
2920 // Display the Open dialog box.
2921 CString revFilename;
2922 CString temp;
2923 temp = CPathUtils::GetFileNameFromPath(changedpaths[0]);
2924 int rfind = temp.ReverseFind('.');
2925 if (rfind > 0)
2926 revFilename.Format(_T("%s-%ld%s"), (LPCTSTR)temp.Left(rfind), rev1, (LPCTSTR)temp.Mid(rfind));
2927 else
2928 revFilename.Format(_T("%s-%ld"), (LPCTSTR)temp, rev1);
2929 bTargetSelected = CAppUtils::FileOpenSave(revFilename, NULL, IDS_LOG_POPUP_SAVE, IDS_COMMONFILEFILTER, false, m_hWnd);
2930 TargetPath.SetFromWin(revFilename);
2932 if (bTargetSelected)
2934 CProgressDlg progDlg;
2935 progDlg.SetTitle(IDS_APPNAME);
2936 progDlg.SetAnimation(IDR_DOWNLOAD);
2937 for (std::vector<LogChangedPath*>::iterator it = changedlogpaths.begin(); it!= changedlogpaths.end(); ++it)
2939 GitRev getrev = ((*it)->action == LOGACTIONS_DELETED) ? rev2 : rev1;
2941 CString sInfoLine;
2942 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)getrev.ToString());
2943 progDlg.SetLine(1, sInfoLine, true);
2944 SetAndClearProgressInfo(&progDlg);
2945 progDlg.ShowModeless(m_hWnd);
2947 CTGitPath tempfile = TargetPath;
2948 if (changedpaths.size() > 1)
2950 // if multiple items are selected, then the TargetPath
2951 // points to a folder and we have to append the filename
2952 // to save to to that folder.
2953 CString sName = (*it)->sPath;
2954 int slashpos = sName.ReverseFind('/');
2955 if (slashpos >= 0)
2956 sName = sName.Mid(slashpos);
2957 tempfile.AppendPathString(sName);
2958 // one problem here:
2959 // a user could have selected multiple items which
2960 // have the same filename but reside in different
2961 // directories, e.g.
2962 // /folder1/file1
2963 // /folder2/file1
2964 // in that case, the second 'file1' will overwrite
2965 // the already saved 'file1'.
2967 // we could maybe find the common root of all selected
2968 // items and then create sub folders to save those files
2969 // there.
2970 // But I think we should just leave it that way: to check
2971 // out multiple items at once, the better way is still to
2972 // use the export command from the top pane of the log dialog.
2974 filepath = sRoot + (*it)->sPath;
2975 if (!Cat(CTGitPath(filepath), getrev, getrev, tempfile))
2977 progDlg.Stop();
2978 SetAndClearProgressInfo((HWND)NULL);
2979 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
2980 EnableOKButton();
2981 theApp.DoWaitCursor(-1);
2982 break;
2985 progDlg.Stop();
2986 SetAndClearProgressInfo((HWND)NULL);
2988 EnableOKButton();
2989 theApp.DoWaitCursor(-1);
2991 break;
2992 case ID_OPENWITH:
2993 bOpenWith = true;
2994 case ID_OPEN:
2996 GitRev getrev = pLogEntry->pArChangedPaths->SafeGetAt(selIndex)->action == LOGACTIONS_DELETED ? rev2 : rev1;
2997 Open(bOpenWith,changedpaths[0],getrev);
2999 break;
3000 case ID_BLAME:
3002 CString filepath;
3003 if (Git::PathIsURL(m_path))
3005 filepath = m_path.GetGitPathString();
3007 else
3009 filepath = GetURLFromPath(m_path);
3010 if (filepath.IsEmpty())
3012 theApp.DoWaitCursor(-1);
3013 CString temp;
3014 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
3015 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3016 TRACE(_T("could not retrieve the URL of the file!\n"));
3017 EnableOKButton();
3018 break;
3021 filepath = GetRepositoryRoot(CTGitPath(filepath));
3022 filepath += changedpaths[0];
3023 CBlameDlg dlg;
3024 dlg.EndRev = rev1;
3025 if (dlg.DoModal() == IDOK)
3027 CBlame blame;
3028 CString tempfile;
3029 CString logfile;
3030 tempfile = blame.BlameToTempFile(CTGitPath(filepath), dlg.StartRev, dlg.EndRev, dlg.EndRev, logfile, _T(""), dlg.m_bIncludeMerge, TRUE, TRUE);
3031 if (!tempfile.IsEmpty())
3033 if (dlg.m_bTextView)
3035 //open the default text editor for the result file
3036 CAppUtils::StartTextViewer(tempfile);
3038 else
3040 CString sParams = _T("/path:\"") + filepath + _T("\" ");
3041 if(!CAppUtils::LaunchTortoiseBlame(tempfile, logfile, CPathUtils::GetFileNameFromPath(filepath),sParams))
3043 break;
3047 else
3049 CMessageBox::Show(this->m_hWnd, blame.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3053 break;
3054 case ID_GETMERGELOGS:
3055 bMergeLog = true;
3056 // fall through
3057 case ID_LOG:
3059 DialogEnableWindow(IDOK, FALSE);
3060 SetPromptApp(&theApp);
3061 theApp.DoWaitCursor(1);
3062 CString filepath;
3063 if (Git::PathIsURL(m_path))
3065 filepath = m_path.GetGitPathString();
3067 else
3069 filepath = GetURLFromPath(m_path);
3070 if (filepath.IsEmpty())
3072 theApp.DoWaitCursor(-1);
3073 CString temp;
3074 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
3075 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3076 TRACE(_T("could not retrieve the URL of the file!\n"));
3077 EnableOKButton();
3078 break;
3081 m_bCancelled = false;
3082 filepath = GetRepositoryRoot(CTGitPath(filepath));
3083 filepath += changedpaths[0];
3084 git_revnum_t logrev = rev1;
3085 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
3087 // if the item got deleted in this revision,
3088 // fetch the log from the previous revision where it
3089 // still existed.
3090 logrev--;
3092 CString sCmd;
3093 sCmd.Format(_T("\"%s\" /command:log /path:\"%s\" /startrev:%ld"), (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)filepath, logrev);
3094 if (bMergeLog)
3095 sCmd += _T(" /merge");
3096 CAppUtils::LaunchApplication(sCmd, NULL, false);
3097 EnableOKButton();
3098 theApp.DoWaitCursor(-1);
3100 break;
3101 case ID_VIEWPATHREV:
3103 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetSelectionMark()));
3104 GitRev rev = pLogEntry->Rev;
3105 CString relurl = changedpaths[0];
3106 CString url = m_ProjectProperties.sWebViewerPathRev;
3107 url.Replace(_T("%REVISION%"), rev.ToString());
3108 url.Replace(_T("%PATH%"), relurl);
3109 relurl = relurl.Mid(relurl.Find('/'));
3110 url.Replace(_T("%PATH1%"), relurl);
3111 if (!url.IsEmpty())
3112 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
3114 break;
3115 #endif
3116 default:
3117 break;
3118 } // switch (cmd)
3120 } // if (popup.CreatePopupMenu())
3122 #endif
3124 void CLogDlg::OnDtnDropdownDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3126 // the date control should not show the "today" button
3127 CMonthCalCtrl * pCtrl = m_DateFrom.GetMonthCalCtrl();
3128 if (pCtrl)
3129 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3130 *pResult = 0;
3133 void CLogDlg::OnDtnDropdownDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3135 // the date control should not show the "today" button
3136 CMonthCalCtrl * pCtrl = m_DateTo.GetMonthCalCtrl();
3137 if (pCtrl)
3138 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3139 *pResult = 0;
3142 void CLogDlg::OnSize(UINT nType, int cx, int cy)
3144 __super::OnSize(nType, cx, cy);
3145 //set range
3146 SetSplitterRange();
3149 void CLogDlg::OnRefresh()
3151 //if (GetDlgItem(IDC_GETALL)->IsWindowEnabled())
3153 m_limit = 0;
3154 this->m_LogProgress.SetPos(0);
3156 Refresh (false);
3162 void CLogDlg::OnFocusFilter()
3164 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3167 void CLogDlg::OnEditCopy()
3169 if (GetFocus() == &m_ChangedFileListCtrl)
3170 CopyChangedSelectionToClipBoard();
3171 else
3172 m_LogList.CopySelectionToClipBoard();
3175 CString CLogDlg::GetAbsoluteUrlFromRelativeUrl(const CString& url)
3177 // is the URL a relative one?
3178 if (url.Left(2).Compare(_T("^/")) == 0)
3180 // URL is relative to the repository root
3181 CString url1 = m_sRepositoryRoot + url.Mid(1);
3182 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3183 DWORD len = url.GetLength();
3184 if (UrlCanonicalize((LPCTSTR)url1, buf, &len, 0) == S_OK)
3185 return CString(buf, len);
3186 return url1;
3188 else if (url[0] == '/')
3190 // URL is relative to the server's hostname
3191 CString sHost;
3192 // find the server's hostname
3193 int schemepos = m_sRepositoryRoot.Find(_T("//"));
3194 if (schemepos >= 0)
3196 sHost = m_sRepositoryRoot.Left(m_sRepositoryRoot.Find('/', schemepos+3));
3197 CString url1 = sHost + url;
3198 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3199 DWORD len = url.GetLength();
3200 if (UrlCanonicalize((LPCTSTR)url, buf, &len, 0) == S_OK)
3201 return CString(buf, len);
3202 return url1;
3205 return url;
3209 void CLogDlg::OnEnChangeSearchedit()
3211 UpdateData();
3212 if (m_LogList.m_sFilterText.IsEmpty())
3214 CStoreSelection storeselection(this);
3215 // clear the filter, i.e. make all entries appear
3216 theApp.DoWaitCursor(1);
3217 KillTimer(LOGFILTER_TIMER);
3218 FillLogMessageCtrl(false);
3220 Refresh();
3221 //m_LogList.StartFilter();
3222 #if 0
3223 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3224 m_arShownList.RemoveAll();
3225 for (DWORD i=0; i<m_logEntries.size(); ++i)
3227 if (IsEntryInDateRange(i))
3228 m_arShownList.Add(m_logEntries[i]);
3230 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3231 m_LogList.DeleteAllItems();
3232 m_LogList.SetItemCountEx(ShownCountWithStopped());
3233 m_LogList.RedrawItems(0, ShownCountWithStopped());
3234 m_LogList.SetRedraw(false);
3235 ResizeAllListCtrlCols();
3236 m_LogList.SetRedraw(true);
3237 #endif
3238 theApp.DoWaitCursor(-1);
3239 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
3240 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
3241 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3242 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
3243 return;
3245 if (Validate(m_LogList.m_sFilterText))
3246 SetTimer(LOGFILTER_TIMER, 1000, NULL);
3247 else
3248 KillTimer(LOGFILTER_TIMER);
3252 void CLogDlg::OnBnClickedAllBranch()
3254 this->UpdateData();
3256 if(this->m_bAllBranch)
3257 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
3258 else
3259 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
3261 OnRefresh();
3263 FillLogMessageCtrl(false);
3266 void CLogDlg::OnBnClickedFollowRenames()
3268 this->UpdateData();
3270 if(m_bFollowRenames)
3272 m_LogList.m_ShowMask |= CGit::LOG_INFO_FOLLOW;
3273 if (m_bAllBranch)
3276 m_bAllBranch = FALSE;
3277 m_LogList.m_ShowMask &=~ CGit::LOG_INFO_ALL_BRANCH;
3281 else
3282 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_FOLLOW;
3284 DialogEnableWindow(IDC_LOG_ALLBRANCH, !m_bFollowRenames);
3285 DialogEnableWindow(IDC_SHOWWHOLEPROJECT, !m_bFollowRenames);
3287 OnRefresh();
3289 FillLogMessageCtrl(false);
3292 void CLogDlg::OnBnClickedBrowseRef()
3294 CString newRef = CBrowseRefsDlg::PickRef(false,m_LogList.GetStartRef());
3295 if(newRef.IsEmpty())
3296 return;
3298 SetStartRef(newRef);
3299 ((CButton*)GetDlgItem(IDC_LOG_ALLBRANCH))->SetCheck(0);
3301 OnBnClickedAllBranch();
3304 void CLogDlg::ShowStartRef()
3306 //Show ref name on top
3307 if(!::IsWindow(m_hWnd))
3308 return;
3309 if(m_bAllBranch)
3311 m_staticRef.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_LOG_ALLBRANCHES)));
3312 m_staticRef.Invalidate(TRUE);
3313 return;
3316 CString showStartRef = m_LogList.GetStartRef();
3317 if(showStartRef.IsEmpty())
3319 //Ref name is HEAD
3320 if (g_Git.Run(L"git symbolic-ref HEAD", &showStartRef, NULL, CP_UTF8))
3321 showStartRef = CString(MAKEINTRESOURCE(IDS_PROC_LOG_NOBRANCH));
3322 showStartRef.Trim(L"\r\n\t ");
3326 if(wcsncmp(showStartRef,L"refs/",5) == 0)
3327 showStartRef = showStartRef.Mid(5);
3328 if(wcsncmp(showStartRef,L"heads/",6) == 0)
3329 showStartRef = showStartRef.Mid(6);
3331 m_staticRef.SetWindowText(showStartRef);
3332 m_staticRef.Invalidate(TRUE);
3335 void CLogDlg::SetStartRef(const CString& StartRef)
3337 m_LogList.SetStartRef(StartRef);
3339 if (m_hightlightRevision.IsEmpty())
3341 m_hightlightRevision = g_Git.GetHash(StartRef);
3342 m_LogList.m_lastSelectedHash = m_hightlightRevision;
3345 ShowStartRef();
3349 void CLogDlg::OnBnClickedFirstParent()
3351 this->UpdateData();
3353 if(this->m_bFirstParent)
3354 m_LogList.m_ShowMask|=CGit::LOG_INFO_FIRST_PARENT;
3355 else
3356 m_LogList.m_ShowMask&=~CGit::LOG_INFO_FIRST_PARENT;
3358 OnRefresh();
3360 FillLogMessageCtrl(false);
3364 void CLogDlg::OnBnClickShowWholeProject()
3366 this->UpdateData();
3368 if(this->m_bWholeProject)
3370 m_LogList.m_Path.Reset();
3371 SetDlgTitle();
3372 DialogEnableWindow(IDC_LOG_FOLLOWRENAMES, FALSE);
3374 else
3376 m_LogList.m_Path=m_path;
3377 DialogEnableWindow(IDC_LOG_FOLLOWRENAMES, !(m_path.IsEmpty() || m_path.IsDirectory()));
3380 SetDlgTitle();
3382 OnRefresh();
3384 FillLogMessageCtrl(false);
3388 LRESULT CLogDlg::OnRefLogChanged(WPARAM wParam, LPARAM lParam)
3390 UNREFERENCED_PARAMETER(wParam);
3391 UNREFERENCED_PARAMETER(lParam);
3392 ShowStartRef();
3393 return 0;
3396 LRESULT CLogDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
3398 m_pTaskbarList.Release();
3399 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
3400 return 0;