OSDN Git Service

553d5a96c6bdc513de1947a122ca8f64f2047d22
[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         \r
306         while (c>=0)\r
307                 m_LogList.DeleteColumn(c--);\r
308         temp.LoadString(IDS_LOG_GRAPH);\r
309 \r
310         m_LogList.InsertColumn(this->LOGLIST_GRAPH, temp);\r
311         \r
312 #if 0   \r
313         // make the revision column right aligned\r
314         LVCOLUMN Column;\r
315         Column.mask = LVCF_FMT;\r
316         Column.fmt = LVCFMT_RIGHT;\r
317         m_LogList.SetColumn(0, &Column); \r
318 #endif  \r
319 //      CString log;\r
320 //      g_Git.GetLog(log);\r
321 \r
322         temp.LoadString(IDS_LOG_ACTIONS);\r
323         m_LogList.InsertColumn(this->LOGLIST_ACTION, temp);\r
324         \r
325         temp.LoadString(IDS_LOG_MESSAGE);\r
326         m_LogList.InsertColumn(this->LOGLIST_MESSAGE, temp);\r
327         \r
328         temp.LoadString(IDS_LOG_AUTHOR);\r
329         m_LogList.InsertColumn(this->LOGLIST_AUTHOR, temp);\r
330         \r
331         temp.LoadString(IDS_LOG_DATE);\r
332         m_LogList.InsertColumn(this->LOGLIST_DATE, temp);\r
333         \r
334 \r
335         if (m_bShowBugtraqColumn)\r
336         {\r
337                 temp = m_ProjectProperties.sLabel;\r
338                 if (temp.IsEmpty())\r
339                         temp.LoadString(IDS_LOG_BUGIDS);\r
340                 m_LogList.InsertColumn(this->LOGLIST_BUG, temp);\r
341 \r
342         }\r
343         \r
344         m_LogList.SetRedraw(false);\r
345         ResizeAllListCtrlCols();\r
346         m_LogList.SetRedraw(true);\r
347 \r
348         m_ChangedFileListCtrl.SetExtendedStyle ( LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER );\r
349         m_ChangedFileListCtrl.DeleteAllItems();\r
350         c = ((CHeaderCtrl*)(m_ChangedFileListCtrl.GetDlgItem(0)))->GetItemCount()-1;\r
351         while (c>=0)\r
352                 m_ChangedFileListCtrl.DeleteColumn(c--);\r
353         temp.LoadString(IDS_PROGRS_ACTION);\r
354         m_ChangedFileListCtrl.InsertColumn(this->FILELIST_ACTION, temp);\r
355         temp.LoadString(IDS_LOG_FILE_LINE_ADD);\r
356         m_ChangedFileListCtrl.InsertColumn(this->FILELIST_ADD, temp);\r
357         temp.LoadString(IDS_LOG_FILE_LINE_DEL);\r
358         m_ChangedFileListCtrl.InsertColumn(this->FILELIST_DEL, temp);\r
359         temp.LoadString(IDS_PROGRS_PATH);\r
360         m_ChangedFileListCtrl.InsertColumn(this->FILELIST_PATH, temp);\r
361         \r
362         m_ChangedFileListCtrl.SetRedraw(false);\r
363         CAppUtils::ResizeAllListCtrlCols(&m_ChangedFileListCtrl);\r
364         m_ChangedFileListCtrl.SetRedraw(true);\r
365 \r
366 \r
367         GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);\r
368 \r
369         m_logcounter = 0;\r
370         m_sMessageBuf.Preallocate(100000);\r
371 \r
372         // set the dialog title to "Log - path/to/whatever/we/show/the/log/for"\r
373         SetDlgTitle(false);\r
374 \r
375         m_tooltips.Create(this);\r
376         CheckRegexpTooltip();\r
377 \r
378         SetSplitterRange();\r
379         \r
380         // the filter control has a 'cancel' button (the red 'X'), we need to load its bitmap\r
381         m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);\r
382         m_cFilter.SetInfoIcon(IDI_LOGFILTER);\r
383         m_cFilter.SetValidator(this);\r
384         \r
385         AdjustControlSize(IDC_HIDEPATHS);\r
386         AdjustControlSize(IDC_CHECK_STOPONCOPY);\r
387         AdjustControlSize(IDC_INCLUDEMERGE);\r
388 \r
389         GetClientRect(m_DlgOrigRect);\r
390         m_LogList.GetClientRect(m_LogListOrigRect);\r
391         GetDlgItem(IDC_MSGVIEW)->GetClientRect(m_MsgViewOrigRect);\r
392         m_ChangedFileListCtrl.GetClientRect(m_ChgOrigRect);\r
393 \r
394         m_DateFrom.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);\r
395         m_DateTo.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);\r
396 \r
397         // resizable stuff\r
398         AddAnchor(IDC_FROMLABEL, TOP_LEFT);\r
399         AddAnchor(IDC_DATEFROM, TOP_LEFT);\r
400         AddAnchor(IDC_TOLABEL, TOP_LEFT);\r
401         AddAnchor(IDC_DATETO, TOP_LEFT);\r
402 \r
403         SetFilterCueText();\r
404         AddAnchor(IDC_SEARCHEDIT, TOP_LEFT, TOP_RIGHT);\r
405         \r
406         AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);\r
407         AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);\r
408         AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);\r
409         AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);\r
410         AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);\r
411 \r
412         AddAnchor(IDC_LOGINFO, BOTTOM_LEFT, BOTTOM_RIGHT);      \r
413         AddAnchor(IDC_HIDEPATHS, BOTTOM_LEFT);  \r
414         AddAnchor(IDC_CHECK_STOPONCOPY, BOTTOM_LEFT);\r
415         AddAnchor(IDC_INCLUDEMERGE, BOTTOM_LEFT);\r
416         AddAnchor(IDC_GETALL, BOTTOM_LEFT);\r
417         AddAnchor(IDC_NEXTHUNDRED, BOTTOM_LEFT);\r
418         AddAnchor(IDC_REFRESH, BOTTOM_LEFT);\r
419         AddAnchor(IDC_STATBUTTON, BOTTOM_RIGHT);\r
420         AddAnchor(IDC_PROGRESS, BOTTOM_LEFT, BOTTOM_RIGHT);\r
421         AddAnchor(IDOK, BOTTOM_RIGHT);\r
422         AddAnchor(IDCANCEL, BOTTOM_RIGHT);\r
423         AddAnchor(IDHELP, BOTTOM_RIGHT);\r
424 \r
425 //      SetPromptParentWindow(m_hWnd);\r
426 \r
427         if (hWndExplorer)\r
428                 CenterWindow(CWnd::FromHandle(hWndExplorer));\r
429         EnableSaveRestore(_T("LogDlg"));\r
430 \r
431         DWORD yPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));\r
432         DWORD yPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));\r
433         RECT rcDlg, rcLogList, rcChgMsg;\r
434         GetClientRect(&rcDlg);\r
435         m_LogList.GetWindowRect(&rcLogList);\r
436         ScreenToClient(&rcLogList);\r
437         m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg);\r
438         ScreenToClient(&rcChgMsg);\r
439         if (yPos1)\r
440         {\r
441                 RECT rectSplitter;\r
442                 m_wndSplitter1.GetWindowRect(&rectSplitter);\r
443                 ScreenToClient(&rectSplitter);\r
444                 int delta = yPos1 - rectSplitter.top;\r
445 \r
446                 if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30))\r
447                 {\r
448                         m_wndSplitter1.SetWindowPos(NULL, 0, yPos1, 0, 0, SWP_NOSIZE);\r
449                         DoSizeV1(delta);\r
450                 }\r
451         }\r
452         if (yPos2)\r
453         {\r
454                 RECT rectSplitter;\r
455                 m_wndSplitter2.GetWindowRect(&rectSplitter);\r
456                 ScreenToClient(&rectSplitter);\r
457                 int delta = yPos2 - rectSplitter.top;\r
458 \r
459                 if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30))\r
460                 {\r
461                         m_wndSplitter2.SetWindowPos(NULL, 0, yPos2, 0, 0, SWP_NOSIZE);\r
462                         DoSizeV2(delta);\r
463                 }\r
464         }\r
465 \r
466         \r
467         if (m_bSelect)\r
468         {\r
469                 // the dialog is used to select revisions\r
470                 if (m_bSelectionMustBeContinuous)\r
471                         DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(IsSelectionContinuous()));\r
472                 else\r
473                         DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);\r
474         }\r
475         else\r
476         {\r
477                 // the dialog is used to just view log messages\r
478                 GetDlgItemText(IDOK, temp);\r
479                 SetDlgItemText(IDCANCEL, temp);\r
480                 GetDlgItem(IDOK)->ShowWindow(SW_HIDE);\r
481         }\r
482         \r
483         // set the choices for the "Show All" button\r
484         temp.LoadString(IDS_LOG_SHOWALL);\r
485         m_btnShow.AddEntry(temp);\r
486         temp.LoadString(IDS_LOG_SHOWRANGE);\r
487         m_btnShow.AddEntry(temp);\r
488         m_btnShow.SetCurrentEntry((LONG)CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry")));\r
489 \r
490         m_mergedRevs.clear();\r
491 \r
492         // first start a thread to obtain the log messages without\r
493         // blocking the dialog\r
494         m_tTo = 0;\r
495         m_tFrom = (DWORD)-1;\r
496         InterlockedExchange(&m_bThreadRunning, TRUE);\r
497         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
498         if (AfxBeginThread(LogThreadEntry, this)==NULL)\r
499         {\r
500                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
501                 InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
502                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
503         }\r
504         GetDlgItem(IDC_LOGLIST)->SetFocus();\r
505         return FALSE;\r
506 }\r
507 \r
508 void CLogDlg::SetDlgTitle(bool bOffline)\r
509 {\r
510         if (m_sTitle.IsEmpty())\r
511                 GetWindowText(m_sTitle);\r
512 \r
513         if (bOffline)\r
514         {\r
515                 CString sTemp;\r
516                 if (m_path.IsUrl())\r
517                         sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetUIPathString());\r
518                 else if (m_path.IsDirectory())\r
519                         sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetWinPathString());\r
520                 else\r
521                         sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetFilename());\r
522                 SetWindowText(sTemp);\r
523         }\r
524         else\r
525         {\r
526                 if (m_path.IsUrl())\r
527                         SetWindowText(m_sTitle + _T(" - ") + m_path.GetUIPathString());\r
528                 else if (m_path.IsDirectory())\r
529                         SetWindowText(m_sTitle + _T(" - ") + m_path.GetWinPathString());\r
530                 else\r
531                         SetWindowText(m_sTitle + _T(" - ") + m_path.GetFilename());\r
532         }\r
533 }\r
534 \r
535 void CLogDlg::CheckRegexpTooltip()\r
536 {\r
537         CWnd *pWnd = GetDlgItem(IDC_SEARCHEDIT);\r
538         // Since tooltip describes regexp features, show it only if regexps are enabled.\r
539         if (m_bFilterWithRegex)\r
540         {\r
541                 m_tooltips.AddTool(pWnd, IDS_LOG_FILTER_REGEX_TT);\r
542         }\r
543         else\r
544                 m_tooltips.DelTool(pWnd);\r
545 }\r
546 \r
547 void CLogDlg::EnableOKButton()\r
548 {\r
549         if (m_bSelect)\r
550         {\r
551                 // the dialog is used to select revisions\r
552                 if (m_bSelectionMustBeContinuous)\r
553                         DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(IsSelectionContinuous()));\r
554                 else\r
555                         DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);\r
556         }\r
557         else\r
558                 DialogEnableWindow(IDOK, TRUE);\r
559 }\r
560 \r
561 void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)\r
562 {\r
563         // we fill here the log message rich edit control,\r
564         // and also populate the changed files list control\r
565         // according to the selected revision(s).\r
566 \r
567         CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);\r
568         // empty the log message view\r
569         pMsgView->SetWindowText(_T(" "));\r
570         // empty the changed files list\r
571         m_ChangedFileListCtrl.SetRedraw(FALSE);\r
572         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
573         m_currentChangedArray = NULL;\r
574         m_ChangedFileListCtrl.SetExtendedStyle ( LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER );\r
575         m_ChangedFileListCtrl.DeleteAllItems();\r
576         m_ChangedFileListCtrl.SetItemCountEx(0);\r
577 \r
578         // if we're not here to really show a selected revision, just\r
579         // get out of here after clearing the views, which is what is intended\r
580         // if that flag is not set.\r
581         if (!bShow)\r
582         {\r
583                 // force a redraw\r
584                 m_ChangedFileListCtrl.Invalidate();\r
585                 InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
586                 m_ChangedFileListCtrl.SetRedraw(TRUE);\r
587                 return;\r
588         }\r
589 \r
590         // depending on how many revisions are selected, we have to do different\r
591         // tasks.\r
592         int selCount = m_LogList.GetSelectedCount();\r
593         if (selCount == 0)\r
594         {\r
595                 // if nothing is selected, we have nothing more to do\r
596                 InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
597                 m_ChangedFileListCtrl.SetRedraw(TRUE);\r
598                 return;\r
599         }\r
600         else if (selCount == 1)\r
601         {\r
602                 // if one revision is selected, we have to fill the log message view\r
603                 // with the corresponding log message, and also fill the changed files\r
604                 // list fully.\r
605                 POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
606                 int selIndex = m_LogList.GetNextSelectedItem(pos);\r
607                 if (selIndex >= m_arShownList.GetCount())\r
608                 {\r
609                         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
610                         m_ChangedFileListCtrl.SetRedraw(TRUE);\r
611                         return;\r
612                 }\r
613                 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(selIndex));\r
614 \r
615                 // set the log message text\r
616                 pMsgView->SetWindowText(_T("*")+pLogEntry->m_Subject+_T("\n\n")+pLogEntry->m_Body);\r
617                 // turn bug ID's into links if the bugtraq: properties have been set\r
618                 // and we can find a match of those in the log message\r
619                 m_ProjectProperties.FindBugID(pLogEntry->m_Body, pMsgView);\r
620                 CAppUtils::FormatTextInRichEditControl(pMsgView);\r
621                 m_currentChangedArray = &(pLogEntry->m_Files);\r
622                 if (m_currentChangedArray == NULL)\r
623                 {\r
624                         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
625                         m_ChangedFileListCtrl.SetRedraw(TRUE);\r
626                         return;\r
627                 }\r
628 #if 0\r
629                 // fill in the changed files list control\r
630                 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)\r
631                 {\r
632                         m_CurrentFilteredChangedArray.RemoveAll();\r
633                         for (INT_PTR c = 0; c < m_currentChangedArray->GetCount(); ++c)\r
634                         {\r
635                                 LogChangedPath * cpath = m_currentChangedArray->GetAt(c);\r
636                                 if (cpath == NULL)\r
637                                         continue;\r
638                                 if (m_currentChangedArray->GetAt(c)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)\r
639                                 {\r
640                                         m_CurrentFilteredChangedArray.Add(cpath);\r
641                                 }\r
642                         }\r
643                         m_currentChangedArray = &m_CurrentFilteredChangedArray;\r
644                 }\r
645 #endif\r
646         }\r
647         else\r
648         {\r
649                 // more than one revision is selected:\r
650                 // the log message view must be emptied\r
651                 // the changed files list contains all the changed paths from all\r
652                 // selected revisions, with 'doubles' removed\r
653                 m_currentChangedPathList = GetChangedPathsFromSelectedRevisions(true);\r
654         }\r
655         \r
656         // redraw the views\r
657         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
658         if (m_currentChangedArray)\r
659         {\r
660                 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedArray->GetCount());\r
661                 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedArray->GetCount());\r
662         }\r
663         else if (m_currentChangedPathList.GetCount())\r
664         {\r
665                 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedPathList.GetCount());\r
666                 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedPathList.GetCount());\r
667         }\r
668         else\r
669         {\r
670                 m_ChangedFileListCtrl.SetItemCountEx(0);\r
671                 m_ChangedFileListCtrl.Invalidate();\r
672         }\r
673         CAppUtils::ResizeAllListCtrlCols(&m_ChangedFileListCtrl);\r
674         // sort according to the settings\r
675         if (m_nSortColumnPathList > 0)\r
676                 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);\r
677         else\r
678                 SetSortArrow(&m_ChangedFileListCtrl, -1, false);\r
679         m_ChangedFileListCtrl.SetRedraw(TRUE);\r
680 \r
681 }\r
682 \r
683 void CLogDlg::OnBnClickedGetall()\r
684 {\r
685         GetAll();\r
686 }\r
687 \r
688 void CLogDlg::GetAll(bool bForceAll /* = false */)\r
689 {\r
690 #if 0\r
691         // fetch all requested log messages, either the specified range or\r
692         // really *all* available log messages.\r
693         UpdateData();\r
694         INT_PTR entry = m_btnShow.GetCurrentEntry();\r
695         if (bForceAll)\r
696                 entry = 0;\r
697 \r
698         switch (entry)\r
699         {\r
700         case 0: // show all\r
701         \r
702                 m_endrev = 0;\r
703                 m_startrev = m_LogRevision;\r
704                 if (m_bStrict)\r
705                         m_bShowedAll = true;\r
706 \r
707                 break;\r
708         case 1: // show range\r
709                 {\r
710 \r
711                         // ask for a revision range\r
712                         CRevisionRangeDlg dlg;\r
713                         dlg.SetStartRevision(m_startrev);\r
714                         dlg.SetEndRevision( (m_endrev>=0) ? m_endrev : 0);\r
715                         if (dlg.DoModal()!=IDOK)\r
716                         {\r
717                                 return;\r
718                         }\r
719                         m_endrev = dlg.GetEndRevision();\r
720                         m_startrev = dlg.GetStartRevision();\r
721                         if (((m_endrev.IsNumber())&&(m_startrev.IsNumber()))||\r
722                                 (m_endrev.IsHead()||m_startrev.IsHead()))\r
723                         {\r
724                                 if (((LONG)m_startrev < (LONG)m_endrev)||\r
725                                         (m_endrev.IsHead()))\r
726                                 {\r
727                                         git_revnum_t temp = m_startrev;\r
728                                         m_startrev = m_endrev;\r
729                                         m_endrev = temp;\r
730                                 }\r
731                         }\r
732                         m_bShowedAll = false;\r
733                 }\r
734 \r
735                 break;\r
736         }\r
737         m_ChangedFileListCtrl.SetItemCountEx(0);\r
738         m_ChangedFileListCtrl.Invalidate();\r
739         // We need to create CStoreSelection on the heap or else\r
740         // the variable will run out of the scope before the\r
741         // thread ends. Therefore we let the thread delete\r
742         // the instance.\r
743         m_pStoreSelection = new CStoreSelection(this);\r
744         m_LogList.SetItemCountEx(0);\r
745         m_LogList.Invalidate();\r
746         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
747         CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);\r
748         pMsgView->SetWindowText(_T(""));\r
749 \r
750         SetSortArrow(&m_LogList, -1, true);\r
751 \r
752         m_LogList.DeleteAllItems();\r
753         m_arShownList.RemoveAll();\r
754         m_logEntries.ClearAll();\r
755 \r
756         m_logcounter = 0;\r
757         m_bCancelled = FALSE;\r
758         m_tTo = 0;\r
759         m_tFrom = (DWORD)-1;\r
760         m_limit = 0;\r
761 \r
762         InterlockedExchange(&m_bThreadRunning, TRUE);\r
763         if (AfxBeginThread(LogThreadEntry, this)==NULL)\r
764         {\r
765                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
766                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
767         }\r
768         GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);\r
769         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
770 #endif\r
771 }\r
772 \r
773 void CLogDlg::OnBnClickedRefresh()\r
774 {\r
775         m_limit = 0;\r
776         Refresh (true);\r
777 }\r
778 \r
779 void CLogDlg::Refresh (bool autoGoOnline)\r
780 {\r
781 #if 0\r
782         // refreshing means re-downloading the already shown log messages\r
783         UpdateData();\r
784         m_maxChild = 0;\r
785         m_childCounter = 0;\r
786 \r
787         if ((m_limit == 0)||(m_bStrict)||(int(m_logEntries.size()-1) > m_limit))\r
788         {\r
789                 if (m_logEntries.size() != 0)\r
790                 {\r
791                         m_endrev = m_logEntries[m_logEntries.size()-1]->Rev;\r
792                 }\r
793         }\r
794         m_startrev = -1;\r
795         m_bCancelled = FALSE;\r
796 \r
797         // We need to create CStoreSelection on the heap or else\r
798         // the variable will run out of the scope before the\r
799         // thread ends. Therefore we let the thread delete\r
800         // the instance.\r
801         m_pStoreSelection = new CStoreSelection(this);\r
802         m_ChangedFileListCtrl.SetItemCountEx(0);\r
803         m_ChangedFileListCtrl.Invalidate();\r
804         m_LogList.SetItemCountEx(0);\r
805         m_LogList.Invalidate();\r
806         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
807         CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);\r
808         pMsgView->SetWindowText(_T(""));\r
809 \r
810         SetSortArrow(&m_LogList, -1, true);\r
811 \r
812         m_LogList.DeleteAllItems();\r
813         m_arShownList.RemoveAll();\r
814         m_logEntries.ClearAll();\r
815 \r
816     // reset the cached HEAD property & go on-line\r
817 \r
818     if (autoGoOnline)\r
819     {\r
820             SetDlgTitle (false);\r
821         logCachePool.GetRepositoryInfo().ResetHeadRevision (m_sUUID, m_sRepositoryRoot);\r
822     }\r
823 \r
824         InterlockedExchange(&m_bThreadRunning, TRUE);\r
825         if (AfxBeginThread(LogThreadEntry, this)==NULL)\r
826         {\r
827                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
828                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
829         }\r
830         GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);\r
831         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
832 #endif\r
833 }\r
834 \r
835 void CLogDlg::OnBnClickedNexthundred()\r
836 {\r
837 #if 0\r
838         UpdateData();\r
839         // we have to fetch the next X log messages.\r
840         if (m_logEntries.size() < 1)\r
841         {\r
842                 // since there weren't any log messages fetched before, just\r
843                 // fetch all since we don't have an 'anchor' to fetch the 'next'\r
844                 // messages from.\r
845                 return GetAll(true);\r
846         }\r
847         git_revnum_t rev = m_logEntries[m_logEntries.size()-1]->Rev;\r
848 \r
849         if (rev < 1)\r
850                 return;         // do nothing! No more revisions to get\r
851 \r
852         m_startrev = rev;\r
853         m_endrev = 0;\r
854         m_bCancelled = FALSE;\r
855 \r
856     // rev is is revision we already have and we will receive it again\r
857     // -> fetch one extra revision to get NumberOfLogs *new* revisions\r
858 \r
859         m_limit = (int)(DWORD)CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100) +1;\r
860         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
861         SetSortArrow(&m_LogList, -1, true);\r
862         InterlockedExchange(&m_bThreadRunning, TRUE);\r
863         // We need to create CStoreSelection on the heap or else\r
864         // the variable will run out of the scope before the\r
865         // thread ends. Therefore we let the thread delete\r
866         // the instance.\r
867         m_pStoreSelection = new CStoreSelection(this);\r
868 \r
869         // since we fetch the log from the last revision we already have,\r
870         // we have to remove that revision entry to avoid getting it twice\r
871         m_logEntries.pop_back();\r
872         if (AfxBeginThread(LogThreadEntry, this)==NULL)\r
873         {\r
874                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
875                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
876         }\r
877         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
878         GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);\r
879 #endif\r
880 }\r
881 \r
882 BOOL CLogDlg::Cancel()\r
883 {\r
884         return m_bCancelled;\r
885 }\r
886 \r
887 void CLogDlg::SaveSplitterPos()\r
888 {\r
889         if (!IsIconic())\r
890         {\r
891                 CRegDWORD regPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));\r
892                 CRegDWORD regPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));\r
893                 RECT rectSplitter;\r
894                 m_wndSplitter1.GetWindowRect(&rectSplitter);\r
895                 ScreenToClient(&rectSplitter);\r
896                 regPos1 = rectSplitter.top;\r
897                 m_wndSplitter2.GetWindowRect(&rectSplitter);\r
898                 ScreenToClient(&rectSplitter);\r
899                 regPos2 = rectSplitter.top;\r
900         }\r
901 }\r
902 \r
903 void CLogDlg::OnCancel()\r
904 {\r
905         // canceling means stopping the working thread if it's still running.\r
906         // we do this by using the Subversion cancel callback.\r
907         // But canceling can also mean just to close the dialog, depending on the\r
908         // text shown on the cancel button (it could simply read "OK").\r
909         CString temp, temp2;\r
910         GetDlgItemText(IDOK, temp);\r
911         temp2.LoadString(IDS_MSGBOX_CANCEL);\r
912         if ((temp.Compare(temp2)==0)||(m_bThreadRunning))\r
913         {\r
914                 m_bCancelled = true;\r
915                 return;\r
916         }\r
917         UpdateData();\r
918         if (m_bSaveStrict)\r
919                 m_regLastStrict = m_bStrict;\r
920         CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry"));\r
921         reg = m_btnShow.GetCurrentEntry();\r
922         SaveSplitterPos();\r
923         __super::OnCancel();\r
924 }\r
925 \r
926 CString CLogDlg::MakeShortMessage(const CString& message)\r
927 {\r
928         bool bFoundShort = true;\r
929         CString sShortMessage = m_ProjectProperties.GetLogSummary(message);\r
930         if (sShortMessage.IsEmpty())\r
931         {\r
932                 bFoundShort = false;\r
933                 sShortMessage = message;\r
934         }\r
935         // Remove newlines and tabs 'cause those are not shown nicely in the list control\r
936         sShortMessage.Replace(_T("\r"), _T(""));\r
937         sShortMessage.Replace(_T("\t"), _T(" "));\r
938         \r
939         // Suppose the first empty line separates 'summary' from the rest of the message.\r
940         int found = sShortMessage.Find(_T("\n\n"));\r
941         // To avoid too short 'short' messages \r
942         // (e.g. if the message looks something like "Bugfix:\n\n*done this\n*done that")\r
943         // only use the empty newline as a separator if it comes after at least 15 chars.\r
944         if ((!bFoundShort)&&(found >= 15))\r
945         {\r
946                 sShortMessage = sShortMessage.Left(found);\r
947         }\r
948         sShortMessage.Replace('\n', ' ');\r
949         return sShortMessage;\r
950 }\r
951 \r
952 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
953 {\r
954 #if 0\r
955         if (rev == SVN_INVALID_REVNUM)\r
956         {\r
957                 m_childCounter--;\r
958                 return TRUE;\r
959         }\r
960 \r
961         // this is the callback function which receives the data for every revision we ask the log for\r
962         // we store this information here one by one.\r
963         m_logcounter += 1;\r
964         if (m_startrev == -1)\r
965                 m_startrev = rev;\r
966         if (m_limit != 0)\r
967         {\r
968                 m_limitcounter--;\r
969                 m_LogProgress.SetPos(m_limit - m_limitcounter);\r
970         }\r
971         else if (m_startrev.IsNumber() && m_startrev.IsNumber())\r
972                 m_LogProgress.SetPos((git_revnum_t)m_startrev-rev+(git_revnum_t)m_endrev);\r
973         __time64_t ttime = time/1000000L;\r
974         if (m_tTo < (DWORD)ttime)\r
975                 m_tTo = (DWORD)ttime;\r
976         if (m_tFrom > (DWORD)ttime)\r
977                 m_tFrom = (DWORD)ttime;\r
978         if ((m_lowestRev > rev)||(m_lowestRev < 0))\r
979                 m_lowestRev = rev;\r
980         // Add as many characters from the log message to the list control\r
981         PLOGENTRYDATA pLogItem = new LOGENTRYDATA;\r
982         pLogItem->bCopies = !!copies;\r
983         \r
984         // find out if this item was copied in the revision\r
985         BOOL copiedself = FALSE;\r
986         if (copies)\r
987         {\r
988                 for (INT_PTR cpPathIndex = 0; cpPathIndex < cpaths->GetCount(); ++cpPathIndex)\r
989                 {\r
990                         LogChangedPath * cpath = cpaths->GetAt(cpPathIndex);\r
991                         if (!cpath->sCopyFromPath.IsEmpty() && (cpath->sPath.Compare(m_sSelfRelativeURL) == 0))\r
992                         {\r
993                                 // note: this only works if the log is fetched top-to-bottom\r
994                                 // but since we do that, it shouldn't be a problem\r
995                                 m_sSelfRelativeURL = cpath->sCopyFromPath;\r
996                                 copiedself = TRUE;\r
997                                 break;\r
998                         }\r
999                 }\r
1000         }\r
1001         pLogItem->bCopiedSelf = copiedself;\r
1002         pLogItem->tmDate = ttime;\r
1003         pLogItem->sAuthor = author;\r
1004         pLogItem->sDate = date;\r
1005         pLogItem->sShortMessage = MakeShortMessage(message);\r
1006         pLogItem->dwFileChanges = filechanges;\r
1007         pLogItem->actions = actions;\r
1008         pLogItem->haschildren = haschildren;\r
1009         pLogItem->childStackDepth = m_childCounter;\r
1010         m_maxChild = max(m_childCounter, m_maxChild);\r
1011         if (haschildren)\r
1012                 m_childCounter++;\r
1013         pLogItem->sBugIDs = m_ProjectProperties.FindBugID(message).Trim();\r
1014         \r
1015         // split multi line log entries and concatenate them\r
1016         // again but this time with \r\n as line separators\r
1017         // so that the edit control recognizes them\r
1018         try\r
1019         {\r
1020                 if (message.GetLength()>0)\r
1021                 {\r
1022                         m_sMessageBuf = message;\r
1023                         m_sMessageBuf.Replace(_T("\n\r"), _T("\n"));\r
1024                         m_sMessageBuf.Replace(_T("\r\n"), _T("\n"));\r
1025                         if (m_sMessageBuf.Right(1).Compare(_T("\n"))==0)\r
1026                                 m_sMessageBuf = m_sMessageBuf.Left(m_sMessageBuf.GetLength()-1);\r
1027                 }\r
1028                 else\r
1029                         m_sMessageBuf.Empty();\r
1030         pLogItem->sMessage = m_sMessageBuf;\r
1031         pLogItem->Rev = rev;\r
1032 \r
1033         // move-construct path array\r
1034 \r
1035         pLogItem->pArChangedPaths = new LogChangedPathArray (*cpaths);\r
1036         cpaths->RemoveAll();\r
1037         }\r
1038         catch (CException * e)\r
1039         {\r
1040                 ::MessageBox(NULL, _T("not enough memory!"), _T("TortoiseGit"), MB_ICONERROR);\r
1041                 e->Delete();\r
1042                 m_bCancelled = TRUE;\r
1043         }\r
1044         m_logEntries.push_back(pLogItem);\r
1045         m_arShownList.Add(pLogItem);\r
1046 #endif\r
1047         return TRUE;\r
1048 }\r
1049 \r
1050 //this is the thread function which calls the subversion function\r
1051 UINT CLogDlg::LogThreadEntry(LPVOID pVoid)\r
1052 {\r
1053         return ((CLogDlg*)pVoid)->LogThread();\r
1054 }\r
1055 \r
1056 GitRev g_rev;\r
1057 //this is the thread function which calls the subversion function\r
1058 UINT CLogDlg::LogThread()\r
1059 {\r
1060 \r
1061         InterlockedExchange(&m_bThreadRunning, TRUE);\r
1062 \r
1063     //does the user force the cache to refresh (shift or control key down)?\r
1064     bool refresh =    (GetKeyState (VK_CONTROL) < 0) \r
1065                    || (GetKeyState (VK_SHIFT) < 0);\r
1066 \r
1067         //disable the "Get All" button while we're receiving\r
1068         //log messages.\r
1069         DialogEnableWindow(IDC_GETALL, FALSE);\r
1070         DialogEnableWindow(IDC_NEXTHUNDRED, FALSE);\r
1071         DialogEnableWindow(IDC_CHECK_STOPONCOPY, FALSE);\r
1072         DialogEnableWindow(IDC_INCLUDEMERGE, FALSE);\r
1073         DialogEnableWindow(IDC_STATBUTTON, FALSE);\r
1074         DialogEnableWindow(IDC_REFRESH, FALSE);\r
1075         \r
1076         CString temp;\r
1077         temp.LoadString(IDS_PROGRESSWAIT);\r
1078         m_LogList.ShowText(temp, true);\r
1079         // change the text of the close button to "Cancel" since now the thread\r
1080         // is running, and simply closing the dialog doesn't work.\r
1081         if (!GetDlgItem(IDOK)->IsWindowVisible())\r
1082         {\r
1083                 temp.LoadString(IDS_MSGBOX_CANCEL);\r
1084                 SetDlgItemText(IDCANCEL, temp);\r
1085         }\r
1086         // We use a progress bar while getting the logs\r
1087         m_LogProgress.SetRange32(0, 100);\r
1088         m_LogProgress.SetPos(0);\r
1089         GetDlgItem(IDC_PROGRESS)->ShowWindow(TRUE);\r
1090 //      git_revnum_t r = -1;\r
1091         \r
1092         // get the repository root url, because the changed-files-list has the\r
1093         // paths shown there relative to the repository root.\r
1094 //      CTGitPath rootpath;\r
1095 //  BOOL succeeded = GetRootAndHead(m_path, rootpath, r);\r
1096 \r
1097 //    m_sRepositoryRoot = rootpath.GetGitPathString();\r
1098 //    m_sURL = m_path.GetGitPathString();\r
1099 \r
1100     // we need the UUID to unambigously identify the log cache\r
1101 //    if (logCachePool.IsEnabled())\r
1102 //        m_sUUID = logCachePool.GetRepositoryInfo().GetRepositoryUUID (rootpath);\r
1103 \r
1104     // if the log dialog is started from a working copy, we need to turn that\r
1105     // local path into an url here\r
1106 //    if (succeeded)\r
1107 //    {\r
1108 //        if (!m_path.IsUrl())\r
1109 //        {\r
1110 //              m_sURL = GetURLFromPath(m_path);\r
1111 \r
1112                 // The URL is escaped because Git::logReceiver\r
1113                 // returns the path in a native format\r
1114 //              m_sURL = CPathUtils::PathUnescape(m_sURL);\r
1115   //      }\r
1116 //        m_sRelativeRoot = m_sURL.Mid(CPathUtils::PathUnescape(m_sRepositoryRoot).GetLength());\r
1117 //              m_sSelfRelativeURL = m_sRelativeRoot;\r
1118   //  }\r
1119 #if 0\r
1120     if (succeeded && !m_mergePath.IsEmpty() && m_mergedRevs.empty())\r
1121     {\r
1122             // in case we got a merge path set, retrieve the merge info\r
1123             // of that path and check whether one of the merge URLs\r
1124             // match the URL we show the log for.\r
1125             GitPool localpool(pool);\r
1126             git_error_clear(Err);\r
1127             apr_hash_t * mergeinfo = NULL;\r
1128             if (git_client_mergeinfo_get_merged (&mergeinfo, m_mergePath.GetGitApiPath(localpool), GitRev(GitRev::REV_WC), m_pctx, localpool) == NULL)\r
1129             {\r
1130                     // now check the relative paths\r
1131                     apr_hash_index_t *hi;\r
1132                     const void *key;\r
1133                     void *val;\r
1134 \r
1135                     if (mergeinfo)\r
1136                     {\r
1137                             for (hi = apr_hash_first(localpool, mergeinfo); hi; hi = apr_hash_next(hi))\r
1138                             {\r
1139                                     apr_hash_this(hi, &key, NULL, &val);\r
1140                                     if (m_sURL.Compare(CUnicodeUtils::GetUnicode((char*)key)) == 0)\r
1141                                     {\r
1142                                             apr_array_header_t * arr = (apr_array_header_t*)val;\r
1143                                             if (val)\r
1144                                             {\r
1145                                                     for (long i=0; i<arr->nelts; ++i)\r
1146                                                     {\r
1147                                                             git_merge_range_t * pRange = APR_ARRAY_IDX(arr, i, git_merge_range_t*);\r
1148                                                             if (pRange)\r
1149                                                             {\r
1150                                                                     for (git_revnum_t r=pRange->start+1; r<=pRange->end; ++r)\r
1151                                                                     {\r
1152                                                                             m_mergedRevs.insert(r);\r
1153                                                                     }\r
1154                                                             }\r
1155                                                     }\r
1156                                             }\r
1157                                             break;\r
1158                                     }\r
1159                             }\r
1160                     }\r
1161             }\r
1162     }\r
1163 \r
1164     m_LogProgress.SetPos(1);\r
1165     if (m_startrev == GitRev::REV_HEAD)\r
1166     {\r
1167             m_startrev = r;\r
1168     }\r
1169     if (m_endrev == GitRev::REV_HEAD)\r
1170     {\r
1171             m_endrev = r;\r
1172     }\r
1173 \r
1174     if (m_limit != 0)\r
1175     {\r
1176             m_limitcounter = m_limit;\r
1177             m_LogProgress.SetRange32(0, m_limit);\r
1178     }\r
1179     else\r
1180             m_LogProgress.SetRange32(m_endrev, m_startrev);\r
1181         \r
1182     if (!m_pegrev.IsValid())\r
1183             m_pegrev = m_startrev;\r
1184     size_t startcount = m_logEntries.size();\r
1185     m_lowestRev = -1;\r
1186     m_bStrictStopped = false;\r
1187 \r
1188     if (succeeded)\r
1189     {\r
1190         succeeded = ReceiveLog (CTGitPathList(m_path), m_pegrev, m_startrev, m_endrev, m_limit, m_bStrict, m_bIncludeMerges, refresh);\r
1191         if ((!succeeded)&&(!m_path.IsUrl()))\r
1192         {\r
1193                 // try again with REV_WC as the start revision, just in case the path doesn't\r
1194                 // exist anymore in HEAD\r
1195                 succeeded = ReceiveLog(CTGitPathList(m_path), GitRev(), GitRev::REV_WC, m_endrev, m_limit, m_bStrict, m_bIncludeMerges, refresh);\r
1196         }\r
1197     }\r
1198         m_LogList.ClearText();\r
1199     if (!succeeded)\r
1200         {\r
1201                 m_LogList.ShowText(GetLastErrorMessage(), true);\r
1202         }\r
1203         else\r
1204         {\r
1205                 if (!m_wcRev.IsValid())\r
1206                 {\r
1207                         // fetch the revision the wc path is on so we can mark it\r
1208                         CTGitPath revWCPath = m_ProjectProperties.GetPropsPath();\r
1209                         if (!m_path.IsUrl())\r
1210                                 revWCPath = m_path;\r
1211                         if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RecursiveLogRev"), FALSE)))\r
1212                         {\r
1213                                 git_revnum_t minrev, maxrev;\r
1214                                 bool switched, modified, sparse;\r
1215                                 GetWCRevisionStatus(revWCPath, true, minrev, maxrev, switched, modified, sparse);\r
1216                                 if (maxrev)\r
1217                                         m_wcRev = maxrev;\r
1218                         }\r
1219                         else\r
1220                         {\r
1221                                 CTGitPath dummypath;\r
1222                                 GitStatus status;\r
1223                                 git_wc_status2_t * stat = status.GetFirstFileStatus(revWCPath, dummypath, false, git_depth_empty);\r
1224                                 if (stat && stat->entry && stat->entry->cmt_rev)\r
1225                                         m_wcRev = stat->entry->cmt_rev;\r
1226                                 if (stat && stat->entry && (stat->entry->kind == git_node_dir))\r
1227                                         m_wcRev = stat->entry->revision;\r
1228                         }\r
1229                 }\r
1230         }\r
1231     if (m_bStrict && (m_lowestRev>1) && ((m_limit>0) ? ((startcount + m_limit)>m_logEntries.size()) : (m_endrev<m_lowestRev)))\r
1232                 m_bStrictStopped = true;\r
1233         m_LogList.SetItemCountEx(ShownCountWithStopped());\r
1234 \r
1235         m_timFrom = (__time64_t(m_tFrom));\r
1236         m_timTo = (__time64_t(m_tTo));\r
1237         m_DateFrom.SetRange(&m_timFrom, &m_timTo);\r
1238         m_DateTo.SetRange(&m_timFrom, &m_timTo);\r
1239         m_DateFrom.SetTime(&m_timFrom);\r
1240         m_DateTo.SetTime(&m_timTo);\r
1241 #endif\r
1242         DialogEnableWindow(IDC_GETALL, TRUE);\r
1243         m_LogList.ClearText();\r
1244 \r
1245         this->m_logEntries.ClearAll();\r
1246         this->m_logEntries.ParserFromLog();\r
1247         m_LogList.SetItemCountEx(this->m_logEntries.size());\r
1248 \r
1249         this->m_arShownList.RemoveAll();\r
1250 \r
1251         for(int i=0;i<m_logEntries.size();i++)\r
1252                 this->m_arShownList.Add(&m_logEntries[i]);\r
1253         \r
1254 #if 0   \r
1255         if (!m_bShowedAll)\r
1256                 DialogEnableWindow(IDC_NEXTHUNDRED, TRUE);\r
1257 #endif\r
1258         DialogEnableWindow(IDC_CHECK_STOPONCOPY, TRUE);\r
1259         DialogEnableWindow(IDC_INCLUDEMERGE, TRUE);\r
1260         DialogEnableWindow(IDC_STATBUTTON, TRUE);\r
1261         DialogEnableWindow(IDC_REFRESH, TRUE);\r
1262 \r
1263 #if 0\r
1264         LogCache::CRepositoryInfo& cachedProperties = logCachePool.GetRepositoryInfo();\r
1265         SetDlgTitle(cachedProperties.IsOffline (m_sUUID, m_sRepositoryRoot, false));\r
1266 \r
1267         GetDlgItem(IDC_PROGRESS)->ShowWindow(FALSE);\r
1268         m_bCancelled = true;\r
1269 #endif\r
1270         InterlockedExchange(&m_bThreadRunning, FALSE);\r
1271         m_LogList.RedrawItems(0, m_arShownList.GetCount());\r
1272         m_LogList.SetRedraw(false);\r
1273         ResizeAllListCtrlCols();\r
1274         m_LogList.SetRedraw(true);\r
1275         if ( m_pStoreSelection )\r
1276         {\r
1277                 // Deleting the instance will restore the\r
1278                 // selection of the CLogDlg.\r
1279                 delete m_pStoreSelection;\r
1280                 m_pStoreSelection = NULL;\r
1281         }\r
1282         else\r
1283         {\r
1284                 // If no selection has been set then this must be the first time\r
1285                 // the revisions are shown. Let's preselect the topmost revision.\r
1286                 if ( m_LogList.GetItemCount()>0 )\r
1287                 {\r
1288                         m_LogList.SetSelectionMark(0);\r
1289                         m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);\r
1290                 }\r
1291         }\r
1292 \r
1293         if (!GetDlgItem(IDOK)->IsWindowVisible())\r
1294         {\r
1295                 temp.LoadString(IDS_MSGBOX_OK);\r
1296                 SetDlgItemText(IDCANCEL, temp);\r
1297         }\r
1298 \r
1299         RefreshCursor();\r
1300         // make sure the filter is applied (if any) now, after we refreshed/fetched\r
1301         // the log messages\r
1302         PostMessage(WM_TIMER, LOGFILTER_TIMER);\r
1303 \r
1304         return 0;\r
1305 }\r
1306 \r
1307 void CLogDlg::CopySelectionToClipBoard()\r
1308 {\r
1309 #if 0\r
1310         CString sClipdata;\r
1311         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1312         if (pos != NULL)\r
1313         {\r
1314                 CString sRev;\r
1315                 sRev.LoadString(IDS_LOG_REVISION);\r
1316                 CString sAuthor;\r
1317                 sAuthor.LoadString(IDS_LOG_AUTHOR);\r
1318                 CString sDate;\r
1319                 sDate.LoadString(IDS_LOG_DATE);\r
1320                 CString sMessage;\r
1321                 sMessage.LoadString(IDS_LOG_MESSAGE);\r
1322                 while (pos)\r
1323                 {\r
1324                         CString sLogCopyText;\r
1325                         CString sPaths;\r
1326                         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1327                         LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;\r
1328                         for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)\r
1329                         {\r
1330                                 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
1331                                 sPaths += cpath->GetAction() + _T(" : ") + cpath->sPath;\r
1332                                 if (cpath->sCopyFromPath.IsEmpty())\r
1333                                         sPaths += _T("\r\n");\r
1334                                 else\r
1335                                 {\r
1336                                         CString sCopyFrom;\r
1337                                         sCopyFrom.Format(_T(" (%s: %s, %s, %ld)\r\n"), CString(MAKEINTRESOURCE(IDS_LOG_COPYFROM)), \r
1338                                                 (LPCTSTR)cpath->sCopyFromPath, \r
1339                                                 (LPCTSTR)CString(MAKEINTRESOURCE(IDS_LOG_REVISION)), \r
1340                                                 (LPCTSTR)cpath->lCopyFromRev);\r
1341                                         sPaths += sCopyFrom;\r
1342                                 }\r
1343                         }\r
1344                         sPaths.Trim();\r
1345                         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
1346                                 (LPCTSTR)sRev, pLogEntry->Rev,\r
1347                                 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->sAuthor,\r
1348                                 (LPCTSTR)sDate, (LPCTSTR)pLogEntry->sDate,\r
1349                                 (LPCTSTR)sMessage, (LPCTSTR)pLogEntry->sMessage,\r
1350                                 (LPCTSTR)sPaths);\r
1351                         sClipdata +=  sLogCopyText;\r
1352                 }\r
1353                 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());\r
1354         }\r
1355 #endif\r
1356 }\r
1357 \r
1358 void CLogDlg::CopyChangedSelectionToClipBoard()\r
1359 {\r
1360 #if 0\r
1361         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1362         if (pos == NULL)\r
1363                 return; // nothing is selected, get out of here\r
1364 \r
1365         CString sPaths;\r
1366 \r
1367         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1368         if (pos)\r
1369         {\r
1370                 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();\r
1371                 while (pos)\r
1372                 {\r
1373                         int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);\r
1374                         sPaths += m_currentChangedPathList[nItem].GetGitPathString();\r
1375                         sPaths += _T("\r\n");\r
1376                 }\r
1377         }\r
1378         else\r
1379         {\r
1380                 // only one revision is selected in the log dialog top pane\r
1381                 // but multiple items could be selected  in the changed items list\r
1382                 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();\r
1383                 while (pos)\r
1384                 {\r
1385                         int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);\r
1386                         LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->GetAt(nItem);\r
1387 \r
1388                         if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)\r
1389                         {\r
1390                                 // some items are hidden! So find out which item the user really selected\r
1391                                 INT_PTR selRealIndex = -1;\r
1392                                 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)\r
1393                                 {\r
1394                                         if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)\r
1395                                                 selRealIndex++;\r
1396                                         if (selRealIndex == nItem)\r
1397                                         {\r
1398                                                 changedlogpath = pLogEntry->pArChangedPaths->GetAt(hiddenindex);\r
1399                                                 break;\r
1400                                         }\r
1401                                 }\r
1402                         }\r
1403                         if (changedlogpath)\r
1404                         {\r
1405                                 sPaths += changedlogpath->sPath;\r
1406                                 sPaths += _T("\r\n");\r
1407                         }\r
1408                 }\r
1409         }\r
1410         sPaths.Trim();\r
1411         CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());\r
1412 #endif\r
1413 }\r
1414 \r
1415 BOOL CLogDlg::IsDiffPossible(LogChangedPath * changedpath, git_revnum_t rev)\r
1416 {\r
1417 #if 0\r
1418         CString added, deleted;\r
1419         if (changedpath == NULL)\r
1420                 return false;\r
1421 \r
1422         if ((rev > 1)&&(changedpath->action != LOGACTIONS_DELETED))\r
1423         {\r
1424                 if (changedpath->action == LOGACTIONS_ADDED) // file is added\r
1425                 {\r
1426                         if (changedpath->lCopyFromRev == 0)\r
1427                                 return FALSE; // but file was not added with history\r
1428                 }\r
1429                 return TRUE;\r
1430         }\r
1431 #endif\r
1432         return FALSE;\r
1433 }\r
1434 \r
1435 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)\r
1436 {\r
1437         // we have two separate context menus:\r
1438         // one shown on the log message list control,\r
1439         // the other shown in the changed-files list control\r
1440         int selCount = m_LogList.GetSelectedCount();\r
1441         if (pWnd == &m_LogList)\r
1442         {\r
1443                 ShowContextMenuForRevisions(pWnd, point);\r
1444         }\r
1445         else if (pWnd == &m_ChangedFileListCtrl)\r
1446         {\r
1447                 ShowContextMenuForChangedpaths(pWnd, point);\r
1448         }\r
1449         else if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))\r
1450         {\r
1451                 POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1452                 int selIndex = -1;\r
1453                 if (pos)\r
1454                         selIndex = m_LogList.GetNextSelectedItem(pos);\r
1455                 if ((point.x == -1) && (point.y == -1))\r
1456                 {\r
1457                         CRect rect;\r
1458                         GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);\r
1459                         ClientToScreen(&rect);\r
1460                         point = rect.CenterPoint();\r
1461                 }\r
1462                 CString sMenuItemText;\r
1463                 CMenu popup;\r
1464                 if (popup.CreatePopupMenu())\r
1465                 {\r
1466                         // add the 'default' entries\r
1467                         sMenuItemText.LoadString(IDS_SCIEDIT_COPY);\r
1468                         popup.AppendMenu(MF_STRING | MF_ENABLED, WM_COPY, sMenuItemText);\r
1469                         sMenuItemText.LoadString(IDS_SCIEDIT_SELECTALL);\r
1470                         popup.AppendMenu(MF_STRING | MF_ENABLED, EM_SETSEL, sMenuItemText);\r
1471 \r
1472                         if (selIndex >= 0)\r
1473                         {\r
1474                                 popup.AppendMenu(MF_SEPARATOR);\r
1475                                 sMenuItemText.LoadString(IDS_LOG_POPUP_EDITLOG);\r
1476                                 popup.AppendMenu(MF_STRING | MF_ENABLED, ID_EDITAUTHOR, sMenuItemText);\r
1477                         }\r
1478 \r
1479                         int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);\r
1480                         switch (cmd)\r
1481                         {\r
1482                         case 0:\r
1483                                 break;  // no command selected\r
1484                         case EM_SETSEL:\r
1485                         case WM_COPY:\r
1486                                 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);\r
1487                                 break;\r
1488                         case ID_EDITAUTHOR:\r
1489                                 EditLogMessage(selIndex);\r
1490                                 break;\r
1491                         }\r
1492                 }\r
1493         }\r
1494 }\r
1495 \r
1496 bool CLogDlg::IsSelectionContinuous()\r
1497 {\r
1498         if ( m_LogList.GetSelectedCount()==1 )\r
1499         {\r
1500                 // if only one revision is selected, the selection is of course\r
1501                 // continuous\r
1502                 return true;\r
1503         }\r
1504 \r
1505         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1506         bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());\r
1507         if (bContinuous)\r
1508         {\r
1509                 int itemindex = m_LogList.GetNextSelectedItem(pos);\r
1510                 while (pos)\r
1511                 {\r
1512                         int nextindex = m_LogList.GetNextSelectedItem(pos);\r
1513                         if (nextindex - itemindex > 1)\r
1514                         {\r
1515                                 bContinuous = false;\r
1516                                 break;\r
1517                         }\r
1518                         itemindex = nextindex;\r
1519                 }\r
1520         }\r
1521         return bContinuous;\r
1522 }\r
1523 \r
1524 LRESULT CLogDlg::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)\r
1525 {\r
1526 #if 0\r
1527     ASSERT(m_pFindDialog != NULL);\r
1528 \r
1529     if (m_pFindDialog->IsTerminating())\r
1530     {\r
1531             // invalidate the handle identifying the dialog box.\r
1532         m_pFindDialog = NULL;\r
1533         return 0;\r
1534     }\r
1535 \r
1536     if(m_pFindDialog->FindNext())\r
1537     {\r
1538         //read data from dialog\r
1539         CString FindText = m_pFindDialog->GetFindString();\r
1540         bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);\r
1541                 bool bFound = false;\r
1542                 tr1::wregex pat;\r
1543                 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);\r
1544 \r
1545                 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;\r
1546 \r
1547                 int i;\r
1548                 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)\r
1549                 {\r
1550                         if (bRegex)\r
1551                         {\r
1552                                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));\r
1553 \r
1554                                 if (regex_search(wstring((LPCTSTR)pLogEntry->sMessage), pat, flags))\r
1555                                 {\r
1556                                         bFound = true;\r
1557                                         break;\r
1558                                 }\r
1559                                 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;\r
1560                                 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)\r
1561                                 {\r
1562                                         LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
1563                                         if (regex_search(wstring((LPCTSTR)cpath->sCopyFromPath), pat, flags))\r
1564                                         {\r
1565                                                 bFound = true;\r
1566                                                 --i;\r
1567                                                 break;\r
1568                                         }\r
1569                                         if (regex_search(wstring((LPCTSTR)cpath->sPath), pat, flags))\r
1570                                         {\r
1571                                                 bFound = true;\r
1572                                                 --i;\r
1573                                                 break;\r
1574                                         }\r
1575                                 }\r
1576                         }\r
1577                         else\r
1578                         {\r
1579                                 if (bMatchCase)\r
1580                                 {\r
1581                                         if (m_logEntries[i]->sMessage.Find(FindText) >= 0)\r
1582                                         {\r
1583                                                 bFound = true;\r
1584                                                 break;\r
1585                                         }\r
1586                                         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));\r
1587                                         LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;\r
1588                                         for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)\r
1589                                         {\r
1590                                                 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
1591                                                 if (cpath->sCopyFromPath.Find(FindText)>=0)\r
1592                                                 {\r
1593                                                         bFound = true;\r
1594                                                         --i;\r
1595                                                         break;\r
1596                                                 }\r
1597                                                 if (cpath->sPath.Find(FindText)>=0)\r
1598                                                 {\r
1599                                                         bFound = true;\r
1600                                                         --i;\r
1601                                                         break;\r
1602                                                 }\r
1603                                         }\r
1604                                 }\r
1605                                 else\r
1606                                 {\r
1607                                     PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));\r
1608                                         CString msg = pLogEntry->sMessage;\r
1609                                         msg = msg.MakeLower();\r
1610                                         CString find = FindText.MakeLower();\r
1611                                         if (msg.Find(find) >= 0)\r
1612                                         {\r
1613                                                 bFound = TRUE;\r
1614                                                 break;\r
1615                                         }\r
1616                                         LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;\r
1617                                         for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)\r
1618                                         {\r
1619                                                 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
1620                                                 CString lowerpath = cpath->sCopyFromPath;\r
1621                                                 lowerpath.MakeLower();\r
1622                                                 if (lowerpath.Find(find)>=0)\r
1623                                                 {\r
1624                                                         bFound = TRUE;\r
1625                                                         --i;\r
1626                                                         break;\r
1627                                                 }\r
1628                                                 lowerpath = cpath->sPath;\r
1629                                                 lowerpath.MakeLower();\r
1630                                                 if (lowerpath.Find(find)>=0)\r
1631                                                 {\r
1632                                                         bFound = TRUE;\r
1633                                                         --i;\r
1634                                                         break;\r
1635                                                 }\r
1636                                         }\r
1637                                 } \r
1638                         }\r
1639                 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)\r
1640                 if (bFound)\r
1641                 {\r
1642                         this->m_nSearchIndex = (i+1);\r
1643                         m_LogList.EnsureVisible(i, FALSE);\r
1644                         m_LogList.SetItemState(m_LogList.GetSelectionMark(), 0, LVIS_SELECTED);\r
1645                         m_LogList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);\r
1646                         m_LogList.SetSelectionMark(i);\r
1647                         FillLogMessageCtrl();\r
1648                         UpdateData(FALSE);\r
1649                         m_nSearchIndex++;\r
1650                         if (m_nSearchIndex >= m_arShownList.GetCount())\r
1651                                 m_nSearchIndex = (int)m_arShownList.GetCount()-1;\r
1652                 }\r
1653     } // if(m_pFindDialog->FindNext()) \r
1654         UpdateLogInfoLabel();\r
1655 #endif\r
1656     return 0;\r
1657 }\r
1658 \r
1659 void CLogDlg::OnOK()\r
1660 {\r
1661 #if 0 \r
1662         // since the log dialog is also used to select revisions for other\r
1663         // dialogs, we have to do some work before closing this dialog\r
1664         if (GetFocus() != GetDlgItem(IDOK))\r
1665                 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter\r
1666         if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))\r
1667                 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.\r
1668 \r
1669         CString temp;\r
1670         CString buttontext;\r
1671         GetDlgItemText(IDOK, buttontext);\r
1672         temp.LoadString(IDS_MSGBOX_CANCEL);\r
1673         if (temp.Compare(buttontext) != 0)\r
1674                 __super::OnOK();        // only exit if the button text matches, and that will match only if the thread isn't running anymore\r
1675         m_bCancelled = TRUE;\r
1676         m_selectedRevs.Clear();\r
1677         m_selectedRevsOneRange.Clear();\r
1678         if (m_pNotifyWindow)\r
1679         {\r
1680                 int selIndex = m_LogList.GetSelectionMark();\r
1681                 if (selIndex >= 0)\r
1682                 {       \r
1683                     PLOGENTRYDATA pLogEntry = NULL;\r
1684                         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1685                         pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1686                         m_selectedRevs.AddRevision(pLogEntry->Rev);\r
1687                         git_revnum_t lowerRev = pLogEntry->Rev;\r
1688                         git_revnum_t higherRev = lowerRev;\r
1689                         while (pos)\r
1690                         {\r
1691                             pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1692                                 git_revnum_t rev = pLogEntry->Rev;\r
1693                                 m_selectedRevs.AddRevision(pLogEntry->Rev);\r
1694                                 if (lowerRev > rev)\r
1695                                         lowerRev = rev;\r
1696                                 if (higherRev < rev)\r
1697                                         higherRev = rev;\r
1698                         }\r
1699                         if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())\r
1700                         {\r
1701                                 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);\r
1702                         }\r
1703                         BOOL bSentMessage = FALSE;\r
1704                         if (m_LogList.GetSelectedCount() == 1)\r
1705                         {\r
1706                                 // if only one revision is selected, check if the path/url with which the dialog was started\r
1707                                 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.\r
1708                                 // if it was copied, use the copy from revision as lowerRev\r
1709                                 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))\r
1710                                 {\r
1711                                         CString sUrl = m_path.GetGitPathString();\r
1712                                         if (!m_path.IsUrl())\r
1713                                         {\r
1714                                                 sUrl = GetURLFromPath(m_path);\r
1715                                         }\r
1716                                         sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());\r
1717                                         for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)\r
1718                                         {\r
1719                                                 LogChangedPath * pData = pLogEntry->pArChangedPaths->GetAt(cp);\r
1720                                                 if (pData)\r
1721                                                 {\r
1722                                                         if (sUrl.Compare(pData->sPath) == 0)\r
1723                                                         {\r
1724                                                                 if (!pData->sCopyFromPath.IsEmpty())\r
1725                                                                 {\r
1726                                                                         lowerRev = pData->lCopyFromRev;\r
1727                                                                         m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);\r
1728                                                                         m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);\r
1729                                                                         m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);\r
1730                                                                         bSentMessage = TRUE;\r
1731                                                                 }\r
1732                                                         }\r
1733                                                 }\r
1734                                         }\r
1735                                 }\r
1736                         }\r
1737                         if ( !bSentMessage )\r
1738                         {\r
1739                                 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);\r
1740                                 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);\r
1741                                 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);\r
1742                                 if (m_selectedRevsOneRange.GetCount())\r
1743                                         m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);\r
1744                         }\r
1745                 }\r
1746         }\r
1747         UpdateData();\r
1748         if (m_bSaveStrict)\r
1749                 m_regLastStrict = m_bStrict;\r
1750         CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry"));\r
1751         reg = m_btnShow.GetCurrentEntry();\r
1752         SaveSplitterPos();\r
1753 #endif \r
1754 }\r
1755 \r
1756 void CLogDlg::OnNMDblclkChangedFileList(NMHDR * /*pNMHDR*/, LRESULT *pResult)\r
1757 {\r
1758         // a double click on an entry in the changed-files list has happened\r
1759         *pResult = 0;\r
1760 \r
1761         DiffSelectedFile();\r
1762 }\r
1763 \r
1764 void CLogDlg::DiffSelectedFile()\r
1765 {\r
1766 #if 0\r
1767         if (m_bThreadRunning)\r
1768                 return;\r
1769         UpdateLogInfoLabel();\r
1770         INT_PTR selIndex = m_ChangedFileListCtrl.GetSelectionMark();\r
1771         if (selIndex < 0)\r
1772                 return;\r
1773         if (m_ChangedFileListCtrl.GetSelectedCount() == 0)\r
1774                 return;\r
1775         // find out if there's an entry selected in the log list\r
1776         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1777         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1778         git_revnum_t rev1 = pLogEntry->Rev;\r
1779         git_revnum_t rev2 = rev1;\r
1780         if (pos)\r
1781         {\r
1782                 while (pos)\r
1783                 {\r
1784                         // there's at least a second entry selected in the log list: several revisions selected!\r
1785                         pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1786                         if (pLogEntry)\r
1787                         {\r
1788                                 rev1 = max(rev1,(long)pLogEntry->Rev);\r
1789                                 rev2 = min(rev2,(long)pLogEntry->Rev);\r
1790                         }\r
1791                 }\r
1792                 rev2--;\r
1793                 // now we have both revisions selected in the log list, so we can do a diff of the selected\r
1794                 // entry in the changed files list with these two revisions.\r
1795                 DoDiffFromLog(selIndex, rev1, rev2, false, false);\r
1796         }\r
1797         else\r
1798         {\r
1799                 rev2 = rev1-1;\r
1800                 // nothing or only one revision selected in the log list\r
1801                 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);\r
1802 \r
1803                 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)\r
1804                 {\r
1805                         // some items are hidden! So find out which item the user really clicked on\r
1806                         INT_PTR selRealIndex = -1;\r
1807                         for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)\r
1808                         {\r
1809                                 if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)\r
1810                                         selRealIndex++;\r
1811                                 if (selRealIndex == selIndex)\r
1812                                 {\r
1813                                         selIndex = hiddenindex;\r
1814                                         changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);\r
1815                                         break;\r
1816                                 }\r
1817                         }\r
1818                 }\r
1819 \r
1820                 if (IsDiffPossible(changedpath, rev1))\r
1821                 {\r
1822                         // diffs with renamed files are possible\r
1823                         if ((changedpath)&&(!changedpath->sCopyFromPath.IsEmpty()))\r
1824                                 rev2 = changedpath->lCopyFromRev;\r
1825                         else\r
1826                         {\r
1827                                 // if the path was modified but the parent path was 'added with history'\r
1828                                 // then we have to use the copy from revision of the parent path\r
1829                                 CTGitPath cpath = CTGitPath(changedpath->sPath);\r
1830                                 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)\r
1831                                 {\r
1832                                         CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->GetAt(flist)->sPath);\r
1833                                         if (p.IsAncestorOf(cpath))\r
1834                                         {\r
1835                                                 if (!pLogEntry->pArChangedPaths->GetAt(flist)->sCopyFromPath.IsEmpty())\r
1836                                                         rev2 = pLogEntry->pArChangedPaths->GetAt(flist)->lCopyFromRev;\r
1837                                         }\r
1838                                 }\r
1839                         }\r
1840                         DoDiffFromLog(selIndex, rev1, rev2, false, false);\r
1841                 }\r
1842                 else \r
1843                 {\r
1844                         CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));\r
1845                         CTGitPath tempfile2 = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));\r
1846                         GitRev r = rev1;\r
1847                         // deleted files must be opened from the revision before the deletion\r
1848                         if (changedpath->action == LOGACTIONS_DELETED)\r
1849                                 r = rev1-1;\r
1850                         m_bCancelled = false;\r
1851 \r
1852                         CProgressDlg progDlg;\r
1853                         progDlg.SetTitle(IDS_APPNAME);\r
1854                         progDlg.SetAnimation(IDR_DOWNLOAD);\r
1855                         CString sInfoLine;\r
1856                         sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)(m_sRepositoryRoot + changedpath->sPath), (LPCTSTR)r.ToString());\r
1857                         progDlg.SetLine(1, sInfoLine, true);\r
1858                         SetAndClearProgressInfo(&progDlg);\r
1859                         progDlg.ShowModeless(m_hWnd);\r
1860 \r
1861                         if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), r, r, tempfile))\r
1862                         {\r
1863                                 m_bCancelled = false;\r
1864                                 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), GitRev::REV_HEAD, r, tempfile))\r
1865                                 {\r
1866                                         progDlg.Stop();\r
1867                                         SetAndClearProgressInfo((HWND)NULL);\r
1868                                         CMessageBox::Show(m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
1869                                         return;\r
1870                                 }\r
1871                         }\r
1872                         progDlg.Stop();\r
1873                         SetAndClearProgressInfo((HWND)NULL);\r
1874 \r
1875                         CString sName1, sName2;\r
1876                         sName1.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1);\r
1877                         sName2.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1-1);\r
1878                         CAppUtils::DiffFlags flags;\r
1879                         flags.AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1880                         if (changedpath->action == LOGACTIONS_DELETED)\r
1881                                 CAppUtils::StartExtDiff(tempfile, tempfile2, sName2, sName1, flags);\r
1882                         else\r
1883                                 CAppUtils::StartExtDiff(tempfile2, tempfile, sName2, sName1, flags);\r
1884                 }\r
1885         }\r
1886 #endif \r
1887 }\r
1888 \r
1889 \r
1890 void CLogDlg::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)\r
1891 {\r
1892         // a double click on an entry in the revision list has happened\r
1893         *pResult = 0;\r
1894 \r
1895   if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))\r
1896           DiffSelectedRevWithPrevious();\r
1897 }\r
1898 \r
1899 void CLogDlg::DiffSelectedRevWithPrevious()\r
1900 {\r
1901 #if 0\r
1902         if (m_bThreadRunning)\r
1903                 return;\r
1904         UpdateLogInfoLabel();\r
1905         int selIndex = m_LogList.GetSelectionMark();\r
1906         if (selIndex < 0)\r
1907                 return;\r
1908         int selCount = m_LogList.GetSelectedCount();\r
1909         if (selCount != 1)\r
1910                 return;\r
1911 \r
1912         // Find selected entry in the log list\r
1913         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1914         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1915         long rev1 = pLogEntry->Rev;\r
1916         long rev2 = rev1-1;\r
1917         CTGitPath path = m_path;\r
1918 \r
1919         // See how many files under the relative root were changed in selected revision\r
1920         int nChanged = 0;\r
1921         LogChangedPath * changed = NULL;\r
1922         for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)\r
1923         {\r
1924                 LogChangedPath * cpath = pLogEntry->pArChangedPaths->GetAt(c);\r
1925                 if (cpath  &&  cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)\r
1926                 {\r
1927                         ++nChanged;\r
1928                         changed = cpath;\r
1929                 }\r
1930         }\r
1931 \r
1932         if (m_path.IsDirectory() && nChanged == 1) \r
1933         {\r
1934                 // We're looking at the log for a directory and only one file under dir was changed in the revision\r
1935                 // Do diff on that file instead of whole directory\r
1936                 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));\r
1937         } \r
1938 \r
1939         m_bCancelled = FALSE;\r
1940         DialogEnableWindow(IDOK, FALSE);\r
1941         SetPromptApp(&theApp);\r
1942         theApp.DoWaitCursor(1);\r
1943 \r
1944         if (PromptShown())\r
1945         {\r
1946                 GitDiff diff(this, m_hWnd, true);\r
1947                 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1948                 diff.SetHEADPeg(m_LogRevision);\r
1949                 diff.ShowCompare(path, rev2, path, rev1);\r
1950         }\r
1951         else\r
1952         {\r
1953                 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1954         }\r
1955 \r
1956         theApp.DoWaitCursor(-1);\r
1957         EnableOKButton();\r
1958 #endif\r
1959 }\r
1960 \r
1961 void CLogDlg::DoDiffFromLog(INT_PTR selIndex, git_revnum_t rev1, git_revnum_t rev2, bool blame, bool unified)\r
1962 {\r
1963 #if 0\r
1964         DialogEnableWindow(IDOK, FALSE);\r
1965         SetPromptApp(&theApp);\r
1966         theApp.DoWaitCursor(1);\r
1967         //get the filename\r
1968         CString filepath;\r
1969         if (Git::PathIsURL(m_path))\r
1970         {\r
1971                 filepath = m_path.GetGitPathString();\r
1972         }\r
1973         else\r
1974         {\r
1975                 filepath = GetURLFromPath(m_path);\r
1976                 if (filepath.IsEmpty())\r
1977                 {\r
1978                         theApp.DoWaitCursor(-1);\r
1979                         CString temp;\r
1980                         temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);\r
1981                         CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);\r
1982                         TRACE(_T("could not retrieve the URL of the file!\n"));\r
1983                         EnableOKButton();\r
1984                         theApp.DoWaitCursor(-11);\r
1985                         return;         //exit\r
1986                 }\r
1987         }\r
1988         m_bCancelled = FALSE;\r
1989         filepath = GetRepositoryRoot(CTGitPath(filepath));\r
1990 \r
1991         CString firstfile, secondfile;\r
1992         if (m_LogList.GetSelectedCount()==1)\r
1993         {\r
1994                 int s = m_LogList.GetSelectionMark();\r
1995                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(s));\r
1996                 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);\r
1997                 firstfile = changedpath->sPath;\r
1998                 secondfile = firstfile;\r
1999                 if ((rev2 == rev1-1)&&(changedpath->lCopyFromRev > 0)) // is it an added file with history?\r
2000                 {\r
2001                         secondfile = changedpath->sCopyFromPath;\r
2002                         rev2 = changedpath->lCopyFromRev;\r
2003                 }\r
2004         }\r
2005         else\r
2006         {\r
2007                 firstfile = m_currentChangedPathList[selIndex].GetGitPathString();\r
2008                 secondfile = firstfile;\r
2009         }\r
2010 \r
2011         firstfile = filepath + firstfile.Trim();\r
2012         secondfile = filepath + secondfile.Trim();\r
2013 \r
2014         GitDiff diff(this, this->m_hWnd, true);\r
2015         diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
2016         diff.SetHEADPeg(m_LogRevision);\r
2017         if (unified)\r
2018         {\r
2019                 if (PromptShown())\r
2020                         diff.ShowUnifiedDiff(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1);\r
2021                 else\r
2022                         CAppUtils::StartShowUnifiedDiff(m_hWnd, CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), m_LogRevision);\r
2023         }\r
2024         else\r
2025         {\r
2026                 if (diff.ShowCompare(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), false, blame))\r
2027                 {\r
2028                         if (firstfile.Compare(secondfile)==0)\r
2029                         {\r
2030                                 git_revnum_t baseRev = 0;\r
2031                                 diff.DiffProps(CTGitPath(firstfile), rev2, rev1, baseRev);\r
2032                         }\r
2033                 }\r
2034         }\r
2035         theApp.DoWaitCursor(-1);\r
2036         EnableOKButton();\r
2037 #endif\r
2038 }\r
2039 \r
2040 BOOL CLogDlg::Open(bool bOpenWith,CString changedpath, git_revnum_t rev)\r
2041 {\r
2042 #if 0\r
2043         DialogEnableWindow(IDOK, FALSE);\r
2044         SetPromptApp(&theApp);\r
2045         theApp.DoWaitCursor(1);\r
2046         CString filepath;\r
2047         if (Git::PathIsURL(m_path))\r
2048         {\r
2049                 filepath = m_path.GetGitPathString();\r
2050         }\r
2051         else\r
2052         {\r
2053                 filepath = GetURLFromPath(m_path);\r
2054                 if (filepath.IsEmpty())\r
2055                 {\r
2056                         theApp.DoWaitCursor(-1);\r
2057                         CString temp;\r
2058                         temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);\r
2059                         CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);\r
2060                         TRACE(_T("could not retrieve the URL of the file!\n"));\r
2061                         EnableOKButton();\r
2062                         return FALSE;\r
2063                 }\r
2064         }\r
2065         m_bCancelled = false;\r
2066         filepath = GetRepositoryRoot(CTGitPath(filepath));\r
2067         filepath += changedpath;\r
2068 \r
2069         CProgressDlg progDlg;\r
2070         progDlg.SetTitle(IDS_APPNAME);\r
2071         progDlg.SetAnimation(IDR_DOWNLOAD);\r
2072         CString sInfoLine;\r
2073         sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)GitRev(rev).ToString());\r
2074         progDlg.SetLine(1, sInfoLine, true);\r
2075         SetAndClearProgressInfo(&progDlg);\r
2076         progDlg.ShowModeless(m_hWnd);\r
2077 \r
2078         CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(filepath), rev);\r
2079         m_bCancelled = false;\r
2080         if (!Cat(CTGitPath(filepath), GitRev(rev), rev, tempfile))\r
2081         {\r
2082                 progDlg.Stop();\r
2083                 SetAndClearProgressInfo((HWND)NULL);\r
2084                 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
2085                 EnableOKButton();\r
2086                 theApp.DoWaitCursor(-1);\r
2087                 return FALSE;\r
2088         }\r
2089         progDlg.Stop();\r
2090         SetAndClearProgressInfo((HWND)NULL);\r
2091         SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);\r
2092         if (!bOpenWith)\r
2093         {\r
2094                 int ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);\r
2095                 if (ret <= HINSTANCE_ERROR)\r
2096                         bOpenWith = true;\r
2097         }\r
2098         if (bOpenWith)\r
2099         {\r
2100                 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");\r
2101                 cmd += tempfile.GetWinPathString() + _T(" ");\r
2102                 CAppUtils::LaunchApplication(cmd, NULL, false);\r
2103         }\r
2104         EnableOKButton();\r
2105         theApp.DoWaitCursor(-1);\r
2106 #endif\r
2107         return TRUE;\r
2108 }\r
2109 \r
2110 void CLogDlg::EditAuthor(const CLogDataVector& logs)\r
2111 {\r
2112 #if 0\r
2113         CString url;\r
2114         CString name;\r
2115         if (logs.size() == 0)\r
2116                 return;\r
2117         DialogEnableWindow(IDOK, FALSE);\r
2118         SetPromptApp(&theApp);\r
2119         theApp.DoWaitCursor(1);\r
2120         if (Git::PathIsURL(m_path))\r
2121                 url = m_path.GetGitPathString();\r
2122         else\r
2123         {\r
2124                 url = GetURLFromPath(m_path);\r
2125         }\r
2126         name = Git_PROP_REVISION_AUTHOR;\r
2127 \r
2128         CString value = RevPropertyGet(name, CTGitPath(url), logs[0]->Rev);\r
2129         CString sOldValue = value;\r
2130         value.Replace(_T("\n"), _T("\r\n"));\r
2131         CInputDlg dlg(this);\r
2132         dlg.m_sHintText.LoadString(IDS_LOG_AUTHOR);\r
2133         dlg.m_sInputText = value;\r
2134         dlg.m_sTitle.LoadString(IDS_LOG_AUTHOREDITTITLE);\r
2135         dlg.m_pProjectProperties = &m_ProjectProperties;\r
2136         dlg.m_bUseLogWidth = false;\r
2137         if (dlg.DoModal() == IDOK)\r
2138         {\r
2139                 dlg.m_sInputText.Replace(_T("\r"), _T(""));\r
2140 \r
2141                 LogCache::CCachedLogInfo* toUpdate \r
2142                         = GetLogCache (CTGitPath (m_sRepositoryRoot));\r
2143 \r
2144                 CProgressDlg progDlg;\r
2145                 progDlg.SetTitle(IDS_APPNAME);\r
2146                 progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));\r
2147                 progDlg.SetTime(true);\r
2148                 progDlg.SetShowProgressBar(true);\r
2149                 progDlg.ShowModeless(m_hWnd);\r
2150                 for (DWORD i=0; i<logs.size(); ++i)\r
2151                 {\r
2152                         if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), logs[i]->Rev))\r
2153                         {\r
2154                                 progDlg.Stop();\r
2155                                 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
2156                                 break;\r
2157                         }\r
2158                         else\r
2159                         {\r
2160 \r
2161                                 logs[i]->sAuthor = dlg.m_sInputText;\r
2162                                 m_LogList.Invalidate();\r
2163 \r
2164                                 // update the log cache \r
2165 \r
2166                                 if (toUpdate != NULL)\r
2167                                 {\r
2168                                         // log caching is active\r
2169 \r
2170                                         LogCache::CCachedLogInfo newInfo;\r
2171                                         newInfo.Insert ( logs[i]->Rev\r
2172                                                 , (const char*) CUnicodeUtils::GetUTF8 (logs[i]->sAuthor)\r
2173                                                 , ""\r
2174                                                 , 0\r
2175                                                 , LogCache::CRevisionInfoContainer::HAS_AUTHOR);\r
2176 \r
2177                                         toUpdate->Update (newInfo);\r
2178                                 }\r
2179                         }\r
2180                         progDlg.SetProgress64(i, logs.size());\r
2181                 }\r
2182                 progDlg.Stop();\r
2183         }\r
2184         theApp.DoWaitCursor(-1);\r
2185         EnableOKButton();\r
2186 #endif\r
2187 }\r
2188 \r
2189 void CLogDlg::EditLogMessage(int index)\r
2190 {\r
2191 #if 0\r
2192         CString url;\r
2193         CString name;\r
2194         DialogEnableWindow(IDOK, FALSE);\r
2195         SetPromptApp(&theApp);\r
2196         theApp.DoWaitCursor(1);\r
2197         if (Git::PathIsURL(m_path))\r
2198                 url = m_path.GetGitPathString();\r
2199         else\r
2200         {\r
2201                 url = GetURLFromPath(m_path);\r
2202         }\r
2203         name = Git_PROP_REVISION_LOG;\r
2204 \r
2205         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(index));\r
2206         m_bCancelled = FALSE;\r
2207         CString value = RevPropertyGet(name, CTGitPath(url), pLogEntry->Rev);\r
2208         CString sOldValue = value;\r
2209         value.Replace(_T("\n"), _T("\r\n"));\r
2210         CInputDlg dlg(this);\r
2211         dlg.m_sHintText.LoadString(IDS_LOG_MESSAGE);\r
2212         dlg.m_sInputText = value;\r
2213         dlg.m_sTitle.LoadString(IDS_LOG_MESSAGEEDITTITLE);\r
2214         dlg.m_pProjectProperties = &m_ProjectProperties;\r
2215         dlg.m_bUseLogWidth = true;\r
2216         if (dlg.DoModal() == IDOK)\r
2217         {\r
2218                 dlg.m_sInputText.Replace(_T("\r"), _T(""));\r
2219                 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), pLogEntry->Rev))\r
2220                 {\r
2221                         CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
2222                 }\r
2223                 else\r
2224                 {\r
2225                         pLogEntry->sShortMessage = MakeShortMessage(dlg.m_sInputText);\r
2226                         // split multi line log entries and concatenate them\r
2227                         // again but this time with \r\n as line separators\r
2228                         // so that the edit control recognizes them\r
2229                         if (dlg.m_sInputText.GetLength()>0)\r
2230                         {\r
2231                                 m_sMessageBuf = dlg.m_sInputText;\r
2232                                 dlg.m_sInputText.Replace(_T("\n\r"), _T("\n"));\r
2233                                 dlg.m_sInputText.Replace(_T("\r\n"), _T("\n"));\r
2234                                 if (dlg.m_sInputText.Right(1).Compare(_T("\n"))==0)\r
2235                                         dlg.m_sInputText = dlg.m_sInputText.Left(dlg.m_sInputText.GetLength()-1);\r
2236                         } \r
2237                         else\r
2238                                 dlg.m_sInputText.Empty();\r
2239                         pLogEntry->sMessage = dlg.m_sInputText;\r
2240                         pLogEntry->sBugIDs = m_ProjectProperties.FindBugID(dlg.m_sInputText);\r
2241                         CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);\r
2242                         pMsgView->SetWindowText(_T(" "));\r
2243                         pMsgView->SetWindowText(dlg.m_sInputText);\r
2244                         m_ProjectProperties.FindBugID(dlg.m_sInputText, pMsgView);\r
2245                         m_LogList.Invalidate();\r
2246         \r
2247             // update the log cache \r
2248 \r
2249             LogCache::CCachedLogInfo* toUpdate \r
2250                 = GetLogCache (CTGitPath (m_sRepositoryRoot));\r
2251             if (toUpdate != NULL)\r
2252             {\r
2253                 // log caching is active\r
2254 \r
2255                 LogCache::CCachedLogInfo newInfo;\r
2256                 newInfo.Insert ( pLogEntry->Rev\r
2257                                , ""\r
2258                                , (const char*) CUnicodeUtils::GetUTF8 (pLogEntry->sMessage)\r
2259                                , 0\r
2260                                , LogCache::CRevisionInfoContainer::HAS_COMMENT);\r
2261 \r
2262                 toUpdate->Update (newInfo);\r
2263             }\r
2264         }\r
2265         }\r
2266         theApp.DoWaitCursor(-1);\r
2267         EnableOKButton();\r
2268 #endif\r
2269 }\r
2270 \r
2271 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)\r
2272 {\r
2273         // Skip Ctrl-C when copying text out of the log message or search filter\r
2274         BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );\r
2275         if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')\r
2276         {\r
2277                 if (GetFocus()==GetDlgItem(IDC_LOGLIST))\r
2278                 {\r
2279                         if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))\r
2280                         {\r
2281                                 DiffSelectedRevWithPrevious();\r
2282                                 return TRUE;\r
2283                         }\r
2284                 }\r
2285                 if (GetFocus()==GetDlgItem(IDC_LOGMSG))\r
2286                 {\r
2287                         DiffSelectedFile();\r
2288                         return TRUE;\r
2289                 }\r
2290         }\r
2291         if (m_hAccel && !bSkipAccelerator)\r
2292         {\r
2293                 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);\r
2294                 if (ret)\r
2295                         return TRUE;\r
2296         }\r
2297         \r
2298         m_tooltips.RelayEvent(pMsg);\r
2299         return __super::PreTranslateMessage(pMsg);\r
2300 }\r
2301 \r
2302 BOOL CLogDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)\r
2303 {\r
2304         if (m_bThreadRunning)\r
2305         {\r
2306                 // only show the wait cursor over the list control\r
2307                 if ((pWnd)&&\r
2308                         ((pWnd == GetDlgItem(IDC_LOGLIST))||\r
2309                         (pWnd == GetDlgItem(IDC_MSGVIEW))||\r
2310                         (pWnd == GetDlgItem(IDC_LOGMSG))))\r
2311                 {\r
2312                         HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));\r
2313                         SetCursor(hCur);\r
2314                         return TRUE;\r
2315                 }\r
2316         }\r
2317         if ((pWnd) && (pWnd == GetDlgItem(IDC_MSGVIEW)))\r
2318                 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);\r
2319 \r
2320         HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));\r
2321         SetCursor(hCur);\r
2322         return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);\r
2323 }\r
2324 \r
2325 void CLogDlg::OnBnClickedHelp()\r
2326 {\r
2327         OnHelp();\r
2328 }\r
2329 \r
2330 void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
2331 {\r
2332         LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);\r
2333         *pResult = 0;\r
2334         if (m_bThreadRunning)\r
2335                 return;\r
2336         if (pNMLV->iItem >= 0)\r
2337         {\r
2338                 m_nSearchIndex = pNMLV->iItem;\r
2339                 if (pNMLV->iSubItem != 0)\r
2340                         return;\r
2341                 if ((pNMLV->iItem == m_arShownList.GetCount())&&(m_bStrict)&&(m_bStrictStopped))\r
2342                 {\r
2343                         // remove the selected state\r
2344                         if (pNMLV->uChanged & LVIF_STATE)\r
2345                         {\r
2346                                 m_LogList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);\r
2347                                 FillLogMessageCtrl();\r
2348                                 UpdateData(FALSE);\r
2349                                 UpdateLogInfoLabel();\r
2350                         }\r
2351                         return;\r
2352                 }\r
2353                 if (pNMLV->uChanged & LVIF_STATE)\r
2354                 {\r
2355                         FillLogMessageCtrl();\r
2356                         UpdateData(FALSE);\r
2357                 }\r
2358         }\r
2359         else\r
2360         {\r
2361                 FillLogMessageCtrl();\r
2362                 UpdateData(FALSE);\r
2363         }\r
2364         EnableOKButton();\r
2365         UpdateLogInfoLabel();\r
2366 }\r
2367 \r
2368 void CLogDlg::OnEnLinkMsgview(NMHDR *pNMHDR, LRESULT *pResult)\r
2369 {\r
2370         ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);\r
2371         if (pEnLink->msg == WM_LBUTTONUP)\r
2372         {\r
2373                 CString url, msg;\r
2374                 GetDlgItemText(IDC_MSGVIEW, msg);\r
2375                 msg.Replace(_T("\r\n"), _T("\n"));\r
2376                 url = msg.Mid(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax-pEnLink->chrg.cpMin);\r
2377                 if (!::PathIsURL(url))\r
2378                 {\r
2379                         url = m_ProjectProperties.GetBugIDUrl(url);\r
2380                         url = GetAbsoluteUrlFromRelativeUrl(url);\r
2381                 }\r
2382                 if (!url.IsEmpty())\r
2383                         ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);\r
2384         }\r
2385         *pResult = 0;\r
2386 }\r
2387 \r
2388 void CLogDlg::OnBnClickedStatbutton()\r
2389 {\r
2390 #if 0\r
2391         if (m_bThreadRunning)\r
2392                 return;\r
2393         if (m_arShownList.IsEmpty())\r
2394                 return;         // nothing is shown, so no statistics.\r
2395         // the statistics dialog expects the log entries to be sorted by date\r
2396         SortByColumn(3, false);\r
2397         CPtrArray shownlist;\r
2398         RecalculateShownList(&shownlist);\r
2399         // create arrays which are aware of the current filter\r
2400         CStringArray m_arAuthorsFiltered;\r
2401         CDWordArray m_arDatesFiltered;\r
2402         CDWordArray m_arFileChangesFiltered;\r
2403         for (INT_PTR i=0; i<shownlist.GetCount(); ++i)\r
2404         {\r
2405                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(shownlist.GetAt(i));\r
2406                 CString strAuthor = pLogEntry->sAuthor;\r
2407                 if ( strAuthor.IsEmpty() )\r
2408                 {\r
2409                         strAuthor.LoadString(IDS_STATGRAPH_EMPTYAUTHOR);\r
2410                 }\r
2411                 m_arAuthorsFiltered.Add(strAuthor);\r
2412                 m_arDatesFiltered.Add(static_cast<DWORD>(pLogEntry->tmDate));\r
2413                 m_arFileChangesFiltered.Add(pLogEntry->dwFileChanges);\r
2414         }\r
2415         CStatGraphDlg dlg;\r
2416         dlg.m_parAuthors = &m_arAuthorsFiltered;\r
2417         dlg.m_parDates = &m_arDatesFiltered;\r
2418         dlg.m_parFileChanges = &m_arFileChangesFiltered;\r
2419         dlg.m_path = m_path;\r
2420         dlg.DoModal();\r
2421         // restore the previous sorting\r
2422         SortByColumn(m_nSortColumn, m_bAscending);\r
2423         OnTimer(LOGFILTER_TIMER);\r
2424 #endif\r
2425 }\r
2426 \r
2427 void CLogDlg::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
2428 {\r
2429 \r
2430         NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );\r
2431         // Take the default processing unless we set this to something else below.\r
2432         *pResult = CDRF_DODEFAULT;\r
2433 \r
2434         if (m_bNoDispUpdates)\r
2435                 return;\r
2436 \r
2437         switch (pLVCD->nmcd.dwDrawStage)\r
2438         {\r
2439         case CDDS_PREPAINT:\r
2440                 {\r
2441                         *pResult = CDRF_NOTIFYITEMDRAW;\r
2442                         return;\r
2443                 }\r
2444                 break;\r
2445         case CDDS_ITEMPREPAINT:\r
2446                 {\r
2447                         // This is the prepaint stage for an item. Here's where we set the\r
2448                         // item's text color. \r
2449                         \r
2450                         // Tell Windows to send draw notifications for each subitem.\r
2451                         *pResult = CDRF_NOTIFYSUBITEMDRAW;\r
2452 \r
2453                         COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);\r
2454 \r
2455                         if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
2456                         {\r
2457                                 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);\r
2458                                 if (data)\r
2459                                 {\r
2460 #if 0\r
2461                                         if (data->bCopiedSelf)\r
2462                                         {\r
2463                                                 // only change the background color if the item is not 'hot' (on vista with themes enabled)\r
2464                                                 if (!theme.IsAppThemed() || !m_bVista || ((pLVCD->nmcd.uItemState & CDIS_HOT)==0))\r
2465                                                         pLVCD->clrTextBk = GetSysColor(COLOR_MENU);\r
2466                                         }\r
2467 \r
2468                                         if (data->bCopies)\r
2469                                                 crText = m_Colors.GetColor(CColors::Modified);\r
2470 #endif\r
2471 //                                      if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))\r
2472 //                                              crText = GetSysColor(COLOR_GRAYTEXT);\r
2473 //                                      if (data->Rev == m_wcRev)\r
2474 //                                      {\r
2475 //                                              SelectObject(pLVCD->nmcd.hdc, m_boldFont);\r
2476                                                 // We changed the font, so we're returning CDRF_NEWFONT. This\r
2477                                                 // tells the control to recalculate the extent of the text.\r
2478 //                                              *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;\r
2479 //                                      }\r
2480                                 }\r
2481                         }\r
2482                         if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
2483                         {\r
2484                                 if (m_bStrictStopped)\r
2485                                         crText = GetSysColor(COLOR_GRAYTEXT);\r
2486                         }\r
2487                         // Store the color back in the NMLVCUSTOMDRAW struct.\r
2488                         pLVCD->clrText = crText;\r
2489                         return;\r
2490                 }\r
2491                 break;\r
2492         case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:\r
2493                 {\r
2494                         if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))\r
2495                         {\r
2496                                 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);\r
2497                         }\r
2498                         if (pLVCD->iSubItem == 1)\r
2499                         {\r
2500                                 *pResult = CDRF_DODEFAULT;\r
2501 \r
2502                                 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
2503                                         return;\r
2504 \r
2505                                 int             nIcons = 0;\r
2506                                 int             iconwidth = ::GetSystemMetrics(SM_CXSMICON);\r
2507                                 int             iconheight = ::GetSystemMetrics(SM_CYSMICON);\r
2508 \r
2509                                 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec));\r
2510 \r
2511                                 // Get the selected state of the\r
2512                                 // item being drawn.\r
2513                                 LVITEM   rItem;\r
2514                                 SecureZeroMemory(&rItem, sizeof(LVITEM));\r
2515                                 rItem.mask  = LVIF_STATE;\r
2516                                 rItem.iItem = pLVCD->nmcd.dwItemSpec;\r
2517                                 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;\r
2518                                 m_LogList.GetItem(&rItem);\r
2519 \r
2520                                 CRect rect;\r
2521                                 m_LogList.GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);\r
2522 \r
2523                                 // Fill the background\r
2524                                 if (theme.IsAppThemed() && m_bVista)\r
2525                                 {\r
2526                                         theme.Open(m_hWnd, L"Explorer");\r
2527                                         int state = LISS_NORMAL;\r
2528                                         if (rItem.state & LVIS_SELECTED)\r
2529                                         {\r
2530                                                 if (::GetFocus() == m_LogList.m_hWnd)\r
2531                                                         state |= LISS_SELECTED;\r
2532                                                 else\r
2533                                                         state |= LISS_SELECTEDNOTFOCUS;\r
2534                                         }\r
2535                                         else\r
2536                                         {\r
2537 #if 0\r
2538                                                 if (pLogEntry->bCopiedSelf)\r
2539                                                 {\r
2540                                                         // unfortunately, the pLVCD->nmcd.uItemState does not contain valid\r
2541                                                         // information at this drawing stage. But we can check the whether the\r
2542                                                         // previous stage changed the background color of the item\r
2543                                                         if (pLVCD->clrTextBk == GetSysColor(COLOR_MENU))\r
2544                                                         {\r
2545                                                                 HBRUSH brush;\r
2546                                                                 brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));\r
2547                                                                 if (brush)\r
2548                                                                 {\r
2549                                                                         ::FillRect(pLVCD->nmcd.hdc, &rect, brush);\r
2550                                                                         ::DeleteObject(brush);\r
2551                                                                 }\r
2552                                                         }\r
2553                                                 }\r
2554 #endif\r
2555                                         }\r
2556 \r
2557                                         if (theme.IsBackgroundPartiallyTransparent(LVP_LISTDETAIL, state))\r
2558                                                 theme.DrawParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);\r
2559 \r
2560                                         theme.DrawBackground(pLVCD->nmcd.hdc, LVP_LISTDETAIL, state, &rect, NULL);\r
2561                                 }\r
2562                                 else\r
2563                                 {\r
2564                                         HBRUSH brush;\r
2565                                         if (rItem.state & LVIS_SELECTED)\r
2566                                         {\r
2567                                                 if (::GetFocus() == m_LogList.m_hWnd)\r
2568                                                         brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));\r
2569                                                 else\r
2570                                                         brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));\r
2571                                         }\r
2572                                         else\r
2573                                         {\r
2574                                                 //if (pLogEntry->bCopiedSelf)\r
2575                                                 //      brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));\r
2576                                                 //else\r
2577                                                         brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));\r
2578                                         }\r
2579                                         if (brush == NULL)\r
2580                                                 return;\r
2581 \r
2582                                         ::FillRect(pLVCD->nmcd.hdc, &rect, brush);\r
2583                                         ::DeleteObject(brush);\r
2584                                 }\r
2585 \r
2586                                 // Draw the icon(s) into the compatible DC\r
2587                                 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_MODIFIED)\r
2588                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
2589                                 nIcons++;\r
2590 \r
2591                                 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_ADDED)\r
2592                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
2593                                 nIcons++;\r
2594 \r
2595                                 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_DELETED)\r
2596                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
2597                                 nIcons++;\r
2598 \r
2599                                 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_REPLACED)\r
2600                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
2601                                 nIcons++;\r
2602                                 *pResult = CDRF_SKIPDEFAULT;\r
2603                                 return;\r
2604                         }\r
2605                 }\r
2606                 break;\r
2607         }\r
2608         *pResult = CDRF_DODEFAULT;\r
2609 \r
2610 }\r
2611 void CLogDlg::OnNMCustomdrawChangedFileList(NMHDR *pNMHDR, LRESULT *pResult)\r
2612 {\r
2613 \r
2614         NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );\r
2615         // Take the default processing unless we set this to something else below.\r
2616         *pResult = CDRF_DODEFAULT;\r
2617 \r
2618         if (m_bNoDispUpdates)\r
2619                 return;\r
2620 \r
2621         // First thing - check the draw stage. If it's the control's prepaint\r
2622         // stage, then tell Windows we want messages for every item.\r
2623 \r
2624         if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )\r
2625         {\r
2626                 *pResult = CDRF_NOTIFYITEMDRAW;\r
2627         }\r
2628         else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )\r
2629         {\r
2630                 // This is the prepaint stage for an item. Here's where we set the\r
2631                 // item's text color. Our return value will tell Windows to draw the\r
2632                 // item itself, but it will use the new color we set here.\r
2633 \r
2634                 // Tell Windows to paint the control itself.\r
2635                 *pResult = CDRF_DODEFAULT;\r
2636 \r
2637                 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);\r
2638                 bool bGrayed = false;\r
2639 #if 0\r
2640                 if ((m_cHidePaths.GetState() & 0x0003)==BST_INDETERMINATE)\r
2641                 {\r
2642                         if ((m_currentChangedArray)&&((m_currentChangedArray->GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)))\r
2643                         {\r
2644                                 //if ((*m_currentChangedArray)[(pLVCD->nmcd.dwItemSpec)]sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)!=0)\r
2645                                 {\r
2646                                         crText = GetSysColor(COLOR_GRAYTEXT);\r
2647                                         bGrayed = true;\r
2648                                 }\r
2649                         }\r
2650                         else if (m_currentChangedPathList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
2651                         {\r
2652                                 //if (m_currentChangedPathList[pLVCD->nmcd.dwItemSpec].GetGitPathString().Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)!=0)\r
2653                                 {\r
2654                                         crText = GetSysColor(COLOR_GRAYTEXT);\r
2655                                         bGrayed = true;\r
2656                                 }\r
2657                         }\r
2658                 }\r
2659 \r
2660 #endif\r
2661                 if ((!bGrayed)&&(m_currentChangedArray)&&(m_currentChangedArray->GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec))\r
2662                 {\r
2663                         DWORD action = ((*m_currentChangedArray)[pLVCD->nmcd.dwItemSpec]).m_Action;\r
2664                         if (action == CTGitPath::LOGACTIONS_MODIFIED)\r
2665                                 crText = m_Colors.GetColor(CColors::Modified);\r
2666                         if (action == CTGitPath::LOGACTIONS_REPLACED)\r
2667                                 crText = m_Colors.GetColor(CColors::Deleted);\r
2668                         if (action == CTGitPath::LOGACTIONS_ADDED)\r
2669                                 crText = m_Colors.GetColor(CColors::Added);\r
2670                         if (action == CTGitPath::LOGACTIONS_DELETED)\r
2671                                 crText = m_Colors.GetColor(CColors::Deleted);\r
2672                 }\r
2673 \r
2674                 // Store the color back in the NMLVCUSTOMDRAW struct.\r
2675                 pLVCD->clrText = crText;\r
2676         }\r
2677 }\r
2678 \r
2679 void CLogDlg::DoSizeV1(int delta)\r
2680 {\r
2681 \r
2682         RemoveAnchor(IDC_LOGLIST);\r
2683         RemoveAnchor(IDC_SPLITTERTOP);\r
2684         RemoveAnchor(IDC_MSGVIEW);\r
2685         RemoveAnchor(IDC_SPLITTERBOTTOM);\r
2686         RemoveAnchor(IDC_LOGMSG);\r
2687         CSplitterControl::ChangeHeight(&m_LogList, delta, CW_TOPALIGN);\r
2688         CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), -delta, CW_BOTTOMALIGN);\r
2689         AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);\r
2690         AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);\r
2691         AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);\r
2692         AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);\r
2693         AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);\r
2694         ArrangeLayout();\r
2695         AdjustMinSize();\r
2696         SetSplitterRange();\r
2697         m_LogList.Invalidate();\r
2698         GetDlgItem(IDC_MSGVIEW)->Invalidate();\r
2699 \r
2700 }\r