Uncheck autoload putty key for git://, http://, and https:// clone URLs
[TortoiseGit.git] / src / TortoiseProc / LogDlg.cpp
blob808da14725adc51ac84a50ec9d8fed47948640d9
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 "PathUtils.h"
29 #include "StringUtils.h"
30 #include "UnicodeUtils.h"
31 #include "TempFile.h"
32 #include "IconMenu.h"
33 #include "BrowseRefsDlg.h"
34 #include "SmartHandle.h"
35 #include "LogOrdering.h"
37 #define WM_TGIT_REFRESH_SELECTION (WM_APP + 1)
39 IMPLEMENT_DYNAMIC(CLogDlg, CResizableStandAloneDialog)
40 CLogDlg::CLogDlg(CWnd* pParent /*=NULL*/)
41 : CResizableStandAloneDialog(CLogDlg::IDD, pParent)
42 , m_wParam(0)
43 , m_currentChangedArray(NULL)
44 , m_nSortColumn(0)
45 , m_bFollowRenames(false)
46 , m_bSelect(false)
47 , m_bSelectionMustBeSingle(true)
48 , m_bShowTags(true)
49 , m_bShowLocalBranches(true)
50 , m_bShowRemoteBranches(true)
51 , m_bNoMerges(false)
52 , m_iHidePaths(0)
53 , m_bWalkBehavior(FALSE)
54 , m_bFirstParent(false)
55 , m_bWholeProject(FALSE)
56 , m_iCompressedGraph(0)
58 , m_bSelectionMustBeContinuous(false)
60 , m_sLogInfo(_T(""))
62 , m_bCancelled(FALSE)
63 , m_pNotifyWindow(NULL)
65 , m_bAscending(FALSE)
67 , m_limit(0)
68 , m_hAccel(NULL)
69 , m_bNavigatingWithSelect(false)
71 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE);
72 m_bFilterCaseSensitively = !!CRegDWORD(L"Software\\TortoiseGit\\FilterCaseSensitively", FALSE);
73 m_bAsteriskLogPrefix = !!CRegDWORD(L"Software\\TortoiseGit\\AsteriskLogPrefix", TRUE);
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.IsEmpty() || range == _T("HEAD")))
217 m_bAllBranch = BST_UNCHECKED;
219 SetRange(range);
221 m_limit = limit;
222 if (::IsWindow(m_hWnd))
223 UpdateData(FALSE);
226 void CLogDlg::SetFilter(const CString& findstr, LONG findtype, bool findregex)
228 m_LogList.m_sFilterText = findstr;
229 if (findtype)
230 m_LogList.m_SelectedFilters = findtype;
231 m_LogList.m_bFilterWithRegex = m_bFilterWithRegex = findregex;
234 BOOL CLogDlg::OnInitDialog()
236 CString temp;
237 CResizableStandAloneDialog::OnInitDialog();
238 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
240 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
241 // do this, Explorer would be unable to send that message to our window if we
242 // were running elevated. It's OK to make the call all the time, since if we're
243 // not elevated, this is a no-op.
244 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
245 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
246 CAutoLibrary hUser = AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
247 if (hUser)
249 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
250 if (pfnChangeWindowMessageFilterEx)
252 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
255 m_pTaskbarList.Release();
256 if (FAILED(m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList)))
257 m_pTaskbarList = nullptr;
259 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_LOGDLG));
261 // use the state of the "stop on copy/rename" option from the last time
262 UpdateData(FALSE);
264 // set the font to use in the log message view, configured in the settings dialog
265 CAppUtils::CreateFontForLogs(m_logFont);
266 GetDlgItem(IDC_MSGVIEW)->SetFont(&m_logFont);
267 // make the log message rich edit control send a message when the mouse pointer is over a link
268 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_SETEVENTMASK, NULL, ENM_LINK | ENM_SCROLL);
270 // "unrelated paths" should be in gray color
271 m_iHidePaths = 2;
273 // set up the columns
274 m_LogList.DeleteAllItems();
276 m_LogList.m_Path=m_path;
277 m_LogList.m_hasWC = m_LogList.m_bShowWC = !g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir);
278 m_LogList.InsertGitColumn();
280 if (m_bWholeProject)
281 m_LogList.m_Path.Reset();
283 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);
285 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
287 SetDlgTitle();
289 m_tooltips.Create(this);
290 CheckRegexpTooltip();
292 SetSplitterRange();
294 // the filter control has a 'cancel' button (the red 'X'), we need to load its bitmap
295 m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);
296 m_cFilter.SetInfoIcon(IDI_LOGFILTER);
297 m_cFilter.SetValidator(this);
299 AdjustControlSize(IDC_LOG_ALLBRANCH);
300 AdjustControlSize(IDC_SHOWWHOLEPROJECT);
302 GetClientRect(m_DlgOrigRect);
303 m_LogList.GetClientRect(m_LogListOrigRect);
304 GetDlgItem(IDC_MSGVIEW)->GetClientRect(m_MsgViewOrigRect);
305 m_ChangedFileListCtrl.GetClientRect(m_ChgOrigRect);
307 m_DateFrom.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
308 m_DateTo.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
310 m_staticRef.SetURL(CString());
312 // resizable stuff
313 AddAnchor(IDC_STATIC_REF, TOP_LEFT);
314 //AddAnchor(IDC_BUTTON_BROWSE_REF, TOP_LEFT);
315 AddAnchor(IDC_FROMLABEL, TOP_LEFT);
316 AddAnchor(IDC_DATEFROM, TOP_LEFT);
317 AddAnchor(IDC_TOLABEL, TOP_LEFT);
318 AddAnchor(IDC_DATETO, TOP_LEFT);
320 SetFilterCueText();
321 AddAnchor(IDC_SEARCHEDIT, TOP_LEFT, TOP_RIGHT);
322 AddAnchor(IDC_LOG_JUMPTYPE, TOP_RIGHT);
323 AddAnchor(IDC_LOG_JUMPUP, TOP_RIGHT);
324 AddAnchor(IDC_LOG_JUMPDOWN, TOP_RIGHT);
326 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
327 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
328 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
329 AddAnchor(IDC_PIC_AUTHOR, TOP_RIGHT);
330 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
331 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
333 AddAnchor(IDC_LOGINFO, BOTTOM_LEFT, BOTTOM_RIGHT);
334 AddAnchor(IDC_WALKBEHAVIOUR, BOTTOM_LEFT);
335 AddAnchor(IDC_VIEW, BOTTOM_LEFT);
336 AddAnchor(IDC_LOG_ALLBRANCH,BOTTOM_LEFT);
337 AddAnchor(IDC_FILTER, BOTTOM_LEFT, BOTTOM_RIGHT);
338 AddAnchor(IDC_SHOWWHOLEPROJECT, BOTTOM_LEFT);
339 AddAnchor(IDC_REFRESH, BOTTOM_LEFT);
340 AddAnchor(IDC_STATBUTTON, BOTTOM_LEFT);
341 AddAnchor(IDC_PROGRESS, BOTTOM_LEFT, BOTTOM_RIGHT);
342 AddAnchor(IDOK, BOTTOM_RIGHT);
343 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
344 AddAnchor(IDHELP, BOTTOM_RIGHT);
346 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_LOCAL_BRANCHES;
347 if (m_bAllBranch == BST_CHECKED)
348 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
349 else if (m_bAllBranch == BST_INDETERMINATE)
350 m_LogList.m_ShowMask |= CGit::LOG_INFO_LOCAL_BRANCHES;
351 else
352 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
354 HandleShowLabels(m_bShowTags, LOGLIST_SHOWTAGS);
355 HandleShowLabels(m_bShowLocalBranches, LOGLIST_SHOWLOCALBRANCHES);
356 HandleShowLabels(m_bShowRemoteBranches, LOGLIST_SHOWREMOTEBRANCHES);
358 // SetPromptParentWindow(m_hWnd);
359 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_AUTHOREMAIL)));
360 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_COMMITTEREMAIL)));
361 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_MERGEPOINT)));
362 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_PARENT1)));
363 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_PARENT2)));
364 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_TAG)));
365 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_TAG_FF)));
366 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_BRANCH)));
367 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_BRANCH_FF)));
368 m_JumpType.AddString(CString(MAKEINTRESOURCE(IDS_PROC_SELECTION_HISTORY)));
369 m_JumpType.SetCurSel(0);
370 m_JumpUp.SetIcon((HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_JUMPUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR));
371 m_JumpDown.SetIcon((HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_JUMPDOWN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR));
373 if (hWndExplorer)
374 CenterWindow(CWnd::FromHandle(hWndExplorer));
375 EnableSaveRestore(_T("LogDlg"));
377 DWORD yPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
378 DWORD yPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
379 RECT rcDlg, rcLogList, rcChgMsg;
380 GetClientRect(&rcDlg);
381 m_LogList.GetWindowRect(&rcLogList);
382 ScreenToClient(&rcLogList);
383 m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg);
384 ScreenToClient(&rcChgMsg);
385 if (yPos1)
387 RECT rectSplitter;
388 m_wndSplitter1.GetWindowRect(&rectSplitter);
389 ScreenToClient(&rectSplitter);
390 int delta = yPos1 - rectSplitter.top;
392 if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30))
394 m_wndSplitter1.SetWindowPos(NULL, rectSplitter.left, yPos1, 0, 0, SWP_NOSIZE);
395 DoSizeV1(delta);
398 if (yPos2)
400 RECT rectSplitter;
401 m_wndSplitter2.GetWindowRect(&rectSplitter);
402 ScreenToClient(&rectSplitter);
403 int delta = yPos2 - rectSplitter.top;
405 if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30))
407 m_wndSplitter2.SetWindowPos(NULL, rectSplitter.left, yPos2, 0, 0, SWP_NOSIZE);
408 DoSizeV2(delta);
412 SetSplitterRange();
414 if (m_bSelect)
416 // the dialog is used to select revisions
417 // enable the OK button if appropriate
418 EnableOKButton();
420 else
422 // the dialog is used to just view log messages
423 // hide the OK button and set text on Cancel button to OK
424 GetDlgItemText(IDOK, temp);
425 SetDlgItemText(IDCANCEL, temp);
426 GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
429 // first start a thread to obtain the log messages without
430 // blocking the dialog
431 //m_tTo = 0;
432 //m_tFrom = (DWORD)-1;
434 // scroll to user selected or current revision
435 if (m_hightlightRevision.IsEmpty() || g_Git.GetHash(m_LogList.m_lastSelectedHash, m_hightlightRevision))
437 if (g_Git.GetHash(m_LogList.m_lastSelectedHash, _T("HEAD")))
438 MessageBox(g_Git.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR);
441 if (g_Git.GetConfigValueBool(_T("tgit.logshowpatch")))
442 TogglePatchView();
444 m_LogList.FetchLogAsync(this);
445 ShowGravatar();
446 m_gravatar.Init();
448 m_cFileFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);
449 m_cFileFilter.SetInfoIcon(IDI_FILTEREDIT);
450 temp.LoadString(IDS_FILEDIFF_FILTERCUE);
451 temp = _T(" ") + temp;
452 m_cFileFilter.SetCueBanner(temp);
454 GetDlgItem(IDC_LOGLIST)->SetFocus();
456 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxRefHistoryItems"), 5));
457 CString reg;
458 reg.Format(_T("Software\\TortoiseGit\\History\\log-refs\\%s"), g_Git.m_CurrentDir);
459 reg.Replace(_T(':'),_T('_'));
460 m_History.Load(reg, _T("ref"));
462 ShowStartRef();
463 return FALSE;
466 LRESULT CLogDlg::OnLogListLoading(WPARAM wParam, LPARAM /*lParam*/)
468 int cur=(int)wParam;
470 if( cur == GITLOG_START )
472 CString temp;
473 temp.LoadString(IDS_PROGRESSWAIT);
475 this->m_LogList.ShowText(temp, true);
477 // We use a progress bar while getting the logs
478 m_LogProgress.SetRange32(0, 100);
479 m_LogProgress.SetPos(0);
480 if (m_pTaskbarList)
482 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
483 m_pTaskbarList->SetProgressValue(m_hWnd, 0, 100);
486 GetDlgItem(IDC_WALKBEHAVIOUR)->ShowWindow(SW_HIDE);
487 GetDlgItem(IDC_VIEW)->ShowWindow(SW_HIDE);
488 GetDlgItem(IDC_STATBUTTON)->ShowWindow(SW_HIDE);
489 GetDlgItem(IDC_PROGRESS)->ShowWindow(TRUE);
491 DialogEnableWindow(IDC_WALKBEHAVIOUR, FALSE);
492 DialogEnableWindow(IDC_STATBUTTON, FALSE);
493 //DialogEnableWindow(IDC_REFRESH, FALSE);
494 DialogEnableWindow(IDC_VIEW, FALSE);
497 else if( cur == GITLOG_END)
499 if(this->m_LogList.HasText())
501 this->m_LogList.ClearText();
503 UpdateLogInfoLabel();
505 if (m_pTaskbarList)
506 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
508 DialogEnableWindow(IDC_SHOWWHOLEPROJECT, !m_bFollowRenames && !m_path.IsEmpty());
510 DialogEnableWindow(IDC_STATBUTTON, !(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC));
511 DialogEnableWindow(IDC_REFRESH, TRUE);
512 DialogEnableWindow(IDC_VIEW, TRUE);
513 DialogEnableWindow(IDC_WALKBEHAVIOUR, TRUE);
514 // PostMessage(WM_TIMER, LOGFILTER_TIMER);
515 GetDlgItem(IDC_WALKBEHAVIOUR)->ShowWindow(SW_SHOW);
516 GetDlgItem(IDC_VIEW)->ShowWindow(SW_SHOW);
517 GetDlgItem(IDC_STATBUTTON)->ShowWindow(SW_SHOW);
518 GetDlgItem(IDC_PROGRESS)->ShowWindow(FALSE);
519 //CTime time=m_LogList.GetOldestTime();
520 CTime begin,end;
521 m_LogList.GetTimeRange(begin,end);
523 if(m_LogList.m_From == -1)
524 m_DateFrom.SetTime(&begin);
526 if(m_LogList.m_To == -1)
527 m_DateTo.SetTime(&end);
531 else
533 if(this->m_LogList.HasText())
535 this->m_LogList.ClearText();
536 this->m_LogList.Invalidate();
538 UpdateLogInfoLabel();
539 m_LogProgress.SetPos(cur);
540 if (m_pTaskbarList)
542 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
543 m_pTaskbarList->SetProgressValue(m_hWnd, cur, 100);
546 return 0;
548 void CLogDlg::SetDlgTitle()
550 if (m_sTitle.IsEmpty())
551 GetWindowText(m_sTitle);
553 if (m_LogList.m_Path.IsEmpty() || m_orgPath.GetWinPathString().IsEmpty())
555 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
557 else
558 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);
561 void CLogDlg::CheckRegexpTooltip()
563 CWnd *pWnd = GetDlgItem(IDC_SEARCHEDIT);
564 // Since tooltip describes regexp features, show it only if regexps are enabled.
565 if (m_bFilterWithRegex)
567 m_tooltips.AddTool(pWnd, IDS_LOG_FILTER_REGEX_TT);
569 else
570 m_tooltips.DelTool(pWnd);
573 void CLogDlg::EnableOKButton()
575 if (m_bSelect)
577 // the dialog is used to select revisions
578 if (m_bSelectionMustBeSingle)
580 // enable OK button if only a single revision is selected
581 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()==1));
583 else if (m_bSelectionMustBeContinuous)
584 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));
585 else
586 DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);
588 else
589 DialogEnableWindow(IDOK, TRUE);
592 bool LookLikeGitHash(const CString& msg, int &pos)
594 int c = 0;
595 for (; pos < msg.GetLength(); ++pos)
597 if (msg[pos] >= '0' && msg[pos] <= '9' || msg[pos] >= 'a' && msg[pos] <= 'f')
599 c++;
601 else
603 return c >= g_Git.GetShortHASHLength() && c <= GIT_HASH_SIZE * 2;
606 return c >= g_Git.GetShortHASHLength() && c <= GIT_HASH_SIZE * 2;
609 std::vector<CHARRANGE> FindGitHashPositions(const CString& msg, int offset)
611 std::vector<CHARRANGE> result;
612 offset = offset < 0 ? 0 : offset;
613 int old = offset;
614 while (offset < msg.GetLength())
616 old = offset;
617 TCHAR e = msg[offset];
618 if (e == '\n')
620 ++offset;
621 if (msg.Mid(offset, 11) == _T("git-svn-id:")
622 || msg.Mid(offset, 14) == _T("Signed-off-by:")
623 || msg.Mid(offset, 10) == _T("Change-Id:")
626 offset += 10;
627 while (offset < msg.GetLength())
629 if (msg[offset++] == '\n')
630 break;
632 continue;
635 else if (e >= 'A' && e <= 'Z' || e >= 'h' && e <= 'z')
639 e = msg[++offset];
640 } while (offset < msg.GetLength() && (e >= 'A' && e <= 'Z' || e >= 'a' && e <= 'z' || e >= '0' && e <= '9'));
642 else if (e >= 'a' && e <= 'g' || e >= '0' && e <= '9')
644 if (e == 'g')
646 ++old;
647 ++offset;
649 if (LookLikeGitHash(msg, offset))
651 TCHAR d = offset < msg.GetLength() ? msg[offset] : '\0';
652 if (!((d >= 'A' && d <= 'Z') || (d >= 'a' && d <= 'z') || (d >= '0' && d <= '9')))
654 CHARRANGE range = { old, offset };
655 result.push_back(range);
658 ++offset;
660 else
662 ++offset;
666 return result;
669 BOOL FindGitHash(const CString& msg, int offset, CWnd *pWnd)
671 std::vector<CHARRANGE> positions = FindGitHashPositions(msg, offset);
672 CAppUtils::SetCharFormat(pWnd, CFM_LINK, CFE_LINK, positions);
674 return positions.empty() ? FALSE : TRUE;
677 static int DescribeCommit(CGitHash& hash, CString& result)
679 CAutoRepository repo(g_Git.GetGitRepository());
680 if (!repo)
681 return -1;
682 CAutoObject commit;
683 if (git_object_lookup(commit.GetPointer(), repo, (const git_oid *)hash.m_hash, GIT_OBJ_COMMIT))
684 return -1;
686 CAutoDescribeResult describe;
687 git_describe_options describe_options = GIT_DESCRIBE_OPTIONS_INIT;
688 describe_options.describe_strategy = CRegDWORD(_T("Software\\TortoiseGit\\DescribeStrategy"), GIT_DESCRIBE_DEFAULT);
689 if (git_describe_commit(describe.GetPointer(), (git_object *)commit, &describe_options))
690 return -1;
692 CAutoBuf describe_buf;
693 git_describe_format_options format_options = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
694 format_options.abbreviated_size = CRegDWORD(_T("Software\\TortoiseGit\\DescribeAbbreviatedSize"), GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE);
695 format_options.always_use_long_format = CRegDWORD(_T("Software\\TortoiseGit\\DescribeAlwaysLong"));
696 if (git_describe_format(describe_buf, describe, &format_options))
697 return -1;
699 result = CUnicodeUtils::GetUnicode(describe_buf->ptr);
700 return 0;
703 void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)
705 // we fill here the log message rich edit control,
706 // and also populate the changed files list control
707 // according to the selected revision(s).
709 CRichEditCtrl * pMsgView = (CRichEditCtrl*)GetDlgItem(IDC_MSGVIEW);
710 // empty the log message view
711 pMsgView->SetWindowText(_T(" "));
712 FillPatchView(true);
713 // empty the changed files list
714 m_ChangedFileListCtrl.SetRedraw(FALSE);
715 // InterlockedExchange(&m_bNoDispUpdates, TRUE);
716 m_currentChangedArray = NULL;
717 m_ChangedFileListCtrl.DeleteAllItems();
719 // if we're not here to really show a selected revision, just
720 // get out of here after clearing the views, which is what is intended
721 // if that flag is not set.
722 if (!bShow)
724 // force a redraw
725 m_ChangedFileListCtrl.Invalidate();
726 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
727 m_ChangedFileListCtrl.SetRedraw(TRUE);
728 m_gravatar.LoadGravatar();
729 return;
732 // depending on how many revisions are selected, we have to do different
733 // tasks.
734 int selCount = m_LogList.GetSelectedCount();
735 if (selCount == 0)
737 // if nothing is selected, we have nothing more to do
738 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
739 m_ChangedFileListCtrl.SetRedraw(TRUE);
740 m_gravatar.LoadGravatar();
741 return;
743 else if (selCount == 1)
745 // if one revision is selected, we have to fill the log message view
746 // with the corresponding log message, and also fill the changed files
747 // list fully.
748 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
749 int selIndex = m_LogList.GetNextSelectedItem(pos);
750 if (selIndex >= m_LogList.m_arShownList.GetCount())
752 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
753 m_ChangedFileListCtrl.SetRedraw(TRUE);
754 return;
756 Locker lock(m_LogList.m_critSec_AsyncDiff);
757 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
760 CString out_describe;
761 if (m_bShowDescribe)
763 CString result;
764 if (!DescribeCommit(pLogEntry->m_CommitHash, result))
765 out_describe = _T("Describe: ") + result + _T("\r\n");
768 // set the log message text
769 pMsgView->SetWindowText(CString(MAKEINTRESOURCE(IDS_HASH)) + _T(": ") + pLogEntry->m_CommitHash.ToString() + _T("\r\n") + out_describe + _T("\r\n"));
770 // turn bug ID's into links if the bugtraq: properties have been set
771 // and we can find a match of those in the log message
773 pMsgView->SetSel(-1,-1);
774 CAppUtils::SetCharFormat(pMsgView, CFM_BOLD, CFE_BOLD);
776 CString msg = m_bAsteriskLogPrefix ? _T("* ") : _T("");
777 msg+=pLogEntry->GetSubject();
778 pMsgView->ReplaceSel(msg);
780 pMsgView->SetSel(-1,-1);
781 CAppUtils::SetCharFormat(pMsgView, CFM_BOLD, 0);
783 msg=_T("\n");
784 msg+=pLogEntry->GetBody();
786 if(!pLogEntry->m_Notes.IsEmpty())
788 msg+= _T("\n*") + CString(MAKEINTRESOURCE(IDS_NOTES)) + _T("* ");
789 msg+= pLogEntry->m_Notes;
790 msg+= _T("\n\n");
793 CString tagInfo = m_LogList.GetTagInfo(pLogEntry);
794 if(!tagInfo.IsEmpty())
795 tagInfo = _T("\n*") + CString(MAKEINTRESOURCE(IDS_PROC_LOG_TAGINFO)) + _T("*\n\n") + tagInfo;
796 msg += tagInfo;
798 pMsgView->ReplaceSel(msg);
800 CString text;
801 pMsgView->GetWindowText(text);
802 // the rich edit control doesn't count the CR char!
803 // to be exact: CRLF is treated as one char.
804 text.Remove('\r');
806 int findHashStart = text.Find('\n');
807 if (!out_describe.IsEmpty())
808 findHashStart = text.Find('\n', findHashStart + 1);
809 FindGitHash(text, findHashStart, pMsgView);
810 m_LogList.m_ProjectProperties.FindBugID(text, pMsgView);
811 CAppUtils::StyleURLs(text, pMsgView);
812 if (((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\StyleCommitMessages"), TRUE)) == TRUE)
813 CAppUtils::FormatTextInRichEditControl(pMsgView);
815 CHARRANGE range;
816 range.cpMin = 0;
817 range.cpMax = 0;
818 pMsgView->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
820 CString matchpath=this->m_path.GetGitPathString();
822 bool mightNeedReset = true;
824 int count = pLogEntry->GetFiles(&m_LogList).GetCount();
825 for (int i = 0 ; i < count && (!matchpath.IsEmpty()); ++i)
827 if( m_bWholeProject )
828 break;
830 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action &= ~(CTGitPath::LOGACTIONS_HIDE|CTGitPath::LOGACTIONS_GRAY);
831 mightNeedReset = false;
833 if(pLogEntry->GetFiles(&m_LogList)[i].GetGitPathString().Left(matchpath.GetLength()) != matchpath && pLogEntry->GetFiles(&m_LogList)[i].GetGitOldPathString().Left(matchpath.GetLength()) != matchpath)
835 if (m_iHidePaths == 1)
836 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;
837 else if (m_iHidePaths == 2)
838 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_GRAY;
842 if (mightNeedReset)
844 for (int i = 0 ; i < count; ++i)
845 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action &= ~CTGitPath::LOGACTIONS_HIDE;
848 CString fileFilter;
849 m_cFileFilter.GetWindowText(fileFilter);
850 fileFilter.MakeLower();
851 for (int i = 0; i < count && (!fileFilter.IsEmpty()); ++i)
853 CString sPath = pLogEntry->GetFiles(&m_LogList)[i].GetGitPathString();
854 sPath.MakeLower();
855 if (sPath.Find(fileFilter) < 0)
856 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;
859 m_ChangedFileListCtrl.UpdateWithGitPathList(pLogEntry->GetFiles(&m_LogList));
860 m_ChangedFileListCtrl.m_CurrentVersion=pLogEntry->m_CommitHash;
861 if (pLogEntry->m_CommitHash.IsEmpty() && m_bShowUnversioned)
863 m_ChangedFileListCtrl.UpdateUnRevFileList(pLogEntry->GetUnRevFiles());
864 m_ChangedFileListCtrl.Show(GITSLC_SHOWVERSIONED | GITSLC_SHOWUNVERSIONED);
866 else
867 m_ChangedFileListCtrl.Show(GITSLC_SHOWVERSIONED);
869 m_ChangedFileListCtrl.SetBusyString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES)));
871 if(!pLogEntry->m_IsDiffFiles)
872 m_ChangedFileListCtrl.SetBusy(TRUE);
873 else
874 m_ChangedFileListCtrl.SetBusy(FALSE);
876 m_ChangedFileListCtrl.SetRedraw(TRUE);
877 m_gravatar.LoadGravatar(pLogEntry->GetAuthorEmail());
878 return;
882 else
884 // more than one revision is selected:
885 // the log message view must be emptied
886 // the changed files list contains all the changed paths from all
887 // selected revisions, with 'doubles' removed
888 m_currentChangedPathList = GetChangedPathsFromSelectedRevisions(true);
889 m_gravatar.LoadGravatar();
892 // redraw the views
893 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
894 #if 0
895 if (m_currentChangedArray)
897 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedArray->GetCount());
898 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedArray->GetCount());
900 else if (m_currentChangedPathList.GetCount())
902 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedPathList.GetCount());
903 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedPathList.GetCount());
905 else
907 m_ChangedFileListCtrl.SetItemCountEx(0);
908 m_ChangedFileListCtrl.Invalidate();
910 #endif
911 // sort according to the settings
912 if (m_nSortColumnPathList > 0)
913 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
914 else
915 SetSortArrow(&m_ChangedFileListCtrl, -1, false);
916 m_ChangedFileListCtrl.SetRedraw(TRUE);
920 void CLogDlg::FillPatchView(bool onlySetTimer)
922 if (!::IsWindow(this->m_patchViewdlg.m_hWnd))
923 return;
925 KillTimer(LOG_FILLPATCHVTIMER);
926 if (onlySetTimer)
928 SetTimer(LOG_FILLPATCHVTIMER, 100, nullptr);
929 return;
932 POSITION posLogList = m_LogList.GetFirstSelectedItemPosition();
933 if (posLogList == nullptr)
935 m_patchViewdlg.ClearView();
936 return; // nothing is selected, get out of here
939 GitRev * pLogEntry = reinterpret_cast<GitRev* >(m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(posLogList)));
940 if (pLogEntry == nullptr || m_LogList.GetNextSelectedItem(posLogList) != -1)
942 m_patchViewdlg.ClearView();
943 return;
946 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
947 CString out;
949 if (pos == nullptr)
951 int diffContext = 0;
952 if (CAppUtils::GetMsysgitVersion() > 0x01080100)
953 diffContext = g_Git.GetConfigValueInt32(_T("diff.context"), -1);
954 CStringA outA;
955 CString rev1 = pLogEntry->m_CommitHash.IsEmpty() ? _T("HEAD") : (pLogEntry->m_CommitHash.ToString() + _T("~1"));
956 CString rev2 = pLogEntry->m_CommitHash.IsEmpty() ? GIT_REV_ZERO : pLogEntry->m_CommitHash.ToString();
957 g_Git.GetUnifiedDiff(CTGitPath(), rev1, rev2, &outA, false, false, diffContext);
958 out = CUnicodeUtils::GetUnicode(outA);
960 else
962 while (pos)
964 int nSelect = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
965 CTGitPath * p = (CTGitPath*)m_ChangedFileListCtrl.GetItemData(nSelect);
966 if (p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER))
968 CString cmd;
969 if (pLogEntry->m_CommitHash.IsEmpty())
970 cmd.Format(_T("git.exe diff HEAD -- \"%s\""), p->GetGitPathString());
971 else
972 cmd.Format(_T("git.exe diff %s^%d..%s -- \"%s\""), pLogEntry->m_CommitHash.ToString(), p->m_ParentNo + 1, pLogEntry->m_CommitHash.ToString(), p->GetGitPathString());
973 g_Git.Run(cmd, &out, CP_UTF8);
978 m_patchViewdlg.SetText(out);
981 void CLogDlg::TogglePatchView()
983 m_patchViewdlg.m_pProjectProperties = &m_LogList.m_ProjectProperties;
984 m_patchViewdlg.m_ParentDlg = this;
985 if (!IsWindow(m_patchViewdlg.m_hWnd))
987 BOOL viewPatchEnabled = FALSE;
988 viewPatchEnabled = g_Git.GetConfigValueBool(_T("tgit.logshowpatch"));
989 if (viewPatchEnabled == FALSE)
990 g_Git.SetConfigValue(_T("tgit.logshowpatch"), _T("true"));
991 m_patchViewdlg.Create(IDD_PATCH_VIEW, this);
992 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTHTRACKING, TRUE);
993 CRect rect;
994 this->GetWindowRect(&rect);
996 m_patchViewdlg.ShowWindow(SW_SHOW);
997 m_patchViewdlg.SetWindowPos(nullptr, rect.right, rect.top, rect.Width(), rect.Height(), SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
999 FillPatchView();
1001 else
1003 g_Git.SetConfigValue(_T("tgit.logshowpatch"), _T("false"));
1004 m_patchViewdlg.ShowWindow(SW_HIDE);
1005 m_patchViewdlg.DestroyWindow();
1009 LRESULT CLogDlg::OnFileListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
1011 FillPatchView(true);
1012 return 0;
1015 void CLogDlg::OnMoving(UINT fwSide, LPRECT pRect)
1017 __super::OnMoving(fwSide, pRect);
1019 if (!::IsWindow(m_patchViewdlg.m_hWnd))
1020 return;
1022 RECT patchrect;
1023 m_patchViewdlg.GetWindowRect(&patchrect);
1024 if (!::IsWindow(m_hWnd))
1025 return;
1027 RECT thisrect;
1028 GetWindowRect(&thisrect);
1029 if (patchrect.left == thisrect.right)
1031 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);
1035 void CLogDlg::OnSizing(UINT fwSide, LPRECT pRect)
1037 __super::OnSizing(fwSide, pRect);
1039 if (!::IsWindow(this->m_patchViewdlg.m_hWnd))
1040 return;
1042 CRect thisrect, patchrect;
1043 this->GetWindowRect(thisrect);
1044 this->m_patchViewdlg.GetWindowRect(patchrect);
1045 if (thisrect.right != patchrect.left)
1046 return;
1048 patchrect.left -= (thisrect.right - pRect->right);
1049 patchrect.right -= (thisrect.right - pRect->right);
1051 if (patchrect.bottom == thisrect.bottom)
1052 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
1053 if (patchrect.top == thisrect.top)
1054 patchrect.top -= thisrect.top - pRect->top;
1055 m_patchViewdlg.MoveWindow(patchrect);
1058 void CLogDlg::OnSelectSearchField()
1060 m_cFilter.SetSel(0, -1, FALSE);
1061 m_cFilter.SetFocus();
1064 void CLogDlg::GoBack()
1066 GoBackForward(false, false);
1069 void CLogDlg::GoForward()
1071 GoBackForward(false, true);
1074 void CLogDlg::GoBackAndSelect()
1076 GoBackForward(true, false);
1079 void CLogDlg::GoForwardAndSelect()
1081 GoBackForward(true, true);
1084 void CLogDlg::GoBackForward(bool select, bool bForward)
1086 m_LogList.m_highlight.Empty();
1087 CGitHash gotoHash;
1088 if (bForward ? m_LogList.m_selectionHistory.GoForward(gotoHash) : m_LogList.m_selectionHistory.GoBack(gotoHash))
1090 int i;
1091 for (i = 0; i < m_LogList.m_arShownList.GetCount(); ++i)
1093 GitRev *rev = (GitRev *)m_LogList.m_arShownList.SafeGetAt(i);
1094 if (!rev) continue;
1095 if (rev->m_CommitHash == gotoHash)
1097 m_LogList.EnsureVisible(i, FALSE);
1098 if (select)
1100 m_LogList.m_highlight.Empty();
1101 m_LogList.SetItemState(m_LogList.GetSelectionMark(), 0, LVIS_SELECTED);
1102 m_bNavigatingWithSelect = true;
1103 m_LogList.SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
1104 m_LogList.SetSelectionMark(i);
1105 m_bNavigatingWithSelect = false;
1107 else
1108 m_LogList.m_highlight = gotoHash;
1109 m_LogList.Invalidate();
1110 return;
1113 if (i == m_LogList.m_arShownList.GetCount())
1115 CString msg;
1116 msg.Format(IDS_LOG_NOT_VISIBLE, gotoHash.ToString());
1117 MessageBox(msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1118 return;
1121 PlaySound((LPCTSTR)SND_ALIAS_SYSTEMASTERISK, nullptr, SND_ASYNC | SND_ALIAS_ID);
1124 void CLogDlg::OnBnClickedRefresh()
1126 Refresh (true);
1129 void CLogDlg::Refresh (bool clearfilter /*autoGoOnline*/)
1131 m_limit = 0;
1132 m_LogList.Refresh(clearfilter);
1133 EnableOKButton();
1134 ShowStartRef();
1135 FillLogMessageCtrl(false);
1140 BOOL CLogDlg::Cancel()
1142 return m_bCancelled;
1145 void CLogDlg::SaveSplitterPos()
1147 if (!IsIconic())
1149 CRegDWORD regPos1(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
1150 CRegDWORD regPos2(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
1151 RECT rectSplitter;
1152 m_wndSplitter1.GetWindowRect(&rectSplitter);
1153 ScreenToClient(&rectSplitter);
1154 regPos1 = rectSplitter.top;
1155 m_wndSplitter2.GetWindowRect(&rectSplitter);
1156 ScreenToClient(&rectSplitter);
1157 regPos2 = rectSplitter.top;
1161 void CLogDlg::OnCancel()
1163 this->ShowWindow(SW_HIDE);
1165 // canceling means stopping the working thread if it's still running.
1166 m_LogList.SafeTerminateAsyncDiffThread();
1167 if (this->IsThreadRunning())
1169 m_LogList.SafeTerminateThread();
1171 UpdateData();
1173 SaveSplitterPos();
1174 __super::OnCancel();
1177 void CLogDlg::CopyChangedSelectionToClipBoard()
1180 POSITION posLogList = m_LogList.GetFirstSelectedItemPosition();
1181 if (posLogList == nullptr)
1182 return; // nothing is selected, get out of here
1184 CString sPaths;
1186 // CGitRev* pLogEntry = reinterpret_cast<CGitRev* >(m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1187 // if (posLogList)
1189 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
1190 while (pos)
1192 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
1193 CTGitPath *path = (CTGitPath*)m_ChangedFileListCtrl.GetItemData(nItem);
1194 if(path)
1195 sPaths += path->GetGitPathString();
1196 sPaths += _T("\r\n");
1199 #if 0
1200 else
1202 // only one revision is selected in the log dialog top pane
1203 // but multiple items could be selected in the changed items list
1204 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
1205 while (pos)
1207 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
1208 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(nItem);
1210 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
1212 // some items are hidden! So find out which item the user really selected
1213 INT_PTR selRealIndex = -1;
1214 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
1216 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1217 ++selRealIndex;
1218 if (selRealIndex == nItem)
1220 changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex);
1221 break;
1225 if (changedlogpath)
1227 sPaths += changedlogpath->sPath;
1228 sPaths += _T("\r\n");
1232 #endif
1233 sPaths.Trim();
1234 CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());
1238 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)
1240 // we have three separate context menus:
1241 // one for the branch label in the upper left
1242 // one shown on the log message list control,
1243 // one shown in the changed-files list control
1244 if (pWnd == GetDlgItem(IDC_STATIC_REF))
1246 CIconMenu popup;
1247 if (!popup.CreatePopupMenu())
1248 return;
1250 int cnt = 0;
1251 popup.AppendMenuIcon(++cnt, IDS_MENUREFBROWSE);
1252 popup.SetDefaultItem(cnt);
1253 popup.AppendMenuIcon(++cnt, _T("HEAD"));
1254 CGitHash fetchHead;
1255 g_Git.GetHash(fetchHead, g_Git.FixBranchName(_T("FETCH_HEAD")));
1256 popup.AppendMenuIcon(++cnt, _T("FETCH_HEAD"));
1257 popup.EnableMenuItem(cnt, fetchHead.IsEmpty());
1258 popup.AppendMenuIcon(++cnt, IDS_ALL);
1259 popup.EnableMenuItem(cnt, m_bFollowRenames);
1260 popup.AppendMenuIcon(++cnt, IDS_PROC_LOG_SELECT_LOCAL_BRANCHES);
1261 popup.EnableMenuItem(cnt, m_bFollowRenames);
1262 int offset = ++cnt;
1263 if (m_History.GetCount() > 0)
1265 popup.AppendMenu(MF_SEPARATOR, 0);
1266 for (size_t i = 0; i < m_History.GetCount(); ++i)
1268 CString entry = m_History.GetEntry(i);
1269 if (entry.GetLength() > 150)
1270 entry = entry.Left(150) + _T("...");
1271 popup.AppendMenuIcon(cnt++, entry);
1275 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1276 if (cmd == 0)
1277 return;
1278 else if (cmd == 1)
1280 OnBnClickedBrowseRef();
1281 return;
1284 m_LogList.m_ShowMask &= ~(CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES);
1285 m_bAllBranch = BST_UNCHECKED;
1286 if (cmd == 2)
1288 SetRange(g_Git.GetCurrentBranch(true));
1290 else if (cmd == 3)
1292 SetRange(fetchHead.ToString());
1294 else if (cmd == 4)
1296 m_bAllBranch = BST_CHECKED;
1297 m_LogList.m_ShowMask |= CGit::LOG_INFO_ALL_BRANCH;
1299 else if (cmd == 5)
1301 m_bAllBranch = BST_INDETERMINATE;
1302 m_LogList.m_ShowMask |= CGit::LOG_INFO_LOCAL_BRANCHES;
1304 else if (cmd >= offset)
1306 SetRange(m_History.GetEntry(cmd - offset));
1307 m_History.AddEntry(m_LogList.m_sRange);
1308 m_History.Save();
1311 UpdateData(FALSE);
1313 OnRefresh();
1314 FillLogMessageCtrl(false);
1316 return;
1318 int selCount = m_LogList.GetSelectedCount();
1319 if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))
1321 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1322 int selIndex = -1;
1323 if (pos)
1324 selIndex = m_LogList.GetNextSelectedItem(pos);
1326 GitRev *pRev = ((GitRev*)m_LogList.m_arShownList[selIndex]);
1328 if ((point.x == -1) && (point.y == -1))
1330 CRect rect;
1331 GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);
1332 ClientToScreen(&rect);
1333 point = rect.CenterPoint();
1335 CString sMenuItemText;
1336 CIconMenu popup;
1337 if (popup.CreatePopupMenu())
1339 long start = -1, end = -1;
1340 auto pEdit = (CRichEditCtrl *)GetDlgItem(IDC_MSGVIEW);
1341 pEdit->GetSel(start, end);
1342 // add the 'default' entries
1343 popup.AppendMenuIcon(WM_COPY, IDS_SCIEDIT_COPY, IDI_COPYCLIP);
1344 if (start >= end)
1345 popup.EnableMenuItem(WM_COPY, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1346 popup.AppendMenu(MF_SEPARATOR);
1347 sMenuItemText.LoadString(IDS_STATUSLIST_CONTEXT_COPYEXT);
1348 popup.AppendMenuIcon(EM_SETSEL, sMenuItemText, IDI_COPYCLIP);
1349 popup.AppendMenu(MF_SEPARATOR, NULL);
1350 sMenuItemText.LoadString(IDS_EDIT_NOTES);
1351 popup.AppendMenuIcon( CGitLogList::ID_EDITNOTE, sMenuItemText, IDI_EDIT);
1353 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1354 switch (cmd)
1356 case 0:
1357 break; // no command selected
1358 case EM_SETSEL:
1360 pEdit->SetRedraw(FALSE);
1361 int oldLine = pEdit->GetFirstVisibleLine();
1362 pEdit->SetSel(0, -1);
1363 pEdit->Copy();
1364 pEdit->SetSel(start, end);
1365 int newLine = pEdit->GetFirstVisibleLine();
1366 pEdit->LineScroll(oldLine - newLine);
1367 pEdit->SetRedraw(TRUE);
1368 pEdit->RedrawWindow();
1370 break;
1371 case WM_COPY:
1372 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);
1373 break;
1374 case CGitLogList::ID_EDITNOTE:
1375 CAppUtils::EditNote(pRev);
1376 this->FillLogMessageCtrl(true);
1377 break;
1383 void CLogDlg::OnOK()
1385 // since the log dialog is also used to select revisions for other
1386 // dialogs, we have to do some work before closing this dialog
1387 if (GetFocus() != GetDlgItem(IDOK))
1388 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter
1390 m_LogList.SafeTerminateAsyncDiffThread();
1391 if (this->IsThreadRunning())
1393 m_LogList.SafeTerminateThread();
1395 UpdateData();
1396 // check that one and only one row is selected
1397 if (m_LogList.GetSelectedCount() == 1)
1399 // get the selected row
1400 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1401 int selIndex = m_LogList.GetNextSelectedItem(pos);
1402 if (selIndex < m_LogList.m_arShownList.GetCount())
1404 // all ok, pick up the revision
1405 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
1406 // extract the hash
1407 m_sSelectedHash = pLogEntry->m_CommitHash;
1410 UpdateData(FALSE);
1411 SaveSplitterPos();
1412 __super::OnOK();
1414 #if 0
1415 if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))
1416 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.
1418 CString temp;
1419 CString buttontext;
1420 GetDlgItemText(IDOK, buttontext);
1421 temp.LoadString(IDS_MSGBOX_CANCEL);
1422 if (temp.Compare(buttontext) != 0)
1423 __super::OnOK(); // only exit if the button text matches, and that will match only if the thread isn't running anymore
1424 m_bCancelled = TRUE;
1425 m_selectedRevs.Clear();
1426 m_selectedRevsOneRange.Clear();
1427 if (m_pNotifyWindow)
1429 int selIndex = m_LogList.GetSelectionMark();
1430 if (selIndex >= 0)
1432 PLOGENTRYDATA pLogEntry = NULL;
1433 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1434 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1435 m_selectedRevs.AddRevision(pLogEntry->Rev);
1436 git_revnum_t lowerRev = pLogEntry->Rev;
1437 git_revnum_t higherRev = lowerRev;
1438 while (pos)
1440 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1441 git_revnum_t rev = pLogEntry->Rev;
1442 m_selectedRevs.AddRevision(pLogEntry->Rev);
1443 if (lowerRev > rev)
1444 lowerRev = rev;
1445 if (higherRev < rev)
1446 higherRev = rev;
1448 if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())
1450 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);
1452 BOOL bSentMessage = FALSE;
1453 if (m_LogList.GetSelectedCount() == 1)
1455 // if only one revision is selected, check if the path/url with which the dialog was started
1456 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.
1457 // if it was copied, use the copy from revision as lowerRev
1458 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))
1460 CString sUrl = m_path.GetGitPathString();
1461 if (!m_path.IsUrl())
1463 sUrl = GetURLFromPath(m_path);
1465 sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());
1466 for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)
1468 LogChangedPath * pData = pLogEntry->pArChangedPaths->SafeGetAt(cp);
1469 if (pData)
1471 if (sUrl.Compare(pData->sPath) == 0)
1473 if (!pData->sCopyFromPath.IsEmpty())
1475 lowerRev = pData->lCopyFromRev;
1476 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);
1477 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);
1478 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1479 bSentMessage = TRUE;
1486 if ( !bSentMessage )
1488 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);
1489 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);
1490 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1491 if (m_selectedRevsOneRange.GetCount())
1492 m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);
1496 UpdateData();
1497 CRegDWORD reg(_T("Software\\TortoiseGit\\ShowAllEntry"));
1498 SaveSplitterPos();
1499 #endif
1502 void CLogDlg::DoDiffFromLog(INT_PTR selIndex, GitRev* rev1, GitRev* rev2, bool /*blame*/, bool /*unified*/)
1504 DialogEnableWindow(IDOK, FALSE);
1505 // SetPromptApp(&theApp);
1506 theApp.DoWaitCursor(1);
1508 CString temppath;
1509 GetTempPath(temppath);
1511 CString file1;
1512 file1.Format(_T("%s%s_%s%s"),
1513 temppath,
1514 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1515 rev1->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength()),
1516 (*m_currentChangedArray)[selIndex].GetFileExtension());
1518 CString file2;
1519 file2.Format(_T("%s\\%s_%s%s"),
1520 temppath,
1521 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1522 rev2->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength()),
1523 (*m_currentChangedArray)[selIndex].GetFileExtension());
1525 CString cmd;
1526 CTGitPath &path = (CTGitPath &)(*m_currentChangedArray)[selIndex];
1528 if (g_Git.GetOneFile(rev1->m_CommitHash.ToString(), path, file1))
1530 CString out;
1531 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, path.GetGitPathString(), rev1->m_CommitHash.ToString(), file1);
1532 CMessageBox::Show(nullptr, g_Git.GetGitLastErr(out, CGit::GIT_CMD_GETONEFILE), _T("TortoiseGit"), MB_OK);
1533 theApp.DoWaitCursor(-1);
1534 EnableOKButton();
1535 return;
1537 if (g_Git.GetOneFile(rev2->m_CommitHash.ToString(), path, file2))
1539 CString out;
1540 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, path.GetGitPathString(), rev2->m_CommitHash.ToString(), file2);
1541 CMessageBox::Show(nullptr, g_Git.GetGitLastErr(out, CGit::GIT_CMD_GETONEFILE), _T("TortoiseGit"), MB_OK);
1542 theApp.DoWaitCursor(-1);
1543 EnableOKButton();
1544 return;
1547 CAppUtils::DiffFlags flags;
1548 CAppUtils::StartExtDiff(file1,file2,_T("A"),_T("B"),
1549 g_Git.CombinePath(path), g_Git.CombinePath(path),
1550 rev1->m_CommitHash.ToString(), rev2->m_CommitHash.ToString(),
1551 flags);
1553 theApp.DoWaitCursor(-1);
1554 EnableOKButton();
1557 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)
1559 // Skip Ctrl-C when copying text out of the log message or search filter
1560 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);
1561 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
1563 if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1565 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1567 m_LogList.DiffSelectedRevWithPrevious();
1568 return TRUE;
1571 if (GetFocus() == GetDlgItem(IDC_SEARCHEDIT))
1573 KillTimer(LOGFILTER_TIMER);
1574 m_limit = 0;
1575 m_LogList.Refresh(FALSE);
1576 FillLogMessageCtrl(false);
1578 if (GetFocus() == GetDlgItem(IDC_FILTER))
1580 KillTimer(FILEFILTER_TIMER);
1581 FillLogMessageCtrl();
1582 return TRUE;
1585 else if (pMsg->message == WM_XBUTTONUP)
1587 bool select = (pMsg->wParam & MK_SHIFT) == 0;
1588 if (HIWORD(pMsg->wParam) & XBUTTON1)
1589 GoBackForward(select, false);
1590 if (HIWORD(pMsg->wParam) & XBUTTON2)
1591 GoBackForward(select, true);
1592 if (HIWORD(pMsg->wParam) & (XBUTTON1 | XBUTTON2))
1593 return TRUE;
1595 if (m_hAccel && !bSkipAccelerator)
1597 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1598 if (ret)
1599 return TRUE;
1602 if(::IsWindow(m_tooltips.m_hWnd))
1603 m_tooltips.RelayEvent(pMsg);
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 temp.LoadString(IDS_LOG_FILTER_TOGGLE);
1957 popup.AppendMenu(MF_STRING | MF_ENABLED, LOGFILTER_TOGGLE, temp);
1959 popup.AppendMenu(MF_SEPARATOR, NULL);
1961 temp.LoadString(IDS_LOG_FILTER_REGEX);
1962 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterWithRegex ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_REGEX, temp);
1964 temp.LoadString(IDS_LOG_FILTER_CASESENSITIVE);
1965 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterCaseSensitively ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_CASE, temp);
1967 m_tooltips.Pop();
1968 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1969 if (selection != 0)
1972 if (selection == LOGFILTER_REGEX)
1974 m_bFilterWithRegex = !m_bFilterWithRegex;
1975 CRegDWORD b(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE);
1976 b = m_bFilterWithRegex;
1977 m_LogList.m_bFilterWithRegex = m_bFilterWithRegex;
1978 SetFilterCueText();
1979 CheckRegexpTooltip();
1981 else if (selection == LOGFILTER_CASE)
1983 m_bFilterCaseSensitively = !m_bFilterCaseSensitively;
1984 CRegDWORD b(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE);
1985 b = m_bFilterCaseSensitively;
1986 m_LogList.m_bFilterCaseSensitively = m_bFilterCaseSensitively;
1988 else if (selection == LOGFILTER_TOGGLE)
1990 m_LogList.m_SelectedFilters = (~m_LogList.m_SelectedFilters) & LOGFILTER_ALL;
1991 SetFilterCueText();
1993 else
1995 m_LogList.m_SelectedFilters ^= selection;
1996 SetFilterCueText();
1998 // Reload only if a search text is entered
1999 if (m_LogList.HasFilterText())
2000 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2003 return 0L;
2006 LRESULT CLogDlg::OnClickedCancelFilter(WPARAM wParam, LPARAM /*lParam*/)
2008 if ((HWND)wParam == m_cFileFilter.GetSafeHwnd())
2010 KillTimer(FILEFILTER_TIMER);
2012 FillLogMessageCtrl();
2013 return 0L;
2016 KillTimer(LOGFILTER_TIMER);
2018 m_LogList.m_sFilterText.Empty();
2019 UpdateData(FALSE);
2020 theApp.DoWaitCursor(1);
2021 CStoreSelection storeselection(this);
2022 FillLogMessageCtrl(false);
2024 m_LogList.RemoveFilter();
2026 Refresh();
2028 CTime begin,end;
2029 m_LogList.GetTimeRange(begin,end);
2030 m_DateFrom.SetTime(&begin);
2031 m_DateTo.SetTime(&end);
2033 theApp.DoWaitCursor(-1);
2034 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2035 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2036 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2037 UpdateLogInfoLabel();
2039 return 0L;
2043 void CLogDlg::SetFilterCueText()
2045 CString temp(MAKEINTRESOURCE(IDS_LOG_FILTER_BY));
2046 temp += _T(" ");
2048 if (m_LogList.m_SelectedFilters & LOGFILTER_SUBJECT)
2050 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_SUBJECT));
2053 if (m_LogList.m_SelectedFilters & LOGFILTER_MESSAGES)
2055 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2056 temp += _T(", ");
2057 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_MESSAGES));
2060 if (m_LogList.m_SelectedFilters & LOGFILTER_PATHS)
2062 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2063 temp += _T(", ");
2064 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_PATHS));
2067 if (m_LogList.m_SelectedFilters & LOGFILTER_AUTHORS)
2069 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2070 temp += _T(", ");
2071 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_AUTHORS));
2074 if (m_LogList.m_SelectedFilters & LOGFILTER_EMAILS)
2076 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2077 temp += _T(", ");
2078 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_EMAILS));
2081 if (m_LogList.m_SelectedFilters & LOGFILTER_REVS)
2083 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2084 temp += _T(", ");
2085 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_REVS));
2088 if (m_LogList.m_SelectedFilters & LOGFILTER_REFNAME)
2090 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2091 temp += _T(", ");
2092 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_REFNAME));
2095 if (m_LogList.m_bShowBugtraqColumn && m_LogList.m_SelectedFilters & LOGFILTER_BUGID)
2097 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2098 temp += _T(", ");
2099 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_BUGIDS));
2102 // to make the cue banner text appear more to the right of the edit control
2103 temp = _T(" ")+temp;
2104 m_cFilter.SetCueBanner(temp.TrimRight());
2107 bool CLogDlg::Validate(LPCTSTR string)
2109 if (!m_bFilterWithRegex)
2110 return true;
2111 std::tr1::wregex pat;
2112 return m_LogList.ValidateRegexp(string, pat, false);
2115 void CLogDlg::OnEnChangeFileFilter()
2117 SetTimer(FILEFILTER_TIMER, 1000, NULL);
2120 void CLogDlg::OnTimer(UINT_PTR nIDEvent)
2122 if (nIDEvent == LOGFTIME_TIMER)
2124 KillTimer(LOGFTIME_TIMER);
2125 m_limit = 0;
2126 m_LogList.Refresh(FALSE);
2127 FillLogMessageCtrl(false);
2129 else if (nIDEvent == LOG_FILLPATCHVTIMER)
2131 FillPatchView();
2133 else if (nIDEvent == LOGFILTER_TIMER)
2135 KillTimer(LOGFILTER_TIMER);
2136 m_limit = 0;
2137 m_LogList.Refresh(FALSE);
2138 FillLogMessageCtrl(false);
2140 #if 0
2141 /* we will use git built-in grep to filter log */
2142 if (this->IsThreadRunning())
2144 // thread still running! So just restart the timer.
2145 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2146 return;
2148 CWnd * focusWnd = GetFocus();
2149 bool bSetFocusToFilterControl = ((focusWnd != GetDlgItem(IDC_DATEFROM))&&(focusWnd != GetDlgItem(IDC_DATETO))
2150 && (focusWnd != GetDlgItem(IDC_LOGLIST)));
2151 if (m_LogList.m_sFilterText.IsEmpty())
2153 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2154 // do not return here!
2155 // we also need to run the filter if the filter text is empty:
2156 // 1. to clear an existing filter
2157 // 2. to rebuild the m_arShownList after sorting
2159 theApp.DoWaitCursor(1);
2160 CStoreSelection storeselection(this);
2161 KillTimer(LOGFILTER_TIMER);
2162 FillLogMessageCtrl(false);
2164 // now start filter the log list
2165 m_LogList.StartFilter();
2167 if ( m_LogList.GetItemCount()==1 )
2169 m_LogList.SetSelectionMark(0);
2170 m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
2172 theApp.DoWaitCursor(-1);
2173 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2174 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2175 if (bSetFocusToFilterControl)
2176 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2177 UpdateLogInfoLabel();
2178 #endif
2179 } // if (nIDEvent == LOGFILTER_TIMER)
2180 else if (nIDEvent == LOG_HEADER_ORDER_TIMER)
2182 KillTimer(LOG_HEADER_ORDER_TIMER);
2183 CLogOrdering orderDlg;
2184 if (orderDlg.DoModal() == IDOK)
2185 Refresh();
2187 else if (nIDEvent == FILEFILTER_TIMER)
2189 KillTimer(FILEFILTER_TIMER);
2190 FillLogMessageCtrl();
2192 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC))));
2193 __super::OnTimer(nIDEvent);
2196 void CLogDlg::OnDtnDatetimechangeDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2200 CTime _time;
2201 m_DateTo.GetTime(_time);
2203 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 23, 59, 59);
2204 if (time.GetTime() != m_LogList.m_To)
2206 m_LogList.m_To = (DWORD)time.GetTime();
2207 SetTimer(LOGFTIME_TIMER, 10, NULL);
2210 catch (...)
2212 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2215 *pResult = 0;
2218 void CLogDlg::OnDtnDatetimechangeDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2223 CTime _time;
2224 m_DateFrom.GetTime(_time);
2226 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 0, 0, 0);
2227 if (time.GetTime() != m_LogList.m_From)
2229 m_LogList.m_From = (DWORD)time.GetTime();
2230 SetTimer(LOGFTIME_TIMER, 10, NULL);
2233 catch (...)
2235 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2238 *pResult = 0;
2241 void CLogDlg::OnCbnSelchangeJumpType()
2243 // reserved for future use
2246 void CLogDlg::OnBnClickedJumpUp()
2248 int sel = m_JumpType.GetCurSel();
2249 if (sel < 0) return;
2250 JumpType jumpType = (JumpType)sel;
2252 if (jumpType == JumpType_History)
2254 GoBack();
2255 return;
2258 CString strValue;
2259 CGitHash hashValue;
2260 int index = -1;
2261 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2262 if (pos)
2264 index = m_LogList.GetNextSelectedItem(pos);
2265 if (index == 0) return;
2267 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(index);
2268 if (jumpType == JumpType_AuthorEmail)
2269 strValue = data->GetAuthorEmail();
2270 else if (jumpType == JumpType_CommitterEmail)
2271 strValue = data->GetCommitterEmail();
2272 else if (jumpType == JumpType_Parent1)
2273 hashValue = data->m_CommitHash;
2274 else if (jumpType == JumpType_Parent2)
2275 hashValue = data->m_CommitHash;
2276 else if (jumpType == JumpType_TagFF)
2277 hashValue = data->m_CommitHash;
2278 else if (jumpType == JumpType_BranchFF)
2279 hashValue = data->m_CommitHash;
2281 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2283 else
2284 return;
2286 while (pos)
2288 index = m_LogList.GetNextSelectedItem(pos);
2289 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2291 m_LogList.SetSelectionMark(-1);
2293 for (int i = index - 1; i >= 0; i--)
2295 bool found = false;
2296 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(i);
2297 if (jumpType == JumpType_AuthorEmail)
2298 found = strValue == data->GetAuthorEmail();
2299 else if (jumpType == JumpType_CommitterEmail)
2300 found = strValue == data->GetCommitterEmail();
2301 else if (jumpType == JumpType_MergePoint)
2302 found = data->ParentsCount() > 1;
2303 else if (jumpType == JumpType_Parent1)
2305 if (data->m_ParentHash.size() > 0)
2306 found = data->m_ParentHash[0] == hashValue;
2308 else if (jumpType == JumpType_Parent2)
2310 if (data->m_ParentHash.size() > 1)
2311 found = data->m_ParentHash[1] == hashValue;
2313 else if (jumpType == JumpType_Tag || jumpType == JumpType_TagFF)
2315 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2316 for (size_t j = 0; j < refList.size(); ++j)
2318 if (refList[j].Left(10) == _T("refs/tags/"))
2320 found = true;
2321 break;
2325 if (found && jumpType == JumpType_TagFF)
2326 found = g_Git.IsFastForward(hashValue, data->m_CommitHash);
2328 else if (jumpType == JumpType_Branch || jumpType == JumpType_BranchFF)
2330 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2331 for (size_t j = 0; j < refList.size(); ++j)
2333 if (refList[j].Left(11) == _T("refs/heads/") || refList[j].Left(13) == _T("refs/remotes/"))
2335 found = true;
2336 break;
2340 if (found && jumpType == JumpType_BranchFF)
2341 found = g_Git.IsFastForward(hashValue, data->m_CommitHash);
2344 if (found)
2346 m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2347 m_LogList.EnsureVisible(i, FALSE);
2348 m_LogList.SetSelectionMark(i);
2349 return;
2353 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_LOG_JUMPNOTFOUND, IDS_APPNAME, 1, IDI_INFORMATION, IDS_OKBUTTON, 0, 0, _T("NoJumpNotFoundWarning"), IDS_MSGBOX_DONOTSHOWAGAIN);
2356 void CLogDlg::OnBnClickedJumpDown()
2358 int jumpType = m_JumpType.GetCurSel();
2359 if (jumpType < 0) return;
2361 if (jumpType == JumpType_History)
2363 GoForward();
2364 return;
2367 CString strValue;
2368 CGitHash hashValue;
2369 int index = -1;
2370 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2371 if (pos)
2373 index = m_LogList.GetNextSelectedItem(pos);
2374 if (index == 0) return;
2376 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(index);
2377 if (jumpType == JumpType_AuthorEmail)
2378 strValue = data->GetAuthorEmail();
2379 else if (jumpType == JumpType_CommitterEmail)
2380 strValue = data->GetCommitterEmail();
2381 else if (jumpType == JumpType_Parent1)
2383 if (data->m_ParentHash.size() > 0)
2384 hashValue = data->m_ParentHash.at(0);
2385 else
2386 return;
2388 else if (jumpType == JumpType_Parent2)
2390 if (data->m_ParentHash.size() > 1)
2391 hashValue = data->m_ParentHash.at(1);
2392 else
2393 return;
2395 else if (jumpType == JumpType_TagFF)
2396 hashValue = data->m_CommitHash;
2397 else if (jumpType == JumpType_BranchFF)
2398 hashValue = data->m_CommitHash;
2400 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2402 else
2403 return;
2405 while (pos)
2407 index = m_LogList.GetNextSelectedItem(pos);
2408 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2410 m_LogList.SetSelectionMark(-1);
2412 for (int i = index + 1; i < m_LogList.GetItemCount(); ++i)
2414 bool found = false;
2415 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(i);
2416 if (jumpType == JumpType_AuthorEmail)
2417 found = strValue == data->GetAuthorEmail();
2418 else if (jumpType == JumpType_CommitterEmail)
2419 found = strValue == data->GetCommitterEmail();
2420 else if (jumpType == JumpType_MergePoint)
2421 found = data->ParentsCount() > 1;
2422 else if (jumpType == JumpType_Parent1)
2423 found = data->m_CommitHash == hashValue;
2424 else if (jumpType == JumpType_Parent2)
2425 found = data->m_CommitHash == hashValue;
2426 else if (jumpType == JumpType_Tag || jumpType == JumpType_TagFF)
2428 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2429 for (size_t j = 0; j < refList.size(); ++j)
2431 if (refList[j].Left(10) == _T("refs/tags/"))
2433 found = true;
2434 break;
2438 if (found && jumpType == JumpType_TagFF)
2439 found = g_Git.IsFastForward(data->m_CommitHash, hashValue);
2441 else if (jumpType == JumpType_Branch || jumpType == JumpType_BranchFF)
2443 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2444 for (size_t j = 0; j < refList.size(); ++j)
2446 if (refList[j].Left(11) == _T("refs/heads/") || refList[j].Left(13) == _T("refs/remotes/"))
2448 found = true;
2449 break;
2453 if (found && jumpType == JumpType_BranchFF)
2454 found = g_Git.IsFastForward(data->m_CommitHash, hashValue);
2457 if (found)
2459 m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2460 m_LogList.EnsureVisible(i, FALSE);
2461 m_LogList.SetSelectionMark(i);
2462 return;
2466 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_LOG_JUMPNOTFOUND, IDS_APPNAME, 1, IDI_INFORMATION, IDS_OKBUTTON, 0, 0, _T("NoJumpNotFoundWarning"), IDS_MSGBOX_DONOTSHOWAGAIN);
2469 CTGitPathList CLogDlg::GetChangedPathsFromSelectedRevisions(bool /*bRelativePaths*/ /* = false */, bool /*bUseFilter*/ /* = true */)
2471 CTGitPathList pathList;
2472 #if 0
2474 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2476 m_sRepositoryRoot = GetRepositoryRoot(m_path);
2478 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2479 return pathList;
2481 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2482 if (pos != NULL)
2484 while (pos)
2486 int nextpos = m_LogList.GetNextSelectedItem(pos);
2487 if (nextpos >= m_arShownList.GetCount())
2488 continue;
2489 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(nextpos));
2490 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2491 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
2493 LogChangedPath * cpath = cpatharray->SafeGetAt(cpPathIndex);
2494 if (cpath == NULL)
2495 continue;
2496 CTGitPath path;
2497 if (!bRelativePaths)
2498 path.SetFromGit(m_sRepositoryRoot);
2499 path.AppendPathString(cpath->sPath);
2500 if ((!bUseFilter)||
2501 ((m_cHidePaths.GetState() & 0x0003)!=BST_CHECKED)||
2502 (cpath->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0))
2503 pathList.AddPath(path);
2508 pathList.RemoveDuplicates();
2509 #endif
2510 return pathList;
2513 void CLogDlg::SortByColumn(int /*nSortColumn*/, bool /*bAscending*/)
2515 #if 0
2516 switch(nSortColumn)
2518 case 0: // Revision
2520 if(bAscending)
2521 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscRevSort());
2522 else
2523 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescRevSort());
2525 break;
2526 case 1: // action
2528 if(bAscending)
2529 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscActionSort());
2530 else
2531 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescActionSort());
2533 break;
2534 case 2: // Author
2536 if(bAscending)
2537 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscAuthorSort());
2538 else
2539 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescAuthorSort());
2541 break;
2542 case 3: // Date
2544 if(bAscending)
2545 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscDateSort());
2546 else
2547 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescDateSort());
2549 break;
2550 case 4: // Message or bug id
2551 if (m_bShowBugtraqColumn)
2553 if(bAscending)
2554 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscBugIDSort());
2555 else
2556 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescBugIDSort());
2557 break;
2559 // fall through here
2560 case 5: // Message
2562 if(bAscending)
2563 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscMessageSort());
2564 else
2565 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescMessageSort());
2567 break;
2568 default:
2569 ATLASSERT(0);
2570 break;
2572 #endif
2575 void CLogDlg::OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult)
2577 if (this->IsThreadRunning())
2578 return; //no sorting while the arrays are filled
2579 #if 0
2580 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2581 const int nColumn = pNMLV->iSubItem;
2582 m_bAscending = nColumn == m_nSortColumn ? !m_bAscending : TRUE;
2583 m_nSortColumn = nColumn;
2584 SortByColumn(m_nSortColumn, m_bAscending);
2585 SetSortArrow(&m_LogList, m_nSortColumn, !!m_bAscending);
2586 SortShownListArray();
2587 m_LogList.Invalidate();
2588 UpdateLogInfoLabel();
2589 #else
2590 UNREFERENCED_PARAMETER(pNMHDR);
2591 #endif
2592 *pResult = 0;
2594 SetTimer(LOG_HEADER_ORDER_TIMER, 10, nullptr);
2597 void CLogDlg::SortShownListArray()
2599 // make sure the shown list still matches the filter after sorting.
2600 OnTimer(LOGFILTER_TIMER);
2601 // clear the selection states
2602 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2603 while (pos)
2605 m_LogList.SetItemState(m_LogList.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
2607 m_LogList.SetSelectionMark(-1);
2610 void CLogDlg::SetSortArrow(CListCtrl * control, int nColumn, bool bAscending)
2612 if (control == NULL)
2613 return;
2614 // set the sort arrow
2615 CHeaderCtrl * pHeader = control->GetHeaderCtrl();
2616 HDITEM HeaderItem = {0};
2617 HeaderItem.mask = HDI_FORMAT;
2618 for (int i=0; i<pHeader->GetItemCount(); ++i)
2620 pHeader->GetItem(i, &HeaderItem);
2621 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
2622 pHeader->SetItem(i, &HeaderItem);
2624 if (nColumn >= 0)
2626 pHeader->GetItem(nColumn, &HeaderItem);
2627 HeaderItem.fmt |= (bAscending ? HDF_SORTUP : HDF_SORTDOWN);
2628 pHeader->SetItem(nColumn, &HeaderItem);
2632 int CLogDlg::m_nSortColumnPathList = 0;
2633 bool CLogDlg::m_bAscendingPathList = false;
2635 void CLogDlg::OnBnClickedHidepaths()
2637 FillLogMessageCtrl();
2638 m_ChangedFileListCtrl.Invalidate();
2641 void CLogDlg::UpdateLogInfoLabel()
2644 CGitHash rev1 ;
2645 CGitHash rev2 ;
2646 long selectedrevs = 0;
2647 long selectedfiles = 0;
2648 int count = (int)m_LogList.m_arShownList.GetCount();
2649 int start = 0;
2650 if (count)
2652 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(0)))->m_CommitHash;
2653 if(this->m_LogList.m_bShowWC && rev1.IsEmpty()&&(count>1))
2654 start = 1;
2655 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(start)))->m_CommitHash;
2656 //pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_arShownList.GetCount()-1));
2657 rev2 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(count-1)))->m_CommitHash;
2658 selectedrevs = m_LogList.GetSelectedCount();
2659 if (selectedrevs)
2660 selectedfiles = m_ChangedFileListCtrl.GetSelectedCount();
2662 CString sTemp;
2663 sTemp.Format(IDS_PROC_LOG_STATS,
2664 count - start,
2665 rev2.ToString().Left(g_Git.GetShortHASHLength()), rev1.ToString().Left(g_Git.GetShortHASHLength()), selectedrevs, selectedfiles);
2667 if(selectedrevs == 1)
2669 CString str=m_ChangedFileListCtrl.GetStatisticsString(true);
2670 str.Replace(_T('\n'), _T(' '));
2671 sTemp += _T("\r\n") + str;
2673 m_sLogInfo = sTemp;
2675 UpdateData(FALSE);
2678 void CLogDlg::OnDtnDropdownDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2680 // the date control should not show the "today" button
2681 CMonthCalCtrl * pCtrl = m_DateFrom.GetMonthCalCtrl();
2682 if (pCtrl)
2683 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
2684 *pResult = 0;
2687 void CLogDlg::OnDtnDropdownDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2689 // the date control should not show the "today" button
2690 CMonthCalCtrl * pCtrl = m_DateTo.GetMonthCalCtrl();
2691 if (pCtrl)
2692 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
2693 *pResult = 0;
2696 void CLogDlg::OnSize(UINT nType, int cx, int cy)
2698 __super::OnSize(nType, cx, cy);
2699 //set range
2700 SetSplitterRange();
2703 void CLogDlg::OnRefresh()
2706 m_limit = 0;
2707 this->m_LogProgress.SetPos(0);
2709 Refresh (false);
2713 void CLogDlg::OnFocusFilter()
2715 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2718 void CLogDlg::OnEditCopy()
2720 if (GetFocus() == &m_ChangedFileListCtrl)
2721 CopyChangedSelectionToClipBoard();
2722 else
2723 m_LogList.CopySelectionToClipBoard();
2726 CString CLogDlg::GetAbsoluteUrlFromRelativeUrl(const CString& url)
2728 // is the URL a relative one?
2729 if (url.Left(2).Compare(_T("^/")) == 0)
2731 // URL is relative to the repository root
2732 CString url1 = m_sRepositoryRoot + url.Mid(1);
2733 TCHAR buf[INTERNET_MAX_URL_LENGTH] = { 0 };
2734 DWORD len = url.GetLength();
2735 if (UrlCanonicalize((LPCTSTR)url1, buf, &len, 0) == S_OK)
2736 return CString(buf, len);
2737 return url1;
2739 else if (url[0] == '/')
2741 // URL is relative to the server's hostname
2742 CString sHost;
2743 // find the server's hostname
2744 int schemepos = m_sRepositoryRoot.Find(_T("//"));
2745 if (schemepos >= 0)
2747 sHost = m_sRepositoryRoot.Left(m_sRepositoryRoot.Find('/', schemepos+3));
2748 CString url1 = sHost + url;
2749 TCHAR buf[INTERNET_MAX_URL_LENGTH] = { 0 };
2750 DWORD len = url.GetLength();
2751 if (UrlCanonicalize((LPCTSTR)url, buf, &len, 0) == S_OK)
2752 return CString(buf, len);
2753 return url1;
2756 return url;
2759 void CLogDlg::ShowGravatar()
2761 m_gravatar.EnableGravatar(m_bShowGravatar);
2762 RemoveAnchor(IDC_MSGVIEW);
2763 if (m_gravatar.IsGravatarEnabled())
2765 RECT rect, rect2;
2766 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(&rect);
2767 ScreenToClient(&rect);
2768 m_gravatar.GetWindowRect(&rect2);
2769 ScreenToClient(&rect2);
2770 rect.right = rect2.left;
2771 GetDlgItem(IDC_MSGVIEW)->MoveWindow(&rect);
2772 m_gravatar.ShowWindow(SW_SHOW);
2774 else
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.right;
2782 GetDlgItem(IDC_MSGVIEW)->MoveWindow(&rect);
2783 m_gravatar.ShowWindow(SW_HIDE);
2785 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
2789 void CLogDlg::OnEnChangeSearchedit()
2791 UpdateData();
2792 if (!m_LogList.HasFilterText())
2794 CStoreSelection storeselection(this);
2795 // clear the filter, i.e. make all entries appear
2796 theApp.DoWaitCursor(1);
2797 KillTimer(LOGFILTER_TIMER);
2798 FillLogMessageCtrl(false);
2800 Refresh();
2801 //m_LogList.StartFilter();
2802 #if 0
2803 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2804 m_arShownList.RemoveAll();
2805 for (DWORD i=0; i<m_logEntries.size(); ++i)
2807 if (IsEntryInDateRange(i))
2808 m_arShownList.Add(m_logEntries[i]);
2810 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2811 m_LogList.DeleteAllItems();
2812 m_LogList.SetItemCountEx(ShownCountWithStopped());
2813 m_LogList.RedrawItems(0, ShownCountWithStopped());
2814 m_LogList.SetRedraw(false);
2815 ResizeAllListCtrlCols();
2816 m_LogList.SetRedraw(true);
2817 #endif
2818 theApp.DoWaitCursor(-1);
2819 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2820 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2821 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2822 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2823 return;
2825 if (Validate(m_LogList.m_sFilterText))
2826 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2827 else
2828 KillTimer(LOGFILTER_TIMER);
2832 void CLogDlg::OnBnClickedAllBranch()
2834 // m_bAllBranch is not auto-toggled by MFC, we have to handle it manually (in order to prevent the indeterminate state)
2836 m_LogList.m_ShowMask &=~ (CGit::LOG_INFO_LOCAL_BRANCHES | CGit::LOG_INFO_ALL_BRANCH);
2838 if (m_bAllBranch)
2840 m_bAllBranch = BST_UNCHECKED;
2841 m_ChangedFileListCtrl.m_sDisplayedBranch = m_LogList.GetRange();
2843 else
2845 m_bAllBranch = BST_CHECKED;
2846 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
2847 m_ChangedFileListCtrl.m_sDisplayedBranch.Empty();
2850 // need to save value here, so that log dialogs started from now on also have AllBranch activated
2851 m_regbAllBranch = m_bAllBranch;
2853 UpdateData(FALSE);
2855 OnRefresh();
2857 FillLogMessageCtrl(false);
2860 void CLogDlg::OnBnClickedFollowRenames()
2862 if(m_bFollowRenames)
2864 m_LogList.m_ShowMask |= CGit::LOG_INFO_FOLLOW;
2865 m_LogList.m_ShowMask &=~ CGit::LOG_INFO_LOCAL_BRANCHES;
2866 if (m_bAllBranch)
2869 m_bAllBranch = FALSE;
2870 m_LogList.m_ShowMask &=~ CGit::LOG_INFO_ALL_BRANCH;
2874 else
2875 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_FOLLOW;
2877 DialogEnableWindow(IDC_LOG_ALLBRANCH, !m_bFollowRenames);
2878 DialogEnableWindow(IDC_SHOWWHOLEPROJECT, !m_bFollowRenames && !m_path.IsEmpty());
2880 OnRefresh();
2882 FillLogMessageCtrl(false);
2885 void CLogDlg::HandleShowLabels(bool var, int flag)
2887 if (var)
2888 m_LogList.m_ShowRefMask |= flag;
2889 else
2890 m_LogList.m_ShowRefMask &= ~flag;
2892 if ((m_LogList.m_ShowFilter & CGitLogListBase::FILTERSHOW_REFS) && !(m_LogList.m_ShowFilter & CGitLogListBase::FILTERSHOW_ANYCOMMIT))
2894 // Remove commits where labels are not shown.
2895 OnRefresh();
2896 FillLogMessageCtrl(false);
2898 else
2900 // Just redraw
2901 m_LogList.Invalidate();
2905 void CLogDlg::OnBnClickedCompressedGraph()
2907 UpdateData();
2909 if (m_iCompressedGraph == 2)
2910 m_LogList.m_ShowFilter = CGitLogListBase::FILTERSHOW_REFS;
2911 else if (m_iCompressedGraph == 1)
2912 m_LogList.m_ShowFilter = static_cast<CGitLogListBase::FilterShow>(CGitLogListBase::FILTERSHOW_REFS | CGitLogListBase::FILTERSHOW_MERGEPOINTS);
2913 else
2914 m_LogList.m_ShowFilter = CGitLogListBase::FILTERSHOW_ALL;
2916 OnRefresh();
2917 FillLogMessageCtrl(false);
2920 void CLogDlg::OnBnClickedBrowseRef()
2922 CString newRef = CBrowseRefsDlg::PickRef(false, m_LogList.GetRange(), gPickRef_All, true);
2923 if(newRef.IsEmpty())
2924 return;
2926 m_History.AddEntry(newRef);
2927 m_History.Save();
2929 SetRange(newRef);
2931 m_LogList.m_ShowMask &= ~(CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES);
2932 m_bAllBranch = BST_UNCHECKED;
2933 UpdateData(FALSE);
2935 OnRefresh();
2936 FillLogMessageCtrl(false);
2939 void CLogDlg::ShowStartRef()
2941 //Show ref name on top
2942 if(!::IsWindow(m_hWnd))
2943 return;
2944 if (m_LogList.m_ShowMask & (CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES))
2946 switch (m_LogList.m_ShowMask & (CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES))
2948 case CGit::LOG_INFO_ALL_BRANCH:
2949 m_staticRef.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_LOG_ALLBRANCHES)));
2950 break;
2952 case CGit::LOG_INFO_LOCAL_BRANCHES:
2953 m_staticRef.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_LOG_LOCAL_BRANCHES)));
2954 break;
2957 m_staticRef.Invalidate(TRUE);
2958 m_tooltips.DelTool(GetDlgItem(IDC_STATIC_REF));
2959 return;
2962 CString showStartRef = m_LogList.GetRange();
2963 if (showStartRef.IsEmpty() || showStartRef == _T("HEAD"))
2965 showStartRef.Empty();
2966 //Ref name is HEAD
2967 if (g_Git.Run(L"git.exe symbolic-ref HEAD", &showStartRef, NULL, CP_UTF8))
2968 showStartRef = CString(MAKEINTRESOURCE(IDS_PROC_LOG_NOBRANCH));
2969 showStartRef.Trim(L"\r\n\t ");
2973 showStartRef = g_Git.StripRefName(showStartRef);
2975 m_staticRef.SetWindowText(showStartRef);
2976 CWnd *pWnd = GetDlgItem(IDC_STATIC_REF);
2977 m_tooltips.AddTool(pWnd, showStartRef);
2978 m_staticRef.Invalidate(TRUE);
2981 void CLogDlg::SetRange(const CString& range)
2983 m_LogList.SetRange(range);
2984 m_ChangedFileListCtrl.m_sDisplayedBranch = range;
2986 ShowStartRef();
2989 static void AppendMenuChecked(CMenu &menu, UINT nTextID, UINT_PTR nItemID, BOOL checked = FALSE, BOOL enabled = TRUE)
2991 CString text;
2992 text.LoadString(nTextID);
2993 menu.AppendMenu(MF_STRING | (enabled ? MF_ENABLED : MF_DISABLED) | (checked ? MF_CHECKED : MF_UNCHECKED), nItemID, text);
2996 #define WALKBEHAVIOUR_FIRSTPARENT 1
2997 #define WALKBEHAVIOUR_FOLLOWRENAMES 2
2998 #define WALKBEHAVIOUR_COMPRESSEDGRAPH 3
2999 #define WALKBEHAVIOUR_LABELEDCOMMITS 4
3000 #define WALKBEHAVIOUR_NOMERGES 5
3002 void CLogDlg::OnBnClickedWalkBehaviour()
3004 CMenu popup;
3005 if (popup.CreatePopupMenu())
3007 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_FIRSTPARENT, WALKBEHAVIOUR_FIRSTPARENT, m_bFirstParent);
3008 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_NOMERGES, WALKBEHAVIOUR_NOMERGES, m_bNoMerges);
3009 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_FOLLOWRENAMES, WALKBEHAVIOUR_FOLLOWRENAMES, m_bFollowRenames, !(m_path.IsEmpty() || m_path.IsDirectory()));
3010 popup.AppendMenu(MF_SEPARATOR, NULL);
3011 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_COMPRESSED, WALKBEHAVIOUR_COMPRESSEDGRAPH, m_iCompressedGraph == 1);
3012 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_LABELEDCOMMITS, WALKBEHAVIOUR_LABELEDCOMMITS, m_iCompressedGraph == 2);
3014 m_tooltips.Pop();
3015 RECT rect;
3016 GetDlgItem(IDC_WALKBEHAVIOUR)->GetWindowRect(&rect);
3017 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, rect.left, rect.top, this, 0);
3018 switch (selection)
3020 case WALKBEHAVIOUR_FIRSTPARENT:
3021 m_bFirstParent = !m_bFirstParent;
3022 OnBnClickedFirstParent();
3023 break;
3024 case WALKBEHAVIOUR_NOMERGES:
3025 m_bNoMerges = !m_bNoMerges;
3026 OnBnClickedFirstParent(); // OnBnClickedFirstParent handles both cases: m_bFirstParent and m_bNoMerges
3027 break;
3028 case WALKBEHAVIOUR_FOLLOWRENAMES:
3029 m_bFollowRenames = !m_bFollowRenames;
3030 OnBnClickedFollowRenames();
3031 break;
3032 case WALKBEHAVIOUR_COMPRESSEDGRAPH:
3033 m_iCompressedGraph = (m_iCompressedGraph == 1 ? 0 : 1);
3034 OnBnClickedCompressedGraph();
3035 break;
3036 case WALKBEHAVIOUR_LABELEDCOMMITS:
3037 m_iCompressedGraph = (m_iCompressedGraph == 2 ? 0 : 2);
3038 OnBnClickedCompressedGraph();
3039 break;
3040 default:
3041 break;
3043 m_bWalkBehavior = (m_bFirstParent || m_bNoMerges || m_bFollowRenames || m_iCompressedGraph);
3044 UpdateData(FALSE);
3048 #define VIEW_HIDEPATHS 1
3049 #define VIEW_GRAYPATHS 2
3050 #define VIEW_SHOWTAGS 3
3051 #define VIEW_SHOWLOCALBRANCHES 4
3052 #define VIEW_SHOWREMOTEBRANCHES 5
3053 #define VIEW_SHOWGRAVATAR 6
3054 #define VIEW_SHOWPATCH 7
3056 void CLogDlg::OnBnClickedView()
3058 CMenu popup;
3059 if (popup.CreatePopupMenu())
3061 AppendMenuChecked(popup, IDS_SHOWFILES_HIDEPATHS, VIEW_HIDEPATHS, m_iHidePaths == 1);
3062 AppendMenuChecked(popup, IDS_SHOWFILES_GRAYPATHS, VIEW_GRAYPATHS, m_iHidePaths == 2);
3063 popup.AppendMenu(MF_SEPARATOR, NULL);
3064 CMenu showLabelsMenu;
3065 if (showLabelsMenu.CreatePopupMenu())
3067 AppendMenuChecked(showLabelsMenu, IDS_VIEW_SHOWTAGLABELS, VIEW_SHOWTAGS, m_bShowTags);
3068 AppendMenuChecked(showLabelsMenu, IDS_VIEW_SHOWLOCALBRANCHLABELS, VIEW_SHOWLOCALBRANCHES, m_bShowLocalBranches);
3069 AppendMenuChecked(showLabelsMenu, IDS_VIEW_SHOWREMOTEBRANCHLABELS, VIEW_SHOWREMOTEBRANCHES, m_bShowRemoteBranches);
3070 popup.AppendMenu(MF_STRING | MF_POPUP, (UINT)showLabelsMenu.m_hMenu, (CString)MAKEINTRESOURCE(IDS_VIEW_LABELS));
3072 popup.AppendMenu(MF_SEPARATOR, NULL);
3073 AppendMenuChecked(popup, IDS_VIEW_SHOWGRAVATAR, VIEW_SHOWGRAVATAR, m_bShowGravatar);
3074 AppendMenuChecked(popup, IDS_MENU_VIEWPATCH, VIEW_SHOWPATCH, IsWindow(this->m_patchViewdlg.m_hWnd));
3076 m_tooltips.Pop();
3077 RECT rect;
3078 GetDlgItem(IDC_VIEW)->GetWindowRect(&rect);
3079 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, rect.left, rect.top, this, 0);
3080 switch (selection)
3082 case VIEW_HIDEPATHS:
3083 if (m_iHidePaths == 1)
3084 m_iHidePaths = 0;
3085 else
3086 m_iHidePaths = 1;
3087 OnBnClickedHidepaths();
3088 break;
3089 case VIEW_GRAYPATHS:
3090 if (m_iHidePaths == 2)
3091 m_iHidePaths = 0;
3092 else
3093 m_iHidePaths = 2;
3094 OnBnClickedHidepaths();
3095 break;
3096 case VIEW_SHOWTAGS:
3097 m_bShowTags = !m_bShowTags;
3098 HandleShowLabels(m_bShowTags, LOGLIST_SHOWTAGS);
3099 break;
3100 case VIEW_SHOWLOCALBRANCHES:
3101 m_bShowLocalBranches = !m_bShowLocalBranches;
3102 HandleShowLabels(m_bShowLocalBranches, LOGLIST_SHOWLOCALBRANCHES);
3103 break;
3104 case VIEW_SHOWREMOTEBRANCHES:
3105 m_bShowRemoteBranches = !m_bShowRemoteBranches;
3106 HandleShowLabels(m_bShowRemoteBranches, LOGLIST_SHOWREMOTEBRANCHES);
3107 break;
3108 case VIEW_SHOWGRAVATAR:
3110 m_bShowGravatar = !m_bShowGravatar;
3111 ShowGravatar();
3112 m_gravatar.Init();
3113 CString email;
3114 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
3115 if (pos)
3117 int selIndex = m_LogList.GetNextSelectedItem(pos);
3118 int moreSel = m_LogList.GetNextSelectedItem(pos);
3119 if (moreSel < 0)
3121 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
3122 if (pLogEntry)
3123 email = pLogEntry->GetAuthorEmail();
3126 m_gravatar.LoadGravatar(email);
3127 break;
3129 case VIEW_SHOWPATCH:
3130 TogglePatchView();
3131 break;
3132 default:
3133 break;
3138 void CLogDlg::OnBnClickedFirstParent()
3140 if(this->m_bFirstParent)
3141 m_LogList.m_ShowMask|=CGit::LOG_INFO_FIRST_PARENT;
3142 else
3143 m_LogList.m_ShowMask&=~CGit::LOG_INFO_FIRST_PARENT;
3145 if (m_bNoMerges)
3146 m_LogList.m_ShowMask |= CGit::LOG_INFO_NO_MERGE;
3147 else
3148 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_NO_MERGE;
3150 OnRefresh();
3152 FillLogMessageCtrl(false);
3156 void CLogDlg::OnBnClickShowWholeProject()
3158 this->UpdateData();
3160 if(this->m_bWholeProject)
3162 m_LogList.m_Path.Reset();
3163 SetDlgTitle();
3165 else
3166 m_LogList.m_Path=m_path;
3168 m_regShowWholeProject = m_bWholeProject;
3170 SetDlgTitle();
3172 OnRefresh();
3174 FillLogMessageCtrl(false);
3178 LRESULT CLogDlg::OnRefLogChanged(WPARAM /*wParam*/, LPARAM /*lParam*/)
3180 ShowStartRef();
3181 return 0;
3184 LRESULT CLogDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
3186 m_pTaskbarList.Release();
3187 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
3188 SetUUIDOverlayIcon(m_hWnd);
3189 return 0;
3192 LRESULT CLogDlg::OnRefreshSelection(WPARAM /*wParam*/, LPARAM /*lParam*/)
3194 // it's enough to deselect, then select again one item of the whole selection
3195 int selMark = m_LogList.GetSelectionMark();
3196 if (selMark >= 0)
3198 m_LogList.SetSelectionMark(selMark);
3199 m_LogList.SetItemState(selMark, 0, LVIS_SELECTED);
3200 m_LogList.SetItemState(selMark, LVIS_SELECTED, LVIS_SELECTED);
3202 return 0;