From 10aa27cfe5be053603ee822f716b4747c4f3c961 Mon Sep 17 00:00:00 2001 From: Thell Fowler Date: Wed, 29 Apr 2009 17:30:32 +0000 Subject: [PATCH] [BUG_FIXED] Fixed context menu population to check sub menus of main menu entries. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@472 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.rc | 1 + PowerEditor/src/Parameters.cpp | 54 +++++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index 0dca6778..7d8b5cda 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -207,6 +207,7 @@ BEGIN MENUITEM "Cu&t", IDM_EDIT_CUT MENUITEM "&Copy", IDM_EDIT_COPY MENUITEM "&Paste", IDM_EDIT_PASTE + MENUITEM "&Delete", IDM_EDIT_DELETE MENUITEM "Select A&ll", IDM_EDIT_SELECTALL MENUITEM SEPARATOR POPUP "Copy to clipboard" diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index b2b48570..8b579b2a 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -1191,19 +1191,49 @@ bool NppParameters::getContextMenuFromXmlTree(HMENU mainMenuHadle) ::GetMenuString(mainMenuHadle, i, menuEntryString, 64, MF_BYPOSITION); if (generic_stricmp(menuEntryName, purgeMenuItemString(menuEntryString).c_str()) == 0) { - HMENU subMenu = ::GetSubMenu(mainMenuHadle, i); - int nbSubMenuCmd = ::GetMenuItemCount(subMenu); - for (int j = 0 ; j < nbSubMenuCmd ; j++) - { - TCHAR cmdStr[256]; - ::GetMenuString(subMenu, j, cmdStr, 256, MF_BYPOSITION); - if (generic_stricmp(menuItemName, purgeMenuItemString(cmdStr).c_str()) == 0) - { - int cmdId = ::GetMenuItemID(subMenu, j); - _contextMenuItems.push_back(MenuItemUnit(cmdId, TEXT(""))); - break; + vector< pair > parentMenuPos; + HMENU topMenu = ::GetSubMenu(mainMenuHadle, i); + int maxTopMenuPos = ::GetMenuItemCount(topMenu); + HMENU currMenu = topMenu; + int currMaxMenuPos = maxTopMenuPos; + + int currMenuPos = 0; + bool notFound = false; + + do { + if ( ::GetSubMenu( currMenu, currMenuPos ) ) { + // Go into sub menu + parentMenuPos.push_back( ::make_pair( currMenu, currMenuPos ) ); + currMenu = ::GetSubMenu( currMenu, currMenuPos ); + currMenuPos = 0; + currMaxMenuPos = ::GetMenuItemCount(currMenu); } - } + else { + // Check current menu position. + TCHAR cmdStr[256]; + ::GetMenuString(currMenu, currMenuPos, cmdStr, 256, MF_BYPOSITION); + if (generic_stricmp(menuItemName, purgeMenuItemString(cmdStr).c_str()) == 0) + { + int cmdId = ::GetMenuItemID(currMenu, currMenuPos); + _contextMenuItems.push_back(MenuItemUnit(cmdId, TEXT(""))); + break; + } + + if ( ( currMenuPos >= currMaxMenuPos ) && ( parentMenuPos.size() > 0 ) ) { + currMenu = parentMenuPos.back().first; + currMenuPos = parentMenuPos.back().second; + parentMenuPos.pop_back(); + currMaxMenuPos = ::GetMenuItemCount( currMenu ); + } + + if ( ( currMenu == topMenu ) && ( currMenuPos >= maxTopMenuPos ) ) { + notFound = true; + } + else { + currMenuPos++; + } + } + } while (! notFound ); break; } }