1 // PathListCtrl.cpp : implementation file
5 #include "TortoiseProc.h"
6 #include "PatchListCtrl.h"
13 IMPLEMENT_DYNAMIC(CPatchListCtrl
, CListCtrl
)
15 CPatchListCtrl::CPatchListCtrl()
17 m_ContextMenuMask
=0xFFFFFFFF;
19 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
21 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
22 lf
.lfWeight
= FW_BOLD
;
23 m_boldFont
= CreateFontIndirect(&lf
);
27 CPatchListCtrl::~CPatchListCtrl()
30 DeleteObject(m_boldFont
);
34 BEGIN_MESSAGE_MAP(CPatchListCtrl
, CListCtrl
)
35 ON_NOTIFY_REFLECT(NM_DBLCLK
, &CPatchListCtrl::OnNMDblclk
)
37 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, &CPatchListCtrl::OnNMCustomdraw
)
42 // CPatchListCtrl message handlers
46 void CPatchListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
48 LPNMITEMACTIVATE pNMItemActivate
= reinterpret_cast<LPNMITEMACTIVATE
>(pNMHDR
);
50 CString path
=GetItemText(pNMItemActivate
->iItem
,0);
52 gitpath
.SetFromWin(path
);
54 CAppUtils::StartUnifiedDiffViewer(path
,gitpath
.GetFilename());
59 void CPatchListCtrl::OnContextMenu(CWnd
* /*pWnd*/, CPoint point
)
61 int selected
=this->GetSelectedCount();
63 POSITION pos
=this->GetFirstSelectedItemPosition();
64 index
=this->GetNextSelectedItem(pos
);
67 if (popup
.CreatePopupMenu())
71 if( m_ContextMenuMask
&GetMenuMask(MENU_VIEWPATCH
))
72 popup
.AppendMenuIcon(MENU_VIEWPATCH
, IDS_MENU_VIEWPATCH
, 0);
74 if( m_ContextMenuMask
&GetMenuMask(MENU_VIEWWITHMERGE
))
75 popup
.AppendMenuIcon(MENU_VIEWWITHMERGE
, IDS_MENU_VIEWWITHMERGE
, 0);
77 popup
.SetDefaultItem(MENU_VIEWPATCH
, FALSE
);
81 if( m_ContextMenuMask
&GetMenuMask(MENU_SENDMAIL
))
82 popup
.AppendMenuIcon(MENU_SENDMAIL
, IDS_MENU_SENDMAIL
, IDI_MENUSENDMAIL
);
84 if( m_ContextMenuMask
&GetMenuMask(MENU_APPLY
))
85 popup
.AppendMenuIcon(MENU_APPLY
, IDS_MENU_APPLY
, 0);
88 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
95 CString path
=GetItemText(index
,0);
97 gitpath
.SetFromWin(path
);
99 CAppUtils::StartUnifiedDiffViewer(path
,gitpath
.GetFilename());
102 case MENU_VIEWWITHMERGE
:
104 CString path
=GetItemText(index
,0);
106 gitpath
.SetFromWin(path
);
109 dir
.SetFromGit(g_Git
.m_CurrentDir
);
111 CAppUtils::StartExtPatch(gitpath
,dir
);
116 LaunchProc(_T("sendmail"));
121 LaunchProc(_T("importpatch"));
131 int CPatchListCtrl::LaunchProc(const CString
& command
)
133 CString tempfile
=GetTempFile();
134 POSITION pos
=this->GetFirstSelectedItemPosition();
136 file
.Open(tempfile
,CFile::modeWrite
|CFile::modeCreate
);
140 int index
= this->GetNextSelectedItem(pos
);
141 CString one
=this->GetItemText(index
,0);
142 file
.Write(one
.GetBuffer(),sizeof(TCHAR
)*one
.GetLength());
143 file
.Write(_T("\n"),sizeof(TCHAR
)*1);
148 CString cmd
= command
;
149 cmd
+=_T(" /pathfile:\"");
151 cmd
+= _T("\" /deletepathfile");
152 CAppUtils::RunTortoiseProc(cmd
);
156 void CPatchListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
158 NMLVCUSTOMDRAW
*pNMCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>(pNMHDR
);
163 switch (pNMCD
->nmcd
.dwDrawStage
)
167 *pResult
= CDRF_NOTIFYITEMDRAW
;
171 case CDDS_ITEMPREPAINT
:
173 // This is the prepaint stage for an item. Here's where we set the
174 // item's text color.
176 // Tell Windows to send draw notifications for each subitem.
177 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
179 DWORD_PTR data
= this->GetItemData((int)pNMCD
->nmcd
.dwItemSpec
);
180 if(data
& (STATUS_APPLY_FAIL
| STATUS_APPLY_SUCCESS
| STATUS_APPLY_SKIP
))
182 pNMCD
->clrTextBk
= RGB(200,200,200);
185 switch(data
& STATUS_MASK
)
187 case STATUS_APPLY_SUCCESS
:
188 pNMCD
->clrText
= RGB(0,128,0);
190 case STATUS_APPLY_FAIL
:
191 pNMCD
->clrText
= RGB(255,0,0);
193 case STATUS_APPLY_SKIP
:
194 pNMCD
->clrText
= RGB(128,64,0);
198 if(data
& STATUS_APPLYING
)
200 SelectObject(pNMCD
->nmcd
.hdc
, m_boldFont
);
201 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
207 *pResult
= CDRF_DODEFAULT
;