Clean up warning
[TortoiseGit.git] / src / TortoiseProc / PatchListCtrl.cpp
blobf88bae564a067598004b85f62af2cf22e029c8cd
1 // PathListCtrl.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "TortoiseProc.h"
6 #include "PatchListCtrl.h"
7 #include "iconmenu.h"
8 #include "AppUtils.h"
9 #include "git.h"
10 #include "PathUtils.h"
11 #include "AppUtils.h"
12 // CPatchListCtrl
14 IMPLEMENT_DYNAMIC(CPatchListCtrl, CListCtrl)
16 CPatchListCtrl::CPatchListCtrl()
18 m_ContextMenuMask=0xFFFFFFFF;
20 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
21 LOGFONT lf = {0};
22 GetObject(hFont, sizeof(LOGFONT), &lf);
23 lf.lfWeight = FW_BOLD;
24 m_boldFont = CreateFontIndirect(&lf);
28 CPatchListCtrl::~CPatchListCtrl()
30 if (m_boldFont)
31 DeleteObject(m_boldFont);
35 BEGIN_MESSAGE_MAP(CPatchListCtrl, CListCtrl)
36 ON_NOTIFY_REFLECT(NM_DBLCLK, &CPatchListCtrl::OnNMDblclk)
37 ON_WM_CONTEXTMENU()
38 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, &CPatchListCtrl::OnNMCustomdraw)
39 END_MESSAGE_MAP()
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);
52 CTGitPath gitpath;
53 gitpath.SetFromWin(path);
55 CAppUtils::StartUnifiedDiffViewer(path,gitpath.GetFilename());
57 *pResult = 0;
60 void CPatchListCtrl::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
62 int selected=this->GetSelectedCount();
63 int index=0;
64 POSITION pos=this->GetFirstSelectedItemPosition();
65 index=this->GetNextSelectedItem(pos);
67 CIconMenu popup;
68 if (popup.CreatePopupMenu())
70 if(selected == 1)
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);
80 if(selected >= 1)
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);
91 switch (cmd)
93 case MENU_VIEWPATCH:
96 CString path=GetItemText(index,0);
97 CTGitPath gitpath;
98 gitpath.SetFromWin(path);
100 CAppUtils::StartUnifiedDiffViewer(path,gitpath.GetFilename());
101 break;
103 case MENU_VIEWWITHMERGE:
105 CString path=GetItemText(index,0);
106 CTGitPath gitpath;
107 gitpath.SetFromWin(path);
109 CTGitPath dir;
110 dir.SetFromGit(g_Git.m_CurrentDir);
112 CAppUtils::StartExtPatch(gitpath,dir);
113 break;
115 case MENU_SENDMAIL:
117 LaunchProc(CString(_T("sendmail")));
118 break;
120 case MENU_APPLY:
122 LaunchProc(CString(_T("importpatch")));
124 break;
126 default:
127 break;
132 int CPatchListCtrl::LaunchProc(const CString& command)
134 CString tempfile=GetTempFile();
135 POSITION pos=this->GetFirstSelectedItemPosition();
136 CFile file;
137 file.Open(tempfile,CFile::modeWrite|CFile::modeCreate);
139 while(pos)
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);
147 file.Close();
149 CString cmd;
150 cmd = CPathUtils::GetAppDirectory();
151 cmd += _T("TortoiseProc.exe /command:");
152 cmd += command;
153 cmd +=_T(" /pathfile:\"");
154 cmd += tempfile;
155 cmd += _T("\" /deletepathfile");
156 CAppUtils::LaunchApplication(cmd, IDS_ERR_PROC,false);
157 return 0;
160 void CPatchListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
162 NMLVCUSTOMDRAW *pNMCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
164 *pResult = 0;
167 switch (pNMCD->nmcd.dwDrawStage)
169 case CDDS_PREPAINT:
171 *pResult = CDRF_NOTIFYITEMDRAW;
172 return;
174 break;
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);
193 break;
194 case STATUS_APPLY_FAIL:
195 pNMCD->clrText = RGB(255,0,0);
196 break;
197 case STATUS_APPLY_SKIP:
198 pNMCD->clrText = RGB(128,64,0);
199 break;
202 if(data & STATUS_APPLYING)
204 SelectObject(pNMCD->nmcd.hdc, m_boldFont);
205 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
209 break;
211 *pResult = CDRF_DODEFAULT;