OSDN Git Service

BrowseRefs: Context menu enhancements
authorJohan 't Hart <johanthart@gmail.com>
Sun, 10 May 2009 21:30:03 +0000 (23:30 +0200)
committerFrank Li <lznuaa@gmail.com>
Thu, 14 May 2009 15:22:19 +0000 (23:22 +0800)
src/TortoiseProc/BrowseRefsDlg.cpp
src/TortoiseProc/BrowseRefsDlg.h

index 6707fea..051de43 100644 (file)
@@ -301,67 +301,6 @@ void CBrowseRefsDlg::FillListCtrlForShadowTree(CShadowTree* pTree, CString refNa
        }\r
 }\r
 \r
-void CBrowseRefsDlg::OnContextMenu_ListRefLeafs(CPoint point)\r
-{\r
-\r
-       CPoint clientPoint=point;\r
-       m_RefTreeCtrl.ScreenToClient(&clientPoint);\r
-\r
-\r
-       std::vector<CShadowTree*> selectedTrees;\r
-       selectedTrees.reserve(m_ListRefLeafs.GetSelectedCount());\r
-       POSITION pos=m_ListRefLeafs.GetFirstSelectedItemPosition();\r
-       while(pos)\r
-       {\r
-               selectedTrees.push_back(\r
-                       (CShadowTree*)m_ListRefLeafs.GetItemData(\r
-                               m_ListRefLeafs.GetNextSelectedItem(pos)));\r
-       }\r
-\r
-       CMenu popupMenu;\r
-       popupMenu.CreatePopupMenu();\r
-\r
-       if(selectedTrees.size()==1)\r
-       {\r
-               popupMenu.AppendMenu(MF_STRING,eCmd_ViewLog,L"View log");\r
-               if(selectedTrees[0]->IsFrom(L"refs/heads"))\r
-                       popupMenu.AppendMenu(MF_STRING,eCmd_DeleteBranch,L"Delete Branch");\r
-               else if(selectedTrees[0]->IsFrom(L"refs/tags"))\r
-                       popupMenu.AppendMenu(MF_STRING,eCmd_DeleteTag,L"Delete Tag");\r
-\r
-//             CShadowTree* pTree = (CShadowTree*)m_ListRefLeafs.GetItemData(pNMHDR->idFrom);\r
-//             if(pTree==NULL)\r
-//                     return;\r
-       }\r
-\r
-\r
-       eCmd cmd=(eCmd)popupMenu.TrackPopupMenuEx(TPM_LEFTALIGN|TPM_RETURNCMD, point.x, point.y, this, 0);\r
-       switch(cmd)\r
-       {\r
-       case eCmd_ViewLog:\r
-               {\r
-                       CLogDlg dlg;\r
-                       dlg.SetStartRef(selectedTrees[0]->m_csRefHash);\r
-                       dlg.DoModal();\r
-               }\r
-               break;\r
-       case eCmd_DeleteBranch:\r
-               {\r
-                       if(ConfirmDeleteRef(selectedTrees[0]->GetRefName()))\r
-                               DoDeleteRef(selectedTrees[0]->GetRefName(), true);\r
-                       Refresh();\r
-               }\r
-               break;\r
-       case eCmd_DeleteTag:\r
-               {\r
-                       if(ConfirmDeleteRef(selectedTrees[0]->GetRefName()))\r
-                               DoDeleteRef(selectedTrees[0]->GetRefName(), true);\r
-                       Refresh();\r
-               }\r
-               break;\r
-       }\r
-}\r
-\r
 bool CBrowseRefsDlg::ConfirmDeleteRef(CString completeRefName)\r
 {\r
        CString csMessage;\r
@@ -448,17 +387,53 @@ void CBrowseRefsDlg::OnContextMenu(CWnd* pWndFrom, CPoint point)
 \r
 void CBrowseRefsDlg::OnContextMenu_RefTreeCtrl(CPoint point)\r
 {\r
-       CMenu popupMenu;\r
-       popupMenu.CreatePopupMenu();\r
-\r
        CPoint clientPoint=point;\r
        m_RefTreeCtrl.ScreenToClient(&clientPoint);\r
 \r
        HTREEITEM hTreeItem=m_RefTreeCtrl.HitTest(clientPoint);\r
        if(hTreeItem!=NULL)\r
-       {\r
                m_RefTreeCtrl.Select(hTreeItem,TVGN_CARET);\r
-               CShadowTree* pTree=(CShadowTree*)m_RefTreeCtrl.GetItemData(hTreeItem);\r
+\r
+       ShowContextMenu(point,hTreeItem,VectorPShadowTree());\r
+}\r
+\r
+\r
+void CBrowseRefsDlg::OnContextMenu_ListRefLeafs(CPoint point)\r
+{\r
+       std::vector<CShadowTree*> selectedLeafs;\r
+       selectedLeafs.reserve(m_ListRefLeafs.GetSelectedCount());\r
+       POSITION pos=m_ListRefLeafs.GetFirstSelectedItemPosition();\r
+       while(pos)\r
+       {\r
+               selectedLeafs.push_back(\r
+                       (CShadowTree*)m_ListRefLeafs.GetItemData(\r
+                               m_ListRefLeafs.GetNextSelectedItem(pos)));\r
+       }\r
+\r
+       ShowContextMenu(point,m_RefTreeCtrl.GetSelectedItem(),selectedLeafs);\r
+}\r
+\r
+void CBrowseRefsDlg::ShowContextMenu(CPoint point, HTREEITEM hTreePos, VectorPShadowTree& selectedLeafs)\r
+{\r
+       CMenu popupMenu;\r
+       popupMenu.CreatePopupMenu();\r
+\r
+       if(selectedLeafs.size()==1)\r
+       {\r
+               popupMenu.AppendMenu(MF_STRING,eCmd_ViewLog,L"View log");\r
+               if(selectedLeafs[0]->IsFrom(L"refs/heads"))\r
+                       popupMenu.AppendMenu(MF_STRING,eCmd_DeleteBranch,L"Delete Branch");\r
+               else if(selectedLeafs[0]->IsFrom(L"refs/tags"))\r
+                       popupMenu.AppendMenu(MF_STRING,eCmd_DeleteTag,L"Delete Tag");\r
+\r
+//             CShadowTree* pTree = (CShadowTree*)m_ListRefLeafs.GetItemData(pNMHDR->idFrom);\r
+//             if(pTree==NULL)\r
+//                     return;\r
+       }\r
+\r
+       if(hTreePos!=NULL)\r
+       {\r
+               CShadowTree* pTree=(CShadowTree*)m_RefTreeCtrl.GetItemData(hTreePos);\r
                if(pTree->IsFrom(L"refs/remotes"))\r
                {\r
 //                     popupMenu.AppendMenu(MF_STRING,eCmd_AddRemote,L"Add Remote");\r
@@ -470,9 +445,31 @@ void CBrowseRefsDlg::OnContextMenu_RefTreeCtrl(CPoint point)
                        popupMenu.AppendMenu(MF_STRING,eCmd_CreateTag,L"Create Tag");\r
        }\r
 \r
+\r
        eCmd cmd=(eCmd)popupMenu.TrackPopupMenuEx(TPM_LEFTALIGN|TPM_RETURNCMD, point.x, point.y, this, 0);\r
        switch(cmd)\r
        {\r
+       case eCmd_ViewLog:\r
+               {\r
+                       CLogDlg dlg;\r
+                       dlg.SetStartRef(selectedLeafs[0]->m_csRefHash);\r
+                       dlg.DoModal();\r
+               }\r
+               break;\r
+       case eCmd_DeleteBranch:\r
+               {\r
+                       if(ConfirmDeleteRef(selectedLeafs[0]->GetRefName()))\r
+                               DoDeleteRef(selectedLeafs[0]->GetRefName(), true);\r
+                       Refresh();\r
+               }\r
+               break;\r
+       case eCmd_DeleteTag:\r
+               {\r
+                       if(ConfirmDeleteRef(selectedLeafs[0]->GetRefName()))\r
+                               DoDeleteRef(selectedLeafs[0]->GetRefName(), true);\r
+                       Refresh();\r
+               }\r
+               break;\r
        case eCmd_AddRemote:\r
                {\r
                        CAddRemoteDlg(this).DoModal();\r
index 12ac928..c251a9c 100644 (file)
@@ -37,6 +37,7 @@ public:
        TShadowTreeMap  m_ShadowTree;\r
        CShadowTree*    m_pParent;\r
 };\r
+typedef std::vector<CShadowTree*> VectorPShadowTree;\r
 \r
 class CBrowseRefsDlg : public CResizableStandAloneDialog\r
 {\r
@@ -94,5 +95,7 @@ public:
 \r
        void            OnContextMenu_ListRefLeafs(CPoint point);\r
        void            OnContextMenu_RefTreeCtrl(CPoint point);\r
+\r
+       void            ShowContextMenu(CPoint point, HTREEITEM hTreePos, VectorPShadowTree& selectedLeafs);\r
        virtual BOOL PreTranslateMessage(MSG* pMsg);\r
 };\r