limit changed files list context menu options on bare repos
[TortoiseGit.git] / src / TortoiseProc / LogDlg.cpp
blobcbdae86c13122af8d9c95fccc725095f070431b5
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2011 - 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 "InputDlg.h"
24 #include "GITProgressDlg.h"
25 #include "ProgressDlg.h"
26 //#include "RepositoryBrowser.h"
27 //#include "CopyDlg.h"
28 #include "StatGraphDlg.h"
29 #include "Logdlg.h"
30 #include "MessageBox.h"
31 #include "Registry.h"
32 #include "AppUtils.h"
33 #include "PathUtils.h"
34 #include "StringUtils.h"
35 #include "UnicodeUtils.h"
36 #include "TempFile.h"
37 //#include "GitInfo.h"
38 //#include "GitDiff.h"
39 #include "IconMenu.h"
40 //#include "RevisionRangeDlg.h"
41 //#include "BrowseFolder.h"
42 //#include "BlameDlg.h"
43 //#include "Blame.h"
44 //#include "GitHelpers.h"
45 #include "GitStatus.h"
46 //#include "LogDlgHelper.h"
47 //#include "CachedLogInfo.h"
48 //#include "RepositoryInfo.h"
49 //#include "EditPropertiesDlg.h"
50 #include "FileDiffDlg.h"
51 #include "BrowseRefsDlg.h"
54 IMPLEMENT_DYNAMIC(CLogDlg, CResizableStandAloneDialog)
55 CLogDlg::CLogDlg(CWnd* pParent /*=NULL*/)
56 : CResizableStandAloneDialog(CLogDlg::IDD, pParent)
57 , m_logcounter(0)
58 , m_wParam(0)
59 , m_currentChangedArray(NULL)
60 , m_nSortColumn(0)
61 , m_bShowedAll(false)
62 , m_bSelect(false)
64 , m_bSelectionMustBeContinuous(false)
65 , m_lowestRev(_T(""))
67 , m_sLogInfo(_T(""))
69 , m_bCancelled(FALSE)
70 , m_pNotifyWindow(NULL)
72 , m_bAscending(FALSE)
74 , m_limit(0)
75 , m_childCounter(0)
76 , m_maxChild(0)
77 , m_bIncludeMerges(FALSE)
78 , m_hAccel(NULL)
80 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
82 CString str;
83 str=g_Git.m_CurrentDir;
84 str.Replace(_T(":"),_T("_"));
85 str=CString(_T("Software\\TortoiseGit\\LogDialog\\AllBranch\\"))+str;
87 m_regbAllBranch=CRegDWORD(str,FALSE);
89 m_bAllBranch=m_regbAllBranch;
91 m_bFirstParent=FALSE;
92 m_bWholeProject=FALSE;
95 CLogDlg::~CLogDlg()
98 m_regbAllBranch=m_bAllBranch;
100 m_CurrentFilteredChangedArray.RemoveAll();
104 void CLogDlg::DoDataExchange(CDataExchange* pDX)
106 CResizableStandAloneDialog::DoDataExchange(pDX);
107 DDX_Control(pDX, IDC_LOGLIST, m_LogList);
108 DDX_Control(pDX, IDC_LOGMSG, m_ChangedFileListCtrl);
109 DDX_Control(pDX, IDC_PROGRESS, m_LogProgress);
110 DDX_Control(pDX, IDC_SPLITTERTOP, m_wndSplitter1);
111 DDX_Control(pDX, IDC_SPLITTERBOTTOM, m_wndSplitter2);
112 DDX_Text(pDX, IDC_SEARCHEDIT, m_LogList.m_sFilterText);
113 DDX_Control(pDX, IDC_DATEFROM, m_DateFrom);
114 DDX_Control(pDX, IDC_DATETO, m_DateTo);
115 DDX_Control(pDX, IDC_HIDEPATHS, m_cHidePaths);
116 DDX_Text(pDX, IDC_LOGINFO, m_sLogInfo);
117 DDX_Check(pDX, IDC_LOG_FIRSTPARENT, m_bFirstParent);
118 DDX_Check(pDX, IDC_LOG_ALLBRANCH,m_bAllBranch);
119 DDX_Check(pDX, IDC_SHOWWHOLEPROJECT,m_bWholeProject);
120 DDX_Control(pDX, IDC_SEARCHEDIT, m_cFilter);
121 DDX_Control(pDX, IDC_STATIC_REF, m_staticRef);
124 BEGIN_MESSAGE_MAP(CLogDlg, CResizableStandAloneDialog)
125 //ON_BN_CLICKED(IDC_GETALL, OnBnClickedGetall)
126 //ON_NOTIFY(NM_DBLCLK, IDC_LOGMSG, OnNMDblclkChangedFileList)
127 ON_WM_CONTEXTMENU()
128 ON_WM_SETCURSOR()
129 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
130 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOGLIST, OnLvnItemchangedLoglist)
131 ON_NOTIFY(EN_LINK, IDC_MSGVIEW, OnEnLinkMsgview)
132 ON_BN_CLICKED(IDC_STATBUTTON, OnBnClickedStatbutton)
135 ON_MESSAGE(WM_FILTEREDIT_INFOCLICKED, OnClickedInfoIcon)
136 ON_MESSAGE(WM_FILTEREDIT_CANCELCLICKED, OnClickedCancelFilter)
138 ON_MESSAGE(MSG_LOAD_PERCENTAGE,OnLogListLoading)
140 ON_EN_CHANGE(IDC_SEARCHEDIT, OnEnChangeSearchedit)
141 ON_WM_TIMER()
142 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETO, OnDtnDatetimechangeDateto)
143 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATEFROM, OnDtnDatetimechangeDatefrom)
144 ON_BN_CLICKED(IDC_SHOWWHOLEPROJECT, OnBnClickShowWholeProject)
145 //ON_NOTIFY(NM_CUSTOMDRAW, IDC_LOGMSG, OnNMCustomdrawChangedFileList)
146 //ON_NOTIFY(LVN_GETDISPINFO, IDC_LOGMSG, OnLvnGetdispinfoChangedFileList)
147 ON_NOTIFY(LVN_COLUMNCLICK,IDC_LOGLIST, OnLvnColumnclick)
148 //ON_NOTIFY(LVN_COLUMNCLICK, IDC_LOGMSG, OnLvnColumnclickChangedFileList)
149 ON_BN_CLICKED(IDC_HIDEPATHS, OnBnClickedHidepaths)
150 ON_COMMAND(MSG_FETCHED_DIFF, OnBnClickedHidepaths)
151 ON_BN_CLICKED(IDC_LOG_ALLBRANCH, OnBnClickedAllBranch)
153 ON_NOTIFY(DTN_DROPDOWN, IDC_DATEFROM, &CLogDlg::OnDtnDropdownDatefrom)
154 ON_NOTIFY(DTN_DROPDOWN, IDC_DATETO, &CLogDlg::OnDtnDropdownDateto)
155 ON_WM_SIZE()
156 ON_BN_CLICKED(IDC_LOG_FIRSTPARENT, &CLogDlg::OnBnClickedFirstParent)
157 ON_BN_CLICKED(IDC_REFRESH, &CLogDlg::OnBnClickedRefresh)
158 // ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CLogDlg::OnBnClickedBrowseRef)
159 ON_STN_CLICKED(IDC_STATIC_REF, &CLogDlg::OnBnClickedBrowseRef)
160 ON_COMMAND(ID_LOGDLG_REFRESH, &CLogDlg::OnBnClickedRefresh)
161 ON_COMMAND(ID_LOGDLG_FIND, &CLogDlg::OnFind)
162 ON_COMMAND(ID_LOGDLG_FOCUSFILTER, &CLogDlg::OnFocusFilter)
163 ON_COMMAND(ID_EDIT_COPY, &CLogDlg::OnEditCopy)
164 ON_MESSAGE(MSG_REFLOG_CHANGED, OnRefLogChanged)
165 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
166 END_MESSAGE_MAP()
168 void CLogDlg::SetParams(const CTGitPath& orgPath, const CTGitPath& path, CString hightlightRevision, CString startrev, CString endrev, int limit /* = FALSE */)
170 m_orgPath = orgPath;
171 m_path = path;
172 m_hightlightRevision = hightlightRevision;
173 this->m_LogList.m_startrev = startrev;
174 m_LogRevision = startrev;
175 this->m_LogList.m_endrev = endrev;
177 if(!endrev.IsEmpty())
178 this->SetStartRef(endrev);
180 m_hasWC = !path.IsUrl();
181 m_limit = limit;
182 if (::IsWindow(m_hWnd))
183 UpdateData(FALSE);
186 BOOL CLogDlg::OnInitDialog()
188 CString temp;
189 CResizableStandAloneDialog::OnInitDialog();
190 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
192 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
193 // do this, Explorer would be unable to send that message to our window if we
194 // were running elevated. It's OK to make the call all the time, since if we're
195 // not elevated, this is a no-op.
196 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
197 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
198 HMODULE hUser = ::LoadLibrary(_T("user32.dll"));
199 if (hUser)
201 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
202 if (pfnChangeWindowMessageFilterEx)
204 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
206 FreeLibrary(hUser);
208 m_pTaskbarList.Release();
209 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
211 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_LOGDLG));
213 // use the state of the "stop on copy/rename" option from the last time
214 UpdateData(FALSE);
216 // set the font to use in the log message view, configured in the settings dialog
217 CAppUtils::CreateFontForLogs(m_logFont);
218 GetDlgItem(IDC_MSGVIEW)->SetFont(&m_logFont);
219 // automatically detect URLs in the log message and turn them into links
220 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_AUTOURLDETECT, TRUE, NULL);
221 // make the log message rich edit control send a message when the mouse pointer is over a link
222 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_SETEVENTMASK, NULL, ENM_LINK);
223 //m_LogList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_SUBITEMIMAGES);
225 // the "hide unrelated paths" checkbox should be indeterminate
226 m_cHidePaths.SetCheck(BST_INDETERMINATE);
229 //SetWindowTheme(m_LogList.GetSafeHwnd(), L"Explorer", NULL);
230 //SetWindowTheme(m_ChangedFileListCtrl.GetSafeHwnd(), L"Explorer", NULL);
232 // set up the columns
233 m_LogList.DeleteAllItems();
235 m_LogList.m_Path=m_path;
236 m_LogList.m_hasWC = m_LogList.m_bShowWC = !g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir);
237 m_LogList.InsertGitColumn();
239 m_ChangedFileListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS |GITSLC_COLADD|GITSLC_COLDEL, _T("LogDlg"), (GITSLC_POPALL ^ (GITSLC_POPCOMMIT|GITSLC_POPIGNORE)), false, m_LogList.m_hasWC);
241 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
243 m_logcounter = 0;
244 m_sMessageBuf.Preallocate(100000);
246 SetDlgTitle();
248 m_tooltips.Create(this);
249 CheckRegexpTooltip();
251 SetSplitterRange();
253 // the filter control has a 'cancel' button (the red 'X'), we need to load its bitmap
254 m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);
255 m_cFilter.SetInfoIcon(IDI_LOGFILTER);
256 m_cFilter.SetValidator(this);
258 AdjustControlSize(IDC_HIDEPATHS);
259 AdjustControlSize(IDC_LOG_FIRSTPARENT);
260 AdjustControlSize(IDC_LOG_ALLBRANCH);
262 GetClientRect(m_DlgOrigRect);
263 m_LogList.GetClientRect(m_LogListOrigRect);
264 GetDlgItem(IDC_MSGVIEW)->GetClientRect(m_MsgViewOrigRect);
265 m_ChangedFileListCtrl.GetClientRect(m_ChgOrigRect);
267 m_DateFrom.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
268 m_DateTo.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
270 m_staticRef.SetURL(CString());
272 // resizable stuff
273 AddAnchor(IDC_STATIC_REF, TOP_LEFT);
274 //AddAnchor(IDC_BUTTON_BROWSE_REF, TOP_LEFT);
275 AddAnchor(IDC_FROMLABEL, TOP_LEFT);
276 AddAnchor(IDC_DATEFROM, TOP_LEFT);
277 AddAnchor(IDC_TOLABEL, TOP_LEFT);
278 AddAnchor(IDC_DATETO, TOP_LEFT);
280 SetFilterCueText();
281 AddAnchor(IDC_SEARCHEDIT, TOP_LEFT, TOP_RIGHT);
283 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
284 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
285 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
286 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
287 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
289 AddAnchor(IDC_LOGINFO, BOTTOM_LEFT, BOTTOM_RIGHT);
290 AddAnchor(IDC_HIDEPATHS, BOTTOM_LEFT);
291 AddAnchor(IDC_LOG_ALLBRANCH,BOTTOM_LEFT);
292 AddAnchor(IDC_LOG_FIRSTPARENT, BOTTOM_LEFT);
293 //AddAnchor(IDC_GETALL, BOTTOM_LEFT);
294 AddAnchor(IDC_SHOWWHOLEPROJECT, BOTTOM_LEFT);
295 AddAnchor(IDC_REFRESH, BOTTOM_LEFT);
296 AddAnchor(IDC_STATBUTTON, BOTTOM_RIGHT);
297 AddAnchor(IDC_PROGRESS, BOTTOM_LEFT, BOTTOM_RIGHT);
298 AddAnchor(IDOK, BOTTOM_RIGHT);
299 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
300 AddAnchor(IDHELP, BOTTOM_RIGHT);
302 if(this->m_bAllBranch)
303 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
304 else
305 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
307 // SetPromptParentWindow(m_hWnd);
309 if (hWndExplorer)
310 CenterWindow(CWnd::FromHandle(hWndExplorer));
311 EnableSaveRestore(_T("LogDlg"));
313 DWORD yPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
314 DWORD yPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
315 RECT rcDlg, rcLogList, rcChgMsg;
316 GetClientRect(&rcDlg);
317 m_LogList.GetWindowRect(&rcLogList);
318 ScreenToClient(&rcLogList);
319 m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg);
320 ScreenToClient(&rcChgMsg);
321 if (yPos1)
323 RECT rectSplitter;
324 m_wndSplitter1.GetWindowRect(&rectSplitter);
325 ScreenToClient(&rectSplitter);
326 int delta = yPos1 - rectSplitter.top;
328 if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30))
330 m_wndSplitter1.SetWindowPos(NULL, 0, yPos1, 0, 0, SWP_NOSIZE);
331 DoSizeV1(delta);
334 if (yPos2)
336 RECT rectSplitter;
337 m_wndSplitter2.GetWindowRect(&rectSplitter);
338 ScreenToClient(&rectSplitter);
339 int delta = yPos2 - rectSplitter.top;
341 if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30))
343 m_wndSplitter2.SetWindowPos(NULL, 0, yPos2, 0, 0, SWP_NOSIZE);
344 DoSizeV2(delta);
349 if (m_bSelect)
351 // the dialog is used to select revisions
352 // enable the OK button if appropriate
353 EnableOKButton();
355 else
357 // the dialog is used to just view log messages
358 // hide the OK button and set text on Cancel button to OK
359 GetDlgItemText(IDOK, temp);
360 SetDlgItemText(IDCANCEL, temp);
361 GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
364 m_mergedRevs.clear();
366 // first start a thread to obtain the log messages without
367 // blocking the dialog
368 //m_tTo = 0;
369 //m_tFrom = (DWORD)-1;
371 // scroll to user selected or current revision
372 if (!m_hightlightRevision.IsEmpty() && m_hightlightRevision.GetLength() >= GIT_HASH_SIZE)
373 m_LogList.m_lastSelectedHash = m_hightlightRevision;
374 else if (!m_LogList.m_endrev.IsEmpty() && m_LogList.m_endrev.GetLength() >= GIT_HASH_SIZE)
375 m_LogList.m_lastSelectedHash = m_hightlightRevision;
376 else
377 m_LogList.m_lastSelectedHash = g_Git.GetHash(_T("HEAD"));
379 m_LogList.FetchLogAsync(this);
381 GetDlgItem(IDC_LOGLIST)->SetFocus();
383 ShowStartRef();
384 return FALSE;
387 LRESULT CLogDlg::OnLogListLoading(WPARAM wParam, LPARAM /*lParam*/)
389 int cur=(int)wParam;
391 if( cur == GITLOG_START )
393 CString temp;
394 temp.LoadString(IDS_PROGRESSWAIT);
396 this->m_LogList.ShowText(temp, true);
398 // We use a progress bar while getting the logs
399 m_LogProgress.SetRange32(0, 100);
400 m_LogProgress.SetPos(0);
401 if (m_pTaskbarList)
403 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
404 m_pTaskbarList->SetProgressValue(m_hWnd, 0, 100);
407 GetDlgItem(IDC_PROGRESS)->ShowWindow(TRUE);
409 //DialogEnableWindow(IDC_GETALL, FALSE);
410 //DialogEnableWindow(IDC_SHOWWHOLEPROJECT, FALSE);
411 //DialogEnableWindow(IDC_LOG_FIRSTPARENT, FALSE);
412 DialogEnableWindow(IDC_STATBUTTON, FALSE);
413 //DialogEnableWindow(IDC_REFRESH, FALSE);
414 DialogEnableWindow(IDC_HIDEPATHS,FALSE);
417 else if( cur == GITLOG_END)
419 if(this->m_LogList.HasText())
421 this->m_LogList.ClearText();
423 UpdateLogInfoLabel();
425 if (m_pTaskbarList)
426 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
428 //if (!m_bShowedAll)
429 DialogEnableWindow(IDC_SHOWWHOLEPROJECT, TRUE);
431 //DialogEnableWindow(IDC_GETALL, TRUE);
432 DialogEnableWindow(IDC_STATBUTTON, !(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC));
433 DialogEnableWindow(IDC_REFRESH, TRUE);
434 DialogEnableWindow(IDC_HIDEPATHS,TRUE);
436 // PostMessage(WM_TIMER, LOGFILTER_TIMER);
437 GetDlgItem(IDC_PROGRESS)->ShowWindow(FALSE);
438 //CTime time=m_LogList.GetOldestTime();
439 CTime begin,end;
440 m_LogList.GetTimeRange(begin,end);
442 if(m_LogList.m_From == -1)
443 m_DateFrom.SetTime(&begin);
445 if(m_LogList.m_To == -1)
446 m_DateTo.SetTime(&end);
450 else
452 if(this->m_LogList.HasText())
454 this->m_LogList.ClearText();
455 this->m_LogList.Invalidate();
457 UpdateLogInfoLabel();
458 m_LogProgress.SetPos(cur);
459 if (m_pTaskbarList)
461 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
462 m_pTaskbarList->SetProgressValue(m_hWnd, cur, 100);
465 return 0;
467 void CLogDlg::SetDlgTitle()
469 if (m_sTitle.IsEmpty())
470 GetWindowText(m_sTitle);
472 if (m_LogList.m_Path.IsEmpty() || m_orgPath.GetWinPathString().IsEmpty())
474 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
476 else
477 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);
480 void CLogDlg::CheckRegexpTooltip()
482 CWnd *pWnd = GetDlgItem(IDC_SEARCHEDIT);
483 // Since tooltip describes regexp features, show it only if regexps are enabled.
484 if (m_bFilterWithRegex)
486 m_tooltips.AddTool(pWnd, IDS_LOG_FILTER_REGEX_TT);
488 else
489 m_tooltips.DelTool(pWnd);
492 void CLogDlg::EnableOKButton()
494 if (m_bSelect)
496 // the dialog is used to select revisions
497 if (m_bSelectionMustBeSingle)
499 // enable OK button if only a single revision is selected
500 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()==1));
502 else if (m_bSelectionMustBeContinuous)
503 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));
504 else
505 DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);
507 else
508 DialogEnableWindow(IDOK, TRUE);
511 CString CLogDlg::GetTagInfo(GitRev* pLogEntry)
513 CString cmd;
514 CString output;
516 if(m_LogList.m_HashMap.find(pLogEntry->m_CommitHash) != m_LogList.m_HashMap.end())
518 STRING_VECTOR &vector = m_LogList.m_HashMap[pLogEntry->m_CommitHash];
519 for(int i=0;i<vector.size();i++)
521 if(vector[i].Find(_T("refs/tags/")) == 0 )
523 CString tag= vector[i];
524 int start = vector[i].Find(_T("^{}"));
525 if(start>0)
526 tag=tag.Left(start);
527 else
528 continue;
530 cmd.Format(_T("git.exe cat-file tag %s"), tag);
532 if(g_Git.Run(cmd, &output, NULL, CP_UTF8) == 0 )
533 output+=_T("\n");
538 if(!output.IsEmpty())
540 output = _T("\n*Tag Info*\n\n") + output;
543 return output;
546 void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)
548 // we fill here the log message rich edit control,
549 // and also populate the changed files list control
550 // according to the selected revision(s).
552 CRichEditCtrl * pMsgView = (CRichEditCtrl*)GetDlgItem(IDC_MSGVIEW);
553 // empty the log message view
554 pMsgView->SetWindowText(_T(" "));
555 // empty the changed files list
556 m_ChangedFileListCtrl.SetRedraw(FALSE);
557 // InterlockedExchange(&m_bNoDispUpdates, TRUE);
558 m_currentChangedArray = NULL;
559 //m_ChangedFileListCtrl.SetExtendedStyle ( LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER );
560 m_ChangedFileListCtrl.DeleteAllItems();
562 // if we're not here to really show a selected revision, just
563 // get out of here after clearing the views, which is what is intended
564 // if that flag is not set.
565 if (!bShow)
567 // force a redraw
568 m_ChangedFileListCtrl.Invalidate();
569 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
570 m_ChangedFileListCtrl.SetRedraw(TRUE);
571 return;
574 // depending on how many revisions are selected, we have to do different
575 // tasks.
576 int selCount = m_LogList.GetSelectedCount();
577 if (selCount == 0)
579 // if nothing is selected, we have nothing more to do
580 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
581 m_ChangedFileListCtrl.SetRedraw(TRUE);
582 return;
584 else if (selCount == 1)
586 // if one revision is selected, we have to fill the log message view
587 // with the corresponding log message, and also fill the changed files
588 // list fully.
589 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
590 int selIndex = m_LogList.GetNextSelectedItem(pos);
591 if (selIndex >= m_LogList.m_arShownList.GetCount())
593 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
594 m_ChangedFileListCtrl.SetRedraw(TRUE);
595 return;
597 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
600 // set the log message text
601 pMsgView->SetWindowText(_T("Commit:")+pLogEntry->m_CommitHash.ToString()+_T("\r\n\r\n"));
602 // turn bug ID's into links if the bugtraq: properties have been set
603 // and we can find a match of those in the log message
605 pMsgView->SetSel(-1,-1);
606 CHARFORMAT2 format;
607 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
608 format.cbSize = sizeof(CHARFORMAT2);
609 format.dwMask = CFM_BOLD;
610 format.dwEffects = CFE_BOLD;
611 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
613 CString msg=_T("* ");
614 msg+=pLogEntry->GetSubject();
615 pMsgView->ReplaceSel(msg);
617 pMsgView->SetSel(-1,-1);
618 format.dwEffects = 0;
619 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
621 msg=_T("\n");
622 msg+=pLogEntry->GetBody();
624 if(!pLogEntry->m_Notes.IsEmpty())
626 msg+= _T("\n*Notes* ");
627 msg+= pLogEntry->m_Notes;
628 msg+= _T("\n\n");
631 msg+=GetTagInfo(pLogEntry);
633 pMsgView->ReplaceSel(msg);
635 CString text;
636 pMsgView->GetWindowText(text);
637 // the rich edit control doesn't count the CR char!
638 // to be exact: CRLF is treated as one char.
639 text.Remove('\r');
641 m_LogList.m_ProjectProperties.FindBugID(text, pMsgView);
642 CAppUtils::FormatTextInRichEditControl(pMsgView);
644 int HidePaths=m_cHidePaths.GetState() & 0x0003;
645 CString matchpath=this->m_path.GetGitPathString();
647 int count = pLogEntry->GetFiles(&m_LogList).GetCount();
648 for(int i=0;i<count && (!matchpath.IsEmpty());i++)
650 if( m_bWholeProject )
651 break;
653 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action &= ~(CTGitPath::LOGACTIONS_HIDE|CTGitPath::LOGACTIONS_GRAY);
655 if(pLogEntry->GetFiles(&m_LogList)[i].GetGitPathString().Left(matchpath.GetLength()) != matchpath)
657 if(HidePaths==BST_CHECKED)
658 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;
659 if(HidePaths==BST_INDETERMINATE)
660 ((CTGitPath&)pLogEntry->GetFiles(&m_LogList)[i]).m_Action |= CTGitPath::LOGACTIONS_GRAY;
664 m_ChangedFileListCtrl.UpdateWithGitPathList(pLogEntry->GetFiles(&m_LogList));
665 m_ChangedFileListCtrl.m_CurrentVersion=pLogEntry->m_CommitHash;
666 m_ChangedFileListCtrl.Show(GITSLC_SHOWVERSIONED);
668 m_ChangedFileListCtrl.SetBusyString(_T("Fetch Changed File..."));
670 if(!pLogEntry->m_IsDiffFiles)
671 m_ChangedFileListCtrl.SetBusy(TRUE);
672 else
673 m_ChangedFileListCtrl.SetBusy(FALSE);
675 m_ChangedFileListCtrl.SetRedraw(TRUE);
676 return;
680 else
682 // more than one revision is selected:
683 // the log message view must be emptied
684 // the changed files list contains all the changed paths from all
685 // selected revisions, with 'doubles' removed
686 m_currentChangedPathList = GetChangedPathsFromSelectedRevisions(true);
689 // redraw the views
690 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
691 #if 0
692 if (m_currentChangedArray)
694 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedArray->GetCount());
695 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedArray->GetCount());
697 else if (m_currentChangedPathList.GetCount())
699 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedPathList.GetCount());
700 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedPathList.GetCount());
702 else
704 m_ChangedFileListCtrl.SetItemCountEx(0);
705 m_ChangedFileListCtrl.Invalidate();
707 #endif
708 // sort according to the settings
709 if (m_nSortColumnPathList > 0)
710 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
711 else
712 SetSortArrow(&m_ChangedFileListCtrl, -1, false);
713 m_ChangedFileListCtrl.SetRedraw(TRUE);
717 void CLogDlg::OnBnClickedRefresh()
719 Refresh (true);
722 void CLogDlg::Refresh (bool clearfilter /*autoGoOnline*/)
724 m_limit = 0;
725 m_LogList.Refresh(clearfilter);
726 FillLogMessageCtrl(false);
731 BOOL CLogDlg::Cancel()
733 return m_bCancelled;
736 void CLogDlg::SaveSplitterPos()
738 if (!IsIconic())
740 CRegDWORD regPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
741 CRegDWORD regPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
742 RECT rectSplitter;
743 m_wndSplitter1.GetWindowRect(&rectSplitter);
744 ScreenToClient(&rectSplitter);
745 regPos1 = rectSplitter.top;
746 m_wndSplitter2.GetWindowRect(&rectSplitter);
747 ScreenToClient(&rectSplitter);
748 regPos2 = rectSplitter.top;
752 void CLogDlg::OnCancel()
754 this->ShowWindow(SW_HIDE);
756 // canceling means stopping the working thread if it's still running.
757 m_LogList.SafeTerminateAsyncDiffThread();
758 if (this->IsThreadRunning())
760 m_LogList.SafeTerminateThread();
762 UpdateData();
764 SaveSplitterPos();
765 __super::OnCancel();
768 CString CLogDlg::MakeShortMessage(const CString& message)
770 bool bFoundShort = true;
771 CString sShortMessage = m_LogList.m_ProjectProperties.GetLogSummary(message);
772 if (sShortMessage.IsEmpty())
774 bFoundShort = false;
775 sShortMessage = message;
777 // Remove newlines and tabs 'cause those are not shown nicely in the list control
778 sShortMessage.Remove('\r');
779 sShortMessage.Replace(_T('\t'), _T(' '));
781 // Suppose the first empty line separates 'summary' from the rest of the message.
782 int found = sShortMessage.Find(_T("\n\n"));
783 // To avoid too short 'short' messages
784 // (e.g. if the message looks something like "Bugfix:\n\n*done this\n*done that")
785 // only use the empty newline as a separator if it comes after at least 15 chars.
786 if ((!bFoundShort)&&(found >= 15))
788 sShortMessage = sShortMessage.Left(found);
790 sShortMessage.Replace('\n', ' ');
791 return sShortMessage;
794 BOOL CLogDlg::Log(git_revnum_t /*rev*/, const CString& /*author*/, const CString& /*date*/, const CString& /*message*/, LogChangedPathArray * /*cpaths*/, int /*filechanges*/, BOOL /*copies*/, DWORD /*actions*/, BOOL /*haschildren*/)
796 #if 0
797 if (rev == SVN_INVALID_REVNUM)
799 m_childCounter--;
800 return TRUE;
803 // this is the callback function which receives the data for every revision we ask the log for
804 // we store this information here one by one.
805 m_logcounter += 1;
806 if (m_startrev == -1)
807 m_startrev = rev;
808 if (m_limit != 0)
810 m_limitcounter--;
811 m_LogProgress.SetPos(m_limit - m_limitcounter);
813 else if (m_startrev.IsNumber() && m_startrev.IsNumber())
814 m_LogProgress.SetPos((git_revnum_t)m_startrev-rev+(git_revnum_t)m_endrev);
815 __time64_t ttime = time/1000000L;
816 if (m_tTo < (DWORD)ttime)
817 m_tTo = (DWORD)ttime;
818 if (m_tFrom > (DWORD)ttime)
819 m_tFrom = (DWORD)ttime;
820 if ((m_lowestRev > rev)||(m_lowestRev < 0))
821 m_lowestRev = rev;
822 // Add as many characters from the log message to the list control
823 PLOGENTRYDATA pLogItem = new LOGENTRYDATA;
824 pLogItem->bCopies = !!copies;
826 // find out if this item was copied in the revision
827 BOOL copiedself = FALSE;
828 if (copies)
830 for (INT_PTR cpPathIndex = 0; cpPathIndex < cpaths->GetCount(); ++cpPathIndex)
832 LogChangedPath * cpath = cpaths->SafeGetAt(cpPathIndex);
833 if (!cpath->sCopyFromPath.IsEmpty() && (cpath->sPath.Compare(m_sSelfRelativeURL) == 0))
835 // note: this only works if the log is fetched top-to-bottom
836 // but since we do that, it shouldn't be a problem
837 m_sSelfRelativeURL = cpath->sCopyFromPath;
838 copiedself = TRUE;
839 break;
843 pLogItem->bCopiedSelf = copiedself;
844 pLogItem->tmDate = ttime;
845 pLogItem->sAuthor = author;
846 pLogItem->sDate = date;
847 pLogItem->sShortMessage = MakeShortMessage(message);
848 pLogItem->dwFileChanges = filechanges;
849 pLogItem->actions = actions;
850 pLogItem->haschildren = haschildren;
851 pLogItem->childStackDepth = m_childCounter;
852 m_maxChild = max(m_childCounter, m_maxChild);
853 if (haschildren)
854 m_childCounter++;
855 pLogItem->sBugIDs = m_ProjectProperties.FindBugID(message).Trim();
857 // split multi line log entries and concatenate them
858 // again but this time with \r\n as line separators
859 // so that the edit control recognizes them
862 if (message.GetLength()>0)
864 m_sMessageBuf = message;
865 m_sMessageBuf.Replace(_T("\n\r"), _T("\n"));
866 m_sMessageBuf.Replace(_T("\r\n"), _T("\n"));
867 if (m_sMessageBuf.Right(1).Compare(_T("\n"))==0)
868 m_sMessageBuf = m_sMessageBuf.Left(m_sMessageBuf.GetLength()-1);
870 else
871 m_sMessageBuf.Empty();
872 pLogItem->sMessage = m_sMessageBuf;
873 pLogItem->Rev = rev;
875 // move-construct path array
877 pLogItem->pArChangedPaths = new LogChangedPathArray (*cpaths);
878 cpaths->RemoveAll();
880 catch (CException * e)
882 ::MessageBox(NULL, _T("not enough memory!"), _T("TortoiseGit"), MB_ICONERROR);
883 e->Delete();
884 m_bCancelled = TRUE;
886 m_logEntries.push_back(pLogItem);
887 m_arShownList.Add(pLogItem);
888 #endif
889 return TRUE;
892 GitRev g_rev;
893 //this is the thread function which calls the subversion function
898 void CLogDlg::CopyChangedSelectionToClipBoard()
901 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
902 if (pos == NULL)
903 return; // nothing is selected, get out of here
905 CString sPaths;
907 // CGitRev* pLogEntry = reinterpret_cast<CGitRev* >(m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
908 // if (pos)
910 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
911 while (pos)
913 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
914 CTGitPath *path = (CTGitPath*)m_ChangedFileListCtrl.GetItemData(nItem);
915 if(path)
916 sPaths += path->GetGitPathString();
917 sPaths += _T("\r\n");
920 #if 0
921 else
923 // only one revision is selected in the log dialog top pane
924 // but multiple items could be selected in the changed items list
925 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
926 while (pos)
928 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
929 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(nItem);
931 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
933 // some items are hidden! So find out which item the user really selected
934 INT_PTR selRealIndex = -1;
935 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
937 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
938 selRealIndex++;
939 if (selRealIndex == nItem)
941 changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex);
942 break;
946 if (changedlogpath)
948 sPaths += changedlogpath->sPath;
949 sPaths += _T("\r\n");
953 #endif
954 sPaths.Trim();
955 CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());
959 BOOL CLogDlg::IsDiffPossible(LogChangedPath * /*changedpath*/, git_revnum_t rev)
961 #if 0
962 CString added, deleted;
963 if (changedpath == NULL)
964 return false;
966 if ((rev > 1)&&(changedpath->action != LOGACTIONS_DELETED))
968 if (changedpath->action == LOGACTIONS_ADDED) // file is added
970 if (changedpath->lCopyFromRev == 0)
971 return FALSE; // but file was not added with history
973 return TRUE;
975 #endif
976 return FALSE;
979 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)
981 // we have two separate context menus:
982 // one shown on the log message list control,
983 // the other shown in the changed-files list control
984 int selCount = m_LogList.GetSelectedCount();
985 if (pWnd == &m_LogList)
987 //ShowContextMenuForRevisions(pWnd, point);
989 else if (pWnd == &m_ChangedFileListCtrl)
991 //ShowContextMenuForChangedpaths(pWnd, point);
993 else if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))
995 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
996 int selIndex = -1;
997 if (pos)
998 selIndex = m_LogList.GetNextSelectedItem(pos);
1000 GitRev *pRev = ((GitRev*)m_LogList.m_arShownList[selIndex]);
1002 if ((point.x == -1) && (point.y == -1))
1004 CRect rect;
1005 GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);
1006 ClientToScreen(&rect);
1007 point = rect.CenterPoint();
1009 CString sMenuItemText;
1010 CIconMenu popup;
1011 if (popup.CreatePopupMenu())
1013 // add the 'default' entries
1014 sMenuItemText.LoadString(IDS_SCIEDIT_COPY);
1015 popup.AppendMenu(MF_STRING | MF_ENABLED, WM_COPY, sMenuItemText);
1016 sMenuItemText.LoadString(IDS_SCIEDIT_SELECTALL);
1017 popup.AppendMenu(MF_STRING | MF_ENABLED, EM_SETSEL, sMenuItemText);
1018 sMenuItemText.LoadString(IDS_EDIT_NOTES);
1019 popup.AppendMenuIcon( CGitLogList::ID_EDITNOTE, sMenuItemText, IDI_EDIT);
1021 //if (selIndex >= 0)
1023 // popup.AppendMenu(MF_SEPARATOR);
1024 // sMenuItemText.LoadString(IDS_LOG_POPUP_EDITLOG);
1025 // popup.AppendMenu(MF_STRING | MF_ENABLED, CGitLogList::ID_EDITAUTHOR, sMenuItemText);
1028 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1029 switch (cmd)
1031 case 0:
1032 break; // no command selected
1033 case EM_SETSEL:
1034 case WM_COPY:
1035 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);
1036 break;
1037 case CGitLogList::ID_EDITNOTE:
1038 CAppUtils::EditNote(pRev);
1039 this->FillLogMessageCtrl(true);
1040 break;
1046 void CLogDlg::OnOK()
1048 // since the log dialog is also used to select revisions for other
1049 // dialogs, we have to do some work before closing this dialog
1050 if (GetFocus() != GetDlgItem(IDOK))
1051 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter
1053 m_LogList.SafeTerminateAsyncDiffThread();
1054 if (this->IsThreadRunning())
1056 m_LogList.SafeTerminateThread();
1058 UpdateData();
1059 // check that one and only one row is selected
1060 if (m_LogList.GetSelectedCount() == 1)
1062 // get the selected row
1063 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1064 int selIndex = m_LogList.GetNextSelectedItem(pos);
1065 if (selIndex < m_LogList.m_arShownList.GetCount())
1067 // all ok, pick up the revision
1068 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(selIndex));
1069 // extract the hash
1070 m_sSelectedHash = pLogEntry->m_CommitHash;
1073 UpdateData(FALSE);
1074 SaveSplitterPos();
1075 __super::OnOK();
1077 #if 0
1078 if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))
1079 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.
1081 CString temp;
1082 CString buttontext;
1083 GetDlgItemText(IDOK, buttontext);
1084 temp.LoadString(IDS_MSGBOX_CANCEL);
1085 if (temp.Compare(buttontext) != 0)
1086 __super::OnOK(); // only exit if the button text matches, and that will match only if the thread isn't running anymore
1087 m_bCancelled = TRUE;
1088 m_selectedRevs.Clear();
1089 m_selectedRevsOneRange.Clear();
1090 if (m_pNotifyWindow)
1092 int selIndex = m_LogList.GetSelectionMark();
1093 if (selIndex >= 0)
1095 PLOGENTRYDATA pLogEntry = NULL;
1096 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1097 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1098 m_selectedRevs.AddRevision(pLogEntry->Rev);
1099 git_revnum_t lowerRev = pLogEntry->Rev;
1100 git_revnum_t higherRev = lowerRev;
1101 while (pos)
1103 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1104 git_revnum_t rev = pLogEntry->Rev;
1105 m_selectedRevs.AddRevision(pLogEntry->Rev);
1106 if (lowerRev > rev)
1107 lowerRev = rev;
1108 if (higherRev < rev)
1109 higherRev = rev;
1111 if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())
1113 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);
1115 BOOL bSentMessage = FALSE;
1116 if (m_LogList.GetSelectedCount() == 1)
1118 // if only one revision is selected, check if the path/url with which the dialog was started
1119 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.
1120 // if it was copied, use the copy from revision as lowerRev
1121 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))
1123 CString sUrl = m_path.GetGitPathString();
1124 if (!m_path.IsUrl())
1126 sUrl = GetURLFromPath(m_path);
1128 sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());
1129 for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)
1131 LogChangedPath * pData = pLogEntry->pArChangedPaths->SafeGetAt(cp);
1132 if (pData)
1134 if (sUrl.Compare(pData->sPath) == 0)
1136 if (!pData->sCopyFromPath.IsEmpty())
1138 lowerRev = pData->lCopyFromRev;
1139 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);
1140 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);
1141 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1142 bSentMessage = TRUE;
1149 if ( !bSentMessage )
1151 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);
1152 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);
1153 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1154 if (m_selectedRevsOneRange.GetCount())
1155 m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);
1159 UpdateData();
1160 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry"));
1161 reg = m_btnShow.GetCurrentEntry();
1162 SaveSplitterPos();
1163 #endif
1166 void CLogDlg::OnNMDblclkChangedFileList(NMHDR * /*pNMHDR*/, LRESULT *pResult)
1168 // a double click on an entry in the changed-files list has happened
1169 *pResult = 0;
1171 DiffSelectedFile();
1174 void CLogDlg::DiffSelectedFile()
1176 #if 0
1177 if (m_bThreadRunning)
1178 return;
1179 UpdateLogInfoLabel();
1180 INT_PTR selIndex = m_ChangedFileListCtrl.GetSelectionMark();
1181 if (selIndex < 0)
1182 return;
1183 if (m_ChangedFileListCtrl.GetSelectedCount() == 0)
1184 return;
1185 // find out if there's an entry selected in the log list
1186 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1187 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1188 git_revnum_t rev1 = pLogEntry->Rev;
1189 git_revnum_t rev2 = rev1;
1190 if (pos)
1192 while (pos)
1194 // there's at least a second entry selected in the log list: several revisions selected!
1195 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1196 if (pLogEntry)
1198 rev1 = max(rev1,(long)pLogEntry->Rev);
1199 rev2 = min(rev2,(long)pLogEntry->Rev);
1202 rev2--;
1203 // now we have both revisions selected in the log list, so we can do a diff of the selected
1204 // entry in the changed files list with these two revisions.
1205 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1207 else
1209 rev2 = rev1-1;
1210 // nothing or only one revision selected in the log list
1211 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
1213 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
1215 // some items are hidden! So find out which item the user really clicked on
1216 INT_PTR selRealIndex = -1;
1217 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
1219 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1220 selRealIndex++;
1221 if (selRealIndex == selIndex)
1223 selIndex = hiddenindex;
1224 changedpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
1225 break;
1230 if (IsDiffPossible(changedpath, rev1))
1232 // diffs with renamed files are possible
1233 if ((changedpath)&&(!changedpath->sCopyFromPath.IsEmpty()))
1234 rev2 = changedpath->lCopyFromRev;
1235 else
1237 // if the path was modified but the parent path was 'added with history'
1238 // then we have to use the copy from revision of the parent path
1239 CTGitPath cpath = CTGitPath(changedpath->sPath);
1240 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
1242 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->SafeGetAt(flist)->sPath);
1243 if (p.IsAncestorOf(cpath))
1245 if (!pLogEntry->pArChangedPaths->SafeGetAt(flist)->sCopyFromPath.IsEmpty())
1246 rev2 = pLogEntry->pArChangedPaths->SafeGetAt(flist)->lCopyFromRev;
1250 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1252 else
1254 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1255 CTGitPath tempfile2 = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1256 GitRev r = rev1;
1257 // deleted files must be opened from the revision before the deletion
1258 if (changedpath->action == LOGACTIONS_DELETED)
1259 r = rev1-1;
1260 m_bCancelled = false;
1262 CProgressDlg progDlg;
1263 progDlg.SetTitle(IDS_APPNAME);
1264 progDlg.SetAnimation(IDR_DOWNLOAD);
1265 CString sInfoLine;
1266 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)(m_sRepositoryRoot + changedpath->sPath), (LPCTSTR)r.ToString());
1267 progDlg.SetLine(1, sInfoLine, true);
1268 SetAndClearProgressInfo(&progDlg);
1269 progDlg.ShowModeless(m_hWnd);
1271 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), r, r, tempfile))
1273 m_bCancelled = false;
1274 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), GitRev::REV_HEAD, r, tempfile))
1276 progDlg.Stop();
1277 SetAndClearProgressInfo((HWND)NULL);
1278 CMessageBox::Show(m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1279 return;
1282 progDlg.Stop();
1283 SetAndClearProgressInfo((HWND)NULL);
1285 CString sName1, sName2;
1286 sName1.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1);
1287 sName2.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1-1);
1288 CAppUtils::DiffFlags flags;
1289 flags.AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1290 if (changedpath->action == LOGACTIONS_DELETED)
1291 CAppUtils::StartExtDiff(tempfile, tempfile2, sName2, sName1, flags);
1292 else
1293 CAppUtils::StartExtDiff(tempfile2, tempfile, sName2, sName1, flags);
1296 #endif
1300 void CLogDlg::DoDiffFromLog(INT_PTR selIndex, GitRev* rev1, GitRev* rev2, bool /*blame*/, bool /*unified*/)
1302 DialogEnableWindow(IDOK, FALSE);
1303 // SetPromptApp(&theApp);
1304 theApp.DoWaitCursor(1);
1306 CString temppath;
1307 GetTempPath(temppath);
1309 CString file1;
1310 file1.Format(_T("%s%s_%s%s"),
1311 temppath,
1312 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1313 rev1->m_CommitHash.ToString().Left(6),
1314 (*m_currentChangedArray)[selIndex].GetFileExtension());
1316 CString file2;
1317 file2.Format(_T("%s\\%s_%s%s"),
1318 temppath,
1319 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1320 rev2->m_CommitHash.ToString().Left(6),
1321 (*m_currentChangedArray)[selIndex].GetFileExtension());
1323 CString cmd;
1325 g_Git.GetOneFile(rev1->m_CommitHash.ToString(), (CTGitPath &)(*m_currentChangedArray)[selIndex],file1);
1327 g_Git.GetOneFile(rev2->m_CommitHash.ToString(), (CTGitPath &)(*m_currentChangedArray)[selIndex],file2);
1329 CAppUtils::DiffFlags flags;
1330 CAppUtils::StartExtDiff(file1,file2,_T("A"),_T("B"),flags);
1332 #if 0
1333 //get the filename
1334 CString filepath;
1335 if (Git::PathIsURL(m_path))
1337 filepath = m_path.GetGitPathString();
1339 else
1341 filepath = GetURLFromPath(m_path);
1342 if (filepath.IsEmpty())
1344 theApp.DoWaitCursor(-1);
1345 CString temp;
1346 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1347 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1348 TRACE(_T("could not retrieve the URL of the file!\n"));
1349 EnableOKButton();
1350 theApp.DoWaitCursor(-11);
1351 return; //exit
1354 m_bCancelled = FALSE;
1355 filepath = GetRepositoryRoot(CTGitPath(filepath));
1357 CString firstfile, secondfile;
1358 if (m_LogList.GetSelectedCount()==1)
1360 int s = m_LogList.GetSelectionMark();
1361 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(s));
1362 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
1363 firstfile = changedpath->sPath;
1364 secondfile = firstfile;
1365 if ((rev2 == rev1-1)&&(changedpath->lCopyFromRev > 0)) // is it an added file with history?
1367 secondfile = changedpath->sCopyFromPath;
1368 rev2 = changedpath->lCopyFromRev;
1371 else
1373 firstfile = m_currentChangedPathList[selIndex].GetGitPathString();
1374 secondfile = firstfile;
1377 firstfile = filepath + firstfile.Trim();
1378 secondfile = filepath + secondfile.Trim();
1380 GitDiff diff(this, this->m_hWnd, true);
1381 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1382 diff.SetHEADPeg(m_LogRevision);
1383 if (unified)
1385 if (PromptShown())
1386 diff.ShowUnifiedDiff(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1);
1387 else
1388 CAppUtils::StartShowUnifiedDiff(m_hWnd, CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), m_LogRevision);
1390 else
1392 if (diff.ShowCompare(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), false, blame))
1394 if (firstfile.Compare(secondfile)==0)
1396 git_revnum_t baseRev = 0;
1397 diff.DiffProps(CTGitPath(firstfile), rev2, rev1, baseRev);
1402 #endif
1404 theApp.DoWaitCursor(-1);
1405 EnableOKButton();
1408 BOOL CLogDlg::Open(bool /*bOpenWith*/,CString changedpath, git_revnum_t rev)
1410 #if 0
1411 DialogEnableWindow(IDOK, FALSE);
1412 SetPromptApp(&theApp);
1413 theApp.DoWaitCursor(1);
1414 CString filepath;
1415 if (Git::PathIsURL(m_path))
1417 filepath = m_path.GetGitPathString();
1419 else
1421 filepath = GetURLFromPath(m_path);
1422 if (filepath.IsEmpty())
1424 theApp.DoWaitCursor(-1);
1425 CString temp;
1426 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1427 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1428 TRACE(_T("could not retrieve the URL of the file!\n"));
1429 EnableOKButton();
1430 return FALSE;
1433 m_bCancelled = false;
1434 filepath = GetRepositoryRoot(CTGitPath(filepath));
1435 filepath += changedpath;
1437 CProgressDlg progDlg;
1438 progDlg.SetTitle(IDS_APPNAME);
1439 progDlg.SetAnimation(IDR_DOWNLOAD);
1440 CString sInfoLine;
1441 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)GitRev(rev).ToString());
1442 progDlg.SetLine(1, sInfoLine, true);
1443 SetAndClearProgressInfo(&progDlg);
1444 progDlg.ShowModeless(m_hWnd);
1446 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(filepath), rev);
1447 m_bCancelled = false;
1448 if (!Cat(CTGitPath(filepath), GitRev(rev), rev, tempfile))
1450 progDlg.Stop();
1451 SetAndClearProgressInfo((HWND)NULL);
1452 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1453 EnableOKButton();
1454 theApp.DoWaitCursor(-1);
1455 return FALSE;
1457 progDlg.Stop();
1458 SetAndClearProgressInfo((HWND)NULL);
1459 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1460 if (!bOpenWith)
1462 int ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1463 if (ret <= HINSTANCE_ERROR)
1464 bOpenWith = true;
1466 if (bOpenWith)
1468 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1469 cmd += tempfile.GetWinPathString() + _T(" ");
1470 CAppUtils::LaunchApplication(cmd, NULL, false);
1472 EnableOKButton();
1473 theApp.DoWaitCursor(-1);
1474 #endif
1475 return TRUE;
1478 void CLogDlg::EditAuthor(const CLogDataVector& /*logs*/)
1480 #if 0
1481 CString url;
1482 CString name;
1483 if (logs.size() == 0)
1484 return;
1485 DialogEnableWindow(IDOK, FALSE);
1486 SetPromptApp(&theApp);
1487 theApp.DoWaitCursor(1);
1488 if (Git::PathIsURL(m_path))
1489 url = m_path.GetGitPathString();
1490 else
1492 url = GetURLFromPath(m_path);
1494 name = Git_PROP_REVISION_AUTHOR;
1496 CString value = RevPropertyGet(name, CTGitPath(url), logs[0]->Rev);
1497 CString sOldValue = value;
1498 value.Replace(_T("\n"), _T("\r\n"));
1499 CInputDlg dlg(this);
1500 dlg.m_sHintText.LoadString(IDS_LOG_AUTHOR);
1501 dlg.m_sInputText = value;
1502 dlg.m_sTitle.LoadString(IDS_LOG_AUTHOREDITTITLE);
1503 dlg.m_pProjectProperties = &m_ProjectProperties;
1504 dlg.m_bUseLogWidth = false;
1505 if (dlg.DoModal() == IDOK)
1507 dlg.m_sInputText.Remove('\r');
1509 LogCache::CCachedLogInfo* toUpdate = GetLogCache (CTGitPath (m_sRepositoryRoot));
1511 CProgressDlg progDlg;
1512 progDlg.SetTitle(IDS_APPNAME);
1513 progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));
1514 progDlg.SetTime(true);
1515 progDlg.SetShowProgressBar(true);
1516 progDlg.ShowModeless(m_hWnd);
1517 for (DWORD i=0; i<logs.size(); ++i)
1519 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), logs[i]->Rev))
1521 progDlg.Stop();
1522 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1523 break;
1525 else
1528 logs[i]->sAuthor = dlg.m_sInputText;
1529 m_LogList.Invalidate();
1531 // update the log cache
1533 if (toUpdate != NULL)
1535 // log caching is active
1537 LogCache::CCachedLogInfo newInfo;
1538 newInfo.Insert ( logs[i]->Rev
1539 , (const char*) CUnicodeUtils::GetUTF8 (logs[i]->sAuthor)
1540 , ""
1542 , LogCache::CRevisionInfoContainer::HAS_AUTHOR);
1544 toUpdate->Update (newInfo);
1547 progDlg.SetProgress64(i, logs.size());
1549 progDlg.Stop();
1551 theApp.DoWaitCursor(-1);
1552 EnableOKButton();
1553 #endif
1556 void CLogDlg::EditLogMessage(int /*index*/)
1559 #if 0
1560 CString url;
1561 CString name;
1562 DialogEnableWindow(IDOK, FALSE);
1563 SetPromptApp(&theApp);
1564 theApp.DoWaitCursor(1);
1565 if (Git::PathIsURL(m_path))
1566 url = m_path.GetGitPathString();
1567 else
1569 url = GetURLFromPath(m_path);
1571 name = Git_PROP_REVISION_LOG;
1573 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(index));
1574 m_bCancelled = FALSE;
1575 CString value = RevPropertyGet(name, CTGitPath(url), pLogEntry->Rev);
1576 CString sOldValue = value;
1577 value.Replace(_T("\n"), _T("\r\n"));
1578 CInputDlg dlg(this);
1579 dlg.m_sHintText.LoadString(IDS_LOG_MESSAGE);
1580 dlg.m_sInputText = value;
1581 dlg.m_sTitle.LoadString(IDS_LOG_MESSAGEEDITTITLE);
1582 dlg.m_pProjectProperties = &m_ProjectProperties;
1583 dlg.m_bUseLogWidth = true;
1584 if (dlg.DoModal() == IDOK)
1586 dlg.m_sInputText.Remove('\r');
1587 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), pLogEntry->Rev))
1589 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1591 else
1593 pLogEntry->sShortMessage = MakeShortMessage(dlg.m_sInputText);
1594 // split multi line log entries and concatenate them
1595 // again but this time with \r\n as line separators
1596 // so that the edit control recognizes them
1597 if (dlg.m_sInputText.GetLength()>0)
1599 m_sMessageBuf = dlg.m_sInputText;
1600 dlg.m_sInputText.Replace(_T("\n\r"), _T("\n"));
1601 dlg.m_sInputText.Replace(_T("\r\n"), _T("\n"));
1602 if (dlg.m_sInputText.Right(1).Compare(_T("\n"))==0)
1603 dlg.m_sInputText = dlg.m_sInputText.Left(dlg.m_sInputText.GetLength()-1);
1605 else
1606 dlg.m_sInputText.Empty();
1607 pLogEntry->sMessage = dlg.m_sInputText;
1608 pLogEntry->sBugIDs = m_ProjectProperties.FindBugID(dlg.m_sInputText);
1609 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
1610 pMsgView->SetWindowText(_T(" "));
1611 pMsgView->SetWindowText(dlg.m_sInputText);
1612 m_ProjectProperties.FindBugID(dlg.m_sInputText, pMsgView);
1613 m_LogList.Invalidate();
1615 // update the log cache
1616 LogCache::CCachedLogInfo* toUpdate = GetLogCache(CTGitPath (m_sRepositoryRoot));
1617 if (toUpdate != NULL)
1619 // log caching is active
1621 LogCache::CCachedLogInfo newInfo;
1622 newInfo.Insert( pLogEntry->Rev
1623 , ""
1624 , (const char*) CUnicodeUtils::GetUTF8 (pLogEntry->sMessage)
1626 , LogCache::CRevisionInfoContainer::HAS_COMMENT);
1628 toUpdate->Update(newInfo);
1632 theApp.DoWaitCursor(-1);
1633 EnableOKButton();
1634 #endif
1637 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)
1639 // Skip Ctrl-C when copying text out of the log message or search filter
1640 BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );
1641 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
1643 if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1645 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1647 m_LogList.DiffSelectedRevWithPrevious();
1648 return TRUE;
1652 if (m_hAccel && !bSkipAccelerator)
1654 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1655 if (ret)
1656 return TRUE;
1659 if(::IsWindow(m_tooltips.m_hWnd))
1660 m_tooltips.RelayEvent(pMsg);
1661 return __super::PreTranslateMessage(pMsg);
1665 BOOL CLogDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1667 //if (this->IsThreadRunning())
1668 if(m_LogList.m_bNoDispUpdates)
1670 // only show the wait cursor over the list control
1671 if ((pWnd)&&
1672 ((pWnd == GetDlgItem(IDC_LOGLIST))||
1673 (pWnd == GetDlgItem(IDC_MSGVIEW))||
1674 (pWnd == GetDlgItem(IDC_LOGMSG))))
1676 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1677 SetCursor(hCur);
1678 return TRUE;
1681 if ((pWnd) && (pWnd == GetDlgItem(IDC_MSGVIEW)))
1682 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1684 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1685 SetCursor(hCur);
1686 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1689 void CLogDlg::OnBnClickedHelp()
1691 OnHelp();
1694 void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1696 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1697 *pResult = 0;
1698 //if (this->IsThreadRunning())
1699 if(m_LogList.m_bNoDispUpdates)
1700 return;
1701 if (pNMLV->iItem >= 0)
1703 this->m_LogList.m_nSearchIndex = pNMLV->iItem;
1704 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(pNMLV->iItem));
1705 m_LogList.m_lastSelectedHash = pLogEntry->m_CommitHash;
1706 if (pNMLV->iSubItem != 0)
1707 return;
1708 if ((pNMLV->iItem == m_LogList.m_arShownList.GetCount()))
1710 // remove the selected state
1711 if (pNMLV->uChanged & LVIF_STATE)
1713 m_LogList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);
1714 FillLogMessageCtrl();
1715 UpdateData(FALSE);
1716 UpdateLogInfoLabel();
1718 return;
1720 if (pNMLV->uChanged & LVIF_STATE)
1722 FillLogMessageCtrl();
1723 UpdateData(FALSE);
1726 else
1728 m_LogList.m_lastSelectedHash.Empty();
1729 FillLogMessageCtrl();
1730 UpdateData(FALSE);
1732 EnableOKButton();
1733 UpdateLogInfoLabel();
1736 void CLogDlg::OnEnLinkMsgview(NMHDR *pNMHDR, LRESULT *pResult)
1738 ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);
1739 if (pEnLink->msg == WM_LBUTTONUP)
1741 CString url, msg;
1742 GetDlgItemText(IDC_MSGVIEW, msg);
1743 msg.Replace(_T("\r\n"), _T("\n"));
1744 url = msg.Mid(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax-pEnLink->chrg.cpMin);
1745 if (!::PathIsURL(url))
1747 url = m_LogList.m_ProjectProperties.GetBugIDUrl(url);
1748 url = GetAbsoluteUrlFromRelativeUrl(url);
1750 if (!url.IsEmpty())
1751 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
1753 *pResult = 0;
1756 class CDateSorter
1758 public:
1759 class CCommitPointer
1761 public:
1762 CCommitPointer():m_cont(NULL){}
1763 CCommitPointer(const CCommitPointer& P_Right)
1764 : m_cont(NULL)
1766 *this = P_Right;
1769 CCommitPointer& operator = (const CCommitPointer& P_Right)
1771 if(IsPointer())
1773 (*m_cont->m_parDates)[m_place] = P_Right.GetDate();
1774 (*m_cont->m_parFileChanges)[m_place] = P_Right.GetChanges();
1775 (*m_cont->m_parAuthors)[m_place] = P_Right.GetAuthor();
1777 else
1779 m_Date = P_Right.GetDate();
1780 m_Changes = P_Right.GetChanges();
1781 m_csAuthor = P_Right.GetAuthor();
1783 return *this;
1786 void Clone(const CCommitPointer& P_Right)
1788 m_cont = P_Right.m_cont;
1789 m_place = P_Right.m_place;
1790 m_Date = P_Right.m_Date;
1791 m_Changes = P_Right.m_Changes;
1792 m_csAuthor = P_Right.m_csAuthor;
1795 DWORD GetDate() const {return IsPointer() ? (*m_cont->m_parDates)[m_place] : m_Date;}
1796 DWORD GetChanges() const {return IsPointer() ? (*m_cont->m_parFileChanges)[m_place] : m_Changes;}
1797 CString GetAuthor() const {return IsPointer() ? (*m_cont->m_parAuthors)[m_place] : m_csAuthor;}
1799 bool IsPointer() const {return m_cont != NULL;}
1800 //When pointer
1801 CDateSorter* m_cont;
1802 int m_place;
1804 //When element
1805 DWORD m_Date;
1806 DWORD m_Changes;
1807 CString m_csAuthor;
1810 class iterator : public std::iterator<std::random_access_iterator_tag, CCommitPointer>
1812 public:
1813 CCommitPointer m_ptr;
1815 iterator(){}
1816 iterator(const iterator& P_Right){*this = P_Right;}
1817 iterator& operator=(const iterator& P_Right)
1819 m_ptr.Clone(P_Right.m_ptr);
1820 return *this;
1823 CCommitPointer& operator*(){return m_ptr;}
1824 CCommitPointer* operator->(){return &m_ptr;}
1825 const CCommitPointer& operator*()const{return m_ptr;}
1826 const CCommitPointer* operator->()const{return &m_ptr;}
1828 iterator& operator+=(size_t P_iOffset){m_ptr.m_place += P_iOffset;return *this;}
1829 iterator& operator-=(size_t P_iOffset){m_ptr.m_place -= P_iOffset;return *this;}
1830 iterator operator+(size_t P_iOffset)const{iterator it(*this); it += P_iOffset;return it;}
1831 iterator operator-(size_t P_iOffset)const{iterator it(*this); it -= P_iOffset;return it;}
1833 iterator& operator++(){++m_ptr.m_place;return *this;}
1834 iterator& operator--(){--m_ptr.m_place;return *this;}
1835 iterator operator++(int){iterator it(*this);++*this;return it;}
1836 iterator operator--(int){iterator it(*this);--*this;return it;}
1838 size_t operator-(const iterator& P_itRight)const{return m_ptr.m_place - P_itRight->m_place;}
1840 bool operator<(const iterator& P_itRight)const{return m_ptr.m_place < P_itRight->m_place;}
1841 bool operator!=(const iterator& P_itRight)const{return m_ptr.m_place != P_itRight->m_place;}
1842 bool operator==(const iterator& P_itRight)const{return m_ptr.m_place == P_itRight->m_place;}
1843 bool operator>(const iterator& P_itRight)const{return m_ptr.m_place > P_itRight->m_place;}
1845 iterator begin()
1847 iterator it;
1848 it->m_place = 0;
1849 it->m_cont = this;
1850 return it;
1852 iterator end()
1854 iterator it;
1855 it->m_place = m_parDates->GetCount();
1856 it->m_cont = this;
1857 return it;
1860 CDWordArray * m_parDates;
1861 CDWordArray * m_parFileChanges;
1862 CStringArray * m_parAuthors;
1865 class CDateSorterLess
1867 public:
1868 bool operator () (const CDateSorter::CCommitPointer& P_Left, const CDateSorter::CCommitPointer& P_Right) const
1870 return P_Left.GetDate() > P_Right.GetDate(); //Last date first
1877 void CLogDlg::OnBnClickedStatbutton()
1879 if (this->IsThreadRunning())
1880 return;
1881 if (m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC)
1882 return; // nothing or just the working copy changes are shown, so no statistics.
1883 // the statistics dialog expects the log entries to be sorted by date
1884 SortByColumn(3, false);
1885 CThreadSafePtrArray shownlist(NULL);
1886 m_LogList.RecalculateShownList(&shownlist);
1887 // create arrays which are aware of the current filter
1888 CStringArray m_arAuthorsFiltered;
1889 CDWordArray m_arDatesFiltered;
1890 CDWordArray m_arFileChangesFiltered;
1891 for (INT_PTR i=0; i<shownlist.GetCount(); ++i)
1893 GitRev* pLogEntry = reinterpret_cast<GitRev*>(shownlist.SafeGetAt(i));
1895 // do not take working dir changes into statistics
1896 if (pLogEntry->m_CommitHash.IsEmpty()) {
1897 continue;
1900 CString strAuthor = pLogEntry->GetAuthorName();
1901 if ( strAuthor.IsEmpty() )
1903 strAuthor.LoadString(IDS_STATGRAPH_EMPTYAUTHOR);
1905 m_arAuthorsFiltered.Add(strAuthor);
1906 m_arDatesFiltered.Add(pLogEntry->GetCommitterDate().GetTime());
1907 m_arFileChangesFiltered.Add(pLogEntry->GetFiles(&m_LogList).GetCount());
1910 CDateSorter W_Sorter;
1911 W_Sorter.m_parAuthors = &m_arAuthorsFiltered;
1912 W_Sorter.m_parDates = &m_arDatesFiltered;
1913 W_Sorter.m_parFileChanges = &m_arFileChangesFiltered;
1914 std::sort(W_Sorter.begin(), W_Sorter.end(), CDateSorterLess());
1916 CStatGraphDlg dlg;
1917 dlg.m_parAuthors = &m_arAuthorsFiltered;
1918 dlg.m_parDates = &m_arDatesFiltered;
1919 dlg.m_parFileChanges = &m_arFileChangesFiltered;
1920 dlg.m_path = m_orgPath;
1921 dlg.DoModal();
1922 // restore the previous sorting
1923 SortByColumn(m_nSortColumn, m_bAscending);
1924 OnTimer(LOGFILTER_TIMER);
1927 void CLogDlg::DoSizeV1(int delta)
1930 RemoveAnchor(IDC_LOGLIST);
1931 RemoveAnchor(IDC_SPLITTERTOP);
1932 RemoveAnchor(IDC_MSGVIEW);
1933 RemoveAnchor(IDC_SPLITTERBOTTOM);
1934 RemoveAnchor(IDC_LOGMSG);
1935 CSplitterControl::ChangeHeight(&m_LogList, delta, CW_TOPALIGN);
1936 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), -delta, CW_BOTTOMALIGN);
1937 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1938 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1939 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1940 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1941 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1942 ArrangeLayout();
1943 AdjustMinSize();
1944 SetSplitterRange();
1945 m_LogList.Invalidate();
1946 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1950 void CLogDlg::DoSizeV2(int delta)
1953 RemoveAnchor(IDC_LOGLIST);
1954 RemoveAnchor(IDC_SPLITTERTOP);
1955 RemoveAnchor(IDC_MSGVIEW);
1956 RemoveAnchor(IDC_SPLITTERBOTTOM);
1957 RemoveAnchor(IDC_LOGMSG);
1958 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), delta, CW_TOPALIGN);
1959 CSplitterControl::ChangeHeight(&m_ChangedFileListCtrl, -delta, CW_BOTTOMALIGN);
1960 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1961 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1962 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1963 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1964 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1965 ArrangeLayout();
1966 AdjustMinSize();
1967 SetSplitterRange();
1968 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1969 m_ChangedFileListCtrl.Invalidate();
1973 void CLogDlg::AdjustMinSize()
1975 // adjust the minimum size of the dialog to prevent the resizing from
1976 // moving the list control too far down.
1977 CRect rcChgListView;
1978 m_ChangedFileListCtrl.GetClientRect(rcChgListView);
1979 CRect rcLogList;
1980 m_LogList.GetClientRect(rcLogList);
1982 SetMinTrackSize(CSize(m_DlgOrigRect.Width(),
1983 m_DlgOrigRect.Height()-m_ChgOrigRect.Height()-m_LogListOrigRect.Height()-m_MsgViewOrigRect.Height()
1984 +rcChgListView.Height()+rcLogList.Height()+60));
1987 LRESULT CLogDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1989 switch (message) {
1990 case WM_NOTIFY:
1991 if (wParam == IDC_SPLITTERTOP)
1993 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1994 DoSizeV1(pHdr->delta);
1996 else if (wParam == IDC_SPLITTERBOTTOM)
1998 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1999 DoSizeV2(pHdr->delta);
2001 break;
2004 return CResizableDialog::DefWindowProc(message, wParam, lParam);
2007 void CLogDlg::SetSplitterRange()
2009 if ((m_LogList)&&(m_ChangedFileListCtrl))
2011 CRect rcTop;
2012 m_LogList.GetWindowRect(rcTop);
2013 ScreenToClient(rcTop);
2014 CRect rcMiddle;
2015 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(rcMiddle);
2016 ScreenToClient(rcMiddle);
2017 m_wndSplitter1.SetRange(rcTop.top+30, rcMiddle.bottom-20);
2018 CRect rcBottom;
2019 m_ChangedFileListCtrl.GetWindowRect(rcBottom);
2020 ScreenToClient(rcBottom);
2021 m_wndSplitter2.SetRange(rcMiddle.top+30, rcBottom.bottom-20);
2025 LRESULT CLogDlg::OnClickedInfoIcon(WPARAM /*wParam*/, LPARAM lParam)
2027 // FIXME: x64 version would get this function called with unexpected parameters.
2028 if (!lParam)
2029 return 0;
2031 RECT * rect = (LPRECT)lParam;
2032 CPoint point;
2033 CString temp;
2034 point = CPoint(rect->left, rect->bottom);
2035 #define LOGMENUFLAGS(x) (MF_STRING | MF_ENABLED | (m_LogList.m_nSelectedFilter == x ? MF_CHECKED : MF_UNCHECKED))
2036 CMenu popup;
2037 if (popup.CreatePopupMenu())
2039 temp.LoadString(IDS_LOG_FILTER_ALL);
2040 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_ALL), LOGFILTER_ALL, temp);
2042 popup.AppendMenu(MF_SEPARATOR, NULL);
2044 temp.LoadString(IDS_LOG_FILTER_SUBJECT);
2045 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_SUBJECT), LOGFILTER_SUBJECT, temp);
2047 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2048 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_MESSAGES), LOGFILTER_MESSAGES, temp);
2050 temp.LoadString(IDS_LOG_FILTER_PATHS);
2051 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_PATHS), LOGFILTER_PATHS, temp);
2053 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2054 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_AUTHORS), LOGFILTER_AUTHORS, temp);
2056 temp.LoadString(IDS_LOG_FILTER_REVS);
2057 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REVS), LOGFILTER_REVS, temp);
2059 if (m_LogList.m_bShowBugtraqColumn == true) {
2060 temp.LoadString(IDS_LOG_FILTER_BUGIDS);
2061 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_BUGID), LOGFILTER_BUGID, temp);
2064 popup.AppendMenu(MF_SEPARATOR, NULL);
2066 temp.LoadString(IDS_LOG_FILTER_REGEX);
2067 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterWithRegex ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_REGEX, temp);
2069 m_tooltips.Pop();
2070 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2071 if (selection != 0)
2074 if (selection == LOGFILTER_REGEX)
2076 m_bFilterWithRegex = !m_bFilterWithRegex;
2077 CRegDWORD b = CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
2078 b = m_bFilterWithRegex;
2079 m_LogList.m_bFilterWithRegex = m_bFilterWithRegex;
2080 SetFilterCueText();
2081 CheckRegexpTooltip();
2083 else
2085 m_LogList.m_nSelectedFilter = selection;
2086 SetFilterCueText();
2088 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2091 return 0L;
2094 LRESULT CLogDlg::OnClickedCancelFilter(WPARAM /*wParam*/, LPARAM /*lParam*/)
2097 KillTimer(LOGFILTER_TIMER);
2099 m_LogList.m_sFilterText.Empty();
2100 UpdateData(FALSE);
2101 theApp.DoWaitCursor(1);
2102 CStoreSelection storeselection(this);
2103 FillLogMessageCtrl(false);
2105 m_LogList.RemoveFilter();
2107 Refresh();
2109 CTime begin,end;
2110 m_LogList.GetTimeRange(begin,end);
2111 m_DateFrom.SetTime(&begin);
2112 m_DateTo.SetTime(&end);
2114 theApp.DoWaitCursor(-1);
2115 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2116 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2117 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2118 UpdateLogInfoLabel();
2120 return 0L;
2124 void CLogDlg::SetFilterCueText()
2126 CString temp;
2127 switch (m_LogList.m_nSelectedFilter)
2129 case LOGFILTER_ALL:
2130 temp.LoadString(IDS_LOG_FILTER_ALL);
2131 break;
2132 case LOGFILTER_SUBJECT:
2133 temp.LoadString(IDS_LOG_FILTER_SUBJECT);
2134 break;
2135 case LOGFILTER_MESSAGES:
2136 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2137 break;
2138 case LOGFILTER_PATHS:
2139 temp.LoadString(IDS_LOG_FILTER_PATHS);
2140 break;
2141 case LOGFILTER_AUTHORS:
2142 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2143 break;
2144 case LOGFILTER_REVS:
2145 temp.LoadString(IDS_LOG_FILTER_REVS);
2146 break;
2148 // to make the cue banner text appear more to the right of the edit control
2149 temp = _T(" ")+temp;
2150 m_cFilter.SetCueBanner(temp);
2153 bool CLogDlg::Validate(LPCTSTR string)
2155 if (!m_bFilterWithRegex)
2156 return true;
2157 tr1::wregex pat;
2158 return m_LogList.ValidateRegexp(string, pat, false);
2162 void CLogDlg::OnTimer(UINT_PTR nIDEvent)
2164 if (nIDEvent == LOGFTIME_TIMER)
2166 KillTimer(LOGFTIME_TIMER);
2167 m_limit = 0;
2168 m_LogList.Refresh(FALSE);
2169 FillLogMessageCtrl(false);
2172 if (nIDEvent == LOGFILTER_TIMER)
2174 KillTimer(LOGFILTER_TIMER);
2175 m_limit = 0;
2176 m_LogList.Refresh(FALSE);
2177 FillLogMessageCtrl(false);
2179 #if 0
2180 /* we will use git built-in grep to filter log */
2181 if (this->IsThreadRunning())
2183 // thread still running! So just restart the timer.
2184 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2185 return;
2187 CWnd * focusWnd = GetFocus();
2188 bool bSetFocusToFilterControl = ((focusWnd != GetDlgItem(IDC_DATEFROM))&&(focusWnd != GetDlgItem(IDC_DATETO))
2189 && (focusWnd != GetDlgItem(IDC_LOGLIST)));
2190 if (m_LogList.m_sFilterText.IsEmpty())
2192 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2193 // do not return here!
2194 // we also need to run the filter if the filter text is empty:
2195 // 1. to clear an existing filter
2196 // 2. to rebuild the m_arShownList after sorting
2198 theApp.DoWaitCursor(1);
2199 CStoreSelection storeselection(this);
2200 KillTimer(LOGFILTER_TIMER);
2201 FillLogMessageCtrl(false);
2203 // now start filter the log list
2204 m_LogList.StartFilter();
2206 if ( m_LogList.GetItemCount()==1 )
2208 m_LogList.SetSelectionMark(0);
2209 m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
2211 theApp.DoWaitCursor(-1);
2212 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2213 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2214 if (bSetFocusToFilterControl)
2215 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2216 UpdateLogInfoLabel();
2217 #endif
2218 } // if (nIDEvent == LOGFILTER_TIMER)
2219 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC))));
2220 __super::OnTimer(nIDEvent);
2223 void CLogDlg::OnDtnDatetimechangeDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2227 CTime _time;
2228 m_DateTo.GetTime(_time);
2230 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 23, 59, 59);
2231 if (time.GetTime() != m_LogList.m_To)
2233 m_LogList.m_To = (DWORD)time.GetTime();
2234 SetTimer(LOGFTIME_TIMER, 10, NULL);
2237 catch (...)
2239 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2242 *pResult = 0;
2245 void CLogDlg::OnDtnDatetimechangeDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2250 CTime _time;
2251 m_DateFrom.GetTime(_time);
2253 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 0, 0, 0);
2254 if (time.GetTime() != m_LogList.m_From)
2256 m_LogList.m_From = (DWORD)time.GetTime();
2257 SetTimer(LOGFTIME_TIMER, 10, NULL);
2260 catch (...)
2262 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2265 *pResult = 0;
2270 CTGitPathList CLogDlg::GetChangedPathsFromSelectedRevisions(bool /*bRelativePaths*/ /* = false */, bool /*bUseFilter*/ /* = true */)
2272 CTGitPathList pathList;
2273 #if 0
2275 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2277 m_sRepositoryRoot = GetRepositoryRoot(m_path);
2279 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2280 return pathList;
2282 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2283 if (pos != NULL)
2285 while (pos)
2287 int nextpos = m_LogList.GetNextSelectedItem(pos);
2288 if (nextpos >= m_arShownList.GetCount())
2289 continue;
2290 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(nextpos));
2291 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2292 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
2294 LogChangedPath * cpath = cpatharray->SafeGetAt(cpPathIndex);
2295 if (cpath == NULL)
2296 continue;
2297 CTGitPath path;
2298 if (!bRelativePaths)
2299 path.SetFromGit(m_sRepositoryRoot);
2300 path.AppendPathString(cpath->sPath);
2301 if ((!bUseFilter)||
2302 ((m_cHidePaths.GetState() & 0x0003)!=BST_CHECKED)||
2303 (cpath->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0))
2304 pathList.AddPath(path);
2309 pathList.RemoveDuplicates();
2310 #endif
2311 return pathList;
2314 void CLogDlg::SortByColumn(int /*nSortColumn*/, bool /*bAscending*/)
2316 #if 0
2317 switch(nSortColumn)
2319 case 0: // Revision
2321 if(bAscending)
2322 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscRevSort());
2323 else
2324 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescRevSort());
2326 break;
2327 case 1: // action
2329 if(bAscending)
2330 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscActionSort());
2331 else
2332 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescActionSort());
2334 break;
2335 case 2: // Author
2337 if(bAscending)
2338 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscAuthorSort());
2339 else
2340 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescAuthorSort());
2342 break;
2343 case 3: // Date
2345 if(bAscending)
2346 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscDateSort());
2347 else
2348 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescDateSort());
2350 break;
2351 case 4: // Message or bug id
2352 if (m_bShowBugtraqColumn)
2354 if(bAscending)
2355 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscBugIDSort());
2356 else
2357 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescBugIDSort());
2358 break;
2360 // fall through here
2361 case 5: // Message
2363 if(bAscending)
2364 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscMessageSort());
2365 else
2366 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescMessageSort());
2368 break;
2369 default:
2370 ATLASSERT(0);
2371 break;
2373 #endif
2376 void CLogDlg::OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult)
2378 if (this->IsThreadRunning())
2379 return; //no sorting while the arrays are filled
2380 #if 0
2381 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2382 const int nColumn = pNMLV->iSubItem;
2383 m_bAscending = nColumn == m_nSortColumn ? !m_bAscending : TRUE;
2384 m_nSortColumn = nColumn;
2385 SortByColumn(m_nSortColumn, m_bAscending);
2386 SetSortArrow(&m_LogList, m_nSortColumn, !!m_bAscending);
2387 SortShownListArray();
2388 m_LogList.Invalidate();
2389 UpdateLogInfoLabel();
2390 #else
2391 UNREFERENCED_PARAMETER(pNMHDR);
2392 #endif
2393 *pResult = 0;
2396 void CLogDlg::SortShownListArray()
2398 // make sure the shown list still matches the filter after sorting.
2399 OnTimer(LOGFILTER_TIMER);
2400 // clear the selection states
2401 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2402 while (pos)
2404 m_LogList.SetItemState(m_LogList.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
2406 m_LogList.SetSelectionMark(-1);
2409 void CLogDlg::SetSortArrow(CListCtrl * control, int nColumn, bool bAscending)
2411 if (control == NULL)
2412 return;
2413 // set the sort arrow
2414 CHeaderCtrl * pHeader = control->GetHeaderCtrl();
2415 HDITEM HeaderItem = {0};
2416 HeaderItem.mask = HDI_FORMAT;
2417 for (int i=0; i<pHeader->GetItemCount(); ++i)
2419 pHeader->GetItem(i, &HeaderItem);
2420 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
2421 pHeader->SetItem(i, &HeaderItem);
2423 if (nColumn >= 0)
2425 pHeader->GetItem(nColumn, &HeaderItem);
2426 HeaderItem.fmt |= (bAscending ? HDF_SORTUP : HDF_SORTDOWN);
2427 pHeader->SetItem(nColumn, &HeaderItem);
2430 void CLogDlg::OnLvnColumnclickChangedFileList(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
2432 #if 0
2433 if (this->IsThreadRunning())
2434 return; //no sorting while the arrays are filled
2435 if (m_currentChangedArray == NULL)
2436 return;
2437 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2438 const int nColumn = pNMLV->iSubItem;
2439 m_bAscendingPathList = nColumn == m_nSortColumnPathList ? !m_bAscendingPathList : TRUE;
2440 m_nSortColumnPathList = nColumn;
2441 // qsort(m_currentChangedArray->GetData(), m_currentChangedArray->GetSize(), sizeof(LogChangedPath*), (GENERICCOMPAREFN)SortCompare);
2443 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
2444 m_ChangedFileListCtrl.Invalidate();
2445 *pResult = 0;
2446 #endif
2449 int CLogDlg::m_nSortColumnPathList = 0;
2450 bool CLogDlg::m_bAscendingPathList = false;
2452 int CLogDlg::SortCompare(const void * /*pElem1*/, const void * /*pElem2*/)
2454 #if 0
2455 LogChangedPath * cpath1 = *((LogChangedPath**)pElem1);
2456 LogChangedPath * cpath2 = *((LogChangedPath**)pElem2);
2458 if (m_bAscendingPathList)
2459 std::swap (cpath1, cpath2);
2461 int cmp = 0;
2462 switch (m_nSortColumnPathList)
2464 case 0: // action
2465 cmp = cpath2->GetAction().Compare(cpath1->GetAction());
2466 if (cmp)
2467 return cmp;
2468 // fall through
2469 case 1: // path
2470 cmp = cpath2->sPath.CompareNoCase(cpath1->sPath);
2471 if (cmp)
2472 return cmp;
2473 // fall through
2474 case 2: // copy from path
2475 cmp = cpath2->sCopyFromPath.Compare(cpath1->sCopyFromPath);
2476 if (cmp)
2477 return cmp;
2478 // fall through
2479 case 3: // copy from revision
2480 return cpath2->lCopyFromRev > cpath1->lCopyFromRev;
2482 #endif
2483 return 0;
2486 void CLogDlg::OnBnClickedHidepaths()
2488 FillLogMessageCtrl();
2489 m_ChangedFileListCtrl.Invalidate();
2494 void CLogDlg::OnBnClickedCheckStoponcopy()
2496 #if 0
2497 if (!GetDlgItem(IDC_GETALL)->IsWindowEnabled())
2498 return;
2500 // ignore old fetch limits when switching
2501 // between copy-following and stop-on-copy
2502 // (otherwise stop-on-copy will limit what
2503 // we see immediately after switching to
2504 // copy-following)
2506 m_endrev = 0;
2508 // now, restart the query
2509 #endif
2510 Refresh();
2514 void CLogDlg::UpdateLogInfoLabel()
2517 CGitHash rev1 ;
2518 CGitHash rev2 ;
2519 long selectedrevs = 0;
2520 int count =m_LogList.m_arShownList.GetCount();
2521 int start = 0;
2522 if (count)
2524 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(0)))->m_CommitHash;
2525 if(this->m_LogList.m_bShowWC && rev1.IsEmpty()&&(count>1))
2526 start = 1;
2527 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(start)))->m_CommitHash;
2528 //pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_arShownList.GetCount()-1));
2529 rev2 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.SafeGetAt(count-1)))->m_CommitHash;
2530 selectedrevs = m_LogList.GetSelectedCount();
2532 CString sTemp;
2533 sTemp.Format(_T("Showing %ld revision(s), from revision %s to revision %s - %ld revision(s) selected\r\n"),
2534 count - start,
2535 rev2.ToString().Left(6), rev1.ToString().Left(6), selectedrevs);
2537 if(selectedrevs == 1)
2539 CString str=m_ChangedFileListCtrl.GetStatisticsString(true);
2540 str.Replace(_T('\n'), _T(' '));
2541 sTemp += str;
2543 m_sLogInfo = sTemp;
2545 UpdateData(FALSE);
2548 #if 0
2549 void CLogDlg::ShowContextMenuForChangedpaths(CWnd* /*pWnd*/, CPoint point)
2552 int selIndex = m_ChangedFileListCtrl.GetSelectionMark();
2553 if ((point.x == -1) && (point.y == -1))
2555 CRect rect;
2556 m_ChangedFileListCtrl.GetItemRect(selIndex, &rect, LVIR_LABEL);
2557 m_ChangedFileListCtrl.ClientToScreen(&rect);
2558 point = rect.CenterPoint();
2560 if (selIndex < 0)
2561 return;
2562 int s = m_LogList.GetSelectionMark();
2563 if (s < 0)
2564 return;
2565 std::vector<CString> changedpaths;
2566 std::vector<LogChangedPath*> changedlogpaths;
2567 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2568 if (pos == NULL)
2569 return; // nothing is selected, get out of here
2571 bool bOneRev = true;
2572 int sel=m_LogList.GetNextSelectedItem(pos);
2573 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(sel));
2574 GitRev * rev1 = pLogEntry;
2575 GitRev * rev2 = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.SafeGetAt(sel+1));
2576 #if 0
2577 bool bOneRev = true;
2578 if (pos)
2580 while (pos)
2582 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2583 if (pLogEntry)
2585 rev1 = max(rev1,(git_revnum_t)pLogEntry->Rev);
2586 rev2 = min(rev2,(git_revnum_t)pLogEntry->Rev);
2587 bOneRev = false;
2590 if (!bOneRev)
2591 rev2--;
2592 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
2593 while (pos)
2595 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
2596 changedpaths.push_back(m_currentChangedPathList[nItem].GetGitPathString());
2599 else
2601 // only one revision is selected in the log dialog top pane
2602 // but multiple items could be selected in the changed items list
2603 rev2 = rev1-1;
2605 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
2606 while (pos)
2608 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
2609 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(nItem);
2611 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
2613 if ((changedlogpath)&&(!changedlogpath->sCopyFromPath.IsEmpty()))
2614 rev2 = changedlogpath->lCopyFromRev;
2615 else
2617 // if the path was modified but the parent path was 'added with history'
2618 // then we have to use the copy from revision of the parent path
2619 CTGitPath cpath = CTGitPath(changedlogpath->sPath);
2620 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
2622 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->SafeGetAt(flist)->sPath);
2623 if (p.IsAncestorOf(cpath))
2625 if (!pLogEntry->pArChangedPaths->SafeGetAt(flist)->sCopyFromPath.IsEmpty())
2626 rev2 = pLogEntry->pArChangedPaths->SafeGetAt(flist)->lCopyFromRev;
2631 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
2633 // some items are hidden! So find out which item the user really clicked on
2634 INT_PTR selRealIndex = -1;
2635 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
2637 if (pLogEntry->pArChangedPaths->SafeGetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2638 selRealIndex++;
2639 if (selRealIndex == nItem)
2641 selIndex = hiddenindex;
2642 changedlogpath = pLogEntry->pArChangedPaths->SafeGetAt(selIndex);
2643 break;
2647 if (changedlogpath)
2649 changedpaths.push_back(changedlogpath->sPath);
2650 changedlogpaths.push_back(changedlogpath);
2654 #endif
2655 //entry is selected, now show the popup menu
2656 CIconMenu popup;
2657 if (popup.CreatePopupMenu())
2659 bool bEntryAdded = false;
2660 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
2662 // if ((!bOneRev)||(IsDiffPossible(changedlogpaths[0], rev1)))
2664 popup.AppendMenuIcon(CGitLogList::ID_DIFF, IDS_LOG_POPUP_DIFF, IDI_DIFF);
2665 popup.AppendMenuIcon(CGitLogList::ID_BLAMEDIFF, IDS_LOG_POPUP_BLAMEDIFF, IDI_BLAME);
2666 popup.SetDefaultItem(CGitLogList::ID_DIFF, FALSE);
2667 popup.AppendMenuIcon(CGitLogList::ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
2668 bEntryAdded = true;
2670 // if (rev2 == rev1-1)
2672 if (bEntryAdded)
2673 popup.AppendMenu(MF_SEPARATOR, NULL);
2674 popup.AppendMenuIcon(CGitLogList::ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
2675 popup.AppendMenuIcon(CGitLogList::ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
2676 popup.AppendMenuIcon(CGitLogList::ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
2677 popup.AppendMenu(MF_SEPARATOR, NULL);
2678 if (m_hasWC)
2679 popup.AppendMenuIcon(CGitLogList::ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2680 popup.AppendMenuIcon(CGitLogList::ID_POPPROPS, IDS_REPOBROWSE_SHOWPROP, IDI_PROPERTIES); // "Show Properties"
2681 popup.AppendMenuIcon(CGitLogList::ID_LOG, IDS_MENULOG, IDI_LOG); // "Show Log"
2682 popup.AppendMenuIcon(CGitLogList::ID_GETMERGELOGS, IDS_LOG_POPUP_GETMERGELOGS, IDI_LOG); // "Show merge log"
2683 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
2684 bEntryAdded = true;
2685 if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2687 popup.AppendMenu(MF_SEPARATOR, NULL);
2688 popup.AppendMenuIcon(CGitLogList::ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2690 if (popup.GetDefaultItem(0,FALSE)==-1)
2691 popup.SetDefaultItem(CGitLogList::ID_OPEN, FALSE);
2694 else if (changedlogpaths.size())
2696 // more than one entry is selected
2697 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE);
2698 bEntryAdded = true;
2701 if (!bEntryAdded)
2702 return;
2703 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2704 bool bOpenWith = false;
2705 bool bMergeLog = false;
2706 m_bCancelled = false;
2708 switch (cmd)
2710 case CGitLogList::ID_DIFF:
2712 DoDiffFromLog(selIndex, rev1, rev2, false, false);
2714 break;
2715 #if 0
2716 case ID_BLAMEDIFF:
2718 DoDiffFromLog(selIndex, rev1, rev2, true, false);
2720 break;
2721 case ID_GNUDIFF1:
2723 DoDiffFromLog(selIndex, rev1, rev2, false, true);
2725 break;
2726 case ID_REVERTREV:
2728 SetPromptApp(&theApp);
2729 theApp.DoWaitCursor(1);
2730 CString sUrl;
2731 if (Git::PathIsURL(m_path))
2733 sUrl = m_path.GetGitPathString();
2735 else
2737 sUrl = GetURLFromPath(m_path);
2738 if (sUrl.IsEmpty())
2740 theApp.DoWaitCursor(-1);
2741 CString temp;
2742 temp.Format(IDS_ERR_NOURLOFFILE, m_path.GetWinPath());
2743 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2744 EnableOKButton();
2745 theApp.DoWaitCursor(-1);
2746 break; //exit
2749 // find the working copy path of the selected item from the URL
2750 m_bCancelled = false;
2751 CString sUrlRoot = GetRepositoryRoot(CTGitPath(sUrl));
2753 CString fileURL = changedpaths[0];
2754 fileURL = sUrlRoot + fileURL.Trim();
2755 // firstfile = (e.g.) http://mydomain.com/repos/trunk/folder/file1
2756 // sUrl = http://mydomain.com/repos/trunk/folder
2757 CString sUnescapedUrl = CPathUtils::PathUnescape(sUrl);
2758 // find out until which char the urls are identical
2759 int i=0;
2760 while ((i<fileURL.GetLength())&&(i<sUnescapedUrl.GetLength())&&(fileURL[i]==sUnescapedUrl[i]))
2761 i++;
2762 int leftcount = m_path.GetWinPathString().GetLength()-(sUnescapedUrl.GetLength()-i);
2763 CString wcPath = m_path.GetWinPathString().Left(leftcount);
2764 wcPath += fileURL.Mid(i);
2765 wcPath.Replace('/', '\\');
2766 CGitProgressDlg dlg;
2767 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
2769 // a deleted path! Since the path isn't there anymore, merge
2770 // won't work. So just do a copy url->wc
2771 dlg.SetCommand(CGitProgressDlg::GitProgress_Copy);
2772 dlg.SetPathList(CTGitPathList(CTGitPath(fileURL)));
2773 dlg.SetUrl(wcPath);
2774 dlg.SetRevision(rev2);
2776 else
2778 if (!PathFileExists(wcPath))
2780 // seems the path got renamed
2781 // tell the user how to work around this.
2782 CMessageBox::Show(this->m_hWnd, IDS_LOG_REVERTREV_ERROR, IDS_APPNAME, MB_ICONERROR);
2783 EnableOKButton();
2784 theApp.DoWaitCursor(-1);
2785 break; //exit
2787 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
2788 dlg.SetPathList(CTGitPathList(CTGitPath(wcPath)));
2789 dlg.SetUrl(fileURL);
2790 dlg.SetSecondUrl(fileURL);
2791 GitRevRangeArray revarray;
2792 revarray.AddRevRange(rev1, rev2);
2793 dlg.SetRevisionRanges(revarray);
2795 CString msg;
2796 msg.Format(IDS_LOG_REVERT_CONFIRM, (LPCTSTR)wcPath);
2797 if (CMessageBox::Show(this->m_hWnd, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
2799 dlg.DoModal();
2801 theApp.DoWaitCursor(-1);
2803 break;
2804 case ID_POPPROPS:
2806 DialogEnableWindow(IDOK, FALSE);
2807 SetPromptApp(&theApp);
2808 theApp.DoWaitCursor(1);
2809 CString filepath;
2810 if (Git::PathIsURL(m_path))
2812 filepath = m_path.GetGitPathString();
2814 else
2816 filepath = GetURLFromPath(m_path);
2817 if (filepath.IsEmpty())
2819 theApp.DoWaitCursor(-1);
2820 CString temp;
2821 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2822 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2823 TRACE(_T("could not retrieve the URL of the file!\n"));
2824 EnableOKButton();
2825 break;
2828 filepath = GetRepositoryRoot(CTGitPath(filepath));
2829 filepath += changedpaths[0];
2830 CPropDlg dlg;
2831 dlg.m_rev = rev1;
2832 dlg.m_Path = CTGitPath(filepath);
2833 dlg.DoModal();
2834 EnableOKButton();
2835 theApp.DoWaitCursor(-1);
2837 break;
2838 case ID_SAVEAS:
2840 DialogEnableWindow(IDOK, FALSE);
2841 SetPromptApp(&theApp);
2842 theApp.DoWaitCursor(1);
2843 CString filepath;
2844 if (Git::PathIsURL(m_path))
2846 filepath = m_path.GetGitPathString();
2848 else
2850 filepath = GetURLFromPath(m_path);
2851 if (filepath.IsEmpty())
2853 theApp.DoWaitCursor(-1);
2854 CString temp;
2855 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2856 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2857 TRACE(_T("could not retrieve the URL of the file!\n"));
2858 EnableOKButton();
2859 break;
2862 m_bCancelled = false;
2863 CString sRoot = GetRepositoryRoot(CTGitPath(filepath));
2864 // if more than one entry is selected, we save them
2865 // one by one into a folder the user has selected
2866 bool bTargetSelected = false;
2867 CTGitPath TargetPath;
2868 if (m_ChangedFileListCtrl.GetSelectedCount() > 1)
2870 CBrowseFolder browseFolder;
2871 browseFolder.SetInfo(CString(MAKEINTRESOURCE(IDS_LOG_SAVEFOLDERTOHINT)));
2872 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
2873 CString strSaveAsDirectory;
2874 if (browseFolder.Show(GetSafeHwnd(), strSaveAsDirectory) == CBrowseFolder::OK)
2876 TargetPath = CTGitPath(strSaveAsDirectory);
2877 bTargetSelected = true;
2880 else
2882 // Display the Open dialog box.
2883 CString revFilename;
2884 CString temp;
2885 temp = CPathUtils::GetFileNameFromPath(changedpaths[0]);
2886 int rfind = temp.ReverseFind('.');
2887 if (rfind > 0)
2888 revFilename.Format(_T("%s-%ld%s"), (LPCTSTR)temp.Left(rfind), rev1, (LPCTSTR)temp.Mid(rfind));
2889 else
2890 revFilename.Format(_T("%s-%ld"), (LPCTSTR)temp, rev1);
2891 bTargetSelected = CAppUtils::FileOpenSave(revFilename, NULL, IDS_LOG_POPUP_SAVE, IDS_COMMONFILEFILTER, false, m_hWnd);
2892 TargetPath.SetFromWin(revFilename);
2894 if (bTargetSelected)
2896 CProgressDlg progDlg;
2897 progDlg.SetTitle(IDS_APPNAME);
2898 progDlg.SetAnimation(IDR_DOWNLOAD);
2899 for (std::vector<LogChangedPath*>::iterator it = changedlogpaths.begin(); it!= changedlogpaths.end(); ++it)
2901 GitRev getrev = ((*it)->action == LOGACTIONS_DELETED) ? rev2 : rev1;
2903 CString sInfoLine;
2904 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)getrev.ToString());
2905 progDlg.SetLine(1, sInfoLine, true);
2906 SetAndClearProgressInfo(&progDlg);
2907 progDlg.ShowModeless(m_hWnd);
2909 CTGitPath tempfile = TargetPath;
2910 if (changedpaths.size() > 1)
2912 // if multiple items are selected, then the TargetPath
2913 // points to a folder and we have to append the filename
2914 // to save to to that folder.
2915 CString sName = (*it)->sPath;
2916 int slashpos = sName.ReverseFind('/');
2917 if (slashpos >= 0)
2918 sName = sName.Mid(slashpos);
2919 tempfile.AppendPathString(sName);
2920 // one problem here:
2921 // a user could have selected multiple items which
2922 // have the same filename but reside in different
2923 // directories, e.g.
2924 // /folder1/file1
2925 // /folder2/file1
2926 // in that case, the second 'file1' will overwrite
2927 // the already saved 'file1'.
2929 // we could maybe find the common root of all selected
2930 // items and then create sub folders to save those files
2931 // there.
2932 // But I think we should just leave it that way: to check
2933 // out multiple items at once, the better way is still to
2934 // use the export command from the top pane of the log dialog.
2936 filepath = sRoot + (*it)->sPath;
2937 if (!Cat(CTGitPath(filepath), getrev, getrev, tempfile))
2939 progDlg.Stop();
2940 SetAndClearProgressInfo((HWND)NULL);
2941 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
2942 EnableOKButton();
2943 theApp.DoWaitCursor(-1);
2944 break;
2947 progDlg.Stop();
2948 SetAndClearProgressInfo((HWND)NULL);
2950 EnableOKButton();
2951 theApp.DoWaitCursor(-1);
2953 break;
2954 case ID_OPENWITH:
2955 bOpenWith = true;
2956 case ID_OPEN:
2958 GitRev getrev = pLogEntry->pArChangedPaths->SafeGetAt(selIndex)->action == LOGACTIONS_DELETED ? rev2 : rev1;
2959 Open(bOpenWith,changedpaths[0],getrev);
2961 break;
2962 case ID_BLAME:
2964 CString filepath;
2965 if (Git::PathIsURL(m_path))
2967 filepath = m_path.GetGitPathString();
2969 else
2971 filepath = GetURLFromPath(m_path);
2972 if (filepath.IsEmpty())
2974 theApp.DoWaitCursor(-1);
2975 CString temp;
2976 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2977 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2978 TRACE(_T("could not retrieve the URL of the file!\n"));
2979 EnableOKButton();
2980 break;
2983 filepath = GetRepositoryRoot(CTGitPath(filepath));
2984 filepath += changedpaths[0];
2985 CBlameDlg dlg;
2986 dlg.EndRev = rev1;
2987 if (dlg.DoModal() == IDOK)
2989 CBlame blame;
2990 CString tempfile;
2991 CString logfile;
2992 tempfile = blame.BlameToTempFile(CTGitPath(filepath), dlg.StartRev, dlg.EndRev, dlg.EndRev, logfile, _T(""), dlg.m_bIncludeMerge, TRUE, TRUE);
2993 if (!tempfile.IsEmpty())
2995 if (dlg.m_bTextView)
2997 //open the default text editor for the result file
2998 CAppUtils::StartTextViewer(tempfile);
3000 else
3002 CString sParams = _T("/path:\"") + filepath + _T("\" ");
3003 if(!CAppUtils::LaunchTortoiseBlame(tempfile, logfile, CPathUtils::GetFileNameFromPath(filepath),sParams))
3005 break;
3009 else
3011 CMessageBox::Show(this->m_hWnd, blame.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3015 break;
3016 case ID_GETMERGELOGS:
3017 bMergeLog = true;
3018 // fall through
3019 case ID_LOG:
3021 DialogEnableWindow(IDOK, FALSE);
3022 SetPromptApp(&theApp);
3023 theApp.DoWaitCursor(1);
3024 CString filepath;
3025 if (Git::PathIsURL(m_path))
3027 filepath = m_path.GetGitPathString();
3029 else
3031 filepath = GetURLFromPath(m_path);
3032 if (filepath.IsEmpty())
3034 theApp.DoWaitCursor(-1);
3035 CString temp;
3036 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
3037 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3038 TRACE(_T("could not retrieve the URL of the file!\n"));
3039 EnableOKButton();
3040 break;
3043 m_bCancelled = false;
3044 filepath = GetRepositoryRoot(CTGitPath(filepath));
3045 filepath += changedpaths[0];
3046 git_revnum_t logrev = rev1;
3047 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
3049 // if the item got deleted in this revision,
3050 // fetch the log from the previous revision where it
3051 // still existed.
3052 logrev--;
3054 CString sCmd;
3055 sCmd.Format(_T("\"%s\" /command:log /path:\"%s\" /startrev:%ld"), (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)filepath, logrev);
3056 if (bMergeLog)
3057 sCmd += _T(" /merge");
3058 CAppUtils::LaunchApplication(sCmd, NULL, false);
3059 EnableOKButton();
3060 theApp.DoWaitCursor(-1);
3062 break;
3063 case ID_VIEWPATHREV:
3065 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetSelectionMark()));
3066 GitRev rev = pLogEntry->Rev;
3067 CString relurl = changedpaths[0];
3068 CString url = m_ProjectProperties.sWebViewerPathRev;
3069 url.Replace(_T("%REVISION%"), rev.ToString());
3070 url.Replace(_T("%PATH%"), relurl);
3071 relurl = relurl.Mid(relurl.Find('/'));
3072 url.Replace(_T("%PATH1%"), relurl);
3073 if (!url.IsEmpty())
3074 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
3076 break;
3077 #endif
3078 default:
3079 break;
3080 } // switch (cmd)
3082 } // if (popup.CreatePopupMenu())
3084 #endif
3086 void CLogDlg::OnDtnDropdownDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3088 // the date control should not show the "today" button
3089 CMonthCalCtrl * pCtrl = m_DateFrom.GetMonthCalCtrl();
3090 if (pCtrl)
3091 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3092 *pResult = 0;
3095 void CLogDlg::OnDtnDropdownDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3097 // the date control should not show the "today" button
3098 CMonthCalCtrl * pCtrl = m_DateTo.GetMonthCalCtrl();
3099 if (pCtrl)
3100 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3101 *pResult = 0;
3104 void CLogDlg::OnSize(UINT nType, int cx, int cy)
3106 __super::OnSize(nType, cx, cy);
3107 //set range
3108 SetSplitterRange();
3111 void CLogDlg::OnRefresh()
3113 //if (GetDlgItem(IDC_GETALL)->IsWindowEnabled())
3114 ShowStartRef();
3116 m_limit = 0;
3117 this->m_LogProgress.SetPos(0);
3119 Refresh (false);
3125 void CLogDlg::OnFocusFilter()
3127 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3130 void CLogDlg::OnEditCopy()
3132 if (GetFocus() == &m_ChangedFileListCtrl)
3133 CopyChangedSelectionToClipBoard();
3134 else
3135 m_LogList.CopySelectionToClipBoard();
3138 CString CLogDlg::GetAbsoluteUrlFromRelativeUrl(const CString& url)
3140 // is the URL a relative one?
3141 if (url.Left(2).Compare(_T("^/")) == 0)
3143 // URL is relative to the repository root
3144 CString url1 = m_sRepositoryRoot + url.Mid(1);
3145 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3146 DWORD len = url.GetLength();
3147 if (UrlCanonicalize((LPCTSTR)url1, buf, &len, 0) == S_OK)
3148 return CString(buf, len);
3149 return url1;
3151 else if (url[0] == '/')
3153 // URL is relative to the server's hostname
3154 CString sHost;
3155 // find the server's hostname
3156 int schemepos = m_sRepositoryRoot.Find(_T("//"));
3157 if (schemepos >= 0)
3159 sHost = m_sRepositoryRoot.Left(m_sRepositoryRoot.Find('/', schemepos+3));
3160 CString url1 = sHost + url;
3161 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3162 DWORD len = url.GetLength();
3163 if (UrlCanonicalize((LPCTSTR)url, buf, &len, 0) == S_OK)
3164 return CString(buf, len);
3165 return url1;
3168 return url;
3172 void CLogDlg::OnEnChangeSearchedit()
3174 UpdateData();
3175 if (m_LogList.m_sFilterText.IsEmpty())
3177 CStoreSelection storeselection(this);
3178 // clear the filter, i.e. make all entries appear
3179 theApp.DoWaitCursor(1);
3180 KillTimer(LOGFILTER_TIMER);
3181 FillLogMessageCtrl(false);
3183 Refresh();
3184 //m_LogList.StartFilter();
3185 #if 0
3186 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3187 m_arShownList.RemoveAll();
3188 for (DWORD i=0; i<m_logEntries.size(); ++i)
3190 if (IsEntryInDateRange(i))
3191 m_arShownList.Add(m_logEntries[i]);
3193 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3194 m_LogList.DeleteAllItems();
3195 m_LogList.SetItemCountEx(ShownCountWithStopped());
3196 m_LogList.RedrawItems(0, ShownCountWithStopped());
3197 m_LogList.SetRedraw(false);
3198 ResizeAllListCtrlCols();
3199 m_LogList.SetRedraw(true);
3200 #endif
3201 theApp.DoWaitCursor(-1);
3202 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
3203 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
3204 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3205 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
3206 return;
3208 if (Validate(m_LogList.m_sFilterText))
3209 SetTimer(LOGFILTER_TIMER, 1000, NULL);
3210 else
3211 KillTimer(LOGFILTER_TIMER);
3215 void CLogDlg::OnBnClickedAllBranch()
3217 this->UpdateData();
3219 if(this->m_bAllBranch)
3220 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
3221 else
3222 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
3224 OnRefresh();
3226 FillLogMessageCtrl(false);
3229 void CLogDlg::OnBnClickedBrowseRef()
3231 CString newRef = CBrowseRefsDlg::PickRef(false,m_LogList.GetStartRef());
3232 if(newRef.IsEmpty())
3233 return;
3235 SetStartRef(newRef);
3236 ((CButton*)GetDlgItem(IDC_LOG_ALLBRANCH))->SetCheck(0);
3238 OnBnClickedAllBranch();
3241 void CLogDlg::ShowStartRef()
3243 //Show ref name on top
3244 if(!::IsWindow(m_hWnd))
3245 return;
3246 if(m_bAllBranch)
3248 m_staticRef.SetWindowText(L"<All Branches>");
3249 m_staticRef.Invalidate(TRUE);
3250 return;
3253 CString showStartRef = m_LogList.GetStartRef();
3254 if(showStartRef.IsEmpty())
3256 //Ref name is HEAD
3257 if (g_Git.Run(L"git symbolic-ref HEAD", &showStartRef, NULL, CP_UTF8))
3258 showStartRef = _T("<No branch>");
3259 showStartRef.Trim(L"\r\n\t ");
3263 if(wcsncmp(showStartRef,L"refs/",5) == 0)
3264 showStartRef = showStartRef.Mid(5);
3265 if(wcsncmp(showStartRef,L"heads/",6) == 0)
3266 showStartRef = showStartRef.Mid(6);
3268 m_staticRef.SetWindowText(showStartRef);
3269 m_staticRef.Invalidate(TRUE);
3272 void CLogDlg::SetStartRef(const CString& StartRef)
3274 m_LogList.SetStartRef(StartRef);
3276 if (m_hightlightRevision.IsEmpty())
3278 m_hightlightRevision = g_Git.GetHash(StartRef);
3279 m_LogList.m_lastSelectedHash = m_hightlightRevision;
3282 ShowStartRef();
3286 void CLogDlg::OnBnClickedFirstParent()
3288 this->UpdateData();
3290 if(this->m_bFirstParent)
3291 m_LogList.m_ShowMask|=CGit::LOG_INFO_FIRST_PARENT;
3292 else
3293 m_LogList.m_ShowMask&=~CGit::LOG_INFO_FIRST_PARENT;
3295 OnRefresh();
3297 FillLogMessageCtrl(false);
3301 void CLogDlg::OnBnClickShowWholeProject()
3303 this->UpdateData();
3305 if(this->m_bWholeProject)
3307 m_LogList.m_Path.Reset();
3308 SetDlgTitle();
3310 else
3312 m_LogList.m_Path=m_path;
3315 SetDlgTitle();
3317 OnRefresh();
3319 FillLogMessageCtrl(false);
3323 LRESULT CLogDlg::OnRefLogChanged(WPARAM wParam, LPARAM lParam)
3325 UNREFERENCED_PARAMETER(wParam);
3326 UNREFERENCED_PARAMETER(lParam);
3327 ShowStartRef();
3328 return 0;
3331 LRESULT CLogDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
3333 m_pTaskbarList.Release();
3334 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
3335 return 0;