DeleteRemoteTagDlg: Allow to delete multiple tags at once
[TortoiseGit.git] / src / TortoiseProc / PatchListCtrl.cpp
blob0e96d9972ce2d1461a9ea31742f2a6f078b844a2
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 "AppUtils.h"
11 // CPatchListCtrl
13 IMPLEMENT_DYNAMIC(CPatchListCtrl, CListCtrl)
15 CPatchListCtrl::CPatchListCtrl()
17 m_ContextMenuMask=0xFFFFFFFF;
19 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
20 LOGFONT lf = {0};
21 GetObject(hFont, sizeof(LOGFONT), &lf);
22 lf.lfWeight = FW_BOLD;
23 m_boldFont = CreateFontIndirect(&lf);
27 CPatchListCtrl::~CPatchListCtrl()
29 if (m_boldFont)
30 DeleteObject(m_boldFont);
34 BEGIN_MESSAGE_MAP(CPatchListCtrl, CListCtrl)
35 ON_NOTIFY_REFLECT(NM_DBLCLK, &CPatchListCtrl::OnNMDblclk)
36 ON_WM_CONTEXTMENU()
37 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, &CPatchListCtrl::OnNMCustomdraw)
38 END_MESSAGE_MAP()
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);
51 CTGitPath gitpath;
52 gitpath.SetFromWin(path);
54 CAppUtils::StartUnifiedDiffViewer(path,gitpath.GetFilename());
56 *pResult = 0;
59 void CPatchListCtrl::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
61 int selected=this->GetSelectedCount();
62 int index=0;
63 POSITION pos=this->GetFirstSelectedItemPosition();
64 index=this->GetNextSelectedItem(pos);
66 CIconMenu popup;
67 if (popup.CreatePopupMenu())
69 if(selected == 1)
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);
79 if(selected >= 1)
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);
90 switch (cmd)
92 case MENU_VIEWPATCH:
95 CString path=GetItemText(index,0);
96 CTGitPath gitpath;
97 gitpath.SetFromWin(path);
99 CAppUtils::StartUnifiedDiffViewer(path,gitpath.GetFilename());
100 break;
102 case MENU_VIEWWITHMERGE:
104 CString path=GetItemText(index,0);
105 CTGitPath gitpath;
106 gitpath.SetFromWin(path);
108 CTGitPath dir;
109 dir.SetFromGit(g_Git.m_CurrentDir);
111 CAppUtils::StartExtPatch(gitpath,dir);
112 break;
114 case MENU_SENDMAIL:
116 LaunchProc(_T("sendmail"));
117 break;
119 case MENU_APPLY:
121 LaunchProc(_T("importpatch"));
123 break;
125 default:
126 break;
131 int CPatchListCtrl::LaunchProc(const CString& command)
133 CString tempfile=GetTempFile();
134 POSITION pos=this->GetFirstSelectedItemPosition();
135 CFile file;
136 file.Open(tempfile,CFile::modeWrite|CFile::modeCreate);
138 while(pos)
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);
146 file.Close();
148 CString cmd = command;
149 cmd +=_T(" /pathfile:\"");
150 cmd += tempfile;
151 cmd += _T("\" /deletepathfile");
152 CAppUtils::RunTortoiseProc(cmd);
153 return 0;
156 void CPatchListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
158 NMLVCUSTOMDRAW *pNMCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
160 *pResult = 0;
163 switch (pNMCD->nmcd.dwDrawStage)
165 case CDDS_PREPAINT:
167 *pResult = CDRF_NOTIFYITEMDRAW;
168 return;
170 break;
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);
189 break;
190 case STATUS_APPLY_FAIL:
191 pNMCD->clrText = RGB(255,0,0);
192 break;
193 case STATUS_APPLY_SKIP:
194 pNMCD->clrText = RGB(128,64,0);
195 break;
198 if(data & STATUS_APPLYING)
200 SelectObject(pNMCD->nmcd.hdc, m_boldFont);
201 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
205 break;
207 *pResult = CDRF_DODEFAULT;