1 // PathListCtrl.cpp : implementation file
5 #include "TortoiseProc.h"
6 #include "PatchListCtrl.h"
10 #include "PathUtils.h"
14 IMPLEMENT_DYNAMIC(CPatchListCtrl
, CListCtrl
)
16 CPatchListCtrl::CPatchListCtrl()
18 m_ContextMenuMask
=0xFFFFFFFF;
20 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
22 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
23 lf
.lfWeight
= FW_BOLD
;
24 m_boldFont
= CreateFontIndirect(&lf
);
28 CPatchListCtrl::~CPatchListCtrl()
31 DeleteObject(m_boldFont
);
35 BEGIN_MESSAGE_MAP(CPatchListCtrl
, CListCtrl
)
36 ON_NOTIFY_REFLECT(NM_DBLCLK
, &CPatchListCtrl::OnNMDblclk
)
38 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, &CPatchListCtrl::OnNMCustomdraw
)
43 // CPatchListCtrl message handlers
47 void CPatchListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
49 LPNMITEMACTIVATE pNMItemActivate
= reinterpret_cast<LPNMITEMACTIVATE
>(pNMHDR
);
51 CString path
=GetItemText(pNMItemActivate
->iItem
,0);
53 gitpath
.SetFromWin(path
);
55 CAppUtils::StartUnifiedDiffViewer(path
,gitpath
.GetFilename());
60 void CPatchListCtrl::OnContextMenu(CWnd
* /*pWnd*/, CPoint point
)
62 int selected
=this->GetSelectedCount();
64 POSITION pos
=this->GetFirstSelectedItemPosition();
65 index
=this->GetNextSelectedItem(pos
);
68 if (popup
.CreatePopupMenu())
72 if( m_ContextMenuMask
&GetMenuMask(MENU_VIEWPATCH
))
73 popup
.AppendMenuIcon(MENU_VIEWPATCH
, IDS_MENU_VIEWPATCH
, 0);
75 if( m_ContextMenuMask
&GetMenuMask(MENU_VIEWWITHMERGE
))
76 popup
.AppendMenuIcon(MENU_VIEWWITHMERGE
, IDS_MENU_VIEWWITHMERGE
, 0);
78 popup
.SetDefaultItem(MENU_VIEWPATCH
, FALSE
);
82 if( m_ContextMenuMask
&GetMenuMask(MENU_SENDMAIL
))
83 popup
.AppendMenuIcon(MENU_SENDMAIL
, IDS_MENU_SENDMAIL
, IDI_MENUSENDMAIL
);
85 if( m_ContextMenuMask
&GetMenuMask(MENU_APPLY
))
86 popup
.AppendMenuIcon(MENU_APPLY
, IDS_MENU_APPLY
, 0);
89 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
96 CString path
=GetItemText(index
,0);
98 gitpath
.SetFromWin(path
);
100 CAppUtils::StartUnifiedDiffViewer(path
,gitpath
.GetFilename());
103 case MENU_VIEWWITHMERGE
:
105 CString path
=GetItemText(index
,0);
107 gitpath
.SetFromWin(path
);
110 dir
.SetFromGit(g_Git
.m_CurrentDir
);
112 CAppUtils::StartExtPatch(gitpath
,dir
);
117 LaunchProc(_T("sendmail"));
122 LaunchProc(_T("importpatch"));
132 int CPatchListCtrl::LaunchProc(const CString
& command
)
134 CString tempfile
=GetTempFile();
135 POSITION pos
=this->GetFirstSelectedItemPosition();
137 file
.Open(tempfile
,CFile::modeWrite
|CFile::modeCreate
);
141 int index
= this->GetNextSelectedItem(pos
);
142 CString one
=this->GetItemText(index
,0);
143 file
.Write(one
.GetBuffer(),sizeof(TCHAR
)*one
.GetLength());
144 file
.Write(_T("\n"),sizeof(TCHAR
)*1);
150 cmd
= CPathUtils::GetAppDirectory();
151 cmd
+= _T("TortoiseProc.exe /command:");
153 cmd
+=_T(" /pathfile:\"");
155 cmd
+= _T("\" /deletepathfile");
156 CAppUtils::LaunchApplication(cmd
, IDS_ERR_PROC
,false);
160 void CPatchListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
162 NMLVCUSTOMDRAW
*pNMCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>(pNMHDR
);
167 switch (pNMCD
->nmcd
.dwDrawStage
)
171 *pResult
= CDRF_NOTIFYITEMDRAW
;
175 case CDDS_ITEMPREPAINT
:
177 // This is the prepaint stage for an item. Here's where we set the
178 // item's text color.
180 // Tell Windows to send draw notifications for each subitem.
181 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
183 DWORD data
= this->GetItemData(pNMCD
->nmcd
.dwItemSpec
);
184 if(data
& (STATUS_APPLY_FAIL
| STATUS_APPLY_SUCCESS
| STATUS_APPLY_SKIP
))
186 pNMCD
->clrTextBk
= RGB(200,200,200);
189 switch(data
& STATUS_MASK
)
191 case STATUS_APPLY_SUCCESS
:
192 pNMCD
->clrText
= RGB(0,128,0);
194 case STATUS_APPLY_FAIL
:
195 pNMCD
->clrText
= RGB(255,0,0);
197 case STATUS_APPLY_SKIP
:
198 pNMCD
->clrText
= RGB(128,64,0);
202 if(data
& STATUS_APPLYING
)
204 SelectObject(pNMCD
->nmcd
.hdc
, m_boldFont
);
205 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
211 *pResult
= CDRF_DODEFAULT
;