From cf898449f75f4bd13c0cd21c64f142ae48e610a8 Mon Sep 17 00:00:00 2001 From: EugenyP Date: Thu, 20 Jul 2023 23:33:54 +0700 Subject: [PATCH 1/3] Single menuitem for plugin --- radiant/pluginmenu.cpp | 80 ++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/radiant/pluginmenu.cpp b/radiant/pluginmenu.cpp index 24f3814a..0b226fe7 100644 --- a/radiant/pluginmenu.cpp +++ b/radiant/pluginmenu.cpp @@ -41,53 +41,63 @@ void PlugInMenu_Add( QMenu* plugin_menu, IPlugIn* pPlugIn ){ const char *menuText; MenuStack menuStack; - menu = plugin_menu->addMenu( pPlugIn->getMenuName() ); - - menu->setTearOffEnabled( g_Layout_enableDetachableMenus.m_value ); - std::size_t nCount = pPlugIn->getCommandCount(); + globalErrorStream() << pPlugIn->getMenuName() << " mismatched > <. " << menuStack.size() << " submenu(s) not closed.\n"; { - while ( nCount > 0 ) - { - menuText = pPlugIn->getCommandTitle( --nCount ); + globalErrorStream() << pPlugIn->getMenuName() << " count: " << nCount << "\n"; + if (nCount > 1) { + menu = plugin_menu->addMenu( pPlugIn->getMenuName() ); + + menu->setTearOffEnabled( g_Layout_enableDetachableMenus.m_value ); + while ( nCount > 0 ) + { + menuText = pPlugIn->getCommandTitle( --nCount ); + + if ( menuText != 0 && strlen( menuText ) > 0 ) { + if ( plugin_menu_separator( menuText ) ) { + menu->addSeparator(); + } + else if ( plugin_submenu_in( menuText ) ) { + menuText = pPlugIn->getCommandTitle( --nCount ); + if ( plugin_menu_special( menuText ) ) { + globalErrorStream() << pPlugIn->getMenuName() << " Invalid title (" << menuText << ") for submenu.\n"; + continue; + } + menuStack.push( menu ); + menu = menu->addMenu( menuText ); + + menu->setTearOffEnabled( g_Layout_enableDetachableMenus.m_value ); - if ( menuText != 0 && strlen( menuText ) > 0 ) { - if ( plugin_menu_separator( menuText ) ) { - menu->addSeparator(); - } - else if ( plugin_submenu_in( menuText ) ) { - menuText = pPlugIn->getCommandTitle( --nCount ); - if ( plugin_menu_special( menuText ) ) { - globalErrorStream() << pPlugIn->getMenuName() << " Invalid title (" << menuText << ") for submenu.\n"; continue; } - menuStack.push( menu ); - menu = menu->addMenu( menuText ); - - menu->setTearOffEnabled( g_Layout_enableDetachableMenus.m_value ); - - continue; - } - else if ( plugin_submenu_out( menuText ) ) { - if ( !menuStack.empty() ) { - menu = menuStack.top(); - menuStack.pop(); + else if ( plugin_submenu_out( menuText ) ) { + if ( !menuStack.empty() ) { + menu = menuStack.top(); + menuStack.pop(); + } + else + { + globalErrorStream() << pPlugIn->getMenuName() << ": Attempt to end non-existent submenu ignored.\n"; + } + continue; } else { - globalErrorStream() << pPlugIn->getMenuName() << ": Attempt to end non-existent submenu ignored.\n"; + create_menu_item_with_mnemonic( menu, menuText, pPlugIn->getGlobalCommand( nCount ) ); } - continue; - } - else - { - create_menu_item_with_mnemonic( menu, menuText, pPlugIn->getGlobalCommand( nCount ) ); } } + if ( !menuStack.empty() ) { + globalErrorStream() << pPlugIn->getMenuName() << " mismatched > <. " << menuStack.size() << " submenu(s) not closed.\n"; + } + } else if (nCount == 1) { + menuText = pPlugIn->getCommandTitle( --nCount ); + + if ( menuText != 0 && strlen( menuText ) > 0 ) { + create_menu_item_with_mnemonic( plugin_menu, menuText, pPlugIn->getGlobalCommand( nCount ) ); + } } - if ( !menuStack.empty() ) { - globalErrorStream() << pPlugIn->getMenuName() << " mismatched > <. " << menuStack.size() << " submenu(s) not closed.\n"; - } + } } From 28b4a090f38e23d574c80d971d8db42672073a22 Mon Sep 17 00:00:00 2001 From: EugenyP Date: Thu, 20 Jul 2023 23:37:14 +0700 Subject: [PATCH 2/3] Update pluginmenu.cpp --- radiant/pluginmenu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radiant/pluginmenu.cpp b/radiant/pluginmenu.cpp index 0b226fe7..8d86af05 100644 --- a/radiant/pluginmenu.cpp +++ b/radiant/pluginmenu.cpp @@ -42,7 +42,7 @@ void PlugInMenu_Add( QMenu* plugin_menu, IPlugIn* pPlugIn ){ MenuStack menuStack; std::size_t nCount = pPlugIn->getCommandCount(); - globalErrorStream() << pPlugIn->getMenuName() << " mismatched > <. " << menuStack.size() << " submenu(s) not closed.\n"; + { globalErrorStream() << pPlugIn->getMenuName() << " count: " << nCount << "\n"; if (nCount > 1) { From aec594f0b8bc948b3875816f66a44810dc15f579 Mon Sep 17 00:00:00 2001 From: EugenyP Date: Thu, 20 Jul 2023 23:38:17 +0700 Subject: [PATCH 3/3] Update pluginmenu.cpp --- radiant/pluginmenu.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/radiant/pluginmenu.cpp b/radiant/pluginmenu.cpp index 8d86af05..a6510982 100644 --- a/radiant/pluginmenu.cpp +++ b/radiant/pluginmenu.cpp @@ -40,9 +40,8 @@ void PlugInMenu_Add( QMenu* plugin_menu, IPlugIn* pPlugIn ){ QMenu *menu; const char *menuText; MenuStack menuStack; - + std::size_t nCount = pPlugIn->getCommandCount(); - { globalErrorStream() << pPlugIn->getMenuName() << " count: " << nCount << "\n"; if (nCount > 1) {