From 60df74568ec5d8ddb53d3b3bd42285b4db4540c8 Mon Sep 17 00:00:00 2001 From: Antoine Beauchamp Date: Wed, 29 Dec 2021 13:21:16 -0500 Subject: [PATCH] Modified Menu class to not use the Node class. For issue #102 --- include/shellanything/Action.h | 1 - include/shellanything/Menu.h | 12 +++++-- include/shellanything/Validator.h | 1 - src/Menu.cpp | 31 ++++++++++++----- src/ObjectFactory.cpp | 2 +- src/shellext.cpp | 2 +- test/TestConfigManager.cpp | 12 +++---- test/TestMenu.cpp | 56 +++++++++++++++---------------- test/TestWin32Registry.cpp | 1 - 9 files changed, 67 insertions(+), 51 deletions(-) diff --git a/include/shellanything/Action.h b/include/shellanything/Action.h index 257e367..8d8be86 100644 --- a/include/shellanything/Action.h +++ b/include/shellanything/Action.h @@ -25,7 +25,6 @@ #ifndef SA_ACTION_H #define SA_ACTION_H -#include "shellanything/Node.h" #include "shellanything/Context.h" #include diff --git a/include/shellanything/Menu.h b/include/shellanything/Menu.h index f6633c0..ed86624 100644 --- a/include/shellanything/Menu.h +++ b/include/shellanything/Menu.h @@ -25,7 +25,6 @@ #ifndef SA_MENU_H #define SA_MENU_H -#include "shellanything/Node.h" #include "shellanything/Icon.h" #include "shellanything/Validator.h" #include "shellanything/Action.h" @@ -52,7 +51,7 @@ namespace shellanything /// /// The Menu class defines a displayed menu option. /// - class Menu : public Node + class Menu { public: /// @@ -260,10 +259,16 @@ namespace shellanything /// const Action::ActionPtrList & GetActions() const; + /// + /// Add a new sub menu to the menu. The menu instance takes ownership of the sub menu. + /// + /// The given menu to add as a sub menu + void AddMenu(Menu* menu); + /// /// Get the list of submenu of the menu. /// - MenuPtrList GetSubMenus(); + MenuPtrList2 GetSubMenus(); private: Icon mIcon; @@ -278,6 +283,7 @@ namespace shellanything int mNameMaxLength; std::string mDescription; Action::ActionPtrList mActions; + MenuPtrList2 mSubMenus; }; } //namespace shellanything diff --git a/include/shellanything/Validator.h b/include/shellanything/Validator.h index fab5623..d4f351f 100644 --- a/include/shellanything/Validator.h +++ b/include/shellanything/Validator.h @@ -25,7 +25,6 @@ #ifndef SA_VALIDATION_H #define SA_VALIDATION_H -#include "shellanything/Node.h" #include "shellanything/Context.h" #include #include diff --git a/src/Menu.cpp b/src/Menu.cpp index 50489a5..4baae9b 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -39,7 +39,7 @@ namespace shellanything const uint32_t Menu::INVALID_COMMAND_ID = 0; const int Menu::DEFAULT_NAME_MAX_LENGTH = 250; - Menu::Menu() : Node("Menu"), + Menu::Menu() : mNameMaxLength(DEFAULT_NAME_MAX_LENGTH), mSeparator(false), mColumnSeparator(false), @@ -74,6 +74,14 @@ namespace shellanything delete action; } mActions.clear(); + + // submenus + for(size_t i=0; i(this->FindChildren("Menu")); - bool parent_menu = (sub_menus.size() != 0); + bool parent_menu = (mSubMenus.size() != 0); return parent_menu; } @@ -207,7 +214,7 @@ namespace shellanything bool all_invisible_children = true; //for each child - Menu::MenuPtrList children = GetSubMenus(); + MenuPtrList2 children = GetSubMenus(); for(size_t i=0; i(this->FindChildren("Menu")); - return sub_menus; + return mSubMenus; + } + + void Menu::AddMenu(Menu* menu) + { + mSubMenus.AddElement(menu); } void Menu::AddAction(Action * action) @@ -361,4 +372,6 @@ namespace shellanything return mActions; } + void AddMenu(Menu* menu); + } //namespace shellanything diff --git a/src/ObjectFactory.cpp b/src/ObjectFactory.cpp index e2e4edf..1f7a3b0 100644 --- a/src/ObjectFactory.cpp +++ b/src/ObjectFactory.cpp @@ -685,7 +685,7 @@ namespace shellanything delete menu; return NULL; } - menu->AddChild(submenu); + menu->AddMenu(submenu); } //find node under diff --git a/src/shellext.cpp b/src/shellext.cpp index cb90d41..361c5f2 100644 --- a/src/shellext.cpp +++ b/src/shellext.cpp @@ -399,7 +399,7 @@ void CContextMenu::BuildMenuTree(HMENU hMenu, shellanything::Menu * menu, UINT & bool next_sub_menu_is_column = false; - shellanything::Menu::MenuPtrList subs = menu->GetSubMenus(); + shellanything::MenuPtrList2 subs = menu->GetSubMenus(); UINT sub_insert_pos = 0; for(size_t i=0; iGetSubMenus(); + MenuPtrList2 submenus = menu->GetSubMenus(); for(size_t i=0; iGetSubMenus(); + MenuPtrList2 menus = parent->GetSubMenus(); if (index >= menus.size()) return NULL; //out of bounds @@ -503,7 +503,7 @@ namespace shellanything { namespace test ASSERT_TRUE( option1_2_1_1 != NULL ); //Query all menus - Menu::MenuPtrList menus; + MenuPtrList2 menus; QueryAllMenusRecursive(configs[0], menus); //Update the menus based on a context with a single file diff --git a/test/TestMenu.cpp b/test/TestMenu.cpp index 4cba7a0..6e2daee 100644 --- a/test/TestMenu.cpp +++ b/test/TestMenu.cpp @@ -132,11 +132,11 @@ namespace shellanything { namespace test ASSERT_FALSE( deleted ); //build tree - root->AddChild(body); - body->AddChild(child1); - body->AddChild(child2); - body->AddChild(child3); - child3->AddChild(my_test_menu); //root takes ownership of my_test_menu + root->AddMenu(body); + body->AddMenu(child1); + body->AddMenu(child2); + body->AddMenu(child3); + child3->AddMenu(my_test_menu); //root takes ownership of my_test_menu //destroy the tree delete root; @@ -161,10 +161,10 @@ namespace shellanything { namespace test ASSERT_FALSE( deleted ); //build tree - root->AddChild(body); - body->AddChild(child1); - body->AddChild(child2); - body->AddChild(child3); + root->AddMenu(body); + body->AddMenu(child1); + body->AddMenu(child2); + body->AddMenu(child3); child3->AddAction(my_test_action); //child3 takes ownership of my_test_menu //destroy the tree @@ -212,12 +212,12 @@ namespace shellanything { namespace test ASSERT_TRUE( root->GetSubMenus().empty() ); //build tree - root->AddChild(body); - body->AddChild(child1); - body->AddChild(child2); - body->AddChild(child3); + root->AddMenu(body); + body->AddMenu(child1); + body->AddMenu(child2); + body->AddMenu(child3); - Menu::MenuPtrList subs = body->GetSubMenus(); + MenuPtrList2 subs = body->GetSubMenus(); ASSERT_EQ(3, subs.size()); ASSERT_EQ( child1, subs[0] ); ASSERT_EQ( child2, subs[1] ); @@ -240,13 +240,13 @@ namespace shellanything { namespace test Menu * child6 = NewMenu("p2"); //build tree - root->AddChild(body); - body->AddChild(child1); - body->AddChild(child2); - body->AddChild(child3); - child3->AddChild(child4); - child3->AddChild(child5); - body->AddChild(child6); + root->AddMenu(body); + body->AddMenu(child1); + body->AddMenu(child2); + body->AddMenu(child3); + child3->AddMenu(child4); + child3->AddMenu(child5); + body->AddMenu(child6); //act uint32_t nextAvailableId = root->AssignCommandIds(101); @@ -279,13 +279,13 @@ namespace shellanything { namespace test Menu * child6 = NewMenu("p2"); //build tree - root->AddChild(body); - body->AddChild(child1); - body->AddChild(child2); - body->AddChild(child3); - child3->AddChild(child4); - child3->AddChild(child5); - body->AddChild(child6); + root->AddMenu(body); + body->AddMenu(child1); + body->AddMenu(child2); + body->AddMenu(child3); + child3->AddMenu(child4); + child3->AddMenu(child5); + body->AddMenu(child6); //act uint32_t nextAvailableId = root->AssignCommandIds(101); diff --git a/test/TestWin32Registry.cpp b/test/TestWin32Registry.cpp index 1815028..8078bce 100644 --- a/test/TestWin32Registry.cpp +++ b/test/TestWin32Registry.cpp @@ -41,7 +41,6 @@ #include "rapidassist/strings.h" #include "rapidassist/filesystem.h" #include "rapidassist/testing.h" -#include "shellanything/Node.h" namespace shellanything { namespace test {