OSDN Git Service

5ba6f3afe31d106754f6748dd61db67b9ed0d02f
[tortoisegit/TortoiseGitJp.git] / TortoiseProc / LogDlg.cpp
1 // TortoiseGit - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseGit\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "stdafx.h"\r
20 #include "TortoiseProc.h"\r
21 #include "cursor.h"\r
22 #include "InputDlg.h"\r
23 #include "PropDlg.h"\r
24 #include "SVNProgressDlg.h"\r
25 #include "ProgressDlg.h"\r
26 //#include "RepositoryBrowser.h"\r
27 //#include "CopyDlg.h"\r
28 //#include "StatGraphDlg.h"\r
29 #include "Logdlg.h"\r
30 #include "MessageBox.h"\r
31 #include "Registry.h"\r
32 #include "AppUtils.h"\r
33 #include "PathUtils.h"\r
34 #include "StringUtils.h"\r
35 #include "UnicodeUtils.h"\r
36 #include "TempFile.h"\r
37 //#include "GitInfo.h"\r
38 //#include "GitDiff.h"\r
39 #include "IconMenu.h"\r
40 //#include "RevisionRangeDlg.h"\r
41 //#include "BrowseFolder.h"\r
42 //#include "BlameDlg.h"\r
43 //#include "Blame.h"\r
44 //#include "GitHelpers.h"\r
45 #include "GitStatus.h"\r
46 //#include "LogDlgHelper.h"\r
47 //#include "CachedLogInfo.h"\r
48 //#include "RepositoryInfo.h"\r
49 //#include "EditPropertiesDlg.h"\r
50 \r
51 \r
52 #if (NTDDI_VERSION < NTDDI_LONGHORN)\r
53 \r
54 enum LISTITEMSTATES_MINE {\r
55         LISS_NORMAL = 1,\r
56         LISS_HOT = 2,\r
57         LISS_SELECTED = 3,\r
58         LISS_DISABLED = 4,\r
59         LISS_SELECTEDNOTFOCUS = 5,\r
60         LISS_HOTSELECTED = 6,\r
61 };\r
62 \r
63 #define MCS_NOTRAILINGDATES  0x0040\r
64 #define MCS_SHORTDAYSOFWEEK  0x0080\r
65 #define MCS_NOSELCHANGEONNAV 0x0100\r
66 \r
67 #define DTM_SETMCSTYLE    (DTM_FIRST + 11)\r
68 \r
69 #endif\r
70 \r
71 #define ICONITEMBORDER 5\r
72 \r
73 const UINT CLogDlg::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);\r
74 \r
75 \r
76 enum LogDlgContextMenuCommands\r
77 {\r
78         // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu\r
79         ID_COMPARE = 1,\r
80         ID_SAVEAS,\r
81         ID_COMPARETWO,\r
82         ID_UPDATE,\r
83         ID_COPY,\r
84         ID_REVERTREV,\r
85         ID_MERGEREV,\r
86         ID_GNUDIFF1,\r
87         ID_GNUDIFF2,\r
88         ID_FINDENTRY,\r
89         ID_OPEN,\r
90         ID_BLAME,\r
91         ID_REPOBROWSE,\r
92         ID_LOG,\r
93         ID_POPPROPS,\r
94         ID_EDITAUTHOR,\r
95         ID_EDITLOG,\r
96         ID_DIFF,\r
97         ID_OPENWITH,\r
98         ID_COPYCLIPBOARD,\r
99         ID_CHECKOUT,\r
100         ID_REVERTTOREV,\r
101         ID_BLAMECOMPARE,\r
102         ID_BLAMETWO,\r
103         ID_BLAMEDIFF,\r
104         ID_VIEWREV,\r
105         ID_VIEWPATHREV,\r
106         ID_EXPORT,\r
107         ID_COMPAREWITHPREVIOUS,\r
108         ID_BLAMEWITHPREVIOUS,\r
109         ID_GETMERGELOGS,\r
110         ID_REVPROPS\r
111 };\r
112 \r
113 \r
114 IMPLEMENT_DYNAMIC(CLogDlg, CResizableStandAloneDialog)\r
115 CLogDlg::CLogDlg(CWnd* pParent /*=NULL*/)\r
116         : CResizableStandAloneDialog(CLogDlg::IDD, pParent)\r
117         , m_logcounter(0)\r
118         , m_nSearchIndex(0)\r
119         , m_wParam(0)\r
120         , m_nSelectedFilter(LOGFILTER_ALL)\r
121         , m_bNoDispUpdates(FALSE)\r
122         , m_currentChangedArray(NULL)\r
123         , m_nSortColumn(0)\r
124         , m_bShowedAll(false)\r
125         , m_bSelect(false)\r
126         , m_regLastStrict(_T("Software\\TortoiseGit\\LastLogStrict"), FALSE)\r
127         , m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)\r
128         , m_bSelectionMustBeContinuous(false)\r
129         , m_bShowBugtraqColumn(false)\r
130         , m_lowestRev(_T(""))\r
131         , m_bStrictStopped(false)\r
132         , m_sLogInfo(_T(""))\r
133         , m_pFindDialog(NULL)\r
134         , m_bCancelled(FALSE)\r
135         , m_pNotifyWindow(NULL)\r
136         , m_bThreadRunning(FALSE)\r
137         , m_bAscending(FALSE)\r
138         , m_pStoreSelection(NULL)\r
139         , m_limit(0)\r
140         , m_childCounter(0)\r
141         , m_maxChild(0)\r
142         , m_bIncludeMerges(FALSE)\r
143         , m_hAccel(NULL)\r
144         , m_bVista(false)\r
145 {\r
146         m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);\r
147         // use the default GUI font, create a copy of it and\r
148         // change the copy to BOLD (leave the rest of the font\r
149         // the same)\r
150         HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);\r
151         LOGFONT lf = {0};\r
152         GetObject(hFont, sizeof(LOGFONT), &lf);\r
153         lf.lfWeight = FW_BOLD;\r
154         m_boldFont = CreateFontIndirect(&lf);\r
155 }\r
156 \r
157 CLogDlg::~CLogDlg()\r
158 {\r
159         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
160     m_CurrentFilteredChangedArray.RemoveAll();\r
161         m_logEntries.ClearAll();\r
162         DestroyIcon(m_hModifiedIcon);\r
163         DestroyIcon(m_hReplacedIcon);\r
164         DestroyIcon(m_hAddedIcon);\r
165         DestroyIcon(m_hDeletedIcon);\r
166         if ( m_pStoreSelection )\r
167         {\r
168                 delete m_pStoreSelection;\r
169                 m_pStoreSelection = NULL;\r
170         }\r
171         if (m_boldFont)\r
172                 DeleteObject(m_boldFont);\r
173 }\r
174 \r
175 void CLogDlg::DoDataExchange(CDataExchange* pDX)\r
176 {\r
177         CResizableStandAloneDialog::DoDataExchange(pDX);\r
178         DDX_Control(pDX, IDC_LOGLIST, m_LogList);\r
179         DDX_Control(pDX, IDC_LOGMSG, m_ChangedFileListCtrl);\r
180         DDX_Control(pDX, IDC_PROGRESS, m_LogProgress);\r
181         DDX_Control(pDX, IDC_SPLITTERTOP, m_wndSplitter1);\r
182         DDX_Control(pDX, IDC_SPLITTERBOTTOM, m_wndSplitter2);\r
183         DDX_Check(pDX, IDC_CHECK_STOPONCOPY, m_bStrict);\r
184         DDX_Text(pDX, IDC_SEARCHEDIT, m_sFilterText);\r
185         DDX_Control(pDX, IDC_DATEFROM, m_DateFrom);\r
186         DDX_Control(pDX, IDC_DATETO, m_DateTo);\r
187         DDX_Control(pDX, IDC_HIDEPATHS, m_cHidePaths);\r
188         DDX_Control(pDX, IDC_GETALL, m_btnShow);\r
189         DDX_Text(pDX, IDC_LOGINFO, m_sLogInfo);\r
190         DDX_Check(pDX, IDC_INCLUDEMERGE, m_bIncludeMerges);\r
191         DDX_Control(pDX, IDC_SEARCHEDIT, m_cFilter);\r
192 }\r
193 \r
194 BEGIN_MESSAGE_MAP(CLogDlg, CResizableStandAloneDialog)\r
195         ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage) \r
196         ON_BN_CLICKED(IDC_GETALL, OnBnClickedGetall)\r
197         ON_NOTIFY(NM_DBLCLK, IDC_LOGMSG, OnNMDblclkChangedFileList)\r
198         ON_NOTIFY(NM_DBLCLK, IDC_LOGLIST, OnNMDblclkLoglist)\r
199         ON_WM_CONTEXTMENU()\r
200         ON_WM_SETCURSOR()\r
201         ON_BN_CLICKED(IDHELP, OnBnClickedHelp)\r
202         ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOGLIST, OnLvnItemchangedLoglist)\r
203         ON_NOTIFY(EN_LINK, IDC_MSGVIEW, OnEnLinkMsgview)\r
204         ON_BN_CLICKED(IDC_STATBUTTON, OnBnClickedStatbutton)\r
205         ON_NOTIFY(NM_CUSTOMDRAW, IDC_LOGLIST, OnNMCustomdrawLoglist)\r
206         ON_MESSAGE(WM_FILTEREDIT_INFOCLICKED, OnClickedInfoIcon)\r
207         ON_MESSAGE(WM_FILTEREDIT_CANCELCLICKED, OnClickedCancelFilter)\r
208         ON_NOTIFY(LVN_GETDISPINFO, IDC_LOGLIST, OnLvnGetdispinfoLoglist)\r
209         ON_EN_CHANGE(IDC_SEARCHEDIT, OnEnChangeSearchedit)\r
210         ON_WM_TIMER()\r
211         ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETO, OnDtnDatetimechangeDateto)\r
212         ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATEFROM, OnDtnDatetimechangeDatefrom)\r
213         ON_BN_CLICKED(IDC_NEXTHUNDRED, OnBnClickedNexthundred)\r
214         ON_NOTIFY(NM_CUSTOMDRAW, IDC_LOGMSG, OnNMCustomdrawChangedFileList)\r
215         ON_NOTIFY(LVN_GETDISPINFO, IDC_LOGMSG, OnLvnGetdispinfoChangedFileList)\r
216         ON_NOTIFY(LVN_COLUMNCLICK, IDC_LOGLIST, OnLvnColumnclick)\r
217         ON_NOTIFY(LVN_COLUMNCLICK, IDC_LOGMSG, OnLvnColumnclickChangedFileList)\r
218         ON_BN_CLICKED(IDC_HIDEPATHS, OnBnClickedHidepaths)\r
219         ON_NOTIFY(LVN_ODFINDITEM, IDC_LOGLIST, OnLvnOdfinditemLoglist)\r
220         ON_BN_CLICKED(IDC_CHECK_STOPONCOPY, &CLogDlg::OnBnClickedCheckStoponcopy)\r
221         ON_NOTIFY(DTN_DROPDOWN, IDC_DATEFROM, &CLogDlg::OnDtnDropdownDatefrom)\r
222         ON_NOTIFY(DTN_DROPDOWN, IDC_DATETO, &CLogDlg::OnDtnDropdownDateto)\r
223         ON_WM_SIZE()\r
224         ON_BN_CLICKED(IDC_INCLUDEMERGE, &CLogDlg::OnBnClickedIncludemerge)\r
225         ON_BN_CLICKED(IDC_REFRESH, &CLogDlg::OnBnClickedRefresh)\r
226         ON_COMMAND(ID_LOGDLG_REFRESH,&CLogDlg::OnRefresh)\r
227         ON_COMMAND(ID_LOGDLG_FIND,&CLogDlg::OnFind)\r
228         ON_COMMAND(ID_LOGDLG_FOCUSFILTER,&CLogDlg::OnFocusFilter)\r
229         ON_COMMAND(ID_EDIT_COPY, &CLogDlg::OnEditCopy)\r
230 END_MESSAGE_MAP()\r
231 \r
232 void CLogDlg::SetParams(const CTGitPath& path, GitRev pegrev, GitRev startrev, GitRev endrev, int limit, BOOL bStrict /* = FALSE */, BOOL bSaveStrict /* = TRUE */)\r
233 {\r
234         m_path = path;\r
235         m_pegrev = pegrev;\r
236         m_startrev = startrev;\r
237         m_LogRevision = startrev;\r
238         m_endrev = endrev;\r
239         m_hasWC = !path.IsUrl();\r
240         m_bStrict = bStrict;\r
241         m_bSaveStrict = bSaveStrict;\r
242         m_limit = limit;\r
243         if (::IsWindow(m_hWnd))\r
244                 UpdateData(FALSE);\r
245 }\r
246 \r
247 BOOL CLogDlg::OnInitDialog()\r
248 {\r
249         CResizableStandAloneDialog::OnInitDialog();\r
250 \r
251         m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_LOGDLG));\r
252 \r
253         OSVERSIONINFOEX inf;\r
254         SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));\r
255         inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);\r
256         GetVersionEx((OSVERSIONINFO *)&inf);\r
257         WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);\r
258         m_bVista = (fullver >= 0x0600);\r
259 \r
260         // use the state of the "stop on copy/rename" option from the last time\r
261         if (!m_bStrict)\r
262                 m_bStrict = m_regLastStrict;\r
263         UpdateData(FALSE);\r
264         CString temp;\r
265         if (m_limit)\r
266                 temp.Format(IDS_LOG_SHOWNEXT, m_limit);\r
267         else\r
268                 temp.Format(IDS_LOG_SHOWNEXT, (int)(DWORD)CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100));\r
269 \r
270         SetDlgItemText(IDC_NEXTHUNDRED, temp);\r
271 \r
272         // set the font to use in the log message view, configured in the settings dialog\r
273         CAppUtils::CreateFontForLogs(m_logFont);\r
274         GetDlgItem(IDC_MSGVIEW)->SetFont(&m_logFont);\r
275         // automatically detect URLs in the log message and turn them into links\r
276         GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_AUTOURLDETECT, TRUE, NULL);\r
277         // make the log message rich edit control send a message when the mouse pointer is over a link\r
278         GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_SETEVENTMASK, NULL, ENM_LINK);\r
279         m_LogList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_SUBITEMIMAGES);\r
280 \r
281         // the "hide unrelated paths" checkbox should be indeterminate\r
282         m_cHidePaths.SetCheck(BST_INDETERMINATE);\r
283 \r
284         // load the icons for the action columns\r
285         m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
286         m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
287         m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
288         m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
289         \r
290         // if there is a working copy, load the project properties\r
291         // to get information about the bugtraq: integration\r
292         if (m_hasWC)\r
293                 m_ProjectProperties.ReadProps(m_path);\r
294 \r
295         // the bugtraq issue id column is only shown if the bugtraq:url or bugtraq:regex is set\r
296         if ((!m_ProjectProperties.sUrl.IsEmpty())||(!m_ProjectProperties.sCheckRe.IsEmpty()))\r
297                 m_bShowBugtraqColumn = true;\r
298 \r
299         theme.SetWindowTheme(m_LogList.GetSafeHwnd(), L"Explorer", NULL);\r
300         theme.SetWindowTheme(m_ChangedFileListCtrl.GetSafeHwnd(), L"Explorer", NULL);\r
301 \r
302         // set up the columns\r
303         m_LogList.DeleteAllItems();\r
304         int c = ((CHeaderCtrl*)(m_LogList.GetDlgItem(0)))->GetItemCount()-1;\r
305         while (c>=0)\r
306                 m_LogList.DeleteColumn(c--);\r
307         temp.LoadString(IDS_LOG_REVISION);\r
308         m_LogList.InsertColumn(0, temp);\r
309         \r
310         // make the revision column right aligned\r
311         LVCOLUMN Column;\r
312         Column.mask = LVCF_FMT;\r
313         Column.fmt = LVCFMT_RIGHT;\r
314         m_LogList.SetColumn(0, &Column); \r
315         \r
316         temp.LoadString(IDS_LOG_ACTIONS);\r
317         m_LogList.InsertColumn(1, temp);\r
318         temp.LoadString(IDS_LOG_AUTHOR);\r
319         m_LogList.InsertColumn(2, temp);\r
320         temp.LoadString(IDS_LOG_DATE);\r
321         m_LogList.InsertColumn(3, temp);\r
322         if (m_bShowBugtraqColumn)\r
323         {\r
324                 temp = m_ProjectProperties.sLabel;\r
325                 if (temp.IsEmpty())\r
326                         temp.LoadString(IDS_LOG_BUGIDS);\r
327                 m_LogList.InsertColumn(4, temp);\r
328         }\r
329         temp.LoadString(IDS_LOG_MESSAGE);\r
330         m_LogList.InsertColumn(m_bShowBugtraqColumn ? 5 : 4, temp);\r
331         m_LogList.SetRedraw(false);\r
332         ResizeAllListCtrlCols();\r
333         m_LogList.SetRedraw(true);\r
334 \r
335         m_ChangedFileListCtrl.SetExtendedStyle ( LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER );\r
336         m_ChangedFileListCtrl.DeleteAllItems();\r
337         c = ((CHeaderCtrl*)(m_ChangedFileListCtrl.GetDlgItem(0)))->GetItemCount()-1;\r
338         while (c>=0)\r
339                 m_ChangedFileListCtrl.DeleteColumn(c--);\r
340         temp.LoadString(IDS_PROGRS_ACTION);\r
341         m_ChangedFileListCtrl.InsertColumn(0, temp);\r
342         temp.LoadString(IDS_PROGRS_PATH);\r
343         m_ChangedFileListCtrl.InsertColumn(1, temp);\r
344         temp.LoadString(IDS_LOG_COPYFROM);\r
345         m_ChangedFileListCtrl.InsertColumn(2, temp);\r
346         temp.LoadString(IDS_LOG_REVISION);\r
347         m_ChangedFileListCtrl.InsertColumn(3, temp);\r
348         m_ChangedFileListCtrl.SetRedraw(false);\r
349         CAppUtils::ResizeAllListCtrlCols(&m_ChangedFileListCtrl);\r
350         m_ChangedFileListCtrl.SetRedraw(true);\r
351 \r
352 \r
353         GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);\r
354 \r
355         m_logcounter = 0;\r
356         m_sMessageBuf.Preallocate(100000);\r
357 \r
358         // set the dialog title to "Log - path/to/whatever/we/show/the/log/for"\r
359         SetDlgTitle(false);\r
360 \r
361         m_tooltips.Create(this);\r
362         CheckRegexpTooltip();\r
363 \r
364         SetSplitterRange();\r
365         \r
366         // the filter control has a 'cancel' button (the red 'X'), we need to load its bitmap\r
367         m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);\r
368         m_cFilter.SetInfoIcon(IDI_LOGFILTER);\r
369         m_cFilter.SetValidator(this);\r
370         \r
371         AdjustControlSize(IDC_HIDEPATHS);\r
372         AdjustControlSize(IDC_CHECK_STOPONCOPY);\r
373         AdjustControlSize(IDC_INCLUDEMERGE);\r
374 \r
375         GetClientRect(m_DlgOrigRect);\r
376         m_LogList.GetClientRect(m_LogListOrigRect);\r
377         GetDlgItem(IDC_MSGVIEW)->GetClientRect(m_MsgViewOrigRect);\r
378         m_ChangedFileListCtrl.GetClientRect(m_ChgOrigRect);\r
379 \r
380         m_DateFrom.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);\r
381         m_DateTo.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);\r
382 \r
383         // resizable stuff\r
384         AddAnchor(IDC_FROMLABEL, TOP_LEFT);\r
385         AddAnchor(IDC_DATEFROM, TOP_LEFT);\r
386         AddAnchor(IDC_TOLABEL, TOP_LEFT);\r
387         AddAnchor(IDC_DATETO, TOP_LEFT);\r
388 \r
389         SetFilterCueText();\r
390         AddAnchor(IDC_SEARCHEDIT, TOP_LEFT, TOP_RIGHT);\r
391         \r
392         AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);\r
393         AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);\r
394         AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);\r
395         AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);\r
396         AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);\r
397 \r
398         AddAnchor(IDC_LOGINFO, BOTTOM_LEFT, BOTTOM_RIGHT);      \r
399         AddAnchor(IDC_HIDEPATHS, BOTTOM_LEFT);  \r
400         AddAnchor(IDC_CHECK_STOPONCOPY, BOTTOM_LEFT);\r
401         AddAnchor(IDC_INCLUDEMERGE, BOTTOM_LEFT);\r
402         AddAnchor(IDC_GETALL, BOTTOM_LEFT);\r
403         AddAnchor(IDC_NEXTHUNDRED, BOTTOM_LEFT);\r
404         AddAnchor(IDC_REFRESH, BOTTOM_LEFT);\r
405         AddAnchor(IDC_STATBUTTON, BOTTOM_RIGHT);\r
406         AddAnchor(IDC_PROGRESS, BOTTOM_LEFT, BOTTOM_RIGHT);\r
407         AddAnchor(IDOK, BOTTOM_RIGHT);\r
408         AddAnchor(IDCANCEL, BOTTOM_RIGHT);\r
409         AddAnchor(IDHELP, BOTTOM_RIGHT);\r
410 \r
411 //      SetPromptParentWindow(m_hWnd);\r
412 \r
413         if (hWndExplorer)\r
414                 CenterWindow(CWnd::FromHandle(hWndExplorer));\r
415         EnableSaveRestore(_T("LogDlg"));\r
416 \r
417         DWORD yPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));\r
418         DWORD yPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));\r
419         RECT rcDlg, rcLogList, rcChgMsg;\r
420         GetClientRect(&rcDlg);\r
421         m_LogList.GetWindowRect(&rcLogList);\r
422         ScreenToClient(&rcLogList);\r
423         m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg);\r
424         ScreenToClient(&rcChgMsg);\r
425         if (yPos1)\r
426         {\r
427                 RECT rectSplitter;\r
428                 m_wndSplitter1.GetWindowRect(&rectSplitter);\r
429                 ScreenToClient(&rectSplitter);\r
430                 int delta = yPos1 - rectSplitter.top;\r
431 \r
432                 if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30))\r
433                 {\r
434                         m_wndSplitter1.SetWindowPos(NULL, 0, yPos1, 0, 0, SWP_NOSIZE);\r
435                         DoSizeV1(delta);\r
436                 }\r
437         }\r
438         if (yPos2)\r
439         {\r
440                 RECT rectSplitter;\r
441                 m_wndSplitter2.GetWindowRect(&rectSplitter);\r
442                 ScreenToClient(&rectSplitter);\r
443                 int delta = yPos2 - rectSplitter.top;\r
444 \r
445                 if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30))\r
446                 {\r
447                         m_wndSplitter2.SetWindowPos(NULL, 0, yPos2, 0, 0, SWP_NOSIZE);\r
448                         DoSizeV2(delta);\r
449                 }\r
450         }\r
451 \r
452         \r
453         if (m_bSelect)\r
454         {\r
455                 // the dialog is used to select revisions\r
456                 if (m_bSelectionMustBeContinuous)\r
457                         DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(IsSelectionContinuous()));\r
458                 else\r
459                         DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);\r
460         }\r
461         else\r
462         {\r
463                 // the dialog is used to just view log messages\r
464                 GetDlgItemText(IDOK, temp);\r
465                 SetDlgItemText(IDCANCEL, temp);\r
466                 GetDlgItem(IDOK)->ShowWindow(SW_HIDE);\r
467         }\r
468         \r
469         // set the choices for the "Show All" button\r
470         temp.LoadString(IDS_LOG_SHOWALL);\r
471         m_btnShow.AddEntry(temp);\r
472         temp.LoadString(IDS_LOG_SHOWRANGE);\r
473         m_btnShow.AddEntry(temp);\r
474         m_btnShow.SetCurrentEntry((LONG)CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry")));\r
475 \r
476         m_mergedRevs.clear();\r
477 \r
478         // first start a thread to obtain the log messages without\r
479         // blocking the dialog\r
480         m_tTo = 0;\r
481         m_tFrom = (DWORD)-1;\r
482         InterlockedExchange(&m_bThreadRunning, TRUE);\r
483         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
484         if (AfxBeginThread(LogThreadEntry, this)==NULL)\r
485         {\r
486                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
487                 InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
488                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
489         }\r
490         GetDlgItem(IDC_LOGLIST)->SetFocus();\r
491         return FALSE;\r
492 }\r
493 \r
494 void CLogDlg::SetDlgTitle(bool bOffline)\r
495 {\r
496         if (m_sTitle.IsEmpty())\r
497                 GetWindowText(m_sTitle);\r
498 \r
499         if (bOffline)\r
500         {\r
501                 CString sTemp;\r
502                 if (m_path.IsUrl())\r
503                         sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetUIPathString());\r
504                 else if (m_path.IsDirectory())\r
505                         sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetWinPathString());\r
506                 else\r
507                         sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetFilename());\r
508                 SetWindowText(sTemp);\r
509         }\r
510         else\r
511         {\r
512                 if (m_path.IsUrl())\r
513                         SetWindowText(m_sTitle + _T(" - ") + m_path.GetUIPathString());\r
514                 else if (m_path.IsDirectory())\r
515                         SetWindowText(m_sTitle + _T(" - ") + m_path.GetWinPathString());\r
516                 else\r
517                         SetWindowText(m_sTitle + _T(" - ") + m_path.GetFilename());\r
518         }\r
519 }\r
520 \r
521 void CLogDlg::CheckRegexpTooltip()\r
522 {\r
523         CWnd *pWnd = GetDlgItem(IDC_SEARCHEDIT);\r
524         // Since tooltip describes regexp features, show it only if regexps are enabled.\r
525         if (m_bFilterWithRegex)\r
526         {\r
527                 m_tooltips.AddTool(pWnd, IDS_LOG_FILTER_REGEX_TT);\r
528         }\r
529         else\r
530                 m_tooltips.DelTool(pWnd);\r
531 }\r
532 \r
533 void CLogDlg::EnableOKButton()\r
534 {\r
535         if (m_bSelect)\r
536         {\r
537                 // the dialog is used to select revisions\r
538                 if (m_bSelectionMustBeContinuous)\r
539                         DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(IsSelectionContinuous()));\r
540                 else\r
541                         DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);\r
542         }\r
543         else\r
544                 DialogEnableWindow(IDOK, TRUE);\r
545 }\r
546 \r
547 void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)\r
548 {\r
549         // we fill here the log message rich edit control,\r
550         // and also populate the changed files list control\r
551         // according to the selected revision(s).\r
552 \r
553         CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);\r
554         // empty the log message view\r
555         pMsgView->SetWindowText(_T(" "));\r
556         // empty the changed files list\r
557         m_ChangedFileListCtrl.SetRedraw(FALSE);\r
558         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
559         m_currentChangedArray = NULL;\r
560         m_ChangedFileListCtrl.SetExtendedStyle ( LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER );\r
561         m_ChangedFileListCtrl.DeleteAllItems();\r
562         m_ChangedFileListCtrl.SetItemCountEx(0);\r
563 \r
564         // if we're not here to really show a selected revision, just\r
565         // get out of here after clearing the views, which is what is intended\r
566         // if that flag is not set.\r
567         if (!bShow)\r
568         {\r
569                 // force a redraw\r
570                 m_ChangedFileListCtrl.Invalidate();\r
571                 InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
572                 m_ChangedFileListCtrl.SetRedraw(TRUE);\r
573                 return;\r
574         }\r
575 \r
576         // depending on how many revisions are selected, we have to do different\r
577         // tasks.\r
578         int selCount = m_LogList.GetSelectedCount();\r
579         if (selCount == 0)\r
580         {\r
581                 // if nothing is selected, we have nothing more to do\r
582                 InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
583                 m_ChangedFileListCtrl.SetRedraw(TRUE);\r
584                 return;\r
585         }\r
586         else if (selCount == 1)\r
587         {\r
588                 // if one revision is selected, we have to fill the log message view\r
589                 // with the corresponding log message, and also fill the changed files\r
590                 // list fully.\r
591                 POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
592                 int selIndex = m_LogList.GetNextSelectedItem(pos);\r
593                 if (selIndex >= m_arShownList.GetCount())\r
594                 {\r
595                         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
596                         m_ChangedFileListCtrl.SetRedraw(TRUE);\r
597                         return;\r
598                 }\r
599                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(selIndex));\r
600 \r
601                 // set the log message text\r
602                 pMsgView->SetWindowText(pLogEntry->sMessage);\r
603                 // turn bug ID's into links if the bugtraq: properties have been set\r
604                 // and we can find a match of those in the log message\r
605                 m_ProjectProperties.FindBugID(pLogEntry->sMessage, pMsgView);\r
606                 CAppUtils::FormatTextInRichEditControl(pMsgView);\r
607                 m_currentChangedArray = pLogEntry->pArChangedPaths;\r
608                 if (m_currentChangedArray == NULL)\r
609                 {\r
610                         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
611                         m_ChangedFileListCtrl.SetRedraw(TRUE);\r
612                         return;\r
613                 }\r
614                 // fill in the changed files list control\r
615                 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)\r
616                 {\r
617                         m_CurrentFilteredChangedArray.RemoveAll();\r
618                         for (INT_PTR c = 0; c < m_currentChangedArray->GetCount(); ++c)\r
619                         {\r
620                                 LogChangedPath * cpath = m_currentChangedArray->GetAt(c);\r
621                                 if (cpath == NULL)\r
622                                         continue;\r
623                                 if (m_currentChangedArray->GetAt(c)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)\r
624                                 {\r
625                                         m_CurrentFilteredChangedArray.Add(cpath);\r
626                                 }\r
627                         }\r
628                         m_currentChangedArray = &m_CurrentFilteredChangedArray;\r
629                 }\r
630         }\r
631         else\r
632         {\r
633                 // more than one revision is selected:\r
634                 // the log message view must be emptied\r
635                 // the changed files list contains all the changed paths from all\r
636                 // selected revisions, with 'doubles' removed\r
637                 m_currentChangedPathList = GetChangedPathsFromSelectedRevisions(true);\r
638         }\r
639         \r
640         // redraw the views\r
641         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
642         if (m_currentChangedArray)\r
643         {\r
644                 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedArray->GetCount());\r
645                 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedArray->GetCount());\r
646         }\r
647         else if (m_currentChangedPathList.GetCount())\r
648         {\r
649                 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedPathList.GetCount());\r
650                 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedPathList.GetCount());\r
651         }\r
652         else\r
653         {\r
654                 m_ChangedFileListCtrl.SetItemCountEx(0);\r
655                 m_ChangedFileListCtrl.Invalidate();\r
656         }\r
657         CAppUtils::ResizeAllListCtrlCols(&m_ChangedFileListCtrl);\r
658         // sort according to the settings\r
659         if (m_nSortColumnPathList > 0)\r
660                 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);\r
661         else\r
662                 SetSortArrow(&m_ChangedFileListCtrl, -1, false);\r
663         m_ChangedFileListCtrl.SetRedraw(TRUE);\r
664 }\r
665 \r
666 void CLogDlg::OnBnClickedGetall()\r
667 {\r
668         GetAll();\r
669 }\r
670 \r
671 void CLogDlg::GetAll(bool bForceAll /* = false */)\r
672 {\r
673 #if 0\r
674         // fetch all requested log messages, either the specified range or\r
675         // really *all* available log messages.\r
676         UpdateData();\r
677         INT_PTR entry = m_btnShow.GetCurrentEntry();\r
678         if (bForceAll)\r
679                 entry = 0;\r
680 \r
681         switch (entry)\r
682         {\r
683         case 0: // show all\r
684         \r
685                 m_endrev = 0;\r
686                 m_startrev = m_LogRevision;\r
687                 if (m_bStrict)\r
688                         m_bShowedAll = true;\r
689 \r
690                 break;\r
691         case 1: // show range\r
692                 {\r
693 \r
694                         // ask for a revision range\r
695                         CRevisionRangeDlg dlg;\r
696                         dlg.SetStartRevision(m_startrev);\r
697                         dlg.SetEndRevision( (m_endrev>=0) ? m_endrev : 0);\r
698                         if (dlg.DoModal()!=IDOK)\r
699                         {\r
700                                 return;\r
701                         }\r
702                         m_endrev = dlg.GetEndRevision();\r
703                         m_startrev = dlg.GetStartRevision();\r
704                         if (((m_endrev.IsNumber())&&(m_startrev.IsNumber()))||\r
705                                 (m_endrev.IsHead()||m_startrev.IsHead()))\r
706                         {\r
707                                 if (((LONG)m_startrev < (LONG)m_endrev)||\r
708                                         (m_endrev.IsHead()))\r
709                                 {\r
710                                         git_revnum_t temp = m_startrev;\r
711                                         m_startrev = m_endrev;\r
712                                         m_endrev = temp;\r
713                                 }\r
714                         }\r
715                         m_bShowedAll = false;\r
716                 }\r
717 \r
718                 break;\r
719         }\r
720         m_ChangedFileListCtrl.SetItemCountEx(0);\r
721         m_ChangedFileListCtrl.Invalidate();\r
722         // We need to create CStoreSelection on the heap or else\r
723         // the variable will run out of the scope before the\r
724         // thread ends. Therefore we let the thread delete\r
725         // the instance.\r
726         m_pStoreSelection = new CStoreSelection(this);\r
727         m_LogList.SetItemCountEx(0);\r
728         m_LogList.Invalidate();\r
729         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
730         CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);\r
731         pMsgView->SetWindowText(_T(""));\r
732 \r
733         SetSortArrow(&m_LogList, -1, true);\r
734 \r
735         m_LogList.DeleteAllItems();\r
736         m_arShownList.RemoveAll();\r
737         m_logEntries.ClearAll();\r
738 \r
739         m_logcounter = 0;\r
740         m_bCancelled = FALSE;\r
741         m_tTo = 0;\r
742         m_tFrom = (DWORD)-1;\r
743         m_limit = 0;\r
744 \r
745         InterlockedExchange(&m_bThreadRunning, TRUE);\r
746         if (AfxBeginThread(LogThreadEntry, this)==NULL)\r
747         {\r
748                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
749                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
750         }\r
751         GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);\r
752         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
753 #endif\r
754 }\r
755 \r
756 void CLogDlg::OnBnClickedRefresh()\r
757 {\r
758         m_limit = 0;\r
759         Refresh (true);\r
760 }\r
761 \r
762 void CLogDlg::Refresh (bool autoGoOnline)\r
763 {\r
764 #if 0\r
765         // refreshing means re-downloading the already shown log messages\r
766         UpdateData();\r
767         m_maxChild = 0;\r
768         m_childCounter = 0;\r
769 \r
770         if ((m_limit == 0)||(m_bStrict)||(int(m_logEntries.size()-1) > m_limit))\r
771         {\r
772                 if (m_logEntries.size() != 0)\r
773                 {\r
774                         m_endrev = m_logEntries[m_logEntries.size()-1]->Rev;\r
775                 }\r
776         }\r
777         m_startrev = -1;\r
778         m_bCancelled = FALSE;\r
779 \r
780         // We need to create CStoreSelection on the heap or else\r
781         // the variable will run out of the scope before the\r
782         // thread ends. Therefore we let the thread delete\r
783         // the instance.\r
784         m_pStoreSelection = new CStoreSelection(this);\r
785         m_ChangedFileListCtrl.SetItemCountEx(0);\r
786         m_ChangedFileListCtrl.Invalidate();\r
787         m_LogList.SetItemCountEx(0);\r
788         m_LogList.Invalidate();\r
789         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
790         CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);\r
791         pMsgView->SetWindowText(_T(""));\r
792 \r
793         SetSortArrow(&m_LogList, -1, true);\r
794 \r
795         m_LogList.DeleteAllItems();\r
796         m_arShownList.RemoveAll();\r
797         m_logEntries.ClearAll();\r
798 \r
799     // reset the cached HEAD property & go on-line\r
800 \r
801     if (autoGoOnline)\r
802     {\r
803             SetDlgTitle (false);\r
804         logCachePool.GetRepositoryInfo().ResetHeadRevision (m_sUUID, m_sRepositoryRoot);\r
805     }\r
806 \r
807         InterlockedExchange(&m_bThreadRunning, TRUE);\r
808         if (AfxBeginThread(LogThreadEntry, this)==NULL)\r
809         {\r
810                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
811                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
812         }\r
813         GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);\r
814         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
815 #endif\r
816 }\r
817 \r
818 void CLogDlg::OnBnClickedNexthundred()\r
819 {\r
820 #if 0\r
821         UpdateData();\r
822         // we have to fetch the next X log messages.\r
823         if (m_logEntries.size() < 1)\r
824         {\r
825                 // since there weren't any log messages fetched before, just\r
826                 // fetch all since we don't have an 'anchor' to fetch the 'next'\r
827                 // messages from.\r
828                 return GetAll(true);\r
829         }\r
830         git_revnum_t rev = m_logEntries[m_logEntries.size()-1]->Rev;\r
831 \r
832         if (rev < 1)\r
833                 return;         // do nothing! No more revisions to get\r
834 \r
835         m_startrev = rev;\r
836         m_endrev = 0;\r
837         m_bCancelled = FALSE;\r
838 \r
839     // rev is is revision we already have and we will receive it again\r
840     // -> fetch one extra revision to get NumberOfLogs *new* revisions\r
841 \r
842         m_limit = (int)(DWORD)CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100) +1;\r
843         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
844         SetSortArrow(&m_LogList, -1, true);\r
845         InterlockedExchange(&m_bThreadRunning, TRUE);\r
846         // We need to create CStoreSelection on the heap or else\r
847         // the variable will run out of the scope before the\r
848         // thread ends. Therefore we let the thread delete\r
849         // the instance.\r
850         m_pStoreSelection = new CStoreSelection(this);\r
851 \r
852         // since we fetch the log from the last revision we already have,\r
853         // we have to remove that revision entry to avoid getting it twice\r
854         m_logEntries.pop_back();\r
855         if (AfxBeginThread(LogThreadEntry, this)==NULL)\r
856         {\r
857                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
858                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
859         }\r
860         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
861         GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);\r
862 #endif\r
863 }\r
864 \r
865 BOOL CLogDlg::Cancel()\r
866 {\r
867         return m_bCancelled;\r
868 }\r
869 \r
870 void CLogDlg::SaveSplitterPos()\r
871 {\r
872         if (!IsIconic())\r
873         {\r
874                 CRegDWORD regPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));\r
875                 CRegDWORD regPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));\r
876                 RECT rectSplitter;\r
877                 m_wndSplitter1.GetWindowRect(&rectSplitter);\r
878                 ScreenToClient(&rectSplitter);\r
879                 regPos1 = rectSplitter.top;\r
880                 m_wndSplitter2.GetWindowRect(&rectSplitter);\r
881                 ScreenToClient(&rectSplitter);\r
882                 regPos2 = rectSplitter.top;\r
883         }\r
884 }\r
885 \r
886 void CLogDlg::OnCancel()\r
887 {\r
888         // canceling means stopping the working thread if it's still running.\r
889         // we do this by using the Subversion cancel callback.\r
890         // But canceling can also mean just to close the dialog, depending on the\r
891         // text shown on the cancel button (it could simply read "OK").\r
892         CString temp, temp2;\r
893         GetDlgItemText(IDOK, temp);\r
894         temp2.LoadString(IDS_MSGBOX_CANCEL);\r
895         if ((temp.Compare(temp2)==0)||(m_bThreadRunning))\r
896         {\r
897                 m_bCancelled = true;\r
898                 return;\r
899         }\r
900         UpdateData();\r
901         if (m_bSaveStrict)\r
902                 m_regLastStrict = m_bStrict;\r
903         CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry"));\r
904         reg = m_btnShow.GetCurrentEntry();\r
905         SaveSplitterPos();\r
906         __super::OnCancel();\r
907 }\r
908 \r
909 CString CLogDlg::MakeShortMessage(const CString& message)\r
910 {\r
911         bool bFoundShort = true;\r
912         CString sShortMessage = m_ProjectProperties.GetLogSummary(message);\r
913         if (sShortMessage.IsEmpty())\r
914         {\r
915                 bFoundShort = false;\r
916                 sShortMessage = message;\r
917         }\r
918         // Remove newlines and tabs 'cause those are not shown nicely in the list control\r
919         sShortMessage.Replace(_T("\r"), _T(""));\r
920         sShortMessage.Replace(_T("\t"), _T(" "));\r
921         \r
922         // Suppose the first empty line separates 'summary' from the rest of the message.\r
923         int found = sShortMessage.Find(_T("\n\n"));\r
924         // To avoid too short 'short' messages \r
925         // (e.g. if the message looks something like "Bugfix:\n\n*done this\n*done that")\r
926         // only use the empty newline as a separator if it comes after at least 15 chars.\r
927         if ((!bFoundShort)&&(found >= 15))\r
928         {\r
929                 sShortMessage = sShortMessage.Left(found);\r
930         }\r
931         sShortMessage.Replace('\n', ' ');\r
932         return sShortMessage;\r
933 }\r
934 \r
935 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)\r
936 {\r
937 #if 0\r
938         if (rev == SVN_INVALID_REVNUM)\r
939         {\r
940                 m_childCounter--;\r
941                 return TRUE;\r
942         }\r
943 \r
944         // this is the callback function which receives the data for every revision we ask the log for\r
945         // we store this information here one by one.\r
946         m_logcounter += 1;\r
947         if (m_startrev == -1)\r
948                 m_startrev = rev;\r
949         if (m_limit != 0)\r
950         {\r
951                 m_limitcounter--;\r
952                 m_LogProgress.SetPos(m_limit - m_limitcounter);\r
953         }\r
954         else if (m_startrev.IsNumber() && m_startrev.IsNumber())\r
955                 m_LogProgress.SetPos((git_revnum_t)m_startrev-rev+(git_revnum_t)m_endrev);\r
956         __time64_t ttime = time/1000000L;\r
957         if (m_tTo < (DWORD)ttime)\r
958                 m_tTo = (DWORD)ttime;\r
959         if (m_tFrom > (DWORD)ttime)\r
960                 m_tFrom = (DWORD)ttime;\r
961         if ((m_lowestRev > rev)||(m_lowestRev < 0))\r
962                 m_lowestRev = rev;\r
963         // Add as many characters from the log message to the list control\r
964         PLOGENTRYDATA pLogItem = new LOGENTRYDATA;\r
965         pLogItem->bCopies = !!copies;\r
966         \r
967         // find out if this item was copied in the revision\r
968         BOOL copiedself = FALSE;\r
969         if (copies)\r
970         {\r
971                 for (INT_PTR cpPathIndex = 0; cpPathIndex < cpaths->GetCount(); ++cpPathIndex)\r
972                 {\r
973                         LogChangedPath * cpath = cpaths->GetAt(cpPathIndex);\r
974                         if (!cpath->sCopyFromPath.IsEmpty() && (cpath->sPath.Compare(m_sSelfRelativeURL) == 0))\r
975                         {\r
976                                 // note: this only works if the log is fetched top-to-bottom\r
977                                 // but since we do that, it shouldn't be a problem\r
978                                 m_sSelfRelativeURL = cpath->sCopyFromPath;\r
979                                 copiedself = TRUE;\r
980                                 break;\r
981                         }\r
982                 }\r
983         }\r
984         pLogItem->bCopiedSelf = copiedself;\r
985         pLogItem->tmDate = ttime;\r
986         pLogItem->sAuthor = author;\r
987         pLogItem->sDate = date;\r
988         pLogItem->sShortMessage = MakeShortMessage(message);\r
989         pLogItem->dwFileChanges = filechanges;\r
990         pLogItem->actions = actions;\r
991         pLogItem->haschildren = haschildren;\r
992         pLogItem->childStackDepth = m_childCounter;\r
993         m_maxChild = max(m_childCounter, m_maxChild);\r
994         if (haschildren)\r
995                 m_childCounter++;\r
996         pLogItem->sBugIDs = m_ProjectProperties.FindBugID(message).Trim();\r
997         \r
998         // split multi line log entries and concatenate them\r
999         // again but this time with \r\n as line separators\r
1000         // so that the edit control recognizes them\r
1001         try\r
1002         {\r
1003                 if (message.GetLength()>0)\r
1004                 {\r
1005                         m_sMessageBuf = message;\r
1006                         m_sMessageBuf.Replace(_T("\n\r"), _T("\n"));\r
1007                         m_sMessageBuf.Replace(_T("\r\n"), _T("\n"));\r
1008                         if (m_sMessageBuf.Right(1).Compare(_T("\n"))==0)\r
1009                                 m_sMessageBuf = m_sMessageBuf.Left(m_sMessageBuf.GetLength()-1);\r
1010                 }\r
1011                 else\r
1012                         m_sMessageBuf.Empty();\r
1013         pLogItem->sMessage = m_sMessageBuf;\r
1014         pLogItem->Rev = rev;\r
1015 \r
1016         // move-construct path array\r
1017 \r
1018         pLogItem->pArChangedPaths = new LogChangedPathArray (*cpaths);\r
1019         cpaths->RemoveAll();\r
1020         }\r
1021         catch (CException * e)\r
1022         {\r
1023                 ::MessageBox(NULL, _T("not enough memory!"), _T("TortoiseGit"), MB_ICONERROR);\r
1024                 e->Delete();\r
1025                 m_bCancelled = TRUE;\r
1026         }\r
1027         m_logEntries.push_back(pLogItem);\r
1028         m_arShownList.Add(pLogItem);\r
1029 #endif\r
1030         return TRUE;\r
1031 }\r
1032 \r
1033 //this is the thread function which calls the subversion function\r
1034 UINT CLogDlg::LogThreadEntry(LPVOID pVoid)\r
1035 {\r
1036         return ((CLogDlg*)pVoid)->LogThread();\r
1037 }\r
1038 \r
1039 \r
1040 //this is the thread function which calls the subversion function\r
1041 UINT CLogDlg::LogThread()\r
1042 {\r
1043 #if 0\r
1044         InterlockedExchange(&m_bThreadRunning, TRUE);\r
1045 \r
1046     //does the user force the cache to refresh (shift or control key down)?\r
1047     bool refresh =    (GetKeyState (VK_CONTROL) < 0) \r
1048                    || (GetKeyState (VK_SHIFT) < 0);\r
1049 \r
1050         //disable the "Get All" button while we're receiving\r
1051         //log messages.\r
1052         DialogEnableWindow(IDC_GETALL, FALSE);\r
1053         DialogEnableWindow(IDC_NEXTHUNDRED, FALSE);\r
1054         DialogEnableWindow(IDC_CHECK_STOPONCOPY, FALSE);\r
1055         DialogEnableWindow(IDC_INCLUDEMERGE, FALSE);\r
1056         DialogEnableWindow(IDC_STATBUTTON, FALSE);\r
1057         DialogEnableWindow(IDC_REFRESH, FALSE);\r
1058         \r
1059         CString temp;\r
1060         temp.LoadString(IDS_PROGRESSWAIT);\r
1061         m_LogList.ShowText(temp, true);\r
1062         // change the text of the close button to "Cancel" since now the thread\r
1063         // is running, and simply closing the dialog doesn't work.\r
1064         if (!GetDlgItem(IDOK)->IsWindowVisible())\r
1065         {\r
1066                 temp.LoadString(IDS_MSGBOX_CANCEL);\r
1067                 SetDlgItemText(IDCANCEL, temp);\r
1068         }\r
1069         // We use a progress bar while getting the logs\r
1070         m_LogProgress.SetRange32(0, 100);\r
1071         m_LogProgress.SetPos(0);\r
1072         GetDlgItem(IDC_PROGRESS)->ShowWindow(TRUE);\r
1073         git_revnum_t r = -1;\r
1074         \r
1075         // get the repository root url, because the changed-files-list has the\r
1076         // paths shown there relative to the repository root.\r
1077         CTGitPath rootpath;\r
1078     BOOL succeeded = GetRootAndHead(m_path, rootpath, r);\r
1079 \r
1080     m_sRepositoryRoot = rootpath.GetGitPathString();\r
1081     m_sURL = m_path.GetGitPathString();\r
1082 \r
1083     // we need the UUID to unambigously identify the log cache\r
1084     if (logCachePool.IsEnabled())\r
1085         m_sUUID = logCachePool.GetRepositoryInfo().GetRepositoryUUID (rootpath);\r
1086 \r
1087     // if the log dialog is started from a working copy, we need to turn that\r
1088     // local path into an url here\r
1089     if (succeeded)\r
1090     {\r
1091         if (!m_path.IsUrl())\r
1092         {\r
1093                 m_sURL = GetURLFromPath(m_path);\r
1094 \r
1095                 // The URL is escaped because Git::logReceiver\r
1096                 // returns the path in a native format\r
1097                 m_sURL = CPathUtils::PathUnescape(m_sURL);\r
1098         }\r
1099         m_sRelativeRoot = m_sURL.Mid(CPathUtils::PathUnescape(m_sRepositoryRoot).GetLength());\r
1100                 m_sSelfRelativeURL = m_sRelativeRoot;\r
1101     }\r
1102 \r
1103     if (succeeded && !m_mergePath.IsEmpty() && m_mergedRevs.empty())\r
1104     {\r
1105             // in case we got a merge path set, retrieve the merge info\r
1106             // of that path and check whether one of the merge URLs\r
1107             // match the URL we show the log for.\r
1108             GitPool localpool(pool);\r
1109             git_error_clear(Err);\r
1110             apr_hash_t * mergeinfo = NULL;\r
1111             if (git_client_mergeinfo_get_merged (&mergeinfo, m_mergePath.GetGitApiPath(localpool), GitRev(GitRev::REV_WC), m_pctx, localpool) == NULL)\r
1112             {\r
1113                     // now check the relative paths\r
1114                     apr_hash_index_t *hi;\r
1115                     const void *key;\r
1116                     void *val;\r
1117 \r
1118                     if (mergeinfo)\r
1119                     {\r
1120                             for (hi = apr_hash_first(localpool, mergeinfo); hi; hi = apr_hash_next(hi))\r
1121                             {\r
1122                                     apr_hash_this(hi, &key, NULL, &val);\r
1123                                     if (m_sURL.Compare(CUnicodeUtils::GetUnicode((char*)key)) == 0)\r
1124                                     {\r
1125                                             apr_array_header_t * arr = (apr_array_header_t*)val;\r
1126                                             if (val)\r
1127                                             {\r
1128                                                     for (long i=0; i<arr->nelts; ++i)\r
1129                                                     {\r
1130                                                             git_merge_range_t * pRange = APR_ARRAY_IDX(arr, i, git_merge_range_t*);\r
1131                                                             if (pRange)\r
1132                                                             {\r
1133                                                                     for (git_revnum_t r=pRange->start+1; r<=pRange->end; ++r)\r
1134                                                                     {\r
1135                                                                             m_mergedRevs.insert(r);\r
1136                                                                     }\r
1137                                                             }\r
1138                                                     }\r
1139                                             }\r
1140                                             break;\r
1141                                     }\r
1142                             }\r
1143                     }\r
1144             }\r
1145     }\r
1146 \r
1147     m_LogProgress.SetPos(1);\r
1148     if (m_startrev == GitRev::REV_HEAD)\r
1149     {\r
1150             m_startrev = r;\r
1151     }\r
1152     if (m_endrev == GitRev::REV_HEAD)\r
1153     {\r
1154             m_endrev = r;\r
1155     }\r
1156 \r
1157     if (m_limit != 0)\r
1158     {\r
1159             m_limitcounter = m_limit;\r
1160             m_LogProgress.SetRange32(0, m_limit);\r
1161     }\r
1162     else\r
1163             m_LogProgress.SetRange32(m_endrev, m_startrev);\r
1164         \r
1165     if (!m_pegrev.IsValid())\r
1166             m_pegrev = m_startrev;\r
1167     size_t startcount = m_logEntries.size();\r
1168     m_lowestRev = -1;\r
1169     m_bStrictStopped = false;\r
1170 \r
1171     if (succeeded)\r
1172     {\r
1173         succeeded = ReceiveLog (CTGitPathList(m_path), m_pegrev, m_startrev, m_endrev, m_limit, m_bStrict, m_bIncludeMerges, refresh);\r
1174         if ((!succeeded)&&(!m_path.IsUrl()))\r
1175         {\r
1176                 // try again with REV_WC as the start revision, just in case the path doesn't\r
1177                 // exist anymore in HEAD\r
1178                 succeeded = ReceiveLog(CTGitPathList(m_path), GitRev(), GitRev::REV_WC, m_endrev, m_limit, m_bStrict, m_bIncludeMerges, refresh);\r
1179         }\r
1180     }\r
1181         m_LogList.ClearText();\r
1182     if (!succeeded)\r
1183         {\r
1184                 m_LogList.ShowText(GetLastErrorMessage(), true);\r
1185         }\r
1186         else\r
1187         {\r
1188                 if (!m_wcRev.IsValid())\r
1189                 {\r
1190                         // fetch the revision the wc path is on so we can mark it\r
1191                         CTGitPath revWCPath = m_ProjectProperties.GetPropsPath();\r
1192                         if (!m_path.IsUrl())\r
1193                                 revWCPath = m_path;\r
1194                         if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RecursiveLogRev"), FALSE)))\r
1195                         {\r
1196                                 git_revnum_t minrev, maxrev;\r
1197                                 bool switched, modified, sparse;\r
1198                                 GetWCRevisionStatus(revWCPath, true, minrev, maxrev, switched, modified, sparse);\r
1199                                 if (maxrev)\r
1200                                         m_wcRev = maxrev;\r
1201                         }\r
1202                         else\r
1203                         {\r
1204                                 CTGitPath dummypath;\r
1205                                 GitStatus status;\r
1206                                 git_wc_status2_t * stat = status.GetFirstFileStatus(revWCPath, dummypath, false, git_depth_empty);\r
1207                                 if (stat && stat->entry && stat->entry->cmt_rev)\r
1208                                         m_wcRev = stat->entry->cmt_rev;\r
1209                                 if (stat && stat->entry && (stat->entry->kind == git_node_dir))\r
1210                                         m_wcRev = stat->entry->revision;\r
1211                         }\r
1212                 }\r
1213         }\r
1214     if (m_bStrict && (m_lowestRev>1) && ((m_limit>0) ? ((startcount + m_limit)>m_logEntries.size()) : (m_endrev<m_lowestRev)))\r
1215                 m_bStrictStopped = true;\r
1216         m_LogList.SetItemCountEx(ShownCountWithStopped());\r
1217 \r
1218         m_timFrom = (__time64_t(m_tFrom));\r
1219         m_timTo = (__time64_t(m_tTo));\r
1220         m_DateFrom.SetRange(&m_timFrom, &m_timTo);\r
1221         m_DateTo.SetRange(&m_timFrom, &m_timTo);\r
1222         m_DateFrom.SetTime(&m_timFrom);\r
1223         m_DateTo.SetTime(&m_timTo);\r
1224 \r
1225         DialogEnableWindow(IDC_GETALL, TRUE);\r
1226         \r
1227         if (!m_bShowedAll)\r
1228                 DialogEnableWindow(IDC_NEXTHUNDRED, TRUE);\r
1229         DialogEnableWindow(IDC_CHECK_STOPONCOPY, TRUE);\r
1230         DialogEnableWindow(IDC_INCLUDEMERGE, TRUE);\r
1231         DialogEnableWindow(IDC_STATBUTTON, TRUE);\r
1232         DialogEnableWindow(IDC_REFRESH, TRUE);\r
1233 \r
1234         LogCache::CRepositoryInfo& cachedProperties = logCachePool.GetRepositoryInfo();\r
1235         SetDlgTitle(cachedProperties.IsOffline (m_sUUID, m_sRepositoryRoot, false));\r
1236 \r
1237         GetDlgItem(IDC_PROGRESS)->ShowWindow(FALSE);\r
1238         m_bCancelled = true;\r
1239         InterlockedExchange(&m_bThreadRunning, FALSE);\r
1240         m_LogList.RedrawItems(0, m_arShownList.GetCount());\r
1241         m_LogList.SetRedraw(false);\r
1242         ResizeAllListCtrlCols();\r
1243         m_LogList.SetRedraw(true);\r
1244         if ( m_pStoreSelection )\r
1245         {\r
1246                 // Deleting the instance will restore the\r
1247                 // selection of the CLogDlg.\r
1248                 delete m_pStoreSelection;\r
1249                 m_pStoreSelection = NULL;\r
1250         }\r
1251         else\r
1252         {\r
1253                 // If no selection has been set then this must be the first time\r
1254                 // the revisions are shown. Let's preselect the topmost revision.\r
1255                 if ( m_LogList.GetItemCount()>0 )\r
1256                 {\r
1257                         m_LogList.SetSelectionMark(0);\r
1258                         m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);\r
1259                 }\r
1260         }\r
1261         if (!GetDlgItem(IDOK)->IsWindowVisible())\r
1262         {\r
1263                 temp.LoadString(IDS_MSGBOX_OK);\r
1264                 SetDlgItemText(IDCANCEL, temp);\r
1265         }\r
1266         RefreshCursor();\r
1267         // make sure the filter is applied (if any) now, after we refreshed/fetched\r
1268         // the log messages\r
1269         PostMessage(WM_TIMER, LOGFILTER_TIMER);\r
1270 #endif\r
1271         return 0;\r
1272 }\r
1273 \r
1274 void CLogDlg::CopySelectionToClipBoard()\r
1275 {\r
1276 #if 0\r
1277         CString sClipdata;\r
1278         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1279         if (pos != NULL)\r
1280         {\r
1281                 CString sRev;\r
1282                 sRev.LoadString(IDS_LOG_REVISION);\r
1283                 CString sAuthor;\r
1284                 sAuthor.LoadString(IDS_LOG_AUTHOR);\r
1285                 CString sDate;\r
1286                 sDate.LoadString(IDS_LOG_DATE);\r
1287                 CString sMessage;\r
1288                 sMessage.LoadString(IDS_LOG_MESSAGE);\r
1289                 while (pos)\r
1290                 {\r
1291                         CString sLogCopyText;\r
1292                         CString sPaths;\r
1293                         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1294                         LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;\r
1295                         for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)\r
1296                         {\r
1297                                 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
1298                                 sPaths += cpath->GetAction() + _T(" : ") + cpath->sPath;\r
1299                                 if (cpath->sCopyFromPath.IsEmpty())\r
1300                                         sPaths += _T("\r\n");\r
1301                                 else\r
1302                                 {\r
1303                                         CString sCopyFrom;\r
1304                                         sCopyFrom.Format(_T(" (%s: %s, %s, %ld)\r\n"), CString(MAKEINTRESOURCE(IDS_LOG_COPYFROM)), \r
1305                                                 (LPCTSTR)cpath->sCopyFromPath, \r
1306                                                 (LPCTSTR)CString(MAKEINTRESOURCE(IDS_LOG_REVISION)), \r
1307                                                 (LPCTSTR)cpath->lCopyFromRev);\r
1308                                         sPaths += sCopyFrom;\r
1309                                 }\r
1310                         }\r
1311                         sPaths.Trim();\r
1312                         sLogCopyText.Format(_T("%s: %d\r\n%s: %s\r\n%s: %s\r\n%s:\r\n%s\r\n----\r\n%s\r\n\r\n"),\r
1313                                 (LPCTSTR)sRev, pLogEntry->Rev,\r
1314                                 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->sAuthor,\r
1315                                 (LPCTSTR)sDate, (LPCTSTR)pLogEntry->sDate,\r
1316                                 (LPCTSTR)sMessage, (LPCTSTR)pLogEntry->sMessage,\r
1317                                 (LPCTSTR)sPaths);\r
1318                         sClipdata +=  sLogCopyText;\r
1319                 }\r
1320                 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());\r
1321         }\r
1322 #endif\r
1323 }\r
1324 \r
1325 void CLogDlg::CopyChangedSelectionToClipBoard()\r
1326 {\r
1327 #if 0\r
1328         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1329         if (pos == NULL)\r
1330                 return; // nothing is selected, get out of here\r
1331 \r
1332         CString sPaths;\r
1333 \r
1334         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1335         if (pos)\r
1336         {\r
1337                 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();\r
1338                 while (pos)\r
1339                 {\r
1340                         int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);\r
1341                         sPaths += m_currentChangedPathList[nItem].GetGitPathString();\r
1342                         sPaths += _T("\r\n");\r
1343                 }\r
1344         }\r
1345         else\r
1346         {\r
1347                 // only one revision is selected in the log dialog top pane\r
1348                 // but multiple items could be selected  in the changed items list\r
1349                 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();\r
1350                 while (pos)\r
1351                 {\r
1352                         int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);\r
1353                         LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->GetAt(nItem);\r
1354 \r
1355                         if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)\r
1356                         {\r
1357                                 // some items are hidden! So find out which item the user really selected\r
1358                                 INT_PTR selRealIndex = -1;\r
1359                                 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)\r
1360                                 {\r
1361                                         if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)\r
1362                                                 selRealIndex++;\r
1363                                         if (selRealIndex == nItem)\r
1364                                         {\r
1365                                                 changedlogpath = pLogEntry->pArChangedPaths->GetAt(hiddenindex);\r
1366                                                 break;\r
1367                                         }\r
1368                                 }\r
1369                         }\r
1370                         if (changedlogpath)\r
1371                         {\r
1372                                 sPaths += changedlogpath->sPath;\r
1373                                 sPaths += _T("\r\n");\r
1374                         }\r
1375                 }\r
1376         }\r
1377         sPaths.Trim();\r
1378         CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());\r
1379 #endif\r
1380 }\r
1381 \r
1382 BOOL CLogDlg::IsDiffPossible(LogChangedPath * changedpath, git_revnum_t rev)\r
1383 {\r
1384 #if 0\r
1385         CString added, deleted;\r
1386         if (changedpath == NULL)\r
1387                 return false;\r
1388 \r
1389         if ((rev > 1)&&(changedpath->action != LOGACTIONS_DELETED))\r
1390         {\r
1391                 if (changedpath->action == LOGACTIONS_ADDED) // file is added\r
1392                 {\r
1393                         if (changedpath->lCopyFromRev == 0)\r
1394                                 return FALSE; // but file was not added with history\r
1395                 }\r
1396                 return TRUE;\r
1397         }\r
1398 #endif\r
1399         return FALSE;\r
1400 }\r
1401 \r
1402 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)\r
1403 {\r
1404         // we have two separate context menus:\r
1405         // one shown on the log message list control,\r
1406         // the other shown in the changed-files list control\r
1407         int selCount = m_LogList.GetSelectedCount();\r
1408         if (pWnd == &m_LogList)\r
1409         {\r
1410                 ShowContextMenuForRevisions(pWnd, point);\r
1411         }\r
1412         else if (pWnd == &m_ChangedFileListCtrl)\r
1413         {\r
1414                 ShowContextMenuForChangedpaths(pWnd, point);\r
1415         }\r
1416         else if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))\r
1417         {\r
1418                 POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1419                 int selIndex = -1;\r
1420                 if (pos)\r
1421                         selIndex = m_LogList.GetNextSelectedItem(pos);\r
1422                 if ((point.x == -1) && (point.y == -1))\r
1423                 {\r
1424                         CRect rect;\r
1425                         GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);\r
1426                         ClientToScreen(&rect);\r
1427                         point = rect.CenterPoint();\r
1428                 }\r
1429                 CString sMenuItemText;\r
1430                 CMenu popup;\r
1431                 if (popup.CreatePopupMenu())\r
1432                 {\r
1433                         // add the 'default' entries\r
1434                         sMenuItemText.LoadString(IDS_SCIEDIT_COPY);\r
1435                         popup.AppendMenu(MF_STRING | MF_ENABLED, WM_COPY, sMenuItemText);\r
1436                         sMenuItemText.LoadString(IDS_SCIEDIT_SELECTALL);\r
1437                         popup.AppendMenu(MF_STRING | MF_ENABLED, EM_SETSEL, sMenuItemText);\r
1438 \r
1439                         if (selIndex >= 0)\r
1440                         {\r
1441                                 popup.AppendMenu(MF_SEPARATOR);\r
1442                                 sMenuItemText.LoadString(IDS_LOG_POPUP_EDITLOG);\r
1443                                 popup.AppendMenu(MF_STRING | MF_ENABLED, ID_EDITAUTHOR, sMenuItemText);\r
1444                         }\r
1445 \r
1446                         int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);\r
1447                         switch (cmd)\r
1448                         {\r
1449                         case 0:\r
1450                                 break;  // no command selected\r
1451                         case EM_SETSEL:\r
1452                         case WM_COPY:\r
1453                                 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);\r
1454                                 break;\r
1455                         case ID_EDITAUTHOR:\r
1456                                 EditLogMessage(selIndex);\r
1457                                 break;\r
1458                         }\r
1459                 }\r
1460         }\r
1461 }\r
1462 \r
1463 bool CLogDlg::IsSelectionContinuous()\r
1464 {\r
1465         if ( m_LogList.GetSelectedCount()==1 )\r
1466         {\r
1467                 // if only one revision is selected, the selection is of course\r
1468                 // continuous\r
1469                 return true;\r
1470         }\r
1471 \r
1472         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1473         bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());\r
1474         if (bContinuous)\r
1475         {\r
1476                 int itemindex = m_LogList.GetNextSelectedItem(pos);\r
1477                 while (pos)\r
1478                 {\r
1479                         int nextindex = m_LogList.GetNextSelectedItem(pos);\r
1480                         if (nextindex - itemindex > 1)\r
1481                         {\r
1482                                 bContinuous = false;\r
1483                                 break;\r
1484                         }\r
1485                         itemindex = nextindex;\r
1486                 }\r
1487         }\r
1488         return bContinuous;\r
1489 }\r
1490 \r
1491 LRESULT CLogDlg::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)\r
1492 {\r
1493 #if 0\r
1494     ASSERT(m_pFindDialog != NULL);\r
1495 \r
1496     if (m_pFindDialog->IsTerminating())\r
1497     {\r
1498             // invalidate the handle identifying the dialog box.\r
1499         m_pFindDialog = NULL;\r
1500         return 0;\r
1501     }\r
1502 \r
1503     if(m_pFindDialog->FindNext())\r
1504     {\r
1505         //read data from dialog\r
1506         CString FindText = m_pFindDialog->GetFindString();\r
1507         bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);\r
1508                 bool bFound = false;\r
1509                 tr1::wregex pat;\r
1510                 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);\r
1511 \r
1512                 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;\r
1513 \r
1514                 int i;\r
1515                 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)\r
1516                 {\r
1517                         if (bRegex)\r
1518                         {\r
1519                                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));\r
1520 \r
1521                                 if (regex_search(wstring((LPCTSTR)pLogEntry->sMessage), pat, flags))\r
1522                                 {\r
1523                                         bFound = true;\r
1524                                         break;\r
1525                                 }\r
1526                                 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;\r
1527                                 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)\r
1528                                 {\r
1529                                         LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
1530                                         if (regex_search(wstring((LPCTSTR)cpath->sCopyFromPath), pat, flags))\r
1531                                         {\r
1532                                                 bFound = true;\r
1533                                                 --i;\r
1534                                                 break;\r
1535                                         }\r
1536                                         if (regex_search(wstring((LPCTSTR)cpath->sPath), pat, flags))\r
1537                                         {\r
1538                                                 bFound = true;\r
1539                                                 --i;\r
1540                                                 break;\r
1541                                         }\r
1542                                 }\r
1543                         }\r
1544                         else\r
1545                         {\r
1546                                 if (bMatchCase)\r
1547                                 {\r
1548                                         if (m_logEntries[i]->sMessage.Find(FindText) >= 0)\r
1549                                         {\r
1550                                                 bFound = true;\r
1551                                                 break;\r
1552                                         }\r
1553                                         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));\r
1554                                         LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;\r
1555                                         for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)\r
1556                                         {\r
1557                                                 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
1558                                                 if (cpath->sCopyFromPath.Find(FindText)>=0)\r
1559                                                 {\r
1560                                                         bFound = true;\r
1561                                                         --i;\r
1562                                                         break;\r
1563                                                 }\r
1564                                                 if (cpath->sPath.Find(FindText)>=0)\r
1565                                                 {\r
1566                                                         bFound = true;\r
1567                                                         --i;\r
1568                                                         break;\r
1569                                                 }\r
1570                                         }\r
1571                                 }\r
1572                                 else\r
1573                                 {\r
1574                                     PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));\r
1575                                         CString msg = pLogEntry->sMessage;\r
1576                                         msg = msg.MakeLower();\r
1577                                         CString find = FindText.MakeLower();\r
1578                                         if (msg.Find(find) >= 0)\r
1579                                         {\r
1580                                                 bFound = TRUE;\r
1581                                                 break;\r
1582                                         }\r
1583                                         LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;\r
1584                                         for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)\r
1585                                         {\r
1586                                                 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
1587                                                 CString lowerpath = cpath->sCopyFromPath;\r
1588                                                 lowerpath.MakeLower();\r
1589                                                 if (lowerpath.Find(find)>=0)\r
1590                                                 {\r
1591                                                         bFound = TRUE;\r
1592                                                         --i;\r
1593                                                         break;\r
1594                                                 }\r
1595                                                 lowerpath = cpath->sPath;\r
1596                                                 lowerpath.MakeLower();\r
1597                                                 if (lowerpath.Find(find)>=0)\r
1598                                                 {\r
1599                                                         bFound = TRUE;\r
1600                                                         --i;\r
1601                                                         break;\r
1602                                                 }\r
1603                                         }\r
1604                                 } \r
1605                         }\r
1606                 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)\r
1607                 if (bFound)\r
1608                 {\r
1609                         this->m_nSearchIndex = (i+1);\r
1610                         m_LogList.EnsureVisible(i, FALSE);\r
1611                         m_LogList.SetItemState(m_LogList.GetSelectionMark(), 0, LVIS_SELECTED);\r
1612                         m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);\r
1613                         m_LogList.SetSelectionMark(i);\r
1614                         FillLogMessageCtrl();\r
1615                         UpdateData(FALSE);\r
1616                         m_nSearchIndex++;\r
1617                         if (m_nSearchIndex >= m_arShownList.GetCount())\r
1618                                 m_nSearchIndex = (int)m_arShownList.GetCount()-1;\r
1619                 }\r
1620     } // if(m_pFindDialog->FindNext()) \r
1621         UpdateLogInfoLabel();\r
1622 #endif\r
1623     return 0;\r
1624 }\r
1625 \r
1626 void CLogDlg::OnOK()\r
1627 {\r
1628 #if 0 \r
1629         // since the log dialog is also used to select revisions for other\r
1630         // dialogs, we have to do some work before closing this dialog\r
1631         if (GetFocus() != GetDlgItem(IDOK))\r
1632                 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter\r
1633         if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))\r
1634                 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.\r
1635 \r
1636         CString temp;\r
1637         CString buttontext;\r
1638         GetDlgItemText(IDOK, buttontext);\r
1639         temp.LoadString(IDS_MSGBOX_CANCEL);\r
1640         if (temp.Compare(buttontext) != 0)\r
1641                 __super::OnOK();        // only exit if the button text matches, and that will match only if the thread isn't running anymore\r
1642         m_bCancelled = TRUE;\r
1643         m_selectedRevs.Clear();\r
1644         m_selectedRevsOneRange.Clear();\r
1645         if (m_pNotifyWindow)\r
1646         {\r
1647                 int selIndex = m_LogList.GetSelectionMark();\r
1648                 if (selIndex >= 0)\r
1649                 {       \r
1650                     PLOGENTRYDATA pLogEntry = NULL;\r
1651                         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1652                         pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1653                         m_selectedRevs.AddRevision(pLogEntry->Rev);\r
1654                         git_revnum_t lowerRev = pLogEntry->Rev;\r
1655                         git_revnum_t higherRev = lowerRev;\r
1656                         while (pos)\r
1657                         {\r
1658                             pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1659                                 git_revnum_t rev = pLogEntry->Rev;\r
1660                                 m_selectedRevs.AddRevision(pLogEntry->Rev);\r
1661                                 if (lowerRev > rev)\r
1662                                         lowerRev = rev;\r
1663                                 if (higherRev < rev)\r
1664                                         higherRev = rev;\r
1665                         }\r
1666                         if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())\r
1667                         {\r
1668                                 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);\r
1669                         }\r
1670                         BOOL bSentMessage = FALSE;\r
1671                         if (m_LogList.GetSelectedCount() == 1)\r
1672                         {\r
1673                                 // if only one revision is selected, check if the path/url with which the dialog was started\r
1674                                 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.\r
1675                                 // if it was copied, use the copy from revision as lowerRev\r
1676                                 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))\r
1677                                 {\r
1678                                         CString sUrl = m_path.GetGitPathString();\r
1679                                         if (!m_path.IsUrl())\r
1680                                         {\r
1681                                                 sUrl = GetURLFromPath(m_path);\r
1682                                         }\r
1683                                         sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());\r
1684                                         for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)\r
1685                                         {\r
1686                                                 LogChangedPath * pData = pLogEntry->pArChangedPaths->GetAt(cp);\r
1687                                                 if (pData)\r
1688                                                 {\r
1689                                                         if (sUrl.Compare(pData->sPath) == 0)\r
1690                                                         {\r
1691                                                                 if (!pData->sCopyFromPath.IsEmpty())\r
1692                                                                 {\r
1693                                                                         lowerRev = pData->lCopyFromRev;\r
1694                                                                         m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);\r
1695                                                                         m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);\r
1696                                                                         m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);\r
1697                                                                         bSentMessage = TRUE;\r
1698                                                                 }\r
1699                                                         }\r
1700                                                 }\r
1701                                         }\r
1702                                 }\r
1703                         }\r
1704                         if ( !bSentMessage )\r
1705                         {\r
1706                                 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);\r
1707                                 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);\r
1708                                 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);\r
1709                                 if (m_selectedRevsOneRange.GetCount())\r
1710                                         m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);\r
1711                         }\r
1712                 }\r
1713         }\r
1714         UpdateData();\r
1715         if (m_bSaveStrict)\r
1716                 m_regLastStrict = m_bStrict;\r
1717         CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry"));\r
1718         reg = m_btnShow.GetCurrentEntry();\r
1719         SaveSplitterPos();\r
1720 #endif \r
1721 }\r
1722 \r
1723 void CLogDlg::OnNMDblclkChangedFileList(NMHDR * /*pNMHDR*/, LRESULT *pResult)\r
1724 {\r
1725         // a double click on an entry in the changed-files list has happened\r
1726         *pResult = 0;\r
1727 \r
1728         DiffSelectedFile();\r
1729 }\r
1730 \r
1731 void CLogDlg::DiffSelectedFile()\r
1732 {\r
1733 #if 0\r
1734         if (m_bThreadRunning)\r
1735                 return;\r
1736         UpdateLogInfoLabel();\r
1737         INT_PTR selIndex = m_ChangedFileListCtrl.GetSelectionMark();\r
1738         if (selIndex < 0)\r
1739                 return;\r
1740         if (m_ChangedFileListCtrl.GetSelectedCount() == 0)\r
1741                 return;\r
1742         // find out if there's an entry selected in the log list\r
1743         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1744         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1745         git_revnum_t rev1 = pLogEntry->Rev;\r
1746         git_revnum_t rev2 = rev1;\r
1747         if (pos)\r
1748         {\r
1749                 while (pos)\r
1750                 {\r
1751                         // there's at least a second entry selected in the log list: several revisions selected!\r
1752                         pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1753                         if (pLogEntry)\r
1754                         {\r
1755                                 rev1 = max(rev1,(long)pLogEntry->Rev);\r
1756                                 rev2 = min(rev2,(long)pLogEntry->Rev);\r
1757                         }\r
1758                 }\r
1759                 rev2--;\r
1760                 // now we have both revisions selected in the log list, so we can do a diff of the selected\r
1761                 // entry in the changed files list with these two revisions.\r
1762                 DoDiffFromLog(selIndex, rev1, rev2, false, false);\r
1763         }\r
1764         else\r
1765         {\r
1766                 rev2 = rev1-1;\r
1767                 // nothing or only one revision selected in the log list\r
1768                 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);\r
1769 \r
1770                 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)\r
1771                 {\r
1772                         // some items are hidden! So find out which item the user really clicked on\r
1773                         INT_PTR selRealIndex = -1;\r
1774                         for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)\r
1775                         {\r
1776                                 if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)\r
1777                                         selRealIndex++;\r
1778                                 if (selRealIndex == selIndex)\r
1779                                 {\r
1780                                         selIndex = hiddenindex;\r
1781                                         changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);\r
1782                                         break;\r
1783                                 }\r
1784                         }\r
1785                 }\r
1786 \r
1787                 if (IsDiffPossible(changedpath, rev1))\r
1788                 {\r
1789                         // diffs with renamed files are possible\r
1790                         if ((changedpath)&&(!changedpath->sCopyFromPath.IsEmpty()))\r
1791                                 rev2 = changedpath->lCopyFromRev;\r
1792                         else\r
1793                         {\r
1794                                 // if the path was modified but the parent path was 'added with history'\r
1795                                 // then we have to use the copy from revision of the parent path\r
1796                                 CTGitPath cpath = CTGitPath(changedpath->sPath);\r
1797                                 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)\r
1798                                 {\r
1799                                         CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->GetAt(flist)->sPath);\r
1800                                         if (p.IsAncestorOf(cpath))\r
1801                                         {\r
1802                                                 if (!pLogEntry->pArChangedPaths->GetAt(flist)->sCopyFromPath.IsEmpty())\r
1803                                                         rev2 = pLogEntry->pArChangedPaths->GetAt(flist)->lCopyFromRev;\r
1804                                         }\r
1805                                 }\r
1806                         }\r
1807                         DoDiffFromLog(selIndex, rev1, rev2, false, false);\r
1808                 }\r
1809                 else \r
1810                 {\r
1811                         CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));\r
1812                         CTGitPath tempfile2 = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));\r
1813                         GitRev r = rev1;\r
1814                         // deleted files must be opened from the revision before the deletion\r
1815                         if (changedpath->action == LOGACTIONS_DELETED)\r
1816                                 r = rev1-1;\r
1817                         m_bCancelled = false;\r
1818 \r
1819                         CProgressDlg progDlg;\r
1820                         progDlg.SetTitle(IDS_APPNAME);\r
1821                         progDlg.SetAnimation(IDR_DOWNLOAD);\r
1822                         CString sInfoLine;\r
1823                         sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)(m_sRepositoryRoot + changedpath->sPath), (LPCTSTR)r.ToString());\r
1824                         progDlg.SetLine(1, sInfoLine, true);\r
1825                         SetAndClearProgressInfo(&progDlg);\r
1826                         progDlg.ShowModeless(m_hWnd);\r
1827 \r
1828                         if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), r, r, tempfile))\r
1829                         {\r
1830                                 m_bCancelled = false;\r
1831                                 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), GitRev::REV_HEAD, r, tempfile))\r
1832                                 {\r
1833                                         progDlg.Stop();\r
1834                                         SetAndClearProgressInfo((HWND)NULL);\r
1835                                         CMessageBox::Show(m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
1836                                         return;\r
1837                                 }\r
1838                         }\r
1839                         progDlg.Stop();\r
1840                         SetAndClearProgressInfo((HWND)NULL);\r
1841 \r
1842                         CString sName1, sName2;\r
1843                         sName1.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1);\r
1844                         sName2.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1-1);\r
1845                         CAppUtils::DiffFlags flags;\r
1846                         flags.AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1847                         if (changedpath->action == LOGACTIONS_DELETED)\r
1848                                 CAppUtils::StartExtDiff(tempfile, tempfile2, sName2, sName1, flags);\r
1849                         else\r
1850                                 CAppUtils::StartExtDiff(tempfile2, tempfile, sName2, sName1, flags);\r
1851                 }\r
1852         }\r
1853 #endif \r
1854 }\r
1855 \r
1856 \r
1857 void CLogDlg::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)\r
1858 {\r
1859         // a double click on an entry in the revision list has happened\r
1860         *pResult = 0;\r
1861 \r
1862   if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))\r
1863           DiffSelectedRevWithPrevious();\r
1864 }\r
1865 \r
1866 void CLogDlg::DiffSelectedRevWithPrevious()\r
1867 {\r
1868 #if 0\r
1869         if (m_bThreadRunning)\r
1870                 return;\r
1871         UpdateLogInfoLabel();\r
1872         int selIndex = m_LogList.GetSelectionMark();\r
1873         if (selIndex < 0)\r
1874                 return;\r
1875         int selCount = m_LogList.GetSelectedCount();\r
1876         if (selCount != 1)\r
1877                 return;\r
1878 \r
1879         // Find selected entry in the log list\r
1880         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1881         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1882         long rev1 = pLogEntry->Rev;\r
1883         long rev2 = rev1-1;\r
1884         CTGitPath path = m_path;\r
1885 \r
1886         // See how many files under the relative root were changed in selected revision\r
1887         int nChanged = 0;\r
1888         LogChangedPath * changed = NULL;\r
1889         for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)\r
1890         {\r
1891                 LogChangedPath * cpath = pLogEntry->pArChangedPaths->GetAt(c);\r
1892                 if (cpath  &&  cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)\r
1893                 {\r
1894                         ++nChanged;\r
1895                         changed = cpath;\r
1896                 }\r
1897         }\r
1898 \r
1899         if (m_path.IsDirectory() && nChanged == 1) \r
1900         {\r
1901                 // We're looking at the log for a directory and only one file under dir was changed in the revision\r
1902                 // Do diff on that file instead of whole directory\r
1903                 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));\r
1904         } \r
1905 \r
1906         m_bCancelled = FALSE;\r
1907         DialogEnableWindow(IDOK, FALSE);\r
1908         SetPromptApp(&theApp);\r
1909         theApp.DoWaitCursor(1);\r
1910 \r
1911         if (PromptShown())\r
1912         {\r
1913                 GitDiff diff(this, m_hWnd, true);\r
1914                 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1915                 diff.SetHEADPeg(m_LogRevision);\r
1916                 diff.ShowCompare(path, rev2, path, rev1);\r
1917         }\r
1918         else\r
1919         {\r
1920                 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1921         }\r
1922 \r
1923         theApp.DoWaitCursor(-1);\r
1924         EnableOKButton();\r
1925 #endif\r
1926 }\r
1927 \r
1928 void CLogDlg::DoDiffFromLog(INT_PTR selIndex, git_revnum_t rev1, git_revnum_t rev2, bool blame, bool unified)\r
1929 {\r
1930 #if 0\r
1931         DialogEnableWindow(IDOK, FALSE);\r
1932         SetPromptApp(&theApp);\r
1933         theApp.DoWaitCursor(1);\r
1934         //get the filename\r
1935         CString filepath;\r
1936         if (Git::PathIsURL(m_path))\r
1937         {\r
1938                 filepath = m_path.GetGitPathString();\r
1939         }\r
1940         else\r
1941         {\r
1942                 filepath = GetURLFromPath(m_path);\r
1943                 if (filepath.IsEmpty())\r
1944                 {\r
1945                         theApp.DoWaitCursor(-1);\r
1946                         CString temp;\r
1947                         temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);\r
1948                         CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);\r
1949                         TRACE(_T("could not retrieve the URL of the file!\n"));\r
1950                         EnableOKButton();\r
1951                         theApp.DoWaitCursor(-11);\r
1952                         return;         //exit\r
1953                 }\r
1954         }\r
1955         m_bCancelled = FALSE;\r
1956         filepath = GetRepositoryRoot(CTGitPath(filepath));\r
1957 \r
1958         CString firstfile, secondfile;\r
1959         if (m_LogList.GetSelectedCount()==1)\r
1960         {\r
1961                 int s = m_LogList.GetSelectionMark();\r
1962                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(s));\r
1963                 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);\r
1964                 firstfile = changedpath->sPath;\r
1965                 secondfile = firstfile;\r
1966                 if ((rev2 == rev1-1)&&(changedpath->lCopyFromRev > 0)) // is it an added file with history?\r
1967                 {\r
1968                         secondfile = changedpath->sCopyFromPath;\r
1969                         rev2 = changedpath->lCopyFromRev;\r
1970                 }\r
1971         }\r
1972         else\r
1973         {\r
1974                 firstfile = m_currentChangedPathList[selIndex].GetGitPathString();\r
1975                 secondfile = firstfile;\r
1976         }\r
1977 \r
1978         firstfile = filepath + firstfile.Trim();\r
1979         secondfile = filepath + secondfile.Trim();\r
1980 \r
1981         GitDiff diff(this, this->m_hWnd, true);\r
1982         diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1983         diff.SetHEADPeg(m_LogRevision);\r
1984         if (unified)\r
1985         {\r
1986                 if (PromptShown())\r
1987                         diff.ShowUnifiedDiff(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1);\r
1988                 else\r
1989                         CAppUtils::StartShowUnifiedDiff(m_hWnd, CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), m_LogRevision);\r
1990         }\r
1991         else\r
1992         {\r
1993                 if (diff.ShowCompare(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), false, blame))\r
1994                 {\r
1995                         if (firstfile.Compare(secondfile)==0)\r
1996                         {\r
1997                                 git_revnum_t baseRev = 0;\r
1998                                 diff.DiffProps(CTGitPath(firstfile), rev2, rev1, baseRev);\r
1999                         }\r
2000                 }\r
2001         }\r
2002         theApp.DoWaitCursor(-1);\r
2003         EnableOKButton();\r
2004 #endif\r
2005 }\r
2006 \r
2007 BOOL CLogDlg::Open(bool bOpenWith,CString changedpath, git_revnum_t rev)\r
2008 {\r
2009 #if 0\r
2010         DialogEnableWindow(IDOK, FALSE);\r
2011         SetPromptApp(&theApp);\r
2012         theApp.DoWaitCursor(1);\r
2013         CString filepath;\r
2014         if (Git::PathIsURL(m_path))\r
2015         {\r
2016                 filepath = m_path.GetGitPathString();\r
2017         }\r
2018         else\r
2019         {\r
2020                 filepath = GetURLFromPath(m_path);\r
2021                 if (filepath.IsEmpty())\r
2022                 {\r
2023                         theApp.DoWaitCursor(-1);\r
2024                         CString temp;\r
2025                         temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);\r
2026                         CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);\r
2027                         TRACE(_T("could not retrieve the URL of the file!\n"));\r
2028                         EnableOKButton();\r
2029                         return FALSE;\r
2030                 }\r
2031         }\r
2032         m_bCancelled = false;\r
2033         filepath = GetRepositoryRoot(CTGitPath(filepath));\r
2034         filepath += changedpath;\r
2035 \r
2036         CProgressDlg progDlg;\r
2037         progDlg.SetTitle(IDS_APPNAME);\r
2038         progDlg.SetAnimation(IDR_DOWNLOAD);\r
2039         CString sInfoLine;\r
2040         sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)GitRev(rev).ToString());\r
2041         progDlg.SetLine(1, sInfoLine, true);\r
2042         SetAndClearProgressInfo(&progDlg);\r
2043         progDlg.ShowModeless(m_hWnd);\r
2044 \r
2045         CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(filepath), rev);\r
2046         m_bCancelled = false;\r
2047         if (!Cat(CTGitPath(filepath), GitRev(rev), rev, tempfile))\r
2048         {\r
2049                 progDlg.Stop();\r
2050                 SetAndClearProgressInfo((HWND)NULL);\r
2051                 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
2052                 EnableOKButton();\r
2053                 theApp.DoWaitCursor(-1);\r
2054                 return FALSE;\r
2055         }\r
2056         progDlg.Stop();\r
2057         SetAndClearProgressInfo((HWND)NULL);\r
2058         SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);\r
2059         if (!bOpenWith)\r
2060         {\r
2061                 int ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);\r
2062                 if (ret <= HINSTANCE_ERROR)\r
2063                         bOpenWith = true;\r
2064         }\r
2065         if (bOpenWith)\r
2066         {\r
2067                 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");\r
2068                 cmd += tempfile.GetWinPathString() + _T(" ");\r
2069                 CAppUtils::LaunchApplication(cmd, NULL, false);\r
2070         }\r
2071         EnableOKButton();\r
2072         theApp.DoWaitCursor(-1);\r
2073 #endif\r
2074         return TRUE;\r
2075 }\r
2076 \r
2077 void CLogDlg::EditAuthor(const CLogDataVector& logs)\r
2078 {\r
2079 #if 0\r
2080         CString url;\r
2081         CString name;\r
2082         if (logs.size() == 0)\r
2083                 return;\r
2084         DialogEnableWindow(IDOK, FALSE);\r
2085         SetPromptApp(&theApp);\r
2086         theApp.DoWaitCursor(1);\r
2087         if (Git::PathIsURL(m_path))\r
2088                 url = m_path.GetGitPathString();\r
2089         else\r
2090         {\r
2091                 url = GetURLFromPath(m_path);\r
2092         }\r
2093         name = Git_PROP_REVISION_AUTHOR;\r
2094 \r
2095         CString value = RevPropertyGet(name, CTGitPath(url), logs[0]->Rev);\r
2096         CString sOldValue = value;\r
2097         value.Replace(_T("\n"), _T("\r\n"));\r
2098         CInputDlg dlg(this);\r
2099         dlg.m_sHintText.LoadString(IDS_LOG_AUTHOR);\r
2100         dlg.m_sInputText = value;\r
2101         dlg.m_sTitle.LoadString(IDS_LOG_AUTHOREDITTITLE);\r
2102         dlg.m_pProjectProperties = &m_ProjectProperties;\r
2103         dlg.m_bUseLogWidth = false;\r
2104         if (dlg.DoModal() == IDOK)\r
2105         {\r
2106                 dlg.m_sInputText.Replace(_T("\r"), _T(""));\r
2107 \r
2108                 LogCache::CCachedLogInfo* toUpdate \r
2109                         = GetLogCache (CTGitPath (m_sRepositoryRoot));\r
2110 \r
2111                 CProgressDlg progDlg;\r
2112                 progDlg.SetTitle(IDS_APPNAME);\r
2113                 progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));\r
2114                 progDlg.SetTime(true);\r
2115                 progDlg.SetShowProgressBar(true);\r
2116                 progDlg.ShowModeless(m_hWnd);\r
2117                 for (DWORD i=0; i<logs.size(); ++i)\r
2118                 {\r
2119                         if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), logs[i]->Rev))\r
2120                         {\r
2121                                 progDlg.Stop();\r
2122                                 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
2123                                 break;\r
2124                         }\r
2125                         else\r
2126                         {\r
2127 \r
2128                                 logs[i]->sAuthor = dlg.m_sInputText;\r
2129                                 m_LogList.Invalidate();\r
2130 \r
2131                                 // update the log cache \r
2132 \r
2133                                 if (toUpdate != NULL)\r
2134                                 {\r
2135                                         // log caching is active\r
2136 \r
2137                                         LogCache::CCachedLogInfo newInfo;\r
2138                                         newInfo.Insert ( logs[i]->Rev\r
2139                                                 , (const char*) CUnicodeUtils::GetUTF8 (logs[i]->sAuthor)\r
2140                                                 , ""\r
2141                                                 , 0\r
2142                                                 , LogCache::CRevisionInfoContainer::HAS_AUTHOR);\r
2143 \r
2144                                         toUpdate->Update (newInfo);\r
2145                                 }\r
2146                         }\r
2147                         progDlg.SetProgress64(i, logs.size());\r
2148                 }\r
2149                 progDlg.Stop();\r
2150         }\r
2151         theApp.DoWaitCursor(-1);\r
2152         EnableOKButton();\r
2153 #endif\r
2154 }\r
2155 \r
2156 void CLogDlg::EditLogMessage(int index)\r
2157 {\r
2158 #if 0\r
2159         CString url;\r
2160         CString name;\r
2161         DialogEnableWindow(IDOK, FALSE);\r
2162         SetPromptApp(&theApp);\r
2163         theApp.DoWaitCursor(1);\r
2164         if (Git::PathIsURL(m_path))\r
2165                 url = m_path.GetGitPathString();\r
2166         else\r
2167         {\r
2168                 url = GetURLFromPath(m_path);\r
2169         }\r
2170         name = Git_PROP_REVISION_LOG;\r
2171 \r
2172         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(index));\r
2173         m_bCancelled = FALSE;\r
2174         CString value = RevPropertyGet(name, CTGitPath(url), pLogEntry->Rev);\r
2175         CString sOldValue = value;\r
2176         value.Replace(_T("\n"), _T("\r\n"));\r
2177         CInputDlg dlg(this);\r
2178         dlg.m_sHintText.LoadString(IDS_LOG_MESSAGE);\r
2179         dlg.m_sInputText = value;\r
2180         dlg.m_sTitle.LoadString(IDS_LOG_MESSAGEEDITTITLE);\r
2181         dlg.m_pProjectProperties = &m_ProjectProperties;\r
2182         dlg.m_bUseLogWidth = true;\r
2183         if (dlg.DoModal() == IDOK)\r
2184         {\r
2185                 dlg.m_sInputText.Replace(_T("\r"), _T(""));\r
2186                 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), pLogEntry->Rev))\r
2187                 {\r
2188                         CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
2189                 }\r
2190                 else\r
2191                 {\r
2192                         pLogEntry->sShortMessage = MakeShortMessage(dlg.m_sInputText);\r
2193                         // split multi line log entries and concatenate them\r
2194                         // again but this time with \r\n as line separators\r
2195                         // so that the edit control recognizes them\r
2196                         if (dlg.m_sInputText.GetLength()>0)\r
2197                         {\r
2198                                 m_sMessageBuf = dlg.m_sInputText;\r
2199                                 dlg.m_sInputText.Replace(_T("\n\r"), _T("\n"));\r
2200                                 dlg.m_sInputText.Replace(_T("\r\n"), _T("\n"));\r
2201                                 if (dlg.m_sInputText.Right(1).Compare(_T("\n"))==0)\r
2202                                         dlg.m_sInputText = dlg.m_sInputText.Left(dlg.m_sInputText.GetLength()-1);\r
2203                         } \r
2204                         else\r
2205                                 dlg.m_sInputText.Empty();\r
2206                         pLogEntry->sMessage = dlg.m_sInputText;\r
2207                         pLogEntry->sBugIDs = m_ProjectProperties.FindBugID(dlg.m_sInputText);\r
2208                         CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);\r
2209                         pMsgView->SetWindowText(_T(" "));\r
2210                         pMsgView->SetWindowText(dlg.m_sInputText);\r
2211                         m_ProjectProperties.FindBugID(dlg.m_sInputText, pMsgView);\r
2212                         m_LogList.Invalidate();\r
2213         \r
2214             // update the log cache \r
2215 \r
2216             LogCache::CCachedLogInfo* toUpdate \r
2217                 = GetLogCache (CTGitPath (m_sRepositoryRoot));\r
2218             if (toUpdate != NULL)\r
2219             {\r
2220                 // log caching is active\r
2221 \r
2222                 LogCache::CCachedLogInfo newInfo;\r
2223                 newInfo.Insert ( pLogEntry->Rev\r
2224                                , ""\r
2225                                , (const char*) CUnicodeUtils::GetUTF8 (pLogEntry->sMessage)\r
2226                                , 0\r
2227                                , LogCache::CRevisionInfoContainer::HAS_COMMENT);\r
2228 \r
2229                 toUpdate->Update (newInfo);\r
2230             }\r
2231         }\r
2232         }\r
2233         theApp.DoWaitCursor(-1);\r
2234         EnableOKButton();\r
2235 #endif\r
2236 }\r
2237 \r
2238 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)\r
2239 {\r
2240         // Skip Ctrl-C when copying text out of the log message or search filter\r
2241         BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );\r
2242         if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')\r
2243         {\r
2244                 if (GetFocus()==GetDlgItem(IDC_LOGLIST))\r
2245                 {\r
2246                         if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))\r
2247                         {\r
2248                                 DiffSelectedRevWithPrevious();\r
2249                                 return TRUE;\r
2250                         }\r
2251                 }\r
2252                 if (GetFocus()==GetDlgItem(IDC_LOGMSG))\r
2253                 {\r
2254                         DiffSelectedFile();\r
2255                         return TRUE;\r
2256                 }\r
2257         }\r
2258         if (m_hAccel && !bSkipAccelerator)\r
2259         {\r
2260                 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);\r
2261                 if (ret)\r
2262                         return TRUE;\r
2263         }\r
2264         \r
2265         m_tooltips.RelayEvent(pMsg);\r
2266         return __super::PreTranslateMessage(pMsg);\r
2267 }\r
2268 \r
2269 BOOL CLogDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)\r
2270 {\r
2271         if (m_bThreadRunning)\r
2272         {\r
2273                 // only show the wait cursor over the list control\r
2274                 if ((pWnd)&&\r
2275                         ((pWnd == GetDlgItem(IDC_LOGLIST))||\r
2276                         (pWnd == GetDlgItem(IDC_MSGVIEW))||\r
2277                         (pWnd == GetDlgItem(IDC_LOGMSG))))\r
2278                 {\r
2279                         HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));\r
2280                         SetCursor(hCur);\r
2281                         return TRUE;\r
2282                 }\r
2283         }\r
2284         if ((pWnd) && (pWnd == GetDlgItem(IDC_MSGVIEW)))\r
2285                 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);\r
2286 \r
2287         HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));\r
2288         SetCursor(hCur);\r
2289         return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);\r
2290 }\r
2291 \r
2292 void CLogDlg::OnBnClickedHelp()\r
2293 {\r
2294         OnHelp();\r
2295 }\r
2296 \r
2297 void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
2298 {\r
2299         LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);\r
2300         *pResult = 0;\r
2301         if (m_bThreadRunning)\r
2302                 return;\r
2303         if (pNMLV->iItem >= 0)\r
2304         {\r
2305                 m_nSearchIndex = pNMLV->iItem;\r
2306                 if (pNMLV->iSubItem != 0)\r
2307                         return;\r
2308                 if ((pNMLV->iItem == m_arShownList.GetCount())&&(m_bStrict)&&(m_bStrictStopped))\r
2309                 {\r
2310                         // remove the selected state\r
2311                         if (pNMLV->uChanged & LVIF_STATE)\r
2312                         {\r
2313                                 m_LogList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);\r
2314                                 FillLogMessageCtrl();\r
2315                                 UpdateData(FALSE);\r
2316                                 UpdateLogInfoLabel();\r
2317                         }\r
2318                         return;\r
2319                 }\r
2320                 if (pNMLV->uChanged & LVIF_STATE)\r
2321                 {\r
2322                         FillLogMessageCtrl();\r
2323                         UpdateData(FALSE);\r
2324                 }\r
2325         }\r
2326         else\r
2327         {\r
2328                 FillLogMessageCtrl();\r
2329                 UpdateData(FALSE);\r
2330         }\r
2331         EnableOKButton();\r
2332         UpdateLogInfoLabel();\r
2333 }\r
2334 \r
2335 void CLogDlg::OnEnLinkMsgview(NMHDR *pNMHDR, LRESULT *pResult)\r
2336 {\r
2337         ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);\r
2338         if (pEnLink->msg == WM_LBUTTONUP)\r
2339         {\r
2340                 CString url, msg;\r
2341                 GetDlgItemText(IDC_MSGVIEW, msg);\r
2342                 msg.Replace(_T("\r\n"), _T("\n"));\r
2343                 url = msg.Mid(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax-pEnLink->chrg.cpMin);\r
2344                 if (!::PathIsURL(url))\r
2345                 {\r
2346                         url = m_ProjectProperties.GetBugIDUrl(url);\r
2347                         url = GetAbsoluteUrlFromRelativeUrl(url);\r
2348                 }\r
2349                 if (!url.IsEmpty())\r
2350                         ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);\r
2351         }\r
2352         *pResult = 0;\r
2353 }\r
2354 \r
2355 void CLogDlg::OnBnClickedStatbutton()\r
2356 {\r
2357 #if 0\r
2358         if (m_bThreadRunning)\r
2359                 return;\r
2360         if (m_arShownList.IsEmpty())\r
2361                 return;         // nothing is shown, so no statistics.\r
2362         // the statistics dialog expects the log entries to be sorted by date\r
2363         SortByColumn(3, false);\r
2364         CPtrArray shownlist;\r
2365         RecalculateShownList(&shownlist);\r
2366         // create arrays which are aware of the current filter\r
2367         CStringArray m_arAuthorsFiltered;\r
2368         CDWordArray m_arDatesFiltered;\r
2369         CDWordArray m_arFileChangesFiltered;\r
2370         for (INT_PTR i=0; i<shownlist.GetCount(); ++i)\r
2371         {\r
2372                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(shownlist.GetAt(i));\r
2373                 CString strAuthor = pLogEntry->sAuthor;\r
2374                 if ( strAuthor.IsEmpty() )\r
2375                 {\r
2376                         strAuthor.LoadString(IDS_STATGRAPH_EMPTYAUTHOR);\r
2377                 }\r
2378                 m_arAuthorsFiltered.Add(strAuthor);\r
2379                 m_arDatesFiltered.Add(static_cast<DWORD>(pLogEntry->tmDate));\r
2380                 m_arFileChangesFiltered.Add(pLogEntry->dwFileChanges);\r
2381         }\r
2382         CStatGraphDlg dlg;\r
2383         dlg.m_parAuthors = &m_arAuthorsFiltered;\r
2384         dlg.m_parDates = &m_arDatesFiltered;\r
2385         dlg.m_parFileChanges = &m_arFileChangesFiltered;\r
2386         dlg.m_path = m_path;\r
2387         dlg.DoModal();\r
2388         // restore the previous sorting\r
2389         SortByColumn(m_nSortColumn, m_bAscending);\r
2390         OnTimer(LOGFILTER_TIMER);\r
2391 #endif\r
2392 }\r
2393 \r
2394 void CLogDlg::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
2395 {\r
2396 #if 0\r
2397         NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );\r
2398         // Take the default processing unless we set this to something else below.\r
2399         *pResult = CDRF_DODEFAULT;\r
2400 \r
2401         if (m_bNoDispUpdates)\r
2402                 return;\r
2403 \r
2404         switch (pLVCD->nmcd.dwDrawStage)\r
2405         {\r
2406         case CDDS_PREPAINT:\r
2407                 {\r
2408                         *pResult = CDRF_NOTIFYITEMDRAW;\r
2409                         return;\r
2410                 }\r
2411                 break;\r
2412         case CDDS_ITEMPREPAINT:\r
2413                 {\r
2414                         // This is the prepaint stage for an item. Here's where we set the\r
2415                         // item's text color. \r
2416                         \r
2417                         // Tell Windows to send draw notifications for each subitem.\r
2418                         *pResult = CDRF_NOTIFYSUBITEMDRAW;\r
2419 \r
2420                         COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);\r
2421 \r
2422                         if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
2423                         {\r
2424                                 PLOGENTRYDATA data = (PLOGENTRYDATA)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);\r
2425                                 if (data)\r
2426                                 {\r
2427                                         if (data->bCopiedSelf)\r
2428                                         {\r
2429                                                 // only change the background color if the item is not 'hot' (on vista with themes enabled)\r
2430                                                 if (!theme.IsAppThemed() || !m_bVista || ((pLVCD->nmcd.uItemState & CDIS_HOT)==0))\r
2431                                                         pLVCD->clrTextBk = GetSysColor(COLOR_MENU);\r
2432                                         }\r
2433                                         if (data->bCopies)\r
2434                                                 crText = m_Colors.GetColor(CColors::Modified);\r
2435                                         if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))\r
2436                                                 crText = GetSysColor(COLOR_GRAYTEXT);\r
2437                                         if (data->Rev == m_wcRev)\r
2438                                         {\r
2439                                                 SelectObject(pLVCD->nmcd.hdc, m_boldFont);\r
2440                                                 // We changed the font, so we're returning CDRF_NEWFONT. This\r
2441                                                 // tells the control to recalculate the extent of the text.\r
2442                                                 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;\r
2443                                         }\r
2444                                 }\r
2445                         }\r
2446                         if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
2447                         {\r
2448                                 if (m_bStrictStopped)\r
2449                                         crText = GetSysColor(COLOR_GRAYTEXT);\r
2450                         }\r
2451                         // Store the color back in the NMLVCUSTOMDRAW struct.\r
2452                         pLVCD->clrText = crText;\r
2453                         return;\r
2454                 }\r
2455                 break;\r
2456         case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:\r
2457                 {\r
2458                         if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))\r
2459                         {\r
2460                                 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);\r
2461                         }\r
2462                         if (pLVCD->iSubItem == 1)\r
2463                         {\r
2464                                 *pResult = CDRF_DODEFAULT;\r
2465 \r
2466                                 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
2467                                         return;\r
2468 \r
2469                                 int             nIcons = 0;\r
2470                                 int             iconwidth = ::GetSystemMetrics(SM_CXSMICON);\r
2471                                 int             iconheight = ::GetSystemMetrics(SM_CYSMICON);\r
2472 \r
2473                                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec));\r
2474 \r
2475                                 // Get the selected state of the\r
2476                                 // item being drawn.\r
2477                                 LVITEM   rItem;\r
2478                                 SecureZeroMemory(&rItem, sizeof(LVITEM));\r
2479                                 rItem.mask  = LVIF_STATE;\r
2480                                 rItem.iItem = pLVCD->nmcd.dwItemSpec;\r
2481                                 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;\r
2482                                 m_LogList.GetItem(&rItem);\r
2483 \r
2484                                 CRect rect;\r
2485                                 m_LogList.GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);\r
2486 \r
2487                                 // Fill the background\r
2488                                 if (theme.IsAppThemed() && m_bVista)\r
2489                                 {\r
2490                                         theme.Open(m_hWnd, L"Explorer");\r
2491                                         int state = LISS_NORMAL;\r
2492                                         if (rItem.state & LVIS_SELECTED)\r
2493                                         {\r
2494                                                 if (::GetFocus() == m_LogList.m_hWnd)\r
2495                                                         state |= LISS_SELECTED;\r
2496                                                 else\r
2497                                                         state |= LISS_SELECTEDNOTFOCUS;\r
2498                                         }\r
2499                                         else\r
2500                                         {\r
2501                                                 if (pLogEntry->bCopiedSelf)\r
2502                                                 {\r
2503                                                         // unfortunately, the pLVCD->nmcd.uItemState does not contain valid\r
2504                                                         // information at this drawing stage. But we can check the whether the\r
2505                                                         // previous stage changed the background color of the item\r
2506                                                         if (pLVCD->clrTextBk == GetSysColor(COLOR_MENU))\r
2507                                                         {\r
2508                                                                 HBRUSH brush;\r
2509                                                                 brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));\r
2510                                                                 if (brush)\r
2511                                                                 {\r
2512                                                                         ::FillRect(pLVCD->nmcd.hdc, &rect, brush);\r
2513                                                                         ::DeleteObject(brush);\r
2514                                                                 }\r
2515                                                         }\r
2516                                                 }\r
2517                                         }\r
2518 \r
2519                                         if (theme.IsBackgroundPartiallyTransparent(LVP_LISTDETAIL, state))\r
2520                                                 theme.DrawParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);\r
2521 \r
2522                                         theme.DrawBackground(pLVCD->nmcd.hdc, LVP_LISTDETAIL, state, &rect, NULL);\r
2523                                 }\r
2524                                 else\r
2525                                 {\r
2526                                         HBRUSH brush;\r
2527                                         if (rItem.state & LVIS_SELECTED)\r
2528                                         {\r
2529                                                 if (::GetFocus() == m_LogList.m_hWnd)\r
2530                                                         brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));\r
2531                                                 else\r
2532                                                         brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));\r
2533                                         }\r
2534                                         else\r
2535                                         {\r
2536                                                 if (pLogEntry->bCopiedSelf)\r
2537                                                         brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));\r
2538                                                 else\r
2539                                                         brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));\r
2540                                         }\r
2541                                         if (brush == NULL)\r
2542                                                 return;\r
2543 \r
2544                                         ::FillRect(pLVCD->nmcd.hdc, &rect, brush);\r
2545                                         ::DeleteObject(brush);\r
2546                                 }\r
2547 \r
2548                                 // Draw the icon(s) into the compatible DC\r
2549                                 if (pLogEntry->actions & LOGACTIONS_MODIFIED)\r
2550                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
2551                                 nIcons++;\r
2552 \r
2553                                 if (pLogEntry->actions & LOGACTIONS_ADDED)\r
2554                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
2555                                 nIcons++;\r
2556 \r
2557                                 if (pLogEntry->actions & LOGACTIONS_DELETED)\r
2558                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
2559                                 nIcons++;\r
2560 \r
2561                                 if (pLogEntry->actions & LOGACTIONS_REPLACED)\r
2562                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
2563                                 nIcons++;\r
2564 \r
2565                                 *pResult = CDRF_SKIPDEFAULT;\r
2566                                 return;\r
2567                         }\r
2568                 }\r
2569                 break;\r
2570         }\r
2571         *pResult = CDRF_DODEFAULT;\r
2572 #endif\r
2573 }\r
2574 void CLogDlg::OnNMCustomdrawChangedFileList(NMHDR *pNMHDR, LRESULT *pResult)\r
2575 {\r
2576 #if 0\r
2577         NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );\r
2578         // Take the default processing unless we set this to something else below.\r
2579         *pResult = CDRF_DODEFAULT;\r
2580 \r
2581         if (m_bNoDispUpdates)\r
2582                 return;\r
2583 \r
2584         // First thing - check the draw stage. If it's the control's prepaint\r
2585         // stage, then tell Windows we want messages for every item.\r
2586 \r
2587         if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )\r
2588         {\r
2589                 *pResult = CDRF_NOTIFYITEMDRAW;\r
2590         }\r
2591         else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )\r
2592         {\r
2593                 // This is the prepaint stage for an item. Here's where we set the\r
2594                 // item's text color. Our return value will tell Windows to draw the\r
2595                 // item itself, but it will use the new color we set here.\r
2596 \r
2597                 // Tell Windows to paint the control itself.\r
2598                 *pResult = CDRF_DODEFAULT;\r
2599 \r
2600                 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);\r
2601                 bool bGrayed = false;\r
2602                 if ((m_cHidePaths.GetState() & 0x0003)==BST_INDETERMINATE)\r
2603                 {\r
2604                         if ((m_currentChangedArray)&&((m_currentChangedArray->GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)))\r
2605                         {\r
2606                                 if (m_currentChangedArray->GetAt(pLVCD->nmcd.dwItemSpec)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)!=0)\r
2607                                 {\r
2608                                         crText = GetSysColor(COLOR_GRAYTEXT);\r
2609                                         bGrayed = true;\r
2610                                 }\r
2611                         }\r
2612                         else if (m_currentChangedPathList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
2613                         {\r
2614                                 if (m_currentChangedPathList[pLVCD->nmcd.dwItemSpec].GetGitPathString().Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)!=0)\r
2615                                 {\r
2616                                         crText = GetSysColor(COLOR_GRAYTEXT);\r
2617                                         bGrayed = true;\r
2618                                 }\r
2619                         }\r
2620                 }\r
2621 \r
2622                 if ((!bGrayed)&&(m_currentChangedArray)&&(m_currentChangedArray->GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec))\r
2623                 {\r
2624                         DWORD action = m_currentChangedArray->GetAt(pLVCD->nmcd.dwItemSpec)->action;\r
2625                         if (action == LOGACTIONS_MODIFIED)\r
2626                                 crText = m_Colors.GetColor(CColors::Modified);\r
2627                         if (action == LOGACTIONS_REPLACED)\r
2628                                 crText = m_Colors.GetColor(CColors::Deleted);\r
2629                         if (action == LOGACTIONS_ADDED)\r
2630                                 crText = m_Colors.GetColor(CColors::Added);\r
2631                         if (action == LOGACTIONS_DELETED)\r
2632                                 crText = m_Colors.GetColor(CColors::Deleted);\r
2633                 }\r
2634 \r
2635                 // Store the color back in the NMLVCUSTOMDRAW struct.\r
2636                 pLVCD->clrText = crText;\r
2637         }\r
2638 #endif\r
2639 }\r
2640 \r
2641 void CLogDlg::DoSizeV1(int delta)\r
2642 {\r
2643 \r
2644         RemoveAnchor(IDC_LOGLIST);\r
2645         RemoveAnchor(IDC_SPLITTERTOP);\r
2646         RemoveAnchor(IDC_MSGVIEW);\r
2647         RemoveAnchor(IDC_SPLITTERBOTTOM);\r
2648         RemoveAnchor(IDC_LOGMSG);\r
2649         CSplitterControl::ChangeHeight(&m_LogList, delta, CW_TOPALIGN);\r
2650         CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), -delta, CW_BOTTOMALIGN);\r
2651         AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);\r
2652         AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);\r
2653         AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);\r
2654         AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);\r
2655         AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);\r
2656         ArrangeLayout();\r
2657         AdjustMinSize();\r
2658         SetSplitterRange();\r
2659         m_LogList.Invalidate();\r
2660         GetDlgItem(IDC_MSGVIEW)->Invalidate();\r
2661 \r
2662 }\r
2663 \r
2664 void CLogDlg::DoSizeV2(int delta)\r
2665 {\r
2666 \r
2667         RemoveAnchor(IDC_LOGLIST);\r
2668         RemoveAnchor(IDC_SPLITTERTOP);\r
2669         RemoveAnchor(IDC_MSGVIEW);\r
2670         RemoveAnchor(IDC_SPLITTERBOTTOM);\r
2671         RemoveAnchor(IDC_LOGMSG);\r
2672         CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), delta, CW_TOPALIGN);\r
2673         CSplitterControl::ChangeHeight(&m_ChangedFileListCtrl, -delta, CW_BOTTOMALIGN);\r
2674         AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);\r
2675         AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);\r
2676         AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);\r
2677         AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);\r
2678         AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);\r
2679         ArrangeLayout();\r
2680         AdjustMinSize();\r
2681         SetSplitterRange();\r
2682         GetDlgItem(IDC_MSGVIEW)->Invalidate();\r
2683         m_ChangedFileListCtrl.Invalidate();\r
2684 \r
2685 }\r
2686 \r
2687 void CLogDlg::AdjustMinSize()\r
2688 {\r
2689         // adjust the minimum size of the dialog to prevent the resizing from\r
2690         // moving the list control too far down.\r
2691         CRect rcChgListView;\r
2692         m_ChangedFileListCtrl.GetClientRect(rcChgListView);\r
2693         CRect rcLogList;\r
2694         m_LogList.GetClientRect(rcLogList);\r
2695 \r
2696         SetMinTrackSize(CSize(m_DlgOrigRect.Width(), \r
2697                 m_DlgOrigRect.Height()-m_ChgOrigRect.Height()-m_LogListOrigRect.Height()-m_MsgViewOrigRect.Height()\r
2698                 +rcChgListView.Height()+rcLogList.Height()+60));\r
2699 }\r
2700 \r
2701 LRESULT CLogDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) \r
2702 {\r
2703         switch (message) {\r
2704         case WM_NOTIFY:\r
2705                 if (wParam == IDC_SPLITTERTOP)\r
2706                 { \r
2707                         SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;\r
2708                         DoSizeV1(pHdr->delta);\r
2709                 }\r
2710                 else if (wParam == IDC_SPLITTERBOTTOM)\r
2711                 { \r
2712                         SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;\r
2713                         DoSizeV2(pHdr->delta);\r
2714                 }\r
2715                 break;\r
2716         }\r
2717 \r
2718         return CResizableDialog::DefWindowProc(message, wParam, lParam);\r
2719 }\r
2720 \r
2721 void CLogDlg::SetSplitterRange()\r
2722 {\r
2723         if ((m_LogList)&&(m_ChangedFileListCtrl))\r
2724         {\r
2725                 CRect rcTop;\r
2726                 m_LogList.GetWindowRect(rcTop);\r
2727                 ScreenToClient(rcTop);\r
2728                 CRect rcMiddle;\r
2729                 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(rcMiddle);\r
2730                 ScreenToClient(rcMiddle);\r
2731                 m_wndSplitter1.SetRange(rcTop.top+30, rcMiddle.bottom-20);\r
2732                 CRect rcBottom;\r
2733                 m_ChangedFileListCtrl.GetWindowRect(rcBottom);\r
2734                 ScreenToClient(rcBottom);\r
2735                 m_wndSplitter2.SetRange(rcMiddle.top+30, rcBottom.bottom-20);\r
2736         }\r
2737 }\r
2738 \r
2739 LRESULT CLogDlg::OnClickedInfoIcon(WPARAM /*wParam*/, LPARAM lParam)\r
2740 {\r
2741         RECT * rect = (LPRECT)lParam;\r
2742         CPoint point;\r
2743         CString temp;\r
2744         point = CPoint(rect->left, rect->bottom);\r
2745 #define LOGMENUFLAGS(x) (MF_STRING | MF_ENABLED | (m_nSelectedFilter == x ? MF_CHECKED : MF_UNCHECKED))\r
2746         CMenu popup;\r
2747         if (popup.CreatePopupMenu())\r
2748         {\r
2749                 temp.LoadString(IDS_LOG_FILTER_ALL);\r
2750                 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_ALL), LOGFILTER_ALL, temp);\r
2751 \r
2752                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
2753                 \r
2754                 temp.LoadString(IDS_LOG_FILTER_MESSAGES);\r
2755                 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_MESSAGES), LOGFILTER_MESSAGES, temp);\r
2756                 temp.LoadString(IDS_LOG_FILTER_PATHS);\r
2757                 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_PATHS), LOGFILTER_PATHS, temp);\r
2758                 temp.LoadString(IDS_LOG_FILTER_AUTHORS);\r
2759                 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_AUTHORS), LOGFILTER_AUTHORS, temp);\r
2760                 temp.LoadString(IDS_LOG_FILTER_REVS);\r
2761                 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REVS), LOGFILTER_REVS, temp);\r
2762                 temp.LoadString(IDS_LOG_FILTER_BUGIDS);\r
2763                 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_BUGID), LOGFILTER_BUGID, temp);\r
2764                 \r
2765                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
2766 \r
2767                 temp.LoadString(IDS_LOG_FILTER_REGEX);\r
2768                 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterWithRegex ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_REGEX, temp);\r
2769 \r
2770                 m_tooltips.Pop();\r
2771                 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);\r
2772                 if (selection != 0)\r
2773                 {\r
2774 \r
2775                         if (selection == LOGFILTER_REGEX)\r
2776                         {\r
2777                                 m_bFilterWithRegex = !m_bFilterWithRegex;\r
2778                                 CRegDWORD b = CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);\r
2779                                 b = m_bFilterWithRegex;\r
2780                                 CheckRegexpTooltip();\r
2781                         }\r
2782                         else\r
2783                         {\r
2784                                 m_nSelectedFilter = selection;\r
2785                                 SetFilterCueText();\r
2786                         }\r
2787                         SetTimer(LOGFILTER_TIMER, 1000, NULL);\r
2788                 }\r
2789         }\r
2790         return 0L;\r
2791 }\r
2792 \r
2793 LRESULT CLogDlg::OnClickedCancelFilter(WPARAM /*wParam*/, LPARAM /*lParam*/)\r
2794 {\r
2795         KillTimer(LOGFILTER_TIMER);\r
2796 \r
2797         m_sFilterText.Empty();\r
2798         UpdateData(FALSE);\r
2799         theApp.DoWaitCursor(1);\r
2800         CStoreSelection storeselection(this);\r
2801         FillLogMessageCtrl(false);\r
2802         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
2803         m_arShownList.RemoveAll();\r
2804 \r
2805         // reset the time filter too\r
2806         m_timFrom = (__time64_t(m_tFrom));\r
2807         m_timTo = (__time64_t(m_tTo));\r
2808         m_DateFrom.SetTime(&m_timFrom);\r
2809         m_DateTo.SetTime(&m_timTo);\r
2810         m_DateFrom.SetRange(&m_timFrom, &m_timTo);\r
2811         m_DateTo.SetRange(&m_timFrom, &m_timTo);\r
2812 \r
2813         for (DWORD i=0; i<m_logEntries.size(); ++i)\r
2814         {\r
2815                 m_arShownList.Add(m_logEntries[i]);\r
2816         }\r
2817         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2818         m_LogList.DeleteAllItems();\r
2819         m_LogList.SetItemCountEx(ShownCountWithStopped());\r
2820         m_LogList.RedrawItems(0, ShownCountWithStopped());\r
2821         m_LogList.SetRedraw(false);\r
2822         ResizeAllListCtrlCols();\r
2823         m_LogList.SetRedraw(true);\r
2824         theApp.DoWaitCursor(-1);\r
2825         GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);\r
2826         GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);\r
2827         GetDlgItem(IDC_SEARCHEDIT)->SetFocus();\r
2828         UpdateLogInfoLabel();\r
2829         return 0L;      \r
2830 }\r
2831 \r
2832 \r
2833 void CLogDlg::SetFilterCueText()\r
2834 {\r
2835         CString temp;\r
2836         switch (m_nSelectedFilter)\r
2837         {\r
2838         case LOGFILTER_ALL:\r
2839                 temp.LoadString(IDS_LOG_FILTER_ALL);\r
2840                 break;\r
2841         case LOGFILTER_MESSAGES:\r
2842                 temp.LoadString(IDS_LOG_FILTER_MESSAGES);\r
2843                 break;\r
2844         case LOGFILTER_PATHS:\r
2845                 temp.LoadString(IDS_LOG_FILTER_PATHS);\r
2846                 break;\r
2847         case LOGFILTER_AUTHORS:\r
2848                 temp.LoadString(IDS_LOG_FILTER_AUTHORS);\r
2849                 break;\r
2850         case LOGFILTER_REVS:\r
2851                 temp.LoadString(IDS_LOG_FILTER_REVS);\r
2852                 break;\r
2853         }\r
2854         // to make the cue banner text appear more to the right of the edit control\r
2855         temp = _T("   ")+temp;\r
2856         m_cFilter.SetCueBanner(temp);\r
2857 }\r
2858 \r
2859 void CLogDlg::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
2860 {\r
2861         NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);\r
2862 \r
2863         // Create a pointer to the item\r
2864         LV_ITEM* pItem = &(pDispInfo)->item;\r
2865 \r
2866         // Do the list need text information?\r
2867         if (!(pItem->mask & LVIF_TEXT))\r
2868                 return;\r
2869 \r
2870         // By default, clear text buffer.\r
2871         lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);\r
2872 \r
2873         bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();\r
2874         \r
2875         *pResult = 0;\r
2876         if (m_bNoDispUpdates || m_bThreadRunning || bOutOfRange)\r
2877                 return;\r
2878 \r
2879         // Which item number?\r
2880         int itemid = pItem->iItem;\r
2881         PLOGENTRYDATA pLogEntry = NULL;\r
2882         if (itemid < m_arShownList.GetCount())\r
2883                 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(pItem->iItem));\r
2884     \r
2885         // Which column?\r
2886         switch (pItem->iSubItem)\r
2887         {\r
2888         case 0: //revision\r
2889                 if (pLogEntry)\r
2890                 {\r
2891                         _stprintf_s(pItem->pszText, pItem->cchTextMax, _T("%ld"), pLogEntry->Rev);\r
2892                         // to make the child entries indented, add spaces\r
2893                         size_t len = _tcslen(pItem->pszText);\r
2894                         TCHAR * pBuf = pItem->pszText + len;\r
2895                         DWORD nSpaces = m_maxChild-pLogEntry->childStackDepth;\r
2896                         while ((pItem->cchTextMax >= (int)len)&&(nSpaces))\r
2897                         {\r
2898                                 *pBuf = ' ';\r
2899                                 pBuf++;\r
2900                                 nSpaces--;\r
2901                         }\r
2902                         *pBuf = 0;\r
2903                 }\r
2904                 break;\r
2905         case 1: //action -- no text in the column\r
2906                 break;\r
2907         case 2: //author\r
2908                 if (pLogEntry)\r
2909                         lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->sAuthor, pItem->cchTextMax);\r
2910                 break;\r
2911         case 3: //date\r
2912                 if (pLogEntry)\r
2913                         lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->sDate, pItem->cchTextMax);\r
2914                 break;\r
2915         case 4: //message or bug id\r
2916                 if (m_bShowBugtraqColumn)\r
2917                 {\r
2918                         if (pLogEntry)\r
2919                                 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->sBugIDs, pItem->cchTextMax);\r
2920                         break;\r
2921                 }\r
2922                 // fall through here!\r
2923         case 5:\r
2924                 if (pLogEntry)\r
2925                 {\r
2926                         // Add as many characters as possible from the short log message\r
2927                         // to the list control. If the message is longer than\r
2928                         // allowed width, add "..." as an indication.\r
2929                         const int dots_len = 3;\r
2930                         if (pLogEntry->sShortMessage.GetLength() >= pItem->cchTextMax && pItem->cchTextMax > dots_len)\r
2931                         {\r
2932                                 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->sShortMessage, pItem->cchTextMax - dots_len);\r
2933                                 lstrcpyn(pItem->pszText + pItem->cchTextMax - dots_len - 1, _T("..."), dots_len + 1);\r
2934                         }\r
2935                         else\r
2936                                 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->sShortMessage, pItem->cchTextMax);\r
2937                 }\r
2938                 else if ((itemid == m_arShownList.GetCount()) && m_bStrict && m_bStrictStopped)\r
2939                 {\r
2940                         CString sTemp;\r
2941                         sTemp.LoadString(IDS_LOG_STOPONCOPY_HINT);\r
2942                         lstrcpyn(pItem->pszText, sTemp, pItem->cchTextMax);\r
2943                 }\r
2944                 break;\r
2945         default:\r
2946                 ASSERT(false);\r
2947         }\r
2948 }\r
2949 \r
2950 void CLogDlg::OnLvnGetdispinfoChangedFileList(NMHDR *pNMHDR, LRESULT *pResult)\r
2951 {\r
2952 #if 0\r
2953         NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);\r
2954 \r
2955         //Create a pointer to the item\r
2956         LV_ITEM* pItem= &(pDispInfo)->item;\r
2957 \r
2958         *pResult = 0;\r
2959         if ((m_bNoDispUpdates)||(m_bThreadRunning))\r
2960         {\r
2961                 if (pItem->mask & LVIF_TEXT)\r
2962                         lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);\r
2963                 return;\r
2964         }\r
2965         if ((m_currentChangedArray!=NULL)&&(pItem->iItem >= m_currentChangedArray->GetCount()))\r
2966         {\r
2967                 if (pItem->mask & LVIF_TEXT)\r
2968                         lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);\r
2969                 return;\r
2970         }\r
2971         if ((m_currentChangedArray==NULL)&&(pItem->iItem >= m_currentChangedPathList.GetCount()))\r
2972         {\r
2973                 if (pItem->mask & LVIF_TEXT)\r
2974                         lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);\r
2975                 return;\r
2976         }\r
2977         LogChangedPath * lcpath = NULL;\r
2978         if (m_currentChangedArray)\r
2979                 lcpath = m_currentChangedArray->GetAt(pItem->iItem);\r
2980         //Does the list need text information?\r
2981         if (pItem->mask & LVIF_TEXT)\r
2982         {\r
2983                 //Which column?\r
2984                 switch (pItem->iSubItem)\r
2985                 {\r
2986                 case 0: //Action\r
2987                         if (lcpath)\r
2988                                 lstrcpyn(pItem->pszText, (LPCTSTR)lcpath->GetAction(), pItem->cchTextMax);\r
2989                         else\r
2990                                 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);                            \r
2991                         break;\r
2992                 case 1: //path\r
2993                         if (lcpath)\r
2994                                 lstrcpyn(pItem->pszText, (LPCTSTR)lcpath->sPath, pItem->cchTextMax);\r
2995                         else\r
2996                                 lstrcpyn(pItem->pszText, (LPCTSTR)m_currentChangedPathList[pItem->iItem].GetGitPathString(), pItem->cchTextMax);\r
2997                         break;\r
2998                 case 2: //copyfrom path\r
2999                         if (lcpath)\r
3000                                 lstrcpyn(pItem->pszText, (LPCTSTR)lcpath->sCopyFromPath, pItem->cchTextMax);\r
3001                         else\r
3002                                 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);\r
3003                         break;\r
3004                 case 3: //revision\r
3005                         if ((lcpath==NULL)||(lcpath->sCopyFromPath.IsEmpty()))\r
3006                                 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);\r
3007                         else\r
3008                                 _stprintf_s(pItem->pszText, pItem->cchTextMax, _T("%ld"), lcpath->lCopyFromRev);\r
3009                         break;\r
3010                 }\r
3011         }\r
3012 \r
3013         *pResult = 0;\r
3014 #endif\r
3015 }\r
3016 \r
3017 void CLogDlg::OnEnChangeSearchedit()\r
3018 {\r
3019         UpdateData();\r
3020         if (m_sFilterText.IsEmpty())\r
3021         {\r
3022                 CStoreSelection storeselection(this);\r
3023                 // clear the filter, i.e. make all entries appear\r
3024                 theApp.DoWaitCursor(1);\r
3025                 KillTimer(LOGFILTER_TIMER);\r
3026                 FillLogMessageCtrl(false);\r
3027                 InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
3028                 m_arShownList.RemoveAll();\r
3029                 for (DWORD i=0; i<m_logEntries.size(); ++i)\r
3030                 {\r
3031                         if (IsEntryInDateRange(i))\r
3032                                 m_arShownList.Add(m_logEntries[i]);\r
3033                 }\r
3034                 InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
3035                 m_LogList.DeleteAllItems();\r
3036                 m_LogList.SetItemCountEx(ShownCountWithStopped());\r
3037                 m_LogList.RedrawItems(0, ShownCountWithStopped());\r
3038                 m_LogList.SetRedraw(false);\r
3039                 ResizeAllListCtrlCols();\r
3040                 m_LogList.SetRedraw(true);\r
3041                 theApp.DoWaitCursor(-1);\r
3042                 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);\r
3043                 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);\r
3044                 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();\r
3045                 DialogEnableWindow(IDC_STATBUTTON, !(((m_bThreadRunning)||(m_arShownList.IsEmpty()))));\r
3046                 return;\r
3047         }\r
3048         if (Validate(m_sFilterText))\r
3049                 SetTimer(LOGFILTER_TIMER, 1000, NULL);\r
3050         else\r
3051                 KillTimer(LOGFILTER_TIMER);\r
3052 }\r
3053 \r
3054 bool CLogDlg::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)\r
3055 {