Browse Source

Added shortcuts to groups menu

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@741 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 11 years ago
parent
commit
8d362e2aec
6 changed files with 242 additions and 109 deletions
  1. 134 26
      GroupTree.cpp
  2. 13 0
      GroupTree.h
  3. 84 1
      Misc.cpp
  4. 2 0
      Misc.h
  5. 7 2
      QPasteWnd.cpp
  6. 2 80
      WndEx.cpp

+ 134 - 26
GroupTree.cpp

@@ -4,6 +4,7 @@
 #include "stdafx.h"
 #include "cp_main.h"
 #include "GroupTree.h"
+#include "ActionEnums.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -40,6 +41,10 @@ BEGIN_MESSAGE_MAP(CGroupTree, CTreeCtrl)
 	ON_COMMAND(ID_MENU_NEWGROUP32896, &CGroupTree::OnMenuNewgroup32896)
 	ON_COMMAND(ID_MENU_DELETEGROUP, &CGroupTree::OnMenuDeletegroup)
 	ON_COMMAND(ID_MENU_PROPERTIES32898, &CGroupTree::OnMenuProperties32898)
+	ON_UPDATE_COMMAND_UI(ID_MENU_NEWGROUP32896, &CGroupTree::OnUpdateMenuNewgroup32896)
+	ON_UPDATE_COMMAND_UI(ID_MENU_DELETEGROUP, &CGroupTree::OnUpdateMenuDeletegroup)
+	ON_UPDATE_COMMAND_UI(ID_MENU_PROPERTIES32898, &CGroupTree::OnUpdateMenuProperties32898)
+	ON_WM_INITMENUPOPUP() 
 END_MESSAGE_MAP()
 
 
@@ -70,10 +75,101 @@ int CGroupTree::OnCreate(LPCREATESTRUCT lpCreateStruct)
 
 	SetImageList(&iml, TVSIL_NORMAL);
 	iml.Detach();
-		
+
+	m_actions.AddAccel(ActionEnums::NEWGROUP, ACCEL_MAKEKEY(VK_F7, HOTKEYF_CONTROL));
+	m_actions.AddAccel(ActionEnums::CLIP_PROPERTIES, ACCEL_MAKEKEY(VK_RETURN, HOTKEYF_ALT));
+	m_actions.AddAccel(ActionEnums::DELETE_SELECTED, VK_DELETE);
+
 	return 0;
 }
 
+BOOL CGroupTree::PreTranslateMessage(MSG *pMsg)
+{
+	if(CheckActions(pMsg))
+	{
+		return TRUE;
+	}
+
+	return CTreeCtrl::PreTranslateMessage(pMsg);
+}
+
+bool CGroupTree::CheckActions(MSG * pMsg) 
+{
+	bool ret = false;
+	DWORD dID;
+
+	if (m_actions.OnMsg(pMsg, dID))
+	{
+		ret = DoAction(dID);
+	}   
+
+	return ret;
+}
+
+bool CGroupTree::DoAction(DWORD actionId)
+{
+	bool ret = false;
+
+	switch (actionId)
+	{
+	case ActionEnums::NEWGROUP:
+		ret = DoActionNewGroup();
+		break;
+	case ActionEnums::DELETE_SELECTED:
+		ret = DoActionDeleteSelected();
+		break;
+	case ActionEnums::CLIP_PROPERTIES:
+		ret = DoActionClipProperties();
+		break;
+	}
+
+	return ret;
+}
+
+bool CGroupTree::DoActionNewGroup()
+{
+	HTREEITEM hItem = GetSelectedItem();
+	if (hItem)
+	{
+		int id = (int) GetItemData(hItem);
+		::PostMessage(m_NotificationWnd, NM_NEW_GROUP, id, 0);	
+		return true;
+	}
+
+	return false;
+}
+
+bool CGroupTree::DoActionDeleteSelected()
+{
+	HTREEITEM hItem = GetSelectedItem();
+	if (hItem)
+	{
+		int id = (int) GetItemData(hItem);
+		if (id >= 0)
+		{
+			::PostMessage(m_NotificationWnd, NM_DELETE_ID, id, 0);
+			return true;
+		}
+	}
+
+	return false;
+}
+
+bool CGroupTree::DoActionClipProperties()
+{
+	HTREEITEM hItem = GetSelectedItem();
+	if (hItem)
+	{
+		int id = (int) GetItemData(hItem);
+		if (id >= 0)
+		{
+			::PostMessage(m_NotificationWnd, NM_SHOW_PROPERTIES, id, 0);
+			return true;
+		}
+	}
+	return false;
+}
+
 void CGroupTree::FillTree()
 {	
 	DeleteAllItems();
@@ -269,38 +365,50 @@ void CGroupTree::OnRclickQuickPaste(NMHDR *pNMHDR, LRESULT *pResult)
 
 void CGroupTree::OnMenuNewgroup32896()
 {
-	HTREEITEM hItem = GetSelectedItem();
-	if (hItem)
-	{
-		int id = (int) GetItemData(hItem);
-		::PostMessage(m_NotificationWnd, NM_NEW_GROUP, id, 0);		
-	}
+	DoAction(ActionEnums::NEWGROUP);
 }
 
 
 void CGroupTree::OnMenuDeletegroup()
 {
-	HTREEITEM hItem = GetSelectedItem();
-	if (hItem)
-	{
-		int id = (int) GetItemData(hItem);
-		if (id >= 0)
-		{
-			::PostMessage(m_NotificationWnd, NM_DELETE_ID, id, 0);
-		}
-	}
+	DoAction(ActionEnums::DELETE_SELECTED);
 }
 
-
 void CGroupTree::OnMenuProperties32898()
 {
-	HTREEITEM hItem = GetSelectedItem();
-	if (hItem)
-	{
-		int id = (int) GetItemData(hItem);
-		if (id >= 0)
-		{
-			::PostMessage(m_NotificationWnd, NM_SHOW_PROPERTIES, id, 0);
-		}
-	}	
+	DoAction(ActionEnums::CLIP_PROPERTIES);
+}
+
+void CGroupTree::OnUpdateMenuNewgroup32896(CCmdUI *pCmdUI)
+{
+	UpdateMenuShortCut(pCmdUI, ActionEnums::NEWGROUP);
 }
+
+void CGroupTree::OnUpdateMenuDeletegroup(CCmdUI *pCmdUI)
+{
+	UpdateMenuShortCut(pCmdUI, ActionEnums::DELETE_SELECTED);	
+}
+
+void CGroupTree::OnUpdateMenuProperties32898(CCmdUI *pCmdUI)
+{
+	UpdateMenuShortCut(pCmdUI, ActionEnums::CLIP_PROPERTIES);	
+}
+
+void CGroupTree::UpdateMenuShortCut(CCmdUI *pCmdUI, DWORD action)
+{
+	CString cs;
+	pCmdUI->m_pMenu->GetMenuString(pCmdUI->m_nID, cs, MF_BYCOMMAND);
+	CString shortcutText = m_actions.GetCmdKeyText(action);
+	if(shortcutText != _T("") &&
+		cs.Find("\t" + shortcutText) < 0)
+	{
+		cs += "\t";
+		cs += shortcutText;
+		pCmdUI->SetText(cs);
+	}
+}
+
+void CGroupTree::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
+{
+	OnInitMenuPopupEx(pPopupMenu, nIndex, bSysMenu, this);
+}

+ 13 - 0
GroupTree.h

@@ -6,6 +6,7 @@
 #endif // _MSC_VER > 1000
 // GroupTree.h : header file
 //
+#include "Accels.h"
 
 /////////////////////////////////////////////////////////////////////////////
 // CGroupTree window
@@ -32,17 +33,25 @@ protected:
 	void FillTree(int parentId, HTREEITEM hParent);
 	void SendToParent(int parentId);
 	UINT GetSelectedCount() const;
+	bool CheckActions(MSG * pMsg);
+	bool DoAction(DWORD actionId);
+	bool DoActionNewGroup();
+	bool DoActionDeleteSelected();
+	bool DoActionClipProperties();
+	void UpdateMenuShortCut(CCmdUI *pCmdUI, DWORD action);
 
 	HWND m_NotificationWnd;
 	CBitmap m_bmOpenFolder;
 	CBitmap m_bmClosedFolder;
 	bool m_bSendAllready;
+	CAccels m_actions;
 
 // Overrides
 	// ClassWizard generated virtual function overrides
 	//{{AFX_VIRTUAL(CGroupTree)
 	public:
 	virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
+	virtual BOOL PreTranslateMessage(MSG *pMsg);
 	//}}AFX_VIRTUAL
 
 // Implementation
@@ -71,6 +80,10 @@ public:
 	afx_msg void OnMenuNewgroup32896();
 	afx_msg void OnMenuDeletegroup();
 	afx_msg void OnMenuProperties32898();
+	afx_msg void OnUpdateMenuNewgroup32896(CCmdUI *pCmdUI);
+	afx_msg void OnUpdateMenuDeletegroup(CCmdUI *pCmdUI);
+	afx_msg void OnUpdateMenuProperties32898(CCmdUI *pCmdUI);
+	afx_msg void OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu);
 };
 
 /////////////////////////////////////////////////////////////////////////////

+ 84 - 1
Misc.cpp

@@ -1052,4 +1052,87 @@ int FindNoCaseAndInsert(CString& mainStr, CString& findStr, CString preInsert, C
 	}
 
 	return replaceCount;
-}
+}
+
+void OnInitMenuPopupEx(CMenu *pPopupMenu, UINT nIndex, BOOL bSysMenu, CWnd *pWnd)
+{
+	ASSERT(pPopupMenu != NULL);
+	// Check the enabled state of various menu items.
+
+	CCmdUI state;
+	state.m_pMenu = pPopupMenu;
+	ASSERT(state.m_pOther == NULL);
+	ASSERT(state.m_pParentMenu == NULL);
+
+	// Determine if menu is popup in top-level menu and set m_pOther to
+	// it if so (m_pParentMenu == NULL indicates that it is secondary popup).
+	HMENU hParentMenu;
+	if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
+	{
+		state.m_pParentMenu = pPopupMenu;    // Parent == child for tracking popup.
+	}
+	else if ((hParentMenu = ::GetMenu(pWnd->m_hWnd)) != NULL)
+	{
+		CWnd* pParent = pWnd;
+		// Child windows don't have menus--need to go to the top!
+		if (pParent != NULL &&
+			(hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
+		{
+			int nIndexMax = ::GetMenuItemCount(hParentMenu);
+			for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
+			{
+				if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
+				{
+					// When popup is found, m_pParentMenu is containing menu.
+					state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
+					break;
+				}
+			}
+		}
+	}
+
+	state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
+	for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
+		state.m_nIndex++)
+	{
+		state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
+		if (state.m_nID == 0)
+			continue; // Menu separator or invalid cmd - ignore it.
+
+		ASSERT(state.m_pOther == NULL);
+		ASSERT(state.m_pMenu != NULL);
+		if (state.m_nID == (UINT)-1)
+		{
+			// Possibly a popup menu, route to first item of that popup.
+			state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
+			if (state.m_pSubMenu == NULL ||
+				(state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
+				state.m_nID == (UINT)-1)
+			{
+				continue;       // First item of popup can't be routed to.
+			}
+			state.DoUpdate(pWnd, TRUE);   // Popups are never auto disabled.
+		}
+		else
+		{
+			// Normal menu item.
+			// Auto enable/disable if frame window has m_bAutoMenuEnable
+			// set and command is _not_ a system command.
+			state.m_pSubMenu = NULL;
+			state.DoUpdate(pWnd, FALSE);
+		}
+
+		// Adjust for menu deletions and additions.
+		UINT nCount = pPopupMenu->GetMenuItemCount();
+		if (nCount < state.m_nIndexMax)
+		{
+			state.m_nIndex -= (state.m_nIndexMax - nCount);
+			while (state.m_nIndex < nCount &&
+				pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
+			{
+				state.m_nIndex++;
+			}
+		}
+		state.m_nIndexMax = nCount;
+	}
+} 

+ 2 - 0
Misc.h

@@ -144,4 +144,6 @@ __int64 FileSize(const TCHAR *fileName);
 
 int FindNoCaseAndInsert(CString& mainStr, CString& findStr, CString preInsert, CString postInsert);
 
+void OnInitMenuPopupEx(CMenu *pPopupMenu, UINT nIndex, BOOL bSysMenu, CWnd *pWnd);
+
 #endif // !defined(AFX_CP_GUI_GLOBALS__FBCDED09_A6F2_47EB_873F_50A746EBC86B__INCLUDED_)

+ 7 - 2
QPasteWnd.cpp

@@ -3976,7 +3976,12 @@ LRESULT CQPasteWnd::OnGroupTreeMessage(WPARAM wParam, LPARAM lParam)
 
     MoveControls();
 
-    if(id >= 0)
+	if(id == -1)
+	{
+		//go back to the main list
+		theApp.EnterGroupID(-1);
+	}
+	else if(id >= 0)
     {
         //Set the app flag so it does a send message to refresh the list
         //We need to do this because we set the list pos to 0 and with Post
@@ -4556,7 +4561,7 @@ void CQPasteWnd::UpdateMenuShortCut(CCmdUI *pCmdUI, DWORD action)
 	pCmdUI->m_pMenu->GetMenuString(pCmdUI->m_nID, cs, MF_BYCOMMAND);
 	CString shortcutText = m_actions.GetCmdKeyText(action);
 	if(shortcutText != _T("") &&
-		cs.Find(shortcutText) < 0)
+		cs.Find("\t" + shortcutText) < 0)
 	{
 		cs += "\t";
 		cs += shortcutText;

+ 2 - 80
WndEx.cpp

@@ -376,85 +376,7 @@ void CWndEx::OnSize(UINT nType, int cx, int cy)
 }
 
 
-void CWndEx::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
+void CWndEx::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex, BOOL bSysMenu)
 {
-    ASSERT(pPopupMenu != NULL);
-    // Check the enabled state of various menu items.
-	
-    CCmdUI state;
-    state.m_pMenu = pPopupMenu;
-    ASSERT(state.m_pOther == NULL);
-    ASSERT(state.m_pParentMenu == NULL);
-	
-    // Determine if menu is popup in top-level menu and set m_pOther to
-    // it if so (m_pParentMenu == NULL indicates that it is secondary popup).
-    HMENU hParentMenu;
-    if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
-	{
-        state.m_pParentMenu = pPopupMenu;    // Parent == child for tracking popup.
-	}
-    else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
-    {
-        CWnd* pParent = this;
-		// Child windows don't have menus--need to go to the top!
-        if (pParent != NULL &&
-			(hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
-        {
-			int nIndexMax = ::GetMenuItemCount(hParentMenu);
-			for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
-			{
-				if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
-				{
-					// When popup is found, m_pParentMenu is containing menu.
-					state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
-					break;
-				}
-			}
-        }
-    }
-	
-    state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
-    for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
-	state.m_nIndex++)
-    {
-        state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
-        if (state.m_nID == 0)
-			continue; // Menu separator or invalid cmd - ignore it.
-		
-        ASSERT(state.m_pOther == NULL);
-        ASSERT(state.m_pMenu != NULL);
-        if (state.m_nID == (UINT)-1)
-        {
-			// Possibly a popup menu, route to first item of that popup.
-			state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
-			if (state.m_pSubMenu == NULL ||
-				(state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
-				state.m_nID == (UINT)-1)
-			{
-				continue;       // First item of popup can't be routed to.
-			}
-			state.DoUpdate(this, TRUE);   // Popups are never auto disabled.
-        }
-        else
-        {
-			// Normal menu item.
-			// Auto enable/disable if frame window has m_bAutoMenuEnable
-			// set and command is _not_ a system command.
-			state.m_pSubMenu = NULL;
-			state.DoUpdate(this, FALSE);
-        }
-		
-        // Adjust for menu deletions and additions.
-        UINT nCount = pPopupMenu->GetMenuItemCount();
-        if (nCount < state.m_nIndexMax)
-        {
-			state.m_nIndex -= (state.m_nIndexMax - nCount);
-			while (state.m_nIndex < nCount &&
-				pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
-			{
-				state.m_nIndex++;
-			}
-        }
-        state.m_nIndexMax = nCount;
-    }
+	OnInitMenuPopupEx(pPopupMenu, nIndex, bSysMenu, this);
 }