Make sounds for indicating a warning or error work
[TortoiseGit.git] / src / TortoiseProc / PatchListCtrl.cpp
blob77cc4eed31b7f350846e1fe95a5fa5d5a29223f7
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
22 #include "stdafx.h"
23 #include "TortoiseProc.h"
24 #include "PatchListCtrl.h"
25 #include "iconmenu.h"
26 #include "AppUtils.h"
27 #include "git.h"
28 #include "AppUtils.h"
29 // CPatchListCtrl
31 IMPLEMENT_DYNAMIC(CPatchListCtrl, CListCtrl)
33 CPatchListCtrl::CPatchListCtrl()
35 m_ContextMenuMask=0xFFFFFFFF;
37 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
38 LOGFONT lf = {0};
39 GetObject(hFont, sizeof(LOGFONT), &lf);
40 lf.lfWeight = FW_BOLD;
41 m_boldFont = CreateFontIndirect(&lf);
45 CPatchListCtrl::~CPatchListCtrl()
47 if (m_boldFont)
48 DeleteObject(m_boldFont);
52 BEGIN_MESSAGE_MAP(CPatchListCtrl, CListCtrl)
53 ON_NOTIFY_REFLECT(NM_DBLCLK, &CPatchListCtrl::OnNMDblclk)
54 ON_WM_CONTEXTMENU()
55 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, &CPatchListCtrl::OnNMCustomdraw)
56 END_MESSAGE_MAP()
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);
69 CTGitPath gitpath;
70 gitpath.SetFromWin(path);
72 CAppUtils::StartUnifiedDiffViewer(path,gitpath.GetFilename());
74 *pResult = 0;
77 void CPatchListCtrl::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
79 int selected=this->GetSelectedCount();
80 int index=0;
81 POSITION pos=this->GetFirstSelectedItemPosition();
82 index=this->GetNextSelectedItem(pos);
84 CIconMenu popup;
85 if (popup.CreatePopupMenu())
87 if(selected == 1)
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);
97 if(selected >= 1)
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);
108 switch (cmd)
110 case MENU_VIEWPATCH:
113 CString path=GetItemText(index,0);
114 CTGitPath gitpath;
115 gitpath.SetFromWin(path);
117 CAppUtils::StartUnifiedDiffViewer(path,gitpath.GetFilename());
118 break;
120 case MENU_VIEWWITHMERGE:
122 CString path=GetItemText(index,0);
123 CTGitPath gitpath;
124 gitpath.SetFromWin(path);
126 CTGitPath dir;
127 dir.SetFromGit(g_Git.m_CurrentDir);
129 CAppUtils::StartExtPatch(gitpath,dir);
130 break;
132 case MENU_SENDMAIL:
134 LaunchProc(_T("sendmail"));
135 break;
137 case MENU_APPLY:
139 LaunchProc(_T("importpatch"));
141 break;
143 default:
144 break;
149 int CPatchListCtrl::LaunchProc(const CString& command)
151 CString tempfile=GetTempFile();
152 POSITION pos=this->GetFirstSelectedItemPosition();
153 CFile file;
154 file.Open(tempfile,CFile::modeWrite|CFile::modeCreate);
156 while(pos)
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);
164 file.Close();
166 CString cmd = command;
167 cmd +=_T(" /pathfile:\"");
168 cmd += tempfile;
169 cmd += _T("\" /deletepathfile");
170 CAppUtils::RunTortoiseGitProc(cmd);
171 return 0;
174 void CPatchListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
176 NMLVCUSTOMDRAW *pNMCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
178 *pResult = 0;
181 switch (pNMCD->nmcd.dwDrawStage)
183 case CDDS_PREPAINT:
185 *pResult = CDRF_NOTIFYITEMDRAW;
186 return;
188 break;
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);
207 break;
208 case STATUS_APPLY_FAIL:
209 pNMCD->clrText = RGB(255,0,0);
210 break;
211 case STATUS_APPLY_SKIP:
212 pNMCD->clrText = RGB(128,64,0);
213 break;
216 if(data & STATUS_APPLYING)
218 SelectObject(pNMCD->nmcd.hdc, m_boldFont);
219 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
223 break;
225 *pResult = CDRF_DODEFAULT;