1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2012 - 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
)
60 // CPatchListCtrl message handlers
64 void CPatchListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
66 LPNMITEMACTIVATE pNMItemActivate
= reinterpret_cast<LPNMITEMACTIVATE
>(pNMHDR
);
68 CString path
=GetItemText(pNMItemActivate
->iItem
,0);
70 gitpath
.SetFromWin(path
);
72 CAppUtils::StartUnifiedDiffViewer(path
,gitpath
.GetFilename());
77 void CPatchListCtrl::OnContextMenu(CWnd
* /*pWnd*/, CPoint point
)
79 int selected
=this->GetSelectedCount();
81 POSITION pos
=this->GetFirstSelectedItemPosition();
82 index
=this->GetNextSelectedItem(pos
);
85 if (popup
.CreatePopupMenu())
89 if( m_ContextMenuMask
&GetMenuMask(MENU_VIEWPATCH
))
90 popup
.AppendMenuIcon(MENU_VIEWPATCH
, IDS_MENU_VIEWPATCH
, 0);
92 if( m_ContextMenuMask
&GetMenuMask(MENU_VIEWWITHMERGE
))
93 popup
.AppendMenuIcon(MENU_VIEWWITHMERGE
, IDS_MENU_VIEWWITHMERGE
, 0);
95 popup
.SetDefaultItem(MENU_VIEWPATCH
, FALSE
);
99 if( m_ContextMenuMask
&GetMenuMask(MENU_SENDMAIL
))
100 popup
.AppendMenuIcon(MENU_SENDMAIL
, IDS_MENU_SENDMAIL
, IDI_MENUSENDMAIL
);
102 if( m_ContextMenuMask
&GetMenuMask(MENU_APPLY
))
103 popup
.AppendMenuIcon(MENU_APPLY
, IDS_MENU_APPLY
, 0);
106 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
113 CString path
=GetItemText(index
,0);
115 gitpath
.SetFromWin(path
);
117 CAppUtils::StartUnifiedDiffViewer(path
,gitpath
.GetFilename());
120 case MENU_VIEWWITHMERGE
:
122 CString path
=GetItemText(index
,0);
124 gitpath
.SetFromWin(path
);
127 dir
.SetFromGit(g_Git
.m_CurrentDir
);
129 CAppUtils::StartExtPatch(gitpath
,dir
);
134 LaunchProc(_T("sendmail"));
139 LaunchProc(_T("importpatch"));
149 int CPatchListCtrl::LaunchProc(const CString
& command
)
151 CString tempfile
=GetTempFile();
152 POSITION pos
=this->GetFirstSelectedItemPosition();
154 file
.Open(tempfile
,CFile::modeWrite
|CFile::modeCreate
);
158 int index
= this->GetNextSelectedItem(pos
);
159 CString one
=this->GetItemText(index
,0);
160 file
.Write(one
.GetBuffer(),sizeof(TCHAR
)*one
.GetLength());
161 file
.Write(_T("\n"),sizeof(TCHAR
)*1);
166 CString cmd
= command
;
167 cmd
+=_T(" /pathfile:\"");
169 cmd
+= _T("\" /deletepathfile");
170 CAppUtils::RunTortoiseGitProc(cmd
);
174 void CPatchListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
176 NMLVCUSTOMDRAW
*pNMCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>(pNMHDR
);
181 switch (pNMCD
->nmcd
.dwDrawStage
)
185 *pResult
= CDRF_NOTIFYITEMDRAW
;
189 case CDDS_ITEMPREPAINT
:
191 // This is the prepaint stage for an item. Here's where we set the
192 // item's text color.
194 // Tell Windows to send draw notifications for each subitem.
195 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
197 DWORD_PTR data
= this->GetItemData((int)pNMCD
->nmcd
.dwItemSpec
);
198 if(data
& (STATUS_APPLY_FAIL
| STATUS_APPLY_SUCCESS
| STATUS_APPLY_SKIP
))
200 pNMCD
->clrTextBk
= RGB(200,200,200);
203 switch(data
& STATUS_MASK
)
205 case STATUS_APPLY_SUCCESS
:
206 pNMCD
->clrText
= RGB(0,128,0);
208 case STATUS_APPLY_FAIL
:
209 pNMCD
->clrText
= RGB(255,0,0);
211 case STATUS_APPLY_SKIP
:
212 pNMCD
->clrText
= RGB(128,64,0);
216 if(data
& STATUS_APPLYING
)
218 SelectObject(pNMCD
->nmcd
.hdc
, m_boldFont
);
219 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
225 *pResult
= CDRF_DODEFAULT
;