StatsGraph: Make a local copy of rev list so that we can directly sort it
[TortoiseGit.git] / src / TortoiseProc / LogDlg.cpp
blob59f14fb27c24d16cd4c03babb12b398e089daca6
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2009, 2015 - TortoiseSVN
4 // Copyright (C) 2008-2017 - 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 "StatGraphDlg.h"
23 #include "LogDlg.h"
24 #include "MessageBox.h"
25 #include "AppUtils.h"
26 #include "StringUtils.h"
27 #include "UnicodeUtils.h"
28 #include "TempFile.h"
29 #include "IconMenu.h"
30 #include "BrowseRefsDlg.h"
31 #include "SmartHandle.h"
32 #include "LogOrdering.h"
33 #include "ClipboardHelper.h"
35 #define WM_TGIT_REFRESH_SELECTION (WM_APP + 1)
37 IMPLEMENT_DYNAMIC(CLogDlg, CResizableStandAloneDialog)
38 CLogDlg::CLogDlg(CWnd* pParent /*=nullptr*/)
39 : CResizableStandAloneDialog(CLogDlg::IDD, pParent)
40 , m_wParam(0)
41 , m_nSortColumn(0)
42 , m_bFollowRenames(false)
43 , m_bSelect(false)
44 , m_bSelectionMustBeSingle(true)
45 , m_bShowTags(true)
46 , m_bShowLocalBranches(true)
47 , m_bShowRemoteBranches(true)
48 , m_bNoMerges(false)
49 , m_iHidePaths(0)
50 , m_bFirstParent(false)
51 , m_bWholeProject(FALSE)
52 , m_iCompressedGraph(0)
53 , m_bShowWC(true)
55 , m_bSelectionMustBeContinuous(false)
57 , m_bCancelled(FALSE)
58 , m_pNotifyWindow(nullptr)
60 , m_bAscending(FALSE)
61 , m_hAccel(nullptr)
62 , m_bNavigatingWithSelect(false)
64 m_bFilterWithRegex = !!CRegDWORD(L"Software\\TortoiseGit\\UseRegexFilter", FALSE);
65 m_bFilterCaseSensitively = !!CRegDWORD(L"Software\\TortoiseGit\\FilterCaseSensitively", FALSE);
66 m_bAsteriskLogPrefix = !!CRegDWORD(L"Software\\TortoiseGit\\AsteriskLogPrefix", TRUE);
67 m_LogList.m_SelectedFilters = CRegDWORD(L"Software\\TortoiseGit\\SelectedLogFilters", LOGFILTER_ALL);
69 CString str = g_Git.m_CurrentDir;
70 str.Replace(L':', L'_');
72 m_regbAllBranch = CRegDWORD(L"Software\\TortoiseGit\\LogDialog\\AllBranch\\" + str, FALSE);
73 m_AllBranchType = (AllBranchType)(DWORD)m_regbAllBranch;
74 switch (m_AllBranchType)
76 case AllBranchType::None:
77 m_bAllBranch = FALSE;
78 break;
79 case AllBranchType::AllBranches:
80 m_bAllBranch = TRUE;
81 break;
82 default:
83 m_bAllBranch = BST_INDETERMINATE;
86 m_regShowWholeProject = CRegDWORD(L"Software\\TortoiseGit\\TortoiseProc\\ShowWholeProject\\" + str, FALSE);
87 m_bWholeProject = m_regShowWholeProject;
88 m_regbShowTags = CRegDWORD(L"Software\\TortoiseGit\\LogDialog\\ShowTags\\" + str, TRUE);
89 m_bShowTags = !!m_regbShowTags;
90 m_regbShowLocalBranches = CRegDWORD(L"Software\\TortoiseGit\\LogDialog\\ShowLocalBranches\\" + str, TRUE);
91 m_bShowLocalBranches = !!m_regbShowLocalBranches;
92 m_regbShowRemoteBranches = CRegDWORD(L"Software\\TortoiseGit\\LogDialog\\ShowRemoteBranches\\" + str, TRUE);
93 m_bShowRemoteBranches = !!m_regbShowRemoteBranches;
95 m_regAddBeforeCommit = CRegDWORD(L"Software\\TortoiseGit\\AddBeforeCommit", TRUE);
96 m_bShowUnversioned = !!m_regAddBeforeCommit;
98 m_bShowGravatar = !!CRegDWORD(L"Software\\TortoiseGit\\EnableGravatar", FALSE);
99 m_regbShowGravatar = CRegDWORD(L"Software\\TortoiseGit\\LogDialog\\ShowGravatar\\" + str, m_bShowGravatar);
100 m_bShowGravatar = !!m_regbShowGravatar;
101 m_bShowDescribe = !!CRegDWORD(L"Software\\TortoiseGit\\ShowDescribe");
102 m_bShowBranchRevNo = !!CRegDWORD(L"Software\\TortoiseGit\\ShowBranchRevisionNumber", FALSE);
105 CLogDlg::~CLogDlg()
107 m_regbAllBranch = (DWORD)m_AllBranchType;
108 m_regbShowTags = m_bShowTags;
109 m_regbShowLocalBranches = m_bShowLocalBranches;
110 m_regbShowRemoteBranches = m_bShowRemoteBranches;
111 m_regbShowGravatar = m_bShowGravatar;
112 m_regAddBeforeCommit = m_bShowUnversioned;
115 void CLogDlg::DoDataExchange(CDataExchange* pDX)
117 CResizableStandAloneDialog::DoDataExchange(pDX);
118 DDX_Control(pDX, IDC_LOGLIST, m_LogList);
119 DDX_Control(pDX, IDC_LOGMSG, m_ChangedFileListCtrl);
120 DDX_Control(pDX, IDC_PROGRESS, m_LogProgress);
121 DDX_Control(pDX, IDC_SPLITTERTOP, m_wndSplitter1);
122 DDX_Control(pDX, IDC_SPLITTERBOTTOM, m_wndSplitter2);
123 DDX_Text(pDX, IDC_SEARCHEDIT, m_LogList.m_sFilterText);
124 DDX_Control(pDX, IDC_DATEFROM, m_DateFrom);
125 DDX_Control(pDX, IDC_DATETO, m_DateTo);
126 DDX_Control(pDX, IDC_LOG_JUMPTYPE, m_JumpType);
127 DDX_Control(pDX, IDC_LOG_JUMPUP, m_JumpUp);
128 DDX_Control(pDX, IDC_LOG_JUMPDOWN, m_JumpDown);
129 DDX_Text(pDX, IDC_LOGINFO, m_sLogInfo);
130 DDX_Check(pDX, IDC_LOG_ALLBRANCH,m_bAllBranch);
131 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
132 DDX_Control(pDX, IDC_WALKBEHAVIOUR, m_ctrlWalkBehavior);
133 DDX_Control(pDX, IDC_VIEW, m_ctrlView);
134 DDX_Control(pDX, IDC_SEARCHEDIT, m_cFilter);
135 DDX_Control(pDX, IDC_STATIC_REF, m_staticRef);
136 DDX_Control(pDX, IDC_PIC_AUTHOR, m_gravatar);
137 DDX_Control(pDX, IDC_FILTER, m_cFileFilter);
140 BEGIN_MESSAGE_MAP(CLogDlg, CResizableStandAloneDialog)
141 ON_WM_CONTEXTMENU()
142 ON_WM_SETCURSOR()
143 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOGLIST, OnLvnItemchangedLoglist)
144 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOGMSG, OnLvnItemchangedLogmsg)
145 ON_NOTIFY(EN_LINK, IDC_MSGVIEW, OnEnLinkMsgview)
146 ON_EN_VSCROLL(IDC_MSGVIEW, OnEnscrollMsgview)
147 ON_EN_HSCROLL(IDC_MSGVIEW, OnEnscrollMsgview)
148 ON_BN_CLICKED(IDC_STATBUTTON, OnBnClickedStatbutton)
150 ON_MESSAGE(WM_TGIT_REFRESH_SELECTION, OnRefreshSelection)
151 ON_MESSAGE(WM_FILTEREDIT_INFOCLICKED, OnClickedInfoIcon)
152 ON_MESSAGE(WM_FILTEREDIT_CANCELCLICKED, OnClickedCancelFilter)
154 ON_MESSAGE(MSG_LOAD_PERCENTAGE,OnLogListLoading)
156 ON_EN_CHANGE(IDC_SEARCHEDIT, OnEnChangeSearchedit)
157 ON_WM_TIMER()
158 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETO, OnDtnDatetimechangeDateto)
159 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATEFROM, OnDtnDatetimechangeDatefrom)
160 ON_CBN_SELCHANGE(IDC_LOG_JUMPTYPE, &CLogDlg::OnCbnSelchangeJumpType)
161 ON_COMMAND(IDC_LOG_JUMPUP, &CLogDlg::OnBnClickedJumpUp)
162 ON_COMMAND(IDC_LOG_JUMPDOWN, &CLogDlg::OnBnClickedJumpDown)
163 ON_COMMAND(ID_GO_UP, &CLogDlg::OnBnClickedJumpUp)
164 ON_COMMAND(ID_GO_DOWN, &CLogDlg::OnBnClickedJumpDown)
165 ON_COMMAND(ID_EXITCLEARFILTER, OnExitClearFilter)
166 ON_BN_CLICKED(IDC_WALKBEHAVIOUR, OnBnClickedWalkBehaviour)
167 ON_BN_CLICKED(IDC_VIEW, OnBnClickedView)
168 ON_BN_CLICKED(IDC_WHOLE_PROJECT, OnBnClickShowWholeProject)
169 ON_NOTIFY(LVN_COLUMNCLICK,IDC_LOGLIST, OnLvnColumnclick)
170 ON_COMMAND(MSG_FETCHED_DIFF, OnBnClickedHidepaths)
171 ON_BN_CLICKED(IDC_LOG_ALLBRANCH, OnBnClickedAllBranch)
172 ON_EN_CHANGE(IDC_FILTER, OnEnChangeFileFilter)
174 ON_NOTIFY(DTN_DROPDOWN, IDC_DATEFROM, &CLogDlg::OnDtnDropdownDatefrom)
175 ON_WM_SIZE()
176 ON_BN_CLICKED(IDC_REFRESH, &CLogDlg::OnBnClickedRefresh)
177 ON_STN_CLICKED(IDC_STATIC_REF, &CLogDlg::OnBnClickedBrowseRef)
178 ON_COMMAND(ID_LOGDLG_REFRESH, &CLogDlg::OnBnClickedRefresh)
179 ON_COMMAND(ID_GO_BACKWARD_SELECT, &CLogDlg::GoBackAndSelect)
180 ON_COMMAND(ID_GO_FORWARD_SELECT, &CLogDlg::GoForwardAndSelect)
181 ON_COMMAND(ID_GO_BACKWARD, &CLogDlg::GoBack)
182 ON_COMMAND(ID_GO_FORWARD, &CLogDlg::GoForward)
183 ON_COMMAND(ID_SELECT_SEARCHFIELD, &CLogDlg::OnSelectSearchField)
184 ON_COMMAND(ID_LOGDLG_FIND, &CLogDlg::OnFind)
185 ON_COMMAND(ID_LOGDLG_FOCUSFILTER, &CLogDlg::OnFocusFilter)
186 ON_COMMAND(ID_EDIT_COPY, &CLogDlg::OnEditCopy)
187 ON_MESSAGE(MSG_REFLOG_CHANGED, OnRefLogChanged)
188 ON_REGISTERED_MESSAGE(TaskBarButtonCreated, OnTaskbarBtnCreated)
190 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED, &CLogDlg::OnFileListCtrlItemChanged)
191 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)
192 ON_WM_MOVE()
193 ON_WM_MOVING()
194 ON_WM_SIZING()
195 ON_WM_CTLCOLOR()
196 ON_WM_PAINT()
197 END_MESSAGE_MAP()
199 enum JumpType
201 JumpType_AuthorEmail,
202 JumpType_CommitterEmail,
203 JumpType_MergePoint,
204 JumpType_Parent1,
205 JumpType_Parent2,
206 JumpType_Tag,
207 JumpType_TagFF,
208 JumpType_Branch,
209 JumpType_BranchFF,
210 JumpType_History,
213 LRESULT CLogDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
215 if (m_LogList.m_hasWC && m_LogList.GetSelectedCount() == 1)
217 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
218 size_t selIndex = m_LogList.GetNextSelectedItem(pos);
219 GitRevLoglist* pLogEntry = m_LogList.m_arShownList.SafeGetAt(selIndex);
220 if (pLogEntry && pLogEntry->m_CommitHash.IsEmpty())
221 m_ChangedFileListCtrl.StoreScrollPos();
223 m_LogList.ResetWcRev(true);
224 m_LogList.Invalidate();
225 return 0;
228 void CLogDlg::SetParams(const CTGitPath& orgPath, const CTGitPath& path, CString hightlightRevision, CString range, DWORD limit, int limitScale/*=-1*/)
230 m_orgPath = orgPath;
231 m_path = path;
232 m_hightlightRevision = hightlightRevision;
234 if (range == GIT_REV_ZERO)
235 range = L"HEAD";
237 if (!(range.IsEmpty() || range == L"HEAD"))
239 m_bAllBranch = BST_UNCHECKED;
240 m_AllBranchType = AllBranchType::None;
243 SetRange(range);
245 if (limitScale == CFilterData::SHOW_NO_LIMIT || (!range.IsEmpty() && m_LogList.m_Filter.m_NumberOfLogsScale != CFilterData::SHOW_LAST_N_COMMITS))
246 m_LogList.m_Filter.m_NumberOfLogsScale = CFilterData::SHOW_NO_LIMIT;
247 if (limitScale >= CFilterData::SHOW_LAST_N_COMMITS && limit > 0)
249 // limitation from command line argument, so override the filter.
250 m_LogList.m_Filter.m_NumberOfLogs = limit;
251 m_LogList.m_Filter.m_NumberOfLogsScale = limitScale;
254 if (::IsWindow(m_hWnd))
255 UpdateData(FALSE);
258 void CLogDlg::SetFilter(const CString& findstr, LONG findtype, bool findregex)
260 m_LogList.m_sFilterText = findstr;
261 if (findtype)
262 m_LogList.m_SelectedFilters = findtype;
263 m_LogList.m_bFilterWithRegex = m_bFilterWithRegex = findregex;
266 BOOL CLogDlg::OnInitDialog()
268 CString temp;
269 CResizableStandAloneDialog::OnInitDialog();
270 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
272 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
273 // do this, Explorer would be unable to send that message to our window if we
274 // were running elevated. It's OK to make the call all the time, since if we're
275 // not elevated, this is a no-op.
276 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
277 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
278 CAutoLibrary hUser = AtlLoadSystemLibraryUsingFullPath(L"user32.dll");
279 if (hUser)
281 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
282 if (pfnChangeWindowMessageFilterEx)
284 pfnChangeWindowMessageFilterEx(m_hWnd, TaskBarButtonCreated, MSGFLT_ALLOW, &cfs);
287 m_pTaskbarList.Release();
288 if (FAILED(m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList)))
289 m_pTaskbarList = nullptr;
291 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_LOGDLG));
293 // use the state of the "stop on copy/rename" option from the last time
294 UpdateData(FALSE);
296 // set the font to use in the log message view, configured in the settings dialog
297 CAppUtils::CreateFontForLogs(m_logFont);
298 GetDlgItem(IDC_MSGVIEW)->SetFont(&m_logFont);
299 // make the log message rich edit control send a message when the mouse pointer is over a link
300 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_SETEVENTMASK, NULL, ENM_LINK | ENM_SCROLL);
302 // "unrelated paths" should be in gray color
303 m_iHidePaths = 2;
305 // set up the columns
306 m_LogList.DeleteAllItems();
308 m_LogList.m_Path=m_path;
309 m_LogList.m_hasWC = !GitAdminDir::IsBareRepo(g_Git.m_CurrentDir);
310 m_LogList.m_bShowWC = m_LogList.m_hasWC && m_bShowWC;
311 m_LogList.InsertGitColumn();
313 if (m_bWholeProject)
314 m_LogList.m_Path.Reset();
316 m_ChangedFileListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS | GITSLC_COLADD | GITSLC_COLDEL, L"LogDlg", (GITSLC_POPALL ^ (GITSLC_POPIGNORE | GITSLC_POPRESTORE)), false, m_LogList.m_hasWC, GITSLC_COLEXT | GITSLC_COLSTATUS | GITSLC_COLADD| GITSLC_COLDEL);
318 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
320 SetDlgTitle();
322 CheckRegexpTooltip();
324 SetSplitterRange();
326 // the filter control has a 'cancel' button (the red 'X'), we need to load its bitmap
327 m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED, 14, 14);
328 m_cFilter.SetInfoIcon(IDI_LOGFILTER, 19, 19);
329 m_cFilter.SetValidator(this);
331 AdjustControlSize(IDC_LOG_ALLBRANCH);
332 AdjustControlSize(IDC_WHOLE_PROJECT);
334 GetClientRect(m_DlgOrigRect);
335 m_LogList.GetClientRect(m_LogListOrigRect);
336 GetDlgItem(IDC_MSGVIEW)->GetClientRect(m_MsgViewOrigRect);
337 m_ChangedFileListCtrl.GetClientRect(m_ChgOrigRect);
339 m_Brush.CreateSolidBrush(RGB(174, 200, 255));
341 m_DateFrom.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
342 m_DateTo.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS | MCS_NOTRAILINGDATES | MCS_NOSELCHANGEONNAV);
344 m_staticRef.SetURL(CString());
346 AddMainAnchors();
347 SetFilterCueText();
349 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_LOCAL_BRANCHES;
350 if (m_AllBranchType == AllBranchType::AllBranches)
351 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
352 else if (m_AllBranchType == AllBranchType::AllLocalBranches)
353 m_LogList.m_ShowMask |= CGit::LOG_INFO_LOCAL_BRANCHES;
354 else if (m_AllBranchType == AllBranchType::AllBasicRefs)
355 m_LogList.m_ShowMask |= CGit::LOG_INFO_BASIC_REFS;
356 else
357 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
359 HandleShowLabels(m_bShowTags, LOGLIST_SHOWTAGS);
360 HandleShowLabels(m_bShowLocalBranches, LOGLIST_SHOWLOCALBRANCHES);
361 HandleShowLabels(m_bShowRemoteBranches, LOGLIST_SHOWREMOTEBRANCHES);
363 // SetPromptParentWindow(m_hWnd);
364 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_AUTHOREMAIL)));
365 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_COMMITTEREMAIL)));
366 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_MERGEPOINT)));
367 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_PARENT1)));
368 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_PARENT2)));
369 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_TAG)));
370 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_TAG_FF)));
371 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_BRANCH)));
372 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_BRANCH_FF)));
373 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_SELECTION_HISTORY)));
374 m_JumpType.SetCurSel(0);
375 int iconWidth = GetSystemMetrics(SM_CXSMICON);
376 int iconHeight = GetSystemMetrics(SM_CYSMICON);
377 m_JumpUp.SetIcon((HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_JUMPUP), IMAGE_ICON, iconWidth, iconHeight, LR_DEFAULTCOLOR));
378 m_JumpDown.SetIcon((HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_JUMPDOWN), IMAGE_ICON, iconWidth, iconHeight, LR_DEFAULTCOLOR));
380 if (hWndExplorer)
381 CenterWindow(CWnd::FromHandle(hWndExplorer));
382 EnableSaveRestore(L"LogDlg");
384 DWORD yPos1 = CRegDWORD(L"Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1");
385 DWORD yPos2 = CRegDWORD(L"Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2");
386 RECT rcDlg, rcLogList, rcChgMsg;
387 GetClientRect(&rcDlg);
388 m_LogList.GetWindowRect(&rcLogList);
389 ScreenToClient(&rcLogList);
390 m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg);
391 ScreenToClient(&rcChgMsg);
392 if (yPos1 && ((LONG)yPos1 < rcDlg.bottom - 185))
394 RECT rectSplitter;
395 m_wndSplitter1.GetWindowRect(&rectSplitter);
396 ScreenToClient(&rectSplitter);
397 int delta = yPos1 - rectSplitter.top;
399 if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30))
401 m_wndSplitter1.SetWindowPos(nullptr, rectSplitter.left, yPos1, 0, 0, SWP_NOSIZE);
402 DoSizeV1(delta);
405 if (yPos2 && ((LONG)yPos2 < rcDlg.bottom - 153))
407 RECT rectSplitter;
408 m_wndSplitter2.GetWindowRect(&rectSplitter);
409 ScreenToClient(&rectSplitter);
410 int delta = yPos2 - rectSplitter.top;
412 if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30))
414 m_wndSplitter2.SetWindowPos(nullptr, rectSplitter.left, yPos2, 0, 0, SWP_NOSIZE);
415 DoSizeV2(delta);
419 SetSplitterRange();
421 if (m_bSelect)
423 // the dialog is used to select revisions
424 // enable the OK button if appropriate
425 EnableOKButton();
427 else
429 // the dialog is used to just view log messages
430 // hide the OK button and set text on Cancel button to OK
431 GetDlgItemText(IDOK, temp);
432 SetDlgItemText(IDCANCEL, temp);
433 GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
436 // first start a thread to obtain the log messages without
437 // blocking the dialog
438 //m_tTo = 0;
439 //m_tFrom = (DWORD)-1;
441 // scroll to user selected or current revision
442 if (m_hightlightRevision.IsEmpty() || g_Git.GetHash(m_LogList.m_lastSelectedHash, m_hightlightRevision))
444 if (g_Git.GetHash(m_LogList.m_lastSelectedHash, L"HEAD"))
445 MessageBox(g_Git.GetGitLastErr(L"Could not get HEAD hash."), L"TortoiseGit", MB_ICONERROR);
448 if (g_Git.GetConfigValueBool(L"tgit.logshowpatch"))
449 TogglePatchView();
451 m_LogList.FetchLogAsync(this);
452 ShowGravatar();
453 m_gravatar.Init();
455 m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED, 14, 14);
456 m_cFilter.SetInfoIcon(IDI_LOGFILTER, 19, 19);
457 temp.LoadString(IDS_FILEDIFF_FILTERCUE);
458 temp = L" " + temp;
459 m_cFileFilter.SetCueBanner(temp);
461 GetDlgItem(IDC_LOGLIST)->SetFocus();
463 m_History.SetMaxHistoryItems((LONG)CRegDWORD(L"Software\\TortoiseGit\\MaxRefHistoryItems", 5));
464 CString reg;
465 reg.Format(L"Software\\TortoiseGit\\History\\log-refs\\%s", (LPCTSTR)g_Git.m_CurrentDir);
466 reg.Replace(L':', L'_');
467 m_History.Load(reg, L"ref");
469 reg.Format(L"Software\\TortoiseGit\\History\\LogDlg_Limits\\%s\\FromDate", (LPCTSTR)g_Git.m_CurrentDir);
470 reg.Replace(L':', L'_');
471 m_regLastSelectedFromDate = CRegString(reg);
473 m_ctrlWalkBehavior.m_bAlwaysShowArrow = true;
474 m_ctrlView.m_bAlwaysShowArrow = true;
476 ShowStartRef();
477 return FALSE;
480 HBRUSH CLogDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
482 HBRUSH hbr = __super::OnCtlColor(pDC, pWnd, nCtlColor);
484 if ((m_LogList.m_Filter.m_NumberOfLogsScale >= CFilterData::SHOW_LAST_N_COMMITS || m_LogList.m_Filter.m_NumberOfLogsScale == CFilterData::SHOW_LAST_SEL_DATE && m_LogList.m_Filter.m_From != -1) && pWnd->GetDlgCtrlID() == IDC_FROMLABEL)
486 pDC->SetBkMode(TRANSPARENT);
487 return m_Brush;
490 return hbr;
493 void CLogDlg::OnPaint()
495 CPaintDC dc(this);
497 if (!(m_LogList.m_Filter.m_NumberOfLogsScale >= CFilterData::SHOW_LAST_N_COMMITS || m_LogList.m_Filter.m_NumberOfLogsScale == CFilterData::SHOW_LAST_SEL_DATE && m_LogList.m_Filter.m_From != -1))
498 return;
500 CWnd* pWnd = GetDlgItem(IDC_FROMLABEL);
501 if (!pWnd)
502 return;
504 CRect rect;
505 pWnd->GetWindowRect(&rect);
506 ScreenToClient(rect);
507 rect.left -= 5;
508 rect.top -= 3;
509 rect.bottom += 3;
511 dc.FillRect(rect, &m_Brush);
514 LRESULT CLogDlg::OnLogListLoading(WPARAM wParam, LPARAM /*lParam*/)
516 int cur=(int)wParam;
518 if( cur == GITLOG_START )
520 CString temp;
521 temp.LoadString(IDS_PROGRESSWAIT);
523 this->m_LogList.ShowText(temp, true);
525 // We use a progress bar while getting the logs
526 m_LogProgress.SetRange32(0, 100);
527 m_LogProgress.SetPos(0);
528 if (m_pTaskbarList)
530 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
531 m_pTaskbarList->SetProgressValue(m_hWnd, 0, 100);
534 GetDlgItem(IDC_WALKBEHAVIOUR)->ShowWindow(SW_HIDE);
535 GetDlgItem(IDC_VIEW)->ShowWindow(SW_HIDE);
536 GetDlgItem(IDC_STATBUTTON)->ShowWindow(SW_HIDE);
537 GetDlgItem(IDC_PROGRESS)->ShowWindow(TRUE);
539 DialogEnableWindow(IDC_WALKBEHAVIOUR, FALSE);
540 DialogEnableWindow(IDC_STATBUTTON, FALSE);
541 //DialogEnableWindow(IDC_REFRESH, FALSE);
542 DialogEnableWindow(IDC_VIEW, FALSE);
545 else if( cur == GITLOG_END)
547 if(this->m_LogList.HasText())
549 this->m_LogList.ClearText();
551 UpdateLogInfoLabel();
553 if (m_pTaskbarList)
554 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
556 DialogEnableWindow(IDC_WHOLE_PROJECT, !m_bFollowRenames && !m_path.IsEmpty());
558 DialogEnableWindow(IDC_STATBUTTON, !(m_LogList.m_arShownList.empty() || m_LogList.m_arShownList.size() == 1 && m_LogList.m_bShowWC));
559 DialogEnableWindow(IDC_REFRESH, TRUE);
560 DialogEnableWindow(IDC_VIEW, TRUE);
561 DialogEnableWindow(IDC_WALKBEHAVIOUR, TRUE);
562 // PostMessage(WM_TIMER, LOGFILTER_TIMER);
563 GetDlgItem(IDC_WALKBEHAVIOUR)->ShowWindow(SW_SHOW);
564 GetDlgItem(IDC_VIEW)->ShowWindow(SW_SHOW);
565 GetDlgItem(IDC_STATBUTTON)->ShowWindow(SW_SHOW);
566 GetDlgItem(IDC_PROGRESS)->ShowWindow(FALSE);
567 //CTime time=m_LogList.GetOldestTime();
568 CTime begin,end;
569 m_LogList.GetTimeRange(begin,end);
571 if (m_LogList.m_Filter.m_From > 0 && m_LogList.m_Filter.m_NumberOfLogsScale >= CFilterData::SHOW_LAST_SEL_DATE)
572 begin = m_LogList.m_Filter.m_From;
573 m_DateFrom.SetTime(&begin);
574 if (m_LogList.m_Filter.m_To != -1)
575 end = m_LogList.m_Filter.m_To;
576 m_DateTo.SetTime(&end);
577 Invalidate();
579 else
581 if(this->m_LogList.HasText())
583 this->m_LogList.ClearText();
584 this->m_LogList.Invalidate();
586 UpdateLogInfoLabel();
587 m_LogProgress.SetPos(cur);
588 if (m_pTaskbarList)
590 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
591 m_pTaskbarList->SetProgressValue(m_hWnd, cur, 100);
594 return 0;
596 void CLogDlg::SetDlgTitle()
598 if (m_sTitle.IsEmpty())
599 GetWindowText(m_sTitle);
601 if (m_LogList.m_Path.IsEmpty() || m_orgPath.GetWinPathString().IsEmpty())
602 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
603 else
604 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);
607 void CLogDlg::CheckRegexpTooltip()
609 CWnd *pWnd = GetDlgItem(IDC_SEARCHEDIT);
610 // Since tooltip describes regexp features, show it only if regexps are enabled.
611 if (m_bFilterWithRegex)
612 m_tooltips.AddTool(pWnd, IDS_LOG_FILTER_REGEX_TT);
613 else
614 m_tooltips.DelTool(pWnd);
617 void CLogDlg::EnableOKButton()
619 if (m_bSelect)
621 // the dialog is used to select revisions
622 if (m_bSelectionMustBeSingle)
624 // enable OK button if only a single revision is selected
625 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()==1));
627 else if (m_bSelectionMustBeContinuous)
628 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));
629 else
630 DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);
632 else
633 DialogEnableWindow(IDOK, TRUE);
636 bool LookLikeGitHash(const CString& msg, int &pos)
638 int c = 0;
639 for (; pos < msg.GetLength(); ++pos)
641 if (msg[pos] >= '0' && msg[pos] <= '9' || msg[pos] >= 'a' && msg[pos] <= 'f')
642 c++;
643 else
644 return c >= g_Git.GetShortHASHLength() && c <= GIT_HASH_SIZE * 2 && msg[pos] != '@';
646 return c >= g_Git.GetShortHASHLength() && c <= GIT_HASH_SIZE * 2;
649 std::vector<CHARRANGE> FindGitHashPositions(const CString& msg, int offset)
651 std::vector<CHARRANGE> result;
652 offset = offset < 0 ? 0 : offset;
653 int old = offset;
654 while (offset < msg.GetLength())
656 old = offset;
657 TCHAR e = msg[offset];
658 if (e == '\n')
660 ++offset;
661 if (msg.Mid(offset, 11) == L"git-svn-id:"
662 || msg.Mid(offset, 14) == L"Signed-off-by:"
663 || msg.Mid(offset, 10) == L"Change-Id:"
666 offset += 10;
667 while (offset < msg.GetLength())
669 if (msg[++offset] == '\n')
670 break;
672 continue;
675 else if (e >= 'A' && e <= 'Z' || e >= 'h' && e <= 'z')
679 e = msg[++offset];
680 } while (offset < msg.GetLength() && (e >= 'A' && e <= 'Z' || e >= 'a' && e <= 'z' || e >= '0' && e <= '9'));
682 else if (e >= 'a' && e <= 'g' || e >= '0' && e <= '9')
684 if (e == 'g')
686 ++old;
687 ++offset;
689 if (LookLikeGitHash(msg, offset))
691 TCHAR d = offset < msg.GetLength() ? msg[offset] : '\0';
692 if (!((d >= 'A' && d <= 'Z') || (d >= 'a' && d <= 'z') || (d >= '0' && d <= '9')))
694 CHARRANGE range = { old, offset };
695 result.push_back(range);
698 ++offset;
700 else
701 ++offset;
704 return result;
707 BOOL FindGitHash(const CString& msg, int offset, CWnd *pWnd)
709 std::vector<CHARRANGE> positions = FindGitHashPositions(msg, offset);
710 CAppUtils::SetCharFormat(pWnd, CFM_LINK, CFE_LINK, positions);
712 return positions.empty() ? FALSE : TRUE;
715 static int DescribeCommit(CGitHash& hash, CString& result)
717 CAutoRepository repo(g_Git.GetGitRepository());
718 if (!repo)
719 return -1;
720 CAutoObject commit;
721 if (git_object_lookup(commit.GetPointer(), repo, (const git_oid *)hash.m_hash, GIT_OBJ_COMMIT))
722 return -1;
724 CAutoDescribeResult describe;
725 git_describe_options describe_options = GIT_DESCRIBE_OPTIONS_INIT;
726 describe_options.describe_strategy = CRegDWORD(L"Software\\TortoiseGit\\DescribeStrategy", GIT_DESCRIBE_DEFAULT);
727 if (git_describe_commit(describe.GetPointer(), (git_object *)commit, &describe_options))
728 return -1;
730 CAutoBuf describe_buf;
731 git_describe_format_options format_options = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
732 format_options.abbreviated_size = CRegDWORD(L"Software\\TortoiseGit\\DescribeAbbreviatedSize", GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE);
733 format_options.always_use_long_format = CRegDWORD(L"Software\\TortoiseGit\\DescribeAlwaysLong");
734 if (git_describe_format(describe_buf, describe, &format_options))
735 return -1;
737 result = CUnicodeUtils::GetUnicode(describe_buf->ptr);
738 return 0;
741 void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)
743 // we fill here the log message rich edit control,
744 // and also populate the changed files list control
745 // according to the selected revision(s).
747 CRichEditCtrl * pMsgView = (CRichEditCtrl*)GetDlgItem(IDC_MSGVIEW);
748 // empty the log message view
749 pMsgView->SetWindowText(L" ");
750 FillPatchView(true);
751 // empty the changed files list
752 m_ChangedFileListCtrl.SetRedraw(FALSE);
753 // InterlockedExchange(&m_bNoDispUpdates, TRUE);
754 m_ChangedFileListCtrl.DeleteAllItems();
756 // if we're not here to really show a selected revision, just
757 // get out of here after clearing the views, which is what is intended
758 // if that flag is not set.
759 if (!bShow)
761 // force a redraw
762 m_ChangedFileListCtrl.Invalidate();
763 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
764 m_ChangedFileListCtrl.SetRedraw(TRUE);
765 m_gravatar.LoadGravatar();
766 return;
769 // depending on how many revisions are selected, we have to do different
770 // tasks.
771 int selCount = m_LogList.GetSelectedCount();
772 if (selCount == 0)
774 // if nothing is selected, we have nothing more to do
775 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
776 m_ChangedFileListCtrl.SetRedraw(TRUE);
777 m_gravatar.LoadGravatar();
778 return;
780 else if (selCount == 1)
782 // if one revision is selected, we have to fill the log message view
783 // with the corresponding log message, and also fill the changed files
784 // list fully.
785 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
786 size_t selIndex = m_LogList.GetNextSelectedItem(pos);
787 if (selIndex >= m_LogList.m_arShownList.size())
789 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
790 m_ChangedFileListCtrl.SetRedraw(TRUE);
791 return;
793 GitRevLoglist* pLogEntry = m_LogList.m_arShownList.SafeGetAt(selIndex);
796 m_gravatar.LoadGravatar(pLogEntry->GetAuthorEmail());
798 CString out_describe;
799 if (m_bShowDescribe)
801 CString result;
802 if (!DescribeCommit(pLogEntry->m_CommitHash, result))
803 out_describe = L"Describe: " + result + L"\r\n";
806 CString out_counter;
807 if (m_bShowBranchRevNo && !pLogEntry->m_CommitHash.IsEmpty())
809 bool isFirstParentCommit = !pLogEntry->m_Lanes.empty() && Lanes::isActive(pLogEntry->m_Lanes[0]);
811 if (isFirstParentCommit)
813 CString rev_counter, rev_err;
814 if (g_Git.Run(L"git.exe rev-list --count --first-parent " + pLogEntry->m_CommitHash.ToString(), &rev_counter, &rev_err, CP_UTF8))
815 CMessageBox::Show(GetSafeHwnd(), L"Could not get rev count\n" + rev_counter + L'\n' + rev_err, L"TortoiseGit", MB_ICONERROR);
816 else
817 out_counter = L", " + CString(MAKEINTRESOURCE(IDS_REV_COUNTER)) + L": " + rev_counter.Trim();
821 // set the log message text
822 pMsgView->SetWindowText(CString(MAKEINTRESOURCE(IDS_HASH)) + L": " + pLogEntry->m_CommitHash.ToString() + out_counter + L"\r\n" + out_describe + L"\r\n");
823 // turn bug ID's into links if the bugtraq: properties have been set
824 // and we can find a match of those in the log message
826 pMsgView->SetSel(-1,-1);
827 CAppUtils::SetCharFormat(pMsgView, CFM_BOLD, CFE_BOLD);
829 CString msg = m_bAsteriskLogPrefix ? L"* " : L"";
830 msg+=pLogEntry->GetSubject();
831 pMsgView->ReplaceSel(msg);
833 pMsgView->SetSel(-1,-1);
834 CAppUtils::SetCharFormat(pMsgView, CFM_BOLD, 0);
836 HCURSOR old = GetCursor(); // hack to fix issue #2792
838 msg = L'\n';
839 msg+=pLogEntry->GetBody();
840 pMsgView->ReplaceSel(msg);
842 if(!pLogEntry->m_Notes.IsEmpty())
844 pMsgView->SetSel(-1, -1);
845 CAppUtils::SetCharFormat(pMsgView, CFM_BOLD, CFE_BOLD);
846 msg = L'\n';
847 if (m_bAsteriskLogPrefix)
848 msg += L"* ";
849 msg += CString(MAKEINTRESOURCE(IDS_NOTES)) + L":\n";
850 pMsgView->ReplaceSel(msg);
851 pMsgView->SetSel(-1, -1);
852 CAppUtils::SetCharFormat(pMsgView, CFM_BOLD, 0);
853 pMsgView->ReplaceSel(pLogEntry->m_Notes);
856 CString tagInfo = m_LogList.GetTagInfo(pLogEntry);
857 if (!tagInfo.IsEmpty())
859 pMsgView->SetSel(-1, -1);
860 CAppUtils::SetCharFormat(pMsgView, CFM_BOLD, CFE_BOLD);
861 msg = L'\n';
862 if (m_bAsteriskLogPrefix)
863 msg += L"* ";
864 msg += CString(MAKEINTRESOURCE(IDS_PROC_LOG_TAGINFO)) + L":\n";
865 pMsgView->ReplaceSel(msg);
866 pMsgView->SetSel(-1, -1);
867 CAppUtils::SetCharFormat(pMsgView, CFM_BOLD, 0);
868 pMsgView->ReplaceSel(tagInfo);
871 SetCursor(old);
873 CString text;
874 pMsgView->GetWindowText(text);
875 // the rich edit control doesn't count the CR char!
876 // to be exact: CRLF is treated as one char.
877 text.Remove('\r');
879 int findHashStart = text.Find('\n');
880 if (!out_describe.IsEmpty())
881 findHashStart = text.Find('\n', findHashStart + 1);
882 FindGitHash(text, findHashStart, pMsgView);
883 m_LogList.m_ProjectProperties.FindBugID(text, pMsgView);
884 CAppUtils::StyleURLs(text, pMsgView);
885 if (((DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\StyleCommitMessages", TRUE)) == TRUE)
886 CAppUtils::FormatTextInRichEditControl(pMsgView);
888 CHARRANGE range;
889 range.cpMin = 0;
890 range.cpMax = 0;
891 pMsgView->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
893 if (!pLogEntry->m_IsDiffFiles)
895 m_ChangedFileListCtrl.SetBusyString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES)));
896 m_ChangedFileListCtrl.SetBusy(TRUE);
897 m_ChangedFileListCtrl.SetRedraw(TRUE);
898 return;
901 CString matchpath=this->m_path.GetGitPathString();
903 CTGitPathList& files = pLogEntry->GetFiles(&m_LogList);
904 int count = files.GetCount();
905 if (!m_bWholeProject && !matchpath.IsEmpty() && m_iHidePaths)
907 int matchPathLen = matchpath.GetLength();
908 bool somethingHidden = false;
909 for (int i = 0; i < count; ++i)
911 ((CTGitPath&)files[i]).m_Action &= ~(CTGitPath::LOGACTIONS_HIDE | CTGitPath::LOGACTIONS_GRAY);
913 if (wcsncmp(files[i].GetGitPathString(), matchpath, matchPathLen) && ((files[i].m_Action & (CTGitPath::LOGACTIONS_REPLACED | CTGitPath::LOGACTIONS_COPY)) == 0 || wcsncmp(files[i].GetGitOldPathString(), matchpath, matchPathLen)))
915 somethingHidden = true;
916 if (m_iHidePaths == 1)
917 ((CTGitPath&)files[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;
918 else if (m_iHidePaths == 2)
919 ((CTGitPath&)files[i]).m_Action |= CTGitPath::LOGACTIONS_GRAY;
922 if (somethingHidden)
923 pLogEntry->GetAction(&m_LogList) |= CTGitPath::LOGACTIONS_HIDE;
924 else
925 pLogEntry->GetAction(&m_LogList) &= ~CTGitPath::LOGACTIONS_HIDE;
927 else if (pLogEntry->GetAction(&m_LogList) & CTGitPath::LOGACTIONS_HIDE)
929 pLogEntry->GetAction(&m_LogList) &= ~CTGitPath::LOGACTIONS_HIDE;
930 for (int i = 0 ; i < count; ++i)
931 ((CTGitPath&)files[i]).m_Action &= ~(CTGitPath::LOGACTIONS_HIDE | CTGitPath::LOGACTIONS_GRAY);
934 CString fileFilter;
935 m_cFileFilter.GetWindowText(fileFilter);
936 if (!fileFilter.IsEmpty())
938 fileFilter.MakeLower();
939 bool somethingHidden = false;
940 for (int i = 0; i < count; ++i)
942 CString sPath(files[i].GetGitPathString());
943 sPath.MakeLower();
944 if (sPath.Find(fileFilter) < 0)
946 ((CTGitPath&)files[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;
947 somethingHidden = true;
950 if (somethingHidden)
951 pLogEntry->GetAction(&m_LogList) |= CTGitPath::LOGACTIONS_HIDE;
954 m_ChangedFileListCtrl.UpdateWithGitPathList(files);
955 m_ChangedFileListCtrl.m_CurrentVersion=pLogEntry->m_CommitHash;
956 if (pLogEntry->m_CommitHash.IsEmpty() && m_bShowUnversioned)
958 m_ChangedFileListCtrl.UpdateUnRevFileList(pLogEntry->GetUnRevFiles());
959 m_ChangedFileListCtrl.Show(GITSLC_SHOWVERSIONED | GITSLC_SHOWUNVERSIONED);
961 else
962 m_ChangedFileListCtrl.Show(GITSLC_SHOWVERSIONED);
964 m_ChangedFileListCtrl.SetBusy(FALSE);
966 m_ChangedFileListCtrl.SetRedraw(TRUE);
967 return;
971 else
973 // more than one revision is selected:
974 // the log message view must be emptied
975 // the changed files list contains all the changed paths from all
976 // selected revisions, with 'doubles' removed
977 m_gravatar.LoadGravatar();
980 // redraw the views
981 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
983 // sort according to the settings
984 if (m_nSortColumnPathList > 0)
985 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
986 else
987 SetSortArrow(&m_ChangedFileListCtrl, -1, false);
988 m_ChangedFileListCtrl.SetRedraw(TRUE);
991 void CLogDlg::FillPatchView(bool onlySetTimer)
993 if (!::IsWindow(this->m_patchViewdlg.m_hWnd))
994 return;
996 KillTimer(LOG_FILLPATCHVTIMER);
997 if (onlySetTimer)
999 SetTimer(LOG_FILLPATCHVTIMER, 100, nullptr);
1000 return;
1003 POSITION posLogList = m_LogList.GetFirstSelectedItemPosition();
1004 if (posLogList == nullptr)
1006 m_patchViewdlg.ClearView();
1007 return; // nothing is selected, get out of here
1010 GitRev* pLogEntry = m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(posLogList));
1011 if (pLogEntry == nullptr || m_LogList.GetNextSelectedItem(posLogList) != -1)
1013 m_patchViewdlg.ClearView();
1014 return;
1017 auto locker(m_ChangedFileListCtrl.AcquireReadLock());
1018 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
1019 CString out;
1021 if (pos == nullptr)
1023 int diffContext = g_Git.GetConfigValueInt32(L"diff.context", -1);
1024 CStringA outA;
1025 CString rev1 = pLogEntry->m_CommitHash.IsEmpty() ? L"HEAD" : (pLogEntry->m_CommitHash.ToString() + L"~1");
1026 CString rev2 = pLogEntry->m_CommitHash.IsEmpty() ? GIT_REV_ZERO : pLogEntry->m_CommitHash.ToString();
1027 g_Git.GetUnifiedDiff(CTGitPath(), rev1, rev2, &outA, false, false, diffContext);
1028 out = CUnicodeUtils::GetUnicode(outA);
1030 else
1032 while (pos)
1034 int nSelect = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
1035 auto p = m_ChangedFileListCtrl.GetListEntry(nSelect);
1036 if (p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER))
1038 CString cmd;
1039 if (pLogEntry->m_CommitHash.IsEmpty())
1040 cmd.Format(L"git.exe diff HEAD -- \"%s\"", (LPCTSTR)p->GetGitPathString());
1041 else
1042 cmd.Format(L"git.exe diff %s^%d..%s -- \"%s\"", (LPCTSTR)pLogEntry->m_CommitHash.ToString(), p->m_ParentNo + 1, (LPCTSTR)pLogEntry->m_CommitHash.ToString(), (LPCTSTR)p->GetGitPathString());
1043 g_Git.Run(cmd, &out, CP_UTF8);
1048 m_patchViewdlg.SetText(out);
1051 void CLogDlg::TogglePatchView()
1053 m_patchViewdlg.m_ParentDlg = this;
1054 if (!IsWindow(m_patchViewdlg.m_hWnd))
1056 if (g_Git.GetConfigValueBool(L"tgit.logshowpatch") == FALSE)
1057 g_Git.SetConfigValue(L"tgit.logshowpatch", L"true");
1058 m_patchViewdlg.Create(IDD_PATCH_VIEW, this);
1059 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTHTRACKING, TRUE);
1060 CRect rect;
1061 this->GetWindowRect(&rect);
1063 m_patchViewdlg.ShowWindow(SW_SHOW);
1064 m_patchViewdlg.SetWindowPos(nullptr, rect.right, rect.top, (DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\TortoiseProc\\PatchDlgWidth", rect.Width()), rect.Height(), SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
1066 FillPatchView();
1068 else
1070 g_Git.SetConfigValue(L"tgit.logshowpatch", L"false");
1071 m_patchViewdlg.ShowWindow(SW_HIDE);
1072 m_patchViewdlg.DestroyWindow();
1076 LRESULT CLogDlg::OnFileListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
1078 FillPatchView(true);
1079 return 0;
1082 void CLogDlg::OnMoving(UINT fwSide, LPRECT pRect)
1084 __super::OnMoving(fwSide, pRect);
1086 if (!::IsWindow(m_patchViewdlg.m_hWnd))
1087 return;
1089 RECT patchrect;
1090 m_patchViewdlg.GetWindowRect(&patchrect);
1091 if (!::IsWindow(m_hWnd))
1092 return;
1094 RECT thisrect;
1095 GetWindowRect(&thisrect);
1096 if (patchrect.left == thisrect.right)
1098 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);
1102 void CLogDlg::OnSizing(UINT fwSide, LPRECT pRect)
1104 __super::OnSizing(fwSide, pRect);
1106 if (!::IsWindow(this->m_patchViewdlg.m_hWnd))
1107 return;
1109 CRect thisrect, patchrect;
1110 this->GetWindowRect(thisrect);
1111 this->m_patchViewdlg.GetWindowRect(patchrect);
1112 if (thisrect.right != patchrect.left)
1113 return;
1115 patchrect.left -= (thisrect.right - pRect->right);
1116 patchrect.right -= (thisrect.right - pRect->right);
1118 if (patchrect.bottom == thisrect.bottom)
1119 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
1120 if (patchrect.top == thisrect.top)
1121 patchrect.top -= thisrect.top - pRect->top;
1122 m_patchViewdlg.MoveWindow(patchrect);
1125 void CLogDlg::OnSelectSearchField()
1127 m_cFilter.SetSel(0, -1, FALSE);
1128 m_cFilter.SetFocus();
1131 void CLogDlg::GoBack()
1133 GoBackForward(false, false);
1136 void CLogDlg::GoForward()
1138 GoBackForward(false, true);
1141 void CLogDlg::GoBackAndSelect()
1143 GoBackForward(true, false);
1146 void CLogDlg::GoForwardAndSelect()
1148 GoBackForward(true, true);
1151 void CLogDlg::GoBackForward(bool select, bool bForward)
1153 m_LogList.m_highlight.Empty();
1154 CGitHash gotoHash;
1155 if (bForward ? m_LogList.m_selectionHistory.GoForward(gotoHash) : m_LogList.m_selectionHistory.GoBack(gotoHash))
1157 int i;
1158 for (i = 0; i < (int)m_LogList.m_arShownList.size(); ++i)
1160 GitRev* rev = m_LogList.m_arShownList.SafeGetAt(i);
1161 if (!rev) continue;
1162 if (rev->m_CommitHash == gotoHash)
1164 m_LogList.EnsureVisible(i, FALSE);
1165 if (select)
1167 m_LogList.m_highlight.Empty();
1168 m_LogList.SetItemState(m_LogList.GetSelectionMark(), 0, LVIS_SELECTED | LVIS_FOCUSED);
1169 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1170 while (pos)
1172 int index = m_LogList.GetNextSelectedItem(pos);
1173 if (index >= 0)
1174 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
1176 m_bNavigatingWithSelect = true;
1177 m_LogList.SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
1178 m_LogList.SetSelectionMark(i);
1179 m_bNavigatingWithSelect = false;
1181 else
1182 m_LogList.m_highlight = gotoHash;
1183 m_LogList.Invalidate();
1184 return;
1187 if (i == (int)m_LogList.m_arShownList.size())
1189 CString msg;
1190 msg.Format(IDS_LOG_NOT_VISIBLE, (LPCTSTR)gotoHash.ToString());
1191 MessageBox(msg, L"TortoiseGit", MB_OK | MB_ICONINFORMATION);
1192 return;
1195 PlaySound((LPCTSTR)SND_ALIAS_SYSTEMASTERISK, nullptr, SND_ASYNC | SND_ALIAS_ID);
1198 void CLogDlg::OnBnClickedRefresh()
1200 Refresh (true);
1203 void CLogDlg::Refresh (bool clearfilter /*autoGoOnline*/)
1205 if (m_bSelect)
1206 DialogEnableWindow(IDOK, FALSE);
1207 m_LogList.Refresh(clearfilter);
1208 EnableOKButton();
1209 ShowStartRef();
1210 FillLogMessageCtrl(false);
1215 BOOL CLogDlg::Cancel()
1217 return m_bCancelled;
1220 void CLogDlg::SaveSplitterPos()
1222 if (!IsIconic())
1224 CRegDWORD regPos1(L"Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1");
1225 CRegDWORD regPos2(L"Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2");
1226 RECT rectSplitter;
1227 m_wndSplitter1.GetWindowRect(&rectSplitter);
1228 ScreenToClient(&rectSplitter);
1229 regPos1 = rectSplitter.top;
1230 m_wndSplitter2.GetWindowRect(&rectSplitter);
1231 ScreenToClient(&rectSplitter);
1232 regPos2 = rectSplitter.top;
1236 void CLogDlg::OnCancel()
1238 this->ShowWindow(SW_HIDE);
1240 // canceling means stopping the working thread if it's still running.
1241 m_LogList.SafeTerminateAsyncDiffThread();
1242 if (this->IsThreadRunning())
1244 m_LogList.SafeTerminateThread();
1246 UpdateData();
1248 SaveSplitterPos();
1249 __super::OnCancel();
1252 void CLogDlg::CopyChangedSelectionToClipBoard()
1254 POSITION posLogList = m_LogList.GetFirstSelectedItemPosition();
1255 if (posLogList == nullptr)
1256 return; // nothing is selected, get out of here
1258 CString sPaths;
1260 // CGitRev* pLogEntry = reinterpret_cast<CGitRev* >(m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1261 // if (posLogList)
1263 auto locker(m_ChangedFileListCtrl.AcquireReadLock());
1264 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
1265 while (pos)
1267 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
1268 auto path = m_ChangedFileListCtrl.GetListEntry(nItem);
1269 if (!path)
1270 continue;
1271 sPaths += path->GetGitPathString();
1272 sPaths += L"\r\n";
1275 #if 0
1276 else
1278 // only one revision is selected in the log dialog top pane
1279 // but multiple items could be selected in the changed items list
1280 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
1281 while (pos)
1283 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
1284 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(nItem);
1286 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
1288 // some items are hidden! So find out which item the user really selected
1289 INT_PTR selRealIndex = -1;
1290 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
1292 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1293 ++selRealIndex;
1294 if (selRealIndex == nItem)
1296 changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex);
1297 break;
1301 if (changedlogpath)
1303 sPaths += changedlogpath->sPath;
1304 sPaths += L"\r\n";
1308 #endif
1309 sPaths.Trim();
1310 CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());
1313 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)
1315 // we have 4 separate context menus:
1316 // one for the branch label in the upper left
1317 // one for FROM date control
1318 // one shown on the log message list control,
1319 // one shown in the changed-files list control
1320 if (pWnd == GetDlgItem(IDC_STATIC_REF))
1322 CIconMenu popup;
1323 if (!popup.CreatePopupMenu())
1324 return;
1326 int cnt = 0;
1327 popup.AppendMenuIcon(++cnt, IDS_MENUREFBROWSE);
1328 popup.SetDefaultItem(cnt);
1329 CString head = L"HEAD";
1330 CString curBranch = g_Git.GetCurrentBranch();
1331 if (!curBranch.IsEmpty())
1332 head.AppendFormat(L" -> \"%s\"", (LPCTSTR)curBranch);
1333 popup.AppendMenuIcon(++cnt, head);
1334 CGitHash fetchHead;
1335 g_Git.GetHash(fetchHead, g_Git.FixBranchName(L"FETCH_HEAD"));
1336 popup.AppendMenuIcon(++cnt, L"FETCH_HEAD");
1337 popup.EnableMenuItem(cnt, fetchHead.IsEmpty());
1338 popup.AppendMenuIcon(++cnt, IDS_ALL);
1339 popup.EnableMenuItem(cnt, m_bFollowRenames);
1340 popup.AppendMenuIcon(++cnt, IDS_PROC_LOG_SELECT_BASIC_REFS);
1341 popup.EnableMenuItem(cnt, m_bFollowRenames);
1342 popup.AppendMenuIcon(++cnt, IDS_PROC_LOG_SELECT_LOCAL_BRANCHES);
1343 popup.EnableMenuItem(cnt, m_bFollowRenames);
1344 int offset = ++cnt;
1345 if (m_History.GetCount() > 0)
1347 popup.AppendMenu(MF_SEPARATOR, 0);
1348 for (size_t i = 0; i < m_History.GetCount(); ++i)
1350 CString entry = m_History.GetEntry(i);
1351 if (entry.GetLength() > 150)
1352 entry = entry.Left(150) + L"...";
1353 popup.AppendMenuIcon(cnt++, entry);
1357 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this);
1358 if (cmd == 0)
1359 return;
1360 else if (cmd == 1)
1362 OnBnClickedBrowseRef();
1363 return;
1366 m_LogList.m_ShowMask &= ~(CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_BASIC_REFS | CGit::LOG_INFO_LOCAL_BRANCHES);
1367 m_bAllBranch = BST_UNCHECKED;
1368 m_AllBranchType = AllBranchType::None;
1369 if (cmd == 2)
1371 SetRange(g_Git.GetCurrentBranch(true));
1373 else if (cmd == 3)
1375 SetRange(fetchHead.ToString());
1377 else if (cmd == 4)
1379 m_bAllBranch = BST_CHECKED;
1380 m_AllBranchType = AllBranchType::AllBranches;
1381 m_LogList.m_ShowMask |= CGit::LOG_INFO_ALL_BRANCH;
1383 else if (cmd == 5)
1385 m_bAllBranch = BST_INDETERMINATE;
1386 m_AllBranchType = AllBranchType::AllBasicRefs;
1387 m_LogList.m_ShowMask |= CGit::LOG_INFO_BASIC_REFS;
1389 else if (cmd == 6)
1391 m_bAllBranch = BST_INDETERMINATE;
1392 m_AllBranchType = AllBranchType::AllLocalBranches;
1393 m_LogList.m_ShowMask |= CGit::LOG_INFO_LOCAL_BRANCHES;
1395 else if (cmd >= offset)
1397 SetRange(m_History.GetEntry(cmd - offset));
1398 m_History.AddEntry(m_LogList.m_sRange);
1399 m_History.Save();
1402 UpdateData(FALSE);
1404 OnRefresh();
1405 FillLogMessageCtrl(false);
1407 return;
1410 if (pWnd == GetDlgItem(IDC_DATEFROM))
1412 CIconMenu popup;
1413 if (!popup.CreatePopupMenu())
1414 return;
1416 int cnt = 0;
1418 popup.AppendMenuIcon(++cnt, IDS_NO_LIMIT);
1420 DWORD scale = (DWORD)CRegDWORD(L"Software\\TortoiseGit\\LogDialog\\NumberOfLogsScale", CFilterData::SHOW_NO_LIMIT);
1421 CString strScale;
1422 switch (scale)
1424 case CFilterData::SHOW_LAST_N_COMMITS:
1425 strScale.LoadString(IDS_LAST_N_COMMITS);
1426 break;
1427 case CFilterData::SHOW_LAST_N_YEARS:
1428 strScale.LoadString(IDS_LAST_N_YEARS);
1429 break;
1430 case CFilterData::SHOW_LAST_N_MONTHS:
1431 strScale.LoadString(IDS_LAST_N_MONTHS);
1432 break;
1433 case CFilterData::SHOW_LAST_N_WEEKS:
1434 strScale.LoadString(IDS_LAST_N_WEEKS);
1435 break;
1437 if (!strScale.IsEmpty() && m_LogList.m_Filter.m_NumberOfLogs > 0)
1439 popup.AppendMenu(MF_SEPARATOR, 0);
1440 CString number;
1441 number.Format(L"%ld", m_LogList.m_Filter.m_NumberOfLogs);
1442 CString item;
1443 item.Format(strScale, (LPCTSTR)number);
1444 popup.AppendMenuIcon(++cnt, item);
1447 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this);
1448 if (cmd <= 0)
1449 return;
1450 else if (cmd == 1)
1452 m_LogList.m_Filter.m_NumberOfLogsScale = CFilterData::SHOW_NO_LIMIT;
1453 // reset last selected date
1454 m_regLastSelectedFromDate.removeValue();
1456 else if (cmd == 2)
1457 m_LogList.m_Filter.m_NumberOfLogsScale = scale;
1459 UpdateData(FALSE);
1460 OnRefresh();
1461 FillLogMessageCtrl(false);
1463 return;
1466 int selCount = m_LogList.GetSelectedCount();
1467 if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))
1469 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1470 int selIndex = -1;
1471 if (pos)
1472 selIndex = m_LogList.GetNextSelectedItem(pos);
1474 GitRevLoglist* pRev = nullptr;
1475 if (selIndex >= 0)
1476 pRev = m_LogList.m_arShownList.SafeGetAt(selIndex);
1478 if ((point.x == -1) && (point.y == -1))
1480 CRect rect;
1481 GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);
1482 ClientToScreen(&rect);
1483 point = rect.CenterPoint();
1485 CString sMenuItemText;
1486 CIconMenu popup;
1487 if (popup.CreatePopupMenu())
1489 long start = -1, end = -1;
1490 auto pEdit = (CRichEditCtrl *)GetDlgItem(IDC_MSGVIEW);
1491 pEdit->GetSel(start, end);
1492 // add the 'default' entries
1493 popup.AppendMenuIcon(WM_COPY, IDS_SCIEDIT_COPY, IDI_COPYCLIP);
1494 if (start >= end)
1495 popup.EnableMenuItem(WM_COPY, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1496 popup.AppendMenu(MF_SEPARATOR);
1497 sMenuItemText.LoadString(IDS_STATUSLIST_CONTEXT_COPYEXT);
1498 popup.AppendMenuIcon(EM_SETSEL, sMenuItemText, IDI_COPYCLIP);
1499 if (pRev && !pRev->m_CommitHash.IsEmpty())
1501 popup.AppendMenu(MF_SEPARATOR, NULL);
1502 sMenuItemText.LoadString(IDS_EDIT_NOTES);
1503 popup.AppendMenuIcon(CGitLogList::ID_EDITNOTE, sMenuItemText, IDI_EDIT);
1506 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this);
1507 switch (cmd)
1509 case 0:
1510 break; // no command selected
1511 case EM_SETSEL:
1513 pEdit->SetRedraw(FALSE);
1514 int oldLine = pEdit->GetFirstVisibleLine();
1515 pEdit->SetSel(0, -1);
1516 pEdit->Copy();
1517 pEdit->SetSel(start, end);
1518 int newLine = pEdit->GetFirstVisibleLine();
1519 pEdit->LineScroll(oldLine - newLine);
1520 pEdit->SetRedraw(TRUE);
1521 pEdit->RedrawWindow();
1523 break;
1524 case WM_COPY:
1525 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);
1526 break;
1527 case CGitLogList::ID_EDITNOTE:
1528 CAppUtils::EditNote(pRev, &m_LogList.m_ProjectProperties);
1529 this->FillLogMessageCtrl(true);
1530 break;
1536 void CLogDlg::OnOK()
1538 // since the log dialog is also used to select revisions for other
1539 // dialogs, we have to do some work before closing this dialog
1540 if (GetFocus() != GetDlgItem(IDOK))
1541 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter
1543 m_LogList.SafeTerminateAsyncDiffThread();
1544 if (this->IsThreadRunning())
1546 m_LogList.SafeTerminateThread();
1548 UpdateData();
1549 // get the selected row(s)
1550 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1551 while (pos)
1553 int selIndex = m_LogList.GetNextSelectedItem(pos);
1554 GitRev* pLogEntry = m_LogList.m_arShownList.SafeGetAt(selIndex);
1555 if (!pLogEntry)
1556 continue;
1557 m_sSelectedHash.push_back(pLogEntry->m_CommitHash);
1559 UpdateData(FALSE);
1560 SaveSplitterPos();
1561 __super::OnOK();
1563 #if 0
1564 if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))
1565 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.
1567 CString temp;
1568 CString buttontext;
1569 GetDlgItemText(IDOK, buttontext);
1570 temp.LoadString(IDS_MSGBOX_CANCEL);
1571 if (temp.Compare(buttontext) != 0)
1572 __super::OnOK(); // only exit if the button text matches, and that will match only if the thread isn't running anymore
1573 m_bCancelled = TRUE;
1574 m_selectedRevs.Clear();
1575 m_selectedRevsOneRange.Clear();
1576 if (m_pNotifyWindow)
1578 int selIndex = m_LogList.GetSelectionMark();
1579 if (selIndex >= 0)
1581 PLOGENTRYDATA pLogEntry = nullptr;
1582 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1583 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1584 m_selectedRevs.AddRevision(pLogEntry->Rev);
1585 git_revnum_t lowerRev = pLogEntry->Rev;
1586 git_revnum_t higherRev = lowerRev;
1587 while (pos)
1589 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1590 git_revnum_t rev = pLogEntry->Rev;
1591 m_selectedRevs.AddRevision(pLogEntry->Rev);
1592 if (lowerRev > rev)
1593 lowerRev = rev;
1594 if (higherRev < rev)
1595 higherRev = rev;
1597 if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())
1599 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);
1601 BOOL bSentMessage = FALSE;
1602 if (m_LogList.GetSelectedCount() == 1)
1604 // if only one revision is selected, check if the path/url with which the dialog was started
1605 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.
1606 // if it was copied, use the copy from revision as lowerRev
1607 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))
1609 CString sUrl = m_path.GetGitPathString();
1610 if (!m_path.IsUrl())
1612 sUrl = GetURLFromPath(m_path);
1614 sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());
1615 for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)
1617 LogChangedPath * pData = pLogEntry->pArChangedPaths->SafeGetAt(cp);
1618 if (pData)
1620 if (sUrl.Compare(pData->sPath) == 0)
1622 if (!pData->sCopyFromPath.IsEmpty())
1624 lowerRev = pData->lCopyFromRev;
1625 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);
1626 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);
1627 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1628 bSentMessage = TRUE;
1635 if ( !bSentMessage )
1637 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);
1638 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);
1639 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1640 if (m_selectedRevsOneRange.GetCount())
1641 m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);
1645 UpdateData();
1646 CRegDWORD reg(L"Software\\TortoiseGit\\ShowAllEntry");
1647 SaveSplitterPos();
1648 #endif
1651 void CLogDlg::OnPasteGitHash()
1653 if (!IsClipboardFormatAvailable(CF_TEXT))
1654 return;
1656 CClipboardHelper clipboardHelper;
1657 if (!clipboardHelper.Open(GetSafeHwnd()))
1658 return;
1660 HGLOBAL hClipboardData = GetClipboardData(CF_TEXT);
1661 if (!hClipboardData)
1662 return;
1664 char* pStr = (char*)GlobalLock(hClipboardData);
1665 CString str(pStr);
1666 GlobalUnlock(hClipboardData);
1667 if (str.IsEmpty())
1668 return;
1670 int pos = 0;
1671 if (LookLikeGitHash(str, pos))
1672 JumpToGitHash(str);
1675 void CLogDlg::JumpToGitHash(CString hash)
1677 int prefixLen = hash.GetLength();
1678 while (hash.GetLength() < 2 * GIT_HASH_SIZE)
1679 hash += L'0';
1680 CGitHash prefixHash(hash);
1681 // start searching downwards, because it's unlikely that a hash is a forward reference
1682 int currentPos = m_LogList.GetSelectionMark();
1683 int cnt = (int)m_LogList.m_arShownList.size();
1684 if (!cnt || currentPos < 0)
1685 return;
1686 for (int i = currentPos + 1; i != currentPos; ++i)
1688 if (i >= cnt)
1689 i = 0;
1691 GitRev* rev = m_LogList.m_arShownList.SafeGetAt(i);
1692 if (!rev) continue;
1693 if (!rev->m_CommitHash.MatchesPrefix(prefixHash, hash, prefixLen))
1694 continue;
1696 m_LogList.SetItemState(m_LogList.GetSelectionMark(), 0, LVIS_SELECTED | LVIS_FOCUSED);
1697 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1698 while (pos)
1700 int index = m_LogList.GetNextSelectedItem(pos);
1701 if (index >= 0)
1702 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
1704 m_LogList.EnsureVisible(i, FALSE);
1705 m_LogList.SetSelectionMark(i);
1706 m_LogList.SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
1707 // refresh of selection needs to be queued instead of done immediately, to ensure hyperlinks in target selection are created
1708 PostMessage(WM_TGIT_REFRESH_SELECTION, 0, 0);
1709 return;
1712 FlashWindowEx(FLASHW_ALL, 3, 100);
1713 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_LOG_JUMPNOTFOUND, IDS_APPNAME, 1, IDI_INFORMATION, IDS_OKBUTTON, 0, 0, L"NoJumpNotFoundWarning", IDS_MSGBOX_DONOTSHOWAGAIN);
1716 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)
1718 // Skip Ctrl-C when copying text out of the log message or search filter
1719 bool bSkipAccelerator = (pMsg->message == WM_KEYDOWN && (pMsg->wParam == 'C' || pMsg->wParam == VK_INSERT) && (GetFocus() == GetDlgItem(IDC_MSGVIEW) || GetFocus() == GetDlgItem(IDC_SEARCHEDIT) || GetFocus() == GetDlgItem(IDC_FILTER)) && GetKeyState(VK_CONTROL) & 0x8000);
1720 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
1722 if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1724 if (CRegDWORD(L"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE))
1726 m_LogList.DiffSelectedRevWithPrevious();
1727 return TRUE;
1730 if (GetFocus() == GetDlgItem(IDC_SEARCHEDIT))
1732 KillTimer(LOGFILTER_TIMER);
1733 Refresh(false);
1735 if (GetFocus() == GetDlgItem(IDC_FILTER))
1737 KillTimer(FILEFILTER_TIMER);
1738 FillLogMessageCtrl();
1739 return TRUE;
1742 else if (pMsg->message == WM_KEYDOWN && ((pMsg->wParam == 'V' && GetKeyState(VK_CONTROL) < 0) || (pMsg->wParam == VK_INSERT && GetKeyState(VK_SHIFT) < 0 && GetKeyState(VK_CONTROL) >= 0)) && GetKeyState(VK_MENU) >= 0)
1744 if (GetFocus() != GetDlgItem(IDC_SEARCHEDIT) && GetFocus() != GetDlgItem(IDC_FILTER))
1746 OnPasteGitHash();
1747 return TRUE;
1750 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE && GetFocus() == GetDlgItem(IDC_FILTER) && m_cFileFilter.GetWindowTextLength())
1752 m_cFileFilter.SetWindowText(L"");
1753 KillTimer(FILEFILTER_TIMER);
1754 FillLogMessageCtrl();
1755 return TRUE;
1757 else if (pMsg->message == WM_XBUTTONUP)
1759 bool select = (pMsg->wParam & MK_SHIFT) == 0;
1760 if (HIWORD(pMsg->wParam) & XBUTTON1)
1761 GoBackForward(select, false);
1762 if (HIWORD(pMsg->wParam) & XBUTTON2)
1763 GoBackForward(select, true);
1764 if (HIWORD(pMsg->wParam) & (XBUTTON1 | XBUTTON2))
1765 return TRUE;
1767 if (m_hAccel && !bSkipAccelerator)
1769 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1770 if (ret)
1771 return TRUE;
1774 return __super::PreTranslateMessage(pMsg);
1778 BOOL CLogDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1780 //if (this->IsThreadRunning())
1781 if(m_LogList.m_bNoDispUpdates)
1783 // only show the wait cursor over the list control
1784 if ((pWnd)&&
1785 ((pWnd == GetDlgItem(IDC_LOGLIST))||
1786 (pWnd == GetDlgItem(IDC_MSGVIEW))||
1787 (pWnd == GetDlgItem(IDC_LOGMSG))))
1789 HCURSOR hCur = LoadCursor(nullptr, IDC_WAIT);
1790 SetCursor(hCur);
1791 return TRUE;
1794 if (pWnd && (pWnd == GetDlgItem(IDC_MSGVIEW) || pWnd == GetDlgItem(IDC_SEARCHEDIT) || pWnd == GetDlgItem(IDC_FILTER)))
1795 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1797 HCURSOR hCur = LoadCursor(nullptr, IDC_ARROW);
1798 SetCursor(hCur);
1799 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1802 void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1804 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1805 *pResult = 0;
1806 //if (this->IsThreadRunning())
1807 if(m_LogList.m_bNoDispUpdates)
1808 return;
1809 if (pNMLV->iItem >= 0)
1811 if (!m_LogList.m_highlight.IsEmpty())
1813 m_LogList.m_highlight.Empty();
1814 m_LogList.Invalidate();
1816 this->m_LogList.m_nSearchIndex = pNMLV->iItem;
1817 GitRev* pLogEntry = m_LogList.m_arShownList.SafeGetAt(pNMLV->iItem);
1818 if (pLogEntry == nullptr)
1819 return;
1820 m_LogList.m_lastSelectedHash = pLogEntry->m_CommitHash;
1821 if (pNMLV->iSubItem != 0)
1822 return;
1823 if (pNMLV->iItem == (int)m_LogList.m_arShownList.size())
1825 // remove the selected state
1826 if (pNMLV->uChanged & LVIF_STATE)
1828 m_LogList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);
1829 FillLogMessageCtrl();
1830 UpdateData(FALSE);
1831 UpdateLogInfoLabel();
1833 return;
1835 if (pNMLV->uChanged & LVIF_STATE)
1837 if ((pNMLV->uNewState & LVIS_SELECTED) && !m_bNavigatingWithSelect)
1839 m_LogList.m_selectionHistory.Add(m_LogList.m_lastSelectedHash);
1840 m_LogList.m_lastSelectedHash = pLogEntry->m_CommitHash;
1842 FillLogMessageCtrl();
1843 UpdateData(FALSE);
1846 else
1848 m_LogList.m_lastSelectedHash.Empty();
1849 FillLogMessageCtrl();
1850 UpdateData(FALSE);
1852 EnableOKButton();
1853 if (pNMLV->iItem < 0)
1854 return;
1855 UpdateLogInfoLabel();
1858 void CLogDlg::OnLvnItemchangedLogmsg(NMHDR * /*pNMHDR*/, LRESULT * /*pResult*/)
1860 if (m_ChangedFileListCtrl.IsBusy())
1861 return;
1862 UpdateLogInfoLabel();
1865 void CLogDlg::OnEnLinkMsgview(NMHDR *pNMHDR, LRESULT *pResult)
1867 // similar code in ProgressDlg.cpp and SyncDlg.cpp
1868 ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);
1869 if ((pEnLink->msg == WM_LBUTTONUP) || (pEnLink->msg == WM_SETCURSOR))
1871 CString url, msg;
1872 GetDlgItemText(IDC_MSGVIEW, msg);
1873 msg.Replace(L"\r\n", L"\n");
1874 url = msg.Mid(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax-pEnLink->chrg.cpMin);
1875 auto findResult = m_LogList.m_ProjectProperties.FindBugIDPositions(msg);
1876 if (std::find_if(findResult.cbegin(), findResult.cend(),
1877 [=] (const CHARRANGE &cr) -> bool { return cr.cpMin == pEnLink->chrg.cpMin && cr.cpMax == pEnLink->chrg.cpMax; }
1878 ) != findResult.cend())
1880 url = m_LogList.m_ProjectProperties.GetBugIDUrl(url);
1881 url = GetAbsoluteUrlFromRelativeUrl(url);
1883 // check if it's an email address
1884 auto atpos = url.Find(L'@');
1885 if ((atpos > 0) && (url.ReverseFind(L'.') > atpos) && !::PathIsURL(url))
1886 url = L"mailto:" + url;
1887 if (::PathIsURL(url))
1889 if (pEnLink->msg == WM_LBUTTONUP)
1890 ShellExecute(GetSafeHwnd(), L"open", url, nullptr, nullptr, SW_SHOWDEFAULT);
1891 else
1893 static RECT prevRect = { 0 };
1894 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
1895 if (pMsgView)
1897 RECT rc;
1898 POINTL pt;
1899 pMsgView->SendMessage(EM_POSFROMCHAR, (WPARAM)&pt, pEnLink->chrg.cpMin);
1900 rc.left = pt.x;
1901 rc.top = pt.y;
1902 pMsgView->SendMessage(EM_POSFROMCHAR, (WPARAM)&pt, pEnLink->chrg.cpMax);
1903 rc.right = pt.x;
1904 rc.bottom = pt.y + 12;
1905 if ((prevRect.left != rc.left) || (prevRect.top != rc.top))
1907 m_tooltips.DelTool(pMsgView, 1);
1908 m_tooltips.AddTool(pMsgView, url, &rc, 1);
1909 prevRect = rc;
1914 else if(pEnLink->msg == WM_LBUTTONUP)
1916 int pos = 0;
1917 if (LookLikeGitHash(url, pos))
1918 JumpToGitHash(url);
1921 *pResult = 0;
1924 void CLogDlg::OnBnClickedStatbutton()
1926 if (this->IsThreadRunning())
1927 return;
1929 if (m_LogList.m_arShownList.empty() || m_LogList.m_arShownList.size() == 1 && m_LogList.m_bShowWC)
1930 return; // nothing or just the working copy changes are shown, so no statistics.
1932 CStatGraphDlg dlg;
1933 dlg.m_ShowList.reserve(m_LogList.m_arShownList.size());
1934 for (int i = m_LogList.m_bShowWC ? 1 : 0; i < m_LogList.m_arShownList.size(); ++i)
1935 dlg.m_ShowList.emplace_back(m_LogList.m_arShownList.SafeGetAt(i));
1937 dlg.m_path = m_orgPath;
1938 dlg.DoModal();
1941 void CLogDlg::MoveToSameTop(CWnd *pWndRef, CWnd *pWndTarget)
1943 CRect rcWndPicAuthor, rcWndMsgView;
1944 pWndRef->GetWindowRect(rcWndMsgView);
1945 ScreenToClient(rcWndMsgView);
1946 pWndTarget->GetWindowRect(rcWndPicAuthor);
1947 ScreenToClient(rcWndPicAuthor);
1948 int diff = rcWndMsgView.top - rcWndPicAuthor.top;
1949 rcWndPicAuthor.top += diff;
1950 rcWndPicAuthor.bottom += diff;
1951 pWndTarget->MoveWindow(rcWndPicAuthor);
1954 void CLogDlg::DoSizeV1(int delta)
1956 RemoveMainAnchors();
1958 // first, reduce the middle section to a minimum.
1959 // if that is not sufficient, minimize the lower section
1961 CRect changeListViewRect;
1962 m_ChangedFileListCtrl.GetClientRect(changeListViewRect);
1963 CRect messageViewRect;
1964 GetDlgItem(IDC_MSGVIEW)->GetClientRect(messageViewRect);
1966 int messageViewDelta = max(-delta, 20 - messageViewRect.Height());
1967 int changeFileListDelta = -delta - messageViewDelta;
1969 // set new sizes & positions
1970 auto hdwp = BeginDeferWindowPos(5);
1971 hdwp = CSplitterControl::ChangeRect(hdwp, &m_LogList, 0, 0, 0, delta);
1972 hdwp = CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_MSGVIEW), 0, delta, 0, delta + messageViewDelta);
1973 MoveToSameTop(GetDlgItem(IDC_MSGVIEW), GetDlgItem(IDC_PIC_AUTHOR));
1974 hdwp = CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_SPLITTERBOTTOM), 0, -changeFileListDelta, 0, -changeFileListDelta);
1975 hdwp = CSplitterControl::ChangeRect(hdwp, &m_ChangedFileListCtrl, 0, -changeFileListDelta, 0, 0);
1976 EndDeferWindowPos(hdwp);
1978 AddMainAnchors();
1979 ArrangeLayout();
1980 AdjustMinSize();
1981 SetSplitterRange();
1982 m_LogList.Invalidate();
1983 m_ChangedFileListCtrl.Invalidate();
1984 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1985 m_gravatar.Invalidate();
1988 void CLogDlg::DoSizeV2(int delta)
1990 RemoveMainAnchors();
1992 // first, reduce the middle section to a minimum.
1993 // if that is not sufficient, minimize the top section
1995 CRect logViewRect;
1996 m_LogList.GetClientRect(logViewRect);
1997 CRect messageViewRect;
1998 GetDlgItem(IDC_MSGVIEW)->GetClientRect(messageViewRect);
2000 int messageViewDelta = max(delta, 20 - messageViewRect.Height());
2001 int logListDelta = delta - messageViewDelta;
2003 // set new sizes & positions
2004 auto hdwp = BeginDeferWindowPos(5);
2005 hdwp = CSplitterControl::ChangeRect(hdwp, &m_LogList, 0, 0, 0, logListDelta);
2006 hdwp = CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_SPLITTERTOP), 0, logListDelta, 0, logListDelta);
2007 hdwp = CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_MSGVIEW), 0, logListDelta, 0, logListDelta + messageViewDelta);
2008 MoveToSameTop(GetDlgItem(IDC_MSGVIEW), GetDlgItem(IDC_PIC_AUTHOR));
2009 hdwp = CSplitterControl::ChangeRect(hdwp, &m_ChangedFileListCtrl, 0, delta, 0, 0);
2010 EndDeferWindowPos(hdwp);
2012 AddMainAnchors();
2013 ArrangeLayout();
2014 AdjustMinSize();
2015 SetSplitterRange();
2016 GetDlgItem(IDC_MSGVIEW)->Invalidate();
2017 m_ChangedFileListCtrl.Invalidate();
2018 m_gravatar.Invalidate();
2021 void CLogDlg::AddMainAnchors()
2023 AddAnchor(IDC_STATIC_REF, TOP_LEFT);
2024 AddAnchor(IDC_FROMLABEL, TOP_LEFT);
2025 AddAnchor(IDC_DATEFROM, TOP_LEFT);
2026 AddAnchor(IDC_TOLABEL, TOP_LEFT);
2027 AddAnchor(IDC_DATETO, TOP_LEFT);
2029 AddAnchor(IDC_SEARCHEDIT, TOP_LEFT, TOP_RIGHT);
2030 AddAnchor(IDC_LOG_JUMPTYPE, TOP_RIGHT);
2031 AddAnchor(IDC_LOG_JUMPUP, TOP_RIGHT);
2032 AddAnchor(IDC_LOG_JUMPDOWN, TOP_RIGHT);
2034 AddAnchor(IDC_LOGLIST, TOP_LEFT, MIDDLE_RIGHT);
2035 AddAnchor(IDC_SPLITTERTOP, MIDDLE_LEFT, MIDDLE_RIGHT);
2036 AddAnchor(IDC_MSGVIEW, MIDDLE_LEFT, MIDDLE_RIGHT); // keep in sync with ShowGravatar()
2037 AddAnchor(IDC_PIC_AUTHOR, MIDDLE_RIGHT);
2038 AddAnchor(IDC_SPLITTERBOTTOM, MIDDLE_LEFT, MIDDLE_RIGHT);
2039 AddAnchor(IDC_LOGMSG, MIDDLE_LEFT, BOTTOM_RIGHT);
2041 AddAnchor(IDC_LOGINFO, BOTTOM_LEFT, BOTTOM_RIGHT);
2042 AddAnchor(IDC_WALKBEHAVIOUR, BOTTOM_LEFT);
2043 AddAnchor(IDC_VIEW, BOTTOM_LEFT);
2044 AddAnchor(IDC_LOG_ALLBRANCH, BOTTOM_LEFT);
2045 AddAnchor(IDC_FILTER, BOTTOM_LEFT, BOTTOM_RIGHT);
2046 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
2047 AddAnchor(IDC_REFRESH, BOTTOM_LEFT);
2048 AddAnchor(IDC_STATBUTTON, BOTTOM_LEFT);
2049 AddAnchor(IDC_PROGRESS, BOTTOM_LEFT, BOTTOM_RIGHT);
2050 AddAnchor(IDOK, BOTTOM_RIGHT);
2051 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
2052 AddAnchor(IDHELP, BOTTOM_RIGHT);
2055 void CLogDlg::RemoveMainAnchors()
2057 RemoveAnchor(IDC_STATIC_REF);
2058 RemoveAnchor(IDC_FROMLABEL);
2059 RemoveAnchor(IDC_DATEFROM);
2060 RemoveAnchor(IDC_TOLABEL);
2061 RemoveAnchor(IDC_DATETO);
2063 RemoveAnchor(IDC_SEARCHEDIT);
2064 RemoveAnchor(IDC_LOG_JUMPTYPE);
2065 RemoveAnchor(IDC_LOG_JUMPUP);
2066 RemoveAnchor(IDC_LOG_JUMPDOWN);
2068 RemoveAnchor(IDC_LOGLIST);
2069 RemoveAnchor(IDC_SPLITTERTOP);
2070 RemoveAnchor(IDC_MSGVIEW);
2071 RemoveAnchor(IDC_PIC_AUTHOR);
2072 RemoveAnchor(IDC_SPLITTERBOTTOM);
2073 RemoveAnchor(IDC_LOGMSG);
2075 RemoveAnchor(IDC_LOGINFO);
2076 RemoveAnchor(IDC_WALKBEHAVIOUR);
2077 RemoveAnchor(IDC_VIEW);
2078 RemoveAnchor(IDC_LOG_ALLBRANCH);
2079 RemoveAnchor(IDC_FILTER);
2080 RemoveAnchor(IDC_WHOLE_PROJECT);
2081 RemoveAnchor(IDC_REFRESH);
2082 RemoveAnchor(IDC_STATBUTTON);
2083 RemoveAnchor(IDC_PROGRESS);
2084 RemoveAnchor(IDOK);
2085 RemoveAnchor(IDCANCEL);
2086 RemoveAnchor(IDHELP);
2089 void CLogDlg::AdjustMinSize()
2091 // adjust the minimum size of the dialog to prevent the resizing from
2092 // moving the list control too far down.
2093 CRect rcChgListView;
2094 m_ChangedFileListCtrl.GetClientRect(rcChgListView);
2095 CRect rcLogList;
2096 m_LogList.GetClientRect(rcLogList);
2097 CRect rcLogMsg;
2098 GetDlgItem(IDC_MSGVIEW)->GetClientRect(rcLogMsg);
2100 SetMinTrackSize(CSize(m_DlgOrigRect.Width(),
2101 m_DlgOrigRect.Height()-m_ChgOrigRect.Height()-m_LogListOrigRect.Height()-m_MsgViewOrigRect.Height()
2102 + rcLogMsg.Height() + abs(rcChgListView.Height() - rcLogList.Height()) + 60));
2105 LRESULT CLogDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
2107 switch (message) {
2108 case WM_NOTIFY:
2109 if (wParam == IDC_SPLITTERTOP)
2111 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
2112 DoSizeV1(pHdr->delta);
2114 else if (wParam == IDC_SPLITTERBOTTOM)
2116 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
2117 DoSizeV2(pHdr->delta);
2119 break;
2122 return CResizableDialog::DefWindowProc(message, wParam, lParam);
2125 void CLogDlg::SetSplitterRange()
2127 if ((m_LogList)&&(m_ChangedFileListCtrl))
2129 CRect rcTop;
2130 m_LogList.GetWindowRect(rcTop);
2131 ScreenToClient(rcTop);
2132 CRect rcBottom;
2133 m_ChangedFileListCtrl.GetWindowRect(rcBottom);
2134 ScreenToClient(rcBottom);
2135 m_wndSplitter1.SetRange(rcTop.top + 20, rcBottom.bottom - 50);
2136 m_wndSplitter2.SetRange(rcTop.top + 50, rcBottom.bottom - 20);
2140 void CLogDlg::OnEnscrollMsgview()
2142 m_tooltips.DelTool(GetDlgItem(IDC_MSGVIEW), 1);
2145 LRESULT CLogDlg::OnClickedInfoIcon(WPARAM wParam, LPARAM lParam)
2147 if ((HWND)wParam == m_cFileFilter.GetSafeHwnd())
2148 return 0;
2150 // FIXME: x64 version would get this function called with unexpected parameters.
2151 if (!lParam)
2152 return 0;
2154 RECT * rect = (LPRECT)lParam;
2155 CPoint point;
2156 CString temp;
2157 point = CPoint(rect->left, rect->bottom);
2158 #define LOGMENUFLAGS(x) (MF_STRING | MF_ENABLED | ((m_LogList.m_SelectedFilters & x) ? MF_CHECKED : MF_UNCHECKED))
2159 CMenu popup;
2160 if (popup.CreatePopupMenu())
2162 temp.LoadString(IDS_LOG_FILTER_SUBJECT);
2163 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_SUBJECT), LOGFILTER_SUBJECT, temp);
2165 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2166 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_MESSAGES), LOGFILTER_MESSAGES, temp);
2168 temp.LoadString(IDS_LOG_FILTER_PATHS);
2169 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_PATHS), LOGFILTER_PATHS, temp);
2171 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2172 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_AUTHORS), LOGFILTER_AUTHORS, temp);
2174 temp.LoadString(IDS_LOG_FILTER_EMAILS);
2175 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_EMAILS), LOGFILTER_EMAILS, temp);
2177 temp.LoadString(IDS_LOG_FILTER_REVS);
2178 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REVS), LOGFILTER_REVS, temp);
2180 temp.LoadString(IDS_LOG_FILTER_REFNAME);
2181 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REFNAME), LOGFILTER_REFNAME, temp);
2183 temp.LoadString(IDS_PROC_LOG_TAGINFO);
2184 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_ANNOTATEDTAG), LOGFILTER_ANNOTATEDTAG, temp);
2186 temp.LoadString(IDS_NOTES);
2187 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_NOTES), LOGFILTER_NOTES, temp);
2189 if (m_LogList.m_bShowBugtraqColumn == TRUE) {
2190 temp.LoadString(IDS_LOG_FILTER_BUGIDS);
2191 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_BUGID), LOGFILTER_BUGID, temp);
2194 popup.AppendMenu(MF_SEPARATOR, NULL);
2196 temp.LoadString(IDS_LOG_FILTER_TOGGLE);
2197 popup.AppendMenu(MF_STRING | MF_ENABLED, LOGFILTER_TOGGLE, temp);
2199 temp.LoadString(IDS_ALL);
2200 popup.AppendMenu(MF_STRING | MF_ENABLED, LOGFILTER_ALL, temp);
2202 popup.AppendMenu(MF_SEPARATOR, NULL);
2204 temp.LoadString(IDS_LOG_FILTER_REGEX);
2205 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterWithRegex ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_REGEX, temp);
2207 temp.LoadString(IDS_LOG_FILTER_CASESENSITIVE);
2208 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterCaseSensitively ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_CASE, temp);
2210 m_tooltips.Pop();
2211 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this);
2212 if (selection != 0)
2214 if (selection == LOGFILTER_REGEX)
2216 m_bFilterWithRegex = !m_bFilterWithRegex;
2217 CRegDWORD b(L"Software\\TortoiseGit\\UseRegexFilter", FALSE);
2218 b = m_bFilterWithRegex;
2219 m_LogList.m_bFilterWithRegex = m_bFilterWithRegex;
2220 SetFilterCueText();
2221 CheckRegexpTooltip();
2222 m_cFilter.ValidateAndRedraw();
2224 else if (selection == LOGFILTER_CASE)
2226 m_bFilterCaseSensitively = !m_bFilterCaseSensitively;
2227 CRegDWORD b(L"Software\\TortoiseGit\\FilterCaseSensitively", FALSE);
2228 b = m_bFilterCaseSensitively;
2229 m_LogList.m_bFilterCaseSensitively = m_bFilterCaseSensitively;
2231 else if (selection == LOGFILTER_TOGGLE)
2233 m_LogList.m_SelectedFilters = (~m_LogList.m_SelectedFilters) & LOGFILTER_ALL;
2234 SetFilterCueText();
2236 else if (selection == LOGFILTER_ALL)
2238 m_LogList.m_SelectedFilters = selection;
2239 SetFilterCueText();
2241 else
2243 m_LogList.m_SelectedFilters ^= selection;
2244 SetFilterCueText();
2246 CRegDWORD(L"Software\\TortoiseGit\\SelectedLogFilters") = m_LogList.m_SelectedFilters;
2247 // Reload only if a search text is entered
2248 if (m_LogList.HasFilterText())
2249 SetTimer(LOGFILTER_TIMER, 1000, nullptr);
2252 return 0L;
2255 LRESULT CLogDlg::OnClickedCancelFilter(WPARAM wParam, LPARAM /*lParam*/)
2257 if ((HWND)wParam == m_cFileFilter.GetSafeHwnd())
2259 KillTimer(FILEFILTER_TIMER);
2261 FillLogMessageCtrl();
2262 return 0L;
2265 KillTimer(LOGFILTER_TIMER);
2267 m_LogList.m_sFilterText.Empty();
2268 UpdateData(FALSE);
2269 theApp.DoWaitCursor(1);
2270 FillLogMessageCtrl(false);
2272 m_LogList.RemoveFilter();
2274 Refresh();
2276 theApp.DoWaitCursor(-1);
2277 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2278 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2279 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2280 UpdateLogInfoLabel();
2282 return 0L;
2286 void CLogDlg::SetFilterCueText()
2288 CString temp(MAKEINTRESOURCE(IDS_LOG_FILTER_BY));
2289 temp += L' ';
2291 if (m_LogList.m_SelectedFilters & LOGFILTER_SUBJECT)
2293 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_SUBJECT));
2296 if (m_LogList.m_SelectedFilters & LOGFILTER_MESSAGES)
2298 if (!CStringUtils::EndsWith(temp, L' '))
2299 temp += L", ";
2300 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_MESSAGES));
2303 if (m_LogList.m_SelectedFilters & LOGFILTER_PATHS)
2305 if (!CStringUtils::EndsWith(temp, L' '))
2306 temp += L", ";
2307 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_PATHS));
2310 if (m_LogList.m_SelectedFilters & LOGFILTER_AUTHORS)
2312 if (!CStringUtils::EndsWith(temp, L' '))
2313 temp += L", ";
2314 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_AUTHORS));
2317 if (m_LogList.m_SelectedFilters & LOGFILTER_EMAILS)
2319 if (!CStringUtils::EndsWith(temp, L' '))
2320 temp += L", ";
2321 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_EMAILS));
2324 if (m_LogList.m_SelectedFilters & LOGFILTER_REVS)
2326 if (!CStringUtils::EndsWith(temp, L' '))
2327 temp += L", ";
2328 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_REVS));
2331 if (m_LogList.m_SelectedFilters & LOGFILTER_REFNAME)
2333 if (!CStringUtils::EndsWith(temp, L' '))
2334 temp += L", ";
2335 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_REFNAME));
2338 if (m_LogList.m_SelectedFilters & LOGFILTER_NOTES)
2340 if (!CStringUtils::EndsWith(temp, L' '))
2341 temp += L", ";
2342 temp += CString(MAKEINTRESOURCE(IDS_NOTES));
2345 if (m_LogList.m_bShowBugtraqColumn && m_LogList.m_SelectedFilters & LOGFILTER_BUGID)
2347 if (!CStringUtils::EndsWith(temp, L' '))
2348 temp += L", ";
2349 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_BUGIDS));
2352 // to make the cue banner text appear more to the right of the edit control
2353 temp = L" " + temp;
2354 m_cFilter.SetCueBanner(temp.TrimRight());
2357 bool CLogDlg::Validate(LPCTSTR string)
2359 if (!m_bFilterWithRegex)
2360 return true;
2361 std::tr1::wregex pat;
2362 return m_LogList.ValidateRegexp(string, pat, false);
2365 void CLogDlg::OnEnChangeFileFilter()
2367 SetTimer(FILEFILTER_TIMER, 1000, nullptr);
2370 void CLogDlg::OnTimer(UINT_PTR nIDEvent)
2372 if (nIDEvent == LOGFTIME_TIMER)
2374 KillTimer(LOGFTIME_TIMER);
2375 Refresh(false);
2377 else if (nIDEvent == LOG_FILLPATCHVTIMER)
2378 FillPatchView();
2379 else if (nIDEvent == LOGFILTER_TIMER)
2381 KillTimer(LOGFILTER_TIMER);
2382 Refresh(false);
2384 #if 0
2385 /* we will use git built-in grep to filter log */
2386 if (this->IsThreadRunning())
2388 // thread still running! So just restart the timer.
2389 SetTimer(LOGFILTER_TIMER, 1000, nullptr);
2390 return;
2392 CWnd * focusWnd = GetFocus();
2393 bool bSetFocusToFilterControl = ((focusWnd != GetDlgItem(IDC_DATEFROM))&&(focusWnd != GetDlgItem(IDC_DATETO))
2394 && (focusWnd != GetDlgItem(IDC_LOGLIST)));
2395 if (m_LogList.m_sFilterText.IsEmpty())
2397 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2398 // do not return here!
2399 // we also need to run the filter if the filter text is empty:
2400 // 1. to clear an existing filter
2401 // 2. to rebuild the m_arShownList after sorting
2403 theApp.DoWaitCursor(1);
2404 CStoreSelection storeselection(this);
2405 KillTimer(LOGFILTER_TIMER);
2406 FillLogMessageCtrl(false);
2408 // now start filter the log list
2409 m_LogList.StartFilter();
2411 if ( m_LogList.GetItemCount()==1 )
2413 m_LogList.SetSelectionMark(0);
2414 m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
2416 theApp.DoWaitCursor(-1);
2417 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2418 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2419 if (bSetFocusToFilterControl)
2420 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2421 UpdateLogInfoLabel();
2422 #endif
2423 } // if (nIDEvent == LOGFILTER_TIMER)
2424 else if (nIDEvent == LOG_HEADER_ORDER_TIMER)
2426 KillTimer(LOG_HEADER_ORDER_TIMER);
2427 CLogOrdering orderDlg;
2428 if (orderDlg.DoModal() == IDOK)
2429 Refresh();
2431 else if (nIDEvent == FILEFILTER_TIMER)
2433 KillTimer(FILEFILTER_TIMER);
2434 FillLogMessageCtrl();
2436 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.empty() || m_LogList.m_arShownList.size() == 1 && m_LogList.m_bShowWC))));
2437 __super::OnTimer(nIDEvent);
2440 void CLogDlg::OnDtnDatetimechangeDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2444 CTime _time;
2445 m_DateTo.GetTime(_time);
2447 CTime fromTime;
2448 m_DateFrom.GetTime(fromTime);
2449 if (_time < fromTime)
2451 _time = fromTime;
2452 m_DateTo.SetTime(&_time);
2455 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 23, 59, 59);
2456 if (time.GetTime() != m_LogList.m_Filter.m_To)
2458 m_LogList.m_Filter.m_To = (DWORD)time.GetTime();
2459 SetTimer(LOGFTIME_TIMER, 10, nullptr);
2462 catch (...)
2464 CMessageBox::Show(GetSafeHwnd(), L"Invalidate Parameter", L"TortoiseGit", MB_OK | MB_ICONERROR);
2467 *pResult = 0;
2470 void CLogDlg::OnDtnDatetimechangeDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2474 CTime _time;
2475 m_DateFrom.GetTime(_time);
2477 CTime toTime;
2478 m_DateTo.GetTime(toTime);
2479 if (_time > toTime)
2481 _time = toTime;
2482 m_DateFrom.SetTime(&_time);
2485 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 0, 0, 0);
2486 if (time.GetTime() != m_LogList.m_Filter.m_From)
2488 m_LogList.m_Filter.m_From = (DWORD)time.GetTime();
2489 m_LogList.m_Filter.m_NumberOfLogsScale = CFilterData::SHOW_LAST_SEL_DATE;
2491 if (CFilterData::SHOW_LAST_SEL_DATE == (DWORD)CRegDWORD(L"Software\\TortoiseGit\\LogDialog\\NumberOfLogsScale", CFilterData::SHOW_NO_LIMIT))
2492 m_regLastSelectedFromDate = time.Format(L"%Y-%m-%d");
2494 SetTimer(LOGFTIME_TIMER, 10, nullptr);
2497 catch (...)
2499 CMessageBox::Show(GetSafeHwnd(), L"Invalidate Parameter", L"TortoiseGit", MB_OK | MB_ICONERROR);
2502 *pResult = 0;
2505 void CLogDlg::OnCbnSelchangeJumpType()
2507 // reserved for future use
2510 void CLogDlg::OnBnClickedJumpUp()
2512 int sel = m_JumpType.GetCurSel();
2513 if (sel < 0) return;
2514 JumpType jumpType = (JumpType)sel;
2516 if (jumpType == JumpType_History)
2518 GoBack();
2519 return;
2522 CString strValue;
2523 CGitHash hashValue;
2524 int index = -1;
2525 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2526 if (pos)
2528 index = m_LogList.GetNextSelectedItem(pos);
2529 if (index == 0) return;
2531 GitRev* data = m_LogList.m_arShownList.SafeGetAt(index);
2532 if (jumpType == JumpType_AuthorEmail)
2533 strValue = data->GetAuthorEmail();
2534 else if (jumpType == JumpType_CommitterEmail)
2535 strValue = data->GetCommitterEmail();
2536 else if (jumpType == JumpType_Parent1)
2537 hashValue = data->m_CommitHash;
2538 else if (jumpType == JumpType_Parent2)
2539 hashValue = data->m_CommitHash;
2540 else if (jumpType == JumpType_TagFF)
2541 hashValue = data->m_CommitHash;
2542 else if (jumpType == JumpType_BranchFF)
2543 hashValue = data->m_CommitHash;
2545 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2547 else
2548 return;
2550 while (pos)
2552 index = m_LogList.GetNextSelectedItem(pos);
2553 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2555 m_LogList.SetSelectionMark(-1);
2557 for (int i = index - 1; i >= 0; i--)
2559 bool found = false;
2560 GitRev* data = m_LogList.m_arShownList.SafeGetAt(i);
2561 if (jumpType == JumpType_AuthorEmail)
2562 found = strValue == data->GetAuthorEmail();
2563 else if (jumpType == JumpType_CommitterEmail)
2564 found = strValue == data->GetCommitterEmail();
2565 else if (jumpType == JumpType_MergePoint)
2566 found = data->ParentsCount() > 1;
2567 else if (jumpType == JumpType_Parent1)
2569 if (!data->m_ParentHash.empty())
2570 found = data->m_ParentHash[0] == hashValue;
2572 else if (jumpType == JumpType_Parent2)
2574 if (data->m_ParentHash.size() > 1)
2575 found = data->m_ParentHash[1] == hashValue;
2577 else if (jumpType == JumpType_Tag || jumpType == JumpType_TagFF)
2579 auto refList = m_LogList.m_HashMap.find(data->m_CommitHash);
2580 if (refList != m_LogList.m_HashMap.cend())
2581 found = find_if((*refList).second, [](const auto& ref) { return CStringUtils::StartsWith(ref, L"refs/tags/"); }) != (*refList).second.cend();
2583 if (found && jumpType == JumpType_TagFF)
2584 found = g_Git.IsFastForward(hashValue, data->m_CommitHash);
2586 else if (jumpType == JumpType_Branch || jumpType == JumpType_BranchFF)
2588 auto refList = m_LogList.m_HashMap.find(data->m_CommitHash);
2589 if (refList != m_LogList.m_HashMap.cend())
2590 found = find_if((*refList).second, [](const auto& ref) { return CStringUtils::StartsWith(ref, L"refs/heads/") || CStringUtils::StartsWith(ref, L"refs/remotes/"); }) != (*refList).second.cend();
2592 if (found && jumpType == JumpType_BranchFF)
2593 found = g_Git.IsFastForward(hashValue, data->m_CommitHash);
2596 if (found)
2598 m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2599 m_LogList.EnsureVisible(i, FALSE);
2600 m_LogList.SetSelectionMark(i);
2601 return;
2605 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_LOG_JUMPNOTFOUND, IDS_APPNAME, 1, IDI_INFORMATION, IDS_OKBUTTON, 0, 0, L"NoJumpNotFoundWarning", IDS_MSGBOX_DONOTSHOWAGAIN);
2608 void CLogDlg::OnBnClickedJumpDown()
2610 int jumpType = m_JumpType.GetCurSel();
2611 if (jumpType < 0) return;
2613 if (jumpType == JumpType_History)
2615 GoForward();
2616 return;
2619 CString strValue;
2620 CGitHash hashValue;
2621 int index = -1;
2622 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2623 if (pos)
2625 index = m_LogList.GetNextSelectedItem(pos);
2626 if (index == 0) return;
2628 GitRev* data = m_LogList.m_arShownList.SafeGetAt(index);
2629 if (jumpType == JumpType_AuthorEmail)
2630 strValue = data->GetAuthorEmail();
2631 else if (jumpType == JumpType_CommitterEmail)
2632 strValue = data->GetCommitterEmail();
2633 else if (jumpType == JumpType_Parent1)
2635 if (!data->m_ParentHash.empty())
2636 hashValue = data->m_ParentHash.at(0);
2637 else
2638 return;
2640 else if (jumpType == JumpType_Parent2)
2642 if (data->m_ParentHash.size() > 1)
2643 hashValue = data->m_ParentHash.at(1);
2644 else
2645 return;
2647 else if (jumpType == JumpType_TagFF)
2648 hashValue = data->m_CommitHash;
2649 else if (jumpType == JumpType_BranchFF)
2650 hashValue = data->m_CommitHash;
2652 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2654 else
2655 return;
2657 while (pos)
2659 index = m_LogList.GetNextSelectedItem(pos);
2660 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2662 m_LogList.SetSelectionMark(-1);
2664 for (int i = index + 1; i < m_LogList.GetItemCount(); ++i)
2666 bool found = false;
2667 GitRev* data = m_LogList.m_arShownList.SafeGetAt(i);
2668 if (jumpType == JumpType_AuthorEmail)
2669 found = strValue == data->GetAuthorEmail();
2670 else if (jumpType == JumpType_CommitterEmail)
2671 found = strValue == data->GetCommitterEmail();
2672 else if (jumpType == JumpType_MergePoint)
2673 found = data->ParentsCount() > 1;
2674 else if (jumpType == JumpType_Parent1)
2675 found = data->m_CommitHash == hashValue;
2676 else if (jumpType == JumpType_Parent2)
2677 found = data->m_CommitHash == hashValue;
2678 else if (jumpType == JumpType_Tag || jumpType == JumpType_TagFF)
2680 auto refList = m_LogList.m_HashMap.find(data->m_CommitHash);
2681 if (refList != m_LogList.m_HashMap.cend())
2682 found = find_if((*refList).second, [](const auto& ref) { return CStringUtils::StartsWith(ref, L"refs/tags/"); }) != (*refList).second.cend();
2684 if (found && jumpType == JumpType_TagFF)
2685 found = g_Git.IsFastForward(data->m_CommitHash, hashValue);
2687 else if (jumpType == JumpType_Branch || jumpType == JumpType_BranchFF)
2689 auto refList = m_LogList.m_HashMap.find(data->m_CommitHash);
2690 if (refList != m_LogList.m_HashMap.cend())
2691 found = find_if((*refList).second, [](const auto& ref) { return CStringUtils::StartsWith(ref, L"refs/heads/") || CStringUtils::StartsWith(ref, L"refs/remotes/"); }) != (*refList).second.cend();
2693 if (found && jumpType == JumpType_BranchFF)
2694 found = g_Git.IsFastForward(data->m_CommitHash, hashValue);
2697 if (found)
2699 m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2700 m_LogList.EnsureVisible(i, FALSE);
2701 m_LogList.SetSelectionMark(i);
2702 return;
2706 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_LOG_JUMPNOTFOUND, IDS_APPNAME, 1, IDI_INFORMATION, IDS_OKBUTTON, 0, 0, L"NoJumpNotFoundWarning", IDS_MSGBOX_DONOTSHOWAGAIN);
2709 void CLogDlg::SortByColumn(int /*nSortColumn*/, bool /*bAscending*/)
2711 #if 0
2712 switch(nSortColumn)
2714 case 0: // Revision
2716 if(bAscending)
2717 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscRevSort());
2718 else
2719 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescRevSort());
2721 break;
2722 case 1: // action
2724 if(bAscending)
2725 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscActionSort());
2726 else
2727 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescActionSort());
2729 break;
2730 case 2: // Author
2732 if(bAscending)
2733 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscAuthorSort());
2734 else
2735 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescAuthorSort());
2737 break;
2738 case 3: // Date
2740 if(bAscending)
2741 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscDateSort());
2742 else
2743 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescDateSort());
2745 break;
2746 case 4: // Message or bug id
2747 if (m_bShowBugtraqColumn)
2749 if(bAscending)
2750 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscBugIDSort());
2751 else
2752 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescBugIDSort());
2753 break;
2755 // fall through here
2756 case 5: // Message
2758 if(bAscending)
2759 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscMessageSort());
2760 else
2761 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescMessageSort());
2763 break;
2764 default:
2765 ATLASSERT(0);
2766 break;
2768 #endif
2771 void CLogDlg::OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult)
2773 if (this->IsThreadRunning())
2774 return; //no sorting while the arrays are filled
2775 #if 0
2776 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2777 const int nColumn = pNMLV->iSubItem;
2778 m_bAscending = nColumn == m_nSortColumn ? !m_bAscending : TRUE;
2779 m_nSortColumn = nColumn;
2780 SortByColumn(m_nSortColumn, m_bAscending);
2781 SetSortArrow(&m_LogList, m_nSortColumn, !!m_bAscending);
2782 SortShownListArray();
2783 m_LogList.Invalidate();
2784 UpdateLogInfoLabel();
2785 #else
2786 UNREFERENCED_PARAMETER(pNMHDR);
2787 #endif
2788 *pResult = 0;
2790 SetTimer(LOG_HEADER_ORDER_TIMER, 10, nullptr);
2793 void CLogDlg::SortShownListArray()
2795 // make sure the shown list still matches the filter after sorting.
2796 OnTimer(LOGFILTER_TIMER);
2797 // clear the selection states
2798 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2799 while (pos)
2801 m_LogList.SetItemState(m_LogList.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
2803 m_LogList.SetSelectionMark(-1);
2806 void CLogDlg::SetSortArrow(CListCtrl * control, int nColumn, bool bAscending)
2808 if (!control)
2809 return;
2810 // set the sort arrow
2811 CHeaderCtrl * pHeader = control->GetHeaderCtrl();
2812 HDITEM HeaderItem = {0};
2813 HeaderItem.mask = HDI_FORMAT;
2814 for (int i=0; i<pHeader->GetItemCount(); ++i)
2816 pHeader->GetItem(i, &HeaderItem);
2817 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
2818 pHeader->SetItem(i, &HeaderItem);
2820 if (nColumn >= 0)
2822 pHeader->GetItem(nColumn, &HeaderItem);
2823 HeaderItem.fmt |= (bAscending ? HDF_SORTUP : HDF_SORTDOWN);
2824 pHeader->SetItem(nColumn, &HeaderItem);
2828 int CLogDlg::m_nSortColumnPathList = 0;
2829 bool CLogDlg::m_bAscendingPathList = false;
2831 void CLogDlg::OnBnClickedHidepaths()
2833 FillLogMessageCtrl();
2834 m_ChangedFileListCtrl.Invalidate();
2837 void CLogDlg::UpdateLogInfoLabel()
2839 CGitHash rev1 ;
2840 CGitHash rev2 ;
2841 long selectedrevs = 0;
2842 long selectedfiles = 0;
2843 int count = (int)m_LogList.m_arShownList.size();
2844 int start = 0;
2845 if (count >= 1)
2847 auto pRev = m_LogList.m_arShownList.SafeGetAt(0);
2848 if (pRev)
2850 rev1 = m_LogList.m_arShownList.SafeGetAt(0)->m_CommitHash;
2851 if (m_LogList.m_bShowWC && rev1.IsEmpty() && count > 1)
2853 start = 1;
2854 pRev = m_LogList.m_arShownList.SafeGetAt(start);
2855 if (pRev)
2856 rev1 = pRev->m_CommitHash;
2859 pRev = m_LogList.m_arShownList.SafeGetAt(count - 1);
2860 if (pRev)
2861 rev2 = pRev->m_CommitHash;
2862 selectedrevs = m_LogList.GetSelectedCount();
2863 if (selectedrevs)
2864 selectedfiles = m_ChangedFileListCtrl.GetSelectedCount();
2866 CString sTemp;
2867 sTemp.Format(IDS_PROC_LOG_STATS,
2868 count - start,
2869 (LPCTSTR)rev2.ToString().Left(g_Git.GetShortHASHLength()), (LPCTSTR)rev1.ToString().Left(g_Git.GetShortHASHLength()), selectedrevs, selectedfiles);
2871 if(selectedrevs == 1)
2873 CString str=m_ChangedFileListCtrl.GetStatisticsString(true);
2874 str.Replace(L'\n', L' ');
2875 sTemp += L"; " + str;
2877 m_sLogInfo = sTemp;
2879 UpdateData(FALSE);
2882 void CLogDlg::OnDtnDropdownDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2884 // the date control should not show the "today" button
2885 CMonthCalCtrl * pCtrl = m_DateFrom.GetMonthCalCtrl();
2886 if (pCtrl)
2887 pCtrl->ModifyStyle(0, MCS_NOTODAY);
2888 *pResult = 0;
2891 void CLogDlg::OnSize(UINT nType, int cx, int cy)
2893 __super::OnSize(nType, cx, cy);
2894 //set range
2895 SetSplitterRange();
2898 void CLogDlg::OnRefresh()
2901 this->m_LogProgress.SetPos(0);
2903 Refresh (false);
2907 void CLogDlg::OnFocusFilter()
2909 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2912 void CLogDlg::OnEditCopy()
2914 if (GetFocus() == &m_ChangedFileListCtrl)
2915 CopyChangedSelectionToClipBoard();
2916 else
2917 m_LogList.CopySelectionToClipBoard();
2920 CString CLogDlg::GetAbsoluteUrlFromRelativeUrl(const CString& url)
2922 // is the URL a relative one?
2923 if (CStringUtils::StartsWith(url, L"^/"))
2925 // URL is relative to the repository root
2926 CString url1 = m_sRepositoryRoot + url.Mid(1);
2927 TCHAR buf[INTERNET_MAX_URL_LENGTH] = { 0 };
2928 DWORD len = url.GetLength();
2929 if (UrlCanonicalize((LPCTSTR)url1, buf, &len, 0) == S_OK)
2930 return CString(buf, len);
2931 return url1;
2933 else if (url[0] == '/')
2935 // URL is relative to the server's hostname
2936 CString sHost;
2937 // find the server's hostname
2938 int schemepos = m_sRepositoryRoot.Find(L"//");
2939 if (schemepos >= 0)
2941 sHost = m_sRepositoryRoot.Left(m_sRepositoryRoot.Find(L'/', schemepos + 3));
2942 CString url1 = sHost + url;
2943 TCHAR buf[INTERNET_MAX_URL_LENGTH] = { 0 };
2944 DWORD len = url.GetLength();
2945 if (UrlCanonicalize((LPCTSTR)url, buf, &len, 0) == S_OK)
2946 return CString(buf, len);
2947 return url1;
2950 return url;
2953 void CLogDlg::ShowGravatar()
2955 m_gravatar.EnableGravatar(m_bShowGravatar);
2956 RemoveAnchor(IDC_MSGVIEW);
2957 if (m_gravatar.IsGravatarEnabled())
2959 RECT rect, rect2;
2960 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(&rect);
2961 ScreenToClient(&rect);
2962 m_gravatar.GetWindowRect(&rect2);
2963 ScreenToClient(&rect2);
2964 rect.right = rect2.left;
2965 GetDlgItem(IDC_MSGVIEW)->MoveWindow(&rect);
2966 m_gravatar.ShowWindow(SW_SHOW);
2968 else
2970 RECT rect, rect2;
2971 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(&rect);
2972 ScreenToClient(&rect);
2973 m_gravatar.GetWindowRect(&rect2);
2974 ScreenToClient(&rect2);
2975 rect.right = rect2.right;
2976 GetDlgItem(IDC_MSGVIEW)->MoveWindow(&rect);
2977 m_gravatar.ShowWindow(SW_HIDE);
2979 AddAnchor(IDC_MSGVIEW, MIDDLE_LEFT, MIDDLE_RIGHT); // keep in sync with AddMainAnchors
2983 void CLogDlg::OnEnChangeSearchedit()
2985 UpdateData();
2986 if (!m_LogList.HasFilterText())
2988 // clear the filter, i.e. make all entries appear
2989 theApp.DoWaitCursor(1);
2990 KillTimer(LOGFILTER_TIMER);
2991 FillLogMessageCtrl(false);
2993 Refresh();
2994 //m_LogList.StartFilter();
2995 #if 0
2996 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2997 m_arShownList.RemoveAll();
2998 for (DWORD i=0; i<m_logEntries.size(); ++i)
3000 if (IsEntryInDateRange(i))
3001 m_arShownList.Add(m_logEntries[i]);
3003 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3004 m_LogList.DeleteAllItems();
3005 m_LogList.SetItemCountEx(ShownCountWithStopped());
3006 m_LogList.RedrawItems(0, ShownCountWithStopped());
3007 m_LogList.SetRedraw(false);
3008 m_LogList.SetRedraw(true);
3009 #endif
3010 theApp.DoWaitCursor(-1);
3011 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
3012 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
3013 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3014 DialogEnableWindow(IDC_STATBUTTON, !(this->IsThreadRunning() || m_LogList.m_arShownList.empty()));
3015 return;
3017 if (Validate(m_LogList.m_sFilterText))
3018 SetTimer(LOGFILTER_TIMER, 1000, nullptr);
3019 else
3020 KillTimer(LOGFILTER_TIMER);
3023 void CLogDlg::OnBnClickedAllBranch()
3025 // m_bAllBranch is not auto-toggled by MFC, we have to handle it manually (in order to prevent the indeterminate state)
3027 m_LogList.m_ShowMask &=~ (CGit::LOG_INFO_LOCAL_BRANCHES | CGit::LOG_INFO_BASIC_REFS | CGit::LOG_INFO_ALL_BRANCH);
3029 if (m_bAllBranch)
3031 m_bAllBranch = BST_UNCHECKED;
3032 m_AllBranchType = AllBranchType::None;
3033 m_ChangedFileListCtrl.m_sDisplayedBranch = m_LogList.GetRange();
3035 else
3037 m_bAllBranch = BST_CHECKED;
3038 m_AllBranchType = AllBranchType::AllBranches;
3039 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
3040 m_ChangedFileListCtrl.m_sDisplayedBranch.Empty();
3043 // need to save value here, so that log dialogs started from now on also have AllBranch activated
3044 m_regbAllBranch = (DWORD)m_AllBranchType;
3046 UpdateData(FALSE);
3048 OnRefresh();
3050 FillLogMessageCtrl(false);
3053 void CLogDlg::OnBnClickedFollowRenames()
3055 if(m_bFollowRenames)
3057 m_LogList.m_ShowMask |= CGit::LOG_INFO_FOLLOW;
3058 m_LogList.m_ShowMask &=~ CGit::LOG_INFO_LOCAL_BRANCHES;
3059 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_BASIC_REFS;
3060 if (m_bAllBranch)
3062 m_bAllBranch = FALSE;
3063 m_AllBranchType = AllBranchType::None;
3064 m_LogList.m_ShowMask &=~ CGit::LOG_INFO_ALL_BRANCH;
3067 else
3068 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_FOLLOW;
3070 DialogEnableWindow(IDC_LOG_ALLBRANCH, !m_bFollowRenames);
3071 DialogEnableWindow(IDC_WHOLE_PROJECT, !m_bFollowRenames && !m_path.IsEmpty());
3073 OnRefresh();
3075 FillLogMessageCtrl(false);
3078 void CLogDlg::HandleShowLabels(bool var, int flag)
3080 if (var)
3081 m_LogList.m_ShowRefMask |= flag;
3082 else
3083 m_LogList.m_ShowRefMask &= ~flag;
3085 if ((m_LogList.m_ShowFilter & CGitLogListBase::FILTERSHOW_REFS) && !(m_LogList.m_ShowFilter & CGitLogListBase::FILTERSHOW_ANYCOMMIT))
3087 // Remove commits where labels are not shown.
3088 OnRefresh();
3089 FillLogMessageCtrl(false);
3091 else
3093 // Just redraw
3094 m_LogList.Invalidate();
3098 void CLogDlg::OnBnClickedCompressedGraph()
3100 UpdateData();
3102 if (m_iCompressedGraph == 2)
3103 m_LogList.m_ShowFilter = CGitLogListBase::FILTERSHOW_REFS;
3104 else if (m_iCompressedGraph == 1)
3105 m_LogList.m_ShowFilter = static_cast<CGitLogListBase::FilterShow>(CGitLogListBase::FILTERSHOW_REFS | CGitLogListBase::FILTERSHOW_MERGEPOINTS);
3106 else
3107 m_LogList.m_ShowFilter = CGitLogListBase::FILTERSHOW_ALL;
3109 OnRefresh();
3110 FillLogMessageCtrl(false);
3113 void CLogDlg::OnBnClickedBrowseRef()
3115 CString newRef = CBrowseRefsDlg::PickRef(false, m_LogList.GetRange(), gPickRef_All, true);
3116 if(newRef.IsEmpty())
3117 return;
3119 m_History.AddEntry(newRef);
3120 m_History.Save();
3122 SetRange(newRef);
3124 m_LogList.m_ShowMask &= ~(CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_BASIC_REFS | CGit::LOG_INFO_LOCAL_BRANCHES);
3125 m_bAllBranch = BST_UNCHECKED;
3126 m_AllBranchType = AllBranchType::None;
3127 UpdateData(FALSE);
3129 OnRefresh();
3130 FillLogMessageCtrl(false);
3133 void CLogDlg::ShowStartRef()
3135 //Show ref name on top
3136 if(!::IsWindow(m_hWnd))
3137 return;
3138 if (m_LogList.m_ShowMask & (CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_BASIC_REFS | CGit::LOG_INFO_LOCAL_BRANCHES))
3140 switch (m_LogList.m_ShowMask & (CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_BASIC_REFS | CGit::LOG_INFO_LOCAL_BRANCHES))
3142 case CGit::LOG_INFO_ALL_BRANCH:
3143 m_staticRef.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_LOG_ALLBRANCHES)));
3144 break;
3146 case CGit::LOG_INFO_BASIC_REFS:
3147 m_staticRef.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_LOG_BASIC_REFS)));
3148 break;
3150 case CGit::LOG_INFO_LOCAL_BRANCHES:
3151 m_staticRef.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_LOG_LOCAL_BRANCHES)));
3152 break;
3155 m_staticRef.Invalidate(TRUE);
3156 m_tooltips.DelTool(GetDlgItem(IDC_STATIC_REF));
3157 return;
3160 CString showStartRef = m_LogList.GetRange();
3161 if (showStartRef.IsEmpty() || showStartRef == L"HEAD")
3163 showStartRef.Empty();
3164 //Ref name is HEAD
3165 if (g_Git.Run(L"git.exe symbolic-ref HEAD", &showStartRef, nullptr, CP_UTF8))
3166 showStartRef.LoadString(IDS_PROC_LOG_NOBRANCH);
3167 showStartRef.Trim(L"\r\n\t ");
3171 showStartRef = g_Git.StripRefName(showStartRef);
3173 m_staticRef.SetWindowText(showStartRef);
3174 CWnd *pWnd = GetDlgItem(IDC_STATIC_REF);
3175 m_tooltips.AddTool(pWnd, showStartRef);
3176 m_staticRef.Invalidate(TRUE);
3179 void CLogDlg::SetRange(const CString& range)
3181 m_LogList.SetRange(range);
3182 m_ChangedFileListCtrl.m_sDisplayedBranch = range;
3184 ShowStartRef();
3187 static void AppendMenuChecked(CMenu &menu, UINT nTextID, UINT_PTR nItemID, BOOL checked = FALSE, BOOL enabled = TRUE)
3189 CString text;
3190 text.LoadString(nTextID);
3191 menu.AppendMenu(MF_STRING | (enabled ? MF_ENABLED : MF_DISABLED) | (checked ? MF_CHECKED : MF_UNCHECKED), nItemID, text);
3194 #define WALKBEHAVIOUR_FIRSTPARENT 1
3195 #define WALKBEHAVIOUR_FOLLOWRENAMES 2
3196 #define WALKBEHAVIOUR_COMPRESSEDGRAPH 3
3197 #define WALKBEHAVIOUR_LABELEDCOMMITS 4
3198 #define WALKBEHAVIOUR_NOMERGES 5
3200 void CLogDlg::OnBnClickedWalkBehaviour()
3202 CMenu popup;
3203 if (popup.CreatePopupMenu())
3205 m_ctrlWalkBehavior.SetCheck(BST_CHECKED);
3206 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_FIRSTPARENT, WALKBEHAVIOUR_FIRSTPARENT, m_bFirstParent);
3207 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_NOMERGES, WALKBEHAVIOUR_NOMERGES, m_bNoMerges);
3208 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_FOLLOWRENAMES, WALKBEHAVIOUR_FOLLOWRENAMES, m_bFollowRenames, !(m_path.IsEmpty() || m_path.IsDirectory()));
3209 popup.AppendMenu(MF_SEPARATOR, NULL);
3210 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_COMPRESSED, WALKBEHAVIOUR_COMPRESSEDGRAPH, m_iCompressedGraph == 1);
3211 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_LABELEDCOMMITS, WALKBEHAVIOUR_LABELEDCOMMITS, m_iCompressedGraph == 2);
3213 m_tooltips.Pop();
3214 RECT rect;
3215 GetDlgItem(IDC_WALKBEHAVIOUR)->GetWindowRect(&rect);
3216 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, rect.left, rect.top, this);
3217 switch (selection)
3219 case WALKBEHAVIOUR_FIRSTPARENT:
3220 m_bFirstParent = !m_bFirstParent;
3221 OnBnClickedFirstParent();
3222 break;
3223 case WALKBEHAVIOUR_NOMERGES:
3224 m_bNoMerges = !m_bNoMerges;
3225 OnBnClickedFirstParent(); // OnBnClickedFirstParent handles both cases: m_bFirstParent and m_bNoMerges
3226 break;
3227 case WALKBEHAVIOUR_FOLLOWRENAMES:
3228 m_bFollowRenames = !m_bFollowRenames;
3229 OnBnClickedFollowRenames();
3230 break;
3231 case WALKBEHAVIOUR_COMPRESSEDGRAPH:
3232 m_iCompressedGraph = (m_iCompressedGraph == 1 ? 0 : 1);
3233 OnBnClickedCompressedGraph();
3234 break;
3235 case WALKBEHAVIOUR_LABELEDCOMMITS:
3236 m_iCompressedGraph = (m_iCompressedGraph == 2 ? 0 : 2);
3237 OnBnClickedCompressedGraph();
3238 break;
3239 default:
3240 break;
3242 m_ctrlWalkBehavior.SetCheck((m_bFirstParent || m_bNoMerges || m_bFollowRenames || m_iCompressedGraph) ? BST_CHECKED : BST_UNCHECKED);
3246 #define VIEW_HIDEPATHS 1
3247 #define VIEW_GRAYPATHS 2
3248 #define VIEW_SHOWTAGS 3
3249 #define VIEW_SHOWLOCALBRANCHES 4
3250 #define VIEW_SHOWREMOTEBRANCHES 5
3251 #define VIEW_SHOWGRAVATAR 6
3252 #define VIEW_SHOWPATCH 7
3253 #define VIEW_SHOWWCUNVERSIONED 8
3255 void CLogDlg::OnBnClickedView()
3257 CMenu popup;
3258 if (popup.CreatePopupMenu())
3260 m_ctrlView.SetCheck(BST_CHECKED);
3261 AppendMenuChecked(popup, IDS_SHOWFILES_HIDEPATHS, VIEW_HIDEPATHS, m_iHidePaths == 1);
3262 AppendMenuChecked(popup, IDS_SHOWFILES_GRAYPATHS, VIEW_GRAYPATHS, m_iHidePaths == 2);
3263 popup.AppendMenu(MF_SEPARATOR, NULL);
3264 AppendMenuChecked(popup, IDS_PROC_LOG_SHOWUNVERSIONED, VIEW_SHOWWCUNVERSIONED, m_bShowUnversioned == BST_CHECKED);
3265 popup.AppendMenu(MF_SEPARATOR, NULL);
3266 CMenu showLabelsMenu;
3267 if (showLabelsMenu.CreatePopupMenu())
3269 AppendMenuChecked(showLabelsMenu, IDS_VIEW_SHOWTAGLABELS, VIEW_SHOWTAGS, m_bShowTags);
3270 AppendMenuChecked(showLabelsMenu, IDS_VIEW_SHOWLOCALBRANCHLABELS, VIEW_SHOWLOCALBRANCHES, m_bShowLocalBranches);
3271 AppendMenuChecked(showLabelsMenu, IDS_VIEW_SHOWREMOTEBRANCHLABELS, VIEW_SHOWREMOTEBRANCHES, m_bShowRemoteBranches);
3272 popup.AppendMenu(MF_STRING | MF_POPUP, (UINT_PTR)showLabelsMenu.m_hMenu, (CString)MAKEINTRESOURCE(IDS_VIEW_LABELS));
3274 popup.AppendMenu(MF_SEPARATOR, NULL);
3275 AppendMenuChecked(popup, IDS_VIEW_SHOWGRAVATAR, VIEW_SHOWGRAVATAR, m_bShowGravatar);
3276 AppendMenuChecked(popup, IDS_MENU_VIEWPATCH, VIEW_SHOWPATCH, IsWindow(this->m_patchViewdlg.m_hWnd));
3278 m_tooltips.Pop();
3279 RECT rect;
3280 GetDlgItem(IDC_VIEW)->GetWindowRect(&rect);
3281 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, rect.left, rect.top, this);
3282 switch (selection)
3284 case VIEW_HIDEPATHS:
3285 if (m_iHidePaths == 1)
3286 m_iHidePaths = 0;
3287 else
3288 m_iHidePaths = 1;
3289 OnBnClickedHidepaths();
3290 break;
3291 case VIEW_GRAYPATHS:
3292 if (m_iHidePaths == 2)
3293 m_iHidePaths = 0;
3294 else
3295 m_iHidePaths = 2;
3296 OnBnClickedHidepaths();
3297 break;
3298 case VIEW_SHOWTAGS:
3299 m_bShowTags = !m_bShowTags;
3300 HandleShowLabels(m_bShowTags, LOGLIST_SHOWTAGS);
3301 break;
3302 case VIEW_SHOWLOCALBRANCHES:
3303 m_bShowLocalBranches = !m_bShowLocalBranches;
3304 HandleShowLabels(m_bShowLocalBranches, LOGLIST_SHOWLOCALBRANCHES);
3305 break;
3306 case VIEW_SHOWREMOTEBRANCHES:
3307 m_bShowRemoteBranches = !m_bShowRemoteBranches;
3308 HandleShowLabels(m_bShowRemoteBranches, LOGLIST_SHOWREMOTEBRANCHES);
3309 break;
3310 case VIEW_SHOWGRAVATAR:
3312 m_bShowGravatar = !m_bShowGravatar;
3313 ShowGravatar();
3314 m_gravatar.Init();
3315 CString email;
3316 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
3317 if (pos)
3319 int selIndex = m_LogList.GetNextSelectedItem(pos);
3320 int moreSel = m_LogList.GetNextSelectedItem(pos);
3321 if (moreSel < 0)
3323 GitRev* pLogEntry = m_LogList.m_arShownList.SafeGetAt(selIndex);
3324 if (pLogEntry)
3325 email = pLogEntry->GetAuthorEmail();
3328 m_gravatar.LoadGravatar(email);
3329 break;
3331 case VIEW_SHOWPATCH:
3332 TogglePatchView();
3333 break;
3334 case VIEW_SHOWWCUNVERSIONED:
3335 m_bShowUnversioned = !m_bShowUnversioned;
3336 FillLogMessageCtrl();
3337 m_ChangedFileListCtrl.Invalidate();
3338 break;
3339 default:
3340 break;
3342 m_ctrlView.SetCheck(BST_UNCHECKED);
3346 void CLogDlg::OnBnClickedFirstParent()
3348 if(this->m_bFirstParent)
3349 m_LogList.m_ShowMask|=CGit::LOG_INFO_FIRST_PARENT;
3350 else
3351 m_LogList.m_ShowMask&=~CGit::LOG_INFO_FIRST_PARENT;
3353 if (m_bNoMerges)
3354 m_LogList.m_ShowMask |= CGit::LOG_INFO_NO_MERGE;
3355 else
3356 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_NO_MERGE;
3358 OnRefresh();
3360 FillLogMessageCtrl(false);
3363 void CLogDlg::OnBnClickShowWholeProject()
3365 this->UpdateData();
3367 if(this->m_bWholeProject)
3369 m_LogList.m_Path.Reset();
3370 SetDlgTitle();
3372 else
3373 m_LogList.m_Path=m_path;
3375 m_regShowWholeProject = m_bWholeProject;
3377 SetDlgTitle();
3379 OnRefresh();
3381 FillLogMessageCtrl(false);
3384 LRESULT CLogDlg::OnRefLogChanged(WPARAM /*wParam*/, LPARAM /*lParam*/)
3386 ShowStartRef();
3387 return 0;
3390 LRESULT CLogDlg::OnTaskbarBtnCreated(WPARAM wParam, LPARAM lParam)
3392 m_pTaskbarList.Release();
3393 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
3394 return __super::OnTaskbarButtonCreated(wParam, lParam);
3397 LRESULT CLogDlg::OnRefreshSelection(WPARAM /*wParam*/, LPARAM /*lParam*/)
3399 // it's enough to deselect, then select again one item of the whole selection
3400 int selMark = m_LogList.GetSelectionMark();
3401 if (selMark >= 0)
3403 m_LogList.SetSelectionMark(selMark);
3404 m_LogList.SetItemState(selMark, 0, LVIS_SELECTED);
3405 m_LogList.SetItemState(selMark, LVIS_SELECTED, LVIS_SELECTED);
3407 return 0;
3410 void CLogDlg::OnExitClearFilter()
3412 if (!m_LogList.m_sFilterText.IsEmpty())
3414 OnClickedCancelFilter(NULL, NULL);
3415 return;
3417 SendMessage(WM_CLOSE);