OSDN Git Service

Add PatchListCtrl to show context menu at sendmail and import patch.
authorFrank Li <lznuaa@gmail.com>
Thu, 23 Apr 2009 15:43:47 +0000 (23:43 +0800)
committerFrank Li <lznuaa@gmail.com>
Thu, 23 Apr 2009 15:43:47 +0000 (23:43 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
src/Resources/TortoiseProcENG.rc
src/TortoiseProc/PatchListCtrl.cpp [new file with mode: 0644]
src/TortoiseProc/PatchListCtrl.h [new file with mode: 0644]
src/TortoiseProc/SendMailDlg.cpp
src/TortoiseProc/SendMailDlg.h
src/TortoiseProc/TortoiseProc.vcproj
src/TortoiseProc/resource.h

index 966b17d..2182cd9 100644 (file)
Binary files a/src/Resources/TortoiseProcENG.rc and b/src/Resources/TortoiseProcENG.rc differ
diff --git a/src/TortoiseProc/PatchListCtrl.cpp b/src/TortoiseProc/PatchListCtrl.cpp
new file mode 100644 (file)
index 0000000..868f32c
--- /dev/null
@@ -0,0 +1,150 @@
+// PathListCtrl.cpp : implementation file\r
+//\r
+\r
+#include "stdafx.h"\r
+#include "TortoiseProc.h"\r
+#include "PatchListCtrl.h"\r
+#include "iconmenu.h"\r
+#include "AppUtils.h"\r
+#include "git.h"\r
+#include "PathUtils.h"\r
+#include "AppUtils.h"\r
+// CPatchListCtrl\r
+\r
+IMPLEMENT_DYNAMIC(CPatchListCtrl, CListCtrl)\r
+\r
+CPatchListCtrl::CPatchListCtrl()\r
+{\r
+       m_ContextMenuMask=0xFFFFFFFF;\r
+}\r
+\r
+CPatchListCtrl::~CPatchListCtrl()\r
+{\r
+}\r
+\r
+\r
+BEGIN_MESSAGE_MAP(CPatchListCtrl, CListCtrl)\r
+       ON_NOTIFY_REFLECT(NM_DBLCLK, &CPatchListCtrl::OnNMDblclk)\r
+       ON_WM_CONTEXTMENU()\r
+END_MESSAGE_MAP()\r
+\r
+\r
+\r
+// CPatchListCtrl message handlers\r
+\r
+\r
+\r
+void CPatchListCtrl::OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult)\r
+{\r
+       LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);\r
+       // TODO: Add your control notification handler code here\r
+       CString path=GetItemText(pNMItemActivate->iItem,0);\r
+       CTGitPath gitpath;\r
+       gitpath.SetFromWin(path);\r
+       \r
+       CAppUtils::StartUnifiedDiffViewer(path,gitpath.GetFilename());\r
+\r
+       *pResult = 0;\r
+\r
+}\r
+\r
+void CPatchListCtrl::OnContextMenu(CWnd* /*pWnd*/, CPoint point)\r
+{\r
+       // TODO: Add your message handler code here\r
+       int selected=this->GetSelectedCount();\r
+       int index=0;\r
+       POSITION pos=this->GetFirstSelectedItemPosition();\r
+       index=this->GetNextSelectedItem(pos);\r
+\r
+       CIconMenu popup;\r
+       if (popup.CreatePopupMenu())\r
+       {\r
+               if(selected == 1)\r
+               {\r
+                       if( m_ContextMenuMask&GetMenuMask(MENU_VIEWPATCH))\r
+                               popup.AppendMenuIcon(MENU_VIEWPATCH, IDS_MENU_VIEWPATCH, 0);\r
+\r
+                       if( m_ContextMenuMask&GetMenuMask(MENU_VIEWWITHMERGE))\r
+                               popup.AppendMenuIcon(MENU_VIEWWITHMERGE, IDS_MENU_VIEWWITHMERGE, 0);\r
+\r
+                       popup.SetDefaultItem(MENU_VIEWPATCH, FALSE);\r
+               }\r
+               if(selected >= 1)\r
+               {\r
+                       if( m_ContextMenuMask&GetMenuMask(MENU_SENDMAIL))\r
+                               popup.AppendMenuIcon(MENU_SENDMAIL, IDS_MENU_SENDMAIL, IDI_MENUSENDMAIL);\r
+\r
+                       if( m_ContextMenuMask&GetMenuMask(MENU_APPLY))\r
+                               popup.AppendMenuIcon(MENU_APPLY, IDS_MENU_APPLY, 0);\r
+               }\r
+\r
+               int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);\r
+\r
+               switch (cmd)\r
+               {\r
+               case MENU_VIEWPATCH:\r
+                       {\r
+\r
+                               CString path=GetItemText(index,0);\r
+                               CTGitPath gitpath;\r
+                               gitpath.SetFromWin(path);\r
+       \r
+                               CAppUtils::StartUnifiedDiffViewer(path,gitpath.GetFilename());\r
+                               break;\r
+                       }\r
+               case MENU_VIEWWITHMERGE:\r
+                       {\r
+                               CString path=GetItemText(index,0);\r
+                               CTGitPath gitpath;\r
+                               gitpath.SetFromWin(path);\r
+\r
+                               CTGitPath dir;\r
+                               dir.SetFromGit(g_Git.m_CurrentDir);\r
+\r
+                               CAppUtils::StartExtPatch(gitpath,dir);\r
+                               break;\r
+                       }\r
+               case MENU_SENDMAIL:\r
+                       {\r
+                               LaunchProc(CString(_T("sendmail")));\r
+                               break;\r
+                       }\r
+               case MENU_APPLY:\r
+                       {\r
+                               LaunchProc(CString(_T("importpatch")));\r
+\r
+                               break;\r
+                       }\r
+               default:\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+int CPatchListCtrl::LaunchProc(CString& command)\r
+{\r
+       CString tempfile=GetTempFile();\r
+       POSITION pos=this->GetFirstSelectedItemPosition();\r
+       CFile file;\r
+       file.Open(tempfile,CFile::modeWrite|CFile::modeCreate);\r
+\r
+       while(pos)\r
+       {\r
+               int index = this->GetNextSelectedItem(pos);\r
+               CString one=this->GetItemText(index,0);\r
+               file.Write(one.GetBuffer(),sizeof(TCHAR)*one.GetLength());\r
+               file.Write(_T("\n"),sizeof(TCHAR)*1);\r
+       }\r
+\r
+       file.Close();\r
+\r
+       CString cmd;\r
+       cmd = CPathUtils::GetAppDirectory();\r
+       cmd += _T("TortoiseProc.exe /command:");\r
+       cmd += command;\r
+       cmd +=_T(" /pathfile:\"");\r
+       cmd += tempfile;\r
+       cmd += _T("\" /deletepathfile");\r
+       CAppUtils::LaunchApplication(cmd, IDS_ERR_PROC,false);\r
+       return 0;\r
+}\r
diff --git a/src/TortoiseProc/PatchListCtrl.h b/src/TortoiseProc/PatchListCtrl.h
new file mode 100644 (file)
index 0000000..1a04acd
--- /dev/null
@@ -0,0 +1,32 @@
+#pragma once\r
+\r
+\r
+// CPatchListCtrl\r
+\r
+class CPatchListCtrl : public CListCtrl\r
+{\r
+       DECLARE_DYNAMIC(CPatchListCtrl)\r
+\r
+public:\r
+       CPatchListCtrl();\r
+       virtual ~CPatchListCtrl();\r
+       DWORD m_ContextMenuMask;\r
+       enum\r
+       {\r
+               MENU_SENDMAIL=1,\r
+               MENU_VIEWPATCH,\r
+               MENU_VIEWWITHMERGE,\r
+               MENU_APPLY\r
+       };\r
+       DWORD GetMenuMask(int x){return 1<<x;}\r
+\r
+protected:\r
+       DECLARE_MESSAGE_MAP()\r
+       \r
+public:\r
+       afx_msg void OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult);\r
+       afx_msg void OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/);\r
+       int LaunchProc(CString& cmd);\r
+};\r
+\r
+\r
index 1e78be1..97ff5f0 100644 (file)
@@ -7,7 +7,7 @@
 #include "MessageBox.h"\r
 #include "commonresource.h"\r
 #include "AppUtils.h"\r
-\r
+#include "PatchListCtrl.h"\r
 // CSendMailDlg dialog\r
 \r
 IMPLEMENT_DYNAMIC(CSendMailDlg, CResizableStandAloneDialog)\r
@@ -23,7 +23,7 @@ CSendMailDlg::CSendMailDlg(CWnd* pParent /*=NULL*/)
 {\r
        m_bAttachment  = m_regAttach;\r
        m_bCombine =     m_regCombine;\r
-\r
+       this->m_ctrlList.m_ContextMenuMask &=~ m_ctrlList.GetMenuMask(CPatchListCtrl::MENU_SENDMAIL);\r
 }\r
 \r
 CSendMailDlg::~CSendMailDlg()\r
index e547d29..22947a9 100644 (file)
@@ -8,6 +8,7 @@
 #include "TGitPath.h"\r
 #include "patch.h"\r
 #include "Registry.h"\r
+#include "PatchListCtrl.h"\r
 \r
 class CSendMailDlg : public CResizableStandAloneDialog\r
 {\r
@@ -38,7 +39,7 @@ public:
        CString m_Subject;\r
        BOOL m_bAttachment;\r
        BOOL m_bCombine;\r
-       CListCtrl m_ctrlList;\r
+       CPatchListCtrl m_ctrlList;\r
        CTGitPathList m_PathList;\r
 \r
     CRegDWORD  m_regAttach;\r
index 5c94fe9..ee4ab86 100644 (file)
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\copy.ico"\r
+                               RelativePath=".\copy.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\copy.ico"\r
+                               RelativePath="..\Resources\copy.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\explorer.ico"\r
+                               RelativePath="..\Resources\explorer.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\explorer.ico"\r
+                               RelativePath=".\explorer.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\newfolder.ico"\r
+                               RelativePath=".\newfolder.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\newfolder.ico"\r
+                               RelativePath="..\Resources\newfolder.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\refresh.ico"\r
+                               RelativePath=".\refresh.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\refresh.ico"\r
+                               RelativePath="..\Resources\refresh.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\save.ico"\r
+                               RelativePath="..\Resources\save.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\save.ico"\r
+                               RelativePath=".\save.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\up.ico"\r
+                               RelativePath=".\up.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\up.ico"\r
+                               RelativePath="..\Resources\up.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                </File>\r
                        </Filter>\r
                        <Filter\r
-                               Name="Stash"\r
-                               >\r
-                               <File\r
-                                       RelativePath=".\Commands\StashCommand.cpp"\r
-                                       >\r
-                               </File>\r
-                               <File\r
-                                       RelativePath=".\Commands\StashCommand.h"\r
-                                       >\r
-                               </File>\r
-                       </Filter>\r
-                       <Filter\r
                                Name="Clean"\r
                                >\r
                                <File\r
                                        >\r
                                </File>\r
                        </Filter>\r
+                       <Filter\r
+                               Name="Stash"\r
+                               >\r
+                               <File\r
+                                       RelativePath=".\Commands\StashCommand.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\Commands\StashCommand.h"\r
+                                       >\r
+                               </File>\r
+                       </Filter>\r
                </Filter>\r
                <Filter\r
                        Name="Utility Dialogs"\r
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath=".\PatchListCtrl.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\PatchListCtrl.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath=".\SwitchDlg.cpp"\r
                                >\r
                        </File>\r
index 0e3037f..0e39ff4 100644 (file)
Binary files a/src/TortoiseProc/resource.h and b/src/TortoiseProc/resource.h differ