Fixed issue #2353: Link to bug tracker not available in Show Log dialog
[TortoiseGit.git] / src / TortoiseProc / LogDlg.cpp
blobbcefeec4b2a923a4751bf02c9d0c4da69a4e9f77
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 CHARFORMAT2 format;
775 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
776 format.cbSize = sizeof(CHARFORMAT2);
777 format.dwMask = CFM_BOLD;
778 format.dwEffects = CFE_BOLD;
779 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
781 CString msg = m_bAsteriskLogPrefix ? _T("* ") : _T("");
782 msg+=pLogEntry->GetSubject();
783 pMsgView->ReplaceSel(msg);
785 pMsgView->SetSel(-1,-1);
786 format.dwEffects = 0;
787 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
789 msg=_T("\n");
790 msg+=pLogEntry->GetBody();
792 if(!pLogEntry->m_Notes.IsEmpty())
794 msg+= _T("\n*") + CString(MAKEINTRESOURCE(IDS_NOTES)) + _T("* ");
795 msg+= pLogEntry->m_Notes;
796 msg+= _T("\n\n");
799 CString tagInfo = m_LogList.GetTagInfo(pLogEntry);
800 if(!tagInfo.IsEmpty())
801 tagInfo = _T("\n*") + CString(MAKEINTRESOURCE(IDS_PROC_LOG_TAGINFO)) + _T("*\n\n") + tagInfo;
802 msg += tagInfo;
804 pMsgView->ReplaceSel(msg);
806 CString text;
807 pMsgView->GetWindowText(text);
808 // the rich edit control doesn't count the CR char!
809 // to be exact: CRLF is treated as one char.
810 text.Remove('\r');
812 int findHashStart = text.Find('\n');
813 if (!out_describe.IsEmpty())
814 findHashStart = text.Find('\n', findHashStart + 1);
815 FindGitHash(text, findHashStart, pMsgView);
816 m_LogList.m_ProjectProperties.FindBugID(text, pMsgView);
817 CAppUtils::StyleURLs(text, pMsgView);
818 if (((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\StyleCommitMessages"), TRUE)) == TRUE)
819 CAppUtils::FormatTextInRichEditControl(pMsgView);
821 CHARRANGE range;
822 range.cpMin = 0;
823 range.cpMax = 0;
824 pMsgView->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
826 CString matchpath=this->m_path.GetGitPathString();
828 bool mightNeedReset = true;
830 int count = pLogEntry->GetFiles(&m_LogList).GetCount();
831 for (int i = 0 ; i < count && (!matchpath.IsEmpty()); ++i)
833 if( m_bWholeProject )
834 break;
836 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action &= ~(CTGitPath::LOGACTIONS_HIDE|CTGitPath::LOGACTIONS_GRAY);
837 mightNeedReset = false;
839 if(pLogEntry->GetFiles(&m_LogList)[i].GetGitPathString().Left(matchpath.GetLength()) != matchpath && pLogEntry->GetFiles(&m_LogList)[i].GetGitOldPathString().Left(matchpath.GetLength()) != matchpath)
841 if (m_iHidePaths == 1)
842 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;
843 else if (m_iHidePaths == 2)
844 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_GRAY;
848 if (mightNeedReset)
850 for (int i = 0 ; i < count; ++i)
851 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action &= ~CTGitPath::LOGACTIONS_HIDE;
854 CString fileFilter;
855 m_cFileFilter.GetWindowText(fileFilter);
856 fileFilter.MakeLower();
857 for (int i = 0; i < count && (!fileFilter.IsEmpty()); ++i)
859 CString sPath = pLogEntry->GetFiles(&m_LogList)[i].GetGitPathString();
860 sPath.MakeLower();
861 if (sPath.Find(fileFilter) < 0)
862 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;
865 m_ChangedFileListCtrl.UpdateWithGitPathList(pLogEntry->GetFiles(&m_LogList));
866 m_ChangedFileListCtrl.m_CurrentVersion=pLogEntry->m_CommitHash;
867 if (pLogEntry->m_CommitHash.IsEmpty() && m_bShowUnversioned)
869 m_ChangedFileListCtrl.UpdateUnRevFileList(pLogEntry->GetUnRevFiles());
870 m_ChangedFileListCtrl.Show(GITSLC_SHOWVERSIONED | GITSLC_SHOWUNVERSIONED);
872 else
873 m_ChangedFileListCtrl.Show(GITSLC_SHOWVERSIONED);
875 m_ChangedFileListCtrl.SetBusyString(CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES)));
877 if(!pLogEntry->m_IsDiffFiles)
878 m_ChangedFileListCtrl.SetBusy(TRUE);
879 else
880 m_ChangedFileListCtrl.SetBusy(FALSE);
882 m_ChangedFileListCtrl.SetRedraw(TRUE);
883 m_gravatar.LoadGravatar(pLogEntry->GetAuthorEmail());
884 return;
888 else
890 // more than one revision is selected:
891 // the log message view must be emptied
892 // the changed files list contains all the changed paths from all
893 // selected revisions, with 'doubles' removed
894 m_currentChangedPathList = GetChangedPathsFromSelectedRevisions(true);
895 m_gravatar.LoadGravatar();
898 // redraw the views
899 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
900 #if 0
901 if (m_currentChangedArray)
903 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedArray->GetCount());
904 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedArray->GetCount());
906 else if (m_currentChangedPathList.GetCount())
908 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedPathList.GetCount());
909 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedPathList.GetCount());
911 else
913 m_ChangedFileListCtrl.SetItemCountEx(0);
914 m_ChangedFileListCtrl.Invalidate();
916 #endif
917 // sort according to the settings
918 if (m_nSortColumnPathList > 0)
919 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
920 else
921 SetSortArrow(&m_ChangedFileListCtrl, -1, false);
922 m_ChangedFileListCtrl.SetRedraw(TRUE);
926 void CLogDlg::FillPatchView(bool onlySetTimer)
928 if (!::IsWindow(this->m_patchViewdlg.m_hWnd))
929 return;
931 KillTimer(LOG_FILLPATCHVTIMER);
932 if (onlySetTimer)
934 SetTimer(LOG_FILLPATCHVTIMER, 100, nullptr);
935 return;
938 POSITION posLogList = m_LogList.GetFirstSelectedItemPosition();
939 if (posLogList == nullptr)
941 m_patchViewdlg.ClearView();
942 return; // nothing is selected, get out of here
945 GitRev * pLogEntry = reinterpret_cast<GitRev* >(m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(posLogList)));
946 if (pLogEntry == nullptr || m_LogList.GetNextSelectedItem(posLogList) != -1)
948 m_patchViewdlg.ClearView();
949 return;
952 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
953 CString out;
955 if (pos == nullptr)
957 int diffContext = 0;
958 if (CAppUtils::GetMsysgitVersion() > 0x01080100)
959 diffContext = g_Git.GetConfigValueInt32(_T("diff.context"), -1);
960 CStringA outA;
961 CString rev1 = pLogEntry->m_CommitHash.IsEmpty() ? _T("HEAD") : (pLogEntry->m_CommitHash.ToString() + _T("~1"));
962 CString rev2 = pLogEntry->m_CommitHash.IsEmpty() ? GIT_REV_ZERO : pLogEntry->m_CommitHash.ToString();
963 g_Git.GetUnifiedDiff(CTGitPath(), rev1, rev2, &outA, false, false, diffContext);
964 out = CUnicodeUtils::GetUnicode(outA);
966 else
968 while (pos)
970 int nSelect = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
971 CTGitPath * p = (CTGitPath*)m_ChangedFileListCtrl.GetItemData(nSelect);
972 if (p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER))
974 CString cmd;
975 if (pLogEntry->m_CommitHash.IsEmpty())
976 cmd.Format(_T("git.exe diff HEAD -- \"%s\""), p->GetGitPathString());
977 else
978 cmd.Format(_T("git.exe diff %s^%d..%s -- \"%s\""), pLogEntry->m_CommitHash.ToString(), p->m_ParentNo + 1, pLogEntry->m_CommitHash.ToString(), p->GetGitPathString());
979 g_Git.Run(cmd, &out, CP_UTF8);
984 m_patchViewdlg.SetText(out);
987 void CLogDlg::TogglePatchView()
989 m_patchViewdlg.m_pProjectProperties = &m_LogList.m_ProjectProperties;
990 m_patchViewdlg.m_ParentDlg = this;
991 if (!IsWindow(m_patchViewdlg.m_hWnd))
993 BOOL viewPatchEnabled = FALSE;
994 viewPatchEnabled = g_Git.GetConfigValueBool(_T("tgit.logshowpatch"));
995 if (viewPatchEnabled == FALSE)
996 g_Git.SetConfigValue(_T("tgit.logshowpatch"), _T("true"));
997 m_patchViewdlg.Create(IDD_PATCH_VIEW, this);
998 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTHTRACKING, TRUE);
999 CRect rect;
1000 this->GetWindowRect(&rect);
1002 m_patchViewdlg.ShowWindow(SW_SHOW);
1003 m_patchViewdlg.SetWindowPos(nullptr, rect.right, rect.top, rect.Width(), rect.Height(), SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
1005 FillPatchView();
1007 else
1009 g_Git.SetConfigValue(_T("tgit.logshowpatch"), _T("false"));
1010 m_patchViewdlg.ShowWindow(SW_HIDE);
1011 m_patchViewdlg.DestroyWindow();
1015 LRESULT CLogDlg::OnFileListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
1017 FillPatchView(true);
1018 return 0;
1021 void CLogDlg::OnMoving(UINT fwSide, LPRECT pRect)
1023 __super::OnMoving(fwSide, pRect);
1025 if (!::IsWindow(m_patchViewdlg.m_hWnd))
1026 return;
1028 RECT patchrect;
1029 m_patchViewdlg.GetWindowRect(&patchrect);
1030 if (!::IsWindow(m_hWnd))
1031 return;
1033 RECT thisrect;
1034 GetWindowRect(&thisrect);
1035 if (patchrect.left == thisrect.right)
1037 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);
1041 void CLogDlg::OnSizing(UINT fwSide, LPRECT pRect)
1043 __super::OnSizing(fwSide, pRect);
1045 if (!::IsWindow(this->m_patchViewdlg.m_hWnd))
1046 return;
1048 CRect thisrect, patchrect;
1049 this->GetWindowRect(thisrect);
1050 this->m_patchViewdlg.GetWindowRect(patchrect);
1051 if (thisrect.right != patchrect.left)
1052 return;
1054 patchrect.left -= (thisrect.right - pRect->right);
1055 patchrect.right -= (thisrect.right - pRect->right);
1057 if (patchrect.bottom == thisrect.bottom)
1058 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
1059 if (patchrect.top == thisrect.top)
1060 patchrect.top -= thisrect.top - pRect->top;
1061 m_patchViewdlg.MoveWindow(patchrect);
1064 void CLogDlg::OnSelectSearchField()
1066 m_cFilter.SetSel(0, -1, FALSE);
1067 m_cFilter.SetFocus();
1070 void CLogDlg::GoBack()
1072 GoBackForward(false, false);
1075 void CLogDlg::GoForward()
1077 GoBackForward(false, true);
1080 void CLogDlg::GoBackAndSelect()
1082 GoBackForward(true, false);
1085 void CLogDlg::GoForwardAndSelect()
1087 GoBackForward(true, true);
1090 void CLogDlg::GoBackForward(bool select, bool bForward)
1092 m_LogList.m_highlight.Empty();
1093 CGitHash gotoHash;
1094 if (bForward ? m_LogList.m_selectionHistory.GoForward(gotoHash) : m_LogList.m_selectionHistory.GoBack(gotoHash))
1096 int i;
1097 for (i = 0; i < m_LogList.m_arShownList.GetCount(); ++i)
1099 GitRev *rev = (GitRev *)m_LogList.m_arShownList.SafeGetAt(i);
1100 if (!rev) continue;
1101 if (rev->m_CommitHash == gotoHash)
1103 m_LogList.EnsureVisible(i, FALSE);
1104 if (select)
1106 m_LogList.m_highlight.Empty();
1107 m_LogList.SetItemState(m_LogList.GetSelectionMark(), 0, LVIS_SELECTED);
1108 m_bNavigatingWithSelect = true;
1109 m_LogList.SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
1110 m_LogList.SetSelectionMark(i);
1111 m_bNavigatingWithSelect = false;
1113 else
1114 m_LogList.m_highlight = gotoHash;
1115 m_LogList.Invalidate();
1116 return;
1119 if (i == m_LogList.m_arShownList.GetCount())
1121 CString msg;
1122 msg.Format(IDS_LOG_NOT_VISIBLE, gotoHash.ToString());
1123 MessageBox(msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1124 return;
1127 PlaySound((LPCTSTR)SND_ALIAS_SYSTEMASTERISK, nullptr, SND_ASYNC | SND_ALIAS_ID);
1130 void CLogDlg::OnBnClickedRefresh()
1132 Refresh (true);
1135 void CLogDlg::Refresh (bool clearfilter /*autoGoOnline*/)
1137 m_limit = 0;
1138 m_LogList.Refresh(clearfilter);
1139 EnableOKButton();
1140 ShowStartRef();
1141 FillLogMessageCtrl(false);
1146 BOOL CLogDlg::Cancel()
1148 return m_bCancelled;
1151 void CLogDlg::SaveSplitterPos()
1153 if (!IsIconic())
1155 CRegDWORD regPos1(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
1156 CRegDWORD regPos2(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
1157 RECT rectSplitter;
1158 m_wndSplitter1.GetWindowRect(&rectSplitter);
1159 ScreenToClient(&rectSplitter);
1160 regPos1 = rectSplitter.top;
1161 m_wndSplitter2.GetWindowRect(&rectSplitter);
1162 ScreenToClient(&rectSplitter);
1163 regPos2 = rectSplitter.top;
1167 void CLogDlg::OnCancel()
1169 this->ShowWindow(SW_HIDE);
1171 // canceling means stopping the working thread if it's still running.
1172 m_LogList.SafeTerminateAsyncDiffThread();
1173 if (this->IsThreadRunning())
1175 m_LogList.SafeTerminateThread();
1177 UpdateData();
1179 SaveSplitterPos();
1180 __super::OnCancel();
1183 void CLogDlg::CopyChangedSelectionToClipBoard()
1186 POSITION posLogList = m_LogList.GetFirstSelectedItemPosition();
1187 if (posLogList == nullptr)
1188 return; // nothing is selected, get out of here
1190 CString sPaths;
1192 // CGitRev* pLogEntry = reinterpret_cast<CGitRev* >(m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1193 // if (posLogList)
1195 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
1196 while (pos)
1198 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
1199 CTGitPath *path = (CTGitPath*)m_ChangedFileListCtrl.GetItemData(nItem);
1200 if(path)
1201 sPaths += path->GetGitPathString();
1202 sPaths += _T("\r\n");
1205 #if 0
1206 else
1208 // only one revision is selected in the log dialog top pane
1209 // but multiple items could be selected in the changed items list
1210 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
1211 while (pos)
1213 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
1214 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(nItem);
1216 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
1218 // some items are hidden! So find out which item the user really selected
1219 INT_PTR selRealIndex = -1;
1220 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
1222 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1223 ++selRealIndex;
1224 if (selRealIndex == nItem)
1226 changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex);
1227 break;
1231 if (changedlogpath)
1233 sPaths += changedlogpath->sPath;
1234 sPaths += _T("\r\n");
1238 #endif
1239 sPaths.Trim();
1240 CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());
1244 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)
1246 // we have three separate context menus:
1247 // one for the branch label in the upper left
1248 // one shown on the log message list control,
1249 // one shown in the changed-files list control
1250 if (pWnd == GetDlgItem(IDC_STATIC_REF))
1252 CIconMenu popup;
1253 if (!popup.CreatePopupMenu())
1254 return;
1256 int cnt = 0;
1257 popup.AppendMenuIcon(++cnt, IDS_MENUREFBROWSE);
1258 popup.SetDefaultItem(cnt);
1259 popup.AppendMenuIcon(++cnt, _T("HEAD"));
1260 CGitHash fetchHead;
1261 g_Git.GetHash(fetchHead, g_Git.FixBranchName(_T("FETCH_HEAD")));
1262 popup.AppendMenuIcon(++cnt, _T("FETCH_HEAD"));
1263 popup.EnableMenuItem(cnt, fetchHead.IsEmpty());
1264 popup.AppendMenuIcon(++cnt, IDS_ALL);
1265 popup.EnableMenuItem(cnt, m_bFollowRenames);
1266 popup.AppendMenuIcon(++cnt, IDS_PROC_LOG_SELECT_LOCAL_BRANCHES);
1267 popup.EnableMenuItem(cnt, m_bFollowRenames);
1268 int offset = ++cnt;
1269 if (m_History.GetCount() > 0)
1271 popup.AppendMenu(MF_SEPARATOR, 0);
1272 for (size_t i = 0; i < m_History.GetCount(); ++i)
1274 CString entry = m_History.GetEntry(i);
1275 if (entry.GetLength() > 150)
1276 entry = entry.Left(150) + _T("...");
1277 popup.AppendMenuIcon(cnt++, entry);
1281 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1282 if (cmd == 0)
1283 return;
1284 else if (cmd == 1)
1286 OnBnClickedBrowseRef();
1287 return;
1290 m_LogList.m_ShowMask &= ~(CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES);
1291 m_bAllBranch = BST_UNCHECKED;
1292 if (cmd == 2)
1294 SetRange(g_Git.GetCurrentBranch(true));
1296 else if (cmd == 3)
1298 SetRange(fetchHead.ToString());
1300 else if (cmd == 4)
1302 m_bAllBranch = BST_CHECKED;
1303 m_LogList.m_ShowMask |= CGit::LOG_INFO_ALL_BRANCH;
1305 else if (cmd == 5)
1307 m_bAllBranch = BST_INDETERMINATE;
1308 m_LogList.m_ShowMask |= CGit::LOG_INFO_LOCAL_BRANCHES;
1310 else if (cmd >= offset)
1312 SetRange(m_History.GetEntry(cmd - offset));
1313 m_History.AddEntry(m_LogList.m_sRange);
1314 m_History.Save();
1317 UpdateData(FALSE);
1319 OnRefresh();
1320 FillLogMessageCtrl(false);
1322 return;
1324 int selCount = m_LogList.GetSelectedCount();
1325 if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))
1327 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1328 int selIndex = -1;
1329 if (pos)
1330 selIndex = m_LogList.GetNextSelectedItem(pos);
1332 GitRev *pRev = ((GitRev*)m_LogList.m_arShownList[selIndex]);
1334 if ((point.x == -1) && (point.y == -1))
1336 CRect rect;
1337 GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);
1338 ClientToScreen(&rect);
1339 point = rect.CenterPoint();
1341 CString sMenuItemText;
1342 CIconMenu popup;
1343 if (popup.CreatePopupMenu())
1345 long start = -1, end = -1;
1346 auto pEdit = (CRichEditCtrl *)GetDlgItem(IDC_MSGVIEW);
1347 pEdit->GetSel(start, end);
1348 // add the 'default' entries
1349 popup.AppendMenuIcon(WM_COPY, IDS_SCIEDIT_COPY, IDI_COPYCLIP);
1350 if (start >= end)
1351 popup.EnableMenuItem(WM_COPY, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1352 popup.AppendMenu(MF_SEPARATOR);
1353 sMenuItemText.LoadString(IDS_STATUSLIST_CONTEXT_COPYEXT);
1354 popup.AppendMenuIcon(EM_SETSEL, sMenuItemText, IDI_COPYCLIP);
1355 popup.AppendMenu(MF_SEPARATOR, NULL);
1356 sMenuItemText.LoadString(IDS_EDIT_NOTES);
1357 popup.AppendMenuIcon( CGitLogList::ID_EDITNOTE, sMenuItemText, IDI_EDIT);
1359 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1360 switch (cmd)
1362 case 0:
1363 break; // no command selected
1364 case EM_SETSEL:
1366 pEdit->SetRedraw(FALSE);
1367 int oldLine = pEdit->GetFirstVisibleLine();
1368 pEdit->SetSel(0, -1);
1369 pEdit->Copy();
1370 pEdit->SetSel(start, end);
1371 int newLine = pEdit->GetFirstVisibleLine();
1372 pEdit->LineScroll(oldLine - newLine);
1373 pEdit->SetRedraw(TRUE);
1374 pEdit->RedrawWindow();
1376 break;
1377 case WM_COPY:
1378 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);
1379 break;
1380 case CGitLogList::ID_EDITNOTE:
1381 CAppUtils::EditNote(pRev);
1382 this->FillLogMessageCtrl(true);
1383 break;
1389 void CLogDlg::OnOK()
1391 // since the log dialog is also used to select revisions for other
1392 // dialogs, we have to do some work before closing this dialog
1393 if (GetFocus() != GetDlgItem(IDOK))
1394 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter
1396 m_LogList.SafeTerminateAsyncDiffThread();
1397 if (this->IsThreadRunning())
1399 m_LogList.SafeTerminateThread();
1401 UpdateData();
1402 // check that one and only one row is selected
1403 if (m_LogList.GetSelectedCount() == 1)
1405 // get the selected row
1406 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1407 int selIndex = m_LogList.GetNextSelectedItem(pos);
1408 if (selIndex < m_LogList.m_arShownList.GetCount())
1410 // all ok, pick up the revision
1411 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
1412 // extract the hash
1413 m_sSelectedHash = pLogEntry->m_CommitHash;
1416 UpdateData(FALSE);
1417 SaveSplitterPos();
1418 __super::OnOK();
1420 #if 0
1421 if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))
1422 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.
1424 CString temp;
1425 CString buttontext;
1426 GetDlgItemText(IDOK, buttontext);
1427 temp.LoadString(IDS_MSGBOX_CANCEL);
1428 if (temp.Compare(buttontext) != 0)
1429 __super::OnOK(); // only exit if the button text matches, and that will match only if the thread isn't running anymore
1430 m_bCancelled = TRUE;
1431 m_selectedRevs.Clear();
1432 m_selectedRevsOneRange.Clear();
1433 if (m_pNotifyWindow)
1435 int selIndex = m_LogList.GetSelectionMark();
1436 if (selIndex >= 0)
1438 PLOGENTRYDATA pLogEntry = NULL;
1439 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1440 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1441 m_selectedRevs.AddRevision(pLogEntry->Rev);
1442 git_revnum_t lowerRev = pLogEntry->Rev;
1443 git_revnum_t higherRev = lowerRev;
1444 while (pos)
1446 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1447 git_revnum_t rev = pLogEntry->Rev;
1448 m_selectedRevs.AddRevision(pLogEntry->Rev);
1449 if (lowerRev > rev)
1450 lowerRev = rev;
1451 if (higherRev < rev)
1452 higherRev = rev;
1454 if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())
1456 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);
1458 BOOL bSentMessage = FALSE;
1459 if (m_LogList.GetSelectedCount() == 1)
1461 // if only one revision is selected, check if the path/url with which the dialog was started
1462 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.
1463 // if it was copied, use the copy from revision as lowerRev
1464 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))
1466 CString sUrl = m_path.GetGitPathString();
1467 if (!m_path.IsUrl())
1469 sUrl = GetURLFromPath(m_path);
1471 sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());
1472 for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)
1474 LogChangedPath * pData = pLogEntry->pArChangedPaths->SafeGetAt(cp);
1475 if (pData)
1477 if (sUrl.Compare(pData->sPath) == 0)
1479 if (!pData->sCopyFromPath.IsEmpty())
1481 lowerRev = pData->lCopyFromRev;
1482 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);
1483 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);
1484 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1485 bSentMessage = TRUE;
1492 if ( !bSentMessage )
1494 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);
1495 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);
1496 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1497 if (m_selectedRevsOneRange.GetCount())
1498 m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);
1502 UpdateData();
1503 CRegDWORD reg(_T("Software\\TortoiseGit\\ShowAllEntry"));
1504 SaveSplitterPos();
1505 #endif
1508 void CLogDlg::DoDiffFromLog(INT_PTR selIndex, GitRev* rev1, GitRev* rev2, bool /*blame*/, bool /*unified*/)
1510 DialogEnableWindow(IDOK, FALSE);
1511 // SetPromptApp(&theApp);
1512 theApp.DoWaitCursor(1);
1514 CString temppath;
1515 GetTempPath(temppath);
1517 CString file1;
1518 file1.Format(_T("%s%s_%s%s"),
1519 temppath,
1520 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1521 rev1->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength()),
1522 (*m_currentChangedArray)[selIndex].GetFileExtension());
1524 CString file2;
1525 file2.Format(_T("%s\\%s_%s%s"),
1526 temppath,
1527 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1528 rev2->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength()),
1529 (*m_currentChangedArray)[selIndex].GetFileExtension());
1531 CString cmd;
1532 CTGitPath &path = (CTGitPath &)(*m_currentChangedArray)[selIndex];
1534 if (g_Git.GetOneFile(rev1->m_CommitHash.ToString(), path, file1))
1536 CString out;
1537 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, path.GetGitPathString(), rev1->m_CommitHash.ToString(), file1);
1538 CMessageBox::Show(nullptr, g_Git.GetGitLastErr(out, CGit::GIT_CMD_GETONEFILE), _T("TortoiseGit"), MB_OK);
1539 theApp.DoWaitCursor(-1);
1540 EnableOKButton();
1541 return;
1543 if (g_Git.GetOneFile(rev2->m_CommitHash.ToString(), path, file2))
1545 CString out;
1546 out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, path.GetGitPathString(), rev2->m_CommitHash.ToString(), file2);
1547 CMessageBox::Show(nullptr, g_Git.GetGitLastErr(out, CGit::GIT_CMD_GETONEFILE), _T("TortoiseGit"), MB_OK);
1548 theApp.DoWaitCursor(-1);
1549 EnableOKButton();
1550 return;
1553 CAppUtils::DiffFlags flags;
1554 CAppUtils::StartExtDiff(file1,file2,_T("A"),_T("B"),
1555 g_Git.CombinePath(path), g_Git.CombinePath(path),
1556 rev1->m_CommitHash.ToString(), rev2->m_CommitHash.ToString(),
1557 flags);
1559 theApp.DoWaitCursor(-1);
1560 EnableOKButton();
1563 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)
1565 // Skip Ctrl-C when copying text out of the log message or search filter
1566 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);
1567 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
1569 if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1571 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1573 m_LogList.DiffSelectedRevWithPrevious();
1574 return TRUE;
1577 if (GetFocus() == GetDlgItem(IDC_SEARCHEDIT))
1579 KillTimer(LOGFILTER_TIMER);
1580 m_limit = 0;
1581 m_LogList.Refresh(FALSE);
1582 FillLogMessageCtrl(false);
1584 if (GetFocus() == GetDlgItem(IDC_FILTER))
1586 KillTimer(FILEFILTER_TIMER);
1587 FillLogMessageCtrl();
1588 return TRUE;
1591 else if (pMsg->message == WM_XBUTTONUP)
1593 bool select = (pMsg->wParam & MK_SHIFT) == 0;
1594 if (HIWORD(pMsg->wParam) & XBUTTON1)
1595 GoBackForward(select, false);
1596 if (HIWORD(pMsg->wParam) & XBUTTON2)
1597 GoBackForward(select, true);
1598 if (HIWORD(pMsg->wParam) & (XBUTTON1 | XBUTTON2))
1599 return TRUE;
1601 if (m_hAccel && !bSkipAccelerator)
1603 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1604 if (ret)
1605 return TRUE;
1608 if(::IsWindow(m_tooltips.m_hWnd))
1609 m_tooltips.RelayEvent(pMsg);
1610 return __super::PreTranslateMessage(pMsg);
1614 BOOL CLogDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1616 //if (this->IsThreadRunning())
1617 if(m_LogList.m_bNoDispUpdates)
1619 // only show the wait cursor over the list control
1620 if ((pWnd)&&
1621 ((pWnd == GetDlgItem(IDC_LOGLIST))||
1622 (pWnd == GetDlgItem(IDC_MSGVIEW))||
1623 (pWnd == GetDlgItem(IDC_LOGMSG))))
1625 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1626 SetCursor(hCur);
1627 return TRUE;
1630 if ((pWnd) && (pWnd == GetDlgItem(IDC_MSGVIEW)))
1631 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1633 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1634 SetCursor(hCur);
1635 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1638 void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1640 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1641 *pResult = 0;
1642 //if (this->IsThreadRunning())
1643 if(m_LogList.m_bNoDispUpdates)
1644 return;
1645 if (pNMLV->iItem >= 0)
1647 if (!m_LogList.m_highlight.IsEmpty())
1649 m_LogList.m_highlight.Empty();
1650 m_LogList.Invalidate();
1652 this->m_LogList.m_nSearchIndex = pNMLV->iItem;
1653 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(pNMLV->iItem));
1654 if (pLogEntry == nullptr)
1655 return;
1656 m_LogList.m_lastSelectedHash = pLogEntry->m_CommitHash;
1657 if (pNMLV->iSubItem != 0)
1658 return;
1659 if ((pNMLV->iItem == m_LogList.m_arShownList.GetCount()))
1661 // remove the selected state
1662 if (pNMLV->uChanged & LVIF_STATE)
1664 m_LogList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);
1665 FillLogMessageCtrl();
1666 UpdateData(FALSE);
1667 UpdateLogInfoLabel();
1669 return;
1671 if (pNMLV->uChanged & LVIF_STATE)
1673 if ((pNMLV->uNewState & LVIS_SELECTED) && !m_bNavigatingWithSelect)
1675 m_LogList.m_selectionHistory.Add(m_LogList.m_lastSelectedHash);
1676 m_LogList.m_lastSelectedHash = pLogEntry->m_CommitHash;
1678 FillLogMessageCtrl();
1679 UpdateData(FALSE);
1682 else
1684 m_LogList.m_lastSelectedHash.Empty();
1685 FillLogMessageCtrl();
1686 UpdateData(FALSE);
1688 EnableOKButton();
1689 UpdateLogInfoLabel();
1692 void CLogDlg::OnLvnItemchangedLogmsg(NMHDR * /*pNMHDR*/, LRESULT * /*pResult*/)
1694 UpdateLogInfoLabel();
1697 void CLogDlg::OnEnLinkMsgview(NMHDR *pNMHDR, LRESULT *pResult)
1699 ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);
1700 if ((pEnLink->msg == WM_LBUTTONUP) || (pEnLink->msg == WM_SETCURSOR))
1702 CString url, msg;
1703 GetDlgItemText(IDC_MSGVIEW, msg);
1704 msg.Replace(_T("\r\n"), _T("\n"));
1705 url = msg.Mid(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax-pEnLink->chrg.cpMin);
1706 auto findResult = m_LogList.m_ProjectProperties.FindBugIDPositions(msg);
1707 if (std::find_if(findResult.begin(), findResult.end(),
1708 [=] (const CHARRANGE &cr) -> bool { return cr.cpMin == pEnLink->chrg.cpMin && cr.cpMax == pEnLink->chrg.cpMax; }
1709 ) != findResult.end())
1711 url = m_LogList.m_ProjectProperties.GetBugIDUrl(url);
1712 url = GetAbsoluteUrlFromRelativeUrl(url);
1714 if (::PathIsURL(url))
1716 if (pEnLink->msg == WM_LBUTTONUP)
1717 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
1718 else
1720 static RECT prevRect = { 0 };
1721 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
1722 if (pMsgView)
1724 RECT rc;
1725 POINTL pt;
1726 pMsgView->SendMessage(EM_POSFROMCHAR, (WPARAM)&pt, pEnLink->chrg.cpMin);
1727 rc.left = pt.x;
1728 rc.top = pt.y;
1729 pMsgView->SendMessage(EM_POSFROMCHAR, (WPARAM)&pt, pEnLink->chrg.cpMax);
1730 rc.right = pt.x;
1731 rc.bottom = pt.y + 12;
1732 if ((prevRect.left != rc.left) || (prevRect.top != rc.top))
1734 m_tooltips.DelTool(pMsgView, 1);
1735 m_tooltips.AddTool(pMsgView, url, &rc, 1);
1736 prevRect = rc;
1741 else if(pEnLink->msg == WM_LBUTTONUP)
1743 int pos = 0;
1744 if (LookLikeGitHash(url, pos))
1746 bool found = false;
1747 for (int i = 0; i < m_LogList.m_arShownList.GetCount(); ++i)
1749 GitRev *rev = (GitRev *)m_LogList.m_arShownList.SafeGetAt(i);
1750 if (!rev) continue;
1751 if (rev->m_CommitHash.ToString().Left(url.GetLength()) == url)
1753 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1754 if (pos)
1756 int index = m_LogList.GetNextSelectedItem(pos);
1757 if (index > 0)
1758 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
1760 m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1761 m_LogList.EnsureVisible(i, FALSE);
1762 m_LogList.SetSelectionMark(i);
1763 found = true;
1764 PostMessage(WM_TGIT_REFRESH_SELECTION, 0, 0);
1765 break;
1769 if (!found)
1770 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_LOG_JUMPNOTFOUND, IDS_APPNAME, 1, IDI_INFORMATION, IDS_OKBUTTON, 0, 0, _T("NoJumpNotFoundWarning"), IDS_MSGBOX_DONOTSHOWAGAIN);
1774 *pResult = 0;
1777 void CLogDlg::OnBnClickedStatbutton()
1779 if (this->IsThreadRunning())
1780 return;
1781 if (m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC)
1782 return; // nothing or just the working copy changes are shown, so no statistics.
1783 // the statistics dialog expects the log entries to be sorted by date
1784 SortByColumn(3, false);
1786 CStatGraphDlg dlg;
1787 m_LogList.RecalculateShownList(&dlg.m_ShowList);
1789 dlg.m_path = m_orgPath;
1790 dlg.DoModal();
1791 // restore the previous sorting
1792 SortByColumn(m_nSortColumn, m_bAscending);
1793 OnTimer(LOGFILTER_TIMER);
1796 void CLogDlg::MoveToSameTop(CWnd *pWndRef, CWnd *pWndTarget)
1798 CRect rcWndPicAuthor, rcWndMsgView;
1799 pWndRef->GetWindowRect(rcWndMsgView);
1800 ScreenToClient(rcWndMsgView);
1801 pWndTarget->GetWindowRect(rcWndPicAuthor);
1802 ScreenToClient(rcWndPicAuthor);
1803 int diff = rcWndMsgView.top - rcWndPicAuthor.top;
1804 rcWndPicAuthor.top += diff;
1805 rcWndPicAuthor.bottom += diff;
1806 pWndTarget->MoveWindow(rcWndPicAuthor);
1809 void CLogDlg::DoSizeV1(int delta)
1812 RemoveAnchor(IDC_LOGLIST);
1813 RemoveAnchor(IDC_SPLITTERTOP);
1814 RemoveAnchor(IDC_MSGVIEW);
1815 RemoveAnchor(IDC_PIC_AUTHOR);
1816 RemoveAnchor(IDC_SPLITTERBOTTOM);
1817 RemoveAnchor(IDC_LOGMSG);
1818 CSplitterControl::ChangeHeight(&m_LogList, delta, CW_TOPALIGN);
1819 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), -delta, CW_BOTTOMALIGN);
1820 MoveToSameTop(GetDlgItem(IDC_MSGVIEW), GetDlgItem(IDC_PIC_AUTHOR));
1821 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1822 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1823 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1824 AddAnchor(IDC_PIC_AUTHOR, TOP_RIGHT);
1825 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1826 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1827 ArrangeLayout();
1828 AdjustMinSize();
1829 SetSplitterRange();
1830 m_LogList.Invalidate();
1831 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1832 m_gravatar.Invalidate();
1836 void CLogDlg::DoSizeV2(int delta)
1839 RemoveAnchor(IDC_LOGLIST);
1840 RemoveAnchor(IDC_SPLITTERTOP);
1841 RemoveAnchor(IDC_MSGVIEW);
1842 RemoveAnchor(IDC_PIC_AUTHOR);
1843 RemoveAnchor(IDC_SPLITTERBOTTOM);
1844 RemoveAnchor(IDC_LOGMSG);
1845 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), delta, CW_TOPALIGN);
1846 CSplitterControl::ChangeHeight(&m_ChangedFileListCtrl, -delta, CW_BOTTOMALIGN);
1847 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1848 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1849 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1850 AddAnchor(IDC_PIC_AUTHOR, TOP_RIGHT);
1851 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1852 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1853 ArrangeLayout();
1854 AdjustMinSize();
1855 SetSplitterRange();
1856 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1857 m_ChangedFileListCtrl.Invalidate();
1858 m_gravatar.Invalidate();
1862 void CLogDlg::AdjustMinSize()
1864 // adjust the minimum size of the dialog to prevent the resizing from
1865 // moving the list control too far down.
1866 CRect rcChgListView;
1867 m_ChangedFileListCtrl.GetClientRect(rcChgListView);
1868 CRect rcLogList;
1869 m_LogList.GetClientRect(rcLogList);
1871 SetMinTrackSize(CSize(m_DlgOrigRect.Width(),
1872 m_DlgOrigRect.Height()-m_ChgOrigRect.Height()-m_LogListOrigRect.Height()-m_MsgViewOrigRect.Height()
1873 +rcChgListView.Height()+rcLogList.Height()+60));
1876 LRESULT CLogDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1878 switch (message) {
1879 case WM_NOTIFY:
1880 if (wParam == IDC_SPLITTERTOP)
1882 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1883 DoSizeV1(pHdr->delta);
1885 else if (wParam == IDC_SPLITTERBOTTOM)
1887 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1888 DoSizeV2(pHdr->delta);
1890 break;
1893 return CResizableDialog::DefWindowProc(message, wParam, lParam);
1896 void CLogDlg::SetSplitterRange()
1898 if ((m_LogList)&&(m_ChangedFileListCtrl))
1900 CRect rcTop;
1901 m_LogList.GetWindowRect(rcTop);
1902 ScreenToClient(rcTop);
1903 CRect rcMiddle;
1904 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(rcMiddle);
1905 ScreenToClient(rcMiddle);
1906 m_wndSplitter1.SetRange(rcTop.top+30, rcMiddle.bottom-20);
1907 CRect rcBottom;
1908 m_ChangedFileListCtrl.GetWindowRect(rcBottom);
1909 ScreenToClient(rcBottom);
1910 m_wndSplitter2.SetRange(rcMiddle.top+30, rcBottom.bottom-20);
1914 void CLogDlg::OnEnscrollMsgview()
1916 m_tooltips.DelTool(GetDlgItem(IDC_MSGVIEW), 1);
1919 LRESULT CLogDlg::OnClickedInfoIcon(WPARAM wParam, LPARAM lParam)
1921 if ((HWND)wParam == m_cFileFilter.GetSafeHwnd())
1922 return 0;
1924 // FIXME: x64 version would get this function called with unexpected parameters.
1925 if (!lParam)
1926 return 0;
1928 RECT * rect = (LPRECT)lParam;
1929 CPoint point;
1930 CString temp;
1931 point = CPoint(rect->left, rect->bottom);
1932 #define LOGMENUFLAGS(x) (MF_STRING | MF_ENABLED | ((m_LogList.m_SelectedFilters & x) ? MF_CHECKED : MF_UNCHECKED))
1933 CMenu popup;
1934 if (popup.CreatePopupMenu())
1936 temp.LoadString(IDS_LOG_FILTER_SUBJECT);
1937 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_SUBJECT), LOGFILTER_SUBJECT, temp);
1939 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
1940 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_MESSAGES), LOGFILTER_MESSAGES, temp);
1942 temp.LoadString(IDS_LOG_FILTER_PATHS);
1943 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_PATHS), LOGFILTER_PATHS, temp);
1945 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
1946 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_AUTHORS), LOGFILTER_AUTHORS, temp);
1948 temp.LoadString(IDS_LOG_FILTER_EMAILS);
1949 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_EMAILS), LOGFILTER_EMAILS, temp);
1951 temp.LoadString(IDS_LOG_FILTER_REVS);
1952 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REVS), LOGFILTER_REVS, temp);
1954 temp.LoadString(IDS_LOG_FILTER_REFNAME);
1955 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REFNAME), LOGFILTER_REFNAME, temp);
1957 if (m_LogList.m_bShowBugtraqColumn == TRUE) {
1958 temp.LoadString(IDS_LOG_FILTER_BUGIDS);
1959 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_BUGID), LOGFILTER_BUGID, temp);
1962 temp.LoadString(IDS_LOG_FILTER_TOGGLE);
1963 popup.AppendMenu(MF_STRING | MF_ENABLED, LOGFILTER_TOGGLE, temp);
1965 popup.AppendMenu(MF_SEPARATOR, NULL);
1967 temp.LoadString(IDS_LOG_FILTER_REGEX);
1968 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterWithRegex ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_REGEX, temp);
1970 temp.LoadString(IDS_LOG_FILTER_CASESENSITIVE);
1971 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterCaseSensitively ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_CASE, temp);
1973 m_tooltips.Pop();
1974 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1975 if (selection != 0)
1978 if (selection == LOGFILTER_REGEX)
1980 m_bFilterWithRegex = !m_bFilterWithRegex;
1981 CRegDWORD b(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE);
1982 b = m_bFilterWithRegex;
1983 m_LogList.m_bFilterWithRegex = m_bFilterWithRegex;
1984 SetFilterCueText();
1985 CheckRegexpTooltip();
1987 else if (selection == LOGFILTER_CASE)
1989 m_bFilterCaseSensitively = !m_bFilterCaseSensitively;
1990 CRegDWORD b(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE);
1991 b = m_bFilterCaseSensitively;
1992 m_LogList.m_bFilterCaseSensitively = m_bFilterCaseSensitively;
1994 else if (selection == LOGFILTER_TOGGLE)
1996 m_LogList.m_SelectedFilters = (~m_LogList.m_SelectedFilters) & LOGFILTER_ALL;
1997 SetFilterCueText();
1999 else
2001 m_LogList.m_SelectedFilters ^= selection;
2002 SetFilterCueText();
2004 // Reload only if a search text is entered
2005 if (m_LogList.HasFilterText())
2006 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2009 return 0L;
2012 LRESULT CLogDlg::OnClickedCancelFilter(WPARAM wParam, LPARAM /*lParam*/)
2014 if ((HWND)wParam == m_cFileFilter.GetSafeHwnd())
2016 KillTimer(FILEFILTER_TIMER);
2018 FillLogMessageCtrl();
2019 return 0L;
2022 KillTimer(LOGFILTER_TIMER);
2024 m_LogList.m_sFilterText.Empty();
2025 UpdateData(FALSE);
2026 theApp.DoWaitCursor(1);
2027 CStoreSelection storeselection(this);
2028 FillLogMessageCtrl(false);
2030 m_LogList.RemoveFilter();
2032 Refresh();
2034 CTime begin,end;
2035 m_LogList.GetTimeRange(begin,end);
2036 m_DateFrom.SetTime(&begin);
2037 m_DateTo.SetTime(&end);
2039 theApp.DoWaitCursor(-1);
2040 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2041 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2042 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2043 UpdateLogInfoLabel();
2045 return 0L;
2049 void CLogDlg::SetFilterCueText()
2051 CString temp(MAKEINTRESOURCE(IDS_LOG_FILTER_BY));
2052 temp += _T(" ");
2054 if (m_LogList.m_SelectedFilters & LOGFILTER_SUBJECT)
2056 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_SUBJECT));
2059 if (m_LogList.m_SelectedFilters & LOGFILTER_MESSAGES)
2061 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2062 temp += _T(", ");
2063 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_MESSAGES));
2066 if (m_LogList.m_SelectedFilters & LOGFILTER_PATHS)
2068 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2069 temp += _T(", ");
2070 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_PATHS));
2073 if (m_LogList.m_SelectedFilters & LOGFILTER_AUTHORS)
2075 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2076 temp += _T(", ");
2077 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_AUTHORS));
2080 if (m_LogList.m_SelectedFilters & LOGFILTER_EMAILS)
2082 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2083 temp += _T(", ");
2084 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_EMAILS));
2087 if (m_LogList.m_SelectedFilters & LOGFILTER_REVS)
2089 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2090 temp += _T(", ");
2091 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_REVS));
2094 if (m_LogList.m_SelectedFilters & LOGFILTER_REFNAME)
2096 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2097 temp += _T(", ");
2098 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_REFNAME));
2101 if (m_LogList.m_bShowBugtraqColumn && m_LogList.m_SelectedFilters & LOGFILTER_BUGID)
2103 if (temp.ReverseFind(_T(' ')) != temp.GetLength() - 1)
2104 temp += _T(", ");
2105 temp += CString(MAKEINTRESOURCE(IDS_LOG_FILTER_BUGIDS));
2108 // to make the cue banner text appear more to the right of the edit control
2109 temp = _T(" ")+temp;
2110 m_cFilter.SetCueBanner(temp.TrimRight());
2113 bool CLogDlg::Validate(LPCTSTR string)
2115 if (!m_bFilterWithRegex)
2116 return true;
2117 std::tr1::wregex pat;
2118 return m_LogList.ValidateRegexp(string, pat, false);
2121 void CLogDlg::OnEnChangeFileFilter()
2123 SetTimer(FILEFILTER_TIMER, 1000, NULL);
2126 void CLogDlg::OnTimer(UINT_PTR nIDEvent)
2128 if (nIDEvent == LOGFTIME_TIMER)
2130 KillTimer(LOGFTIME_TIMER);
2131 m_limit = 0;
2132 m_LogList.Refresh(FALSE);
2133 FillLogMessageCtrl(false);
2135 else if (nIDEvent == LOG_FILLPATCHVTIMER)
2137 FillPatchView();
2139 else if (nIDEvent == LOGFILTER_TIMER)
2141 KillTimer(LOGFILTER_TIMER);
2142 m_limit = 0;
2143 m_LogList.Refresh(FALSE);
2144 FillLogMessageCtrl(false);
2146 #if 0
2147 /* we will use git built-in grep to filter log */
2148 if (this->IsThreadRunning())
2150 // thread still running! So just restart the timer.
2151 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2152 return;
2154 CWnd * focusWnd = GetFocus();
2155 bool bSetFocusToFilterControl = ((focusWnd != GetDlgItem(IDC_DATEFROM))&&(focusWnd != GetDlgItem(IDC_DATETO))
2156 && (focusWnd != GetDlgItem(IDC_LOGLIST)));
2157 if (m_LogList.m_sFilterText.IsEmpty())
2159 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2160 // do not return here!
2161 // we also need to run the filter if the filter text is empty:
2162 // 1. to clear an existing filter
2163 // 2. to rebuild the m_arShownList after sorting
2165 theApp.DoWaitCursor(1);
2166 CStoreSelection storeselection(this);
2167 KillTimer(LOGFILTER_TIMER);
2168 FillLogMessageCtrl(false);
2170 // now start filter the log list
2171 m_LogList.StartFilter();
2173 if ( m_LogList.GetItemCount()==1 )
2175 m_LogList.SetSelectionMark(0);
2176 m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
2178 theApp.DoWaitCursor(-1);
2179 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2180 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2181 if (bSetFocusToFilterControl)
2182 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2183 UpdateLogInfoLabel();
2184 #endif
2185 } // if (nIDEvent == LOGFILTER_TIMER)
2186 else if (nIDEvent == LOG_HEADER_ORDER_TIMER)
2188 KillTimer(LOG_HEADER_ORDER_TIMER);
2189 CLogOrdering orderDlg;
2190 if (orderDlg.DoModal() == IDOK)
2191 Refresh();
2193 else if (nIDEvent == FILEFILTER_TIMER)
2195 KillTimer(FILEFILTER_TIMER);
2196 FillLogMessageCtrl();
2198 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC))));
2199 __super::OnTimer(nIDEvent);
2202 void CLogDlg::OnDtnDatetimechangeDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2206 CTime _time;
2207 m_DateTo.GetTime(_time);
2209 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 23, 59, 59);
2210 if (time.GetTime() != m_LogList.m_To)
2212 m_LogList.m_To = (DWORD)time.GetTime();
2213 SetTimer(LOGFTIME_TIMER, 10, NULL);
2216 catch (...)
2218 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2221 *pResult = 0;
2224 void CLogDlg::OnDtnDatetimechangeDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2229 CTime _time;
2230 m_DateFrom.GetTime(_time);
2232 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 0, 0, 0);
2233 if (time.GetTime() != m_LogList.m_From)
2235 m_LogList.m_From = (DWORD)time.GetTime();
2236 SetTimer(LOGFTIME_TIMER, 10, NULL);
2239 catch (...)
2241 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2244 *pResult = 0;
2247 void CLogDlg::OnCbnSelchangeJumpType()
2249 // reserved for future use
2252 void CLogDlg::OnBnClickedJumpUp()
2254 int sel = m_JumpType.GetCurSel();
2255 if (sel < 0) return;
2256 JumpType jumpType = (JumpType)sel;
2258 if (jumpType == JumpType_History)
2260 GoBack();
2261 return;
2264 CString strValue;
2265 CGitHash hashValue;
2266 int index = -1;
2267 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2268 if (pos)
2270 index = m_LogList.GetNextSelectedItem(pos);
2271 if (index == 0) return;
2273 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(index);
2274 if (jumpType == JumpType_AuthorEmail)
2275 strValue = data->GetAuthorEmail();
2276 else if (jumpType == JumpType_CommitterEmail)
2277 strValue = data->GetCommitterEmail();
2278 else if (jumpType == JumpType_Parent1)
2279 hashValue = data->m_CommitHash;
2280 else if (jumpType == JumpType_Parent2)
2281 hashValue = data->m_CommitHash;
2282 else if (jumpType == JumpType_TagFF)
2283 hashValue = data->m_CommitHash;
2284 else if (jumpType == JumpType_BranchFF)
2285 hashValue = data->m_CommitHash;
2287 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2289 else
2290 return;
2292 while (pos)
2294 index = m_LogList.GetNextSelectedItem(pos);
2295 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2297 m_LogList.SetSelectionMark(-1);
2299 for (int i = index - 1; i >= 0; i--)
2301 bool found = false;
2302 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(i);
2303 if (jumpType == JumpType_AuthorEmail)
2304 found = strValue == data->GetAuthorEmail();
2305 else if (jumpType == JumpType_CommitterEmail)
2306 found = strValue == data->GetCommitterEmail();
2307 else if (jumpType == JumpType_MergePoint)
2308 found = data->ParentsCount() > 1;
2309 else if (jumpType == JumpType_Parent1)
2311 if (data->m_ParentHash.size() > 0)
2312 found = data->m_ParentHash[0] == hashValue;
2314 else if (jumpType == JumpType_Parent2)
2316 if (data->m_ParentHash.size() > 1)
2317 found = data->m_ParentHash[1] == hashValue;
2319 else if (jumpType == JumpType_Tag || jumpType == JumpType_TagFF)
2321 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2322 for (size_t j = 0; j < refList.size(); ++j)
2324 if (refList[j].Left(10) == _T("refs/tags/"))
2326 found = true;
2327 break;
2331 if (found && jumpType == JumpType_TagFF)
2332 found = g_Git.IsFastForward(hashValue, data->m_CommitHash);
2334 else if (jumpType == JumpType_Branch || jumpType == JumpType_BranchFF)
2336 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2337 for (size_t j = 0; j < refList.size(); ++j)
2339 if (refList[j].Left(11) == _T("refs/heads/") || refList[j].Left(13) == _T("refs/remotes/"))
2341 found = true;
2342 break;
2346 if (found && jumpType == JumpType_BranchFF)
2347 found = g_Git.IsFastForward(hashValue, data->m_CommitHash);
2350 if (found)
2352 m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2353 m_LogList.EnsureVisible(i, FALSE);
2354 m_LogList.SetSelectionMark(i);
2355 return;
2359 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_LOG_JUMPNOTFOUND, IDS_APPNAME, 1, IDI_INFORMATION, IDS_OKBUTTON, 0, 0, _T("NoJumpNotFoundWarning"), IDS_MSGBOX_DONOTSHOWAGAIN);
2362 void CLogDlg::OnBnClickedJumpDown()
2364 int jumpType = m_JumpType.GetCurSel();
2365 if (jumpType < 0) return;
2367 if (jumpType == JumpType_History)
2369 GoForward();
2370 return;
2373 CString strValue;
2374 CGitHash hashValue;
2375 int index = -1;
2376 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2377 if (pos)
2379 index = m_LogList.GetNextSelectedItem(pos);
2380 if (index == 0) return;
2382 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(index);
2383 if (jumpType == JumpType_AuthorEmail)
2384 strValue = data->GetAuthorEmail();
2385 else if (jumpType == JumpType_CommitterEmail)
2386 strValue = data->GetCommitterEmail();
2387 else if (jumpType == JumpType_Parent1)
2389 if (data->m_ParentHash.size() > 0)
2390 hashValue = data->m_ParentHash.at(0);
2391 else
2392 return;
2394 else if (jumpType == JumpType_Parent2)
2396 if (data->m_ParentHash.size() > 1)
2397 hashValue = data->m_ParentHash.at(1);
2398 else
2399 return;
2401 else if (jumpType == JumpType_TagFF)
2402 hashValue = data->m_CommitHash;
2403 else if (jumpType == JumpType_BranchFF)
2404 hashValue = data->m_CommitHash;
2406 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2408 else
2409 return;
2411 while (pos)
2413 index = m_LogList.GetNextSelectedItem(pos);
2414 m_LogList.SetItemState(index, 0, LVIS_SELECTED);
2416 m_LogList.SetSelectionMark(-1);
2418 for (int i = index + 1; i < m_LogList.GetItemCount(); ++i)
2420 bool found = false;
2421 GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(i);
2422 if (jumpType == JumpType_AuthorEmail)
2423 found = strValue == data->GetAuthorEmail();
2424 else if (jumpType == JumpType_CommitterEmail)
2425 found = strValue == data->GetCommitterEmail();
2426 else if (jumpType == JumpType_MergePoint)
2427 found = data->ParentsCount() > 1;
2428 else if (jumpType == JumpType_Parent1)
2429 found = data->m_CommitHash == hashValue;
2430 else if (jumpType == JumpType_Parent2)
2431 found = data->m_CommitHash == hashValue;
2432 else if (jumpType == JumpType_Tag || jumpType == JumpType_TagFF)
2434 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2435 for (size_t j = 0; j < refList.size(); ++j)
2437 if (refList[j].Left(10) == _T("refs/tags/"))
2439 found = true;
2440 break;
2444 if (found && jumpType == JumpType_TagFF)
2445 found = g_Git.IsFastForward(data->m_CommitHash, hashValue);
2447 else if (jumpType == JumpType_Branch || jumpType == JumpType_BranchFF)
2449 STRING_VECTOR refList = m_LogList.m_HashMap[data->m_CommitHash];
2450 for (size_t j = 0; j < refList.size(); ++j)
2452 if (refList[j].Left(11) == _T("refs/heads/") || refList[j].Left(13) == _T("refs/remotes/"))
2454 found = true;
2455 break;
2459 if (found && jumpType == JumpType_BranchFF)
2460 found = g_Git.IsFastForward(data->m_CommitHash, hashValue);
2463 if (found)
2465 m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2466 m_LogList.EnsureVisible(i, FALSE);
2467 m_LogList.SetSelectionMark(i);
2468 return;
2472 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_LOG_JUMPNOTFOUND, IDS_APPNAME, 1, IDI_INFORMATION, IDS_OKBUTTON, 0, 0, _T("NoJumpNotFoundWarning"), IDS_MSGBOX_DONOTSHOWAGAIN);
2475 CTGitPathList CLogDlg::GetChangedPathsFromSelectedRevisions(bool /*bRelativePaths*/ /* = false */, bool /*bUseFilter*/ /* = true */)
2477 CTGitPathList pathList;
2478 #if 0
2480 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2482 m_sRepositoryRoot = GetRepositoryRoot(m_path);
2484 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2485 return pathList;
2487 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2488 if (pos != NULL)
2490 while (pos)
2492 int nextpos = m_LogList.GetNextSelectedItem(pos);
2493 if (nextpos >= m_arShownList.GetCount())
2494 continue;
2495 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(nextpos));
2496 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2497 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
2499 LogChangedPath * cpath = cpatharray->SafeGetAt(cpPathIndex);
2500 if (cpath == NULL)
2501 continue;
2502 CTGitPath path;
2503 if (!bRelativePaths)
2504 path.SetFromGit(m_sRepositoryRoot);
2505 path.AppendPathString(cpath->sPath);
2506 if ((!bUseFilter)||
2507 ((m_cHidePaths.GetState() & 0x0003)!=BST_CHECKED)||
2508 (cpath->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0))
2509 pathList.AddPath(path);
2514 pathList.RemoveDuplicates();
2515 #endif
2516 return pathList;
2519 void CLogDlg::SortByColumn(int /*nSortColumn*/, bool /*bAscending*/)
2521 #if 0
2522 switch(nSortColumn)
2524 case 0: // Revision
2526 if(bAscending)
2527 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscRevSort());
2528 else
2529 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescRevSort());
2531 break;
2532 case 1: // action
2534 if(bAscending)
2535 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscActionSort());
2536 else
2537 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescActionSort());
2539 break;
2540 case 2: // Author
2542 if(bAscending)
2543 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscAuthorSort());
2544 else
2545 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescAuthorSort());
2547 break;
2548 case 3: // Date
2550 if(bAscending)
2551 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscDateSort());
2552 else
2553 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescDateSort());
2555 break;
2556 case 4: // Message or bug id
2557 if (m_bShowBugtraqColumn)
2559 if(bAscending)
2560 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscBugIDSort());
2561 else
2562 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescBugIDSort());
2563 break;
2565 // fall through here
2566 case 5: // Message
2568 if(bAscending)
2569 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscMessageSort());
2570 else
2571 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescMessageSort());
2573 break;
2574 default:
2575 ATLASSERT(0);
2576 break;
2578 #endif
2581 void CLogDlg::OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult)
2583 if (this->IsThreadRunning())
2584 return; //no sorting while the arrays are filled
2585 #if 0
2586 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2587 const int nColumn = pNMLV->iSubItem;
2588 m_bAscending = nColumn == m_nSortColumn ? !m_bAscending : TRUE;
2589 m_nSortColumn = nColumn;
2590 SortByColumn(m_nSortColumn, m_bAscending);
2591 SetSortArrow(&m_LogList, m_nSortColumn, !!m_bAscending);
2592 SortShownListArray();
2593 m_LogList.Invalidate();
2594 UpdateLogInfoLabel();
2595 #else
2596 UNREFERENCED_PARAMETER(pNMHDR);
2597 #endif
2598 *pResult = 0;
2600 SetTimer(LOG_HEADER_ORDER_TIMER, 10, nullptr);
2603 void CLogDlg::SortShownListArray()
2605 // make sure the shown list still matches the filter after sorting.
2606 OnTimer(LOGFILTER_TIMER);
2607 // clear the selection states
2608 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2609 while (pos)
2611 m_LogList.SetItemState(m_LogList.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
2613 m_LogList.SetSelectionMark(-1);
2616 void CLogDlg::SetSortArrow(CListCtrl * control, int nColumn, bool bAscending)
2618 if (control == NULL)
2619 return;
2620 // set the sort arrow
2621 CHeaderCtrl * pHeader = control->GetHeaderCtrl();
2622 HDITEM HeaderItem = {0};
2623 HeaderItem.mask = HDI_FORMAT;
2624 for (int i=0; i<pHeader->GetItemCount(); ++i)
2626 pHeader->GetItem(i, &HeaderItem);
2627 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
2628 pHeader->SetItem(i, &HeaderItem);
2630 if (nColumn >= 0)
2632 pHeader->GetItem(nColumn, &HeaderItem);
2633 HeaderItem.fmt |= (bAscending ? HDF_SORTUP : HDF_SORTDOWN);
2634 pHeader->SetItem(nColumn, &HeaderItem);
2638 int CLogDlg::m_nSortColumnPathList = 0;
2639 bool CLogDlg::m_bAscendingPathList = false;
2641 void CLogDlg::OnBnClickedHidepaths()
2643 FillLogMessageCtrl();
2644 m_ChangedFileListCtrl.Invalidate();
2647 void CLogDlg::UpdateLogInfoLabel()
2650 CGitHash rev1 ;
2651 CGitHash rev2 ;
2652 long selectedrevs = 0;
2653 long selectedfiles = 0;
2654 int count = (int)m_LogList.m_arShownList.GetCount();
2655 int start = 0;
2656 if (count)
2658 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(0)))->m_CommitHash;
2659 if(this->m_LogList.m_bShowWC && rev1.IsEmpty()&&(count>1))
2660 start = 1;
2661 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(start)))->m_CommitHash;
2662 //pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_arShownList.GetCount()-1));
2663 rev2 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(count-1)))->m_CommitHash;
2664 selectedrevs = m_LogList.GetSelectedCount();
2665 if (selectedrevs)
2666 selectedfiles = m_ChangedFileListCtrl.GetSelectedCount();
2668 CString sTemp;
2669 sTemp.Format(IDS_PROC_LOG_STATS,
2670 count - start,
2671 rev2.ToString().Left(g_Git.GetShortHASHLength()), rev1.ToString().Left(g_Git.GetShortHASHLength()), selectedrevs, selectedfiles);
2673 if(selectedrevs == 1)
2675 CString str=m_ChangedFileListCtrl.GetStatisticsString(true);
2676 str.Replace(_T('\n'), _T(' '));
2677 sTemp += _T("\r\n") + str;
2679 m_sLogInfo = sTemp;
2681 UpdateData(FALSE);
2684 void CLogDlg::OnDtnDropdownDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2686 // the date control should not show the "today" button
2687 CMonthCalCtrl * pCtrl = m_DateFrom.GetMonthCalCtrl();
2688 if (pCtrl)
2689 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
2690 *pResult = 0;
2693 void CLogDlg::OnDtnDropdownDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2695 // the date control should not show the "today" button
2696 CMonthCalCtrl * pCtrl = m_DateTo.GetMonthCalCtrl();
2697 if (pCtrl)
2698 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
2699 *pResult = 0;
2702 void CLogDlg::OnSize(UINT nType, int cx, int cy)
2704 __super::OnSize(nType, cx, cy);
2705 //set range
2706 SetSplitterRange();
2709 void CLogDlg::OnRefresh()
2712 m_limit = 0;
2713 this->m_LogProgress.SetPos(0);
2715 Refresh (false);
2719 void CLogDlg::OnFocusFilter()
2721 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2724 void CLogDlg::OnEditCopy()
2726 if (GetFocus() == &m_ChangedFileListCtrl)
2727 CopyChangedSelectionToClipBoard();
2728 else
2729 m_LogList.CopySelectionToClipBoard();
2732 CString CLogDlg::GetAbsoluteUrlFromRelativeUrl(const CString& url)
2734 // is the URL a relative one?
2735 if (url.Left(2).Compare(_T("^/")) == 0)
2737 // URL is relative to the repository root
2738 CString url1 = m_sRepositoryRoot + url.Mid(1);
2739 TCHAR buf[INTERNET_MAX_URL_LENGTH] = { 0 };
2740 DWORD len = url.GetLength();
2741 if (UrlCanonicalize((LPCTSTR)url1, buf, &len, 0) == S_OK)
2742 return CString(buf, len);
2743 return url1;
2745 else if (url[0] == '/')
2747 // URL is relative to the server's hostname
2748 CString sHost;
2749 // find the server's hostname
2750 int schemepos = m_sRepositoryRoot.Find(_T("//"));
2751 if (schemepos >= 0)
2753 sHost = m_sRepositoryRoot.Left(m_sRepositoryRoot.Find('/', schemepos+3));
2754 CString url1 = sHost + url;
2755 TCHAR buf[INTERNET_MAX_URL_LENGTH] = { 0 };
2756 DWORD len = url.GetLength();
2757 if (UrlCanonicalize((LPCTSTR)url, buf, &len, 0) == S_OK)
2758 return CString(buf, len);
2759 return url1;
2762 return url;
2765 void CLogDlg::ShowGravatar()
2767 m_gravatar.EnableGravatar(m_bShowGravatar);
2768 RemoveAnchor(IDC_MSGVIEW);
2769 if (m_gravatar.IsGravatarEnabled())
2771 RECT rect, rect2;
2772 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(&rect);
2773 ScreenToClient(&rect);
2774 m_gravatar.GetWindowRect(&rect2);
2775 ScreenToClient(&rect2);
2776 rect.right = rect2.left;
2777 GetDlgItem(IDC_MSGVIEW)->MoveWindow(&rect);
2778 m_gravatar.ShowWindow(SW_SHOW);
2780 else
2782 RECT rect, rect2;
2783 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(&rect);
2784 ScreenToClient(&rect);
2785 m_gravatar.GetWindowRect(&rect2);
2786 ScreenToClient(&rect2);
2787 rect.right = rect2.right;
2788 GetDlgItem(IDC_MSGVIEW)->MoveWindow(&rect);
2789 m_gravatar.ShowWindow(SW_HIDE);
2791 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
2795 void CLogDlg::OnEnChangeSearchedit()
2797 UpdateData();
2798 if (!m_LogList.HasFilterText())
2800 CStoreSelection storeselection(this);
2801 // clear the filter, i.e. make all entries appear
2802 theApp.DoWaitCursor(1);
2803 KillTimer(LOGFILTER_TIMER);
2804 FillLogMessageCtrl(false);
2806 Refresh();
2807 //m_LogList.StartFilter();
2808 #if 0
2809 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2810 m_arShownList.RemoveAll();
2811 for (DWORD i=0; i<m_logEntries.size(); ++i)
2813 if (IsEntryInDateRange(i))
2814 m_arShownList.Add(m_logEntries[i]);
2816 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2817 m_LogList.DeleteAllItems();
2818 m_LogList.SetItemCountEx(ShownCountWithStopped());
2819 m_LogList.RedrawItems(0, ShownCountWithStopped());
2820 m_LogList.SetRedraw(false);
2821 ResizeAllListCtrlCols();
2822 m_LogList.SetRedraw(true);
2823 #endif
2824 theApp.DoWaitCursor(-1);
2825 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2826 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2827 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2828 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2829 return;
2831 if (Validate(m_LogList.m_sFilterText))
2832 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2833 else
2834 KillTimer(LOGFILTER_TIMER);
2838 void CLogDlg::OnBnClickedAllBranch()
2840 // m_bAllBranch is not auto-toggled by MFC, we have to handle it manually (in order to prevent the indeterminate state)
2842 m_LogList.m_ShowMask &=~ (CGit::LOG_INFO_LOCAL_BRANCHES | CGit::LOG_INFO_ALL_BRANCH);
2844 if (m_bAllBranch)
2846 m_bAllBranch = BST_UNCHECKED;
2847 m_ChangedFileListCtrl.m_sDisplayedBranch = m_LogList.GetRange();
2849 else
2851 m_bAllBranch = BST_CHECKED;
2852 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
2853 m_ChangedFileListCtrl.m_sDisplayedBranch.Empty();
2856 // need to save value here, so that log dialogs started from now on also have AllBranch activated
2857 m_regbAllBranch = m_bAllBranch;
2859 UpdateData(FALSE);
2861 OnRefresh();
2863 FillLogMessageCtrl(false);
2866 void CLogDlg::OnBnClickedFollowRenames()
2868 if(m_bFollowRenames)
2870 m_LogList.m_ShowMask |= CGit::LOG_INFO_FOLLOW;
2871 m_LogList.m_ShowMask &=~ CGit::LOG_INFO_LOCAL_BRANCHES;
2872 if (m_bAllBranch)
2875 m_bAllBranch = FALSE;
2876 m_LogList.m_ShowMask &=~ CGit::LOG_INFO_ALL_BRANCH;
2880 else
2881 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_FOLLOW;
2883 DialogEnableWindow(IDC_LOG_ALLBRANCH, !m_bFollowRenames);
2884 DialogEnableWindow(IDC_SHOWWHOLEPROJECT, !m_bFollowRenames && !m_path.IsEmpty());
2886 OnRefresh();
2888 FillLogMessageCtrl(false);
2891 void CLogDlg::HandleShowLabels(bool var, int flag)
2893 if (var)
2894 m_LogList.m_ShowRefMask |= flag;
2895 else
2896 m_LogList.m_ShowRefMask &= ~flag;
2898 if ((m_LogList.m_ShowFilter & CGitLogListBase::FILTERSHOW_REFS) && !(m_LogList.m_ShowFilter & CGitLogListBase::FILTERSHOW_ANYCOMMIT))
2900 // Remove commits where labels are not shown.
2901 OnRefresh();
2902 FillLogMessageCtrl(false);
2904 else
2906 // Just redraw
2907 m_LogList.Invalidate();
2911 void CLogDlg::OnBnClickedCompressedGraph()
2913 UpdateData();
2915 if (m_iCompressedGraph == 2)
2916 m_LogList.m_ShowFilter = CGitLogListBase::FILTERSHOW_REFS;
2917 else if (m_iCompressedGraph == 1)
2918 m_LogList.m_ShowFilter = static_cast<CGitLogListBase::FilterShow>(CGitLogListBase::FILTERSHOW_REFS | CGitLogListBase::FILTERSHOW_MERGEPOINTS);
2919 else
2920 m_LogList.m_ShowFilter = CGitLogListBase::FILTERSHOW_ALL;
2922 OnRefresh();
2923 FillLogMessageCtrl(false);
2926 void CLogDlg::OnBnClickedBrowseRef()
2928 CString newRef = CBrowseRefsDlg::PickRef(false, m_LogList.GetRange(), gPickRef_All, true);
2929 if(newRef.IsEmpty())
2930 return;
2932 m_History.AddEntry(newRef);
2933 m_History.Save();
2935 SetRange(newRef);
2937 m_LogList.m_ShowMask &= ~(CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES);
2938 m_bAllBranch = BST_UNCHECKED;
2939 UpdateData(FALSE);
2941 OnRefresh();
2942 FillLogMessageCtrl(false);
2945 void CLogDlg::ShowStartRef()
2947 //Show ref name on top
2948 if(!::IsWindow(m_hWnd))
2949 return;
2950 if (m_LogList.m_ShowMask & (CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES))
2952 switch (m_LogList.m_ShowMask & (CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES))
2954 case CGit::LOG_INFO_ALL_BRANCH:
2955 m_staticRef.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_LOG_ALLBRANCHES)));
2956 break;
2958 case CGit::LOG_INFO_LOCAL_BRANCHES:
2959 m_staticRef.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_LOG_LOCAL_BRANCHES)));
2960 break;
2963 m_staticRef.Invalidate(TRUE);
2964 m_tooltips.DelTool(GetDlgItem(IDC_STATIC_REF));
2965 return;
2968 CString showStartRef = m_LogList.GetRange();
2969 if (showStartRef.IsEmpty() || showStartRef == _T("HEAD"))
2971 showStartRef.Empty();
2972 //Ref name is HEAD
2973 if (g_Git.Run(L"git.exe symbolic-ref HEAD", &showStartRef, NULL, CP_UTF8))
2974 showStartRef = CString(MAKEINTRESOURCE(IDS_PROC_LOG_NOBRANCH));
2975 showStartRef.Trim(L"\r\n\t ");
2979 showStartRef = g_Git.StripRefName(showStartRef);
2981 m_staticRef.SetWindowText(showStartRef);
2982 CWnd *pWnd = GetDlgItem(IDC_STATIC_REF);
2983 m_tooltips.AddTool(pWnd, showStartRef);
2984 m_staticRef.Invalidate(TRUE);
2987 void CLogDlg::SetRange(const CString& range)
2989 m_LogList.SetRange(range);
2990 m_ChangedFileListCtrl.m_sDisplayedBranch = range;
2992 ShowStartRef();
2995 static void AppendMenuChecked(CMenu &menu, UINT nTextID, UINT_PTR nItemID, BOOL checked = FALSE, BOOL enabled = TRUE)
2997 CString text;
2998 text.LoadString(nTextID);
2999 menu.AppendMenu(MF_STRING | (enabled ? MF_ENABLED : MF_DISABLED) | (checked ? MF_CHECKED : MF_UNCHECKED), nItemID, text);
3002 #define WALKBEHAVIOUR_FIRSTPARENT 1
3003 #define WALKBEHAVIOUR_FOLLOWRENAMES 2
3004 #define WALKBEHAVIOUR_COMPRESSEDGRAPH 3
3005 #define WALKBEHAVIOUR_LABELEDCOMMITS 4
3006 #define WALKBEHAVIOUR_NOMERGES 5
3008 void CLogDlg::OnBnClickedWalkBehaviour()
3010 CMenu popup;
3011 if (popup.CreatePopupMenu())
3013 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_FIRSTPARENT, WALKBEHAVIOUR_FIRSTPARENT, m_bFirstParent);
3014 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_NOMERGES, WALKBEHAVIOUR_NOMERGES, m_bNoMerges);
3015 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_FOLLOWRENAMES, WALKBEHAVIOUR_FOLLOWRENAMES, m_bFollowRenames, !(m_path.IsEmpty() || m_path.IsDirectory()));
3016 popup.AppendMenu(MF_SEPARATOR, NULL);
3017 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_COMPRESSED, WALKBEHAVIOUR_COMPRESSEDGRAPH, m_iCompressedGraph == 1);
3018 AppendMenuChecked(popup, IDS_WALKBEHAVIOUR_LABELEDCOMMITS, WALKBEHAVIOUR_LABELEDCOMMITS, m_iCompressedGraph == 2);
3020 m_tooltips.Pop();
3021 RECT rect;
3022 GetDlgItem(IDC_WALKBEHAVIOUR)->GetWindowRect(&rect);
3023 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, rect.left, rect.top, this, 0);
3024 switch (selection)
3026 case WALKBEHAVIOUR_FIRSTPARENT:
3027 m_bFirstParent = !m_bFirstParent;
3028 OnBnClickedFirstParent();
3029 break;
3030 case WALKBEHAVIOUR_NOMERGES:
3031 m_bNoMerges = !m_bNoMerges;
3032 OnBnClickedFirstParent(); // OnBnClickedFirstParent handles both cases: m_bFirstParent and m_bNoMerges
3033 break;
3034 case WALKBEHAVIOUR_FOLLOWRENAMES:
3035 m_bFollowRenames = !m_bFollowRenames;
3036 OnBnClickedFollowRenames();
3037 break;
3038 case WALKBEHAVIOUR_COMPRESSEDGRAPH:
3039 m_iCompressedGraph = (m_iCompressedGraph == 1 ? 0 : 1);
3040 OnBnClickedCompressedGraph();
3041 break;
3042 case WALKBEHAVIOUR_LABELEDCOMMITS:
3043 m_iCompressedGraph = (m_iCompressedGraph == 2 ? 0 : 2);
3044 OnBnClickedCompressedGraph();
3045 break;
3046 default:
3047 break;
3049 m_bWalkBehavior = (m_bFirstParent || m_bNoMerges || m_bFollowRenames || m_iCompressedGraph);
3050 UpdateData(FALSE);
3054 #define VIEW_HIDEPATHS 1
3055 #define VIEW_GRAYPATHS 2
3056 #define VIEW_SHOWTAGS 3
3057 #define VIEW_SHOWLOCALBRANCHES 4
3058 #define VIEW_SHOWREMOTEBRANCHES 5
3059 #define VIEW_SHOWGRAVATAR 6
3060 #define VIEW_SHOWPATCH 7
3062 void CLogDlg::OnBnClickedView()
3064 CMenu popup;
3065 if (popup.CreatePopupMenu())
3067 AppendMenuChecked(popup, IDS_SHOWFILES_HIDEPATHS, VIEW_HIDEPATHS, m_iHidePaths == 1);
3068 AppendMenuChecked(popup, IDS_SHOWFILES_GRAYPATHS, VIEW_GRAYPATHS, m_iHidePaths == 2);
3069 popup.AppendMenu(MF_SEPARATOR, NULL);
3070 CMenu showLabelsMenu;
3071 if (showLabelsMenu.CreatePopupMenu())
3073 AppendMenuChecked(showLabelsMenu, IDS_VIEW_SHOWTAGLABELS, VIEW_SHOWTAGS, m_bShowTags);
3074 AppendMenuChecked(showLabelsMenu, IDS_VIEW_SHOWLOCALBRANCHLABELS, VIEW_SHOWLOCALBRANCHES, m_bShowLocalBranches);
3075 AppendMenuChecked(showLabelsMenu, IDS_VIEW_SHOWREMOTEBRANCHLABELS, VIEW_SHOWREMOTEBRANCHES, m_bShowRemoteBranches);
3076 popup.AppendMenu(MF_STRING | MF_POPUP, (UINT)showLabelsMenu.m_hMenu, (CString)MAKEINTRESOURCE(IDS_VIEW_LABELS));
3078 popup.AppendMenu(MF_SEPARATOR, NULL);
3079 AppendMenuChecked(popup, IDS_VIEW_SHOWGRAVATAR, VIEW_SHOWGRAVATAR, m_bShowGravatar);
3080 AppendMenuChecked(popup, IDS_MENU_VIEWPATCH, VIEW_SHOWPATCH, IsWindow(this->m_patchViewdlg.m_hWnd));
3082 m_tooltips.Pop();
3083 RECT rect;
3084 GetDlgItem(IDC_VIEW)->GetWindowRect(&rect);
3085 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, rect.left, rect.top, this, 0);
3086 switch (selection)
3088 case VIEW_HIDEPATHS:
3089 if (m_iHidePaths == 1)
3090 m_iHidePaths = 0;
3091 else
3092 m_iHidePaths = 1;
3093 OnBnClickedHidepaths();
3094 break;
3095 case VIEW_GRAYPATHS:
3096 if (m_iHidePaths == 2)
3097 m_iHidePaths = 0;
3098 else
3099 m_iHidePaths = 2;
3100 OnBnClickedHidepaths();
3101 break;
3102 case VIEW_SHOWTAGS:
3103 m_bShowTags = !m_bShowTags;
3104 HandleShowLabels(m_bShowTags, LOGLIST_SHOWTAGS);
3105 break;
3106 case VIEW_SHOWLOCALBRANCHES:
3107 m_bShowLocalBranches = !m_bShowLocalBranches;
3108 HandleShowLabels(m_bShowLocalBranches, LOGLIST_SHOWLOCALBRANCHES);
3109 break;
3110 case VIEW_SHOWREMOTEBRANCHES:
3111 m_bShowRemoteBranches = !m_bShowRemoteBranches;
3112 HandleShowLabels(m_bShowRemoteBranches, LOGLIST_SHOWREMOTEBRANCHES);
3113 break;
3114 case VIEW_SHOWGRAVATAR:
3116 m_bShowGravatar = !m_bShowGravatar;
3117 ShowGravatar();
3118 m_gravatar.Init();
3119 CString email;
3120 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
3121 if (pos)
3123 int selIndex = m_LogList.GetNextSelectedItem(pos);
3124 int moreSel = m_LogList.GetNextSelectedItem(pos);
3125 if (moreSel < 0)
3127 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
3128 if (pLogEntry)
3129 email = pLogEntry->GetAuthorEmail();
3132 m_gravatar.LoadGravatar(email);
3133 break;
3135 case VIEW_SHOWPATCH:
3136 TogglePatchView();
3137 break;
3138 default:
3139 break;
3144 void CLogDlg::OnBnClickedFirstParent()
3146 if(this->m_bFirstParent)
3147 m_LogList.m_ShowMask|=CGit::LOG_INFO_FIRST_PARENT;
3148 else
3149 m_LogList.m_ShowMask&=~CGit::LOG_INFO_FIRST_PARENT;
3151 if (m_bNoMerges)
3152 m_LogList.m_ShowMask |= CGit::LOG_INFO_NO_MERGE;
3153 else
3154 m_LogList.m_ShowMask &= ~CGit::LOG_INFO_NO_MERGE;
3156 OnRefresh();
3158 FillLogMessageCtrl(false);
3162 void CLogDlg::OnBnClickShowWholeProject()
3164 this->UpdateData();
3166 if(this->m_bWholeProject)
3168 m_LogList.m_Path.Reset();
3169 SetDlgTitle();
3171 else
3172 m_LogList.m_Path=m_path;
3174 m_regShowWholeProject = m_bWholeProject;
3176 SetDlgTitle();
3178 OnRefresh();
3180 FillLogMessageCtrl(false);
3184 LRESULT CLogDlg::OnRefLogChanged(WPARAM /*wParam*/, LPARAM /*lParam*/)
3186 ShowStartRef();
3187 return 0;
3190 LRESULT CLogDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
3192 m_pTaskbarList.Release();
3193 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
3194 SetUUIDOverlayIcon(m_hWnd);
3195 return 0;
3198 LRESULT CLogDlg::OnRefreshSelection(WPARAM /*wParam*/, LPARAM /*lParam*/)
3200 // it's enough to deselect, then select again one item of the whole selection
3201 int selMark = m_LogList.GetSelectionMark();
3202 if (selMark >= 0)
3204 m_LogList.SetSelectionMark(selMark);
3205 m_LogList.SetItemState(selMark, 0, LVIS_SELECTED);
3206 m_LogList.SetItemState(selMark, LVIS_SELECTED, LVIS_SELECTED);
3208 return 0;