private void CreateMenu_ValidGitFile(HMenu hMenu, uint iMenu, uint idCmdFirst, uint idCmdLast, CMF uFlags) { Bitmap bpCopy = Resource1.home; //add menu items Helpers.InsertMenu(hMenu, (int)iMenu, MFMENU.MF_BYPOSITION | MFMENU.MF_STRING, new IntPtr(idCmdFirst + 7), "NGit Blame History"); Helpers.SetMenuItemBitmaps(hMenu, (int)iMenu, MFMENU.MF_BYPOSITION, bpCopy.GetHbitmap(), bpCopy.GetHbitmap()); ////add menu items //Helpers.InsertMenu(hMenu, (int)iMenu, MFMENU.MF_BYPOSITION | MFMENU.MF_STRING, new IntPtr(idCmdFirst + 7), "NGit Resolve Conflict"); //Helpers.SetMenuItemBitmaps(hMenu, (int)iMenu+1, MFMENU.MF_BYPOSITION, bpCopy.GetHbitmap(), bpCopy.GetHbitmap()); //Create Sub-Menu HMenu submenu = ShellLib.Helpers.CreatePopupMenu(); Helpers.AppendMenu(submenu, MFMENU.MF_STRING, new IntPtr(idCmdFirst + 3), "Working Area"); Helpers.AppendMenu(submenu, MFMENU.MF_STRING, new IntPtr(idCmdFirst + 4), "Local Storage"); Helpers.AppendMenu(submenu, MFMENU.MF_STRING, new IntPtr(idCmdFirst + 5), "Remote Storage"); Helpers.AppendMenu(submenu, MFMENU.MF_STRING, new IntPtr(idCmdFirst + 6), "Main APP"); Helpers.InsertMenu(hMenu, (int)iMenu + 2, MFMENU.MF_BYPOSITION | MFMENU.MF_POPUP, submenu.handle, "NGit Main"); //add icon into sub-menu //Bitmap bpCopy = Resource1.copy; Helpers.SetMenuItemBitmaps(submenu, 0, MFMENU.MF_BYPOSITION, bpCopy.GetHbitmap(), bpCopy.GetHbitmap()); Helpers.SetMenuItemBitmaps(submenu, 1, MFMENU.MF_BYPOSITION, bpCopy.GetHbitmap(), bpCopy.GetHbitmap()); Helpers.SetMenuItemBitmaps(submenu, 2, MFMENU.MF_BYPOSITION, bpCopy.GetHbitmap(), bpCopy.GetHbitmap()); Helpers.SetMenuItemBitmaps(submenu, 3, MFMENU.MF_BYPOSITION, bpCopy.GetHbitmap(), bpCopy.GetHbitmap()); Helpers.InsertMenu(hMenu, (int)iMenu + 3, MFMENU.MF_BYPOSITION | MFMENU.MF_SEPARATOR, new IntPtr(idCmdFirst + 0), "NGit line"); }
int IContextMenu.QueryContextMenu(HMenu hMenu, uint iMenu, uint idCmdFirst, uint idCmdLast, CMF uFlags) { int id = 0; if ((uFlags & (CMF.CMF_VERBSONLY | CMF.CMF_DEFAULTONLY | CMF.CMF_NOVERBS)) == 0 || (uFlags & CMF.CMF_EXPLORE) != 0) { //创建子菜单 HMenu submenu = ShellLib.Helpers.CreatePopupMenu(); Helpers.AppendMenu(submenu, MFMENU.MF_STRING, new IntPtr(idCmdFirst + id++), "上传"); Helpers.AppendMenu(submenu, MFMENU.MF_STRING, new IntPtr(idCmdFirst + id++), "下载"); Helpers.AppendMenu(submenu, MFMENU.MF_STRING, new IntPtr(idCmdFirst + id++), "查看远程文件"); //将子菜单插入到上下文菜单中 Helpers.InsertMenu(hMenu, 1, MFMENU.MF_BYPOSITION | MFMENU.MF_POPUP, submenu.handle, "FTP管理"); //为菜单增加图标 Bitmap bpCopy = Resource1.copy; Helpers.SetMenuItemBitmaps(submenu, 0, MFMENU.MF_BYPOSITION, bpCopy.GetHbitmap(), bpCopy.GetHbitmap()); Helpers.SetMenuItemBitmaps(submenu, 1, MFMENU.MF_BYPOSITION, bpCopy.GetHbitmap(), bpCopy.GetHbitmap()); Bitmap bpHome = Resource1.home; Helpers.SetMenuItemBitmaps(submenu, 2, MFMENU.MF_BYPOSITION, bpHome.GetHbitmap(), bpHome.GetHbitmap()); } return id; }
internal static extern int SetMenuItemBitmaps(HMenu hmenu, int nPosition, MFMENU uflags, IntPtr hBitmapUnchecked, IntPtr hBitmapChecked);
int IContextMenu.QueryContextMenu(HMenu hMenu, uint iMenu, uint idCmdFirst, uint idCmdLast, CMF uFlags) { //if ((uFlags & (CMF.CMF_VERBSONLY | CMF.CMF_DEFAULTONLY | CMF.CMF_NOVERBS)) == 0 || if ((uFlags & (CMF.CMF_DEFAULTONLY | CMF.CMF_NOVERBS)) == 0 || (uFlags & CMF.CMF_EXPLORE) != 0) { uint nselected = Helpers.DragQueryFile(m_hDrop, 0xffffffff, null, 0); if (nselected <= 0 && string.IsNullOrEmpty(m_szFoderPath) ) { CreateMenu_Base(hMenu, iMenu, idCmdFirst, idCmdLast, uFlags); } else if(false==string.IsNullOrEmpty(m_szFoderPath)) //valid blank right click context menu { if (string.IsNullOrEmpty(CHelpFuntions.GetValidWorkingDir(m_szFoderPath))) { CreateMenu_InValidGit(hMenu, iMenu, idCmdFirst, idCmdLast, uFlags); } else { CreateMenu_ValidGit(hMenu, iMenu, idCmdFirst, idCmdLast, uFlags); } } else if(nselected >1) { CreateMenu_Base(hMenu, iMenu, idCmdFirst, idCmdLast, uFlags); } else if(nselected ==1) { StringBuilder sb = new StringBuilder(1024); ShellLib.Helpers.DragQueryFile(m_hDrop, 0, sb, sb.Capacity + 1); string szDir=sb.ToString(); if (Directory.Exists(szDir)) { if (string.IsNullOrEmpty(CHelpFuntions.GetValidWorkingDir(szDir))) { CreateMenu_InValidGit(hMenu, iMenu, idCmdFirst, idCmdLast, uFlags); } else { CreateMenu_ValidGit(hMenu, iMenu, idCmdFirst, idCmdLast, uFlags); } } else { if (string.IsNullOrEmpty(CHelpFuntions.GetValidWorkingDir(szDir))) { CreateMenu_Base(hMenu, iMenu, idCmdFirst, idCmdLast, uFlags); } else { if (m_NgitMgr != null) { FileSccStatus status = m_NgitMgr.GetFileStatus(szDir); if (status == FileSccStatus.ST_CONFLICT) { CreateMenu_ConflictFile(hMenu, iMenu, idCmdFirst, idCmdLast, uFlags); } else if (status != FileSccStatus.ST_NOT_CONTROLLED && status != FileSccStatus.ST_IGNORED && status != FileSccStatus.ST_INVALID_REPO && status != FileSccStatus.ST_NULL) { CreateMenu_ValidGitFile(hMenu, iMenu, idCmdFirst, idCmdLast, uFlags); } else { CreateMenu_Base(hMenu, iMenu, idCmdFirst, idCmdLast, uFlags); } } } } } } return 8; }
internal static extern bool InsertMenu(HMenu hmenu, int position, MFMENU uflags, IntPtr uIDNewItemOrSubmenu, string text);
internal static extern bool InsertMenuItem(HMenu hmenu, uint uposition, uint uflags, ref MENUITEMINFO mii);
internal static extern bool AppendMenu(HMenu hmenu, MFMENU uflags, IntPtr uIDNewItemOrSubmenu, string text);