Navigate selection history via log jump up/down button
[TortoiseGit.git] / src / TortoiseProc / LogDlg.cpp
blob247689abb35d872da9a484cfeff9af7c20b41737
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2014 - 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 "StatGraphDlg.h"
24 #include "LogDlg.h"
25 #include "MessageBox.h"
26 #include "registry.h"
27 #include "AppUtils.h"
28 #include "PathUtils.h"
29 #include "StringUtils.h"
30 #include "UnicodeUtils.h"
31 #include "TempFile.h"
32 #include "IconMenu.h"
33 #include "BrowseRefsDlg.h"
34 #include "SmartHandle.h"
35 #include "LogOrdering.h"
36 #include <MMSystem.h>
38 #define WM_TGIT_REFRESH_SELECTION (WM_APP + 1)
40 IMPLEMENT_DYNAMIC(CLogDlg, CResizableStandAloneDialog)
41 CLogDlg::CLogDlg(CWnd* pParent /*=NULL*/)
42 : CResizableStandAloneDialog(CLogDlg::IDD, pParent)
43 , m_wParam(0)
44 , m_currentChangedArray(NULL)
45 , m_nSortColumn(0)
46 , m_bFollowRenames(false)
47 , m_bSelect(false)
48 , m_bSelectionMustBeSingle(true)
49 , m_bShowTags(true)
50 , m_bShowLocalBranches(true)
51 , m_bShowRemoteBranches(true)
52 , m_bNoMerges(false)
53 , m_iHidePaths(0)
54 , m_bWalkBehavior(FALSE)
55 , m_bFirstParent(false)
56 , m_bWholeProject(FALSE)
57 , m_iCompressedGraph(0)
59 , m_bSelectionMustBeContinuous(false)
61 , m_sLogInfo(_T(""))
63 , m_bCancelled(FALSE)
64 , m_pNotifyWindow(NULL)
66 , m_bAscending(FALSE)
68 , m_limit(0)
69 , m_hAccel(NULL)
71 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
73 CString str;
74 str=g_Git.m_CurrentDir;
75 str.Replace(_T(":"),_T("_"));
76 str=CString(_T("Software\\TortoiseGit\\LogDialog\\AllBranch\\"))+str;
78 m_regbAllBranch=CRegDWORD(str,FALSE);
80 m_bAllBranch=m_regbAllBranch;
82 str = g_Git.m_CurrentDir;
83 str.Replace(_T(":"),_T("_"));
84 m_regShowWholeProject = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ShowWholeProject\\") + str, FALSE);
85 m_bWholeProject = m_regShowWholeProject;
86 m_regbShowTags = CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\ShowTags\\") + str, TRUE);
87 m_bShowTags = !!m_regbShowTags;
88 m_regbShowLocalBranches = CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\ShowLocalBranches\\") + str, TRUE);
89 m_bShowLocalBranches = !!m_regbShowLocalBranches;
90 m_regbShowRemoteBranches = CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\ShowRemoteBranches\\") + str, TRUE);
91 m_bShowRemoteBranches = !!m_regbShowRemoteBranches;
93 m_bShowUnversioned = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
95 m_bShowGravatar = !!CRegDWORD(_T("Software\\TortoiseGit\\EnableGravatar"), FALSE);
96 m_regbShowGravatar = CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\ShowGravatar\\") + str, m_bShowGravatar);
97 m_bShowGravatar = !!m_regbShowGravatar;
100 CLogDlg::~CLogDlg()
103 m_regbAllBranch = m_bAllBranch;
104 m_regbShowTags = m_bShowTags;
105 m_regbShowLocalBranches = m_bShowLocalBranches;
106 m_regbShowRemoteBranches = m_bShowRemoteBranches;
107 m_regbShowGravatar = m_bShowGravatar;
109 m_CurrentFilteredChangedArray.RemoveAll();
113 void CLogDlg::DoDataExchange(CDataExchange* pDX)
115 CResizableStandAloneDialog::DoDataExchange(pDX);
116 DDX_Control(pDX, IDC_LOGLIST, m_LogList);
117 DDX_Control(pDX, IDC_LOGMSG, m_ChangedFileListCtrl);
118 DDX_Control(pDX, IDC_PROGRESS, m_LogProgress);
119 DDX_Control(pDX, IDC_SPLITTERTOP, m_wndSplitter1);
120 DDX_Control(pDX, IDC_SPLITTERBOTTOM, m_wndSplitter2);
121 DDX_Text(pDX, IDC_SEARCHEDIT, m_LogList.m_sFilterText);
122 DDX_Control(pDX, IDC_DATEFROM, m_DateFrom);
123 DDX_Control(pDX, IDC_DATETO, m_DateTo);
124 DDX_Control(pDX, IDC_LOG_JUMPTYPE, m_JumpType);
125 DDX_Control(pDX, IDC_LOG_JUMPUP, m_JumpUp);
126 DDX_Control(pDX, IDC_LOG_JUMPDOWN, m_JumpDown);
127 DDX_Text(pDX, IDC_LOGINFO, m_sLogInfo);
128 DDX_Check(pDX, IDC_LOG_ALLBRANCH,m_bAllBranch);
129 DDX_Check(pDX, IDC_SHOWWHOLEPROJECT,m_bWholeProject);
130 DDX_Check(pDX, IDC_WALKBEHAVIOUR, m_bWalkBehavior);
131 DDX_Control(pDX, IDC_SEARCHEDIT, m_cFilter);
132 DDX_Control(pDX, IDC_STATIC_REF, m_staticRef);
133 DDX_Control(pDX, IDC_PIC_AUTHOR, m_gravatar);
136 BEGIN_MESSAGE_MAP(CLogDlg, CResizableStandAloneDialog)
137 ON_WM_CONTEXTMENU()
138 ON_WM_SETCURSOR()
139 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOGLIST, OnLvnItemchangedLoglist)
140 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOGMSG, OnLvnItemchangedLogmsg)
141 ON_NOTIFY(EN_LINK, IDC_MSGVIEW, OnEnLinkMsgview)
142 ON_BN_CLICKED(IDC_STATBUTTON, OnBnClickedStatbutton)
144 ON_MESSAGE(WM_TGIT_REFRESH_SELECTION, OnRefreshSelection)
145 ON_MESSAGE(WM_FILTEREDIT_INFOCLICKED, OnClickedInfoIcon)
146 ON_MESSAGE(WM_FILTEREDIT_CANCELCLICKED, OnClickedCancelFilter)
148 ON_MESSAGE(MSG_LOAD_PERCENTAGE,OnLogListLoading)
150 ON_EN_CHANGE(IDC_SEARCHEDIT, OnEnChangeSearchedit)
151 ON_WM_TIMER()
152 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETO, OnDtnDatetimechangeDateto)
153 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATEFROM, OnDtnDatetimechangeDatefrom)
154 ON_CBN_SELCHANGE(IDC_LOG_JUMPTYPE, &CLogDlg::OnCbnSelchangeJumpType)
155 ON_COMMAND(IDC_LOG_JUMPUP, &CLogDlg::OnBnClickedJumpUp)
156 ON_COMMAND(IDC_LOG_JUMPDOWN, &CLogDlg::OnBnClickedJumpDown)
157 ON_BN_CLICKED(IDC_WALKBEHAVIOUR, OnBnClickedWalkBehaviour)
158 ON_BN_CLICKED(IDC_VIEW, OnBnClickedView)
159 ON_BN_CLICKED(IDC_SHOWWHOLEPROJECT, OnBnClickShowWholeProject)
160 ON_NOTIFY(LVN_COLUMNCLICK,IDC_LOGLIST, OnLvnColumnclick)
161 ON_COMMAND(MSG_FETCHED_DIFF, OnBnClickedHidepaths)
162 ON_BN_CLICKED(IDC_LOG_ALLBRANCH, OnBnClickedAllBranch)
164 ON_NOTIFY(DTN_DROPDOWN, IDC_DATEFROM, &CLogDlg::OnDtnDropdownDatefrom)
165 ON_NOTIFY(DTN_DROPDOWN, IDC_DATETO, &CLogDlg::OnDtnDropdownDateto)
166 ON_WM_SIZE()
167 ON_BN_CLICKED(IDC_REFRESH, &CLogDlg::OnBnClickedRefresh)
168 ON_STN_CLICKED(IDC_STATIC_REF, &CLogDlg::OnBnClickedBrowseRef)
169 ON_COMMAND(ID_LOGDLG_REFRESH, &CLogDlg::OnBnClickedRefresh)
170 ON_COMMAND(ID_GO_BACKWARD, &CLogDlg::GoBack)
171 ON_COMMAND(ID_GO_FORWARD, &CLogDlg::GoForward)
172 ON_COMMAND(ID_LOGDLG_FIND, &CLogDlg::OnFind)
173 ON_COMMAND(ID_LOGDLG_FOCUSFILTER, &CLogDlg::OnFocusFilter)
174 ON_COMMAND(ID_EDIT_COPY, &CLogDlg::OnEditCopy)
175 ON_MESSAGE(MSG_REFLOG_CHANGED, OnRefLogChanged)
176 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
178 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED, &CLogDlg::OnFileListCtrlItemChanged)
179 ON_WM_MOVE()
180 ON_WM_MOVING()
181 ON_WM_SIZING()
182 END_MESSAGE_MAP()
184 enum JumpType
186 JumpType_AuthorEmail,
187 JumpType_CommitterEmail,
188 JumpType_MergePoint,
189 JumpType_Parent1,
190 JumpType_Parent2,
191 JumpType_Tag,
192 JumpType_TagFF,
193 JumpType_Branch,
194 JumpType_BranchFF,
195 JumpType_History,
198 void CLogDlg::SetParams(const CTGitPath& orgPath, const CTGitPath& path, CString hightlightRevision, CString range, int limit)
200 m_orgPath = orgPath;
201 m_path = path;
202 m_hightlightRevision = hightlightRevision;
204 if (!(range.IsEmpty() || range == _T("HEAD")))
205 m_bAllBranch = BST_UNCHECKED;
207 SetRange(range);
209 m_limit = limit;
210 if (::IsWindow(m_hWnd))
211 UpdateData(FALSE);
214 void CLogDlg::SetFilter(const CString& findstr, LONG findtype, bool findregex)
216 m_LogList.m_sFilterText = findstr;
217 if (findtype)
218 m_LogList.m_SelectedFilters = findtype;
219 m_LogList.m_bFilterWithRegex = m_bFilterWithRegex = findregex;
222 BOOL CLogDlg::OnInitDialog()
224 CString temp;
225 CResizableStandAloneDialog::OnInitDialog();
226 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
228 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
229 // do this, Explorer would be unable to send that message to our window if we
230 // were running elevated. It's OK to make the call all the time, since if we're
231 // not elevated, this is a no-op.
232 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
233 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
234 CAutoLibrary hUser = AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
235 if (hUser)
237 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
238 if (pfnChangeWindowMessageFilterEx)
240 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
243 m_pTaskbarList.Release();
244 if (FAILED(m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList)))
245 m_pTaskbarList = nullptr;
247 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_LOGDLG));
249 // use the state of the "stop on copy/rename" option from the last time
250 UpdateData(FALSE);
252 // set the font to use in the log message view, configured in the settings dialog
253 CAppUtils::CreateFontForLogs(m_logFont);
254 GetDlgItem(IDC_MSGVIEW)->SetFont(&m_logFont);
255 // automatically detect URLs in the log message and turn them into links
256 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_AUTOURLDETECT, TRUE, NULL);
257 // make the log message rich edit control send a message when the mouse pointer is over a link
258 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_SETEVENTMASK, NULL, ENM_LINK);
260 // "unrelated paths" should be in gray color
261 m_iHidePaths = 2;
263 // set up the columns
264 m_LogList.DeleteAllItems();
266 m_LogList.m_Path=m_path;
267 m_LogList.m_hasWC = m_LogList.m_bShowWC = !g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir);
268 m_LogList.InsertGitColumn();
270 if (m_bWholeProject)
271 m_LogList.m_Path.Reset();
273 m_ChangedFileListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS |GITSLC_COLADD|GITSLC_COLDEL, _T("LogDlg"), (GITSLC_POPALL ^ (GITSLC_POPIGNORE|GITSLC_POPRESTORE)), false, m_LogList.m_hasWC, GITSLC_COLEXT | GITSLC_COLSTATUS | GITSLC_COLADD| GITSLC_COLDEL);
275 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
277 SetDlgTitle();
279 m_tooltips.Create(this);
280 CheckRegexpTooltip();
282 SetSplitterRange();
284 // the filter control has a 'cancel' button (the red 'X'), we need to load its bitmap
285 m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);
286 m_cFilter.SetInfoIcon(IDI_LOGFILTER);
287 m_cFilter.SetValidator(this);
289 AdjustControlSize(IDC_LOG_ALLBRANCH);
290 AdjustControlSize(IDC_SHOWWHOLEPROJECT);
292 GetClientRect(m_DlgOrigRect);
293 m_LogList.GetClientRect(m_LogListOrigRect);
294 GetDlgItem(IDC_MSGVIEW)->GetClientRect(m_MsgViewOrigRect);
295 m_ChangedFileListCtrl.GetClientRect(m_ChgOrigRect);
297 m_DateFrom.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
298 m_DateTo.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
300 m_staticRef.SetURL(CString());
302 // resizable stuff
303 AddAnchor(IDC_STATIC_REF, TOP_LEFT);
304 //AddAnchor(IDC_BUTTON_BROWSE_REF, TOP_LEFT);
305 AddAnchor(IDC_FROMLABEL, TOP_LEFT);
306 AddAnchor(IDC_DATEFROM, TOP_LEFT);
307 AddAnchor(IDC_TOLABEL, TOP_LEFT);
308 AddAnchor(IDC_DATETO, TOP_LEFT);
310 SetFilterCueText();
311 AddAnchor(IDC_SEARCHEDIT, TOP_LEFT, TOP_RIGHT);
312 AddAnchor(IDC_LOG_JUMPTYPE, TOP_RIGHT);
313 AddAnchor(IDC_LOG_JUMPUP, TOP_RIGHT);
314 AddAnchor(IDC_LOG_JUMPDOWN, TOP_RIGHT);
316 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
317 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
318 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
319 AddAnchor(IDC_PIC_AUTHOR, TOP_RIGHT);
320 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
321 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
323 AddAnchor(IDC_LOGINFO, BOTTOM_LEFT, BOTTOM_RIGHT);
324 AddAnchor(IDC_WALKBEHAVIOUR, BOTTOM_LEFT);
325 AddAnchor(IDC_VIEW, BOTTOM_LEFT);
326 AddAnchor(IDC_LOG_ALLBRANCH,BOTTOM_LEFT);
327 AddAnchor(IDC_SHOWWHOLEPROJECT, BOTTOM_LEFT);
328 AddAnchor(IDC_REFRESH, BOTTOM_LEFT);
329 AddAnchor(IDC_STATBUTTON, BOTTOM_RIGHT);
330 AddAnchor(IDC_PROGRESS, BOTTOM_LEFT, BOTTOM_RIGHT);
331 AddAnchor(IDOK, BOTTOM_RIGHT);
332 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
333 AddAnchor(IDHELP, BOTTOM_RIGHT);
335 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_LOCAL_BRANCHES;
336 if (m_bAllBranch == BST_CHECKED)
337 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
338 else if (m_bAllBranch == BST_INDETERMINATE)
339 m_LogList.m_ShowMask |= CGit::LOG_INFO_LOCAL_BRANCHES;
340 else
341 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
343 HandleShowLabels(m_bShowTags, LOGLIST_SHOWTAGS);
344 HandleShowLabels(m_bShowLocalBranches, LOGLIST_SHOWLOCALBRANCHES);
345 HandleShowLabels(m_bShowRemoteBranches, LOGLIST_SHOWREMOTEBRANCHES);
347 // SetPromptParentWindow(m_hWnd);
348 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_AUTHOREMAIL)));
349 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_COMMITTEREMAIL)));
350 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_MERGEPOINT)));
351 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_PARENT1)));
352 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_PARENT2)));
353 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_TAG)));
354 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_TAG_FF)));
355 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_BRANCH)));
356 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_BRANCH_FF)));
357 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_SELECTION_HISTORY)));
358 m_JumpType.SetCurSel(0);
359 m_JumpUp.SetIcon((HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_JUMPUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR));
360 m_JumpDown.SetIcon((HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_JUMPDOWN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR));
362 if (hWndExplorer)
363 CenterWindow(CWnd::FromHandle(hWndExplorer));
364 EnableSaveRestore(_T("LogDlg"));
366 DWORD yPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
367 DWORD yPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
368 RECT rcDlg, rcLogList, rcChgMsg;
369 GetClientRect(&rcDlg);
370 m_LogList.GetWindowRect(&rcLogList);
371 ScreenToClient(&rcLogList);
372 m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg);
373 ScreenToClient(&rcChgMsg);
374 if (yPos1)
376 RECT rectSplitter;
377 m_wndSplitter1.GetWindowRect(&rectSplitter);
378 ScreenToClient(&rectSplitter);
379 int delta = yPos1 - rectSplitter.top;
381 if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30))
383 m_wndSplitter1.SetWindowPos(NULL, rectSplitter.left, yPos1, 0, 0, SWP_NOSIZE);
384 DoSizeV1(delta);
387 if (yPos2)
389 RECT rectSplitter;
390 m_wndSplitter2.GetWindowRect(&rectSplitter);
391 ScreenToClient(&rectSplitter);
392 int delta = yPos2 - rectSplitter.top;
394 if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30))
396 m_wndSplitter2.SetWindowPos(NULL, rectSplitter.left, yPos2, 0, 0, SWP_NOSIZE);
397 DoSizeV2(delta);
401 SetSplitterRange();
403 if (m_bSelect)
405 // the dialog is used to select revisions
406 // enable the OK button if appropriate
407 EnableOKButton();
409 else
411 // the dialog is used to just view log messages
412 // hide the OK button and set text on Cancel button to OK
413 GetDlgItemText(IDOK, temp);
414 SetDlgItemText(IDCANCEL, temp);
415 GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
418 // first start a thread to obtain the log messages without
419 // blocking the dialog
420 //m_tTo = 0;
421 //m_tFrom = (DWORD)-1;
423 // scroll to user selected or current revision
424 if (!m_hightlightRevision.IsEmpty() && m_hightlightRevision.GetLength() >= GIT_HASH_SIZE)
425 m_LogList.m_lastSelectedHash = m_hightlightRevision;
426 else
428 if (g_Git.GetHash(m_LogList.m_lastSelectedHash, _T("HEAD")))
429 MessageBox(g_Git.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR);
432 if (g_Git.GetConfigValueBool(_T("tgit.logshowpatch")))
433 TogglePatchView();
435 m_LogList.FetchLogAsync(this);
436 ShowGravatar();
437 m_gravatar.Init();
439 GetDlgItem(IDC_LOGLIST)->SetFocus();
441 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxRefHistoryItems"), 5));
442 CString reg;
443 reg.Format(_T("Software\\TortoiseGit\\History\\log-refs\\%s"), g_Git.m_CurrentDir);
444 reg.Replace(_T(':'),_T('_'));
445 m_History.Load(reg, _T("ref"));
447 ShowStartRef();
448 return FALSE;
451 LRESULT CLogDlg::OnLogListLoading(WPARAM wParam, LPARAM /*lParam*/)
453 int cur=(int)wParam;
455 if( cur == GITLOG_START )
457 CString temp;
458 temp.LoadString(IDS_PROGRESSWAIT);
460 this->m_LogList.ShowText(temp, true);
462 // We use a progress bar while getting the logs
463 m_LogProgress.SetRange32(0, 100);
464 m_LogProgress.SetPos(0);
465 if (m_pTaskbarList)
467 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
468 m_pTaskbarList->SetProgressValue(m_hWnd, 0, 100);
471 GetDlgItem(IDC_PROGRESS)->ShowWindow(TRUE);
473 DialogEnableWindow(IDC_WALKBEHAVIOUR, FALSE);
474 DialogEnableWindow(IDC_STATBUTTON, FALSE);
475 //DialogEnableWindow(IDC_REFRESH, FALSE);
476 DialogEnableWindow(IDC_VIEW, FALSE);
479 else if( cur == GITLOG_END)
481 if(this->m_LogList.HasText())
483 this->m_LogList.ClearText();
485 UpdateLogInfoLabel();
487 if (m_pTaskbarList)
488 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
490 DialogEnableWindow(IDC_SHOWWHOLEPROJECT, !m_bFollowRenames && !m_path.IsEmpty());
492 DialogEnableWindow(IDC_STATBUTTON, !(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC));
493 DialogEnableWindow(IDC_REFRESH, TRUE);
494 DialogEnableWindow(IDC_VIEW, TRUE);
495 DialogEnableWindow(IDC_WALKBEHAVIOUR, TRUE);
496 // PostMessage(WM_TIMER, LOGFILTER_TIMER);
497 GetDlgItem(IDC_PROGRESS)->ShowWindow(FALSE);
498 //CTime time=m_LogList.GetOldestTime();
499 CTime begin,end;
500 m_LogList.GetTimeRange(begin,end);
502 if(m_LogList.m_From == -1)
503 m_DateFrom.SetTime(&begin);
505 if(m_LogList.m_To == -1)
506 m_DateTo.SetTime(&end);
510 else
512 if(this->m_LogList.HasText())
514 this->m_LogList.ClearText();
515 this->m_LogList.Invalidate();
517 UpdateLogInfoLabel();
518 m_LogProgress.SetPos(cur);
519 if (m_pTaskbarList)
521 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
522 m_pTaskbarList->SetProgressValue(m_hWnd, cur, 100);
525 return 0;
527 void CLogDlg::SetDlgTitle()
529 if (m_sTitle.IsEmpty())
530 GetWindowText(m_sTitle);
532 if (m_LogList.m_Path.IsEmpty() || m_orgPath.GetWinPathString().IsEmpty())
534 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
536 else
537 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);
540 void CLogDlg::CheckRegexpTooltip()
542 CWnd *pWnd = GetDlgItem(IDC_SEARCHEDIT);
543 // Since tooltip describes regexp features, show it only if regexps are enabled.
544 if (m_bFilterWithRegex)
546 m_tooltips.AddTool(pWnd, IDS_LOG_FILTER_REGEX_TT);
548 else
549 m_tooltips.DelTool(pWnd);
552 void CLogDlg::EnableOKButton()
554 if (m_bSelect)
556 // the dialog is used to select revisions
557 if (m_bSelectionMustBeSingle)
559 // enable OK button if only a single revision is selected
560 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()==1));
562 else if (m_bSelectionMustBeContinuous)
563 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));
564 else
565 DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);
567 else
568 DialogEnableWindow(IDOK, TRUE);
571 bool LookLikeGitHash(const CString& msg, int &pos)
573 int c = 0;
574 for (; pos < msg.GetLength(); ++pos)
576 if (msg[pos] >= '0' && msg[pos] <= '9' || msg[pos] >= 'a' && msg[pos] <= 'f')
578 c++;
580 else
582 return c >= g_Git.GetShortHASHLength() && c <= GIT_HASH_SIZE * 2;
585 return c >= g_Git.GetShortHASHLength() && c <= GIT_HASH_SIZE * 2;
588 std::vector<CHARRANGE> FindGitHashPositions(const CString& msg, int offset)
590 std::vector<CHARRANGE> result;
591 offset = offset < 0 ? 0 : offset;
592 int old = offset;
593 while (offset < msg.GetLength())
595 old = offset;
596 TCHAR e = msg[offset];
597 if (e == '\n')
599 ++offset;
600 if (msg.Mid(offset, 11) == _T("git-svn-id:")
601 || msg.Mid(offset, 14) == _T("Signed-off-by:")
602 || msg.Mid(offset, 10) == _T("Change-Id:")
605 offset += 10;
606 while (offset < msg.GetLength())
608 if (msg[offset++] == '\n')
609 break;
611 continue;
614 else if (e >= 'A' && e <= 'Z' || e >= 'h' && e <= 'z')
618 e = msg[++offset];
619 } while (offset < msg.GetLength() && (e >= 'A' && e <= 'Z' || e >= 'a' && e <= 'z' || e >= '0' && e <= '9'));
621 else if (e >= 'a' && e <= 'g' || e >= '0' && e <= '9')
623 if (e == 'g')
625 ++old;
626 ++offset;
628 if (LookLikeGitHash(msg, offset))
630 TCHAR d = offset < msg.GetLength() ? msg[offset] : '\0';
631 if (!((d >= 'A' && d <= 'Z') || (d >= 'a' && d <= 'z') || (d >= '0' && d <= '9')))
633 CHARRANGE range = { old, offset };
634 result.push_back(range);
637 ++offset;
639 else
641 ++offset;
645 return result;
648 BOOL FindGitHash(const CString& msg, int offset, CWnd *pWnd)
650 std::vector<CHARRANGE> positions = FindGitHashPositions(msg, offset);
651 CAppUtils::SetCharFormat(pWnd, CFM_LINK, CFE_LINK, positions);
653 return positions.empty() ? FALSE : TRUE;
656 void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)
658 // we fill here the log message rich edit control,
659 // and also populate the changed files list control
660 // according to the selected revision(s).
662 CRichEditCtrl * pMsgView = (CRichEditCtrl*)GetDlgItem(IDC_MSGVIEW);
663 // empty the log message view
664 pMsgView->SetWindowText(_T(" "));
665 FillPatchView(true);
666 // empty the changed files list
667 m_ChangedFileListCtrl.SetRedraw(FALSE);
668 // InterlockedExchange(&m_bNoDispUpdates, TRUE);
669 m_currentChangedArray = NULL;
670 m_ChangedFileListCtrl.DeleteAllItems();
672 // if we're not here to really show a selected revision, just
673 // get out of here after clearing the views, which is what is intended
674 // if that flag is not set.
675 if (!bShow)
677 // force a redraw
678 m_ChangedFileListCtrl.Invalidate();
679 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
680 m_ChangedFileListCtrl.SetRedraw(TRUE);
681 m_gravatar.LoadGravatar();
682 return;
685 // depending on how many revisions are selected, we have to do different
686 // tasks.
687 int selCount = m_LogList.GetSelectedCount();
688 if (selCount == 0)
690 // if nothing is selected, we have nothing more to do
691 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
692 m_ChangedFileListCtrl.SetRedraw(TRUE);
693 m_gravatar.LoadGravatar();
694 return;
696 else if (selCount == 1)
698 // if one revision is selected, we have to fill the log message view
699 // with the corresponding log message, and also fill the changed files
700 // list fully.
701 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
702 int selIndex = m_LogList.GetNextSelectedItem(pos);
703 if (selIndex >= m_LogList.m_arShownList.GetCount())
705 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
706 m_ChangedFileListCtrl.SetRedraw(TRUE);
707 return;
709 Locker lock(m_LogList.m_critSec_AsyncDiff);
710 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
713 // set the log message text
714 pMsgView->SetWindowText(CString(MAKEINTRESOURCE(IDS_HASH)) + _T(": ") + pLogEntry->m_CommitHash.ToString() + _T("\r\n\r\n"));
715 // turn bug ID's into links if the bugtraq: properties have been set
716 // and we can find a match of those in the log message
718 pMsgView->SetSel(-1,-1);
719 CHARFORMAT2 format;
720 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
721 format.cbSize = sizeof(CHARFORMAT2);
722 format.dwMask = CFM_BOLD;
723 format.dwEffects = CFE_BOLD;
724 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
726 CString msg=_T("* ");
727 msg+=pLogEntry->GetSubject();
728 pMsgView->ReplaceSel(msg);
730 pMsgView->SetSel(-1,-1);
731 format.dwEffects = 0;
732 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
734 msg=_T("\n");
735 msg+=pLogEntry->GetBody();
737 if(!pLogEntry->m_Notes.IsEmpty())
739 msg+= _T("\n*") + CString(MAKEINTRESOURCE(IDS_NOTES)) + _T("* ");
740 msg+= pLogEntry->m_Notes;
741 msg+= _T("\n\n");
744 CString tagInfo = m_LogList.GetTagInfo(pLogEntry);
745 if(!tagInfo.IsEmpty())
746 tagInfo = _T("\n*") + CString(MAKEINTRESOURCE(IDS_PROC_LOG_TAGINFO)) + _T("*\n\n") + tagInfo;
747 msg += tagInfo;
749 pMsgView->ReplaceSel(msg);
751 CString text;
752 pMsgView->GetWindowText(text);
753 // the rich edit control doesn't count the CR char!
754 // to be exact: CRLF is treated as one char.
755 text.Remove('\r');
757 FindGitHash(text, text.Find('\n'), pMsgView);
758 m_LogList.m_ProjectProperties.FindBugID(text, pMsgView);
759 if (((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\StyleCommitMessages"), TRUE)) == TRUE)
760 CAppUtils::FormatTextInRichEditControl(pMsgView);
762 CHARRANGE range;
763 range.cpMin = 0;
764 range.cpMax = 0;
765 pMsgView->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
767 CString matchpath=this->m_path.GetGitPathString();
769 int count = pLogEntry->GetFiles(&m_LogList).GetCount();
770 for (int i = 0 ; i < count && (!matchpath.IsEmpty()); ++i)
772 if( m_bWholeProject )
773 break;
775 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action &= ~(CTGitPath::LOGACTIONS_HIDE|CTGitPath::LOGACTIONS_GRAY);
777 if(pLogEntry->GetFiles(&m_LogList)[i].GetGitPathString().Left(matchpath.GetLength()) != matchpath && pLogEntry->GetFiles(&m_LogList)[i].GetGitOldPathString().Left(matchpath.GetLength()) != matchpath)
779 if (m_iHidePaths == 1)
780 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;
781 else if (m_iHidePaths == 2)
782 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_GRAY;
786 m_ChangedFileListCtrl.UpdateWithGitPathList(pLogEntry->GetFiles(&m_LogList));
787 m_ChangedFileListCtrl.m_CurrentVersion=pLogEntry->m_CommitHash;
788 if (pLogEntry->m_CommitHash.IsEmpty() && m_bShowUnversioned)
790 m_ChangedFileListCtrl.UpdateUnRevFileList(pLogEntry->GetUnRevFiles());
791 m_ChangedFileListCtrl.Show(GITSLC_SHOWVERSIONED | GITSLC_SHOWUNVERSIONED);
793 else
794 m_ChangedFileListCtrl.Show(GITSLC_SHOWVERSIONED);
796 m_ChangedFileListCtrl.SetBusyString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES)));
798 if(!pLogEntry->m_IsDiffFiles)
799 m_ChangedFileListCtrl.SetBusy(TRUE);
800 else
801 m_ChangedFileListCtrl.SetBusy(FALSE);
803 m_ChangedFileListCtrl.SetRedraw(TRUE);
804 m_gravatar.LoadGravatar(pLogEntry->GetAuthorEmail());
805 return;
809 else
811 // more than one revision is selected:
812 // the log message view must be emptied
813 // the changed files list contains all the changed paths from all
814 // selected revisions, with 'doubles' removed
815 m_currentChangedPathList = GetChangedPathsFromSelectedRevisions(true);
816 m_gravatar.LoadGravatar();
819 // redraw the views
820 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
821 #if 0
822 if (m_currentChangedArray)
824 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedArray->GetCount());
825 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedArray->GetCount());
827 else if (m_currentChangedPathList.GetCount())
829 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedPathList.GetCount());
830 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedPathList.GetCount());
832 else
834 m_ChangedFileListCtrl.SetItemCountEx(0);
835 m_ChangedFileListCtrl.Invalidate();
837 #endif
838 // sort according to the settings
839 if (m_nSortColumnPathList > 0)
840 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
841 else
842 SetSortArrow(&m_ChangedFileListCtrl, -1, false);
843 m_ChangedFileListCtrl.SetRedraw(TRUE);
847 void CLogDlg::FillPatchView(bool onlySetTimer)
849 if (!::IsWindow(this->m_patchViewdlg.m_hWnd))
850 return;
852 KillTimer(LOG_FILLPATCHVTIMER);
853 if (onlySetTimer)
855 SetTimer(LOG_FILLPATCHVTIMER, 100, nullptr);
856 return;
859 POSITION posLogList = m_LogList.GetFirstSelectedItemPosition();
860 if (posLogList == nullptr)
862 m_patchViewdlg.ClearView();
863 return; // nothing is selected, get out of here
866 GitRev * pLogEntry = reinterpret_cast<GitRev* >(m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(posLogList)));
867 if (pLogEntry == nullptr || m_LogList.GetNextSelectedItem(posLogList) != -1)
869 m_patchViewdlg.ClearView();
870 return;
873 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
874 CString out;
876 if (pos == nullptr)
878 int diffContext = 0;
879 if (CAppUtils::GetMsysgitVersion() > 0x01080100)
880 diffContext = g_Git.GetConfigValueInt32(_T("diff.context"), -1);
881 CStringA outA;
882 g_Git.GetUnifiedDiff(CTGitPath(), pLogEntry->m_CommitHash.ToString() + _T("~1"), pLogEntry->m_CommitHash.ToString(), &outA, false, false, diffContext);
883 out = CUnicodeUtils::GetUnicode(outA);
885 else
887 while (pos)
889 int nSelect = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
890 CTGitPath * p = (CTGitPath*)m_ChangedFileListCtrl.GetItemData(nSelect);
891 if (p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER))
893 CString cmd;
894 if (pLogEntry->m_CommitHash.IsEmpty())
895 cmd.Format(_T("git.exe diff HEAD -- \"%s\""), p->GetGitPathString());
896 else
897 cmd.Format(_T("git.exe diff %s^%d..%s -- \"%s\""), pLogEntry->m_CommitHash.ToString(), p->m_ParentNo + 1, pLogEntry->m_CommitHash.ToString(), p->GetGitPathString());
898 g_Git.Run(cmd, &out, CP_UTF8);
903 m_patchViewdlg.SetText(out);
906 void CLogDlg::TogglePatchView()
908 m_patchViewdlg.m_pProjectProperties = &m_LogList.m_ProjectProperties;
909 m_patchViewdlg.m_ParentDlg = this;
910 if (!IsWindow(m_patchViewdlg.m_hWnd))
912 BOOL viewPatchEnabled = FALSE;
913 viewPatchEnabled = g_Git.GetConfigValueBool(_T("tgit.logshowpatch"));
914 if (viewPatchEnabled == FALSE)
915 g_Git.SetConfigValue(_T("tgit.logshowpatch"), _T("true"));
916 m_patchViewdlg.Create(IDD_PATCH_VIEW, this);
917 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTHTRACKING, TRUE);
918 CRect rect;
919 this->GetWindowRect(&rect);
921 m_patchViewdlg.ShowWindow(SW_SHOW);
922 m_patchViewdlg.SetWindowPos(nullptr, rect.right, rect.top, rect.Width(), rect.Height(), SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
924 FillPatchView();
926 else
928 g_Git.SetConfigValue(_T("tgit.logshowpatch"), _T("false"));
929 m_patchViewdlg.ShowWindow(SW_HIDE);
930 m_patchViewdlg.DestroyWindow();
934 LRESULT CLogDlg::OnFileListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
936 FillPatchView(true);
937 return 0;
940 void CLogDlg::OnMoving(UINT fwSide, LPRECT pRect)
942 __super::OnMoving(fwSide, pRect);
944 if (!::IsWindow(m_patchViewdlg.m_hWnd))
945 return;
947 RECT patchrect;
948 m_patchViewdlg.GetWindowRect(&patchrect);
949 if (!::IsWindow(m_hWnd))
950 return;
952 RECT thisrect;
953 GetWindowRect(&thisrect);
954 if (patchrect.left == thisrect.right)
956 m_patchViewdlg.SetWindowPos(nullptr, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top), 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
960 void CLogDlg::OnSizing(UINT fwSide, LPRECT pRect)
962 __super::OnSizing(fwSide, pRect);
964 if (!::IsWindow(this->m_patchViewdlg.m_hWnd))
965 return;
967 CRect thisrect, patchrect;
968 this->GetWindowRect(thisrect);
969 this->m_patchViewdlg.GetWindowRect(patchrect);
970 if (thisrect.right != patchrect.left)
971 return;
973 patchrect.left -= (thisrect.right - pRect->right);
974 patchrect.right -= (thisrect.right - pRect->right);
976 if (patchrect.bottom == thisrect.bottom)
977 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
978 if (patchrect.top == thisrect.top)
979 patchrect.top -= thisrect.top - pRect->top;
980 m_patchViewdlg.MoveWindow(patchrect);
983 void CLogDlg::GoBack()
985 m_LogList.m_highlight.Empty();
986 CGitHash gotoHash;
987 BOOL reachFirstOne = m_LogList.m_selectionHistory.GoBack(gotoHash);
988 int i;
989 for (i = 0; i < m_LogList.m_arShownList.GetCount(); ++i)
991 GitRev *rev = (GitRev *)m_LogList.m_arShownList.SafeGetAt(i);
992 if (!rev) continue;
993 if (rev->m_CommitHash == gotoHash)
995 m_LogList.m_highlight = gotoHash;
996 m_LogList.EnsureVisible(i, FALSE);
997 m_LogList.Invalidate();
998 break;
1001 if (i == m_LogList.m_arShownList.GetCount())
1003 CString msg;
1004 msg.FormatMessage(IDS_LOG_NOT_VISIBLE, gotoHash.ToString());
1005 MessageBox(msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1007 if (reachFirstOne)
1008 PlaySound((LPCTSTR)SND_ALIAS_SYSTEMASTERISK, nullptr, SND_ASYNC | SND_ALIAS_ID);
1011 void CLogDlg::GoForward()
1013 m_LogList.m_highlight.Empty();
1014 CGitHash gotoHash;
1015 if (m_LogList.m_selectionHistory.GoForward(gotoHash))
1017 int i;
1018 for (i = 0; i < m_LogList.m_arShownList.GetCount(); ++i)
1020 GitRev *rev = (GitRev *)m_LogList.m_arShownList.SafeGetAt(i);
1021 if (!rev) continue;
1022 if (rev->m_CommitHash == gotoHash)
1024 m_LogList.m_highlight = gotoHash;
1025 m_LogList.EnsureVisible(i, FALSE);
1026 m_LogList.Invalidate();
1027 return;
1030 if (i == m_LogList.m_arShownList.GetCount())
1032 CString msg;
1033 msg.FormatMessage(IDS_LOG_NOT_VISIBLE, gotoHash.ToString());
1034 MessageBox(msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1037 m_LogList.Invalidate();
1038 PlaySound((LPCTSTR)SND_ALIAS_SYSTEMASTERISK, nullptr, SND_ASYNC | SND_ALIAS_ID);
1041 void CLogDlg::OnBnClickedRefresh()
1043 Refresh (true);
1046 void CLogDlg::Refresh (bool clearfilter /*autoGoOnline*/)
1048 m_limit = 0;
1049 m_LogList.Refresh(clearfilter);
1050 EnableOKButton();
1051 ShowStartRef();
1052 FillLogMessageCtrl(false);
1057 BOOL CLogDlg::Cancel()
1059 return m_bCancelled;
1062 void CLogDlg::SaveSplitterPos()
1064 if (!IsIconic())
1066 CRegDWORD regPos1(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
1067 CRegDWORD regPos2(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
1068 RECT rectSplitter;
1069 m_wndSplitter1.GetWindowRect(&rectSplitter);
1070 ScreenToClient(&rectSplitter);
1071 regPos1 = rectSplitter.top;
1072 m_wndSplitter2.GetWindowRect(&rectSplitter);
1073 ScreenToClient(&rectSplitter);
1074 regPos2 = rectSplitter.top;
1078 void CLogDlg::OnCancel()
1080 this->ShowWindow(SW_HIDE);
1082 // canceling means stopping the working thread if it's still running.
1083 m_LogList.SafeTerminateAsyncDiffThread();
1084 if (this->IsThreadRunning())
1086 m_LogList.SafeTerminateThread();
1088 UpdateData();
1090 SaveSplitterPos();
1091 __super::OnCancel();
1094 void CLogDlg::CopyChangedSelectionToClipBoard()
1097 POSITION posLogList = m_LogList.GetFirstSelectedItemPosition();
1098 if (posLogList == nullptr)
1099 return; // nothing is selected, get out of here
1101 CString sPaths;
1103 // CGitRev* pLogEntry = reinterpret_cast<CGitRev* >(m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1104 // if (posLogList)
1106 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
1107 while (pos)
1109 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
1110 CTGitPath *path = (CTGitPath*)m_ChangedFileListCtrl.GetItemData(nItem);
1111 if(path)
1112 sPaths += path->GetGitPathString();
1113 sPaths += _T("\r\n");
1116 #if 0
1117 else
1119 // only one revision is selected in the log dialog top pane
1120 // but multiple items could be selected in the changed items list
1121 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
1122 while (pos)
1124 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
1125 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(nItem);
1127 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
1129 // some items are hidden! So find out which item the user really selected
1130 INT_PTR selRealIndex = -1;
1131 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
1133 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1134 ++selRealIndex;
1135 if (selRealIndex == nItem)
1137 changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex);
1138 break;
1142 if (changedlogpath)
1144 sPaths += changedlogpath->sPath;
1145 sPaths += _T("\r\n");
1149 #endif
1150 sPaths.Trim();
1151 CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());
1155 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)
1157 // we have three separate context menus:
1158 // one for the branch label in the upper left
1159 // one shown on the log message list control,
1160 // one shown in the changed-files list control
1161 if (pWnd == GetDlgItem(IDC_STATIC_REF))
1163 CIconMenu popup;
1164 if (!popup.CreatePopupMenu())
1165 return;
1167 int cnt = 0;
1168 popup.AppendMenuIcon(++cnt, IDS_MENUREFBROWSE);
1169 popup.SetDefaultItem(cnt);
1170 popup.AppendMenuIcon(++cnt, _T("HEAD"));
1171 popup.AppendMenuIcon(++cnt, IDS_ALL);
1172 popup.EnableMenuItem(cnt, m_bFollowRenames);
1173 popup.AppendMenuIcon(++cnt, IDS_PROC_LOG_SELECT_LOCAL_BRANCHES);
1174 popup.EnableMenuItem(cnt, m_bFollowRenames);
1175 int offset = ++cnt;
1176 if (m_History.GetCount() > 0)
1178 popup.AppendMenu(MF_SEPARATOR, 0);
1179 for (size_t i = 0; i < m_History.GetCount(); ++i)
1181 CString entry = m_History.GetEntry(i);
1182 if (entry.GetLength() > 150)
1183 entry = entry.Left(150) + _T("...");
1184 popup.AppendMenuIcon(cnt++, entry);
1188 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1189 if (cmd == 0)
1190 return;
1191 else if (cmd == 1)
1193 OnBnClickedBrowseRef();
1194 return;
1197 m_LogList.m_ShowMask &= ~(CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES);
1198 m_bAllBranch = BST_UNCHECKED;
1199 if (cmd == 2)
1201 SetRange(g_Git.GetCurrentBranch(true));
1203 else if (cmd == 3)
1205 m_bAllBranch = BST_CHECKED;
1206 m_LogList.m_ShowMask |= CGit::LOG_INFO_ALL_BRANCH;
1208 else if (cmd == 4)
1210 m_bAllBranch = BST_INDETERMINATE;
1211 m_LogList.m_ShowMask |= CGit::LOG_INFO_LOCAL_BRANCHES;
1213 else if (cmd >= offset)
1215 SetRange(m_History.GetEntry(cmd - offset));
1216 m_History.AddEntry(m_LogList.m_sRange);
1217 m_History.Save();
1220 UpdateData(FALSE);
1222 OnRefresh();
1223 FillLogMessageCtrl(false);
1225 return;
1227 int selCount = m_LogList.GetSelectedCount();
1228 if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))
1230 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1231 int selIndex = -1;
1232 if (pos)
1233 selIndex = m_LogList.GetNextSelectedItem(pos);
1235 GitRev *pRev = ((GitRev*)m_LogList.m_arShownList[selIndex]);
1237 if ((point.x == -1) && (point.y == -1))
1239 CRect rect;
1240 GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);
1241 ClientToScreen(&rect);
1242 point = rect.CenterPoint();
1244 CString sMenuItemText;
1245 CIconMenu popup;
1246 if (popup.CreatePopupMenu())
1248 long start = -1, end = -1;
1249 auto pEdit = (CRichEditCtrl *)GetDlgItem(IDC_MSGVIEW);
1250 pEdit->GetSel(start, end);
1251 // add the 'default' entries
1252 popup.AppendMenuIcon(WM_COPY, IDS_SCIEDIT_COPY, IDI_COPYCLIP);
1253 if (start >= end)
1254 popup.EnableMenuItem(WM_COPY, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1255 popup.AppendMenu(MF_SEPARATOR);
1256 sMenuItemText.LoadString(IDS_STATUSLIST_CONTEXT_COPYEXT);
1257 popup.AppendMenuIcon(EM_SETSEL, sMenuItemText, IDI_COPYCLIP);
1258 popup.AppendMenu(MF_SEPARATOR, NULL);
1259 sMenuItemText.LoadString(IDS_EDIT_NOTES);
1260 popup.AppendMenuIcon( CGitLogList::ID_EDITNOTE, sMenuItemText, IDI_EDIT);
1262 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1263 switch (cmd)
1265 case 0:
1266 break; // no command selected
1267 case EM_SETSEL:
1269 pEdit->SetRedraw(FALSE);
1270 int oldLine = pEdit->GetFirstVisibleLine();
1271 pEdit->SetSel(0, -1);
1272 pEdit->Copy();
1273 pEdit->SetSel(start, end);
1274 int newLine = pEdit->GetFirstVisibleLine();
1275 pEdit->LineScroll(oldLine - newLine);
1276 pEdit->SetRedraw(TRUE);
1277 pEdit->RedrawWindow();
1279 break;
1280 case WM_COPY:
1281 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);
1282 break;
1283 case CGitLogList::ID_EDITNOTE:
1284 CAppUtils::EditNote(pRev);
1285 this->FillLogMessageCtrl(true);
1286 break;
1292 void CLogDlg::OnOK()
1294 // since the log dialog is also used to select revisions for other
1295 // dialogs, we have to do some work before closing this dialog
1296 if (GetFocus() != GetDlgItem(IDOK))
1297 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter
1299 m_LogList.SafeTerminateAsyncDiffThread();
1300 if (this->IsThreadRunning())
1302 m_LogList.SafeTerminateThread();
1304 UpdateData();
1305 // check that one and only one row is selected
1306 if (m_LogList.GetSelectedCount() == 1)
1308 // get the selected row
1309 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1310 int selIndex = m_LogList.GetNextSelectedItem(pos);
1311 if (selIndex < m_LogList.m_arShownList.GetCount())
1313 // all ok, pick up the revision
1314 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
1315 // extract the hash
1316 m_sSelectedHash = pLogEntry->m_CommitHash;
1319 UpdateData(FALSE);
1320 SaveSplitterPos();
1321 __super::OnOK();
1323 #if 0
1324 if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))
1325 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.
1327 CString temp;
1328 CString buttontext;
1329 GetDlgItemText(IDOK, buttontext);
1330 temp.LoadString(IDS_MSGBOX_CANCEL);
1331 if (temp.Compare(buttontext) != 0)
1332 __super::OnOK(); // only exit if the button text matches, and that will match only if the thread isn't running anymore
1333 m_bCancelled = TRUE;
1334 m_selectedRevs.Clear();
1335 m_selectedRevsOneRange.Clear();
1336 if (m_pNotifyWindow)
1338 int selIndex = m_LogList.GetSelectionMark();
1339 if (selIndex >= 0)
1341 PLOGENTRYDATA pLogEntry = NULL;
1342 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1343 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1344 m_selectedRevs.AddRevision(pLogEntry->Rev);
1345 git_revnum_t lowerRev = pLogEntry->Rev;
1346 git_revnum_t higherRev = lowerRev;
1347 while (pos)
1349 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1350 git_revnum_t rev = pLogEntry->Rev;
1351 m_selectedRevs.AddRevision(pLogEntry->Rev);
1352 if (lowerRev > rev)
1353 lowerRev = rev;
1354 if (higherRev < rev)
1355 higherRev = rev;
1357 if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())
1359 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);
1361 BOOL bSentMessage = FALSE;
1362 if (m_LogList.GetSelectedCount() == 1)
1364 // if only one revision is selected, check if the path/url with which the dialog was started
1365 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.
1366 // if it was copied, use the copy from revision as lowerRev
1367 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))
1369 CString sUrl = m_path.GetGitPathString();
1370 if (!m_path.IsUrl())
1372 sUrl = GetURLFromPath(m_path);
1374 sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());
1375 for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)
1377 LogChangedPath * pData = pLogEntry->pArChangedPaths->SafeGetAt(cp);
1378 if (pData)
1380 if (sUrl.Compare(pData->sPath) == 0)
1382 if (!pData->sCopyFromPath.IsEmpty())
1384 lowerRev = pData->lCopyFromRev;
1385 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);
1386 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);
1387 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1388 bSentMessage = TRUE;
1395 if ( !bSentMessage )
1397 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);
1398 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);
1399 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1400 if (m_selectedRevsOneRange.GetCount())
1401 m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);
1405 UpdateData();
1406 CRegDWORD reg(_T("Software\\TortoiseGit\\ShowAllEntry"));
1407 SaveSplitterPos();
1408 #endif
1411 void CLogDlg::DoDiffFromLog(INT_PTR selIndex, GitRev* rev1, GitRev* rev2, bool /*blame*/, bool /*unified*/)
1413 DialogEnableWindow(IDOK, FALSE);
1414 // SetPromptApp(&theApp);
1415 theApp.DoWaitCursor(1);
1417 CString temppath;
1418 GetTempPath(temppath);
1420 CString file1;
1421 file1.Format(_T("%s%s_%s%s"),
1422 temppath,
1423 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1424 rev1->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength()),
1425 (*m_currentChangedArray)[selIndex].GetFileExtension());
1427 CString file2;
1428 file2.Format(_T("%s\\%s_%s%s"),
1429 temppath,
1430 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1431 rev2->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength()),
1432 (*m_currentChangedArray)[selIndex].GetFileExtension());
1434 CString cmd;
1435 CTGitPath &path = (CTGitPath &)(*m_currentChangedArray)[selIndex];
1437 if (g_Git.GetOneFile(rev1->m_CommitHash.ToString(), path, file1))
1439 CString out;
1440 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, path.GetGitPathString(), rev1->m_CommitHash.ToString(), file1);
1441 CMessageBox::Show(nullptr, g_Git.GetGitLastErr(out, CGit::GIT_CMD_GETONEFILE), _T("TortoiseGit"), MB_OK);
1442 theApp.DoWaitCursor(-1);
1443 EnableOKButton();
1444 return;
1446 if (g_Git.GetOneFile(rev2->m_CommitHash.ToString(), path, file2))
1448 CString out;
1449 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, path.GetGitPathString(), rev2->m_CommitHash.ToString(), file2);
1450 CMessageBox::Show(nullptr, g_Git.GetGitLastErr(out, CGit::GIT_CMD_GETONEFILE), _T("TortoiseGit"), MB_OK);
1451 theApp.DoWaitCursor(-1);
1452 EnableOKButton();
1453 return;
1456 CAppUtils::DiffFlags flags;
1457 CAppUtils::StartExtDiff(file1,file2,_T("A"),_T("B"),
1458 g_Git.CombinePath(path), g_Git.CombinePath(path),
1459 rev1->m_CommitHash.ToString(), rev2->m_CommitHash.ToString(),
1460 flags);
1462 theApp.DoWaitCursor(-1);
1463 EnableOKButton();
1466 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)
1468 // Skip Ctrl-C when copying text out of the log message or search filter
1469 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);
1470 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
1472 if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1474 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1476 m_LogList.DiffSelectedRevWithPrevious();
1477 return TRUE;
1480 if (GetFocus() == GetDlgItem(IDC_SEARCHEDIT))
1482 KillTimer(LOGFILTER_TIMER);
1483 m_limit = 0;
1484 m_LogList.Refresh(FALSE);
1485 FillLogMessageCtrl(false);
1488 if (m_hAccel && !bSkipAccelerator)
1490 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1491 if (ret)
1492 return TRUE;
1495 if(::IsWindow(m_tooltips.m_hWnd))
1496 m_tooltips.RelayEvent(pMsg);
1497 return __super::PreTranslateMessage(pMsg);
1501 BOOL CLogDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1503 //if (this->IsThreadRunning())
1504 if(m_LogList.m_bNoDispUpdates)
1506 // only show the wait cursor over the list control
1507 if ((pWnd)&&
1508 ((pWnd == GetDlgItem(IDC_LOGLIST))||
1509 (pWnd == GetDlgItem(IDC_MSGVIEW))||
1510 (pWnd == GetDlgItem(IDC_LOGMSG))))
1512 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1513 SetCursor(hCur);
1514 return TRUE;
1517 if ((pWnd) && (pWnd == GetDlgItem(IDC_MSGVIEW)))
1518 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1520 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1521 SetCursor(hCur);
1522 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1525 void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1527 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1528 *pResult = 0;
1529 //if (this->IsThreadRunning())
1530 if(m_LogList.m_bNoDispUpdates)
1531 return;
1532 if (pNMLV->iItem >= 0)
1534 if (!m_LogList.m_highlight.IsEmpty())
1536 m_LogList.m_highlight.Empty();
1537 m_LogList.Invalidate();
1539 this->m_LogList.m_nSearchIndex = pNMLV->iItem;
1540 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(pNMLV->iItem));
1541 if (pLogEntry == nullptr)
1542 return;
1543 m_LogList.m_lastSelectedHash = pLogEntry->m_CommitHash;
1544 if (pNMLV->iSubItem != 0)
1545 return;
1546 if ((pNMLV->iItem == m_LogList.m_arShownList.GetCount()))
1548 // remove the selected state
1549 if (pNMLV->uChanged & LVIF_STATE)
1551 m_LogList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);
1552 FillLogMessageCtrl();
1553 UpdateData(FALSE);
1554 UpdateLogInfoLabel();
1556 return;
1558 if (pNMLV->uChanged & LVIF_STATE)
1560 if (pNMLV->uNewState & LVIS_SELECTED)
1562 m_LogList.m_selectionHistory.Add(m_LogList.m_lastSelectedHash);
1563 m_LogList.m_lastSelectedHash = pLogEntry->m_CommitHash;
1565 FillLogMessageCtrl();
1566 UpdateData(FALSE);
1569 else
1571 m_LogList.m_lastSelectedHash.Empty();
1572 FillLogMessageCtrl();
1573 UpdateData(FALSE);
1575 EnableOKButton();
1576 UpdateLogInfoLabel();
1579 void CLogDlg::OnLvnItemchangedLogmsg(NMHDR * /*pNMHDR*/, LRESULT * /*pResult*/)
1581 UpdateLogInfoLabel();
1584 void CLogDlg::OnEnLinkMsgview(NMHDR *pNMHDR, LRESULT *pResult)
1586 ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);
1587 if (pEnLink->msg == WM_LBUTTONUP)
1589 CString url, msg;
1590 GetDlgItemText(IDC_MSGVIEW, msg);
1591 msg.Replace(_T("\r\n"), _T("\n"));
1592 url = msg.Mid(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax-pEnLink->chrg.cpMin);
1593 auto findResult = m_LogList.m_ProjectProperties.FindBugIDPositions(msg);
1594 if (std::find_if(findResult.begin(), findResult.end(),
1595 [=] (const CHARRANGE &cr) -> bool { return cr.cpMin == pEnLink->chrg.cpMin && cr.cpMax == pEnLink->chrg.cpMax; }
1596 ) != findResult.end())
1598 url = m_LogList.m_ProjectProperties.GetBugIDUrl(url);
1599 url = GetAbsoluteUrlFromRelativeUrl(url);
1601 if (::PathIsURL(url))
1602 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
1603 else
1605 int pos = 0;
1606 if (LookLikeGitHash(url, pos))
1608 bool found = false;
1609 for (int i = 0; i < m_LogList.m_arShownList.GetCount(); ++i)
1611 GitRev *rev = (GitRev *)m_LogList.m_arShownList.SafeGetAt(i);
1612 if (!rev) continue;
1613 if (rev->m_CommitHash.ToString().Left(url.GetLength()) == url)
1615 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1616 if (pos)
1618 int index = m_LogList.GetNextSelectedItem(pos);
1619 if (index > 0)
1620 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
1622 m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1623 m_LogList.EnsureVisible(i, FALSE);
1624 m_LogList.SetSelectionMark(i);
1625 found = true;
1626 PostMessage(WM_TGIT_REFRESH_SELECTION, 0, 0);
1627 break;
1631 if (!found)
1632 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_LOG_JUMPNOTFOUND, IDS_APPNAME, 1, IDI_INFORMATION, IDS_OKBUTTON, 0, 0, _T("NoJumpNotFoundWarning"), IDS_MSGBOX_DONOTSHOWAGAIN);
1636 *pResult = 0;
1639 void CLogDlg::OnBnClickedStatbutton()
1641 if (this->IsThreadRunning())
1642 return;
1643 if (m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC)
1644 return; // nothing or just the working copy changes are shown, so no statistics.
1645 // the statistics dialog expects the log entries to be sorted by date
1646 SortByColumn(3, false);
1648 CStatGraphDlg dlg;
1649 m_LogList.RecalculateShownList(&dlg.m_ShowList);
1651 dlg.m_path = m_orgPath;
1652 dlg.DoModal();
1653 // restore the previous sorting
1654 SortByColumn(m_nSortColumn, m_bAscending);
1655 OnTimer(LOGFILTER_TIMER);
1658 void CLogDlg::MoveToSameTop(CWnd *pWndRef, CWnd *pWndTarget)
1660 CRect rcWndPicAuthor, rcWndMsgView;
1661 pWndRef->GetWindowRect(rcWndMsgView);
1662 ScreenToClient(rcWndMsgView);
1663 pWndTarget->GetWindowRect(rcWndPicAuthor);
1664 ScreenToClient(rcWndPicAuthor);
1665 int diff = rcWndMsgView.top - rcWndPicAuthor.top;
1666 rcWndPicAuthor.top += diff;
1667 rcWndPicAuthor.bottom += diff;
1668 pWndTarget->MoveWindow(rcWndPicAuthor);
1671 void CLogDlg::DoSizeV1(int delta)
1674 RemoveAnchor(IDC_LOGLIST);
1675 RemoveAnchor(IDC_SPLITTERTOP);
1676 RemoveAnchor(IDC_MSGVIEW);
1677 RemoveAnchor(IDC_PIC_AUTHOR);
1678 RemoveAnchor(IDC_SPLITTERBOTTOM);
1679 RemoveAnchor(IDC_LOGMSG);
1680 CSplitterControl::ChangeHeight(&m_LogList, delta, CW_TOPALIGN);
1681 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), -delta, CW_BOTTOMALIGN);
1682 MoveToSameTop(GetDlgItem(IDC_MSGVIEW), GetDlgItem(IDC_PIC_AUTHOR));
1683 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1684 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1685 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1686 AddAnchor(IDC_PIC_AUTHOR, TOP_RIGHT);
1687 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1688 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1689 ArrangeLayout();
1690 AdjustMinSize();
1691 SetSplitterRange();
1692 m_LogList.Invalidate();
1693 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1694 m_gravatar.Invalidate();
1698 void CLogDlg::DoSizeV2(int delta)
1701 RemoveAnchor(IDC_LOGLIST);
1702 RemoveAnchor(IDC_SPLITTERTOP);
1703 RemoveAnchor(IDC_MSGVIEW);
1704 RemoveAnchor(IDC_PIC_AUTHOR);
1705 RemoveAnchor(IDC_SPLITTERBOTTOM);
1706 RemoveAnchor(IDC_LOGMSG);
1707 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), delta, CW_TOPALIGN);
1708 CSplitterControl::ChangeHeight(&m_ChangedFileListCtrl, -delta, CW_BOTTOMALIGN);
1709 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1710 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1711 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1712 AddAnchor(IDC_PIC_AUTHOR, TOP_RIGHT);
1713 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1714 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1715 ArrangeLayout();
1716 AdjustMinSize();
1717 SetSplitterRange();
1718 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1719 m_ChangedFileListCtrl.Invalidate();
1720 m_gravatar.Invalidate();
1724 void CLogDlg::AdjustMinSize()
1726 // adjust the minimum size of the dialog to prevent the resizing from
1727 // moving the list control too far down.
1728 CRect rcChgListView;
1729 m_ChangedFileListCtrl.GetClientRect(rcChgListView);
1730 CRect rcLogList;
1731 m_LogList.GetClientRect(rcLogList);
1733 SetMinTrackSize(CSize(m_DlgOrigRect.Width(),
1734 m_DlgOrigRect.Height()-m_ChgOrigRect.Height()-m_LogListOrigRect.Height()-m_MsgViewOrigRect.Height()
1735 +rcChgListView.Height()+rcLogList.Height()+60));
1738 LRESULT CLogDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1740 switch (message) {
1741 case WM_NOTIFY:
1742 if (wParam == IDC_SPLITTERTOP)
1744 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1745 DoSizeV1(pHdr->delta);
1747 else if (wParam == IDC_SPLITTERBOTTOM)
1749 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1750 DoSizeV2(pHdr->delta);
1752 break;
1755 return CResizableDialog::DefWindowProc(message, wParam, lParam);
1758 void CLogDlg::SetSplitterRange()
1760 if ((m_LogList)&&(m_ChangedFileListCtrl))
1762 CRect rcTop;
1763 m_LogList.GetWindowRect(rcTop);
1764 ScreenToClient(rcTop);
1765 CRect rcMiddle;
1766 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(rcMiddle);
1767 ScreenToClient(rcMiddle);
1768 m_wndSplitter1.SetRange(rcTop.top+30, rcMiddle.bottom-20);
1769 CRect rcBottom;
1770 m_ChangedFileListCtrl.GetWindowRect(rcBottom);
1771 ScreenToClient(rcBottom);
1772 m_wndSplitter2.SetRange(rcMiddle.top+30, rcBottom.bottom-20);
1776 LRESULT CLogDlg::OnClickedInfoIcon(WPARAM /*wParam*/, LPARAM lParam)
1778 // FIXME: x64 version would get this function called with unexpected parameters.
1779 if (!lParam)
1780 return 0;
1782 RECT * rect = (LPRECT)lParam;
1783 CPoint point;
1784 CString temp;
1785 point = CPoint(rect->left, rect->bottom);
1786 #define LOGMENUFLAGS(x) (MF_STRING | MF_ENABLED | (m_LogList.m_SelectedFilters & x ? MF_CHECKED : MF_UNCHECKED))
1787 CMenu popup;
1788 if (popup.CreatePopupMenu())
1790 temp.LoadString(IDS_LOG_FILTER_SUBJECT);
1791 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_SUBJECT), LOGFILTER_SUBJECT, temp);
1793 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
1794 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_MESSAGES), LOGFILTER_MESSAGES, temp);
1796 temp.LoadString(IDS_LOG_FILTER_PATHS);
1797 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_PATHS), LOGFILTER_PATHS, temp);
1799 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
1800 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_AUTHORS), LOGFILTER_AUTHORS, temp);
1802 temp.LoadString(IDS_LOG_FILTER_EMAILS);
1803 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_EMAILS), LOGFILTER_EMAILS, temp);
1805 temp.LoadString(IDS_LOG_FILTER_REVS);
1806 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REVS), LOGFILTER_REVS, temp);
1808 temp.LoadString(IDS_LOG_FILTER_REFNAME);
1809 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REFNAME), LOGFILTER_REFNAME, temp);
1811 if (m_LogList.m_bShowBugtraqColumn == TRUE) {
1812 temp.LoadString(IDS_LOG_FILTER_BUGIDS);
1813 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_BUGID), LOGFILTER_BUGID, temp);
1816 temp.LoadString(IDS_LOG_FILTER_TOGGLE);
1817 popup.AppendMenu(MF_STRING | MF_ENABLED, LOGFILTER_TOGGLE, temp);
1819 popup.AppendMenu(MF_SEPARATOR, NULL);
1821 temp.LoadString(IDS_LOG_FILTER_REGEX);
1822 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterWithRegex ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_REGEX, temp);
1824 m_tooltips.Pop();
1825 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1826 if (selection != 0)
1829 if (selection == LOGFILTER_REGEX)
1831 m_bFilterWithRegex = !m_bFilterWithRegex;
1832 CRegDWORD b(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
1833 b = m_bFilterWithRegex;
1834 m_LogList.m_bFilterWithRegex = m_bFilterWithRegex;
1835 SetFilterCueText();
1836 CheckRegexpTooltip();
1838 else if (selection == LOGFILTER_TOGGLE)
1840 m_LogList.m_SelectedFilters = (~m_LogList.m_SelectedFilters) & LOGFILTER_ALL;
1841 SetFilterCueText();
1843 else
1845 m_LogList.m_SelectedFilters ^= selection;
1846 SetFilterCueText();
1848 // Reload only if a search text is entered
1849 if (m_LogList.HasFilterText())
1850 SetTimer(LOGFILTER_TIMER, 1000, NULL);
1853 return 0L;
1856 LRESULT CLogDlg::OnClickedCancelFilter(WPARAM /*wParam*/, LPARAM /*lParam*/)
1859 KillTimer(LOGFILTER_TIMER);
1861 m_LogList.m_sFilterText.Empty();
1862 UpdateData(FALSE);
1863 theApp.DoWaitCursor(1);
1864 CStoreSelection storeselection(this);
1865 FillLogMessageCtrl(false);
1867 m_LogList.RemoveFilter();
1869 Refresh();
1871 CTime begin,end;
1872 m_LogList.GetTimeRange(begin,end);
1873 m_DateFrom.SetTime(&begin);
1874 m_DateTo.SetTime(&end);
1876 theApp.DoWaitCursor(-1);
1877 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
1878 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
1879 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
1880 UpdateLogInfoLabel();
1882 return 0L;
1886 void CLogDlg::SetFilterCueText()
1888 CString temp(MAKEINTRESOURCE(IDS_LOG_FILTER_BY));
1889 temp += _T(" ");
1891 if (m_LogList.m_SelectedFilters & LOGFILTER_SUBJECT)
1893 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_SUBJECT));
1896 if (m_LogList.m_SelectedFilters & LOGFILTER_MESSAGES)
1898 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
1899 temp += _T(", ");
1900 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_MESSAGES));
1903 if (m_LogList.m_SelectedFilters & LOGFILTER_PATHS)
1905 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
1906 temp += _T(", ");
1907 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_PATHS));
1910 if (m_LogList.m_SelectedFilters & LOGFILTER_AUTHORS)
1912 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
1913 temp += _T(", ");
1914 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_AUTHORS));
1917 if (m_LogList.m_SelectedFilters & LOGFILTER_EMAILS)
1919 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
1920 temp += _T(", ");
1921 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_EMAILS));
1924 if (m_LogList.m_SelectedFilters & LOGFILTER_REVS)
1926 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
1927 temp += _T(", ");
1928 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_REVS));
1931 if (m_LogList.m_SelectedFilters & LOGFILTER_REFNAME)
1933 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
1934 temp += _T(", ");
1935 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_REFNAME));
1938 if (m_LogList.m_SelectedFilters & LOGFILTER_BUGID)
1940 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
1941 temp += _T(", ");
1942 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_BUGIDS));
1945 // to make the cue banner text appear more to the right of the edit control
1946 temp = _T(" ")+temp;
1947 m_cFilter.SetCueBanner(temp.TrimRight());
1950 bool CLogDlg::Validate(LPCTSTR string)
1952 if (!m_bFilterWithRegex)
1953 return true;
1954 std::tr1::wregex pat;
1955 return m_LogList.ValidateRegexp(string, pat, false);
1959 void CLogDlg::OnTimer(UINT_PTR nIDEvent)
1961 if (nIDEvent == LOGFTIME_TIMER)
1963 KillTimer(LOGFTIME_TIMER);
1964 m_limit = 0;
1965 m_LogList.Refresh(FALSE);
1966 FillLogMessageCtrl(false);
1968 else if (nIDEvent == LOG_FILLPATCHVTIMER)
1970 FillPatchView();
1972 else if (nIDEvent == LOGFILTER_TIMER)
1974 KillTimer(LOGFILTER_TIMER);
1975 m_limit = 0;
1976 m_LogList.Refresh(FALSE);
1977 FillLogMessageCtrl(false);
1979 #if 0
1980 /* we will use git built-in grep to filter log */
1981 if (this->IsThreadRunning())
1983 // thread still running! So just restart the timer.
1984 SetTimer(LOGFILTER_TIMER, 1000, NULL);
1985 return;
1987 CWnd * focusWnd = GetFocus();
1988 bool bSetFocusToFilterControl = ((focusWnd != GetDlgItem(IDC_DATEFROM))&&(focusWnd != GetDlgItem(IDC_DATETO))
1989 && (focusWnd != GetDlgItem(IDC_LOGLIST)));
1990 if (m_LogList.m_sFilterText.IsEmpty())
1992 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
1993 // do not return here!
1994 // we also need to run the filter if the filter text is empty:
1995 // 1. to clear an existing filter
1996 // 2. to rebuild the m_arShownList after sorting
1998 theApp.DoWaitCursor(1);
1999 CStoreSelection storeselection(this);
2000 KillTimer(LOGFILTER_TIMER);
2001 FillLogMessageCtrl(false);
2003 // now start filter the log list
2004 m_LogList.StartFilter();
2006 if ( m_LogList.GetItemCount()==1 )
2008 m_LogList.SetSelectionMark(0);
2009 m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
2011 theApp.DoWaitCursor(-1);
2012 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2013 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2014 if (bSetFocusToFilterControl)
2015 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2016 UpdateLogInfoLabel();
2017 #endif
2018 } // if (nIDEvent == LOGFILTER_TIMER)
2019 else if (nIDEvent == LOG_HEADER_ORDER_TIMER)
2021 KillTimer(LOG_HEADER_ORDER_TIMER);
2022 CLogOrdering orderDlg;
2023 if (orderDlg.DoModal() == IDOK)
2024 Refresh();
2026 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC))));
2027 __super::OnTimer(nIDEvent);
2030 void CLogDlg::OnDtnDatetimechangeDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2034 CTime _time;
2035 m_DateTo.GetTime(_time);
2037 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 23, 59, 59);
2038 if (time.GetTime() != m_LogList.m_To)
2040 m_LogList.m_To = (DWORD)time.GetTime();
2041 SetTimer(LOGFTIME_TIMER, 10, NULL);
2044 catch (...)
2046 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2049 *pResult = 0;
2052 void CLogDlg::OnDtnDatetimechangeDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2057 CTime _time;
2058 m_DateFrom.GetTime(_time);
2060 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 0, 0, 0);
2061 if (time.GetTime() != m_LogList.m_From)
2063 m_LogList.m_From = (DWORD)time.GetTime();
2064 SetTimer(LOGFTIME_TIMER, 10, NULL);
2067 catch (...)
2069 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2072 *pResult = 0;
2075 void CLogDlg::OnCbnSelchangeJumpType()
2077 // reserved for future use
2080 void CLogDlg::OnBnClickedJumpUp()
2082 int sel = m_JumpType.GetCurSel();
2083 if (sel < 0) return;
2084 JumpType jumpType = (JumpType)sel;
2086 if (jumpType == JumpType_History)
2088 GoBack();
2089 return;
2092 CString strValue;
2093 CGitHash hashValue;
2094 int index = -1;
2095 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2096 if (pos)
2098 index = m_LogList.GetNextSelectedItem(pos);
2099 if (index == 0) return;
2101 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(index);
2102 if (jumpType == JumpType_AuthorEmail)
2103 strValue = data->GetAuthorEmail();
2104 else if (jumpType == JumpType_CommitterEmail)
2105 strValue = data->GetCommitterEmail();
2106 else if (jumpType == JumpType_Parent1)
2107 hashValue = data->m_CommitHash;
2108 else if (jumpType == JumpType_Parent2)
2109 hashValue = data->m_CommitHash;
2110 else if (jumpType == JumpType_TagFF)
2111 hashValue = data->m_CommitHash;
2112 else if (jumpType == JumpType_BranchFF)
2113 hashValue = data->m_CommitHash;
2115 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2117 else
2118 return;
2120 while (pos)
2122 index = m_LogList.GetNextSelectedItem(pos);
2123 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2125 m_LogList.SetSelectionMark(-1);
2127 for (int i = index - 1; i >= 0; i--)
2129 bool found = false;
2130 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(i);
2131 if (jumpType == JumpType_AuthorEmail)
2132 found = strValue == data->GetAuthorEmail();
2133 else if (jumpType == JumpType_CommitterEmail)
2134 found = strValue == data->GetCommitterEmail();
2135 else if (jumpType == JumpType_MergePoint)
2136 found = data->ParentsCount() > 1;
2137 else if (jumpType == JumpType_Parent1)
2139 if (data->m_ParentHash.size() > 0)
2140 found = data->m_ParentHash[0] == hashValue;
2142 else if (jumpType == JumpType_Parent2)
2144 if (data->m_ParentHash.size() > 1)
2145 found = data->m_ParentHash[1] == hashValue;
2147 else if (jumpType == JumpType_Tag || jumpType == JumpType_TagFF)
2149 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2150 for (size_t j = 0; j < refList.size(); ++j)
2152 if (refList[j].Left(10) == _T("refs/tags/"))
2154 found = true;
2155 break;
2159 if (found && jumpType == JumpType_TagFF)
2160 found = g_Git.IsFastForward(hashValue, data->m_CommitHash);
2162 else if (jumpType == JumpType_Branch || jumpType == JumpType_BranchFF)
2164 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2165 for (size_t j = 0; j < refList.size(); ++j)
2167 if (refList[j].Left(11) == _T("refs/heads/") || refList[j].Left(13) == _T("refs/remotes/"))
2169 found = true;
2170 break;
2174 if (found && jumpType == JumpType_BranchFF)
2175 found = g_Git.IsFastForward(hashValue, data->m_CommitHash);
2178 if (found)
2180 m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2181 m_LogList.EnsureVisible(i, FALSE);
2182 m_LogList.SetSelectionMark(i);
2183 return;
2187 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_LOG_JUMPNOTFOUND, IDS_APPNAME, 1, IDI_INFORMATION, IDS_OKBUTTON, 0, 0, _T("NoJumpNotFoundWarning"), IDS_MSGBOX_DONOTSHOWAGAIN);
2190 void CLogDlg::OnBnClickedJumpDown()
2192 int jumpType = m_JumpType.GetCurSel();
2193 if (jumpType < 0) return;
2195 if (jumpType == JumpType_History)
2197 GoForward();
2198 return;
2201 CString strValue;
2202 CGitHash hashValue;
2203 int index = -1;
2204 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2205 if (pos)
2207 index = m_LogList.GetNextSelectedItem(pos);
2208 if (index == 0) return;
2210 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(index);
2211 if (jumpType == JumpType_AuthorEmail)
2212 strValue = data->GetAuthorEmail();
2213 else if (jumpType == JumpType_CommitterEmail)
2214 strValue = data->GetCommitterEmail();
2215 else if (jumpType == JumpType_Parent1)
2217 if (data->m_ParentHash.size() > 0)
2218 hashValue = data->m_ParentHash.at(0);
2219 else
2220 return;
2222 else if (jumpType == JumpType_Parent2)
2224 if (data->m_ParentHash.size() > 1)
2225 hashValue = data->m_ParentHash.at(1);
2226 else
2227 return;
2229 else if (jumpType == JumpType_TagFF)
2230 hashValue = data->m_CommitHash;
2231 else if (jumpType == JumpType_BranchFF)
2232 hashValue = data->m_CommitHash;
2234 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2236 else
2237 return;
2239 while (pos)
2241 index = m_LogList.GetNextSelectedItem(pos);
2242 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2244 m_LogList.SetSelectionMark(-1);
2246 for (int i = index + 1; i < m_LogList.GetItemCount(); ++i)
2248 bool found = false;
2249 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(i);
2250 if (jumpType == JumpType_AuthorEmail)
2251 found = strValue == data->GetAuthorEmail();
2252 else if (jumpType == JumpType_CommitterEmail)
2253 found = strValue == data->GetCommitterEmail();
2254 else if (jumpType == JumpType_MergePoint)
2255 found = data->ParentsCount() > 1;
2256 else if (jumpType == JumpType_Parent1)
2257 found = data->m_CommitHash == hashValue;
2258 else if (jumpType == JumpType_Parent2)
2259 found = data->m_CommitHash == hashValue;
2260 else if (jumpType == JumpType_Tag || jumpType == JumpType_TagFF)
2262 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2263 for (size_t j = 0; j < refList.size(); ++j)
2265 if (refList[j].Left(10) == _T("refs/tags/"))
2267 found = true;
2268 break;
2272 if (found && jumpType == JumpType_TagFF)
2273 found = g_Git.IsFastForward(data->m_CommitHash, hashValue);
2275 else if (jumpType == JumpType_Branch || jumpType == JumpType_BranchFF)
2277 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2278 for (size_t j = 0; j < refList.size(); ++j)
2280 if (refList[j].Left(11) == _T("refs/heads/") || refList[j].Left(13) == _T("refs/remotes/"))
2282 found = true;
2283 break;
2287 if (found && jumpType == JumpType_BranchFF)
2288 found = g_Git.IsFastForward(data->m_CommitHash, hashValue);
2291 if (found)
2293 m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2294 m_LogList.EnsureVisible(i, FALSE);
2295 m_LogList.SetSelectionMark(i);
2296 return;
2300 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_LOG_JUMPNOTFOUND, IDS_APPNAME, 1, IDI_INFORMATION, IDS_OKBUTTON, 0, 0, _T("NoJumpNotFoundWarning"), IDS_MSGBOX_DONOTSHOWAGAIN);
2303 CTGitPathList CLogDlg::GetChangedPathsFromSelectedRevisions(bool /*bRelativePaths*/ /* = false */, bool /*bUseFilter*/ /* = true */)
2305 CTGitPathList pathList;
2306 #if 0
2308 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2310 m_sRepositoryRoot = GetRepositoryRoot(m_path);
2312 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2313 return pathList;
2315 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2316 if (pos != NULL)
2318 while (pos)
2320 int nextpos = m_LogList.GetNextSelectedItem(pos);
2321 if (nextpos >= m_arShownList.GetCount())
2322 continue;
2323 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(nextpos));
2324 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2325 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
2327 LogChangedPath * cpath = cpatharray->SafeGetAt(cpPathIndex);
2328 if (cpath == NULL)
2329 continue;
2330 CTGitPath path;
2331 if (!bRelativePaths)
2332 path.SetFromGit(m_sRepositoryRoot);
2333 path.AppendPathString(cpath->sPath);
2334 if ((!bUseFilter)||
2335 ((m_cHidePaths.GetState() & 0x0003)!=BST_CHECKED)||
2336 (cpath->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0))
2337 pathList.AddPath(path);
2342 pathList.RemoveDuplicates();
2343 #endif
2344 return pathList;
2347 void CLogDlg::SortByColumn(int /*nSortColumn*/, bool /*bAscending*/)
2349 #if 0
2350 switch(nSortColumn)
2352 case 0: // Revision
2354 if(bAscending)
2355 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscRevSort());
2356 else
2357 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescRevSort());
2359 break;
2360 case 1: // action
2362 if(bAscending)
2363 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscActionSort());
2364 else
2365 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescActionSort());
2367 break;
2368 case 2: // Author
2370 if(bAscending)
2371 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscAuthorSort());
2372 else
2373 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescAuthorSort());
2375 break;
2376 case 3: // Date
2378 if(bAscending)
2379 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscDateSort());
2380 else
2381 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescDateSort());
2383 break;
2384 case 4: // Message or bug id
2385 if (m_bShowBugtraqColumn)
2387 if(bAscending)
2388 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscBugIDSort());
2389 else
2390 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescBugIDSort());
2391 break;
2393 // fall through here
2394 case 5: // Message
2396 if(bAscending)
2397 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscMessageSort());
2398 else
2399 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescMessageSort());
2401 break;
2402 default:
2403 ATLASSERT(0);
2404 break;
2406 #endif
2409 void CLogDlg::OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult)
2411 if (this->IsThreadRunning())
2412 return; //no sorting while the arrays are filled
2413 #if 0
2414 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2415 const int nColumn = pNMLV->iSubItem;
2416 m_bAscending = nColumn == m_nSortColumn ? !m_bAscending : TRUE;
2417 m_nSortColumn = nColumn;
2418 SortByColumn(m_nSortColumn, m_bAscending);
2419 SetSortArrow(&m_LogList, m_nSortColumn, !!m_bAscending);
2420 SortShownListArray();
2421 m_LogList.Invalidate();
2422 UpdateLogInfoLabel();
2423 #else
2424 UNREFERENCED_PARAMETER(pNMHDR);
2425 #endif
2426 *pResult = 0;
2428 SetTimer(LOG_HEADER_ORDER_TIMER, 10, nullptr);
2431 void CLogDlg::SortShownListArray()
2433 // make sure the shown list still matches the filter after sorting.
2434 OnTimer(LOGFILTER_TIMER);
2435 // clear the selection states
2436 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2437 while (pos)
2439 m_LogList.SetItemState(m_LogList.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
2441 m_LogList.SetSelectionMark(-1);
2444 void CLogDlg::SetSortArrow(CListCtrl * control, int nColumn, bool bAscending)
2446 if (control == NULL)
2447 return;
2448 // set the sort arrow
2449 CHeaderCtrl * pHeader = control->GetHeaderCtrl();
2450 HDITEM HeaderItem = {0};
2451 HeaderItem.mask = HDI_FORMAT;
2452 for (int i=0; i<pHeader->GetItemCount(); ++i)
2454 pHeader->GetItem(i, &HeaderItem);
2455 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
2456 pHeader->SetItem(i, &HeaderItem);
2458 if (nColumn >= 0)
2460 pHeader->GetItem(nColumn, &HeaderItem);
2461 HeaderItem.fmt |= (bAscending ? HDF_SORTUP : HDF_SORTDOWN);
2462 pHeader->SetItem(nColumn, &HeaderItem);
2466 int CLogDlg::m_nSortColumnPathList = 0;
2467 bool CLogDlg::m_bAscendingPathList = false;
2469 void CLogDlg::OnBnClickedHidepaths()
2471 FillLogMessageCtrl();
2472 m_ChangedFileListCtrl.Invalidate();
2475 void CLogDlg::UpdateLogInfoLabel()
2478 CGitHash rev1 ;
2479 CGitHash rev2 ;
2480 long selectedrevs = 0;
2481 long selectedfiles = 0;
2482 int count = (int)m_LogList.m_arShownList.GetCount();
2483 int start = 0;
2484 if (count)
2486 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(0)))->m_CommitHash;
2487 if(this->m_LogList.m_bShowWC && rev1.IsEmpty()&&(count>1))
2488 start = 1;
2489 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(start)))->m_CommitHash;
2490 //pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_arShownList.GetCount()-1));
2491 rev2 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(count-1)))->m_CommitHash;
2492 selectedrevs = m_LogList.GetSelectedCount();
2493 if (selectedrevs)
2494 selectedfiles = m_ChangedFileListCtrl.GetSelectedCount();
2496 CString sTemp;
2497 sTemp.Format(IDS_PROC_LOG_STATS,
2498 count - start,
2499 rev2.ToString().Left(g_Git.GetShortHASHLength()), rev1.ToString().Left(g_Git.GetShortHASHLength()), selectedrevs, selectedfiles);
2501 if(selectedrevs == 1)
2503 CString str=m_ChangedFileListCtrl.GetStatisticsString(true);
2504 str.Replace(_T('\n'), _T(' '));
2505 sTemp += _T("\r\n") + str;
2507 m_sLogInfo = sTemp;
2509 UpdateData(FALSE);
2512 void CLogDlg::OnDtnDropdownDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2514 // the date control should not show the "today" button
2515 CMonthCalCtrl * pCtrl = m_DateFrom.GetMonthCalCtrl();
2516 if (pCtrl)
2517 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
2518 *pResult = 0;
2521 void CLogDlg::OnDtnDropdownDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2523 // the date control should not show the "today" button
2524 CMonthCalCtrl * pCtrl = m_DateTo.GetMonthCalCtrl();
2525 if (pCtrl)
2526 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
2527 *pResult = 0;
2530 void CLogDlg::OnSize(UINT nType, int cx, int cy)
2532 __super::OnSize(nType, cx, cy);
2533 //set range
2534 SetSplitterRange();
2537 void CLogDlg::OnRefresh()
2540 m_limit = 0;
2541 this->m_LogProgress.SetPos(0);
2543 Refresh (false);
2547 void CLogDlg::OnFocusFilter()
2549 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2552 void CLogDlg::OnEditCopy()
2554 if (GetFocus() == &m_ChangedFileListCtrl)
2555 CopyChangedSelectionToClipBoard();
2556 else
2557 m_LogList.CopySelectionToClipBoard();
2560 CString CLogDlg::GetAbsoluteUrlFromRelativeUrl(const CString& url)
2562 // is the URL a relative one?
2563 if (url.Left(2).Compare(_T("^/")) == 0)
2565 // URL is relative to the repository root
2566 CString url1 = m_sRepositoryRoot + url.Mid(1);
2567 TCHAR buf[INTERNET_MAX_URL_LENGTH] = { 0 };
2568 DWORD len = url.GetLength();
2569 if (UrlCanonicalize((LPCTSTR)url1, buf, &len, 0) == S_OK)
2570 return CString(buf, len);
2571 return url1;
2573 else if (url[0] == '/')
2575 // URL is relative to the server's hostname
2576 CString sHost;
2577 // find the server's hostname
2578 int schemepos = m_sRepositoryRoot.Find(_T("//"));
2579 if (schemepos >= 0)
2581 sHost = m_sRepositoryRoot.Left(m_sRepositoryRoot.Find('/', schemepos+3));
2582 CString url1 = sHost + url;
2583 TCHAR buf[INTERNET_MAX_URL_LENGTH] = { 0 };
2584 DWORD len = url.GetLength();
2585 if (UrlCanonicalize((LPCTSTR)url, buf, &len, 0) == S_OK)
2586 return CString(buf, len);
2587 return url1;
2590 return url;
2593 void CLogDlg::ShowGravatar()
2595 m_gravatar.EnableGravatar(m_bShowGravatar);
2596 RemoveAnchor(IDC_MSGVIEW);
2597 if (m_gravatar.IsGravatarEnabled())
2599 RECT rect, rect2;
2600 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(&rect);
2601 ScreenToClient(&rect);
2602 m_gravatar.GetWindowRect(&rect2);
2603 ScreenToClient(&rect2);
2604 rect.right = rect2.left;
2605 GetDlgItem(IDC_MSGVIEW)->MoveWindow(&rect);
2606 m_gravatar.ShowWindow(SW_SHOW);
2608 else
2610 RECT rect, rect2;
2611 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(&rect);
2612 ScreenToClient(&rect);
2613 m_gravatar.GetWindowRect(&rect2);
2614 ScreenToClient(&rect2);
2615 rect.right = rect2.right;
2616 GetDlgItem(IDC_MSGVIEW)->MoveWindow(&rect);
2617 m_gravatar.ShowWindow(SW_HIDE);
2619 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
2623 void CLogDlg::OnEnChangeSearchedit()
2625 UpdateData();
2626 if (!m_LogList.HasFilterText())
2628 CStoreSelection storeselection(this);
2629 // clear the filter, i.e. make all entries appear
2630 theApp.DoWaitCursor(1);
2631 KillTimer(LOGFILTER_TIMER);
2632 FillLogMessageCtrl(false);
2634 Refresh();
2635 //m_LogList.StartFilter();
2636 #if 0
2637 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2638 m_arShownList.RemoveAll();
2639 for (DWORD i=0; i<m_logEntries.size(); ++i)
2641 if (IsEntryInDateRange(i))
2642 m_arShownList.Add(m_logEntries[i]);
2644 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2645 m_LogList.DeleteAllItems();
2646 m_LogList.SetItemCountEx(ShownCountWithStopped());
2647 m_LogList.RedrawItems(0, ShownCountWithStopped());
2648 m_LogList.SetRedraw(false);
2649 ResizeAllListCtrlCols();
2650 m_LogList.SetRedraw(true);
2651 #endif
2652 theApp.DoWaitCursor(-1);
2653 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2654 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2655 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2656 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2657 return;
2659 if (Validate(m_LogList.m_sFilterText))
2660 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2661 else
2662 KillTimer(LOGFILTER_TIMER);
2666 void CLogDlg::OnBnClickedAllBranch()
2668 // m_bAllBranch is not auto-toggled by MFC, we have to handle it manually (in order to prevent the indeterminate state)
2670 m_LogList.m_ShowMask &=~ (CGit::LOG_INFO_LOCAL_BRANCHES | CGit::LOG_INFO_ALL_BRANCH);
2672 if (m_bAllBranch)
2674 m_bAllBranch = BST_UNCHECKED;
2675 m_ChangedFileListCtrl.m_sDisplayedBranch = m_LogList.GetRange();
2677 else
2679 m_bAllBranch = BST_CHECKED;
2680 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
2681 m_ChangedFileListCtrl.m_sDisplayedBranch.Empty();
2684 // need to save value here, so that log dialogs started from now on also have AllBranch activated
2685 m_regbAllBranch = m_bAllBranch;
2687 UpdateData(FALSE);
2689 OnRefresh();
2691 FillLogMessageCtrl(false);
2694 void CLogDlg::OnBnClickedFollowRenames()
2696 if(m_bFollowRenames)
2698 m_LogList.m_ShowMask |= CGit::LOG_INFO_FOLLOW;
2699 m_LogList.m_ShowMask &=~ CGit::LOG_INFO_LOCAL_BRANCHES;
2700 if (m_bAllBranch)
2703 m_bAllBranch = FALSE;
2704 m_LogList.m_ShowMask &=~ CGit::LOG_INFO_ALL_BRANCH;
2708 else
2709 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_FOLLOW;
2711 DialogEnableWindow(IDC_LOG_ALLBRANCH, !m_bFollowRenames);
2712 DialogEnableWindow(IDC_SHOWWHOLEPROJECT, !m_bFollowRenames && !m_path.IsEmpty());
2714 OnRefresh();
2716 FillLogMessageCtrl(false);
2719 void CLogDlg::HandleShowLabels(bool var, int flag)
2721 if (var)
2722 m_LogList.m_ShowRefMask |= flag;
2723 else
2724 m_LogList.m_ShowRefMask &= ~flag;
2726 if ((m_LogList.m_ShowFilter & CGitLogListBase::FILTERSHOW_REFS) && !(m_LogList.m_ShowFilter & CGitLogListBase::FILTERSHOW_ANYCOMMIT))
2728 // Remove commits where labels are not shown.
2729 OnRefresh();
2730 FillLogMessageCtrl(false);
2732 else
2734 // Just redraw
2735 m_LogList.Invalidate();
2739 void CLogDlg::OnBnClickedCompressedGraph()
2741 UpdateData();
2743 if (m_iCompressedGraph == 2)
2744 m_LogList.m_ShowFilter = CGitLogListBase::FILTERSHOW_REFS;
2745 else if (m_iCompressedGraph == 1)
2746 m_LogList.m_ShowFilter = static_cast<CGitLogListBase::FilterShow>(CGitLogListBase::FILTERSHOW_REFS | CGitLogListBase::FILTERSHOW_MERGEPOINTS);
2747 else
2748 m_LogList.m_ShowFilter = CGitLogListBase::FILTERSHOW_ALL;
2750 OnRefresh();
2751 FillLogMessageCtrl(false);
2754 void CLogDlg::OnBnClickedBrowseRef()
2756 CString newRef = CBrowseRefsDlg::PickRef(false, m_LogList.GetRange(), gPickRef_All, true);
2757 if(newRef.IsEmpty())
2758 return;
2760 m_History.AddEntry(newRef);
2761 m_History.Save();
2763 SetRange(newRef);
2765 m_LogList.m_ShowMask &= ~(CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES);
2766 m_bAllBranch = BST_UNCHECKED;
2767 UpdateData(FALSE);
2769 OnRefresh();
2770 FillLogMessageCtrl(false);
2773 void CLogDlg::ShowStartRef()
2775 //Show ref name on top
2776 if(!::IsWindow(m_hWnd))
2777 return;
2778 if (m_LogList.m_ShowMask & (CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES))
2780 switch (m_LogList.m_ShowMask & (CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES))
2782 case CGit::LOG_INFO_ALL_BRANCH:
2783 m_staticRef.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_LOG_ALLBRANCHES)));
2784 break;
2786 case CGit::LOG_INFO_LOCAL_BRANCHES:
2787 m_staticRef.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_LOG_LOCAL_BRANCHES)));
2788 break;
2791 m_staticRef.Invalidate(TRUE);
2792 m_tooltips.DelTool(GetDlgItem(IDC_STATIC_REF));
2793 return;
2796 CString showStartRef = m_LogList.GetRange();
2797 if (showStartRef.IsEmpty() || showStartRef == _T("HEAD"))
2799 showStartRef.Empty();
2800 //Ref name is HEAD
2801 if (g_Git.Run(L"git.exe symbolic-ref HEAD", &showStartRef, NULL, CP_UTF8))
2802 showStartRef = CString(MAKEINTRESOURCE(IDS_PROC_LOG_NOBRANCH));
2803 showStartRef.Trim(L"\r\n\t ");
2807 showStartRef = g_Git.StripRefName(showStartRef);
2809 m_staticRef.SetWindowText(showStartRef);
2810 CWnd *pWnd = GetDlgItem(IDC_STATIC_REF);
2811 m_tooltips.AddTool(pWnd, showStartRef);
2812 m_staticRef.Invalidate(TRUE);
2815 void CLogDlg::SetRange(const CString& range)
2817 m_LogList.SetRange(range);
2818 m_ChangedFileListCtrl.m_sDisplayedBranch = range;
2820 ShowStartRef();
2823 static void AppendMenuChecked(CMenu &menu, UINT nTextID, UINT_PTR nItemID, BOOL checked = FALSE, BOOL enabled = TRUE)
2825 CString text;
2826 text.LoadString(nTextID);
2827 menu.AppendMenu(MF_STRING | (enabled ? MF_ENABLED : MF_DISABLED) | (checked ? MF_CHECKED : MF_UNCHECKED), nItemID, text);
2830 #define WALKBEHAVIOUR_FIRSTPARENT 1
2831 #define WALKBEHAVIOUR_FOLLOWRENAMES 2
2832 #define WALKBEHAVIOUR_COMPRESSEDGRAPH 3
2833 #define WALKBEHAVIOUR_LABELEDCOMMITS 4
2834 #define WALKBEHAVIOUR_NOMERGES 5
2836 void CLogDlg::OnBnClickedWalkBehaviour()
2838 CMenu popup;
2839 if (popup.CreatePopupMenu())
2841 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_FIRSTPARENT, WALKBEHAVIOUR_FIRSTPARENT, m_bFirstParent);
2842 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_NOMERGES, WALKBEHAVIOUR_NOMERGES, m_bNoMerges);
2843 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_FOLLOWRENAMES, WALKBEHAVIOUR_FOLLOWRENAMES, m_bFollowRenames, !(m_path.IsEmpty() || m_path.IsDirectory()));
2844 popup.AppendMenu(MF_SEPARATOR, NULL);
2845 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_COMPRESSED, WALKBEHAVIOUR_COMPRESSEDGRAPH, m_iCompressedGraph == 1);
2846 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_LABELEDCOMMITS, WALKBEHAVIOUR_LABELEDCOMMITS, m_iCompressedGraph == 2);
2848 m_tooltips.Pop();
2849 RECT rect;
2850 GetDlgItem(IDC_WALKBEHAVIOUR)->GetWindowRect(&rect);
2851 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, rect.left, rect.top, this, 0);
2852 switch (selection)
2854 case WALKBEHAVIOUR_FIRSTPARENT:
2855 m_bFirstParent = !m_bFirstParent;
2856 OnBnClickedFirstParent();
2857 break;
2858 case WALKBEHAVIOUR_NOMERGES:
2859 m_bNoMerges = !m_bNoMerges;
2860 OnBnClickedFirstParent(); // OnBnClickedFirstParent handles both cases: m_bFirstParent and m_bNoMerges
2861 break;
2862 case WALKBEHAVIOUR_FOLLOWRENAMES:
2863 m_bFollowRenames = !m_bFollowRenames;
2864 OnBnClickedFollowRenames();
2865 break;
2866 case WALKBEHAVIOUR_COMPRESSEDGRAPH:
2867 m_iCompressedGraph = (m_iCompressedGraph == 1 ? 0 : 1);
2868 OnBnClickedCompressedGraph();
2869 break;
2870 case WALKBEHAVIOUR_LABELEDCOMMITS:
2871 m_iCompressedGraph = (m_iCompressedGraph == 2 ? 0 : 2);
2872 OnBnClickedCompressedGraph();
2873 break;
2874 default:
2875 break;
2877 m_bWalkBehavior = (m_bFirstParent || m_bNoMerges || m_bFollowRenames || m_iCompressedGraph);
2878 UpdateData(FALSE);
2882 #define VIEW_HIDEPATHS 1
2883 #define VIEW_GRAYPATHS 2
2884 #define VIEW_SHOWTAGS 3
2885 #define VIEW_SHOWLOCALBRANCHES 4
2886 #define VIEW_SHOWREMOTEBRANCHES 5
2887 #define VIEW_SHOWGRAVATAR 6
2888 #define VIEW_SHOWPATCH 7
2890 void CLogDlg::OnBnClickedView()
2892 CMenu popup;
2893 if (popup.CreatePopupMenu())
2895 AppendMenuChecked(popup, IDS_SHOWFILES_HIDEPATHS, VIEW_HIDEPATHS, m_iHidePaths == 1);
2896 AppendMenuChecked(popup, IDS_SHOWFILES_GRAYPATHS, VIEW_GRAYPATHS, m_iHidePaths == 2);
2897 popup.AppendMenu(MF_SEPARATOR, NULL);
2898 CMenu showLabelsMenu;
2899 if (showLabelsMenu.CreatePopupMenu())
2901 AppendMenuChecked(showLabelsMenu, IDS_VIEW_SHOWTAGLABELS, VIEW_SHOWTAGS, m_bShowTags);
2902 AppendMenuChecked(showLabelsMenu, IDS_VIEW_SHOWLOCALBRANCHLABELS, VIEW_SHOWLOCALBRANCHES, m_bShowLocalBranches);
2903 AppendMenuChecked(showLabelsMenu, IDS_VIEW_SHOWREMOTEBRANCHLABELS, VIEW_SHOWREMOTEBRANCHES, m_bShowRemoteBranches);
2904 popup.AppendMenu(MF_STRING | MF_POPUP, (UINT)showLabelsMenu.m_hMenu, (CString)MAKEINTRESOURCE(IDS_VIEW_LABELS));
2906 popup.AppendMenu(MF_SEPARATOR, NULL);
2907 AppendMenuChecked(popup, IDS_VIEW_SHOWGRAVATAR, VIEW_SHOWGRAVATAR, m_bShowGravatar);
2908 AppendMenuChecked(popup, IDS_MENU_VIEWPATCH, VIEW_SHOWPATCH, IsWindow(this->m_patchViewdlg.m_hWnd));
2910 m_tooltips.Pop();
2911 RECT rect;
2912 GetDlgItem(IDC_VIEW)->GetWindowRect(&rect);
2913 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, rect.left, rect.top, this, 0);
2914 switch (selection)
2916 case VIEW_HIDEPATHS:
2917 if (m_iHidePaths == 1)
2918 m_iHidePaths = 0;
2919 else
2920 m_iHidePaths = 1;
2921 OnBnClickedHidepaths();
2922 break;
2923 case VIEW_GRAYPATHS:
2924 if (m_iHidePaths == 2)
2925 m_iHidePaths = 0;
2926 else
2927 m_iHidePaths = 2;
2928 OnBnClickedHidepaths();
2929 break;
2930 case VIEW_SHOWTAGS:
2931 m_bShowTags = !m_bShowTags;
2932 HandleShowLabels(m_bShowTags, LOGLIST_SHOWTAGS);
2933 break;
2934 case VIEW_SHOWLOCALBRANCHES:
2935 m_bShowLocalBranches = !m_bShowLocalBranches;
2936 HandleShowLabels(m_bShowLocalBranches, LOGLIST_SHOWLOCALBRANCHES);
2937 break;
2938 case VIEW_SHOWREMOTEBRANCHES:
2939 m_bShowRemoteBranches = !m_bShowRemoteBranches;
2940 HandleShowLabels(m_bShowRemoteBranches, LOGLIST_SHOWREMOTEBRANCHES);
2941 break;
2942 case VIEW_SHOWGRAVATAR:
2944 m_bShowGravatar = !m_bShowGravatar;
2945 ShowGravatar();
2946 m_gravatar.Init();
2947 CString email;
2948 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2949 if (pos)
2951 int selIndex = m_LogList.GetNextSelectedItem(pos);
2952 int moreSel = m_LogList.GetNextSelectedItem(pos);
2953 if (moreSel < 0)
2955 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
2956 if (pLogEntry)
2957 email = pLogEntry->GetAuthorEmail();
2960 m_gravatar.LoadGravatar(email);
2961 break;
2963 case VIEW_SHOWPATCH:
2964 TogglePatchView();
2965 break;
2966 default:
2967 break;
2972 void CLogDlg::OnBnClickedFirstParent()
2974 if(this->m_bFirstParent)
2975 m_LogList.m_ShowMask|=CGit::LOG_INFO_FIRST_PARENT;
2976 else
2977 m_LogList.m_ShowMask&=~CGit::LOG_INFO_FIRST_PARENT;
2979 if (m_bNoMerges)
2980 m_LogList.m_ShowMask |= CGit::LOG_INFO_NO_MERGE;
2981 else
2982 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_NO_MERGE;
2984 OnRefresh();
2986 FillLogMessageCtrl(false);
2990 void CLogDlg::OnBnClickShowWholeProject()
2992 this->UpdateData();
2994 if(this->m_bWholeProject)
2996 m_LogList.m_Path.Reset();
2997 SetDlgTitle();
2999 else
3000 m_LogList.m_Path=m_path;
3002 m_regShowWholeProject = m_bWholeProject;
3004 SetDlgTitle();
3006 OnRefresh();
3008 FillLogMessageCtrl(false);
3012 LRESULT CLogDlg::OnRefLogChanged(WPARAM /*wParam*/, LPARAM /*lParam*/)
3014 ShowStartRef();
3015 return 0;
3018 LRESULT CLogDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
3020 m_pTaskbarList.Release();
3021 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
3022 SetUUIDOverlayIcon(m_hWnd);
3023 return 0;
3026 LRESULT CLogDlg::OnRefreshSelection(WPARAM /*wParam*/, LPARAM /*lParam*/)
3028 // it's enough to deselect, then select again one item of the whole selection
3029 int selMark = m_LogList.GetSelectionMark();
3030 if (selMark >= 0)
3032 m_LogList.SetSelectionMark(selMark);
3033 m_LogList.SetItemState(selMark, 0, LVIS_SELECTED);
3034 m_LogList.SetItemState(selMark, LVIS_SELECTED, LVIS_SELECTED);
3036 return 0;