For git > 2.1, pass --date=now when amending commit with author date reset
[TortoiseGit.git] / src / TortoiseProc / LogDlg.cpp
blobcaf211d51a986bc24949f9221bb1e70f938a904b
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2009, 2015 - TortoiseSVN
4 // Copyright (C) 2008-2015 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "cursor.h"
23 #include "StatGraphDlg.h"
24 #include "LogDlg.h"
25 #include "MessageBox.h"
26 #include "registry.h"
27 #include "AppUtils.h"
28 #include "StringUtils.h"
29 #include "UnicodeUtils.h"
30 #include "TempFile.h"
31 #include "IconMenu.h"
32 #include "BrowseRefsDlg.h"
33 #include "SmartHandle.h"
34 #include "LogOrdering.h"
36 #define WM_TGIT_REFRESH_SELECTION (WM_APP + 1)
38 IMPLEMENT_DYNAMIC(CLogDlg, CResizableStandAloneDialog)
39 CLogDlg::CLogDlg(CWnd* pParent /*=NULL*/)
40 : CResizableStandAloneDialog(CLogDlg::IDD, pParent)
41 , m_wParam(0)
42 , m_currentChangedArray(NULL)
43 , m_nSortColumn(0)
44 , m_bFollowRenames(false)
45 , m_bSelect(false)
46 , m_bSelectionMustBeSingle(true)
47 , m_bShowTags(true)
48 , m_bShowLocalBranches(true)
49 , m_bShowRemoteBranches(true)
50 , m_bNoMerges(false)
51 , m_iHidePaths(0)
52 , m_bWalkBehavior(FALSE)
53 , m_bFirstParent(false)
54 , m_bWholeProject(FALSE)
55 , m_iCompressedGraph(0)
57 , m_bSelectionMustBeContinuous(false)
59 , m_sLogInfo(_T(""))
61 , m_bCancelled(FALSE)
62 , m_pNotifyWindow(NULL)
64 , m_bAscending(FALSE)
66 , m_limit(0)
67 , m_hAccel(NULL)
68 , m_bNavigatingWithSelect(false)
70 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE);
71 m_bFilterCaseSensitively = !!CRegDWORD(L"Software\\TortoiseGit\\FilterCaseSensitively", FALSE);
72 m_bAsteriskLogPrefix = !!CRegDWORD(L"Software\\TortoiseGit\\AsteriskLogPrefix", TRUE);
73 m_LogList.m_SelectedFilters = CRegDWORD(_T("Software\\TortoiseGit\\SelectedLogFilters"), LOGFILTER_ALL);
75 CString str;
76 str=g_Git.m_CurrentDir;
77 str.Replace(_T(":"),_T("_"));
78 str=CString(_T("Software\\TortoiseGit\\LogDialog\\AllBranch\\"))+str;
80 m_regbAllBranch=CRegDWORD(str,FALSE);
82 m_bAllBranch=m_regbAllBranch;
84 str = g_Git.m_CurrentDir;
85 str.Replace(_T(":"),_T("_"));
86 m_regShowWholeProject = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ShowWholeProject\\") + str, FALSE);
87 m_bWholeProject = m_regShowWholeProject;
88 m_regbShowTags = CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\ShowTags\\") + str, TRUE);
89 m_bShowTags = !!m_regbShowTags;
90 m_regbShowLocalBranches = CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\ShowLocalBranches\\") + str, TRUE);
91 m_bShowLocalBranches = !!m_regbShowLocalBranches;
92 m_regbShowRemoteBranches = CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\ShowRemoteBranches\\") + str, TRUE);
93 m_bShowRemoteBranches = !!m_regbShowRemoteBranches;
95 m_bShowUnversioned = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
97 m_bShowGravatar = !!CRegDWORD(_T("Software\\TortoiseGit\\EnableGravatar"), FALSE);
98 m_regbShowGravatar = CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\ShowGravatar\\") + str, m_bShowGravatar);
99 m_bShowGravatar = !!m_regbShowGravatar;
100 m_bShowDescribe = !!CRegDWORD(_T("Software\\TortoiseGit\\ShowDescribe"));
103 CLogDlg::~CLogDlg()
106 m_regbAllBranch = m_bAllBranch;
107 m_regbShowTags = m_bShowTags;
108 m_regbShowLocalBranches = m_bShowLocalBranches;
109 m_regbShowRemoteBranches = m_bShowRemoteBranches;
110 m_regbShowGravatar = m_bShowGravatar;
112 m_CurrentFilteredChangedArray.RemoveAll();
116 void CLogDlg::DoDataExchange(CDataExchange* pDX)
118 CResizableStandAloneDialog::DoDataExchange(pDX);
119 DDX_Control(pDX, IDC_LOGLIST, m_LogList);
120 DDX_Control(pDX, IDC_LOGMSG, m_ChangedFileListCtrl);
121 DDX_Control(pDX, IDC_PROGRESS, m_LogProgress);
122 DDX_Control(pDX, IDC_SPLITTERTOP, m_wndSplitter1);
123 DDX_Control(pDX, IDC_SPLITTERBOTTOM, m_wndSplitter2);
124 DDX_Text(pDX, IDC_SEARCHEDIT, m_LogList.m_sFilterText);
125 DDX_Control(pDX, IDC_DATEFROM, m_DateFrom);
126 DDX_Control(pDX, IDC_DATETO, m_DateTo);
127 DDX_Control(pDX, IDC_LOG_JUMPTYPE, m_JumpType);
128 DDX_Control(pDX, IDC_LOG_JUMPUP, m_JumpUp);
129 DDX_Control(pDX, IDC_LOG_JUMPDOWN, m_JumpDown);
130 DDX_Text(pDX, IDC_LOGINFO, m_sLogInfo);
131 DDX_Check(pDX, IDC_LOG_ALLBRANCH,m_bAllBranch);
132 DDX_Check(pDX, IDC_SHOWWHOLEPROJECT,m_bWholeProject);
133 DDX_Check(pDX, IDC_WALKBEHAVIOUR, m_bWalkBehavior);
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_BN_CLICKED(IDC_WALKBEHAVIOUR, OnBnClickedWalkBehaviour)
166 ON_BN_CLICKED(IDC_VIEW, OnBnClickedView)
167 ON_BN_CLICKED(IDC_SHOWWHOLEPROJECT, OnBnClickShowWholeProject)
168 ON_NOTIFY(LVN_COLUMNCLICK,IDC_LOGLIST, OnLvnColumnclick)
169 ON_COMMAND(MSG_FETCHED_DIFF, OnBnClickedHidepaths)
170 ON_BN_CLICKED(IDC_LOG_ALLBRANCH, OnBnClickedAllBranch)
171 ON_EN_CHANGE(IDC_FILTER, OnEnChangeFileFilter)
173 ON_NOTIFY(DTN_DROPDOWN, IDC_DATEFROM, &CLogDlg::OnDtnDropdownDatefrom)
174 ON_NOTIFY(DTN_DROPDOWN, IDC_DATETO, &CLogDlg::OnDtnDropdownDateto)
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(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
190 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED, &CLogDlg::OnFileListCtrlItemChanged)
191 ON_WM_MOVE()
192 ON_WM_MOVING()
193 ON_WM_SIZING()
194 END_MESSAGE_MAP()
196 enum JumpType
198 JumpType_AuthorEmail,
199 JumpType_CommitterEmail,
200 JumpType_MergePoint,
201 JumpType_Parent1,
202 JumpType_Parent2,
203 JumpType_Tag,
204 JumpType_TagFF,
205 JumpType_Branch,
206 JumpType_BranchFF,
207 JumpType_History,
210 void CLogDlg::SetParams(const CTGitPath& orgPath, const CTGitPath& path, CString hightlightRevision, CString range, int limit)
212 m_orgPath = orgPath;
213 m_path = path;
214 m_hightlightRevision = hightlightRevision;
216 if (range == GIT_REV_ZERO)
217 range = _T("HEAD");
219 if (!(range.IsEmpty() || range == _T("HEAD")))
220 m_bAllBranch = BST_UNCHECKED;
222 SetRange(range);
224 m_limit = limit;
225 if (::IsWindow(m_hWnd))
226 UpdateData(FALSE);
229 void CLogDlg::SetFilter(const CString& findstr, LONG findtype, bool findregex)
231 m_LogList.m_sFilterText = findstr;
232 if (findtype)
233 m_LogList.m_SelectedFilters = findtype;
234 m_LogList.m_bFilterWithRegex = m_bFilterWithRegex = findregex;
237 BOOL CLogDlg::OnInitDialog()
239 CString temp;
240 CResizableStandAloneDialog::OnInitDialog();
241 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
243 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
244 // do this, Explorer would be unable to send that message to our window if we
245 // were running elevated. It's OK to make the call all the time, since if we're
246 // not elevated, this is a no-op.
247 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
248 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
249 CAutoLibrary hUser = AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
250 if (hUser)
252 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
253 if (pfnChangeWindowMessageFilterEx)
255 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
258 m_pTaskbarList.Release();
259 if (FAILED(m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList)))
260 m_pTaskbarList = nullptr;
262 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_LOGDLG));
264 // use the state of the "stop on copy/rename" option from the last time
265 UpdateData(FALSE);
267 // set the font to use in the log message view, configured in the settings dialog
268 CAppUtils::CreateFontForLogs(m_logFont);
269 GetDlgItem(IDC_MSGVIEW)->SetFont(&m_logFont);
270 // make the log message rich edit control send a message when the mouse pointer is over a link
271 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_SETEVENTMASK, NULL, ENM_LINK | ENM_SCROLL);
273 // "unrelated paths" should be in gray color
274 m_iHidePaths = 2;
276 // set up the columns
277 m_LogList.DeleteAllItems();
279 m_LogList.m_Path=m_path;
280 m_LogList.m_hasWC = m_LogList.m_bShowWC = !GitAdminDir::IsBareRepo(g_Git.m_CurrentDir);
281 m_LogList.InsertGitColumn();
283 if (m_bWholeProject)
284 m_LogList.m_Path.Reset();
286 m_ChangedFileListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS |GITSLC_COLADD|GITSLC_COLDEL, _T("LogDlg"), (GITSLC_POPALL ^ (GITSLC_POPIGNORE|GITSLC_POPRESTORE)), false, m_LogList.m_hasWC, GITSLC_COLEXT | GITSLC_COLSTATUS | GITSLC_COLADD| GITSLC_COLDEL);
288 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
290 SetDlgTitle();
292 CheckRegexpTooltip();
294 SetSplitterRange();
296 // the filter control has a 'cancel' button (the red 'X'), we need to load its bitmap
297 m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);
298 m_cFilter.SetInfoIcon(IDI_LOGFILTER);
299 m_cFilter.SetValidator(this);
301 AdjustControlSize(IDC_LOG_ALLBRANCH);
302 AdjustControlSize(IDC_SHOWWHOLEPROJECT);
304 GetClientRect(m_DlgOrigRect);
305 m_LogList.GetClientRect(m_LogListOrigRect);
306 GetDlgItem(IDC_MSGVIEW)->GetClientRect(m_MsgViewOrigRect);
307 m_ChangedFileListCtrl.GetClientRect(m_ChgOrigRect);
309 m_DateFrom.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
310 m_DateTo.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
312 m_staticRef.SetURL(CString());
314 // resizable stuff
315 AddAnchor(IDC_STATIC_REF, TOP_LEFT);
316 //AddAnchor(IDC_BUTTON_BROWSE_REF, TOP_LEFT);
317 AddAnchor(IDC_FROMLABEL, TOP_LEFT);
318 AddAnchor(IDC_DATEFROM, TOP_LEFT);
319 AddAnchor(IDC_TOLABEL, TOP_LEFT);
320 AddAnchor(IDC_DATETO, TOP_LEFT);
322 SetFilterCueText();
323 AddAnchor(IDC_SEARCHEDIT, TOP_LEFT, TOP_RIGHT);
324 AddAnchor(IDC_LOG_JUMPTYPE, TOP_RIGHT);
325 AddAnchor(IDC_LOG_JUMPUP, TOP_RIGHT);
326 AddAnchor(IDC_LOG_JUMPDOWN, TOP_RIGHT);
328 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
329 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
330 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
331 AddAnchor(IDC_PIC_AUTHOR, TOP_RIGHT);
332 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
333 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
335 AddAnchor(IDC_LOGINFO, BOTTOM_LEFT, BOTTOM_RIGHT);
336 AddAnchor(IDC_WALKBEHAVIOUR, BOTTOM_LEFT);
337 AddAnchor(IDC_VIEW, BOTTOM_LEFT);
338 AddAnchor(IDC_LOG_ALLBRANCH,BOTTOM_LEFT);
339 AddAnchor(IDC_FILTER, BOTTOM_LEFT, BOTTOM_RIGHT);
340 AddAnchor(IDC_SHOWWHOLEPROJECT, BOTTOM_LEFT);
341 AddAnchor(IDC_REFRESH, BOTTOM_LEFT);
342 AddAnchor(IDC_STATBUTTON, BOTTOM_LEFT);
343 AddAnchor(IDC_PROGRESS, BOTTOM_LEFT, BOTTOM_RIGHT);
344 AddAnchor(IDOK, BOTTOM_RIGHT);
345 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
346 AddAnchor(IDHELP, BOTTOM_RIGHT);
348 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_LOCAL_BRANCHES;
349 if (m_bAllBranch == BST_CHECKED)
350 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
351 else if (m_bAllBranch == BST_INDETERMINATE)
352 m_LogList.m_ShowMask |= CGit::LOG_INFO_LOCAL_BRANCHES;
353 else
354 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
356 HandleShowLabels(m_bShowTags, LOGLIST_SHOWTAGS);
357 HandleShowLabels(m_bShowLocalBranches, LOGLIST_SHOWLOCALBRANCHES);
358 HandleShowLabels(m_bShowRemoteBranches, LOGLIST_SHOWREMOTEBRANCHES);
360 // SetPromptParentWindow(m_hWnd);
361 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_AUTHOREMAIL)));
362 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_COMMITTEREMAIL)));
363 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_MERGEPOINT)));
364 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_PARENT1)));
365 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_PARENT2)));
366 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_TAG)));
367 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_TAG_FF)));
368 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_BRANCH)));
369 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_BRANCH_FF)));
370 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_SELECTION_HISTORY)));
371 m_JumpType.SetCurSel(0);
372 m_JumpUp.SetIcon((HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_JUMPUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR));
373 m_JumpDown.SetIcon((HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_JUMPDOWN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR));
375 if (hWndExplorer)
376 CenterWindow(CWnd::FromHandle(hWndExplorer));
377 EnableSaveRestore(_T("LogDlg"));
379 DWORD yPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
380 DWORD yPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
381 RECT rcDlg, rcLogList, rcChgMsg;
382 GetClientRect(&rcDlg);
383 m_LogList.GetWindowRect(&rcLogList);
384 ScreenToClient(&rcLogList);
385 m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg);
386 ScreenToClient(&rcChgMsg);
387 if (yPos1)
389 RECT rectSplitter;
390 m_wndSplitter1.GetWindowRect(&rectSplitter);
391 ScreenToClient(&rectSplitter);
392 int delta = yPos1 - rectSplitter.top;
394 if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30))
396 m_wndSplitter1.SetWindowPos(NULL, rectSplitter.left, yPos1, 0, 0, SWP_NOSIZE);
397 DoSizeV1(delta);
400 if (yPos2)
402 RECT rectSplitter;
403 m_wndSplitter2.GetWindowRect(&rectSplitter);
404 ScreenToClient(&rectSplitter);
405 int delta = yPos2 - rectSplitter.top;
407 if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30))
409 m_wndSplitter2.SetWindowPos(NULL, rectSplitter.left, yPos2, 0, 0, SWP_NOSIZE);
410 DoSizeV2(delta);
414 SetSplitterRange();
416 if (m_bSelect)
418 // the dialog is used to select revisions
419 // enable the OK button if appropriate
420 EnableOKButton();
422 else
424 // the dialog is used to just view log messages
425 // hide the OK button and set text on Cancel button to OK
426 GetDlgItemText(IDOK, temp);
427 SetDlgItemText(IDCANCEL, temp);
428 GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
431 // first start a thread to obtain the log messages without
432 // blocking the dialog
433 //m_tTo = 0;
434 //m_tFrom = (DWORD)-1;
436 // scroll to user selected or current revision
437 if (m_hightlightRevision.IsEmpty() || g_Git.GetHash(m_LogList.m_lastSelectedHash, m_hightlightRevision))
439 if (g_Git.GetHash(m_LogList.m_lastSelectedHash, _T("HEAD")))
440 MessageBox(g_Git.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR);
443 if (g_Git.GetConfigValueBool(_T("tgit.logshowpatch")))
444 TogglePatchView();
446 m_LogList.FetchLogAsync(this);
447 ShowGravatar();
448 m_gravatar.Init();
450 m_cFileFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);
451 m_cFileFilter.SetInfoIcon(IDI_FILTEREDIT);
452 temp.LoadString(IDS_FILEDIFF_FILTERCUE);
453 temp = _T(" ") + temp;
454 m_cFileFilter.SetCueBanner(temp);
456 GetDlgItem(IDC_LOGLIST)->SetFocus();
458 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxRefHistoryItems"), 5));
459 CString reg;
460 reg.Format(_T("Software\\TortoiseGit\\History\\log-refs\\%s"), g_Git.m_CurrentDir);
461 reg.Replace(_T(':'),_T('_'));
462 m_History.Load(reg, _T("ref"));
464 ShowStartRef();
465 return FALSE;
468 LRESULT CLogDlg::OnLogListLoading(WPARAM wParam, LPARAM /*lParam*/)
470 int cur=(int)wParam;
472 if( cur == GITLOG_START )
474 CString temp;
475 temp.LoadString(IDS_PROGRESSWAIT);
477 this->m_LogList.ShowText(temp, true);
479 // We use a progress bar while getting the logs
480 m_LogProgress.SetRange32(0, 100);
481 m_LogProgress.SetPos(0);
482 if (m_pTaskbarList)
484 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
485 m_pTaskbarList->SetProgressValue(m_hWnd, 0, 100);
488 GetDlgItem(IDC_WALKBEHAVIOUR)->ShowWindow(SW_HIDE);
489 GetDlgItem(IDC_VIEW)->ShowWindow(SW_HIDE);
490 GetDlgItem(IDC_STATBUTTON)->ShowWindow(SW_HIDE);
491 GetDlgItem(IDC_PROGRESS)->ShowWindow(TRUE);
493 DialogEnableWindow(IDC_WALKBEHAVIOUR, FALSE);
494 DialogEnableWindow(IDC_STATBUTTON, FALSE);
495 //DialogEnableWindow(IDC_REFRESH, FALSE);
496 DialogEnableWindow(IDC_VIEW, FALSE);
499 else if( cur == GITLOG_END)
501 if(this->m_LogList.HasText())
503 this->m_LogList.ClearText();
505 UpdateLogInfoLabel();
507 if (m_pTaskbarList)
508 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
510 DialogEnableWindow(IDC_SHOWWHOLEPROJECT, !m_bFollowRenames && !m_path.IsEmpty());
512 DialogEnableWindow(IDC_STATBUTTON, !(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC));
513 DialogEnableWindow(IDC_REFRESH, TRUE);
514 DialogEnableWindow(IDC_VIEW, TRUE);
515 DialogEnableWindow(IDC_WALKBEHAVIOUR, TRUE);
516 // PostMessage(WM_TIMER, LOGFILTER_TIMER);
517 GetDlgItem(IDC_WALKBEHAVIOUR)->ShowWindow(SW_SHOW);
518 GetDlgItem(IDC_VIEW)->ShowWindow(SW_SHOW);
519 GetDlgItem(IDC_STATBUTTON)->ShowWindow(SW_SHOW);
520 GetDlgItem(IDC_PROGRESS)->ShowWindow(FALSE);
521 //CTime time=m_LogList.GetOldestTime();
522 CTime begin,end;
523 m_LogList.GetTimeRange(begin,end);
525 if(m_LogList.m_From == -1)
526 m_DateFrom.SetTime(&begin);
528 if(m_LogList.m_To == -1)
529 m_DateTo.SetTime(&end);
533 else
535 if(this->m_LogList.HasText())
537 this->m_LogList.ClearText();
538 this->m_LogList.Invalidate();
540 UpdateLogInfoLabel();
541 m_LogProgress.SetPos(cur);
542 if (m_pTaskbarList)
544 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
545 m_pTaskbarList->SetProgressValue(m_hWnd, cur, 100);
548 return 0;
550 void CLogDlg::SetDlgTitle()
552 if (m_sTitle.IsEmpty())
553 GetWindowText(m_sTitle);
555 if (m_LogList.m_Path.IsEmpty() || m_orgPath.GetWinPathString().IsEmpty())
557 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
559 else
560 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);
563 void CLogDlg::CheckRegexpTooltip()
565 CWnd *pWnd = GetDlgItem(IDC_SEARCHEDIT);
566 // Since tooltip describes regexp features, show it only if regexps are enabled.
567 if (m_bFilterWithRegex)
569 m_tooltips.AddTool(pWnd, IDS_LOG_FILTER_REGEX_TT);
571 else
572 m_tooltips.DelTool(pWnd);
575 void CLogDlg::EnableOKButton()
577 if (m_bSelect)
579 // the dialog is used to select revisions
580 if (m_bSelectionMustBeSingle)
582 // enable OK button if only a single revision is selected
583 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()==1));
585 else if (m_bSelectionMustBeContinuous)
586 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));
587 else
588 DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);
590 else
591 DialogEnableWindow(IDOK, TRUE);
594 bool LookLikeGitHash(const CString& msg, int &pos)
596 int c = 0;
597 for (; pos < msg.GetLength(); ++pos)
599 if (msg[pos] >= '0' && msg[pos] <= '9' || msg[pos] >= 'a' && msg[pos] <= 'f')
601 c++;
603 else
605 return c >= g_Git.GetShortHASHLength() && c <= GIT_HASH_SIZE * 2;
608 return c >= g_Git.GetShortHASHLength() && c <= GIT_HASH_SIZE * 2;
611 std::vector<CHARRANGE> FindGitHashPositions(const CString& msg, int offset)
613 std::vector<CHARRANGE> result;
614 offset = offset < 0 ? 0 : offset;
615 int old = offset;
616 while (offset < msg.GetLength())
618 old = offset;
619 TCHAR e = msg[offset];
620 if (e == '\n')
622 ++offset;
623 if (msg.Mid(offset, 11) == _T("git-svn-id:")
624 || msg.Mid(offset, 14) == _T("Signed-off-by:")
625 || msg.Mid(offset, 10) == _T("Change-Id:")
628 offset += 10;
629 while (offset < msg.GetLength())
631 if (msg[offset++] == '\n')
632 break;
634 continue;
637 else if (e >= 'A' && e <= 'Z' || e >= 'h' && e <= 'z')
641 e = msg[++offset];
642 } while (offset < msg.GetLength() && (e >= 'A' && e <= 'Z' || e >= 'a' && e <= 'z' || e >= '0' && e <= '9'));
644 else if (e >= 'a' && e <= 'g' || e >= '0' && e <= '9')
646 if (e == 'g')
648 ++old;
649 ++offset;
651 if (LookLikeGitHash(msg, offset))
653 TCHAR d = offset < msg.GetLength() ? msg[offset] : '\0';
654 if (!((d >= 'A' && d <= 'Z') || (d >= 'a' && d <= 'z') || (d >= '0' && d <= '9')))
656 CHARRANGE range = { old, offset };
657 result.push_back(range);
660 ++offset;
662 else
664 ++offset;
668 return result;
671 BOOL FindGitHash(const CString& msg, int offset, CWnd *pWnd)
673 std::vector<CHARRANGE> positions = FindGitHashPositions(msg, offset);
674 CAppUtils::SetCharFormat(pWnd, CFM_LINK, CFE_LINK, positions);
676 return positions.empty() ? FALSE : TRUE;
679 static int DescribeCommit(CGitHash& hash, CString& result)
681 CAutoRepository repo(g_Git.GetGitRepository());
682 if (!repo)
683 return -1;
684 CAutoObject commit;
685 if (git_object_lookup(commit.GetPointer(), repo, (const git_oid *)hash.m_hash, GIT_OBJ_COMMIT))
686 return -1;
688 CAutoDescribeResult describe;
689 git_describe_options describe_options = GIT_DESCRIBE_OPTIONS_INIT;
690 describe_options.describe_strategy = CRegDWORD(_T("Software\\TortoiseGit\\DescribeStrategy"), GIT_DESCRIBE_DEFAULT);
691 if (git_describe_commit(describe.GetPointer(), (git_object *)commit, &describe_options))
692 return -1;
694 CAutoBuf describe_buf;
695 git_describe_format_options format_options = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
696 format_options.abbreviated_size = CRegDWORD(_T("Software\\TortoiseGit\\DescribeAbbreviatedSize"), GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE);
697 format_options.always_use_long_format = CRegDWORD(_T("Software\\TortoiseGit\\DescribeAlwaysLong"));
698 if (git_describe_format(describe_buf, describe, &format_options))
699 return -1;
701 result = CUnicodeUtils::GetUnicode(describe_buf->ptr);
702 return 0;
705 void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)
707 // we fill here the log message rich edit control,
708 // and also populate the changed files list control
709 // according to the selected revision(s).
711 CRichEditCtrl * pMsgView = (CRichEditCtrl*)GetDlgItem(IDC_MSGVIEW);
712 // empty the log message view
713 pMsgView->SetWindowText(_T(" "));
714 FillPatchView(true);
715 // empty the changed files list
716 m_ChangedFileListCtrl.SetRedraw(FALSE);
717 // InterlockedExchange(&m_bNoDispUpdates, TRUE);
718 m_currentChangedArray = NULL;
719 m_ChangedFileListCtrl.DeleteAllItems();
721 // if we're not here to really show a selected revision, just
722 // get out of here after clearing the views, which is what is intended
723 // if that flag is not set.
724 if (!bShow)
726 // force a redraw
727 m_ChangedFileListCtrl.Invalidate();
728 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
729 m_ChangedFileListCtrl.SetRedraw(TRUE);
730 m_gravatar.LoadGravatar();
731 return;
734 // depending on how many revisions are selected, we have to do different
735 // tasks.
736 int selCount = m_LogList.GetSelectedCount();
737 if (selCount == 0)
739 // if nothing is selected, we have nothing more to do
740 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
741 m_ChangedFileListCtrl.SetRedraw(TRUE);
742 m_gravatar.LoadGravatar();
743 return;
745 else if (selCount == 1)
747 // if one revision is selected, we have to fill the log message view
748 // with the corresponding log message, and also fill the changed files
749 // list fully.
750 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
751 int selIndex = m_LogList.GetNextSelectedItem(pos);
752 if (selIndex >= m_LogList.m_arShownList.GetCount())
754 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
755 m_ChangedFileListCtrl.SetRedraw(TRUE);
756 return;
758 Locker lock(m_LogList.m_critSec_AsyncDiff);
759 GitRevLoglist* pLogEntry = reinterpret_cast<GitRevLoglist*>(m_LogList.m_arShownList.SafeGetAt(selIndex));
762 CString out_describe;
763 if (m_bShowDescribe)
765 CString result;
766 if (!DescribeCommit(pLogEntry->m_CommitHash, result))
767 out_describe = _T("Describe: ") + result + _T("\r\n");
770 // set the log message text
771 pMsgView->SetWindowText(CString(MAKEINTRESOURCE(IDS_HASH)) + _T(": ") + pLogEntry->m_CommitHash.ToString() + _T("\r\n") + out_describe + _T("\r\n"));
772 // turn bug ID's into links if the bugtraq: properties have been set
773 // and we can find a match of those in the log message
775 pMsgView->SetSel(-1,-1);
776 CAppUtils::SetCharFormat(pMsgView, CFM_BOLD, CFE_BOLD);
778 CString msg = m_bAsteriskLogPrefix ? _T("* ") : _T("");
779 msg+=pLogEntry->GetSubject();
780 pMsgView->ReplaceSel(msg);
782 pMsgView->SetSel(-1,-1);
783 CAppUtils::SetCharFormat(pMsgView, CFM_BOLD, 0);
785 msg=_T("\n");
786 msg+=pLogEntry->GetBody();
788 if(!pLogEntry->m_Notes.IsEmpty())
790 msg+= _T("\n*") + CString(MAKEINTRESOURCE(IDS_NOTES)) + _T("* ");
791 msg+= pLogEntry->m_Notes;
792 msg+= _T("\n\n");
795 CString tagInfo = m_LogList.GetTagInfo(pLogEntry);
796 if(!tagInfo.IsEmpty())
797 tagInfo = _T("\n*") + CString(MAKEINTRESOURCE(IDS_PROC_LOG_TAGINFO)) + _T("*\n\n") + tagInfo;
798 msg += tagInfo;
800 pMsgView->ReplaceSel(msg);
802 CString text;
803 pMsgView->GetWindowText(text);
804 // the rich edit control doesn't count the CR char!
805 // to be exact: CRLF is treated as one char.
806 text.Remove('\r');
808 int findHashStart = text.Find('\n');
809 if (!out_describe.IsEmpty())
810 findHashStart = text.Find('\n', findHashStart + 1);
811 FindGitHash(text, findHashStart, pMsgView);
812 m_LogList.m_ProjectProperties.FindBugID(text, pMsgView);
813 CAppUtils::StyleURLs(text, pMsgView);
814 if (((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\StyleCommitMessages"), TRUE)) == TRUE)
815 CAppUtils::FormatTextInRichEditControl(pMsgView);
817 CHARRANGE range;
818 range.cpMin = 0;
819 range.cpMax = 0;
820 pMsgView->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
822 CString matchpath=this->m_path.GetGitPathString();
824 bool mightNeedReset = true;
826 int count = pLogEntry->GetFiles(&m_LogList).GetCount();
827 for (int i = 0 ; i < count && (!matchpath.IsEmpty()); ++i)
829 if( m_bWholeProject )
830 break;
832 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action &= ~(CTGitPath::LOGACTIONS_HIDE|CTGitPath::LOGACTIONS_GRAY);
833 mightNeedReset = false;
835 if(pLogEntry->GetFiles(&m_LogList)[i].GetGitPathString().Left(matchpath.GetLength()) != matchpath && pLogEntry->GetFiles(&m_LogList)[i].GetGitOldPathString().Left(matchpath.GetLength()) != matchpath)
837 if (m_iHidePaths == 1)
838 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;
839 else if (m_iHidePaths == 2)
840 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_GRAY;
844 if (mightNeedReset)
846 for (int i = 0 ; i < count; ++i)
847 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action &= ~CTGitPath::LOGACTIONS_HIDE;
850 CString fileFilter;
851 m_cFileFilter.GetWindowText(fileFilter);
852 fileFilter.MakeLower();
853 for (int i = 0; i < count && (!fileFilter.IsEmpty()); ++i)
855 CString sPath = pLogEntry->GetFiles(&m_LogList)[i].GetGitPathString();
856 sPath.MakeLower();
857 if (sPath.Find(fileFilter) < 0)
858 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;
861 m_ChangedFileListCtrl.UpdateWithGitPathList(pLogEntry->GetFiles(&m_LogList));
862 m_ChangedFileListCtrl.m_CurrentVersion=pLogEntry->m_CommitHash;
863 if (pLogEntry->m_CommitHash.IsEmpty() && m_bShowUnversioned)
865 m_ChangedFileListCtrl.UpdateUnRevFileList(pLogEntry->GetUnRevFiles());
866 m_ChangedFileListCtrl.Show(GITSLC_SHOWVERSIONED | GITSLC_SHOWUNVERSIONED);
868 else
869 m_ChangedFileListCtrl.Show(GITSLC_SHOWVERSIONED);
871 m_ChangedFileListCtrl.SetBusyString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES)));
873 if(!pLogEntry->m_IsDiffFiles)
874 m_ChangedFileListCtrl.SetBusy(TRUE);
875 else
876 m_ChangedFileListCtrl.SetBusy(FALSE);
878 m_ChangedFileListCtrl.SetRedraw(TRUE);
879 m_gravatar.LoadGravatar(pLogEntry->GetAuthorEmail());
880 return;
884 else
886 // more than one revision is selected:
887 // the log message view must be emptied
888 // the changed files list contains all the changed paths from all
889 // selected revisions, with 'doubles' removed
890 m_currentChangedPathList = GetChangedPathsFromSelectedRevisions(true);
891 m_gravatar.LoadGravatar();
894 // redraw the views
895 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
896 #if 0
897 if (m_currentChangedArray)
899 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedArray->GetCount());
900 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedArray->GetCount());
902 else if (m_currentChangedPathList.GetCount())
904 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedPathList.GetCount());
905 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedPathList.GetCount());
907 else
909 m_ChangedFileListCtrl.SetItemCountEx(0);
910 m_ChangedFileListCtrl.Invalidate();
912 #endif
913 // sort according to the settings
914 if (m_nSortColumnPathList > 0)
915 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
916 else
917 SetSortArrow(&m_ChangedFileListCtrl, -1, false);
918 m_ChangedFileListCtrl.SetRedraw(TRUE);
922 void CLogDlg::FillPatchView(bool onlySetTimer)
924 if (!::IsWindow(this->m_patchViewdlg.m_hWnd))
925 return;
927 KillTimer(LOG_FILLPATCHVTIMER);
928 if (onlySetTimer)
930 SetTimer(LOG_FILLPATCHVTIMER, 100, nullptr);
931 return;
934 POSITION posLogList = m_LogList.GetFirstSelectedItemPosition();
935 if (posLogList == nullptr)
937 m_patchViewdlg.ClearView();
938 return; // nothing is selected, get out of here
941 GitRev * pLogEntry = reinterpret_cast<GitRev* >(m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(posLogList)));
942 if (pLogEntry == nullptr || m_LogList.GetNextSelectedItem(posLogList) != -1)
944 m_patchViewdlg.ClearView();
945 return;
948 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
949 CString out;
951 if (pos == nullptr)
953 int diffContext = 0;
954 if (CAppUtils::GetMsysgitVersion() > 0x01080100)
955 diffContext = g_Git.GetConfigValueInt32(_T("diff.context"), -1);
956 CStringA outA;
957 CString rev1 = pLogEntry->m_CommitHash.IsEmpty() ? _T("HEAD") : (pLogEntry->m_CommitHash.ToString() + _T("~1"));
958 CString rev2 = pLogEntry->m_CommitHash.IsEmpty() ? GIT_REV_ZERO : pLogEntry->m_CommitHash.ToString();
959 g_Git.GetUnifiedDiff(CTGitPath(), rev1, rev2, &outA, false, false, diffContext);
960 out = CUnicodeUtils::GetUnicode(outA);
962 else
964 while (pos)
966 int nSelect = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
967 CTGitPath * p = (CTGitPath*)m_ChangedFileListCtrl.GetItemData(nSelect);
968 if (p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER))
970 CString cmd;
971 if (pLogEntry->m_CommitHash.IsEmpty())
972 cmd.Format(_T("git.exe diff HEAD -- \"%s\""), p->GetGitPathString());
973 else
974 cmd.Format(_T("git.exe diff %s^%d..%s -- \"%s\""), pLogEntry->m_CommitHash.ToString(), p->m_ParentNo + 1, pLogEntry->m_CommitHash.ToString(), p->GetGitPathString());
975 g_Git.Run(cmd, &out, CP_UTF8);
980 m_patchViewdlg.SetText(out);
983 void CLogDlg::TogglePatchView()
985 m_patchViewdlg.m_pProjectProperties = &m_LogList.m_ProjectProperties;
986 m_patchViewdlg.m_ParentDlg = this;
987 if (!IsWindow(m_patchViewdlg.m_hWnd))
989 BOOL viewPatchEnabled = FALSE;
990 viewPatchEnabled = g_Git.GetConfigValueBool(_T("tgit.logshowpatch"));
991 if (viewPatchEnabled == FALSE)
992 g_Git.SetConfigValue(_T("tgit.logshowpatch"), _T("true"));
993 m_patchViewdlg.Create(IDD_PATCH_VIEW, this);
994 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTHTRACKING, TRUE);
995 CRect rect;
996 this->GetWindowRect(&rect);
998 m_patchViewdlg.ShowWindow(SW_SHOW);
999 m_patchViewdlg.SetWindowPos(nullptr, rect.right, rect.top, rect.Width(), rect.Height(), SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
1001 FillPatchView();
1003 else
1005 g_Git.SetConfigValue(_T("tgit.logshowpatch"), _T("false"));
1006 m_patchViewdlg.ShowWindow(SW_HIDE);
1007 m_patchViewdlg.DestroyWindow();
1011 LRESULT CLogDlg::OnFileListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
1013 FillPatchView(true);
1014 return 0;
1017 void CLogDlg::OnMoving(UINT fwSide, LPRECT pRect)
1019 __super::OnMoving(fwSide, pRect);
1021 if (!::IsWindow(m_patchViewdlg.m_hWnd))
1022 return;
1024 RECT patchrect;
1025 m_patchViewdlg.GetWindowRect(&patchrect);
1026 if (!::IsWindow(m_hWnd))
1027 return;
1029 RECT thisrect;
1030 GetWindowRect(&thisrect);
1031 if (patchrect.left == thisrect.right)
1033 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);
1037 void CLogDlg::OnSizing(UINT fwSide, LPRECT pRect)
1039 __super::OnSizing(fwSide, pRect);
1041 if (!::IsWindow(this->m_patchViewdlg.m_hWnd))
1042 return;
1044 CRect thisrect, patchrect;
1045 this->GetWindowRect(thisrect);
1046 this->m_patchViewdlg.GetWindowRect(patchrect);
1047 if (thisrect.right != patchrect.left)
1048 return;
1050 patchrect.left -= (thisrect.right - pRect->right);
1051 patchrect.right -= (thisrect.right - pRect->right);
1053 if (patchrect.bottom == thisrect.bottom)
1054 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
1055 if (patchrect.top == thisrect.top)
1056 patchrect.top -= thisrect.top - pRect->top;
1057 m_patchViewdlg.MoveWindow(patchrect);
1060 void CLogDlg::OnSelectSearchField()
1062 m_cFilter.SetSel(0, -1, FALSE);
1063 m_cFilter.SetFocus();
1066 void CLogDlg::GoBack()
1068 GoBackForward(false, false);
1071 void CLogDlg::GoForward()
1073 GoBackForward(false, true);
1076 void CLogDlg::GoBackAndSelect()
1078 GoBackForward(true, false);
1081 void CLogDlg::GoForwardAndSelect()
1083 GoBackForward(true, true);
1086 void CLogDlg::GoBackForward(bool select, bool bForward)
1088 m_LogList.m_highlight.Empty();
1089 CGitHash gotoHash;
1090 if (bForward ? m_LogList.m_selectionHistory.GoForward(gotoHash) : m_LogList.m_selectionHistory.GoBack(gotoHash))
1092 int i;
1093 for (i = 0; i < m_LogList.m_arShownList.GetCount(); ++i)
1095 GitRev *rev = (GitRev *)m_LogList.m_arShownList.SafeGetAt(i);
1096 if (!rev) continue;
1097 if (rev->m_CommitHash == gotoHash)
1099 m_LogList.EnsureVisible(i, FALSE);
1100 if (select)
1102 m_LogList.m_highlight.Empty();
1103 m_LogList.SetItemState(m_LogList.GetSelectionMark(), 0, LVIS_SELECTED);
1104 m_bNavigatingWithSelect = true;
1105 m_LogList.SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
1106 m_LogList.SetSelectionMark(i);
1107 m_bNavigatingWithSelect = false;
1109 else
1110 m_LogList.m_highlight = gotoHash;
1111 m_LogList.Invalidate();
1112 return;
1115 if (i == m_LogList.m_arShownList.GetCount())
1117 CString msg;
1118 msg.Format(IDS_LOG_NOT_VISIBLE, gotoHash.ToString());
1119 MessageBox(msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1120 return;
1123 PlaySound((LPCTSTR)SND_ALIAS_SYSTEMASTERISK, nullptr, SND_ASYNC | SND_ALIAS_ID);
1126 void CLogDlg::OnBnClickedRefresh()
1128 Refresh (true);
1131 void CLogDlg::Refresh (bool clearfilter /*autoGoOnline*/)
1133 m_limit = 0;
1134 m_LogList.Refresh(clearfilter);
1135 EnableOKButton();
1136 ShowStartRef();
1137 FillLogMessageCtrl(false);
1142 BOOL CLogDlg::Cancel()
1144 return m_bCancelled;
1147 void CLogDlg::SaveSplitterPos()
1149 if (!IsIconic())
1151 CRegDWORD regPos1(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
1152 CRegDWORD regPos2(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
1153 RECT rectSplitter;
1154 m_wndSplitter1.GetWindowRect(&rectSplitter);
1155 ScreenToClient(&rectSplitter);
1156 regPos1 = rectSplitter.top;
1157 m_wndSplitter2.GetWindowRect(&rectSplitter);
1158 ScreenToClient(&rectSplitter);
1159 regPos2 = rectSplitter.top;
1163 void CLogDlg::OnCancel()
1165 this->ShowWindow(SW_HIDE);
1167 // canceling means stopping the working thread if it's still running.
1168 m_LogList.SafeTerminateAsyncDiffThread();
1169 if (this->IsThreadRunning())
1171 m_LogList.SafeTerminateThread();
1173 UpdateData();
1175 SaveSplitterPos();
1176 __super::OnCancel();
1179 void CLogDlg::CopyChangedSelectionToClipBoard()
1182 POSITION posLogList = m_LogList.GetFirstSelectedItemPosition();
1183 if (posLogList == nullptr)
1184 return; // nothing is selected, get out of here
1186 CString sPaths;
1188 // CGitRev* pLogEntry = reinterpret_cast<CGitRev* >(m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1189 // if (posLogList)
1191 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
1192 while (pos)
1194 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
1195 CTGitPath *path = (CTGitPath*)m_ChangedFileListCtrl.GetItemData(nItem);
1196 if(path)
1197 sPaths += path->GetGitPathString();
1198 sPaths += _T("\r\n");
1201 #if 0
1202 else
1204 // only one revision is selected in the log dialog top pane
1205 // but multiple items could be selected in the changed items list
1206 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
1207 while (pos)
1209 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
1210 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(nItem);
1212 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
1214 // some items are hidden! So find out which item the user really selected
1215 INT_PTR selRealIndex = -1;
1216 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
1218 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1219 ++selRealIndex;
1220 if (selRealIndex == nItem)
1222 changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex);
1223 break;
1227 if (changedlogpath)
1229 sPaths += changedlogpath->sPath;
1230 sPaths += _T("\r\n");
1234 #endif
1235 sPaths.Trim();
1236 CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());
1240 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)
1242 // we have three separate context menus:
1243 // one for the branch label in the upper left
1244 // one shown on the log message list control,
1245 // one shown in the changed-files list control
1246 if (pWnd == GetDlgItem(IDC_STATIC_REF))
1248 CIconMenu popup;
1249 if (!popup.CreatePopupMenu())
1250 return;
1252 int cnt = 0;
1253 popup.AppendMenuIcon(++cnt, IDS_MENUREFBROWSE);
1254 popup.SetDefaultItem(cnt);
1255 popup.AppendMenuIcon(++cnt, _T("HEAD"));
1256 CGitHash fetchHead;
1257 g_Git.GetHash(fetchHead, g_Git.FixBranchName(_T("FETCH_HEAD")));
1258 popup.AppendMenuIcon(++cnt, _T("FETCH_HEAD"));
1259 popup.EnableMenuItem(cnt, fetchHead.IsEmpty());
1260 popup.AppendMenuIcon(++cnt, IDS_ALL);
1261 popup.EnableMenuItem(cnt, m_bFollowRenames);
1262 popup.AppendMenuIcon(++cnt, IDS_PROC_LOG_SELECT_LOCAL_BRANCHES);
1263 popup.EnableMenuItem(cnt, m_bFollowRenames);
1264 int offset = ++cnt;
1265 if (m_History.GetCount() > 0)
1267 popup.AppendMenu(MF_SEPARATOR, 0);
1268 for (size_t i = 0; i < m_History.GetCount(); ++i)
1270 CString entry = m_History.GetEntry(i);
1271 if (entry.GetLength() > 150)
1272 entry = entry.Left(150) + _T("...");
1273 popup.AppendMenuIcon(cnt++, entry);
1277 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1278 if (cmd == 0)
1279 return;
1280 else if (cmd == 1)
1282 OnBnClickedBrowseRef();
1283 return;
1286 m_LogList.m_ShowMask &= ~(CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES);
1287 m_bAllBranch = BST_UNCHECKED;
1288 if (cmd == 2)
1290 SetRange(g_Git.GetCurrentBranch(true));
1292 else if (cmd == 3)
1294 SetRange(fetchHead.ToString());
1296 else if (cmd == 4)
1298 m_bAllBranch = BST_CHECKED;
1299 m_LogList.m_ShowMask |= CGit::LOG_INFO_ALL_BRANCH;
1301 else if (cmd == 5)
1303 m_bAllBranch = BST_INDETERMINATE;
1304 m_LogList.m_ShowMask |= CGit::LOG_INFO_LOCAL_BRANCHES;
1306 else if (cmd >= offset)
1308 SetRange(m_History.GetEntry(cmd - offset));
1309 m_History.AddEntry(m_LogList.m_sRange);
1310 m_History.Save();
1313 UpdateData(FALSE);
1315 OnRefresh();
1316 FillLogMessageCtrl(false);
1318 return;
1320 int selCount = m_LogList.GetSelectedCount();
1321 if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))
1323 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1324 int selIndex = -1;
1325 if (pos)
1326 selIndex = m_LogList.GetNextSelectedItem(pos);
1328 GitRevLoglist* pRev = ((GitRevLoglist*)m_LogList.m_arShownList[selIndex]);
1330 if ((point.x == -1) && (point.y == -1))
1332 CRect rect;
1333 GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);
1334 ClientToScreen(&rect);
1335 point = rect.CenterPoint();
1337 CString sMenuItemText;
1338 CIconMenu popup;
1339 if (popup.CreatePopupMenu())
1341 long start = -1, end = -1;
1342 auto pEdit = (CRichEditCtrl *)GetDlgItem(IDC_MSGVIEW);
1343 pEdit->GetSel(start, end);
1344 // add the 'default' entries
1345 popup.AppendMenuIcon(WM_COPY, IDS_SCIEDIT_COPY, IDI_COPYCLIP);
1346 if (start >= end)
1347 popup.EnableMenuItem(WM_COPY, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1348 popup.AppendMenu(MF_SEPARATOR);
1349 sMenuItemText.LoadString(IDS_STATUSLIST_CONTEXT_COPYEXT);
1350 popup.AppendMenuIcon(EM_SETSEL, sMenuItemText, IDI_COPYCLIP);
1351 popup.AppendMenu(MF_SEPARATOR, NULL);
1352 sMenuItemText.LoadString(IDS_EDIT_NOTES);
1353 popup.AppendMenuIcon( CGitLogList::ID_EDITNOTE, sMenuItemText, IDI_EDIT);
1355 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1356 switch (cmd)
1358 case 0:
1359 break; // no command selected
1360 case EM_SETSEL:
1362 pEdit->SetRedraw(FALSE);
1363 int oldLine = pEdit->GetFirstVisibleLine();
1364 pEdit->SetSel(0, -1);
1365 pEdit->Copy();
1366 pEdit->SetSel(start, end);
1367 int newLine = pEdit->GetFirstVisibleLine();
1368 pEdit->LineScroll(oldLine - newLine);
1369 pEdit->SetRedraw(TRUE);
1370 pEdit->RedrawWindow();
1372 break;
1373 case WM_COPY:
1374 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);
1375 break;
1376 case CGitLogList::ID_EDITNOTE:
1377 CAppUtils::EditNote(pRev);
1378 this->FillLogMessageCtrl(true);
1379 break;
1385 void CLogDlg::OnOK()
1387 // since the log dialog is also used to select revisions for other
1388 // dialogs, we have to do some work before closing this dialog
1389 if (GetFocus() != GetDlgItem(IDOK))
1390 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter
1392 m_LogList.SafeTerminateAsyncDiffThread();
1393 if (this->IsThreadRunning())
1395 m_LogList.SafeTerminateThread();
1397 UpdateData();
1398 // check that one and only one row is selected
1399 if (m_LogList.GetSelectedCount() == 1)
1401 // get the selected row
1402 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1403 int selIndex = m_LogList.GetNextSelectedItem(pos);
1404 if (selIndex < m_LogList.m_arShownList.GetCount())
1406 // all ok, pick up the revision
1407 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
1408 // extract the hash
1409 m_sSelectedHash = pLogEntry->m_CommitHash;
1412 UpdateData(FALSE);
1413 SaveSplitterPos();
1414 __super::OnOK();
1416 #if 0
1417 if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))
1418 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.
1420 CString temp;
1421 CString buttontext;
1422 GetDlgItemText(IDOK, buttontext);
1423 temp.LoadString(IDS_MSGBOX_CANCEL);
1424 if (temp.Compare(buttontext) != 0)
1425 __super::OnOK(); // only exit if the button text matches, and that will match only if the thread isn't running anymore
1426 m_bCancelled = TRUE;
1427 m_selectedRevs.Clear();
1428 m_selectedRevsOneRange.Clear();
1429 if (m_pNotifyWindow)
1431 int selIndex = m_LogList.GetSelectionMark();
1432 if (selIndex >= 0)
1434 PLOGENTRYDATA pLogEntry = NULL;
1435 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1436 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1437 m_selectedRevs.AddRevision(pLogEntry->Rev);
1438 git_revnum_t lowerRev = pLogEntry->Rev;
1439 git_revnum_t higherRev = lowerRev;
1440 while (pos)
1442 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1443 git_revnum_t rev = pLogEntry->Rev;
1444 m_selectedRevs.AddRevision(pLogEntry->Rev);
1445 if (lowerRev > rev)
1446 lowerRev = rev;
1447 if (higherRev < rev)
1448 higherRev = rev;
1450 if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())
1452 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);
1454 BOOL bSentMessage = FALSE;
1455 if (m_LogList.GetSelectedCount() == 1)
1457 // if only one revision is selected, check if the path/url with which the dialog was started
1458 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.
1459 // if it was copied, use the copy from revision as lowerRev
1460 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))
1462 CString sUrl = m_path.GetGitPathString();
1463 if (!m_path.IsUrl())
1465 sUrl = GetURLFromPath(m_path);
1467 sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());
1468 for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)
1470 LogChangedPath * pData = pLogEntry->pArChangedPaths->SafeGetAt(cp);
1471 if (pData)
1473 if (sUrl.Compare(pData->sPath) == 0)
1475 if (!pData->sCopyFromPath.IsEmpty())
1477 lowerRev = pData->lCopyFromRev;
1478 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);
1479 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);
1480 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1481 bSentMessage = TRUE;
1488 if ( !bSentMessage )
1490 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);
1491 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);
1492 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1493 if (m_selectedRevsOneRange.GetCount())
1494 m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);
1498 UpdateData();
1499 CRegDWORD reg(_T("Software\\TortoiseGit\\ShowAllEntry"));
1500 SaveSplitterPos();
1501 #endif
1504 void CLogDlg::DoDiffFromLog(INT_PTR selIndex, GitRev* rev1, GitRev* rev2, bool /*blame*/, bool /*unified*/)
1506 DialogEnableWindow(IDOK, FALSE);
1507 // SetPromptApp(&theApp);
1508 theApp.DoWaitCursor(1);
1510 CString temppath;
1511 GetTempPath(temppath);
1513 CString file1;
1514 file1.Format(_T("%s%s_%s%s"),
1515 temppath,
1516 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1517 rev1->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength()),
1518 (*m_currentChangedArray)[selIndex].GetFileExtension());
1520 CString file2;
1521 file2.Format(_T("%s\\%s_%s%s"),
1522 temppath,
1523 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1524 rev2->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength()),
1525 (*m_currentChangedArray)[selIndex].GetFileExtension());
1527 CString cmd;
1528 CTGitPath &path = (CTGitPath &)(*m_currentChangedArray)[selIndex];
1530 if (g_Git.GetOneFile(rev1->m_CommitHash.ToString(), path, file1))
1532 CString out;
1533 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, path.GetGitPathString(), rev1->m_CommitHash.ToString(), file1);
1534 CMessageBox::Show(nullptr, g_Git.GetGitLastErr(out, CGit::GIT_CMD_GETONEFILE), _T("TortoiseGit"), MB_OK);
1535 theApp.DoWaitCursor(-1);
1536 EnableOKButton();
1537 return;
1539 if (g_Git.GetOneFile(rev2->m_CommitHash.ToString(), path, file2))
1541 CString out;
1542 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, path.GetGitPathString(), rev2->m_CommitHash.ToString(), file2);
1543 CMessageBox::Show(nullptr, g_Git.GetGitLastErr(out, CGit::GIT_CMD_GETONEFILE), _T("TortoiseGit"), MB_OK);
1544 theApp.DoWaitCursor(-1);
1545 EnableOKButton();
1546 return;
1549 CAppUtils::DiffFlags flags;
1550 CAppUtils::StartExtDiff(file1,file2,_T("A"),_T("B"),
1551 g_Git.CombinePath(path), g_Git.CombinePath(path),
1552 rev1->m_CommitHash.ToString(), rev2->m_CommitHash.ToString(),
1553 flags);
1555 theApp.DoWaitCursor(-1);
1556 EnableOKButton();
1559 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)
1561 // Skip Ctrl-C when copying text out of the log message or search filter
1562 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);
1563 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
1565 if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1567 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1569 m_LogList.DiffSelectedRevWithPrevious();
1570 return TRUE;
1573 if (GetFocus() == GetDlgItem(IDC_SEARCHEDIT))
1575 KillTimer(LOGFILTER_TIMER);
1576 m_limit = 0;
1577 m_LogList.Refresh(FALSE);
1578 FillLogMessageCtrl(false);
1580 if (GetFocus() == GetDlgItem(IDC_FILTER))
1582 KillTimer(FILEFILTER_TIMER);
1583 FillLogMessageCtrl();
1584 return TRUE;
1587 else if (pMsg->message == WM_XBUTTONUP)
1589 bool select = (pMsg->wParam & MK_SHIFT) == 0;
1590 if (HIWORD(pMsg->wParam) & XBUTTON1)
1591 GoBackForward(select, false);
1592 if (HIWORD(pMsg->wParam) & XBUTTON2)
1593 GoBackForward(select, true);
1594 if (HIWORD(pMsg->wParam) & (XBUTTON1 | XBUTTON2))
1595 return TRUE;
1597 if (m_hAccel && !bSkipAccelerator)
1599 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1600 if (ret)
1601 return TRUE;
1604 return __super::PreTranslateMessage(pMsg);
1608 BOOL CLogDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1610 //if (this->IsThreadRunning())
1611 if(m_LogList.m_bNoDispUpdates)
1613 // only show the wait cursor over the list control
1614 if ((pWnd)&&
1615 ((pWnd == GetDlgItem(IDC_LOGLIST))||
1616 (pWnd == GetDlgItem(IDC_MSGVIEW))||
1617 (pWnd == GetDlgItem(IDC_LOGMSG))))
1619 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1620 SetCursor(hCur);
1621 return TRUE;
1624 if ((pWnd) && (pWnd == GetDlgItem(IDC_MSGVIEW)))
1625 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1627 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1628 SetCursor(hCur);
1629 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1632 void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1634 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1635 *pResult = 0;
1636 //if (this->IsThreadRunning())
1637 if(m_LogList.m_bNoDispUpdates)
1638 return;
1639 if (pNMLV->iItem >= 0)
1641 if (!m_LogList.m_highlight.IsEmpty())
1643 m_LogList.m_highlight.Empty();
1644 m_LogList.Invalidate();
1646 this->m_LogList.m_nSearchIndex = pNMLV->iItem;
1647 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(pNMLV->iItem));
1648 if (pLogEntry == nullptr)
1649 return;
1650 m_LogList.m_lastSelectedHash = pLogEntry->m_CommitHash;
1651 if (pNMLV->iSubItem != 0)
1652 return;
1653 if ((pNMLV->iItem == m_LogList.m_arShownList.GetCount()))
1655 // remove the selected state
1656 if (pNMLV->uChanged & LVIF_STATE)
1658 m_LogList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);
1659 FillLogMessageCtrl();
1660 UpdateData(FALSE);
1661 UpdateLogInfoLabel();
1663 return;
1665 if (pNMLV->uChanged & LVIF_STATE)
1667 if ((pNMLV->uNewState & LVIS_SELECTED) && !m_bNavigatingWithSelect)
1669 m_LogList.m_selectionHistory.Add(m_LogList.m_lastSelectedHash);
1670 m_LogList.m_lastSelectedHash = pLogEntry->m_CommitHash;
1672 FillLogMessageCtrl();
1673 UpdateData(FALSE);
1676 else
1678 m_LogList.m_lastSelectedHash.Empty();
1679 FillLogMessageCtrl();
1680 UpdateData(FALSE);
1682 EnableOKButton();
1683 UpdateLogInfoLabel();
1686 void CLogDlg::OnLvnItemchangedLogmsg(NMHDR * /*pNMHDR*/, LRESULT * /*pResult*/)
1688 UpdateLogInfoLabel();
1691 void CLogDlg::OnEnLinkMsgview(NMHDR *pNMHDR, LRESULT *pResult)
1693 ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);
1694 if ((pEnLink->msg == WM_LBUTTONUP) || (pEnLink->msg == WM_SETCURSOR))
1696 CString url, msg;
1697 GetDlgItemText(IDC_MSGVIEW, msg);
1698 msg.Replace(_T("\r\n"), _T("\n"));
1699 url = msg.Mid(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax-pEnLink->chrg.cpMin);
1700 auto findResult = m_LogList.m_ProjectProperties.FindBugIDPositions(msg);
1701 if (std::find_if(findResult.begin(), findResult.end(),
1702 [=] (const CHARRANGE &cr) -> bool { return cr.cpMin == pEnLink->chrg.cpMin && cr.cpMax == pEnLink->chrg.cpMax; }
1703 ) != findResult.end())
1705 url = m_LogList.m_ProjectProperties.GetBugIDUrl(url);
1706 url = GetAbsoluteUrlFromRelativeUrl(url);
1708 if (::PathIsURL(url))
1710 if (pEnLink->msg == WM_LBUTTONUP)
1711 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
1712 else
1714 static RECT prevRect = { 0 };
1715 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
1716 if (pMsgView)
1718 RECT rc;
1719 POINTL pt;
1720 pMsgView->SendMessage(EM_POSFROMCHAR, (WPARAM)&pt, pEnLink->chrg.cpMin);
1721 rc.left = pt.x;
1722 rc.top = pt.y;
1723 pMsgView->SendMessage(EM_POSFROMCHAR, (WPARAM)&pt, pEnLink->chrg.cpMax);
1724 rc.right = pt.x;
1725 rc.bottom = pt.y + 12;
1726 if ((prevRect.left != rc.left) || (prevRect.top != rc.top))
1728 m_tooltips.DelTool(pMsgView, 1);
1729 m_tooltips.AddTool(pMsgView, url, &rc, 1);
1730 prevRect = rc;
1735 else if(pEnLink->msg == WM_LBUTTONUP)
1737 int pos = 0;
1738 if (LookLikeGitHash(url, pos))
1740 bool found = false;
1741 for (int i = 0; i < m_LogList.m_arShownList.GetCount(); ++i)
1743 GitRev *rev = (GitRev *)m_LogList.m_arShownList.SafeGetAt(i);
1744 if (!rev) continue;
1745 if (rev->m_CommitHash.ToString().Left(url.GetLength()) == url)
1747 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1748 if (pos)
1750 int index = m_LogList.GetNextSelectedItem(pos);
1751 if (index >= 0)
1752 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
1754 m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1755 m_LogList.EnsureVisible(i, FALSE);
1756 m_LogList.SetSelectionMark(i);
1757 found = true;
1758 PostMessage(WM_TGIT_REFRESH_SELECTION, 0, 0);
1759 break;
1763 if (!found)
1764 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_LOG_JUMPNOTFOUND, IDS_APPNAME, 1, IDI_INFORMATION, IDS_OKBUTTON, 0, 0, _T("NoJumpNotFoundWarning"), IDS_MSGBOX_DONOTSHOWAGAIN);
1768 *pResult = 0;
1771 void CLogDlg::OnBnClickedStatbutton()
1773 if (this->IsThreadRunning())
1774 return;
1775 if (m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC)
1776 return; // nothing or just the working copy changes are shown, so no statistics.
1777 // the statistics dialog expects the log entries to be sorted by date
1778 SortByColumn(3, false);
1780 CStatGraphDlg dlg;
1781 m_LogList.RecalculateShownList(&dlg.m_ShowList);
1783 dlg.m_path = m_orgPath;
1784 dlg.DoModal();
1785 // restore the previous sorting
1786 SortByColumn(m_nSortColumn, m_bAscending);
1787 OnTimer(LOGFILTER_TIMER);
1790 void CLogDlg::MoveToSameTop(CWnd *pWndRef, CWnd *pWndTarget)
1792 CRect rcWndPicAuthor, rcWndMsgView;
1793 pWndRef->GetWindowRect(rcWndMsgView);
1794 ScreenToClient(rcWndMsgView);
1795 pWndTarget->GetWindowRect(rcWndPicAuthor);
1796 ScreenToClient(rcWndPicAuthor);
1797 int diff = rcWndMsgView.top - rcWndPicAuthor.top;
1798 rcWndPicAuthor.top += diff;
1799 rcWndPicAuthor.bottom += diff;
1800 pWndTarget->MoveWindow(rcWndPicAuthor);
1803 void CLogDlg::DoSizeV1(int delta)
1806 RemoveAnchor(IDC_LOGLIST);
1807 RemoveAnchor(IDC_SPLITTERTOP);
1808 RemoveAnchor(IDC_MSGVIEW);
1809 RemoveAnchor(IDC_PIC_AUTHOR);
1810 RemoveAnchor(IDC_SPLITTERBOTTOM);
1811 RemoveAnchor(IDC_LOGMSG);
1812 CSplitterControl::ChangeHeight(&m_LogList, delta, CW_TOPALIGN);
1813 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), -delta, CW_BOTTOMALIGN);
1814 MoveToSameTop(GetDlgItem(IDC_MSGVIEW), GetDlgItem(IDC_PIC_AUTHOR));
1815 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1816 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1817 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1818 AddAnchor(IDC_PIC_AUTHOR, TOP_RIGHT);
1819 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1820 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1821 ArrangeLayout();
1822 AdjustMinSize();
1823 SetSplitterRange();
1824 m_LogList.Invalidate();
1825 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1826 m_gravatar.Invalidate();
1830 void CLogDlg::DoSizeV2(int delta)
1833 RemoveAnchor(IDC_LOGLIST);
1834 RemoveAnchor(IDC_SPLITTERTOP);
1835 RemoveAnchor(IDC_MSGVIEW);
1836 RemoveAnchor(IDC_PIC_AUTHOR);
1837 RemoveAnchor(IDC_SPLITTERBOTTOM);
1838 RemoveAnchor(IDC_LOGMSG);
1839 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), delta, CW_TOPALIGN);
1840 CSplitterControl::ChangeHeight(&m_ChangedFileListCtrl, -delta, CW_BOTTOMALIGN);
1841 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1842 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1843 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1844 AddAnchor(IDC_PIC_AUTHOR, TOP_RIGHT);
1845 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1846 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1847 ArrangeLayout();
1848 AdjustMinSize();
1849 SetSplitterRange();
1850 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1851 m_ChangedFileListCtrl.Invalidate();
1852 m_gravatar.Invalidate();
1856 void CLogDlg::AdjustMinSize()
1858 // adjust the minimum size of the dialog to prevent the resizing from
1859 // moving the list control too far down.
1860 CRect rcChgListView;
1861 m_ChangedFileListCtrl.GetClientRect(rcChgListView);
1862 CRect rcLogList;
1863 m_LogList.GetClientRect(rcLogList);
1865 SetMinTrackSize(CSize(m_DlgOrigRect.Width(),
1866 m_DlgOrigRect.Height()-m_ChgOrigRect.Height()-m_LogListOrigRect.Height()-m_MsgViewOrigRect.Height()
1867 +rcChgListView.Height()+rcLogList.Height()+60));
1870 LRESULT CLogDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1872 switch (message) {
1873 case WM_NOTIFY:
1874 if (wParam == IDC_SPLITTERTOP)
1876 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1877 DoSizeV1(pHdr->delta);
1879 else if (wParam == IDC_SPLITTERBOTTOM)
1881 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1882 DoSizeV2(pHdr->delta);
1884 break;
1887 return CResizableDialog::DefWindowProc(message, wParam, lParam);
1890 void CLogDlg::SetSplitterRange()
1892 if ((m_LogList)&&(m_ChangedFileListCtrl))
1894 CRect rcTop;
1895 m_LogList.GetWindowRect(rcTop);
1896 ScreenToClient(rcTop);
1897 CRect rcMiddle;
1898 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(rcMiddle);
1899 ScreenToClient(rcMiddle);
1900 m_wndSplitter1.SetRange(rcTop.top+30, rcMiddle.bottom-20);
1901 CRect rcBottom;
1902 m_ChangedFileListCtrl.GetWindowRect(rcBottom);
1903 ScreenToClient(rcBottom);
1904 m_wndSplitter2.SetRange(rcMiddle.top+30, rcBottom.bottom-20);
1908 void CLogDlg::OnEnscrollMsgview()
1910 m_tooltips.DelTool(GetDlgItem(IDC_MSGVIEW), 1);
1913 LRESULT CLogDlg::OnClickedInfoIcon(WPARAM wParam, LPARAM lParam)
1915 if ((HWND)wParam == m_cFileFilter.GetSafeHwnd())
1916 return 0;
1918 // FIXME: x64 version would get this function called with unexpected parameters.
1919 if (!lParam)
1920 return 0;
1922 RECT * rect = (LPRECT)lParam;
1923 CPoint point;
1924 CString temp;
1925 point = CPoint(rect->left, rect->bottom);
1926 #define LOGMENUFLAGS(x) (MF_STRING | MF_ENABLED | ((m_LogList.m_SelectedFilters & x) ? MF_CHECKED : MF_UNCHECKED))
1927 CMenu popup;
1928 if (popup.CreatePopupMenu())
1930 temp.LoadString(IDS_LOG_FILTER_SUBJECT);
1931 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_SUBJECT), LOGFILTER_SUBJECT, temp);
1933 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
1934 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_MESSAGES), LOGFILTER_MESSAGES, temp);
1936 temp.LoadString(IDS_LOG_FILTER_PATHS);
1937 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_PATHS), LOGFILTER_PATHS, temp);
1939 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
1940 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_AUTHORS), LOGFILTER_AUTHORS, temp);
1942 temp.LoadString(IDS_LOG_FILTER_EMAILS);
1943 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_EMAILS), LOGFILTER_EMAILS, temp);
1945 temp.LoadString(IDS_LOG_FILTER_REVS);
1946 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REVS), LOGFILTER_REVS, temp);
1948 temp.LoadString(IDS_LOG_FILTER_REFNAME);
1949 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REFNAME), LOGFILTER_REFNAME, temp);
1951 if (m_LogList.m_bShowBugtraqColumn == TRUE) {
1952 temp.LoadString(IDS_LOG_FILTER_BUGIDS);
1953 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_BUGID), LOGFILTER_BUGID, temp);
1956 popup.AppendMenu(MF_SEPARATOR, NULL);
1958 temp.LoadString(IDS_LOG_FILTER_TOGGLE);
1959 popup.AppendMenu(MF_STRING | MF_ENABLED, LOGFILTER_TOGGLE, temp);
1961 temp.LoadString(IDS_ALL);
1962 popup.AppendMenu(MF_STRING | MF_ENABLED, LOGFILTER_ALL, temp);
1964 popup.AppendMenu(MF_SEPARATOR, NULL);
1966 temp.LoadString(IDS_LOG_FILTER_REGEX);
1967 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterWithRegex ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_REGEX, temp);
1969 temp.LoadString(IDS_LOG_FILTER_CASESENSITIVE);
1970 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterCaseSensitively ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_CASE, temp);
1972 m_tooltips.Pop();
1973 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1974 if (selection != 0)
1977 if (selection == LOGFILTER_REGEX)
1979 m_bFilterWithRegex = !m_bFilterWithRegex;
1980 CRegDWORD b(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE);
1981 b = m_bFilterWithRegex;
1982 m_LogList.m_bFilterWithRegex = m_bFilterWithRegex;
1983 SetFilterCueText();
1984 CheckRegexpTooltip();
1986 else if (selection == LOGFILTER_CASE)
1988 m_bFilterCaseSensitively = !m_bFilterCaseSensitively;
1989 CRegDWORD b(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE);
1990 b = m_bFilterCaseSensitively;
1991 m_LogList.m_bFilterCaseSensitively = m_bFilterCaseSensitively;
1993 else if (selection == LOGFILTER_TOGGLE)
1995 m_LogList.m_SelectedFilters = (~m_LogList.m_SelectedFilters) & LOGFILTER_ALL;
1996 SetFilterCueText();
1998 else if (selection == LOGFILTER_ALL)
2000 m_LogList.m_SelectedFilters = selection;
2001 SetFilterCueText();
2003 else
2005 m_LogList.m_SelectedFilters ^= selection;
2006 SetFilterCueText();
2008 CRegDWORD(_T("Software\\TortoiseGit\\SelectedLogFilters")) = m_LogList.m_SelectedFilters;
2009 // Reload only if a search text is entered
2010 if (m_LogList.HasFilterText())
2011 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2014 return 0L;
2017 LRESULT CLogDlg::OnClickedCancelFilter(WPARAM wParam, LPARAM /*lParam*/)
2019 if ((HWND)wParam == m_cFileFilter.GetSafeHwnd())
2021 KillTimer(FILEFILTER_TIMER);
2023 FillLogMessageCtrl();
2024 return 0L;
2027 KillTimer(LOGFILTER_TIMER);
2029 m_LogList.m_sFilterText.Empty();
2030 UpdateData(FALSE);
2031 theApp.DoWaitCursor(1);
2032 CStoreSelection storeselection(this);
2033 FillLogMessageCtrl(false);
2035 m_LogList.RemoveFilter();
2037 Refresh();
2039 CTime begin,end;
2040 m_LogList.GetTimeRange(begin,end);
2041 m_DateFrom.SetTime(&begin);
2042 m_DateTo.SetTime(&end);
2044 theApp.DoWaitCursor(-1);
2045 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2046 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2047 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2048 UpdateLogInfoLabel();
2050 return 0L;
2054 void CLogDlg::SetFilterCueText()
2056 CString temp(MAKEINTRESOURCE(IDS_LOG_FILTER_BY));
2057 temp += _T(" ");
2059 if (m_LogList.m_SelectedFilters & LOGFILTER_SUBJECT)
2061 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_SUBJECT));
2064 if (m_LogList.m_SelectedFilters & LOGFILTER_MESSAGES)
2066 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2067 temp += _T(", ");
2068 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_MESSAGES));
2071 if (m_LogList.m_SelectedFilters & LOGFILTER_PATHS)
2073 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2074 temp += _T(", ");
2075 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_PATHS));
2078 if (m_LogList.m_SelectedFilters & LOGFILTER_AUTHORS)
2080 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2081 temp += _T(", ");
2082 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_AUTHORS));
2085 if (m_LogList.m_SelectedFilters & LOGFILTER_EMAILS)
2087 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2088 temp += _T(", ");
2089 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_EMAILS));
2092 if (m_LogList.m_SelectedFilters & LOGFILTER_REVS)
2094 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2095 temp += _T(", ");
2096 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_REVS));
2099 if (m_LogList.m_SelectedFilters & LOGFILTER_REFNAME)
2101 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2102 temp += _T(", ");
2103 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_REFNAME));
2106 if (m_LogList.m_bShowBugtraqColumn && m_LogList.m_SelectedFilters & LOGFILTER_BUGID)
2108 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2109 temp += _T(", ");
2110 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_BUGIDS));
2113 // to make the cue banner text appear more to the right of the edit control
2114 temp = _T(" ")+temp;
2115 m_cFilter.SetCueBanner(temp.TrimRight());
2118 bool CLogDlg::Validate(LPCTSTR string)
2120 if (!m_bFilterWithRegex)
2121 return true;
2122 std::tr1::wregex pat;
2123 return m_LogList.ValidateRegexp(string, pat, false);
2126 void CLogDlg::OnEnChangeFileFilter()
2128 SetTimer(FILEFILTER_TIMER, 1000, NULL);
2131 void CLogDlg::OnTimer(UINT_PTR nIDEvent)
2133 if (nIDEvent == LOGFTIME_TIMER)
2135 KillTimer(LOGFTIME_TIMER);
2136 m_limit = 0;
2137 m_LogList.Refresh(FALSE);
2138 FillLogMessageCtrl(false);
2140 else if (nIDEvent == LOG_FILLPATCHVTIMER)
2142 FillPatchView();
2144 else if (nIDEvent == LOGFILTER_TIMER)
2146 KillTimer(LOGFILTER_TIMER);
2147 m_limit = 0;
2148 m_LogList.Refresh(FALSE);
2149 FillLogMessageCtrl(false);
2151 #if 0
2152 /* we will use git built-in grep to filter log */
2153 if (this->IsThreadRunning())
2155 // thread still running! So just restart the timer.
2156 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2157 return;
2159 CWnd * focusWnd = GetFocus();
2160 bool bSetFocusToFilterControl = ((focusWnd != GetDlgItem(IDC_DATEFROM))&&(focusWnd != GetDlgItem(IDC_DATETO))
2161 && (focusWnd != GetDlgItem(IDC_LOGLIST)));
2162 if (m_LogList.m_sFilterText.IsEmpty())
2164 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2165 // do not return here!
2166 // we also need to run the filter if the filter text is empty:
2167 // 1. to clear an existing filter
2168 // 2. to rebuild the m_arShownList after sorting
2170 theApp.DoWaitCursor(1);
2171 CStoreSelection storeselection(this);
2172 KillTimer(LOGFILTER_TIMER);
2173 FillLogMessageCtrl(false);
2175 // now start filter the log list
2176 m_LogList.StartFilter();
2178 if ( m_LogList.GetItemCount()==1 )
2180 m_LogList.SetSelectionMark(0);
2181 m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
2183 theApp.DoWaitCursor(-1);
2184 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2185 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2186 if (bSetFocusToFilterControl)
2187 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2188 UpdateLogInfoLabel();
2189 #endif
2190 } // if (nIDEvent == LOGFILTER_TIMER)
2191 else if (nIDEvent == LOG_HEADER_ORDER_TIMER)
2193 KillTimer(LOG_HEADER_ORDER_TIMER);
2194 CLogOrdering orderDlg;
2195 if (orderDlg.DoModal() == IDOK)
2196 Refresh();
2198 else if (nIDEvent == FILEFILTER_TIMER)
2200 KillTimer(FILEFILTER_TIMER);
2201 FillLogMessageCtrl();
2203 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC))));
2204 __super::OnTimer(nIDEvent);
2207 void CLogDlg::OnDtnDatetimechangeDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2211 CTime _time;
2212 m_DateTo.GetTime(_time);
2214 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 23, 59, 59);
2215 if (time.GetTime() != m_LogList.m_To)
2217 m_LogList.m_To = (DWORD)time.GetTime();
2218 SetTimer(LOGFTIME_TIMER, 10, NULL);
2221 catch (...)
2223 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2226 *pResult = 0;
2229 void CLogDlg::OnDtnDatetimechangeDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2234 CTime _time;
2235 m_DateFrom.GetTime(_time);
2237 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 0, 0, 0);
2238 if (time.GetTime() != m_LogList.m_From)
2240 m_LogList.m_From = (DWORD)time.GetTime();
2241 SetTimer(LOGFTIME_TIMER, 10, NULL);
2244 catch (...)
2246 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2249 *pResult = 0;
2252 void CLogDlg::OnCbnSelchangeJumpType()
2254 // reserved for future use
2257 void CLogDlg::OnBnClickedJumpUp()
2259 int sel = m_JumpType.GetCurSel();
2260 if (sel < 0) return;
2261 JumpType jumpType = (JumpType)sel;
2263 if (jumpType == JumpType_History)
2265 GoBack();
2266 return;
2269 CString strValue;
2270 CGitHash hashValue;
2271 int index = -1;
2272 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2273 if (pos)
2275 index = m_LogList.GetNextSelectedItem(pos);
2276 if (index == 0) return;
2278 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(index);
2279 if (jumpType == JumpType_AuthorEmail)
2280 strValue = data->GetAuthorEmail();
2281 else if (jumpType == JumpType_CommitterEmail)
2282 strValue = data->GetCommitterEmail();
2283 else if (jumpType == JumpType_Parent1)
2284 hashValue = data->m_CommitHash;
2285 else if (jumpType == JumpType_Parent2)
2286 hashValue = data->m_CommitHash;
2287 else if (jumpType == JumpType_TagFF)
2288 hashValue = data->m_CommitHash;
2289 else if (jumpType == JumpType_BranchFF)
2290 hashValue = data->m_CommitHash;
2292 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2294 else
2295 return;
2297 while (pos)
2299 index = m_LogList.GetNextSelectedItem(pos);
2300 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2302 m_LogList.SetSelectionMark(-1);
2304 for (int i = index - 1; i >= 0; i--)
2306 bool found = false;
2307 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(i);
2308 if (jumpType == JumpType_AuthorEmail)
2309 found = strValue == data->GetAuthorEmail();
2310 else if (jumpType == JumpType_CommitterEmail)
2311 found = strValue == data->GetCommitterEmail();
2312 else if (jumpType == JumpType_MergePoint)
2313 found = data->ParentsCount() > 1;
2314 else if (jumpType == JumpType_Parent1)
2316 if (data->m_ParentHash.size() > 0)
2317 found = data->m_ParentHash[0] == hashValue;
2319 else if (jumpType == JumpType_Parent2)
2321 if (data->m_ParentHash.size() > 1)
2322 found = data->m_ParentHash[1] == hashValue;
2324 else if (jumpType == JumpType_Tag || jumpType == JumpType_TagFF)
2326 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2327 for (size_t j = 0; j < refList.size(); ++j)
2329 if (refList[j].Left(10) == _T("refs/tags/"))
2331 found = true;
2332 break;
2336 if (found && jumpType == JumpType_TagFF)
2337 found = g_Git.IsFastForward(hashValue, data->m_CommitHash);
2339 else if (jumpType == JumpType_Branch || jumpType == JumpType_BranchFF)
2341 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2342 for (size_t j = 0; j < refList.size(); ++j)
2344 if (refList[j].Left(11) == _T("refs/heads/") || refList[j].Left(13) == _T("refs/remotes/"))
2346 found = true;
2347 break;
2351 if (found && jumpType == JumpType_BranchFF)
2352 found = g_Git.IsFastForward(hashValue, data->m_CommitHash);
2355 if (found)
2357 m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2358 m_LogList.EnsureVisible(i, FALSE);
2359 m_LogList.SetSelectionMark(i);
2360 return;
2364 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_LOG_JUMPNOTFOUND, IDS_APPNAME, 1, IDI_INFORMATION, IDS_OKBUTTON, 0, 0, _T("NoJumpNotFoundWarning"), IDS_MSGBOX_DONOTSHOWAGAIN);
2367 void CLogDlg::OnBnClickedJumpDown()
2369 int jumpType = m_JumpType.GetCurSel();
2370 if (jumpType < 0) return;
2372 if (jumpType == JumpType_History)
2374 GoForward();
2375 return;
2378 CString strValue;
2379 CGitHash hashValue;
2380 int index = -1;
2381 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2382 if (pos)
2384 index = m_LogList.GetNextSelectedItem(pos);
2385 if (index == 0) return;
2387 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(index);
2388 if (jumpType == JumpType_AuthorEmail)
2389 strValue = data->GetAuthorEmail();
2390 else if (jumpType == JumpType_CommitterEmail)
2391 strValue = data->GetCommitterEmail();
2392 else if (jumpType == JumpType_Parent1)
2394 if (data->m_ParentHash.size() > 0)
2395 hashValue = data->m_ParentHash.at(0);
2396 else
2397 return;
2399 else if (jumpType == JumpType_Parent2)
2401 if (data->m_ParentHash.size() > 1)
2402 hashValue = data->m_ParentHash.at(1);
2403 else
2404 return;
2406 else if (jumpType == JumpType_TagFF)
2407 hashValue = data->m_CommitHash;
2408 else if (jumpType == JumpType_BranchFF)
2409 hashValue = data->m_CommitHash;
2411 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2413 else
2414 return;
2416 while (pos)
2418 index = m_LogList.GetNextSelectedItem(pos);
2419 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2421 m_LogList.SetSelectionMark(-1);
2423 for (int i = index + 1; i < m_LogList.GetItemCount(); ++i)
2425 bool found = false;
2426 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(i);
2427 if (jumpType == JumpType_AuthorEmail)
2428 found = strValue == data->GetAuthorEmail();
2429 else if (jumpType == JumpType_CommitterEmail)
2430 found = strValue == data->GetCommitterEmail();
2431 else if (jumpType == JumpType_MergePoint)
2432 found = data->ParentsCount() > 1;
2433 else if (jumpType == JumpType_Parent1)
2434 found = data->m_CommitHash == hashValue;
2435 else if (jumpType == JumpType_Parent2)
2436 found = data->m_CommitHash == hashValue;
2437 else if (jumpType == JumpType_Tag || jumpType == JumpType_TagFF)
2439 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2440 for (size_t j = 0; j < refList.size(); ++j)
2442 if (refList[j].Left(10) == _T("refs/tags/"))
2444 found = true;
2445 break;
2449 if (found && jumpType == JumpType_TagFF)
2450 found = g_Git.IsFastForward(data->m_CommitHash, hashValue);
2452 else if (jumpType == JumpType_Branch || jumpType == JumpType_BranchFF)
2454 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2455 for (size_t j = 0; j < refList.size(); ++j)
2457 if (refList[j].Left(11) == _T("refs/heads/") || refList[j].Left(13) == _T("refs/remotes/"))
2459 found = true;
2460 break;
2464 if (found && jumpType == JumpType_BranchFF)
2465 found = g_Git.IsFastForward(data->m_CommitHash, hashValue);
2468 if (found)
2470 m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2471 m_LogList.EnsureVisible(i, FALSE);
2472 m_LogList.SetSelectionMark(i);
2473 return;
2477 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_LOG_JUMPNOTFOUND, IDS_APPNAME, 1, IDI_INFORMATION, IDS_OKBUTTON, 0, 0, _T("NoJumpNotFoundWarning"), IDS_MSGBOX_DONOTSHOWAGAIN);
2480 CTGitPathList CLogDlg::GetChangedPathsFromSelectedRevisions(bool /*bRelativePaths*/ /* = false */, bool /*bUseFilter*/ /* = true */)
2482 CTGitPathList pathList;
2483 #if 0
2485 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2487 m_sRepositoryRoot = GetRepositoryRoot(m_path);
2489 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2490 return pathList;
2492 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2493 if (pos != NULL)
2495 while (pos)
2497 int nextpos = m_LogList.GetNextSelectedItem(pos);
2498 if (nextpos >= m_arShownList.GetCount())
2499 continue;
2500 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(nextpos));
2501 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2502 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
2504 LogChangedPath * cpath = cpatharray->SafeGetAt(cpPathIndex);
2505 if (cpath == NULL)
2506 continue;
2507 CTGitPath path;
2508 if (!bRelativePaths)
2509 path.SetFromGit(m_sRepositoryRoot);
2510 path.AppendPathString(cpath->sPath);
2511 if ((!bUseFilter)||
2512 ((m_cHidePaths.GetState() & 0x0003)!=BST_CHECKED)||
2513 (cpath->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0))
2514 pathList.AddPath(path);
2519 pathList.RemoveDuplicates();
2520 #endif
2521 return pathList;
2524 void CLogDlg::SortByColumn(int /*nSortColumn*/, bool /*bAscending*/)
2526 #if 0
2527 switch(nSortColumn)
2529 case 0: // Revision
2531 if(bAscending)
2532 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscRevSort());
2533 else
2534 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescRevSort());
2536 break;
2537 case 1: // action
2539 if(bAscending)
2540 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscActionSort());
2541 else
2542 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescActionSort());
2544 break;
2545 case 2: // Author
2547 if(bAscending)
2548 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscAuthorSort());
2549 else
2550 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescAuthorSort());
2552 break;
2553 case 3: // Date
2555 if(bAscending)
2556 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscDateSort());
2557 else
2558 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescDateSort());
2560 break;
2561 case 4: // Message or bug id
2562 if (m_bShowBugtraqColumn)
2564 if(bAscending)
2565 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscBugIDSort());
2566 else
2567 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescBugIDSort());
2568 break;
2570 // fall through here
2571 case 5: // Message
2573 if(bAscending)
2574 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscMessageSort());
2575 else
2576 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescMessageSort());
2578 break;
2579 default:
2580 ATLASSERT(0);
2581 break;
2583 #endif
2586 void CLogDlg::OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult)
2588 if (this->IsThreadRunning())
2589 return; //no sorting while the arrays are filled
2590 #if 0
2591 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2592 const int nColumn = pNMLV->iSubItem;
2593 m_bAscending = nColumn == m_nSortColumn ? !m_bAscending : TRUE;
2594 m_nSortColumn = nColumn;
2595 SortByColumn(m_nSortColumn, m_bAscending);
2596 SetSortArrow(&m_LogList, m_nSortColumn, !!m_bAscending);
2597 SortShownListArray();
2598 m_LogList.Invalidate();
2599 UpdateLogInfoLabel();
2600 #else
2601 UNREFERENCED_PARAMETER(pNMHDR);
2602 #endif
2603 *pResult = 0;
2605 SetTimer(LOG_HEADER_ORDER_TIMER, 10, nullptr);
2608 void CLogDlg::SortShownListArray()
2610 // make sure the shown list still matches the filter after sorting.
2611 OnTimer(LOGFILTER_TIMER);
2612 // clear the selection states
2613 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2614 while (pos)
2616 m_LogList.SetItemState(m_LogList.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
2618 m_LogList.SetSelectionMark(-1);
2621 void CLogDlg::SetSortArrow(CListCtrl * control, int nColumn, bool bAscending)
2623 if (control == NULL)
2624 return;
2625 // set the sort arrow
2626 CHeaderCtrl * pHeader = control->GetHeaderCtrl();
2627 HDITEM HeaderItem = {0};
2628 HeaderItem.mask = HDI_FORMAT;
2629 for (int i=0; i<pHeader->GetItemCount(); ++i)
2631 pHeader->GetItem(i, &HeaderItem);
2632 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
2633 pHeader->SetItem(i, &HeaderItem);
2635 if (nColumn >= 0)
2637 pHeader->GetItem(nColumn, &HeaderItem);
2638 HeaderItem.fmt |= (bAscending ? HDF_SORTUP : HDF_SORTDOWN);
2639 pHeader->SetItem(nColumn, &HeaderItem);
2643 int CLogDlg::m_nSortColumnPathList = 0;
2644 bool CLogDlg::m_bAscendingPathList = false;
2646 void CLogDlg::OnBnClickedHidepaths()
2648 FillLogMessageCtrl();
2649 m_ChangedFileListCtrl.Invalidate();
2652 void CLogDlg::UpdateLogInfoLabel()
2655 CGitHash rev1 ;
2656 CGitHash rev2 ;
2657 long selectedrevs = 0;
2658 long selectedfiles = 0;
2659 int count = (int)m_LogList.m_arShownList.GetCount();
2660 int start = 0;
2661 if (count)
2663 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(0)))->m_CommitHash;
2664 if(this->m_LogList.m_bShowWC && rev1.IsEmpty()&&(count>1))
2665 start = 1;
2666 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(start)))->m_CommitHash;
2667 //pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_arShownList.GetCount()-1));
2668 rev2 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(count-1)))->m_CommitHash;
2669 selectedrevs = m_LogList.GetSelectedCount();
2670 if (selectedrevs)
2671 selectedfiles = m_ChangedFileListCtrl.GetSelectedCount();
2673 CString sTemp;
2674 sTemp.Format(IDS_PROC_LOG_STATS,
2675 count - start,
2676 rev2.ToString().Left(g_Git.GetShortHASHLength()), rev1.ToString().Left(g_Git.GetShortHASHLength()), selectedrevs, selectedfiles);
2678 if(selectedrevs == 1)
2680 CString str=m_ChangedFileListCtrl.GetStatisticsString(true);
2681 str.Replace(_T('\n'), _T(' '));
2682 sTemp += _T("\r\n") + str;
2684 m_sLogInfo = sTemp;
2686 UpdateData(FALSE);
2689 void CLogDlg::OnDtnDropdownDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2691 // the date control should not show the "today" button
2692 CMonthCalCtrl * pCtrl = m_DateFrom.GetMonthCalCtrl();
2693 if (pCtrl)
2694 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
2695 *pResult = 0;
2698 void CLogDlg::OnDtnDropdownDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2700 // the date control should not show the "today" button
2701 CMonthCalCtrl * pCtrl = m_DateTo.GetMonthCalCtrl();
2702 if (pCtrl)
2703 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
2704 *pResult = 0;
2707 void CLogDlg::OnSize(UINT nType, int cx, int cy)
2709 __super::OnSize(nType, cx, cy);
2710 //set range
2711 SetSplitterRange();
2714 void CLogDlg::OnRefresh()
2717 m_limit = 0;
2718 this->m_LogProgress.SetPos(0);
2720 Refresh (false);
2724 void CLogDlg::OnFocusFilter()
2726 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2729 void CLogDlg::OnEditCopy()
2731 if (GetFocus() == &m_ChangedFileListCtrl)
2732 CopyChangedSelectionToClipBoard();
2733 else
2734 m_LogList.CopySelectionToClipBoard();
2737 CString CLogDlg::GetAbsoluteUrlFromRelativeUrl(const CString& url)
2739 // is the URL a relative one?
2740 if (url.Left(2).Compare(_T("^/")) == 0)
2742 // URL is relative to the repository root
2743 CString url1 = m_sRepositoryRoot + url.Mid(1);
2744 TCHAR buf[INTERNET_MAX_URL_LENGTH] = { 0 };
2745 DWORD len = url.GetLength();
2746 if (UrlCanonicalize((LPCTSTR)url1, buf, &len, 0) == S_OK)
2747 return CString(buf, len);
2748 return url1;
2750 else if (url[0] == '/')
2752 // URL is relative to the server's hostname
2753 CString sHost;
2754 // find the server's hostname
2755 int schemepos = m_sRepositoryRoot.Find(_T("//"));
2756 if (schemepos >= 0)
2758 sHost = m_sRepositoryRoot.Left(m_sRepositoryRoot.Find('/', schemepos+3));
2759 CString url1 = sHost + url;
2760 TCHAR buf[INTERNET_MAX_URL_LENGTH] = { 0 };
2761 DWORD len = url.GetLength();
2762 if (UrlCanonicalize((LPCTSTR)url, buf, &len, 0) == S_OK)
2763 return CString(buf, len);
2764 return url1;
2767 return url;
2770 void CLogDlg::ShowGravatar()
2772 m_gravatar.EnableGravatar(m_bShowGravatar);
2773 RemoveAnchor(IDC_MSGVIEW);
2774 if (m_gravatar.IsGravatarEnabled())
2776 RECT rect, rect2;
2777 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(&rect);
2778 ScreenToClient(&rect);
2779 m_gravatar.GetWindowRect(&rect2);
2780 ScreenToClient(&rect2);
2781 rect.right = rect2.left;
2782 GetDlgItem(IDC_MSGVIEW)->MoveWindow(&rect);
2783 m_gravatar.ShowWindow(SW_SHOW);
2785 else
2787 RECT rect, rect2;
2788 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(&rect);
2789 ScreenToClient(&rect);
2790 m_gravatar.GetWindowRect(&rect2);
2791 ScreenToClient(&rect2);
2792 rect.right = rect2.right;
2793 GetDlgItem(IDC_MSGVIEW)->MoveWindow(&rect);
2794 m_gravatar.ShowWindow(SW_HIDE);
2796 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
2800 void CLogDlg::OnEnChangeSearchedit()
2802 UpdateData();
2803 if (!m_LogList.HasFilterText())
2805 CStoreSelection storeselection(this);
2806 // clear the filter, i.e. make all entries appear
2807 theApp.DoWaitCursor(1);
2808 KillTimer(LOGFILTER_TIMER);
2809 FillLogMessageCtrl(false);
2811 Refresh();
2812 //m_LogList.StartFilter();
2813 #if 0
2814 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2815 m_arShownList.RemoveAll();
2816 for (DWORD i=0; i<m_logEntries.size(); ++i)
2818 if (IsEntryInDateRange(i))
2819 m_arShownList.Add(m_logEntries[i]);
2821 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2822 m_LogList.DeleteAllItems();
2823 m_LogList.SetItemCountEx(ShownCountWithStopped());
2824 m_LogList.RedrawItems(0, ShownCountWithStopped());
2825 m_LogList.SetRedraw(false);
2826 ResizeAllListCtrlCols();
2827 m_LogList.SetRedraw(true);
2828 #endif
2829 theApp.DoWaitCursor(-1);
2830 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2831 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2832 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2833 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2834 return;
2836 if (Validate(m_LogList.m_sFilterText))
2837 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2838 else
2839 KillTimer(LOGFILTER_TIMER);
2843 void CLogDlg::OnBnClickedAllBranch()
2845 // m_bAllBranch is not auto-toggled by MFC, we have to handle it manually (in order to prevent the indeterminate state)
2847 m_LogList.m_ShowMask &=~ (CGit::LOG_INFO_LOCAL_BRANCHES | CGit::LOG_INFO_ALL_BRANCH);
2849 if (m_bAllBranch)
2851 m_bAllBranch = BST_UNCHECKED;
2852 m_ChangedFileListCtrl.m_sDisplayedBranch = m_LogList.GetRange();
2854 else
2856 m_bAllBranch = BST_CHECKED;
2857 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
2858 m_ChangedFileListCtrl.m_sDisplayedBranch.Empty();
2861 // need to save value here, so that log dialogs started from now on also have AllBranch activated
2862 m_regbAllBranch = m_bAllBranch;
2864 UpdateData(FALSE);
2866 OnRefresh();
2868 FillLogMessageCtrl(false);
2871 void CLogDlg::OnBnClickedFollowRenames()
2873 if(m_bFollowRenames)
2875 m_LogList.m_ShowMask |= CGit::LOG_INFO_FOLLOW;
2876 m_LogList.m_ShowMask &=~ CGit::LOG_INFO_LOCAL_BRANCHES;
2877 if (m_bAllBranch)
2880 m_bAllBranch = FALSE;
2881 m_LogList.m_ShowMask &=~ CGit::LOG_INFO_ALL_BRANCH;
2885 else
2886 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_FOLLOW;
2888 DialogEnableWindow(IDC_LOG_ALLBRANCH, !m_bFollowRenames);
2889 DialogEnableWindow(IDC_SHOWWHOLEPROJECT, !m_bFollowRenames && !m_path.IsEmpty());
2891 OnRefresh();
2893 FillLogMessageCtrl(false);
2896 void CLogDlg::HandleShowLabels(bool var, int flag)
2898 if (var)
2899 m_LogList.m_ShowRefMask |= flag;
2900 else
2901 m_LogList.m_ShowRefMask &= ~flag;
2903 if ((m_LogList.m_ShowFilter & CGitLogListBase::FILTERSHOW_REFS) && !(m_LogList.m_ShowFilter & CGitLogListBase::FILTERSHOW_ANYCOMMIT))
2905 // Remove commits where labels are not shown.
2906 OnRefresh();
2907 FillLogMessageCtrl(false);
2909 else
2911 // Just redraw
2912 m_LogList.Invalidate();
2916 void CLogDlg::OnBnClickedCompressedGraph()
2918 UpdateData();
2920 if (m_iCompressedGraph == 2)
2921 m_LogList.m_ShowFilter = CGitLogListBase::FILTERSHOW_REFS;
2922 else if (m_iCompressedGraph == 1)
2923 m_LogList.m_ShowFilter = static_cast<CGitLogListBase::FilterShow>(CGitLogListBase::FILTERSHOW_REFS | CGitLogListBase::FILTERSHOW_MERGEPOINTS);
2924 else
2925 m_LogList.m_ShowFilter = CGitLogListBase::FILTERSHOW_ALL;
2927 OnRefresh();
2928 FillLogMessageCtrl(false);
2931 void CLogDlg::OnBnClickedBrowseRef()
2933 CString newRef = CBrowseRefsDlg::PickRef(false, m_LogList.GetRange(), gPickRef_All, true);
2934 if(newRef.IsEmpty())
2935 return;
2937 m_History.AddEntry(newRef);
2938 m_History.Save();
2940 SetRange(newRef);
2942 m_LogList.m_ShowMask &= ~(CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES);
2943 m_bAllBranch = BST_UNCHECKED;
2944 UpdateData(FALSE);
2946 OnRefresh();
2947 FillLogMessageCtrl(false);
2950 void CLogDlg::ShowStartRef()
2952 //Show ref name on top
2953 if(!::IsWindow(m_hWnd))
2954 return;
2955 if (m_LogList.m_ShowMask & (CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES))
2957 switch (m_LogList.m_ShowMask & (CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES))
2959 case CGit::LOG_INFO_ALL_BRANCH:
2960 m_staticRef.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_LOG_ALLBRANCHES)));
2961 break;
2963 case CGit::LOG_INFO_LOCAL_BRANCHES:
2964 m_staticRef.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_LOG_LOCAL_BRANCHES)));
2965 break;
2968 m_staticRef.Invalidate(TRUE);
2969 m_tooltips.DelTool(GetDlgItem(IDC_STATIC_REF));
2970 return;
2973 CString showStartRef = m_LogList.GetRange();
2974 if (showStartRef.IsEmpty() || showStartRef == _T("HEAD"))
2976 showStartRef.Empty();
2977 //Ref name is HEAD
2978 if (g_Git.Run(L"git.exe symbolic-ref HEAD", &showStartRef, NULL, CP_UTF8))
2979 showStartRef = CString(MAKEINTRESOURCE(IDS_PROC_LOG_NOBRANCH));
2980 showStartRef.Trim(L"\r\n\t ");
2984 showStartRef = g_Git.StripRefName(showStartRef);
2986 m_staticRef.SetWindowText(showStartRef);
2987 CWnd *pWnd = GetDlgItem(IDC_STATIC_REF);
2988 m_tooltips.AddTool(pWnd, showStartRef);
2989 m_staticRef.Invalidate(TRUE);
2992 void CLogDlg::SetRange(const CString& range)
2994 m_LogList.SetRange(range);
2995 m_ChangedFileListCtrl.m_sDisplayedBranch = range;
2997 ShowStartRef();
3000 static void AppendMenuChecked(CMenu &menu, UINT nTextID, UINT_PTR nItemID, BOOL checked = FALSE, BOOL enabled = TRUE)
3002 CString text;
3003 text.LoadString(nTextID);
3004 menu.AppendMenu(MF_STRING | (enabled ? MF_ENABLED : MF_DISABLED) | (checked ? MF_CHECKED : MF_UNCHECKED), nItemID, text);
3007 #define WALKBEHAVIOUR_FIRSTPARENT 1
3008 #define WALKBEHAVIOUR_FOLLOWRENAMES 2
3009 #define WALKBEHAVIOUR_COMPRESSEDGRAPH 3
3010 #define WALKBEHAVIOUR_LABELEDCOMMITS 4
3011 #define WALKBEHAVIOUR_NOMERGES 5
3013 void CLogDlg::OnBnClickedWalkBehaviour()
3015 CMenu popup;
3016 if (popup.CreatePopupMenu())
3018 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_FIRSTPARENT, WALKBEHAVIOUR_FIRSTPARENT, m_bFirstParent);
3019 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_NOMERGES, WALKBEHAVIOUR_NOMERGES, m_bNoMerges);
3020 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_FOLLOWRENAMES, WALKBEHAVIOUR_FOLLOWRENAMES, m_bFollowRenames, !(m_path.IsEmpty() || m_path.IsDirectory()));
3021 popup.AppendMenu(MF_SEPARATOR, NULL);
3022 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_COMPRESSED, WALKBEHAVIOUR_COMPRESSEDGRAPH, m_iCompressedGraph == 1);
3023 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_LABELEDCOMMITS, WALKBEHAVIOUR_LABELEDCOMMITS, m_iCompressedGraph == 2);
3025 m_tooltips.Pop();
3026 RECT rect;
3027 GetDlgItem(IDC_WALKBEHAVIOUR)->GetWindowRect(&rect);
3028 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, rect.left, rect.top, this, 0);
3029 switch (selection)
3031 case WALKBEHAVIOUR_FIRSTPARENT:
3032 m_bFirstParent = !m_bFirstParent;
3033 OnBnClickedFirstParent();
3034 break;
3035 case WALKBEHAVIOUR_NOMERGES:
3036 m_bNoMerges = !m_bNoMerges;
3037 OnBnClickedFirstParent(); // OnBnClickedFirstParent handles both cases: m_bFirstParent and m_bNoMerges
3038 break;
3039 case WALKBEHAVIOUR_FOLLOWRENAMES:
3040 m_bFollowRenames = !m_bFollowRenames;
3041 OnBnClickedFollowRenames();
3042 break;
3043 case WALKBEHAVIOUR_COMPRESSEDGRAPH:
3044 m_iCompressedGraph = (m_iCompressedGraph == 1 ? 0 : 1);
3045 OnBnClickedCompressedGraph();
3046 break;
3047 case WALKBEHAVIOUR_LABELEDCOMMITS:
3048 m_iCompressedGraph = (m_iCompressedGraph == 2 ? 0 : 2);
3049 OnBnClickedCompressedGraph();
3050 break;
3051 default:
3052 break;
3054 m_bWalkBehavior = (m_bFirstParent || m_bNoMerges || m_bFollowRenames || m_iCompressedGraph);
3055 UpdateData(FALSE);
3059 #define VIEW_HIDEPATHS 1
3060 #define VIEW_GRAYPATHS 2
3061 #define VIEW_SHOWTAGS 3
3062 #define VIEW_SHOWLOCALBRANCHES 4
3063 #define VIEW_SHOWREMOTEBRANCHES 5
3064 #define VIEW_SHOWGRAVATAR 6
3065 #define VIEW_SHOWPATCH 7
3067 void CLogDlg::OnBnClickedView()
3069 CMenu popup;
3070 if (popup.CreatePopupMenu())
3072 AppendMenuChecked(popup, IDS_SHOWFILES_HIDEPATHS, VIEW_HIDEPATHS, m_iHidePaths == 1);
3073 AppendMenuChecked(popup, IDS_SHOWFILES_GRAYPATHS, VIEW_GRAYPATHS, m_iHidePaths == 2);
3074 popup.AppendMenu(MF_SEPARATOR, NULL);
3075 CMenu showLabelsMenu;
3076 if (showLabelsMenu.CreatePopupMenu())
3078 AppendMenuChecked(showLabelsMenu, IDS_VIEW_SHOWTAGLABELS, VIEW_SHOWTAGS, m_bShowTags);
3079 AppendMenuChecked(showLabelsMenu, IDS_VIEW_SHOWLOCALBRANCHLABELS, VIEW_SHOWLOCALBRANCHES, m_bShowLocalBranches);
3080 AppendMenuChecked(showLabelsMenu, IDS_VIEW_SHOWREMOTEBRANCHLABELS, VIEW_SHOWREMOTEBRANCHES, m_bShowRemoteBranches);
3081 popup.AppendMenu(MF_STRING | MF_POPUP, (UINT)showLabelsMenu.m_hMenu, (CString)MAKEINTRESOURCE(IDS_VIEW_LABELS));
3083 popup.AppendMenu(MF_SEPARATOR, NULL);
3084 AppendMenuChecked(popup, IDS_VIEW_SHOWGRAVATAR, VIEW_SHOWGRAVATAR, m_bShowGravatar);
3085 AppendMenuChecked(popup, IDS_MENU_VIEWPATCH, VIEW_SHOWPATCH, IsWindow(this->m_patchViewdlg.m_hWnd));
3087 m_tooltips.Pop();
3088 RECT rect;
3089 GetDlgItem(IDC_VIEW)->GetWindowRect(&rect);
3090 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, rect.left, rect.top, this, 0);
3091 switch (selection)
3093 case VIEW_HIDEPATHS:
3094 if (m_iHidePaths == 1)
3095 m_iHidePaths = 0;
3096 else
3097 m_iHidePaths = 1;
3098 OnBnClickedHidepaths();
3099 break;
3100 case VIEW_GRAYPATHS:
3101 if (m_iHidePaths == 2)
3102 m_iHidePaths = 0;
3103 else
3104 m_iHidePaths = 2;
3105 OnBnClickedHidepaths();
3106 break;
3107 case VIEW_SHOWTAGS:
3108 m_bShowTags = !m_bShowTags;
3109 HandleShowLabels(m_bShowTags, LOGLIST_SHOWTAGS);
3110 break;
3111 case VIEW_SHOWLOCALBRANCHES:
3112 m_bShowLocalBranches = !m_bShowLocalBranches;
3113 HandleShowLabels(m_bShowLocalBranches, LOGLIST_SHOWLOCALBRANCHES);
3114 break;
3115 case VIEW_SHOWREMOTEBRANCHES:
3116 m_bShowRemoteBranches = !m_bShowRemoteBranches;
3117 HandleShowLabels(m_bShowRemoteBranches, LOGLIST_SHOWREMOTEBRANCHES);
3118 break;
3119 case VIEW_SHOWGRAVATAR:
3121 m_bShowGravatar = !m_bShowGravatar;
3122 ShowGravatar();
3123 m_gravatar.Init();
3124 CString email;
3125 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
3126 if (pos)
3128 int selIndex = m_LogList.GetNextSelectedItem(pos);
3129 int moreSel = m_LogList.GetNextSelectedItem(pos);
3130 if (moreSel < 0)
3132 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
3133 if (pLogEntry)
3134 email = pLogEntry->GetAuthorEmail();
3137 m_gravatar.LoadGravatar(email);
3138 break;
3140 case VIEW_SHOWPATCH:
3141 TogglePatchView();
3142 break;
3143 default:
3144 break;
3149 void CLogDlg::OnBnClickedFirstParent()
3151 if(this->m_bFirstParent)
3152 m_LogList.m_ShowMask|=CGit::LOG_INFO_FIRST_PARENT;
3153 else
3154 m_LogList.m_ShowMask&=~CGit::LOG_INFO_FIRST_PARENT;
3156 if (m_bNoMerges)
3157 m_LogList.m_ShowMask |= CGit::LOG_INFO_NO_MERGE;
3158 else
3159 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_NO_MERGE;
3161 OnRefresh();
3163 FillLogMessageCtrl(false);
3167 void CLogDlg::OnBnClickShowWholeProject()
3169 this->UpdateData();
3171 if(this->m_bWholeProject)
3173 m_LogList.m_Path.Reset();
3174 SetDlgTitle();
3176 else
3177 m_LogList.m_Path=m_path;
3179 m_regShowWholeProject = m_bWholeProject;
3181 SetDlgTitle();
3183 OnRefresh();
3185 FillLogMessageCtrl(false);
3189 LRESULT CLogDlg::OnRefLogChanged(WPARAM /*wParam*/, LPARAM /*lParam*/)
3191 ShowStartRef();
3192 return 0;
3195 LRESULT CLogDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
3197 m_pTaskbarList.Release();
3198 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
3199 SetUUIDOverlayIcon(m_hWnd);
3200 return 0;
3203 LRESULT CLogDlg::OnRefreshSelection(WPARAM /*wParam*/, LPARAM /*lParam*/)
3205 // it's enough to deselect, then select again one item of the whole selection
3206 int selMark = m_LogList.GetSelectionMark();
3207 if (selMark >= 0)
3209 m_LogList.SetSelectionMark(selMark);
3210 m_LogList.SetItemState(selMark, 0, LVIS_SELECTED);
3211 m_LogList.SetItemState(selMark, LVIS_SELECTED, LVIS_SELECTED);
3213 return 0;