1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2013, 2015-2016 - 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()
34 : m_ContextMenuMask(0xFFFFFFFF)
36 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
38 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
39 lf
.lfWeight
= FW_BOLD
;
40 m_boldFont
.CreateFontIndirect(&lf
);
43 CPatchListCtrl::~CPatchListCtrl()
48 BEGIN_MESSAGE_MAP(CPatchListCtrl
, CListCtrl
)
49 ON_NOTIFY_REFLECT(NM_DBLCLK
, &CPatchListCtrl::OnNMDblclk
)
51 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, &CPatchListCtrl::OnNMCustomdraw
)
57 // CPatchListCtrl message handlers
61 void CPatchListCtrl::OnNMDblclk(NMHDR
*pNMHDR
, LRESULT
*pResult
)
63 LPNMITEMACTIVATE pNMItemActivate
= reinterpret_cast<LPNMITEMACTIVATE
>(pNMHDR
);
65 CString path
=GetItemText(pNMItemActivate
->iItem
,0);
67 gitpath
.SetFromWin(path
);
69 CAppUtils::StartUnifiedDiffViewer(path
, gitpath
.GetFilename(), 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
74 void CPatchListCtrl::OnContextMenu(CWnd
* /*pWnd*/, CPoint point
)
76 int selected
=this->GetSelectedCount();
78 POSITION pos
=this->GetFirstSelectedItemPosition();
79 index
=this->GetNextSelectedItem(pos
);
82 if (popup
.CreatePopupMenu())
86 if( m_ContextMenuMask
&GetMenuMask(MENU_VIEWPATCH
))
87 popup
.AppendMenuIcon(MENU_VIEWPATCH
, IDS_MENU_VIEWPATCH
, 0);
89 if( m_ContextMenuMask
&GetMenuMask(MENU_VIEWWITHMERGE
))
90 popup
.AppendMenuIcon(MENU_VIEWWITHMERGE
, IDS_MENU_VIEWWITHMERGE
, 0);
92 popup
.SetDefaultItem(MENU_VIEWPATCH
, FALSE
);
96 if( m_ContextMenuMask
&GetMenuMask(MENU_SENDMAIL
))
97 popup
.AppendMenuIcon(MENU_SENDMAIL
, IDS_MENU_SENDMAIL
, IDI_MENUSENDMAIL
);
99 if( m_ContextMenuMask
&GetMenuMask(MENU_APPLY
))
100 popup
.AppendMenuIcon(MENU_APPLY
, IDS_MENU_APPLY
, 0);
103 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this);
109 CString path
=GetItemText(index
,0);
111 gitpath
.SetFromWin(path
);
113 CAppUtils::StartUnifiedDiffViewer(path
, gitpath
.GetFilename(), 0, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
116 case MENU_VIEWWITHMERGE
:
118 CString path
=GetItemText(index
,0);
120 gitpath
.SetFromWin(path
);
123 dir
.SetFromGit(g_Git
.m_CurrentDir
);
125 CAppUtils::StartExtPatch(gitpath
,dir
);
130 LaunchProc(L
"sendmail");
135 LaunchProc(L
"importpatch");
145 int CPatchListCtrl::LaunchProc(const CString
& command
)
147 CString tempfile
=GetTempFile();
148 POSITION pos
=this->GetFirstSelectedItemPosition();
150 file
.Open(tempfile
,CFile::modeWrite
|CFile::modeCreate
);
154 int index
= this->GetNextSelectedItem(pos
);
155 CString one
=this->GetItemText(index
,0);
156 file
.Write((LPCTSTR
)one
, sizeof(TCHAR
) * one
.GetLength());
157 file
.Write(L
"\n", sizeof(TCHAR
) * 1);
162 CString cmd
= L
"/command:";
164 cmd
+= L
" /pathfile:\"";
166 cmd
+= L
"\" /deletepathfile";
167 CAppUtils::RunTortoiseGitProc(cmd
);
171 void CPatchListCtrl::OnNMCustomdraw(NMHDR
*pNMHDR
, LRESULT
*pResult
)
173 NMLVCUSTOMDRAW
*pNMCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>(pNMHDR
);
177 switch (pNMCD
->nmcd
.dwDrawStage
)
181 *pResult
= CDRF_NOTIFYITEMDRAW
;
185 case CDDS_ITEMPREPAINT
:
187 // This is the prepaint stage for an item. Here's where we set the
188 // item's text color.
190 // Tell Windows to send draw notifications for each subitem.
191 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
193 DWORD_PTR data
= this->GetItemData((int)pNMCD
->nmcd
.dwItemSpec
);
194 if(data
& (STATUS_APPLY_FAIL
| STATUS_APPLY_SUCCESS
| STATUS_APPLY_SKIP
))
195 pNMCD
->clrTextBk
= RGB(200,200,200);
197 switch(data
& STATUS_MASK
)
199 case STATUS_APPLY_SUCCESS
:
200 pNMCD
->clrText
= RGB(0,128,0);
202 case STATUS_APPLY_FAIL
:
203 pNMCD
->clrText
= RGB(255,0,0);
205 case STATUS_APPLY_SKIP
:
206 pNMCD
->clrText
= RGB(128,64,0);
210 if(data
& STATUS_APPLYING
)
212 SelectObject(pNMCD
->nmcd
.hdc
, m_boldFont
.GetSafeHandle());
213 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
219 *pResult
= CDRF_DODEFAULT
;
222 void CPatchListCtrl::OnDropFiles(HDROP hDropInfo
)
224 UINT nNumFiles
= DragQueryFile(hDropInfo
, 0xFFFFFFFF, nullptr, 0);
225 for (UINT i
= 0; i
< nNumFiles
; ++i
)
228 DragQueryFile(hDropInfo
, i
, CStrBuf(file
, MAX_PATH
), MAX_PATH
);
229 if (PathIsDirectory(file
))
234 lvInfo
.flags
= LVFI_STRING
;
236 if (FindItem(&lvInfo
, -1) != -1)
239 int index
= InsertItem(GetItemCount(), file
);
241 SetCheck(index
, true);
243 DragFinish(hDropInfo
);
244 SetColumnWidth(0, LVSCW_AUTOSIZE
);