mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-28 08:14:18 +02:00
[UPDATE] Method getContextMenuFromXmlTree refactoring
The method getContextMenuFromXmlTree of NppParameters is too long to maintain. Making 2 new methods to make the method in question more readable.
This commit is contained in:
parent
c0cd924c1e
commit
4ace901a07
@ -2149,7 +2149,7 @@ void Notepad_plus::command(int id)
|
||||
generic_string warning, title;
|
||||
_nativeLangSpeaker.messageBox("ContextMenuXmlEditWarning",
|
||||
_pPublicInterface->getHSelf(),
|
||||
TEXT("Editing contextMenu.xml allows you to modify your Notepad++ popup context menu.\rYou have to restart your Notepad++ to take effect after modifying contextMenu.xml."),
|
||||
TEXT("Editing contextMenu.xml allows you to modify your Notepad++ popup context menu on edit zone.\rYou have to restart your Notepad++ to take effect after modifying contextMenu.xml."),
|
||||
TEXT("Editing contextMenu"),
|
||||
MB_OK|MB_APPLMODAL);
|
||||
}
|
||||
|
@ -1832,6 +1832,91 @@ bool NppParameters::reloadContextMenuFromXmlTree(HMENU mainMenuHadle, HMENU plug
|
||||
return getContextMenuFromXmlTree(mainMenuHadle, pluginsMenu);
|
||||
}
|
||||
|
||||
int NppParameters::getCmdIdFromMenuEntryItemName(HMENU mainMenuHadle, generic_string menuEntryName, generic_string menuItemName)
|
||||
{
|
||||
int nbMenuEntry = ::GetMenuItemCount(mainMenuHadle);
|
||||
for (int i = 0; i < nbMenuEntry; ++i)
|
||||
{
|
||||
TCHAR menuEntryString[64];
|
||||
::GetMenuString(mainMenuHadle, i, menuEntryString, 64, MF_BYPOSITION);
|
||||
if (generic_stricmp(menuEntryName.c_str(), purgeMenuItemString(menuEntryString).c_str()) == 0)
|
||||
{
|
||||
vector< pair<HMENU, int> > 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.c_str(), purgeMenuItemString(cmdStr).c_str()) == 0)
|
||||
{
|
||||
return ::GetMenuItemID(currMenu, currMenuPos);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int NppParameters::getPluginCmdIdFromMenuEntryItemName(HMENU pluginsMenu, generic_string pluginName, generic_string pluginCmdName)
|
||||
{
|
||||
int nbPlugins = ::GetMenuItemCount(pluginsMenu);
|
||||
for (int i = 0; i < nbPlugins; ++i)
|
||||
{
|
||||
TCHAR menuItemString[256];
|
||||
::GetMenuString(pluginsMenu, i, menuItemString, 256, MF_BYPOSITION);
|
||||
if (generic_stricmp(pluginName.c_str(), purgeMenuItemString(menuItemString).c_str()) == 0)
|
||||
{
|
||||
HMENU pluginMenu = ::GetSubMenu(pluginsMenu, i);
|
||||
int nbPluginCmd = ::GetMenuItemCount(pluginMenu);
|
||||
for (int j = 0; j < nbPluginCmd; ++j)
|
||||
{
|
||||
TCHAR pluginCmdStr[256];
|
||||
::GetMenuString(pluginMenu, j, pluginCmdStr, 256, MF_BYPOSITION);
|
||||
if (generic_stricmp(pluginCmdName.c_str(), purgeMenuItemString(pluginCmdStr).c_str()) == 0)
|
||||
{
|
||||
return ::GetMenuItemID(pluginMenu, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool NppParameters::getContextMenuFromXmlTree(HMENU mainMenuHadle, HMENU pluginsMenu)
|
||||
{
|
||||
if (!_pXmlContextMenuDocA)
|
||||
@ -1875,59 +1960,9 @@ bool NppParameters::getContextMenuFromXmlTree(HMENU mainMenuHadle, HMENU plugins
|
||||
|
||||
if (menuEntryName != TEXT("") && menuItemName != TEXT(""))
|
||||
{
|
||||
int nbMenuEntry = ::GetMenuItemCount(mainMenuHadle);
|
||||
for (int i = 0 ; i < nbMenuEntry ; ++i)
|
||||
{
|
||||
TCHAR menuEntryString[64];
|
||||
::GetMenuString(mainMenuHadle, i, menuEntryString, 64, MF_BYPOSITION);
|
||||
if (generic_stricmp(menuEntryName.c_str(), purgeMenuItemString(menuEntryString).c_str()) == 0)
|
||||
{
|
||||
vector< pair<HMENU, int> > 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.c_str(), purgeMenuItemString(cmdStr).c_str()) == 0)
|
||||
{
|
||||
int cmdId = ::GetMenuItemID(currMenu, currMenuPos);
|
||||
_contextMenuItems.push_back(MenuItemUnit(cmdId, displayAs.c_str(), folderName.c_str()));
|
||||
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;
|
||||
}
|
||||
}
|
||||
int cmd = getCmdIdFromMenuEntryItemName(mainMenuHadle, menuEntryName, menuItemName);
|
||||
if (cmd != -1)
|
||||
_contextMenuItems.push_back(MenuItemUnit(cmd, displayAs.c_str(), folderName.c_str()));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1942,29 +1977,9 @@ bool NppParameters::getContextMenuFromXmlTree(HMENU mainMenuHadle, HMENU plugins
|
||||
// if plugin menu existing plls the value of PluginEntryName and PluginCommandItemName are valid
|
||||
if (pluginsMenu && pluginName != TEXT("") && pluginCmdName != TEXT(""))
|
||||
{
|
||||
int nbPlugins = ::GetMenuItemCount(pluginsMenu);
|
||||
for (int i = 0 ; i < nbPlugins ; ++i)
|
||||
{
|
||||
TCHAR menuItemString[256];
|
||||
::GetMenuString(pluginsMenu, i, menuItemString, 256, MF_BYPOSITION);
|
||||
if (generic_stricmp(pluginName.c_str(), purgeMenuItemString(menuItemString).c_str()) == 0)
|
||||
{
|
||||
HMENU pluginMenu = ::GetSubMenu(pluginsMenu, i);
|
||||
int nbPluginCmd = ::GetMenuItemCount(pluginMenu);
|
||||
for (int j = 0 ; j < nbPluginCmd ; ++j)
|
||||
{
|
||||
TCHAR pluginCmdStr[256];
|
||||
::GetMenuString(pluginMenu, j, pluginCmdStr, 256, MF_BYPOSITION);
|
||||
if (generic_stricmp(pluginCmdName.c_str(), purgeMenuItemString(pluginCmdStr).c_str()) == 0)
|
||||
{
|
||||
int pluginCmdId = ::GetMenuItemID(pluginMenu, j);
|
||||
_contextMenuItems.push_back(MenuItemUnit(pluginCmdId, displayAs.c_str(), folderName.c_str()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
int pluginCmdId = getPluginCmdIdFromMenuEntryItemName(pluginsMenu, pluginName, pluginCmdName);
|
||||
if (pluginCmdId != -1)
|
||||
_contextMenuItems.push_back(MenuItemUnit(pluginCmdId, displayAs.c_str(), folderName.c_str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1694,6 +1694,8 @@ private:
|
||||
void writePrintSetting(TiXmlElement *element);
|
||||
void initMenuKeys(); //initialise menu keys and scintilla keys. Other keys are initialized on their own
|
||||
void initScintillaKeys(); //these functions have to be called first before any modifications are loaded
|
||||
int getCmdIdFromMenuEntryItemName(HMENU mainMenuHadle, generic_string menuEntryName, generic_string menuItemName); // return -1 if not found
|
||||
int getPluginCmdIdFromMenuEntryItemName(HMENU pluginsMenu, generic_string pluginName, generic_string pluginCmdName); // return -1 if not found
|
||||
};
|
||||
|
||||
#endif //PARAMETERS_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user