Rework Log List Basic Work
[TortoiseGit.git] / src / TortoiseProc / LogDlg.cpp
blob44a6218fe05bb86d335a6f0afdb5558993eda755
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "cursor.h"
22 #include "InputDlg.h"
23 #include "PropDlg.h"
24 #include "SVNProgressDlg.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"
53 const UINT CLogDlg::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
58 IMPLEMENT_DYNAMIC(CLogDlg, CResizableStandAloneDialog)
59 CLogDlg::CLogDlg(CWnd* pParent /*=NULL*/)
60 : CResizableStandAloneDialog(CLogDlg::IDD, pParent)
61 , m_logcounter(0)
62 , m_nSearchIndex(0)
63 , m_wParam(0)
64 , m_nSelectedFilter(LOGFILTER_ALL)
65 , m_currentChangedArray(NULL)
66 , m_nSortColumn(0)
67 , m_bShowedAll(false)
68 , m_bSelect(false)
69 , m_regLastStrict(_T("Software\\TortoiseGit\\LastLogStrict"), FALSE)
71 , m_bSelectionMustBeContinuous(false)
72 , m_bShowBugtraqColumn(false)
73 , m_lowestRev(_T(""))
75 , m_sLogInfo(_T(""))
76 , m_pFindDialog(NULL)
77 , m_bCancelled(FALSE)
78 , m_pNotifyWindow(NULL)
80 , m_bAscending(FALSE)
82 , m_limit(0)
83 , m_childCounter(0)
84 , m_maxChild(0)
85 , m_bIncludeMerges(FALSE)
86 , m_hAccel(NULL)
87 , m_bVista(false)
89 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
93 CLogDlg::~CLogDlg()
96 m_CurrentFilteredChangedArray.RemoveAll();
103 void CLogDlg::DoDataExchange(CDataExchange* pDX)
105 CResizableStandAloneDialog::DoDataExchange(pDX);
106 DDX_Control(pDX, IDC_LOGLIST, m_LogList);
107 DDX_Control(pDX, IDC_LOGMSG, m_ChangedFileListCtrl);
108 DDX_Control(pDX, IDC_PROGRESS, m_LogProgress);
109 DDX_Control(pDX, IDC_SPLITTERTOP, m_wndSplitter1);
110 DDX_Control(pDX, IDC_SPLITTERBOTTOM, m_wndSplitter2);
111 DDX_Check(pDX, IDC_CHECK_STOPONCOPY, m_bStrict);
112 DDX_Text(pDX, IDC_SEARCHEDIT, 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_Control(pDX, IDC_GETALL, m_btnShow);
117 DDX_Text(pDX, IDC_LOGINFO, m_sLogInfo);
118 DDX_Check(pDX, IDC_INCLUDEMERGE, m_bIncludeMerges);
119 DDX_Control(pDX, IDC_SEARCHEDIT, m_cFilter);
122 BEGIN_MESSAGE_MAP(CLogDlg, CResizableStandAloneDialog)
123 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
124 ON_BN_CLICKED(IDC_GETALL, OnBnClickedGetall)
125 ON_NOTIFY(NM_DBLCLK, IDC_LOGMSG, OnNMDblclkChangedFileList)
126 ON_WM_CONTEXTMENU()
127 ON_WM_SETCURSOR()
128 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
129 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOGLIST, OnLvnItemchangedLoglist)
130 ON_NOTIFY(EN_LINK, IDC_MSGVIEW, OnEnLinkMsgview)
131 ON_BN_CLICKED(IDC_STATBUTTON, OnBnClickedStatbutton)
133 ON_MESSAGE(WM_FILTEREDIT_INFOCLICKED, OnClickedInfoIcon)
134 ON_MESSAGE(WM_FILTEREDIT_CANCELCLICKED, OnClickedCancelFilter)
136 ON_EN_CHANGE(IDC_SEARCHEDIT, OnEnChangeSearchedit)
137 ON_WM_TIMER()
138 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETO, OnDtnDatetimechangeDateto)
139 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATEFROM, OnDtnDatetimechangeDatefrom)
140 ON_BN_CLICKED(IDC_NEXTHUNDRED, OnBnClickedNexthundred)
141 ON_NOTIFY(NM_CUSTOMDRAW, IDC_LOGMSG, OnNMCustomdrawChangedFileList)
142 ON_NOTIFY(LVN_GETDISPINFO, IDC_LOGMSG, OnLvnGetdispinfoChangedFileList)
143 ON_NOTIFY(LVN_COLUMNCLICK,IDC_LOGLIST , OnLvnColumnclick)
144 ON_NOTIFY(LVN_COLUMNCLICK, IDC_LOGMSG, OnLvnColumnclickChangedFileList)
145 ON_BN_CLICKED(IDC_HIDEPATHS, OnBnClickedHidepaths)
147 ON_BN_CLICKED(IDC_CHECK_STOPONCOPY, &CLogDlg::OnBnClickedCheckStoponcopy)
148 ON_NOTIFY(DTN_DROPDOWN, IDC_DATEFROM, &CLogDlg::OnDtnDropdownDatefrom)
149 ON_NOTIFY(DTN_DROPDOWN, IDC_DATETO, &CLogDlg::OnDtnDropdownDateto)
150 ON_WM_SIZE()
151 ON_BN_CLICKED(IDC_INCLUDEMERGE, &CLogDlg::OnBnClickedIncludemerge)
152 ON_BN_CLICKED(IDC_REFRESH, &CLogDlg::OnBnClickedRefresh)
153 ON_COMMAND(ID_LOGDLG_REFRESH,&CLogDlg::OnRefresh)
154 ON_COMMAND(ID_LOGDLG_FIND,&CLogDlg::OnFind)
155 ON_COMMAND(ID_LOGDLG_FOCUSFILTER,&CLogDlg::OnFocusFilter)
156 ON_COMMAND(ID_EDIT_COPY, &CLogDlg::OnEditCopy)
157 END_MESSAGE_MAP()
159 void CLogDlg::SetParams(const CTGitPath& path, GitRev pegrev, GitRev startrev, GitRev endrev, int limit, BOOL bStrict /* = FALSE */, BOOL bSaveStrict /* = TRUE */)
161 m_path = path;
162 m_pegrev = pegrev;
163 m_startrev = startrev;
164 m_LogRevision = startrev;
165 m_endrev = endrev;
166 m_hasWC = !path.IsUrl();
167 m_bStrict = bStrict;
168 m_bSaveStrict = bSaveStrict;
169 m_limit = limit;
170 if (::IsWindow(m_hWnd))
171 UpdateData(FALSE);
174 BOOL CLogDlg::OnInitDialog()
176 CResizableStandAloneDialog::OnInitDialog();
178 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_LOGDLG));
180 OSVERSIONINFOEX inf;
181 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
182 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
183 GetVersionEx((OSVERSIONINFO *)&inf);
184 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
185 m_bVista = (fullver >= 0x0600);
187 // use the state of the "stop on copy/rename" option from the last time
188 if (!m_bStrict)
189 m_bStrict = m_regLastStrict;
190 UpdateData(FALSE);
191 CString temp;
192 if (m_limit)
193 temp.Format(IDS_LOG_SHOWNEXT, m_limit);
194 else
195 temp.Format(IDS_LOG_SHOWNEXT, (int)(DWORD)CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100));
197 SetDlgItemText(IDC_NEXTHUNDRED, temp);
199 // set the font to use in the log message view, configured in the settings dialog
200 CAppUtils::CreateFontForLogs(m_logFont);
201 GetDlgItem(IDC_MSGVIEW)->SetFont(&m_logFont);
202 // automatically detect URLs in the log message and turn them into links
203 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_AUTOURLDETECT, TRUE, NULL);
204 // make the log message rich edit control send a message when the mouse pointer is over a link
205 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_SETEVENTMASK, NULL, ENM_LINK);
206 //m_LogList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_SUBITEMIMAGES);
208 // the "hide unrelated paths" checkbox should be indeterminate
209 m_cHidePaths.SetCheck(BST_INDETERMINATE);
212 // if there is a working copy, load the project properties
213 // to get information about the bugtraq: integration
214 if (m_hasWC)
215 m_ProjectProperties.ReadProps(m_path);
217 // the bugtraq issue id column is only shown if the bugtraq:url or bugtraq:regex is set
218 if ((!m_ProjectProperties.sUrl.IsEmpty())||(!m_ProjectProperties.sCheckRe.IsEmpty()))
219 m_bShowBugtraqColumn = true;
221 //theme.SetWindowTheme(m_LogList.GetSafeHwnd(), L"Explorer", NULL);
222 theme.SetWindowTheme(m_ChangedFileListCtrl.GetSafeHwnd(), L"Explorer", NULL);
224 // set up the columns
225 m_LogList.DeleteAllItems();
226 m_LogList.InsertGitColumn();
228 m_ChangedFileListCtrl.SetExtendedStyle ( LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER );
229 m_ChangedFileListCtrl.DeleteAllItems();
230 int c = ((CHeaderCtrl*)(m_ChangedFileListCtrl.GetDlgItem(0)))->GetItemCount()-1;
231 while (c>=0)
232 m_ChangedFileListCtrl.DeleteColumn(c--);
233 temp.LoadString(IDS_PROGRS_ACTION);
234 m_ChangedFileListCtrl.InsertColumn(this->FILELIST_ACTION, temp);
235 temp.LoadString(IDS_LOG_FILE_LINE_ADD);
236 m_ChangedFileListCtrl.InsertColumn(this->FILELIST_ADD, temp);
237 temp.LoadString(IDS_LOG_FILE_LINE_DEL);
238 m_ChangedFileListCtrl.InsertColumn(this->FILELIST_DEL, temp);
239 temp.LoadString(IDS_PROGRS_PATH);
240 m_ChangedFileListCtrl.InsertColumn(this->FILELIST_PATH, temp);
242 m_ChangedFileListCtrl.SetRedraw(false);
243 CAppUtils::ResizeAllListCtrlCols(&m_ChangedFileListCtrl);
244 m_ChangedFileListCtrl.SetRedraw(true);
247 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
249 m_logcounter = 0;
250 m_sMessageBuf.Preallocate(100000);
252 // set the dialog title to "Log - path/to/whatever/we/show/the/log/for"
253 SetDlgTitle(false);
255 m_tooltips.Create(this);
256 CheckRegexpTooltip();
258 SetSplitterRange();
260 // the filter control has a 'cancel' button (the red 'X'), we need to load its bitmap
261 m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);
262 m_cFilter.SetInfoIcon(IDI_LOGFILTER);
263 m_cFilter.SetValidator(this);
265 AdjustControlSize(IDC_HIDEPATHS);
266 AdjustControlSize(IDC_CHECK_STOPONCOPY);
267 AdjustControlSize(IDC_INCLUDEMERGE);
269 GetClientRect(m_DlgOrigRect);
270 m_LogList.GetClientRect(m_LogListOrigRect);
271 GetDlgItem(IDC_MSGVIEW)->GetClientRect(m_MsgViewOrigRect);
272 m_ChangedFileListCtrl.GetClientRect(m_ChgOrigRect);
274 m_DateFrom.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
275 m_DateTo.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
277 // resizable stuff
278 AddAnchor(IDC_FROMLABEL, TOP_LEFT);
279 AddAnchor(IDC_DATEFROM, TOP_LEFT);
280 AddAnchor(IDC_TOLABEL, TOP_LEFT);
281 AddAnchor(IDC_DATETO, TOP_LEFT);
283 SetFilterCueText();
284 AddAnchor(IDC_SEARCHEDIT, TOP_LEFT, TOP_RIGHT);
286 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
287 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
288 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
289 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
290 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
292 AddAnchor(IDC_LOGINFO, BOTTOM_LEFT, BOTTOM_RIGHT);
293 AddAnchor(IDC_HIDEPATHS, BOTTOM_LEFT);
294 AddAnchor(IDC_CHECK_STOPONCOPY, BOTTOM_LEFT);
295 AddAnchor(IDC_INCLUDEMERGE, BOTTOM_LEFT);
296 AddAnchor(IDC_GETALL, BOTTOM_LEFT);
297 AddAnchor(IDC_NEXTHUNDRED, BOTTOM_LEFT);
298 AddAnchor(IDC_REFRESH, BOTTOM_LEFT);
299 AddAnchor(IDC_STATBUTTON, BOTTOM_RIGHT);
300 AddAnchor(IDC_PROGRESS, BOTTOM_LEFT, BOTTOM_RIGHT);
301 AddAnchor(IDOK, BOTTOM_RIGHT);
302 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
303 AddAnchor(IDHELP, BOTTOM_RIGHT);
305 // SetPromptParentWindow(m_hWnd);
307 if (hWndExplorer)
308 CenterWindow(CWnd::FromHandle(hWndExplorer));
309 EnableSaveRestore(_T("LogDlg"));
311 DWORD yPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
312 DWORD yPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
313 RECT rcDlg, rcLogList, rcChgMsg;
314 GetClientRect(&rcDlg);
315 m_LogList.GetWindowRect(&rcLogList);
316 ScreenToClient(&rcLogList);
317 m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg);
318 ScreenToClient(&rcChgMsg);
319 if (yPos1)
321 RECT rectSplitter;
322 m_wndSplitter1.GetWindowRect(&rectSplitter);
323 ScreenToClient(&rectSplitter);
324 int delta = yPos1 - rectSplitter.top;
326 if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30))
328 m_wndSplitter1.SetWindowPos(NULL, 0, yPos1, 0, 0, SWP_NOSIZE);
329 DoSizeV1(delta);
332 if (yPos2)
334 RECT rectSplitter;
335 m_wndSplitter2.GetWindowRect(&rectSplitter);
336 ScreenToClient(&rectSplitter);
337 int delta = yPos2 - rectSplitter.top;
339 if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30))
341 m_wndSplitter2.SetWindowPos(NULL, 0, yPos2, 0, 0, SWP_NOSIZE);
342 DoSizeV2(delta);
347 if (m_bSelect)
349 // the dialog is used to select revisions
350 if (m_bSelectionMustBeContinuous)
351 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));
352 else
353 DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);
355 else
357 // the dialog is used to just view log messages
358 GetDlgItemText(IDOK, temp);
359 SetDlgItemText(IDCANCEL, temp);
360 GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
363 // set the choices for the "Show All" button
364 temp.LoadString(IDS_LOG_SHOWALL);
365 m_btnShow.AddEntry(temp);
366 temp.LoadString(IDS_LOG_SHOWRANGE);
367 m_btnShow.AddEntry(temp);
368 m_btnShow.SetCurrentEntry((LONG)CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry")));
370 m_mergedRevs.clear();
372 // first start a thread to obtain the log messages without
373 // blocking the dialog
374 m_tTo = 0;
375 m_tFrom = (DWORD)-1;
377 m_LogList.FetchLogAsync(LogCallBack,this);
379 GetDlgItem(IDC_LOGLIST)->SetFocus();
380 return FALSE;
383 void CLogDlg::LogRunStatus(int cur)
385 if( cur == GITLOG_START )
387 CString temp;
388 temp.LoadString(IDS_PROGRESSWAIT);
390 // change the text of the close button to "Cancel" since now the thread
391 // is running, and simply closing the dialog doesn't work.
392 if (!GetDlgItem(IDOK)->IsWindowVisible())
394 temp.LoadString(IDS_MSGBOX_CANCEL);
395 SetDlgItemText(IDCANCEL, temp);
398 // We use a progress bar while getting the logs
399 //m_LogProgress.SetRange32(0, 100);
400 //m_LogProgress.SetPos(0);
402 GetDlgItem(IDC_PROGRESS)->ShowWindow(TRUE);
404 DialogEnableWindow(IDC_GETALL, FALSE);
405 DialogEnableWindow(IDC_NEXTHUNDRED, FALSE);
406 DialogEnableWindow(IDC_CHECK_STOPONCOPY, FALSE);
407 DialogEnableWindow(IDC_INCLUDEMERGE, FALSE);
408 DialogEnableWindow(IDC_STATBUTTON, FALSE);
409 DialogEnableWindow(IDC_REFRESH, FALSE);
412 if( cur == GITLOG_END)
415 if (!m_bShowedAll)
416 DialogEnableWindow(IDC_NEXTHUNDRED, TRUE);
418 DialogEnableWindow(IDC_CHECK_STOPONCOPY, TRUE);
419 DialogEnableWindow(IDC_INCLUDEMERGE, TRUE);
420 DialogEnableWindow(IDC_STATBUTTON, TRUE);
421 DialogEnableWindow(IDC_REFRESH, TRUE);
423 PostMessage(WM_TIMER, LOGFILTER_TIMER);
427 void CLogDlg::SetDlgTitle(bool bOffline)
429 if (m_sTitle.IsEmpty())
430 GetWindowText(m_sTitle);
432 if (bOffline)
434 CString sTemp;
435 if (m_path.IsUrl())
436 sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetUIPathString());
437 else if (m_path.IsDirectory())
438 sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetWinPathString());
439 else
440 sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetFilename());
441 SetWindowText(sTemp);
443 else
445 if (m_path.IsUrl())
446 SetWindowText(m_sTitle + _T(" - ") + m_path.GetUIPathString());
447 else if (m_path.IsDirectory())
448 SetWindowText(m_sTitle + _T(" - ") + m_path.GetWinPathString());
449 else
450 SetWindowText(m_sTitle + _T(" - ") + m_path.GetFilename());
454 void CLogDlg::CheckRegexpTooltip()
456 CWnd *pWnd = GetDlgItem(IDC_SEARCHEDIT);
457 // Since tooltip describes regexp features, show it only if regexps are enabled.
458 if (m_bFilterWithRegex)
460 m_tooltips.AddTool(pWnd, IDS_LOG_FILTER_REGEX_TT);
462 else
463 m_tooltips.DelTool(pWnd);
466 void CLogDlg::EnableOKButton()
468 if (m_bSelect)
470 // the dialog is used to select revisions
471 if (m_bSelectionMustBeContinuous)
472 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));
473 else
474 DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);
476 else
477 DialogEnableWindow(IDOK, TRUE);
480 void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)
482 // we fill here the log message rich edit control,
483 // and also populate the changed files list control
484 // according to the selected revision(s).
486 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
487 // empty the log message view
488 pMsgView->SetWindowText(_T(" "));
489 // empty the changed files list
490 m_ChangedFileListCtrl.SetRedraw(FALSE);
491 // InterlockedExchange(&m_bNoDispUpdates, TRUE);
492 m_currentChangedArray = NULL;
493 m_ChangedFileListCtrl.SetExtendedStyle ( LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER );
494 m_ChangedFileListCtrl.DeleteAllItems();
495 m_ChangedFileListCtrl.SetItemCountEx(0);
497 // if we're not here to really show a selected revision, just
498 // get out of here after clearing the views, which is what is intended
499 // if that flag is not set.
500 if (!bShow)
502 // force a redraw
503 m_ChangedFileListCtrl.Invalidate();
504 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
505 m_ChangedFileListCtrl.SetRedraw(TRUE);
506 return;
509 // depending on how many revisions are selected, we have to do different
510 // tasks.
511 int selCount = m_LogList.GetSelectedCount();
512 if (selCount == 0)
514 // if nothing is selected, we have nothing more to do
515 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
516 m_ChangedFileListCtrl.SetRedraw(TRUE);
517 return;
519 else if (selCount == 1)
521 // if one revision is selected, we have to fill the log message view
522 // with the corresponding log message, and also fill the changed files
523 // list fully.
524 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
525 int selIndex = m_LogList.GetNextSelectedItem(pos);
526 if (selIndex >= m_LogList.m_arShownList.GetCount())
528 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
529 m_ChangedFileListCtrl.SetRedraw(TRUE);
530 return;
532 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.GetAt(selIndex));
534 // set the log message text
535 pMsgView->SetWindowText(_T("*")+pLogEntry->m_Subject+_T("\n\n")+pLogEntry->m_Body);
536 // turn bug ID's into links if the bugtraq: properties have been set
537 // and we can find a match of those in the log message
538 m_ProjectProperties.FindBugID(pLogEntry->m_Body, pMsgView);
539 CAppUtils::FormatTextInRichEditControl(pMsgView);
540 m_currentChangedArray = &(pLogEntry->m_Files);
541 if (m_currentChangedArray == NULL)
543 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
544 m_ChangedFileListCtrl.SetRedraw(TRUE);
545 return;
547 #if 0
548 // fill in the changed files list control
549 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
551 m_CurrentFilteredChangedArray.RemoveAll();
552 for (INT_PTR c = 0; c < m_currentChangedArray->GetCount(); ++c)
554 LogChangedPath * cpath = m_currentChangedArray->GetAt(c);
555 if (cpath == NULL)
556 continue;
557 if (m_currentChangedArray->GetAt(c)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
559 m_CurrentFilteredChangedArray.Add(cpath);
562 m_currentChangedArray = &m_CurrentFilteredChangedArray;
564 #endif
566 else
568 // more than one revision is selected:
569 // the log message view must be emptied
570 // the changed files list contains all the changed paths from all
571 // selected revisions, with 'doubles' removed
572 m_currentChangedPathList = GetChangedPathsFromSelectedRevisions(true);
575 // redraw the views
576 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
577 if (m_currentChangedArray)
579 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedArray->GetCount());
580 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedArray->GetCount());
582 else if (m_currentChangedPathList.GetCount())
584 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedPathList.GetCount());
585 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedPathList.GetCount());
587 else
589 m_ChangedFileListCtrl.SetItemCountEx(0);
590 m_ChangedFileListCtrl.Invalidate();
592 CAppUtils::ResizeAllListCtrlCols(&m_ChangedFileListCtrl);
593 // sort according to the settings
594 if (m_nSortColumnPathList > 0)
595 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
596 else
597 SetSortArrow(&m_ChangedFileListCtrl, -1, false);
598 m_ChangedFileListCtrl.SetRedraw(TRUE);
602 void CLogDlg::OnBnClickedGetall()
604 GetAll();
607 void CLogDlg::GetAll(bool bForceAll /* = false */)
609 #if 0
610 // fetch all requested log messages, either the specified range or
611 // really *all* available log messages.
612 UpdateData();
613 INT_PTR entry = m_btnShow.GetCurrentEntry();
614 if (bForceAll)
615 entry = 0;
617 switch (entry)
619 case 0: // show all
621 m_endrev = 0;
622 m_startrev = m_LogRevision;
623 if (m_bStrict)
624 m_bShowedAll = true;
626 break;
627 case 1: // show range
630 // ask for a revision range
631 CRevisionRangeDlg dlg;
632 dlg.SetStartRevision(m_startrev);
633 dlg.SetEndRevision( (m_endrev>=0) ? m_endrev : 0);
634 if (dlg.DoModal()!=IDOK)
636 return;
638 m_endrev = dlg.GetEndRevision();
639 m_startrev = dlg.GetStartRevision();
640 if (((m_endrev.IsNumber())&&(m_startrev.IsNumber()))||
641 (m_endrev.IsHead()||m_startrev.IsHead()))
643 if (((LONG)m_startrev < (LONG)m_endrev)||
644 (m_endrev.IsHead()))
646 git_revnum_t temp = m_startrev;
647 m_startrev = m_endrev;
648 m_endrev = temp;
651 m_bShowedAll = false;
654 break;
656 m_ChangedFileListCtrl.SetItemCountEx(0);
657 m_ChangedFileListCtrl.Invalidate();
658 // We need to create CStoreSelection on the heap or else
659 // the variable will run out of the scope before the
660 // thread ends. Therefore we let the thread delete
661 // the instance.
662 m_pStoreSelection = new CStoreSelection(this);
663 m_LogList.SetItemCountEx(0);
664 m_LogList.Invalidate();
665 InterlockedExchange(&m_bNoDispUpdates, TRUE);
666 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
667 pMsgView->SetWindowText(_T(""));
669 SetSortArrow(&m_LogList, -1, true);
671 m_LogList.DeleteAllItems();
672 m_arShownList.RemoveAll();
673 m_logEntries.ClearAll();
675 m_logcounter = 0;
676 m_bCancelled = FALSE;
677 m_tTo = 0;
678 m_tFrom = (DWORD)-1;
679 m_limit = 0;
681 InterlockedExchange(&m_bThreadRunning, TRUE);
682 if (AfxBeginThread(LogThreadEntry, this)==NULL)
684 InterlockedExchange(&m_bThreadRunning, FALSE);
685 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
687 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
688 InterlockedExchange(&m_bNoDispUpdates, FALSE);
689 #endif
692 void CLogDlg::OnBnClickedRefresh()
694 m_limit = 0;
695 Refresh (true);
698 void CLogDlg::Refresh (bool autoGoOnline)
700 #if 0
701 // refreshing means re-downloading the already shown log messages
702 UpdateData();
703 m_maxChild = 0;
704 m_childCounter = 0;
706 if ((m_limit == 0)||(m_bStrict)||(int(m_logEntries.size()-1) > m_limit))
708 if (m_logEntries.size() != 0)
710 m_endrev = m_logEntries[m_logEntries.size()-1]->Rev;
713 m_startrev = -1;
714 m_bCancelled = FALSE;
716 // We need to create CStoreSelection on the heap or else
717 // the variable will run out of the scope before the
718 // thread ends. Therefore we let the thread delete
719 // the instance.
720 m_pStoreSelection = new CStoreSelection(this);
721 m_ChangedFileListCtrl.SetItemCountEx(0);
722 m_ChangedFileListCtrl.Invalidate();
723 m_LogList.SetItemCountEx(0);
724 m_LogList.Invalidate();
725 InterlockedExchange(&m_bNoDispUpdates, TRUE);
726 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
727 pMsgView->SetWindowText(_T(""));
729 SetSortArrow(&m_LogList, -1, true);
731 m_LogList.DeleteAllItems();
732 m_arShownList.RemoveAll();
733 m_logEntries.ClearAll();
735 // reset the cached HEAD property & go on-line
737 if (autoGoOnline)
739 SetDlgTitle (false);
740 logCachePool.GetRepositoryInfo().ResetHeadRevision (m_sUUID, m_sRepositoryRoot);
743 InterlockedExchange(&m_bThreadRunning, TRUE);
744 if (AfxBeginThread(LogThreadEntry, this)==NULL)
746 InterlockedExchange(&m_bThreadRunning, FALSE);
747 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
749 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
750 InterlockedExchange(&m_bNoDispUpdates, FALSE);
751 #endif
754 void CLogDlg::OnBnClickedNexthundred()
756 #if 0
757 UpdateData();
758 // we have to fetch the next X log messages.
759 if (m_logEntries.size() < 1)
761 // since there weren't any log messages fetched before, just
762 // fetch all since we don't have an 'anchor' to fetch the 'next'
763 // messages from.
764 return GetAll(true);
766 git_revnum_t rev = m_logEntries[m_logEntries.size()-1]->Rev;
768 if (rev < 1)
769 return; // do nothing! No more revisions to get
771 m_startrev = rev;
772 m_endrev = 0;
773 m_bCancelled = FALSE;
775 // rev is is revision we already have and we will receive it again
776 // -> fetch one extra revision to get NumberOfLogs *new* revisions
778 m_limit = (int)(DWORD)CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100) +1;
779 InterlockedExchange(&m_bNoDispUpdates, TRUE);
780 SetSortArrow(&m_LogList, -1, true);
781 InterlockedExchange(&m_bThreadRunning, TRUE);
782 // We need to create CStoreSelection on the heap or else
783 // the variable will run out of the scope before the
784 // thread ends. Therefore we let the thread delete
785 // the instance.
786 m_pStoreSelection = new CStoreSelection(this);
788 // since we fetch the log from the last revision we already have,
789 // we have to remove that revision entry to avoid getting it twice
790 m_logEntries.pop_back();
791 if (AfxBeginThread(LogThreadEntry, this)==NULL)
793 InterlockedExchange(&m_bThreadRunning, FALSE);
794 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
796 InterlockedExchange(&m_bNoDispUpdates, TRUE);
797 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
798 #endif
801 BOOL CLogDlg::Cancel()
803 return m_bCancelled;
806 void CLogDlg::SaveSplitterPos()
808 if (!IsIconic())
810 CRegDWORD regPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
811 CRegDWORD regPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
812 RECT rectSplitter;
813 m_wndSplitter1.GetWindowRect(&rectSplitter);
814 ScreenToClient(&rectSplitter);
815 regPos1 = rectSplitter.top;
816 m_wndSplitter2.GetWindowRect(&rectSplitter);
817 ScreenToClient(&rectSplitter);
818 regPos2 = rectSplitter.top;
822 void CLogDlg::OnCancel()
824 // canceling means stopping the working thread if it's still running.
825 // we do this by using the Subversion cancel callback.
826 // But canceling can also mean just to close the dialog, depending on the
827 // text shown on the cancel button (it could simply read "OK").
828 CString temp, temp2;
829 GetDlgItemText(IDOK, temp);
830 temp2.LoadString(IDS_MSGBOX_CANCEL);
831 if ((temp.Compare(temp2)==0)||(this->IsThreadRunning()))
833 m_bCancelled = true;
834 return;
836 UpdateData();
837 if (m_bSaveStrict)
838 m_regLastStrict = m_bStrict;
839 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry"));
840 reg = m_btnShow.GetCurrentEntry();
841 SaveSplitterPos();
842 __super::OnCancel();
845 CString CLogDlg::MakeShortMessage(const CString& message)
847 bool bFoundShort = true;
848 CString sShortMessage = m_ProjectProperties.GetLogSummary(message);
849 if (sShortMessage.IsEmpty())
851 bFoundShort = false;
852 sShortMessage = message;
854 // Remove newlines and tabs 'cause those are not shown nicely in the list control
855 sShortMessage.Replace(_T("\r"), _T(""));
856 sShortMessage.Replace(_T("\t"), _T(" "));
858 // Suppose the first empty line separates 'summary' from the rest of the message.
859 int found = sShortMessage.Find(_T("\n\n"));
860 // To avoid too short 'short' messages
861 // (e.g. if the message looks something like "Bugfix:\n\n*done this\n*done that")
862 // only use the empty newline as a separator if it comes after at least 15 chars.
863 if ((!bFoundShort)&&(found >= 15))
865 sShortMessage = sShortMessage.Left(found);
867 sShortMessage.Replace('\n', ' ');
868 return sShortMessage;
871 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)
873 #if 0
874 if (rev == SVN_INVALID_REVNUM)
876 m_childCounter--;
877 return TRUE;
880 // this is the callback function which receives the data for every revision we ask the log for
881 // we store this information here one by one.
882 m_logcounter += 1;
883 if (m_startrev == -1)
884 m_startrev = rev;
885 if (m_limit != 0)
887 m_limitcounter--;
888 m_LogProgress.SetPos(m_limit - m_limitcounter);
890 else if (m_startrev.IsNumber() && m_startrev.IsNumber())
891 m_LogProgress.SetPos((git_revnum_t)m_startrev-rev+(git_revnum_t)m_endrev);
892 __time64_t ttime = time/1000000L;
893 if (m_tTo < (DWORD)ttime)
894 m_tTo = (DWORD)ttime;
895 if (m_tFrom > (DWORD)ttime)
896 m_tFrom = (DWORD)ttime;
897 if ((m_lowestRev > rev)||(m_lowestRev < 0))
898 m_lowestRev = rev;
899 // Add as many characters from the log message to the list control
900 PLOGENTRYDATA pLogItem = new LOGENTRYDATA;
901 pLogItem->bCopies = !!copies;
903 // find out if this item was copied in the revision
904 BOOL copiedself = FALSE;
905 if (copies)
907 for (INT_PTR cpPathIndex = 0; cpPathIndex < cpaths->GetCount(); ++cpPathIndex)
909 LogChangedPath * cpath = cpaths->GetAt(cpPathIndex);
910 if (!cpath->sCopyFromPath.IsEmpty() && (cpath->sPath.Compare(m_sSelfRelativeURL) == 0))
912 // note: this only works if the log is fetched top-to-bottom
913 // but since we do that, it shouldn't be a problem
914 m_sSelfRelativeURL = cpath->sCopyFromPath;
915 copiedself = TRUE;
916 break;
920 pLogItem->bCopiedSelf = copiedself;
921 pLogItem->tmDate = ttime;
922 pLogItem->sAuthor = author;
923 pLogItem->sDate = date;
924 pLogItem->sShortMessage = MakeShortMessage(message);
925 pLogItem->dwFileChanges = filechanges;
926 pLogItem->actions = actions;
927 pLogItem->haschildren = haschildren;
928 pLogItem->childStackDepth = m_childCounter;
929 m_maxChild = max(m_childCounter, m_maxChild);
930 if (haschildren)
931 m_childCounter++;
932 pLogItem->sBugIDs = m_ProjectProperties.FindBugID(message).Trim();
934 // split multi line log entries and concatenate them
935 // again but this time with \r\n as line separators
936 // so that the edit control recognizes them
939 if (message.GetLength()>0)
941 m_sMessageBuf = message;
942 m_sMessageBuf.Replace(_T("\n\r"), _T("\n"));
943 m_sMessageBuf.Replace(_T("\r\n"), _T("\n"));
944 if (m_sMessageBuf.Right(1).Compare(_T("\n"))==0)
945 m_sMessageBuf = m_sMessageBuf.Left(m_sMessageBuf.GetLength()-1);
947 else
948 m_sMessageBuf.Empty();
949 pLogItem->sMessage = m_sMessageBuf;
950 pLogItem->Rev = rev;
952 // move-construct path array
954 pLogItem->pArChangedPaths = new LogChangedPathArray (*cpaths);
955 cpaths->RemoveAll();
957 catch (CException * e)
959 ::MessageBox(NULL, _T("not enough memory!"), _T("TortoiseGit"), MB_ICONERROR);
960 e->Delete();
961 m_bCancelled = TRUE;
963 m_logEntries.push_back(pLogItem);
964 m_arShownList.Add(pLogItem);
965 #endif
966 return TRUE;
969 GitRev g_rev;
970 //this is the thread function which calls the subversion function
975 void CLogDlg::CopyChangedSelectionToClipBoard()
977 #if 0
978 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
979 if (pos == NULL)
980 return; // nothing is selected, get out of here
982 CString sPaths;
984 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
985 if (pos)
987 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
988 while (pos)
990 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
991 sPaths += m_currentChangedPathList[nItem].GetGitPathString();
992 sPaths += _T("\r\n");
995 else
997 // only one revision is selected in the log dialog top pane
998 // but multiple items could be selected in the changed items list
999 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
1000 while (pos)
1002 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
1003 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->GetAt(nItem);
1005 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
1007 // some items are hidden! So find out which item the user really selected
1008 INT_PTR selRealIndex = -1;
1009 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
1011 if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1012 selRealIndex++;
1013 if (selRealIndex == nItem)
1015 changedlogpath = pLogEntry->pArChangedPaths->GetAt(hiddenindex);
1016 break;
1020 if (changedlogpath)
1022 sPaths += changedlogpath->sPath;
1023 sPaths += _T("\r\n");
1027 sPaths.Trim();
1028 CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());
1029 #endif
1032 BOOL CLogDlg::IsDiffPossible(LogChangedPath * changedpath, git_revnum_t rev)
1034 #if 0
1035 CString added, deleted;
1036 if (changedpath == NULL)
1037 return false;
1039 if ((rev > 1)&&(changedpath->action != LOGACTIONS_DELETED))
1041 if (changedpath->action == LOGACTIONS_ADDED) // file is added
1043 if (changedpath->lCopyFromRev == 0)
1044 return FALSE; // but file was not added with history
1046 return TRUE;
1048 #endif
1049 return FALSE;
1052 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)
1054 // we have two separate context menus:
1055 // one shown on the log message list control,
1056 // the other shown in the changed-files list control
1057 int selCount = m_LogList.GetSelectedCount();
1058 if (pWnd == &m_LogList)
1060 //ShowContextMenuForRevisions(pWnd, point);
1062 else if (pWnd == &m_ChangedFileListCtrl)
1064 ShowContextMenuForChangedpaths(pWnd, point);
1066 else if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))
1068 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1069 int selIndex = -1;
1070 if (pos)
1071 selIndex = m_LogList.GetNextSelectedItem(pos);
1072 if ((point.x == -1) && (point.y == -1))
1074 CRect rect;
1075 GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);
1076 ClientToScreen(&rect);
1077 point = rect.CenterPoint();
1079 CString sMenuItemText;
1080 CMenu popup;
1081 if (popup.CreatePopupMenu())
1083 // add the 'default' entries
1084 sMenuItemText.LoadString(IDS_SCIEDIT_COPY);
1085 popup.AppendMenu(MF_STRING | MF_ENABLED, WM_COPY, sMenuItemText);
1086 sMenuItemText.LoadString(IDS_SCIEDIT_SELECTALL);
1087 popup.AppendMenu(MF_STRING | MF_ENABLED, EM_SETSEL, sMenuItemText);
1089 if (selIndex >= 0)
1091 popup.AppendMenu(MF_SEPARATOR);
1092 sMenuItemText.LoadString(IDS_LOG_POPUP_EDITLOG);
1093 popup.AppendMenu(MF_STRING | MF_ENABLED, CGitLogList::ID_EDITAUTHOR, sMenuItemText);
1096 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1097 switch (cmd)
1099 case 0:
1100 break; // no command selected
1101 case EM_SETSEL:
1102 case WM_COPY:
1103 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);
1104 break;
1105 case CGitLogList::ID_EDITAUTHOR:
1106 EditLogMessage(selIndex);
1107 break;
1114 LRESULT CLogDlg::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
1116 #if 0
1117 ASSERT(m_pFindDialog != NULL);
1119 if (m_pFindDialog->IsTerminating())
1121 // invalidate the handle identifying the dialog box.
1122 m_pFindDialog = NULL;
1123 return 0;
1126 if(m_pFindDialog->FindNext())
1128 //read data from dialog
1129 CString FindText = m_pFindDialog->GetFindString();
1130 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
1131 bool bFound = false;
1132 tr1::wregex pat;
1133 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
1135 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;
1137 int i;
1138 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)
1140 if (bRegex)
1142 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));
1144 if (regex_search(wstring((LPCTSTR)pLogEntry->sMessage), pat, flags))
1146 bFound = true;
1147 break;
1149 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1150 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
1152 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
1153 if (regex_search(wstring((LPCTSTR)cpath->sCopyFromPath), pat, flags))
1155 bFound = true;
1156 --i;
1157 break;
1159 if (regex_search(wstring((LPCTSTR)cpath->sPath), pat, flags))
1161 bFound = true;
1162 --i;
1163 break;
1167 else
1169 if (bMatchCase)
1171 if (m_logEntries[i]->sMessage.Find(FindText) >= 0)
1173 bFound = true;
1174 break;
1176 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));
1177 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1178 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
1180 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
1181 if (cpath->sCopyFromPath.Find(FindText)>=0)
1183 bFound = true;
1184 --i;
1185 break;
1187 if (cpath->sPath.Find(FindText)>=0)
1189 bFound = true;
1190 --i;
1191 break;
1195 else
1197 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));
1198 CString msg = pLogEntry->sMessage;
1199 msg = msg.MakeLower();
1200 CString find = FindText.MakeLower();
1201 if (msg.Find(find) >= 0)
1203 bFound = TRUE;
1204 break;
1206 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1207 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
1209 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
1210 CString lowerpath = cpath->sCopyFromPath;
1211 lowerpath.MakeLower();
1212 if (lowerpath.Find(find)>=0)
1214 bFound = TRUE;
1215 --i;
1216 break;
1218 lowerpath = cpath->sPath;
1219 lowerpath.MakeLower();
1220 if (lowerpath.Find(find)>=0)
1222 bFound = TRUE;
1223 --i;
1224 break;
1229 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
1230 if (bFound)
1232 this->m_nSearchIndex = (i+1);
1233 m_LogList.EnsureVisible(i, FALSE);
1234 m_LogList.SetItemState(m_LogList.GetSelectionMark(), 0, LVIS_SELECTED);
1235 m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1236 m_LogList.SetSelectionMark(i);
1237 FillLogMessageCtrl();
1238 UpdateData(FALSE);
1239 m_nSearchIndex++;
1240 if (m_nSearchIndex >= m_arShownList.GetCount())
1241 m_nSearchIndex = (int)m_arShownList.GetCount()-1;
1243 } // if(m_pFindDialog->FindNext())
1244 UpdateLogInfoLabel();
1245 #endif
1246 return 0;
1249 void CLogDlg::OnOK()
1251 #if 0
1252 // since the log dialog is also used to select revisions for other
1253 // dialogs, we have to do some work before closing this dialog
1254 if (GetFocus() != GetDlgItem(IDOK))
1255 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter
1256 if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))
1257 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.
1259 CString temp;
1260 CString buttontext;
1261 GetDlgItemText(IDOK, buttontext);
1262 temp.LoadString(IDS_MSGBOX_CANCEL);
1263 if (temp.Compare(buttontext) != 0)
1264 __super::OnOK(); // only exit if the button text matches, and that will match only if the thread isn't running anymore
1265 m_bCancelled = TRUE;
1266 m_selectedRevs.Clear();
1267 m_selectedRevsOneRange.Clear();
1268 if (m_pNotifyWindow)
1270 int selIndex = m_LogList.GetSelectionMark();
1271 if (selIndex >= 0)
1273 PLOGENTRYDATA pLogEntry = NULL;
1274 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1275 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
1276 m_selectedRevs.AddRevision(pLogEntry->Rev);
1277 git_revnum_t lowerRev = pLogEntry->Rev;
1278 git_revnum_t higherRev = lowerRev;
1279 while (pos)
1281 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
1282 git_revnum_t rev = pLogEntry->Rev;
1283 m_selectedRevs.AddRevision(pLogEntry->Rev);
1284 if (lowerRev > rev)
1285 lowerRev = rev;
1286 if (higherRev < rev)
1287 higherRev = rev;
1289 if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())
1291 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);
1293 BOOL bSentMessage = FALSE;
1294 if (m_LogList.GetSelectedCount() == 1)
1296 // if only one revision is selected, check if the path/url with which the dialog was started
1297 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.
1298 // if it was copied, use the copy from revision as lowerRev
1299 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))
1301 CString sUrl = m_path.GetGitPathString();
1302 if (!m_path.IsUrl())
1304 sUrl = GetURLFromPath(m_path);
1306 sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());
1307 for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)
1309 LogChangedPath * pData = pLogEntry->pArChangedPaths->GetAt(cp);
1310 if (pData)
1312 if (sUrl.Compare(pData->sPath) == 0)
1314 if (!pData->sCopyFromPath.IsEmpty())
1316 lowerRev = pData->lCopyFromRev;
1317 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);
1318 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);
1319 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1320 bSentMessage = TRUE;
1327 if ( !bSentMessage )
1329 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);
1330 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);
1331 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1332 if (m_selectedRevsOneRange.GetCount())
1333 m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);
1337 UpdateData();
1338 if (m_bSaveStrict)
1339 m_regLastStrict = m_bStrict;
1340 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry"));
1341 reg = m_btnShow.GetCurrentEntry();
1342 SaveSplitterPos();
1343 #endif
1346 void CLogDlg::OnNMDblclkChangedFileList(NMHDR * /*pNMHDR*/, LRESULT *pResult)
1348 // a double click on an entry in the changed-files list has happened
1349 *pResult = 0;
1351 DiffSelectedFile();
1354 void CLogDlg::DiffSelectedFile()
1356 #if 0
1357 if (m_bThreadRunning)
1358 return;
1359 UpdateLogInfoLabel();
1360 INT_PTR selIndex = m_ChangedFileListCtrl.GetSelectionMark();
1361 if (selIndex < 0)
1362 return;
1363 if (m_ChangedFileListCtrl.GetSelectedCount() == 0)
1364 return;
1365 // find out if there's an entry selected in the log list
1366 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1367 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
1368 git_revnum_t rev1 = pLogEntry->Rev;
1369 git_revnum_t rev2 = rev1;
1370 if (pos)
1372 while (pos)
1374 // there's at least a second entry selected in the log list: several revisions selected!
1375 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
1376 if (pLogEntry)
1378 rev1 = max(rev1,(long)pLogEntry->Rev);
1379 rev2 = min(rev2,(long)pLogEntry->Rev);
1382 rev2--;
1383 // now we have both revisions selected in the log list, so we can do a diff of the selected
1384 // entry in the changed files list with these two revisions.
1385 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1387 else
1389 rev2 = rev1-1;
1390 // nothing or only one revision selected in the log list
1391 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);
1393 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
1395 // some items are hidden! So find out which item the user really clicked on
1396 INT_PTR selRealIndex = -1;
1397 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
1399 if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1400 selRealIndex++;
1401 if (selRealIndex == selIndex)
1403 selIndex = hiddenindex;
1404 changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);
1405 break;
1410 if (IsDiffPossible(changedpath, rev1))
1412 // diffs with renamed files are possible
1413 if ((changedpath)&&(!changedpath->sCopyFromPath.IsEmpty()))
1414 rev2 = changedpath->lCopyFromRev;
1415 else
1417 // if the path was modified but the parent path was 'added with history'
1418 // then we have to use the copy from revision of the parent path
1419 CTGitPath cpath = CTGitPath(changedpath->sPath);
1420 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
1422 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->GetAt(flist)->sPath);
1423 if (p.IsAncestorOf(cpath))
1425 if (!pLogEntry->pArChangedPaths->GetAt(flist)->sCopyFromPath.IsEmpty())
1426 rev2 = pLogEntry->pArChangedPaths->GetAt(flist)->lCopyFromRev;
1430 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1432 else
1434 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1435 CTGitPath tempfile2 = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1436 GitRev r = rev1;
1437 // deleted files must be opened from the revision before the deletion
1438 if (changedpath->action == LOGACTIONS_DELETED)
1439 r = rev1-1;
1440 m_bCancelled = false;
1442 CProgressDlg progDlg;
1443 progDlg.SetTitle(IDS_APPNAME);
1444 progDlg.SetAnimation(IDR_DOWNLOAD);
1445 CString sInfoLine;
1446 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)(m_sRepositoryRoot + changedpath->sPath), (LPCTSTR)r.ToString());
1447 progDlg.SetLine(1, sInfoLine, true);
1448 SetAndClearProgressInfo(&progDlg);
1449 progDlg.ShowModeless(m_hWnd);
1451 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), r, r, tempfile))
1453 m_bCancelled = false;
1454 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), GitRev::REV_HEAD, r, tempfile))
1456 progDlg.Stop();
1457 SetAndClearProgressInfo((HWND)NULL);
1458 CMessageBox::Show(m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1459 return;
1462 progDlg.Stop();
1463 SetAndClearProgressInfo((HWND)NULL);
1465 CString sName1, sName2;
1466 sName1.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1);
1467 sName2.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1-1);
1468 CAppUtils::DiffFlags flags;
1469 flags.AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1470 if (changedpath->action == LOGACTIONS_DELETED)
1471 CAppUtils::StartExtDiff(tempfile, tempfile2, sName2, sName1, flags);
1472 else
1473 CAppUtils::StartExtDiff(tempfile2, tempfile, sName2, sName1, flags);
1476 #endif
1480 void CLogDlg::DoDiffFromLog(INT_PTR selIndex, GitRev* rev1, GitRev* rev2, bool blame, bool unified)
1482 DialogEnableWindow(IDOK, FALSE);
1483 // SetPromptApp(&theApp);
1484 theApp.DoWaitCursor(1);
1486 CString temppath;
1487 GetTempPath(temppath);
1489 CString file1;
1490 file1.Format(_T("%s%s_%s%s"),
1491 temppath,
1492 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1493 rev1->m_CommitHash.Left(6),
1494 (*m_currentChangedArray)[selIndex].GetFileExtension());
1496 CString file2;
1497 file2.Format(_T("%s\\%s_%s%s"),
1498 temppath,
1499 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1500 rev2->m_CommitHash.Left(6),
1501 (*m_currentChangedArray)[selIndex].GetFileExtension());
1503 CString cmd;
1505 cmd.Format(_T("git.cmd cat-file -p %s:%s"),rev1->m_CommitHash,(*m_currentChangedArray)[selIndex].GetGitPathString());
1506 g_Git.RunLogFile(cmd,file1);
1507 cmd.Format(_T("git.cmd cat-file -p %s:%s"),rev2->m_CommitHash,(*m_currentChangedArray)[selIndex].GetGitPathString());
1508 g_Git.RunLogFile(cmd,file2);
1510 CAppUtils::DiffFlags flags;
1511 CAppUtils::StartExtDiff(file1,file2,_T("A"),_T("B"),flags);
1513 #if 0
1514 //get the filename
1515 CString filepath;
1516 if (Git::PathIsURL(m_path))
1518 filepath = m_path.GetGitPathString();
1520 else
1522 filepath = GetURLFromPath(m_path);
1523 if (filepath.IsEmpty())
1525 theApp.DoWaitCursor(-1);
1526 CString temp;
1527 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1528 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1529 TRACE(_T("could not retrieve the URL of the file!\n"));
1530 EnableOKButton();
1531 theApp.DoWaitCursor(-11);
1532 return; //exit
1535 m_bCancelled = FALSE;
1536 filepath = GetRepositoryRoot(CTGitPath(filepath));
1538 CString firstfile, secondfile;
1539 if (m_LogList.GetSelectedCount()==1)
1541 int s = m_LogList.GetSelectionMark();
1542 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(s));
1543 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);
1544 firstfile = changedpath->sPath;
1545 secondfile = firstfile;
1546 if ((rev2 == rev1-1)&&(changedpath->lCopyFromRev > 0)) // is it an added file with history?
1548 secondfile = changedpath->sCopyFromPath;
1549 rev2 = changedpath->lCopyFromRev;
1552 else
1554 firstfile = m_currentChangedPathList[selIndex].GetGitPathString();
1555 secondfile = firstfile;
1558 firstfile = filepath + firstfile.Trim();
1559 secondfile = filepath + secondfile.Trim();
1561 GitDiff diff(this, this->m_hWnd, true);
1562 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1563 diff.SetHEADPeg(m_LogRevision);
1564 if (unified)
1566 if (PromptShown())
1567 diff.ShowUnifiedDiff(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1);
1568 else
1569 CAppUtils::StartShowUnifiedDiff(m_hWnd, CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), m_LogRevision);
1571 else
1573 if (diff.ShowCompare(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), false, blame))
1575 if (firstfile.Compare(secondfile)==0)
1577 git_revnum_t baseRev = 0;
1578 diff.DiffProps(CTGitPath(firstfile), rev2, rev1, baseRev);
1583 #endif
1585 theApp.DoWaitCursor(-1);
1586 EnableOKButton();
1589 BOOL CLogDlg::Open(bool bOpenWith,CString changedpath, git_revnum_t rev)
1591 #if 0
1592 DialogEnableWindow(IDOK, FALSE);
1593 SetPromptApp(&theApp);
1594 theApp.DoWaitCursor(1);
1595 CString filepath;
1596 if (Git::PathIsURL(m_path))
1598 filepath = m_path.GetGitPathString();
1600 else
1602 filepath = GetURLFromPath(m_path);
1603 if (filepath.IsEmpty())
1605 theApp.DoWaitCursor(-1);
1606 CString temp;
1607 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1608 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1609 TRACE(_T("could not retrieve the URL of the file!\n"));
1610 EnableOKButton();
1611 return FALSE;
1614 m_bCancelled = false;
1615 filepath = GetRepositoryRoot(CTGitPath(filepath));
1616 filepath += changedpath;
1618 CProgressDlg progDlg;
1619 progDlg.SetTitle(IDS_APPNAME);
1620 progDlg.SetAnimation(IDR_DOWNLOAD);
1621 CString sInfoLine;
1622 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)GitRev(rev).ToString());
1623 progDlg.SetLine(1, sInfoLine, true);
1624 SetAndClearProgressInfo(&progDlg);
1625 progDlg.ShowModeless(m_hWnd);
1627 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(filepath), rev);
1628 m_bCancelled = false;
1629 if (!Cat(CTGitPath(filepath), GitRev(rev), rev, tempfile))
1631 progDlg.Stop();
1632 SetAndClearProgressInfo((HWND)NULL);
1633 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1634 EnableOKButton();
1635 theApp.DoWaitCursor(-1);
1636 return FALSE;
1638 progDlg.Stop();
1639 SetAndClearProgressInfo((HWND)NULL);
1640 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1641 if (!bOpenWith)
1643 int ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1644 if (ret <= HINSTANCE_ERROR)
1645 bOpenWith = true;
1647 if (bOpenWith)
1649 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1650 cmd += tempfile.GetWinPathString() + _T(" ");
1651 CAppUtils::LaunchApplication(cmd, NULL, false);
1653 EnableOKButton();
1654 theApp.DoWaitCursor(-1);
1655 #endif
1656 return TRUE;
1659 void CLogDlg::EditAuthor(const CLogDataVector& logs)
1661 #if 0
1662 CString url;
1663 CString name;
1664 if (logs.size() == 0)
1665 return;
1666 DialogEnableWindow(IDOK, FALSE);
1667 SetPromptApp(&theApp);
1668 theApp.DoWaitCursor(1);
1669 if (Git::PathIsURL(m_path))
1670 url = m_path.GetGitPathString();
1671 else
1673 url = GetURLFromPath(m_path);
1675 name = Git_PROP_REVISION_AUTHOR;
1677 CString value = RevPropertyGet(name, CTGitPath(url), logs[0]->Rev);
1678 CString sOldValue = value;
1679 value.Replace(_T("\n"), _T("\r\n"));
1680 CInputDlg dlg(this);
1681 dlg.m_sHintText.LoadString(IDS_LOG_AUTHOR);
1682 dlg.m_sInputText = value;
1683 dlg.m_sTitle.LoadString(IDS_LOG_AUTHOREDITTITLE);
1684 dlg.m_pProjectProperties = &m_ProjectProperties;
1685 dlg.m_bUseLogWidth = false;
1686 if (dlg.DoModal() == IDOK)
1688 dlg.m_sInputText.Replace(_T("\r"), _T(""));
1690 LogCache::CCachedLogInfo* toUpdate
1691 = GetLogCache (CTGitPath (m_sRepositoryRoot));
1693 CProgressDlg progDlg;
1694 progDlg.SetTitle(IDS_APPNAME);
1695 progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));
1696 progDlg.SetTime(true);
1697 progDlg.SetShowProgressBar(true);
1698 progDlg.ShowModeless(m_hWnd);
1699 for (DWORD i=0; i<logs.size(); ++i)
1701 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), logs[i]->Rev))
1703 progDlg.Stop();
1704 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1705 break;
1707 else
1710 logs[i]->sAuthor = dlg.m_sInputText;
1711 m_LogList.Invalidate();
1713 // update the log cache
1715 if (toUpdate != NULL)
1717 // log caching is active
1719 LogCache::CCachedLogInfo newInfo;
1720 newInfo.Insert ( logs[i]->Rev
1721 , (const char*) CUnicodeUtils::GetUTF8 (logs[i]->sAuthor)
1722 , ""
1724 , LogCache::CRevisionInfoContainer::HAS_AUTHOR);
1726 toUpdate->Update (newInfo);
1729 progDlg.SetProgress64(i, logs.size());
1731 progDlg.Stop();
1733 theApp.DoWaitCursor(-1);
1734 EnableOKButton();
1735 #endif
1738 void CLogDlg::EditLogMessage(int index)
1740 #if 0
1741 CString url;
1742 CString name;
1743 DialogEnableWindow(IDOK, FALSE);
1744 SetPromptApp(&theApp);
1745 theApp.DoWaitCursor(1);
1746 if (Git::PathIsURL(m_path))
1747 url = m_path.GetGitPathString();
1748 else
1750 url = GetURLFromPath(m_path);
1752 name = Git_PROP_REVISION_LOG;
1754 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(index));
1755 m_bCancelled = FALSE;
1756 CString value = RevPropertyGet(name, CTGitPath(url), pLogEntry->Rev);
1757 CString sOldValue = value;
1758 value.Replace(_T("\n"), _T("\r\n"));
1759 CInputDlg dlg(this);
1760 dlg.m_sHintText.LoadString(IDS_LOG_MESSAGE);
1761 dlg.m_sInputText = value;
1762 dlg.m_sTitle.LoadString(IDS_LOG_MESSAGEEDITTITLE);
1763 dlg.m_pProjectProperties = &m_ProjectProperties;
1764 dlg.m_bUseLogWidth = true;
1765 if (dlg.DoModal() == IDOK)
1767 dlg.m_sInputText.Replace(_T("\r"), _T(""));
1768 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), pLogEntry->Rev))
1770 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1772 else
1774 pLogEntry->sShortMessage = MakeShortMessage(dlg.m_sInputText);
1775 // split multi line log entries and concatenate them
1776 // again but this time with \r\n as line separators
1777 // so that the edit control recognizes them
1778 if (dlg.m_sInputText.GetLength()>0)
1780 m_sMessageBuf = dlg.m_sInputText;
1781 dlg.m_sInputText.Replace(_T("\n\r"), _T("\n"));
1782 dlg.m_sInputText.Replace(_T("\r\n"), _T("\n"));
1783 if (dlg.m_sInputText.Right(1).Compare(_T("\n"))==0)
1784 dlg.m_sInputText = dlg.m_sInputText.Left(dlg.m_sInputText.GetLength()-1);
1786 else
1787 dlg.m_sInputText.Empty();
1788 pLogEntry->sMessage = dlg.m_sInputText;
1789 pLogEntry->sBugIDs = m_ProjectProperties.FindBugID(dlg.m_sInputText);
1790 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
1791 pMsgView->SetWindowText(_T(" "));
1792 pMsgView->SetWindowText(dlg.m_sInputText);
1793 m_ProjectProperties.FindBugID(dlg.m_sInputText, pMsgView);
1794 m_LogList.Invalidate();
1796 // update the log cache
1798 LogCache::CCachedLogInfo* toUpdate
1799 = GetLogCache (CTGitPath (m_sRepositoryRoot));
1800 if (toUpdate != NULL)
1802 // log caching is active
1804 LogCache::CCachedLogInfo newInfo;
1805 newInfo.Insert ( pLogEntry->Rev
1806 , ""
1807 , (const char*) CUnicodeUtils::GetUTF8 (pLogEntry->sMessage)
1809 , LogCache::CRevisionInfoContainer::HAS_COMMENT);
1811 toUpdate->Update (newInfo);
1815 theApp.DoWaitCursor(-1);
1816 EnableOKButton();
1817 #endif
1819 #if 0
1820 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)
1822 // Skip Ctrl-C when copying text out of the log message or search filter
1823 BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );
1824 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
1826 if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1828 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1830 DiffSelectedRevWithPrevious();
1831 return TRUE;
1834 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
1836 DiffSelectedFile();
1837 return TRUE;
1840 if (m_hAccel && !bSkipAccelerator)
1842 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1843 if (ret)
1844 return TRUE;
1847 m_tooltips.RelayEvent(pMsg);
1848 return __super::PreTranslateMessage(pMsg);
1850 #endif
1852 BOOL CLogDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1854 if (this->IsThreadRunning())
1856 // only show the wait cursor over the list control
1857 if ((pWnd)&&
1858 ((pWnd == GetDlgItem(IDC_LOGLIST))||
1859 (pWnd == GetDlgItem(IDC_MSGVIEW))||
1860 (pWnd == GetDlgItem(IDC_LOGMSG))))
1862 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1863 SetCursor(hCur);
1864 return TRUE;
1867 if ((pWnd) && (pWnd == GetDlgItem(IDC_MSGVIEW)))
1868 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1870 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1871 SetCursor(hCur);
1872 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1875 void CLogDlg::OnBnClickedHelp()
1877 OnHelp();
1880 void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1882 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1883 *pResult = 0;
1884 if (this->IsThreadRunning())
1885 return;
1886 if (pNMLV->iItem >= 0)
1888 m_nSearchIndex = pNMLV->iItem;
1889 if (pNMLV->iSubItem != 0)
1890 return;
1891 if ((pNMLV->iItem == m_LogList.m_arShownList.GetCount())&&(m_bStrict)&&(1/*m_bStrictStopped*/))
1893 // remove the selected state
1894 if (pNMLV->uChanged & LVIF_STATE)
1896 m_LogList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);
1897 FillLogMessageCtrl();
1898 UpdateData(FALSE);
1899 UpdateLogInfoLabel();
1901 return;
1903 if (pNMLV->uChanged & LVIF_STATE)
1905 FillLogMessageCtrl();
1906 UpdateData(FALSE);
1909 else
1911 FillLogMessageCtrl();
1912 UpdateData(FALSE);
1914 EnableOKButton();
1915 UpdateLogInfoLabel();
1918 void CLogDlg::OnEnLinkMsgview(NMHDR *pNMHDR, LRESULT *pResult)
1920 ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);
1921 if (pEnLink->msg == WM_LBUTTONUP)
1923 CString url, msg;
1924 GetDlgItemText(IDC_MSGVIEW, msg);
1925 msg.Replace(_T("\r\n"), _T("\n"));
1926 url = msg.Mid(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax-pEnLink->chrg.cpMin);
1927 if (!::PathIsURL(url))
1929 url = m_ProjectProperties.GetBugIDUrl(url);
1930 url = GetAbsoluteUrlFromRelativeUrl(url);
1932 if (!url.IsEmpty())
1933 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
1935 *pResult = 0;
1938 void CLogDlg::OnBnClickedStatbutton()
1940 #if 0
1941 if (m_bThreadRunning)
1942 return;
1943 if (m_arShownList.IsEmpty())
1944 return; // nothing is shown, so no statistics.
1945 // the statistics dialog expects the log entries to be sorted by date
1946 SortByColumn(3, false);
1947 CPtrArray shownlist;
1948 RecalculateShownList(&shownlist);
1949 // create arrays which are aware of the current filter
1950 CStringArray m_arAuthorsFiltered;
1951 CDWordArray m_arDatesFiltered;
1952 CDWordArray m_arFileChangesFiltered;
1953 for (INT_PTR i=0; i<shownlist.GetCount(); ++i)
1955 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(shownlist.GetAt(i));
1956 CString strAuthor = pLogEntry->sAuthor;
1957 if ( strAuthor.IsEmpty() )
1959 strAuthor.LoadString(IDS_STATGRAPH_EMPTYAUTHOR);
1961 m_arAuthorsFiltered.Add(strAuthor);
1962 m_arDatesFiltered.Add(static_cast<DWORD>(pLogEntry->tmDate));
1963 m_arFileChangesFiltered.Add(pLogEntry->dwFileChanges);
1965 CStatGraphDlg dlg;
1966 dlg.m_parAuthors = &m_arAuthorsFiltered;
1967 dlg.m_parDates = &m_arDatesFiltered;
1968 dlg.m_parFileChanges = &m_arFileChangesFiltered;
1969 dlg.m_path = m_path;
1970 dlg.DoModal();
1971 // restore the previous sorting
1972 SortByColumn(m_nSortColumn, m_bAscending);
1973 OnTimer(LOGFILTER_TIMER);
1974 #endif
1977 #if 0
1978 void CLogDlg::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1981 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1982 // Take the default processing unless we set this to something else below.
1983 *pResult = CDRF_DODEFAULT;
1985 if (m_bNoDispUpdates)
1986 return;
1988 switch (pLVCD->nmcd.dwDrawStage)
1990 case CDDS_PREPAINT:
1992 *pResult = CDRF_NOTIFYITEMDRAW;
1993 return;
1995 break;
1996 case CDDS_ITEMPREPAINT:
1998 // This is the prepaint stage for an item. Here's where we set the
1999 // item's text color.
2001 // Tell Windows to send draw notifications for each subitem.
2002 *pResult = CDRF_NOTIFYSUBITEMDRAW;
2004 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
2006 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
2008 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);
2009 if (data)
2011 #if 0
2012 if (data->bCopiedSelf)
2014 // only change the background color if the item is not 'hot' (on vista with themes enabled)
2015 if (!theme.IsAppThemed() || !m_bVista || ((pLVCD->nmcd.uItemState & CDIS_HOT)==0))
2016 pLVCD->clrTextBk = GetSysColor(COLOR_MENU);
2019 if (data->bCopies)
2020 crText = m_Colors.GetColor(CColors::Modified);
2021 #endif
2022 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
2023 // crText = GetSysColor(COLOR_GRAYTEXT);
2024 // if (data->Rev == m_wcRev)
2025 // {
2026 // SelectObject(pLVCD->nmcd.hdc, m_boldFont);
2027 // We changed the font, so we're returning CDRF_NEWFONT. This
2028 // tells the control to recalculate the extent of the text.
2029 // *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
2030 // }
2033 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
2035 if (m_bStrictStopped)
2036 crText = GetSysColor(COLOR_GRAYTEXT);
2038 // Store the color back in the NMLVCUSTOMDRAW struct.
2039 pLVCD->clrText = crText;
2040 return;
2042 break;
2043 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
2045 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
2047 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
2049 if (pLVCD->iSubItem == 1)
2051 *pResult = CDRF_DODEFAULT;
2053 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
2054 return;
2056 int nIcons = 0;
2057 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
2058 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
2060 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec));
2062 // Get the selected state of the
2063 // item being drawn.
2064 LVITEM rItem;
2065 SecureZeroMemory(&rItem, sizeof(LVITEM));
2066 rItem.mask = LVIF_STATE;
2067 rItem.iItem = pLVCD->nmcd.dwItemSpec;
2068 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
2069 m_LogList.GetItem(&rItem);
2071 CRect rect;
2072 m_LogList.GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
2074 // Fill the background
2075 if (theme.IsAppThemed() && m_bVista)
2077 theme.Open(m_hWnd, L"Explorer");
2078 int state = LISS_NORMAL;
2079 if (rItem.state & LVIS_SELECTED)
2081 if (::GetFocus() == m_LogList.m_hWnd)
2082 state |= LISS_SELECTED;
2083 else
2084 state |= LISS_SELECTEDNOTFOCUS;
2086 else
2088 #if 0
2089 if (pLogEntry->bCopiedSelf)
2091 // unfortunately, the pLVCD->nmcd.uItemState does not contain valid
2092 // information at this drawing stage. But we can check the whether the
2093 // previous stage changed the background color of the item
2094 if (pLVCD->clrTextBk == GetSysColor(COLOR_MENU))
2096 HBRUSH brush;
2097 brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));
2098 if (brush)
2100 ::FillRect(pLVCD->nmcd.hdc, &rect, brush);
2101 ::DeleteObject(brush);
2105 #endif
2108 if (theme.IsBackgroundPartiallyTransparent(LVP_LISTDETAIL, state))
2109 theme.DrawParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
2111 theme.DrawBackground(pLVCD->nmcd.hdc, LVP_LISTDETAIL, state, &rect, NULL);
2113 else
2115 HBRUSH brush;
2116 if (rItem.state & LVIS_SELECTED)
2118 if (::GetFocus() == m_LogList.m_hWnd)
2119 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
2120 else
2121 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
2123 else
2125 //if (pLogEntry->bCopiedSelf)
2126 // brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));
2127 //else
2128 brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
2130 if (brush == NULL)
2131 return;
2133 ::FillRect(pLVCD->nmcd.hdc, &rect, brush);
2134 ::DeleteObject(brush);
2137 // Draw the icon(s) into the compatible DC
2138 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_MODIFIED)
2139 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
2140 nIcons++;
2142 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_ADDED)
2143 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
2144 nIcons++;
2146 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_DELETED)
2147 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
2148 nIcons++;
2150 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
2151 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
2152 nIcons++;
2153 *pResult = CDRF_SKIPDEFAULT;
2154 return;
2157 break;
2159 *pResult = CDRF_DODEFAULT;
2162 #endif
2164 void CLogDlg::OnNMCustomdrawChangedFileList(NMHDR *pNMHDR, LRESULT *pResult)
2167 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
2168 // Take the default processing unless we set this to something else below.
2169 *pResult = CDRF_DODEFAULT;
2171 // if (m_bNoDispUpdates)
2172 // return;
2174 // First thing - check the draw stage. If it's the control's prepaint
2175 // stage, then tell Windows we want messages for every item.
2177 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
2179 *pResult = CDRF_NOTIFYITEMDRAW;
2181 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
2183 // This is the prepaint stage for an item. Here's where we set the
2184 // item's text color. Our return value will tell Windows to draw the
2185 // item itself, but it will use the new color we set here.
2187 // Tell Windows to paint the control itself.
2188 *pResult = CDRF_DODEFAULT;
2190 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
2191 bool bGrayed = false;
2192 #if 0
2193 if ((m_cHidePaths.GetState() & 0x0003)==BST_INDETERMINATE)
2195 if ((m_currentChangedArray)&&((m_currentChangedArray->GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)))
2197 //if ((*m_currentChangedArray)[(pLVCD->nmcd.dwItemSpec)]sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)!=0)
2199 crText = GetSysColor(COLOR_GRAYTEXT);
2200 bGrayed = true;
2203 else if (m_currentChangedPathList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
2205 //if (m_currentChangedPathList[pLVCD->nmcd.dwItemSpec].GetGitPathString().Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)!=0)
2207 crText = GetSysColor(COLOR_GRAYTEXT);
2208 bGrayed = true;
2213 #endif
2214 if ((!bGrayed)&&(m_currentChangedArray)&&(m_currentChangedArray->GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec))
2216 DWORD action = ((*m_currentChangedArray)[pLVCD->nmcd.dwItemSpec]).m_Action;
2217 if (action == CTGitPath::LOGACTIONS_MODIFIED)
2218 crText = m_Colors.GetColor(CColors::Modified);
2219 if (action == CTGitPath::LOGACTIONS_REPLACED)
2220 crText = m_Colors.GetColor(CColors::Deleted);
2221 if (action == CTGitPath::LOGACTIONS_ADDED)
2222 crText = m_Colors.GetColor(CColors::Added);
2223 if (action == CTGitPath::LOGACTIONS_DELETED)
2224 crText = m_Colors.GetColor(CColors::Deleted);
2227 // Store the color back in the NMLVCUSTOMDRAW struct.
2228 pLVCD->clrText = crText;
2232 void CLogDlg::DoSizeV1(int delta)
2235 RemoveAnchor(IDC_LOGLIST);
2236 RemoveAnchor(IDC_SPLITTERTOP);
2237 RemoveAnchor(IDC_MSGVIEW);
2238 RemoveAnchor(IDC_SPLITTERBOTTOM);
2239 RemoveAnchor(IDC_LOGMSG);
2240 CSplitterControl::ChangeHeight(&m_LogList, delta, CW_TOPALIGN);
2241 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), -delta, CW_BOTTOMALIGN);
2242 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
2243 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
2244 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
2245 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
2246 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
2247 ArrangeLayout();
2248 AdjustMinSize();
2249 SetSplitterRange();
2250 m_LogList.Invalidate();
2251 GetDlgItem(IDC_MSGVIEW)->Invalidate();
2255 void CLogDlg::DoSizeV2(int delta)
2258 RemoveAnchor(IDC_LOGLIST);
2259 RemoveAnchor(IDC_SPLITTERTOP);
2260 RemoveAnchor(IDC_MSGVIEW);
2261 RemoveAnchor(IDC_SPLITTERBOTTOM);
2262 RemoveAnchor(IDC_LOGMSG);
2263 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), delta, CW_TOPALIGN);
2264 CSplitterControl::ChangeHeight(&m_ChangedFileListCtrl, -delta, CW_BOTTOMALIGN);
2265 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
2266 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
2267 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
2268 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
2269 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
2270 ArrangeLayout();
2271 AdjustMinSize();
2272 SetSplitterRange();
2273 GetDlgItem(IDC_MSGVIEW)->Invalidate();
2274 m_ChangedFileListCtrl.Invalidate();
2278 void CLogDlg::AdjustMinSize()
2280 // adjust the minimum size of the dialog to prevent the resizing from
2281 // moving the list control too far down.
2282 CRect rcChgListView;
2283 m_ChangedFileListCtrl.GetClientRect(rcChgListView);
2284 CRect rcLogList;
2285 m_LogList.GetClientRect(rcLogList);
2287 SetMinTrackSize(CSize(m_DlgOrigRect.Width(),
2288 m_DlgOrigRect.Height()-m_ChgOrigRect.Height()-m_LogListOrigRect.Height()-m_MsgViewOrigRect.Height()
2289 +rcChgListView.Height()+rcLogList.Height()+60));
2292 LRESULT CLogDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
2294 switch (message) {
2295 case WM_NOTIFY:
2296 if (wParam == IDC_SPLITTERTOP)
2298 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
2299 DoSizeV1(pHdr->delta);
2301 else if (wParam == IDC_SPLITTERBOTTOM)
2303 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
2304 DoSizeV2(pHdr->delta);
2306 break;
2309 return CResizableDialog::DefWindowProc(message, wParam, lParam);
2312 void CLogDlg::SetSplitterRange()
2314 if ((m_LogList)&&(m_ChangedFileListCtrl))
2316 CRect rcTop;
2317 m_LogList.GetWindowRect(rcTop);
2318 ScreenToClient(rcTop);
2319 CRect rcMiddle;
2320 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(rcMiddle);
2321 ScreenToClient(rcMiddle);
2322 m_wndSplitter1.SetRange(rcTop.top+30, rcMiddle.bottom-20);
2323 CRect rcBottom;
2324 m_ChangedFileListCtrl.GetWindowRect(rcBottom);
2325 ScreenToClient(rcBottom);
2326 m_wndSplitter2.SetRange(rcMiddle.top+30, rcBottom.bottom-20);
2330 LRESULT CLogDlg::OnClickedInfoIcon(WPARAM /*wParam*/, LPARAM lParam)
2332 RECT * rect = (LPRECT)lParam;
2333 CPoint point;
2334 CString temp;
2335 point = CPoint(rect->left, rect->bottom);
2336 #define LOGMENUFLAGS(x) (MF_STRING | MF_ENABLED | (m_nSelectedFilter == x ? MF_CHECKED : MF_UNCHECKED))
2337 CMenu popup;
2338 if (popup.CreatePopupMenu())
2340 temp.LoadString(IDS_LOG_FILTER_ALL);
2341 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_ALL), LOGFILTER_ALL, temp);
2343 popup.AppendMenu(MF_SEPARATOR, NULL);
2345 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2346 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_MESSAGES), LOGFILTER_MESSAGES, temp);
2347 temp.LoadString(IDS_LOG_FILTER_PATHS);
2348 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_PATHS), LOGFILTER_PATHS, temp);
2349 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2350 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_AUTHORS), LOGFILTER_AUTHORS, temp);
2351 temp.LoadString(IDS_LOG_FILTER_REVS);
2352 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REVS), LOGFILTER_REVS, temp);
2353 temp.LoadString(IDS_LOG_FILTER_BUGIDS);
2354 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_BUGID), LOGFILTER_BUGID, temp);
2356 popup.AppendMenu(MF_SEPARATOR, NULL);
2358 temp.LoadString(IDS_LOG_FILTER_REGEX);
2359 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterWithRegex ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_REGEX, temp);
2361 m_tooltips.Pop();
2362 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2363 if (selection != 0)
2366 if (selection == LOGFILTER_REGEX)
2368 m_bFilterWithRegex = !m_bFilterWithRegex;
2369 CRegDWORD b = CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
2370 b = m_bFilterWithRegex;
2371 CheckRegexpTooltip();
2373 else
2375 m_nSelectedFilter = selection;
2376 SetFilterCueText();
2378 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2381 return 0L;
2384 LRESULT CLogDlg::OnClickedCancelFilter(WPARAM /*wParam*/, LPARAM /*lParam*/)
2386 #if 0
2387 KillTimer(LOGFILTER_TIMER);
2389 m_sFilterText.Empty();
2390 UpdateData(FALSE);
2391 theApp.DoWaitCursor(1);
2392 CStoreSelection storeselection(this);
2393 FillLogMessageCtrl(false);
2394 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2395 m_arShownList.RemoveAll();
2397 // reset the time filter too
2398 m_timFrom = (__time64_t(m_tFrom));
2399 m_timTo = (__time64_t(m_tTo));
2400 m_DateFrom.SetTime(&m_timFrom);
2401 m_DateTo.SetTime(&m_timTo);
2402 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
2403 m_DateTo.SetRange(&m_timFrom, &m_timTo);
2405 for (DWORD i=0; i<m_logEntries.size(); ++i)
2407 m_arShownList.Add(m_logEntries[i]);
2409 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2410 m_LogList.DeleteAllItems();
2411 m_LogList.SetItemCountEx(ShownCountWithStopped());
2412 m_LogList.RedrawItems(0, ShownCountWithStopped());
2413 m_LogList.SetRedraw(false);
2414 ResizeAllListCtrlCols();
2415 m_LogList.SetRedraw(true);
2416 theApp.DoWaitCursor(-1);
2417 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2418 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2419 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2420 UpdateLogInfoLabel();
2421 #endif
2422 return 0L;
2426 void CLogDlg::SetFilterCueText()
2428 CString temp;
2429 switch (m_nSelectedFilter)
2431 case LOGFILTER_ALL:
2432 temp.LoadString(IDS_LOG_FILTER_ALL);
2433 break;
2434 case LOGFILTER_MESSAGES:
2435 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2436 break;
2437 case LOGFILTER_PATHS:
2438 temp.LoadString(IDS_LOG_FILTER_PATHS);
2439 break;
2440 case LOGFILTER_AUTHORS:
2441 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2442 break;
2443 case LOGFILTER_REVS:
2444 temp.LoadString(IDS_LOG_FILTER_REVS);
2445 break;
2447 // to make the cue banner text appear more to the right of the edit control
2448 temp = _T(" ")+temp;
2449 m_cFilter.SetCueBanner(temp);
2451 #if 0
2452 void CLogDlg::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2454 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
2456 // Create a pointer to the item
2457 LV_ITEM* pItem = &(pDispInfo)->item;
2459 // Do the list need text information?
2460 if (!(pItem->mask & LVIF_TEXT))
2461 return;
2463 // By default, clear text buffer.
2464 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
2466 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
2468 *pResult = 0;
2469 if (m_bNoDispUpdates || m_bThreadRunning || bOutOfRange)
2470 return;
2472 // Which item number?
2473 int itemid = pItem->iItem;
2474 GitRev * pLogEntry = NULL;
2475 if (itemid < m_arShownList.GetCount())
2476 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(pItem->iItem));
2478 // Which column?
2479 switch (pItem->iSubItem)
2481 case this->LOGLIST_GRAPH: //Graphic
2482 if (pLogEntry)
2485 break;
2486 case this->LOGLIST_ACTION: //action -- no text in the column
2487 break;
2488 case this->LOGLIST_MESSAGE: //Message
2489 if (pLogEntry)
2490 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_Subject, pItem->cchTextMax);
2491 break;
2492 case this->LOGLIST_AUTHOR: //Author
2493 if (pLogEntry)
2494 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_AuthorName, pItem->cchTextMax);
2495 break;
2496 case this->LOGLIST_DATE: //Date
2497 if (pLogEntry)
2498 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_AuthorDate.Format(_T("%Y-%m-%d %H:%M")), pItem->cchTextMax);
2499 break;
2501 case 5:
2503 break;
2504 default:
2505 ASSERT(false);
2508 #endif
2509 void CLogDlg::OnLvnGetdispinfoChangedFileList(NMHDR *pNMHDR, LRESULT *pResult)
2512 #if 0
2513 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
2515 //Create a pointer to the item
2516 LV_ITEM* pItem= &(pDispInfo)->item;
2518 *pResult = 0;
2519 if ((m_bNoDispUpdates)||(m_bThreadRunning))
2521 if (pItem->mask & LVIF_TEXT)
2522 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
2523 return;
2525 if ((m_currentChangedArray!=NULL)&&(pItem->iItem >= m_currentChangedArray->GetCount()))
2527 if (pItem->mask & LVIF_TEXT)
2528 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
2529 return;
2531 if ((m_currentChangedArray==NULL)&&(pItem->iItem >= m_currentChangedPathList.GetCount()))
2533 if (pItem->mask & LVIF_TEXT)
2534 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
2535 return;
2537 CTGitPath lcpath = NULL;
2538 if (m_currentChangedArray)
2539 lcpath = (*m_currentChangedArray)[pItem->iItem];
2540 //Does the list need text information?
2541 if (pItem->mask & LVIF_TEXT)
2543 //Which column?
2544 switch (pItem->iSubItem)
2546 case this->FILELIST_ACTION: //Action
2547 #if 0
2548 if (lcpath)
2549 lstrcpyn(pItem->pszText, (LPCTSTR)lcpath->GetAction(), pItem->cchTextMax);
2550 else
2551 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
2552 #endif
2553 lstrcpyn(pItem->pszText, (LPCTSTR)lcpath.GetActionName(), pItem->cchTextMax);
2555 break;
2557 case this->FILELIST_ADD: //add
2558 #if 0
2559 if (lcpath)
2560 lstrcpyn(pItem->pszText, (LPCTSTR)lcpath->sPath, pItem->cchTextMax);
2561 else
2562 lstrcpyn(pItem->pszText, (LPCTSTR)m_currentChangedPathList[pItem->iItem].GetGitPathString(), pItem->cchTextMax);
2563 #endif
2564 lstrcpyn(pItem->pszText, (LPCTSTR)lcpath.m_StatAdd, pItem->cchTextMax);
2565 break;
2567 case this->FILELIST_DEL: //del
2568 #if 0
2569 if (lcpath)
2570 lstrcpyn(pItem->pszText, (LPCTSTR)lcpath->sCopyFromPath, pItem->cchTextMax);
2571 else
2572 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
2573 #endif
2574 lstrcpyn(pItem->pszText, (LPCTSTR)lcpath.m_StatDel, pItem->cchTextMax);
2575 break;
2576 case this->FILELIST_PATH: //path
2577 #if 0
2578 if ((lcpath==NULL)||(lcpath->sCopyFromPath.IsEmpty()))
2579 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
2580 else
2581 _stprintf_s(pItem->pszText, pItem->cchTextMax, _T("%ld"), lcpath->lCopyFromRev);
2582 #endif
2583 lstrcpyn(pItem->pszText, (LPCTSTR)lcpath.GetGitPathString(), pItem->cchTextMax);
2584 break;
2587 #endif
2588 *pResult = 0;
2591 void CLogDlg::OnEnChangeSearchedit()
2593 #if 0
2594 UpdateData();
2595 if (m_sFilterText.IsEmpty())
2597 CStoreSelection storeselection(this);
2598 // clear the filter, i.e. make all entries appear
2599 theApp.DoWaitCursor(1);
2600 KillTimer(LOGFILTER_TIMER);
2601 FillLogMessageCtrl(false);
2602 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2603 m_arShownList.RemoveAll();
2604 for (DWORD i=0; i<m_logEntries.size(); ++i)
2606 if (IsEntryInDateRange(i))
2607 m_arShownList.Add(m_logEntries[i]);
2609 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2610 m_LogList.DeleteAllItems();
2611 m_LogList.SetItemCountEx(ShownCountWithStopped());
2612 m_LogList.RedrawItems(0, ShownCountWithStopped());
2613 m_LogList.SetRedraw(false);
2614 ResizeAllListCtrlCols();
2615 m_LogList.SetRedraw(true);
2616 theApp.DoWaitCursor(-1);
2617 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2618 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2619 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2620 DialogEnableWindow(IDC_STATBUTTON, !(((m_bThreadRunning)||(m_arShownList.IsEmpty()))));
2621 return;
2623 if (Validate(m_sFilterText))
2624 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2625 else
2626 KillTimer(LOGFILTER_TIMER);
2627 #endif
2630 bool CLogDlg::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
2634 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
2635 if (!bMatchCase)
2636 type |= tr1::regex_constants::icase;
2637 pat = tr1::wregex(regexp_str, type);
2638 return true;
2640 catch (exception) {}
2641 return false;
2644 bool CLogDlg::Validate(LPCTSTR string)
2646 if (!m_bFilterWithRegex)
2647 return true;
2648 tr1::wregex pat;
2649 return ValidateRegexp(string, pat, false);
2652 void CLogDlg::RecalculateShownList(CPtrArray * pShownlist)
2654 #if 0
2655 pShownlist->RemoveAll();
2656 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2657 bool bRegex = false;
2658 if (m_bFilterWithRegex)
2659 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2661 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2662 CString sRev;
2663 for (DWORD i=0; i<m_logEntries.size(); ++i)
2665 if ((bRegex)&&(m_bFilterWithRegex))
2667 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2669 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
2670 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
2672 pShownlist->Add(m_logEntries[i]);
2673 continue;
2676 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2678 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sMessage);
2679 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sMessage), pat, flags)&&IsEntryInDateRange(i))
2681 pShownlist->Add(m_logEntries[i]);
2682 continue;
2685 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
2687 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;
2689 bool bGoing = true;
2690 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)
2692 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
2693 if (regex_search(wstring((LPCTSTR)cpath->sCopyFromPath), pat, flags)&&IsEntryInDateRange(i))
2695 pShownlist->Add(m_logEntries[i]);
2696 bGoing = false;
2697 continue;
2699 if (regex_search(wstring((LPCTSTR)cpath->sPath), pat, flags)&&IsEntryInDateRange(i))
2701 pShownlist->Add(m_logEntries[i]);
2702 bGoing = false;
2703 continue;
2705 if (regex_search(wstring((LPCTSTR)cpath->GetAction()), pat, flags)&&IsEntryInDateRange(i))
2707 pShownlist->Add(m_logEntries[i]);
2708 bGoing = false;
2709 continue;
2712 if (!bGoing)
2713 continue;
2715 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
2717 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sAuthor), pat, flags)&&IsEntryInDateRange(i))
2719 pShownlist->Add(m_logEntries[i]);
2720 continue;
2723 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
2725 sRev.Format(_T("%ld"), m_logEntries[i]->Rev);
2726 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
2728 pShownlist->Add(m_logEntries[i]);
2729 continue;
2732 } // if (bRegex)
2733 else
2735 CString find = m_sFilterText;
2736 find.MakeLower();
2737 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2739 CString sBugIDs = m_logEntries[i]->sBugIDs;
2741 sBugIDs = sBugIDs.MakeLower();
2742 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2744 pShownlist->Add(m_logEntries[i]);
2745 continue;
2748 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2750 CString msg = m_logEntries[i]->sMessage;
2752 msg = msg.MakeLower();
2753 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2755 pShownlist->Add(m_logEntries[i]);
2756 continue;
2759 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
2761 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;
2763 bool bGoing = true;
2764 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)
2766 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
2767 CString path = cpath->sCopyFromPath;
2768 path.MakeLower();
2769 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2771 pShownlist->Add(m_logEntries[i]);
2772 bGoing = false;
2773 continue;
2775 path = cpath->sPath;
2776 path.MakeLower();
2777 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2779 pShownlist->Add(m_logEntries[i]);
2780 bGoing = false;
2781 continue;
2783 path = cpath->GetAction();
2784 path.MakeLower();
2785 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2787 pShownlist->Add(m_logEntries[i]);
2788 bGoing = false;
2789 continue;
2793 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
2795 CString msg = m_logEntries[i]->sAuthor;
2796 msg = msg.MakeLower();
2797 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2799 pShownlist->Add(m_logEntries[i]);
2800 continue;
2803 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
2805 sRev.Format(_T("%ld"), m_logEntries[i]->Rev);
2806 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2808 pShownlist->Add(m_logEntries[i]);
2809 continue;
2812 } // else (from if (bRegex))
2813 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2814 #endif
2817 void CLogDlg::OnTimer(UINT_PTR nIDEvent)
2819 if (nIDEvent == LOGFILTER_TIMER)
2821 if (this->IsThreadRunning())
2823 // thread still running! So just restart the timer.
2824 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2825 return;
2827 CWnd * focusWnd = GetFocus();
2828 bool bSetFocusToFilterControl = ((focusWnd != GetDlgItem(IDC_DATEFROM))&&(focusWnd != GetDlgItem(IDC_DATETO))
2829 && (focusWnd != GetDlgItem(IDC_LOGLIST)));
2830 if (m_sFilterText.IsEmpty())
2832 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2833 // do not return here!
2834 // we also need to run the filter if the filter text is empty:
2835 // 1. to clear an existing filter
2836 // 2. to rebuild the m_arShownList after sorting
2838 theApp.DoWaitCursor(1);
2839 CStoreSelection storeselection(this);
2840 KillTimer(LOGFILTER_TIMER);
2841 FillLogMessageCtrl(false);
2843 // now start filter the log list
2844 // InterlockedExchange(&m_bNoDispUpdates, TRUE);
2845 RecalculateShownList(&m_LogList.m_arShownList);
2846 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
2849 m_LogList.DeleteAllItems();
2850 m_LogList.SetItemCountEx(m_LogList.ShownCountWithStopped());
2851 m_LogList.RedrawItems(0, m_LogList.ShownCountWithStopped());
2852 m_LogList.SetRedraw(false);
2853 m_LogList.ResizeAllListCtrlCols();
2854 m_LogList.SetRedraw(true);
2855 m_LogList.Invalidate();
2856 if ( m_LogList.GetItemCount()==1 )
2858 m_LogList.SetSelectionMark(0);
2859 m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
2861 theApp.DoWaitCursor(-1);
2862 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2863 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2864 if (bSetFocusToFilterControl)
2865 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2866 UpdateLogInfoLabel();
2867 } // if (nIDEvent == LOGFILTER_TIMER)
2868 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2869 __super::OnTimer(nIDEvent);
2872 void CLogDlg::OnDtnDatetimechangeDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2874 CTime _time;
2875 m_DateTo.GetTime(_time);
2878 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 23, 59, 59);
2879 if (time.GetTime() != m_tTo)
2881 m_tTo = (DWORD)time.GetTime();
2882 SetTimer(LOGFILTER_TIMER, 10, NULL);
2885 catch (CAtlException)
2889 *pResult = 0;
2892 void CLogDlg::OnDtnDatetimechangeDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2894 CTime _time;
2895 m_DateFrom.GetTime(_time);
2898 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 0, 0, 0);
2899 if (time.GetTime() != m_tFrom)
2901 m_tFrom = (DWORD)time.GetTime();
2902 SetTimer(LOGFILTER_TIMER, 10, NULL);
2905 catch (CAtlException)
2909 *pResult = 0;
2912 BOOL CLogDlg::IsEntryInDateRange(int i)
2914 #if 0
2915 __time64_t time = m_logEntries[i]->tmDate;
2916 if ((time >= m_tFrom)&&(time <= m_tTo))
2917 return TRUE;
2918 #endif
2919 return FALSE;
2923 CTGitPathList CLogDlg::GetChangedPathsFromSelectedRevisions(bool bRelativePaths /* = false */, bool bUseFilter /* = true */)
2925 CTGitPathList pathList;
2926 #if 0
2928 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2930 m_sRepositoryRoot = GetRepositoryRoot(m_path);
2932 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2933 return pathList;
2935 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2936 if (pos != NULL)
2938 while (pos)
2940 int nextpos = m_LogList.GetNextSelectedItem(pos);
2941 if (nextpos >= m_arShownList.GetCount())
2942 continue;
2943 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(nextpos));
2944 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2945 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
2947 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
2948 if (cpath == NULL)
2949 continue;
2950 CTGitPath path;
2951 if (!bRelativePaths)
2952 path.SetFromGit(m_sRepositoryRoot);
2953 path.AppendPathString(cpath->sPath);
2954 if ((!bUseFilter)||
2955 ((m_cHidePaths.GetState() & 0x0003)!=BST_CHECKED)||
2956 (cpath->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0))
2957 pathList.AddPath(path);
2962 pathList.RemoveDuplicates();
2963 #endif
2964 return pathList;
2967 void CLogDlg::SortByColumn(int nSortColumn, bool bAscending)
2969 #if 0
2970 switch(nSortColumn)
2972 case 0: // Revision
2974 if(bAscending)
2975 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscRevSort());
2976 else
2977 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescRevSort());
2979 break;
2980 case 1: // action
2982 if(bAscending)
2983 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscActionSort());
2984 else
2985 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescActionSort());
2987 break;
2988 case 2: // Author
2990 if(bAscending)
2991 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscAuthorSort());
2992 else
2993 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescAuthorSort());
2995 break;
2996 case 3: // Date
2998 if(bAscending)
2999 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscDateSort());
3000 else
3001 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescDateSort());
3003 break;
3004 case 4: // Message or bug id
3005 if (m_bShowBugtraqColumn)
3007 if(bAscending)
3008 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscBugIDSort());
3009 else
3010 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescBugIDSort());
3011 break;
3013 // fall through here
3014 case 5: // Message
3016 if(bAscending)
3017 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscMessageSort());
3018 else
3019 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescMessageSort());
3021 break;
3022 default:
3023 ATLASSERT(0);
3024 break;
3026 #endif
3029 void CLogDlg::OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult)
3031 if (this->IsThreadRunning())
3032 return; //no sorting while the arrays are filled
3033 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
3034 const int nColumn = pNMLV->iSubItem;
3035 m_bAscending = nColumn == m_nSortColumn ? !m_bAscending : TRUE;
3036 m_nSortColumn = nColumn;
3037 SortByColumn(m_nSortColumn, m_bAscending);
3038 SetSortArrow(&m_LogList, m_nSortColumn, !!m_bAscending);
3039 SortShownListArray();
3040 m_LogList.Invalidate();
3041 UpdateLogInfoLabel();
3042 // the "next 100" button only makes sense if the log messages
3043 // are sorted by revision in descending order
3044 if ((m_nSortColumn)||(m_bAscending))
3046 DialogEnableWindow(IDC_NEXTHUNDRED, false);
3048 else
3050 DialogEnableWindow(IDC_NEXTHUNDRED, true);
3052 *pResult = 0;
3055 void CLogDlg::SortShownListArray()
3057 // make sure the shown list still matches the filter after sorting.
3058 OnTimer(LOGFILTER_TIMER);
3059 // clear the selection states
3060 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
3061 while (pos)
3063 m_LogList.SetItemState(m_LogList.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
3065 m_LogList.SetSelectionMark(-1);
3068 void CLogDlg::SetSortArrow(CListCtrl * control, int nColumn, bool bAscending)
3070 if (control == NULL)
3071 return;
3072 // set the sort arrow
3073 CHeaderCtrl * pHeader = control->GetHeaderCtrl();
3074 HDITEM HeaderItem = {0};
3075 HeaderItem.mask = HDI_FORMAT;
3076 for (int i=0; i<pHeader->GetItemCount(); ++i)
3078 pHeader->GetItem(i, &HeaderItem);
3079 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
3080 pHeader->SetItem(i, &HeaderItem);
3082 if (nColumn >= 0)
3084 pHeader->GetItem(nColumn, &HeaderItem);
3085 HeaderItem.fmt |= (bAscending ? HDF_SORTUP : HDF_SORTDOWN);
3086 pHeader->SetItem(nColumn, &HeaderItem);
3089 void CLogDlg::OnLvnColumnclickChangedFileList(NMHDR *pNMHDR, LRESULT *pResult)
3091 if (this->IsThreadRunning())
3092 return; //no sorting while the arrays are filled
3093 if (m_currentChangedArray == NULL)
3094 return;
3095 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
3096 const int nColumn = pNMLV->iSubItem;
3097 m_bAscendingPathList = nColumn == m_nSortColumnPathList ? !m_bAscendingPathList : TRUE;
3098 m_nSortColumnPathList = nColumn;
3099 // qsort(m_currentChangedArray->GetData(), m_currentChangedArray->GetSize(), sizeof(LogChangedPath*), (GENERICCOMPAREFN)SortCompare);
3101 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
3102 m_ChangedFileListCtrl.Invalidate();
3103 *pResult = 0;
3106 int CLogDlg::m_nSortColumnPathList = 0;
3107 bool CLogDlg::m_bAscendingPathList = false;
3109 int CLogDlg::SortCompare(const void * pElem1, const void * pElem2)
3111 #if 0
3112 LogChangedPath * cpath1 = *((LogChangedPath**)pElem1);
3113 LogChangedPath * cpath2 = *((LogChangedPath**)pElem2);
3115 if (m_bAscendingPathList)
3116 std::swap (cpath1, cpath2);
3118 int cmp = 0;
3119 switch (m_nSortColumnPathList)
3121 case 0: // action
3122 cmp = cpath2->GetAction().Compare(cpath1->GetAction());
3123 if (cmp)
3124 return cmp;
3125 // fall through
3126 case 1: // path
3127 cmp = cpath2->sPath.CompareNoCase(cpath1->sPath);
3128 if (cmp)
3129 return cmp;
3130 // fall through
3131 case 2: // copy from path
3132 cmp = cpath2->sCopyFromPath.Compare(cpath1->sCopyFromPath);
3133 if (cmp)
3134 return cmp;
3135 // fall through
3136 case 3: // copy from revision
3137 return cpath2->lCopyFromRev > cpath1->lCopyFromRev;
3139 #endif
3140 return 0;
3143 #if 0
3144 void CLogDlg::ResizeAllListCtrlCols()
3147 const int nMinimumWidth = ICONITEMBORDER+16*4;
3148 int maxcol = ((CHeaderCtrl*)(m_LogList.GetDlgItem(0)))->GetItemCount()-1;
3149 int nItemCount = m_LogList.GetItemCount();
3150 TCHAR textbuf[MAX_PATH];
3151 CHeaderCtrl * pHdrCtrl = (CHeaderCtrl*)(m_LogList.GetDlgItem(0));
3152 if (pHdrCtrl)
3154 for (int col = 0; col <= maxcol; col++)
3156 HDITEM hdi = {0};
3157 hdi.mask = HDI_TEXT;
3158 hdi.pszText = textbuf;
3159 hdi.cchTextMax = sizeof(textbuf);
3160 pHdrCtrl->GetItem(col, &hdi);
3161 int cx = m_LogList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
3162 for (int index = 0; index<nItemCount; ++index)
3164 // get the width of the string and add 14 pixels for the column separator and margins
3165 int linewidth = m_LogList.GetStringWidth(m_LogList.GetItemText(index, col)) + 14;
3166 if (index < m_arShownList.GetCount())
3168 GitRev * pCurLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(index));
3169 if ((pCurLogEntry)&&(pCurLogEntry->m_CommitHash == m_wcRev.m_CommitHash))
3171 // set the bold font and ask for the string width again
3172 m_LogList.SendMessage(WM_SETFONT, (WPARAM)m_boldFont, NULL);
3173 linewidth = m_LogList.GetStringWidth(m_LogList.GetItemText(index, col)) + 14;
3174 // restore the system font
3175 m_LogList.SendMessage(WM_SETFONT, NULL, NULL);
3178 if (index == 0)
3180 // add the image size
3181 CImageList * pImgList = m_LogList.GetImageList(LVSIL_SMALL);
3182 if ((pImgList)&&(pImgList->GetImageCount()))
3184 IMAGEINFO imginfo;
3185 pImgList->GetImageInfo(0, &imginfo);
3186 linewidth += (imginfo.rcImage.right - imginfo.rcImage.left);
3187 linewidth += 3; // 3 pixels between icon and text
3190 if (cx < linewidth)
3191 cx = linewidth;
3193 // Adjust columns "Actions" containing icons
3194 if (col == this->LOGLIST_ACTION)
3196 if (cx < nMinimumWidth)
3198 cx = nMinimumWidth;
3202 if (col == this->LOGLIST_MESSAGE)
3204 if (cx > LOGLIST_MESSAGE_MAX)
3206 cx = LOGLIST_MESSAGE_MAX;
3210 // keep the bug id column small
3211 if ((col == 4)&&(m_bShowBugtraqColumn))
3213 if (cx > (int)(DWORD)m_regMaxBugIDColWidth)
3215 cx = (int)(DWORD)m_regMaxBugIDColWidth;
3219 m_LogList.SetColumnWidth(col, cx);
3224 #endif
3226 void CLogDlg::OnBnClickedHidepaths()
3228 FillLogMessageCtrl();
3229 m_ChangedFileListCtrl.Invalidate();
3234 void CLogDlg::OnBnClickedCheckStoponcopy()
3236 #if 0
3237 if (!GetDlgItem(IDC_GETALL)->IsWindowEnabled())
3238 return;
3240 // ignore old fetch limits when switching
3241 // between copy-following and stop-on-copy
3242 // (otherwise stop-on-copy will limit what
3243 // we see immediately after switching to
3244 // copy-following)
3246 m_endrev = 0;
3248 // now, restart the query
3249 #endif
3250 Refresh();
3253 void CLogDlg::OnBnClickedIncludemerge()
3255 #if 0
3256 m_endrev = 0;
3258 m_limit = 0;
3259 #endif
3260 Refresh();
3263 void CLogDlg::UpdateLogInfoLabel()
3265 #if 0
3266 git_revnum_t rev1 = 0;
3267 git_revnum_t rev2 = 0;
3268 long selectedrevs = 0;
3269 if (m_arShownList.GetCount())
3271 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(0));
3272 rev1 = pLogEntry->Rev;
3273 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_arShownList.GetCount()-1));
3274 rev2 = pLogEntry->Rev;
3275 selectedrevs = m_LogList.GetSelectedCount();
3277 CString sTemp;
3278 sTemp.Format(IDS_LOG_LOGINFOSTRING, m_arShownList.GetCount(), rev2, rev1, selectedrevs);
3279 m_sLogInfo = sTemp;
3280 #endif
3281 UpdateData(FALSE);
3284 void CLogDlg::ShowContextMenuForChangedpaths(CWnd* /*pWnd*/, CPoint point)
3287 int selIndex = m_ChangedFileListCtrl.GetSelectionMark();
3288 if ((point.x == -1) && (point.y == -1))
3290 CRect rect;
3291 m_ChangedFileListCtrl.GetItemRect(selIndex, &rect, LVIR_LABEL);
3292 m_ChangedFileListCtrl.ClientToScreen(&rect);
3293 point = rect.CenterPoint();
3295 if (selIndex < 0)
3296 return;
3297 int s = m_LogList.GetSelectionMark();
3298 if (s < 0)
3299 return;
3300 std::vector<CString> changedpaths;
3301 std::vector<LogChangedPath*> changedlogpaths;
3302 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
3303 if (pos == NULL)
3304 return; // nothing is selected, get out of here
3306 bool bOneRev = true;
3307 int sel=m_LogList.GetNextSelectedItem(pos);
3308 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.GetAt(sel));
3309 GitRev * rev1 = pLogEntry;
3310 GitRev * rev2 = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.GetAt(sel+1));
3311 #if 0
3312 bool bOneRev = true;
3313 if (pos)
3315 while (pos)
3317 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
3318 if (pLogEntry)
3320 rev1 = max(rev1,(git_revnum_t)pLogEntry->Rev);
3321 rev2 = min(rev2,(git_revnum_t)pLogEntry->Rev);
3322 bOneRev = false;
3325 if (!bOneRev)
3326 rev2--;
3327 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
3328 while (pos)
3330 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
3331 changedpaths.push_back(m_currentChangedPathList[nItem].GetGitPathString());
3334 else
3336 // only one revision is selected in the log dialog top pane
3337 // but multiple items could be selected in the changed items list
3338 rev2 = rev1-1;
3340 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
3341 while (pos)
3343 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
3344 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->GetAt(nItem);
3346 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
3348 if ((changedlogpath)&&(!changedlogpath->sCopyFromPath.IsEmpty()))
3349 rev2 = changedlogpath->lCopyFromRev;
3350 else
3352 // if the path was modified but the parent path was 'added with history'
3353 // then we have to use the copy from revision of the parent path
3354 CTGitPath cpath = CTGitPath(changedlogpath->sPath);
3355 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
3357 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->GetAt(flist)->sPath);
3358 if (p.IsAncestorOf(cpath))
3360 if (!pLogEntry->pArChangedPaths->GetAt(flist)->sCopyFromPath.IsEmpty())
3361 rev2 = pLogEntry->pArChangedPaths->GetAt(flist)->lCopyFromRev;
3366 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
3368 // some items are hidden! So find out which item the user really clicked on
3369 INT_PTR selRealIndex = -1;
3370 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
3372 if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
3373 selRealIndex++;
3374 if (selRealIndex == nItem)
3376 selIndex = hiddenindex;
3377 changedlogpath = pLogEntry->pArChangedPaths->GetAt(selIndex);
3378 break;
3382 if (changedlogpath)
3384 changedpaths.push_back(changedlogpath->sPath);
3385 changedlogpaths.push_back(changedlogpath);
3389 #endif
3390 //entry is selected, now show the popup menu
3391 CIconMenu popup;
3392 if (popup.CreatePopupMenu())
3394 bool bEntryAdded = false;
3395 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
3397 // if ((!bOneRev)||(IsDiffPossible(changedlogpaths[0], rev1)))
3399 popup.AppendMenuIcon(CGitLogList::ID_DIFF, IDS_LOG_POPUP_DIFF, IDI_DIFF);
3400 popup.AppendMenuIcon(CGitLogList::ID_BLAMEDIFF, IDS_LOG_POPUP_BLAMEDIFF, IDI_BLAME);
3401 popup.SetDefaultItem(CGitLogList::ID_DIFF, FALSE);
3402 popup.AppendMenuIcon(CGitLogList::ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
3403 bEntryAdded = true;
3405 // if (rev2 == rev1-1)
3407 if (bEntryAdded)
3408 popup.AppendMenu(MF_SEPARATOR, NULL);
3409 popup.AppendMenuIcon(CGitLogList::ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
3410 popup.AppendMenuIcon(CGitLogList::ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
3411 popup.AppendMenuIcon(CGitLogList::ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
3412 popup.AppendMenu(MF_SEPARATOR, NULL);
3413 if (m_hasWC)
3414 popup.AppendMenuIcon(CGitLogList::ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
3415 popup.AppendMenuIcon(CGitLogList::ID_POPPROPS, IDS_REPOBROWSE_SHOWPROP, IDI_PROPERTIES); // "Show Properties"
3416 popup.AppendMenuIcon(CGitLogList::ID_LOG, IDS_MENULOG, IDI_LOG); // "Show Log"
3417 popup.AppendMenuIcon(CGitLogList::ID_GETMERGELOGS, IDS_LOG_POPUP_GETMERGELOGS, IDI_LOG); // "Show merge log"
3418 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
3419 bEntryAdded = true;
3420 if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
3422 popup.AppendMenu(MF_SEPARATOR, NULL);
3423 popup.AppendMenuIcon(CGitLogList::ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
3425 if (popup.GetDefaultItem(0,FALSE)==-1)
3426 popup.SetDefaultItem(CGitLogList::ID_OPEN, FALSE);
3429 else if (changedlogpaths.size())
3431 // more than one entry is selected
3432 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE);
3433 bEntryAdded = true;
3436 if (!bEntryAdded)
3437 return;
3438 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
3439 bool bOpenWith = false;
3440 bool bMergeLog = false;
3441 m_bCancelled = false;
3443 switch (cmd)
3445 case CGitLogList::ID_DIFF:
3447 DoDiffFromLog(selIndex, rev1, rev2, false, false);
3449 break;
3450 #if 0
3451 case ID_BLAMEDIFF:
3453 DoDiffFromLog(selIndex, rev1, rev2, true, false);
3455 break;
3456 case ID_GNUDIFF1:
3458 DoDiffFromLog(selIndex, rev1, rev2, false, true);
3460 break;
3461 case ID_REVERTREV:
3463 SetPromptApp(&theApp);
3464 theApp.DoWaitCursor(1);
3465 CString sUrl;
3466 if (Git::PathIsURL(m_path))
3468 sUrl = m_path.GetGitPathString();
3470 else
3472 sUrl = GetURLFromPath(m_path);
3473 if (sUrl.IsEmpty())
3475 theApp.DoWaitCursor(-1);
3476 CString temp;
3477 temp.Format(IDS_ERR_NOURLOFFILE, m_path.GetWinPath());
3478 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3479 EnableOKButton();
3480 theApp.DoWaitCursor(-1);
3481 break; //exit
3484 // find the working copy path of the selected item from the URL
3485 m_bCancelled = false;
3486 CString sUrlRoot = GetRepositoryRoot(CTGitPath(sUrl));
3488 CString fileURL = changedpaths[0];
3489 fileURL = sUrlRoot + fileURL.Trim();
3490 // firstfile = (e.g.) http://mydomain.com/repos/trunk/folder/file1
3491 // sUrl = http://mydomain.com/repos/trunk/folder
3492 CString sUnescapedUrl = CPathUtils::PathUnescape(sUrl);
3493 // find out until which char the urls are identical
3494 int i=0;
3495 while ((i<fileURL.GetLength())&&(i<sUnescapedUrl.GetLength())&&(fileURL[i]==sUnescapedUrl[i]))
3496 i++;
3497 int leftcount = m_path.GetWinPathString().GetLength()-(sUnescapedUrl.GetLength()-i);
3498 CString wcPath = m_path.GetWinPathString().Left(leftcount);
3499 wcPath += fileURL.Mid(i);
3500 wcPath.Replace('/', '\\');
3501 CGitProgressDlg dlg;
3502 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
3504 // a deleted path! Since the path isn't there anymore, merge
3505 // won't work. So just do a copy url->wc
3506 dlg.SetCommand(CGitProgressDlg::GitProgress_Copy);
3507 dlg.SetPathList(CTGitPathList(CTGitPath(fileURL)));
3508 dlg.SetUrl(wcPath);
3509 dlg.SetRevision(rev2);
3511 else
3513 if (!PathFileExists(wcPath))
3515 // seems the path got renamed
3516 // tell the user how to work around this.
3517 CMessageBox::Show(this->m_hWnd, IDS_LOG_REVERTREV_ERROR, IDS_APPNAME, MB_ICONERROR);
3518 EnableOKButton();
3519 theApp.DoWaitCursor(-1);
3520 break; //exit
3522 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
3523 dlg.SetPathList(CTGitPathList(CTGitPath(wcPath)));
3524 dlg.SetUrl(fileURL);
3525 dlg.SetSecondUrl(fileURL);
3526 GitRevRangeArray revarray;
3527 revarray.AddRevRange(rev1, rev2);
3528 dlg.SetRevisionRanges(revarray);
3530 CString msg;
3531 msg.Format(IDS_LOG_REVERT_CONFIRM, (LPCTSTR)wcPath);
3532 if (CMessageBox::Show(this->m_hWnd, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
3534 dlg.DoModal();
3536 theApp.DoWaitCursor(-1);
3538 break;
3539 case ID_POPPROPS:
3541 DialogEnableWindow(IDOK, FALSE);
3542 SetPromptApp(&theApp);
3543 theApp.DoWaitCursor(1);
3544 CString filepath;
3545 if (Git::PathIsURL(m_path))
3547 filepath = m_path.GetGitPathString();
3549 else
3551 filepath = GetURLFromPath(m_path);
3552 if (filepath.IsEmpty())
3554 theApp.DoWaitCursor(-1);
3555 CString temp;
3556 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
3557 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3558 TRACE(_T("could not retrieve the URL of the file!\n"));
3559 EnableOKButton();
3560 break;
3563 filepath = GetRepositoryRoot(CTGitPath(filepath));
3564 filepath += changedpaths[0];
3565 CPropDlg dlg;
3566 dlg.m_rev = rev1;
3567 dlg.m_Path = CTGitPath(filepath);
3568 dlg.DoModal();
3569 EnableOKButton();
3570 theApp.DoWaitCursor(-1);
3572 break;
3573 case ID_SAVEAS:
3575 DialogEnableWindow(IDOK, FALSE);
3576 SetPromptApp(&theApp);
3577 theApp.DoWaitCursor(1);
3578 CString filepath;
3579 if (Git::PathIsURL(m_path))
3581 filepath = m_path.GetGitPathString();
3583 else
3585 filepath = GetURLFromPath(m_path);
3586 if (filepath.IsEmpty())
3588 theApp.DoWaitCursor(-1);
3589 CString temp;
3590 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
3591 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3592 TRACE(_T("could not retrieve the URL of the file!\n"));
3593 EnableOKButton();
3594 break;
3597 m_bCancelled = false;
3598 CString sRoot = GetRepositoryRoot(CTGitPath(filepath));
3599 // if more than one entry is selected, we save them
3600 // one by one into a folder the user has selected
3601 bool bTargetSelected = false;
3602 CTGitPath TargetPath;
3603 if (m_ChangedFileListCtrl.GetSelectedCount() > 1)
3605 CBrowseFolder browseFolder;
3606 browseFolder.SetInfo(CString(MAKEINTRESOURCE(IDS_LOG_SAVEFOLDERTOHINT)));
3607 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
3608 CString strSaveAsDirectory;
3609 if (browseFolder.Show(GetSafeHwnd(), strSaveAsDirectory) == CBrowseFolder::OK)
3611 TargetPath = CTGitPath(strSaveAsDirectory);
3612 bTargetSelected = true;
3615 else
3617 // Display the Open dialog box.
3618 CString revFilename;
3619 CString temp;
3620 temp = CPathUtils::GetFileNameFromPath(changedpaths[0]);
3621 int rfind = temp.ReverseFind('.');
3622 if (rfind > 0)
3623 revFilename.Format(_T("%s-%ld%s"), (LPCTSTR)temp.Left(rfind), rev1, (LPCTSTR)temp.Mid(rfind));
3624 else
3625 revFilename.Format(_T("%s-%ld"), (LPCTSTR)temp, rev1);
3626 bTargetSelected = CAppUtils::FileOpenSave(revFilename, NULL, IDS_LOG_POPUP_SAVE, IDS_COMMONFILEFILTER, false, m_hWnd);
3627 TargetPath.SetFromWin(revFilename);
3629 if (bTargetSelected)
3631 CProgressDlg progDlg;
3632 progDlg.SetTitle(IDS_APPNAME);
3633 progDlg.SetAnimation(IDR_DOWNLOAD);
3634 for (std::vector<LogChangedPath*>::iterator it = changedlogpaths.begin(); it!= changedlogpaths.end(); ++it)
3636 GitRev getrev = ((*it)->action == LOGACTIONS_DELETED) ? rev2 : rev1;
3638 CString sInfoLine;
3639 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)getrev.ToString());
3640 progDlg.SetLine(1, sInfoLine, true);
3641 SetAndClearProgressInfo(&progDlg);
3642 progDlg.ShowModeless(m_hWnd);
3644 CTGitPath tempfile = TargetPath;
3645 if (changedpaths.size() > 1)
3647 // if multiple items are selected, then the TargetPath
3648 // points to a folder and we have to append the filename
3649 // to save to to that folder.
3650 CString sName = (*it)->sPath;
3651 int slashpos = sName.ReverseFind('/');
3652 if (slashpos >= 0)
3653 sName = sName.Mid(slashpos);
3654 tempfile.AppendPathString(sName);
3655 // one problem here:
3656 // a user could have selected multiple items which
3657 // have the same filename but reside in different
3658 // directories, e.g.
3659 // /folder1/file1
3660 // /folder2/file1
3661 // in that case, the second 'file1' will overwrite
3662 // the already saved 'file1'.
3664 // we could maybe find the common root of all selected
3665 // items and then create sub folders to save those files
3666 // there.
3667 // But I think we should just leave it that way: to check
3668 // out multiple items at once, the better way is still to
3669 // use the export command from the top pane of the log dialog.
3671 filepath = sRoot + (*it)->sPath;
3672 if (!Cat(CTGitPath(filepath), getrev, getrev, tempfile))
3674 progDlg.Stop();
3675 SetAndClearProgressInfo((HWND)NULL);
3676 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3677 EnableOKButton();
3678 theApp.DoWaitCursor(-1);
3679 break;
3682 progDlg.Stop();
3683 SetAndClearProgressInfo((HWND)NULL);
3685 EnableOKButton();
3686 theApp.DoWaitCursor(-1);
3688 break;
3689 case ID_OPENWITH:
3690 bOpenWith = true;
3691 case ID_OPEN:
3693 GitRev getrev = pLogEntry->pArChangedPaths->GetAt(selIndex)->action == LOGACTIONS_DELETED ? rev2 : rev1;
3694 Open(bOpenWith,changedpaths[0],getrev);
3696 break;
3697 case ID_BLAME:
3699 CString filepath;
3700 if (Git::PathIsURL(m_path))
3702 filepath = m_path.GetGitPathString();
3704 else
3706 filepath = GetURLFromPath(m_path);
3707 if (filepath.IsEmpty())
3709 theApp.DoWaitCursor(-1);
3710 CString temp;
3711 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
3712 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3713 TRACE(_T("could not retrieve the URL of the file!\n"));
3714 EnableOKButton();
3715 break;
3718 filepath = GetRepositoryRoot(CTGitPath(filepath));
3719 filepath += changedpaths[0];
3720 CBlameDlg dlg;
3721 dlg.EndRev = rev1;
3722 if (dlg.DoModal() == IDOK)
3724 CBlame blame;
3725 CString tempfile;
3726 CString logfile;
3727 tempfile = blame.BlameToTempFile(CTGitPath(filepath), dlg.StartRev, dlg.EndRev, dlg.EndRev, logfile, _T(""), dlg.m_bIncludeMerge, TRUE, TRUE);
3728 if (!tempfile.IsEmpty())
3730 if (dlg.m_bTextView)
3732 //open the default text editor for the result file
3733 CAppUtils::StartTextViewer(tempfile);
3735 else
3737 CString sParams = _T("/path:\"") + filepath + _T("\" ");
3738 if(!CAppUtils::LaunchTortoiseBlame(tempfile, logfile, CPathUtils::GetFileNameFromPath(filepath),sParams))
3740 break;
3744 else
3746 CMessageBox::Show(this->m_hWnd, blame.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
3750 break;
3751 case ID_GETMERGELOGS:
3752 bMergeLog = true;
3753 // fall through
3754 case ID_LOG:
3756 DialogEnableWindow(IDOK, FALSE);
3757 SetPromptApp(&theApp);
3758 theApp.DoWaitCursor(1);
3759 CString filepath;
3760 if (Git::PathIsURL(m_path))
3762 filepath = m_path.GetGitPathString();
3764 else
3766 filepath = GetURLFromPath(m_path);
3767 if (filepath.IsEmpty())
3769 theApp.DoWaitCursor(-1);
3770 CString temp;
3771 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
3772 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
3773 TRACE(_T("could not retrieve the URL of the file!\n"));
3774 EnableOKButton();
3775 break;
3778 m_bCancelled = false;
3779 filepath = GetRepositoryRoot(CTGitPath(filepath));
3780 filepath += changedpaths[0];
3781 git_revnum_t logrev = rev1;
3782 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
3784 // if the item got deleted in this revision,
3785 // fetch the log from the previous revision where it
3786 // still existed.
3787 logrev--;
3789 CString sCmd;
3790 sCmd.Format(_T("\"%s\" /command:log /path:\"%s\" /startrev:%ld"), (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)filepath, logrev);
3791 if (bMergeLog)
3792 sCmd += _T(" /merge");
3793 CAppUtils::LaunchApplication(sCmd, NULL, false);
3794 EnableOKButton();
3795 theApp.DoWaitCursor(-1);
3797 break;
3798 case ID_VIEWPATHREV:
3800 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetSelectionMark()));
3801 GitRev rev = pLogEntry->Rev;
3802 CString relurl = changedpaths[0];
3803 CString url = m_ProjectProperties.sWebViewerPathRev;
3804 url.Replace(_T("%REVISION%"), rev.ToString());
3805 url.Replace(_T("%PATH%"), relurl);
3806 relurl = relurl.Mid(relurl.Find('/'));
3807 url.Replace(_T("%PATH1%"), relurl);
3808 if (!url.IsEmpty())
3809 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
3811 break;
3812 #endif
3813 default:
3814 break;
3815 } // switch (cmd)
3817 } // if (popup.CreatePopupMenu())
3820 void CLogDlg::OnDtnDropdownDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3822 // the date control should not show the "today" button
3823 CMonthCalCtrl * pCtrl = m_DateFrom.GetMonthCalCtrl();
3824 if (pCtrl)
3825 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3826 *pResult = 0;
3829 void CLogDlg::OnDtnDropdownDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3831 // the date control should not show the "today" button
3832 CMonthCalCtrl * pCtrl = m_DateTo.GetMonthCalCtrl();
3833 if (pCtrl)
3834 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3835 *pResult = 0;
3838 void CLogDlg::OnSize(UINT nType, int cx, int cy)
3840 __super::OnSize(nType, cx, cy);
3841 //set range
3842 SetSplitterRange();
3845 void CLogDlg::OnRefresh()
3847 if (GetDlgItem(IDC_GETALL)->IsWindowEnabled())
3849 m_limit = 0;
3850 Refresh (true);
3854 void CLogDlg::OnFind()
3856 if (!m_pFindDialog)
3858 m_pFindDialog = new CFindReplaceDialog();
3859 m_pFindDialog->Create(TRUE, NULL, NULL, FR_HIDEUPDOWN | FR_HIDEWHOLEWORD, this);
3863 void CLogDlg::OnFocusFilter()
3865 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3868 void CLogDlg::OnEditCopy()
3870 if (GetFocus() == &m_ChangedFileListCtrl)
3871 CopyChangedSelectionToClipBoard();
3872 else
3873 m_LogList.CopySelectionToClipBoard();
3876 CString CLogDlg::GetAbsoluteUrlFromRelativeUrl(const CString& url)
3878 // is the URL a relative one?
3879 if (url.Left(2).Compare(_T("^/")) == 0)
3881 // URL is relative to the repository root
3882 CString url1 = m_sRepositoryRoot + url.Mid(1);
3883 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3884 DWORD len = url.GetLength();
3885 if (UrlCanonicalize((LPCTSTR)url1, buf, &len, 0) == S_OK)
3886 return CString(buf, len);
3887 return url1;
3889 else if (url[0] == '/')
3891 // URL is relative to the server's hostname
3892 CString sHost;
3893 // find the server's hostname
3894 int schemepos = m_sRepositoryRoot.Find(_T("//"));
3895 if (schemepos >= 0)
3897 sHost = m_sRepositoryRoot.Left(m_sRepositoryRoot.Find('/', schemepos+3));
3898 CString url1 = sHost + url;
3899 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3900 DWORD len = url.GetLength();
3901 if (UrlCanonicalize((LPCTSTR)url, buf, &len, 0) == S_OK)
3902 return CString(buf, len);
3903 return url1;
3906 return url;
3910 int CLogDataVector::ParserFromLog()
3912 CString log;
3913 GitRev rev;
3914 g_Git.GetLog(log);
3916 CString begin;
3917 begin.Format(_T("#<%c>"),LOG_REV_ITEM_BEGIN);
3919 if(log.GetLength()==0)
3920 return 0;
3922 int start=4;
3923 int length;
3924 int next =1;
3925 while( next>0 )
3927 next=log.Find(begin,start);
3928 if(next >0 )
3929 length = next - start+4;
3930 else
3931 length = log.GetLength()-start+4;
3933 CString onelog =log;
3934 onelog=log.Mid(start -4,length);
3935 rev.ParserFromLog(onelog);
3936 this->push_back(rev);
3937 start = next +4;
3940 return 0;