1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2013, 2015 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // PathListCtrl.cpp : implementation file
23 #include "TortoiseProc.h"
24 #include "PatchListCtrl.h"
31 IMPLEMENT_DYNAMIC(CPatchListCtrl
, CListCtrl
)
33 CPatchListCtrl::CPatchListCtrl()
35 m_ContextMenuMask
=0xFFFFFFFF;
37 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
39 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
40 lf
.lfWeight
= FW_BOLD
;
41 m_boldFont
= CreateFontIndirect(&lf
);
45 CPatchListCtrl::~CPatchListCtrl()
48 DeleteObject(m_boldFont
);
52 BEGIN_MESSAGE_MAP(CPatchListCtrl
, CListCtrl
)
53 ON_NOTIFY_REFLECT(NM_DBLCLK
, &CPatchListCtrl::OnNMDblclk
)
55 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, &CPatchListCtrl::OnNMCustomdraw
)
61 // CPatchListCtrl message handlers
65 void CPatchListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
67 LPNMITEMACTIVATE pNMItemActivate
= reinterpret_cast<LPNMITEMACTIVATE
>(pNMHDR
);
69 CString path
=GetItemText(pNMItemActivate
->iItem
,0);
71 gitpath
.SetFromWin(path
);
73 CAppUtils::StartUnifiedDiffViewer(path
,gitpath
.GetFilename());
78 void CPatchListCtrl::OnContextMenu(CWnd
* /*pWnd*/, CPoint point
)
80 int selected
=this->GetSelectedCount();
82 POSITION pos
=this->GetFirstSelectedItemPosition();
83 index
=this->GetNextSelectedItem(pos
);
86 if (popup
.CreatePopupMenu())
90 if( m_ContextMenuMask
&GetMenuMask(MENU_VIEWPATCH
))
91 popup
.AppendMenuIcon(MENU_VIEWPATCH
, IDS_MENU_VIEWPATCH
, 0);
93 if( m_ContextMenuMask
&GetMenuMask(MENU_VIEWWITHMERGE
))
94 popup
.AppendMenuIcon(MENU_VIEWWITHMERGE
, IDS_MENU_VIEWWITHMERGE
, 0);
96 popup
.SetDefaultItem(MENU_VIEWPATCH
, FALSE
);
100 if( m_ContextMenuMask
&GetMenuMask(MENU_SENDMAIL
))
101 popup
.AppendMenuIcon(MENU_SENDMAIL
, IDS_MENU_SENDMAIL
, IDI_MENUSENDMAIL
);
103 if( m_ContextMenuMask
&GetMenuMask(MENU_APPLY
))
104 popup
.AppendMenuIcon(MENU_APPLY
, IDS_MENU_APPLY
, 0);
107 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
114 CString path
=GetItemText(index
,0);
116 gitpath
.SetFromWin(path
);
118 CAppUtils::StartUnifiedDiffViewer(path
,gitpath
.GetFilename());
121 case MENU_VIEWWITHMERGE
:
123 CString path
=GetItemText(index
,0);
125 gitpath
.SetFromWin(path
);
128 dir
.SetFromGit(g_Git
.m_CurrentDir
);
130 CAppUtils::StartExtPatch(gitpath
,dir
);
135 LaunchProc(_T("sendmail"));
140 LaunchProc(_T("importpatch"));
150 int CPatchListCtrl::LaunchProc(const CString
& command
)
152 CString tempfile
=GetTempFile();
153 POSITION pos
=this->GetFirstSelectedItemPosition();
155 file
.Open(tempfile
,CFile::modeWrite
|CFile::modeCreate
);
159 int index
= this->GetNextSelectedItem(pos
);
160 CString one
=this->GetItemText(index
,0);
161 file
.Write(one
.GetBuffer(),sizeof(TCHAR
)*one
.GetLength());
162 file
.Write(_T("\n"),sizeof(TCHAR
)*1);
167 CString cmd
= command
;
168 cmd
+=_T(" /pathfile:\"");
170 cmd
+= _T("\" /deletepathfile");
171 CAppUtils::RunTortoiseGitProc(cmd
);
175 void CPatchListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
177 NMLVCUSTOMDRAW
*pNMCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>(pNMHDR
);
182 switch (pNMCD
->nmcd
.dwDrawStage
)
186 *pResult
= CDRF_NOTIFYITEMDRAW
;
190 case CDDS_ITEMPREPAINT
:
192 // This is the prepaint stage for an item. Here's where we set the
193 // item's text color.
195 // Tell Windows to send draw notifications for each subitem.
196 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
198 DWORD_PTR data
= this->GetItemData((int)pNMCD
->nmcd
.dwItemSpec
);
199 if(data
& (STATUS_APPLY_FAIL
| STATUS_APPLY_SUCCESS
| STATUS_APPLY_SKIP
))
201 pNMCD
->clrTextBk
= RGB(200,200,200);
204 switch(data
& STATUS_MASK
)
206 case STATUS_APPLY_SUCCESS
:
207 pNMCD
->clrText
= RGB(0,128,0);
209 case STATUS_APPLY_FAIL
:
210 pNMCD
->clrText
= RGB(255,0,0);
212 case STATUS_APPLY_SKIP
:
213 pNMCD
->clrText
= RGB(128,64,0);
217 if(data
& STATUS_APPLYING
)
219 SelectObject(pNMCD
->nmcd
.hdc
, m_boldFont
);
220 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
226 *pResult
= CDRF_DODEFAULT
;
229 void CPatchListCtrl::OnDropFiles(HDROP hDropInfo
)
231 UINT nNumFiles
= DragQueryFile(hDropInfo
, 0xFFFFFFFF, nullptr, 0);
232 for (UINT i
= 0; i
< nNumFiles
; ++i
)
235 DragQueryFile(hDropInfo
, i
, file
.GetBufferSetLength(MAX_PATH
), MAX_PATH
);
236 file
.ReleaseBuffer();
237 if (PathIsDirectory(file
))
242 lvInfo
.flags
= LVFI_STRING
;
244 if (FindItem(&lvInfo
, -1) != -1)
247 int index
= InsertItem(GetItemCount(), file
);
249 SetCheck(index
, true);
251 DragFinish(hDropInfo
);
252 SetColumnWidth(0, LVSCW_AUTOSIZE
);