Skip to content

Commit

Permalink
Modified Menu class to not use the Node class.
Browse files Browse the repository at this point in the history
For issue #102
  • Loading branch information
end2endzone committed Dec 29, 2021
1 parent 934d061 commit 60df745
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 51 deletions.
1 change: 0 additions & 1 deletion include/shellanything/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#ifndef SA_ACTION_H
#define SA_ACTION_H

#include "shellanything/Node.h"
#include "shellanything/Context.h"
#include <vector>

Expand Down
12 changes: 9 additions & 3 deletions include/shellanything/Menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -52,7 +51,7 @@ namespace shellanything
/// <summary>
/// The Menu class defines a displayed menu option.
/// </summary>
class Menu : public Node
class Menu
{
public:
/// <summary>
Expand Down Expand Up @@ -260,10 +259,16 @@ namespace shellanything
/// </summary>
const Action::ActionPtrList & GetActions() const;

/// <summary>
/// Add a new sub menu to the menu. The menu instance takes ownership of the sub menu.
/// </summary>
/// <param name="menu">The given menu to add as a sub menu</param>
void AddMenu(Menu* menu);

/// <summary>
/// Get the list of submenu of the menu.
/// </summary>
MenuPtrList GetSubMenus();
MenuPtrList2 GetSubMenus();

private:
Icon mIcon;
Expand All @@ -278,6 +283,7 @@ namespace shellanything
int mNameMaxLength;
std::string mDescription;
Action::ActionPtrList mActions;
MenuPtrList2 mSubMenus;
};

} //namespace shellanything
Expand Down
1 change: 0 additions & 1 deletion include/shellanything/Validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#ifndef SA_VALIDATION_H
#define SA_VALIDATION_H

#include "shellanything/Node.h"
#include "shellanything/Context.h"
#include <string>
#include <vector>
Expand Down
31 changes: 22 additions & 9 deletions src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -74,6 +74,14 @@ namespace shellanything
delete action;
}
mActions.clear();

// submenus
for(size_t i=0; i<mSubMenus.size(); i++)
{
Menu * sub = mSubMenus[i];
delete sub;
}
mSubMenus.Clear();
}

bool Menu::IsSeparator() const
Expand All @@ -98,8 +106,7 @@ namespace shellanything

bool Menu::IsParentMenu() const
{
Menu::MenuPtrList sub_menus = FilterNodes<Menu*>(this->FindChildren("Menu"));
bool parent_menu = (sub_menus.size() != 0);
bool parent_menu = (mSubMenus.size() != 0);
return parent_menu;
}

Expand Down Expand Up @@ -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<children.size(); i++)
{
Menu * child = children[i];
Expand All @@ -232,7 +239,7 @@ namespace shellanything
return this;

//for each child
Menu::MenuPtrList children = GetSubMenus();
MenuPtrList2 children = GetSubMenus();
for(size_t i=0; i<children.size(); i++)
{
Menu * child = children[i];
Expand Down Expand Up @@ -261,7 +268,7 @@ namespace shellanything
}

//for each child
Menu::MenuPtrList children = GetSubMenus();
MenuPtrList2 children = GetSubMenus();
for(size_t i=0; i<children.size(); i++)
{
Menu * child = children[i];
Expand Down Expand Up @@ -345,10 +352,14 @@ namespace shellanything
mVisibilities.push_back(validator);
}

Menu::MenuPtrList Menu::GetSubMenus()
MenuPtrList2 Menu::GetSubMenus()
{
Menu::MenuPtrList sub_menus = FilterNodes<Menu*>(this->FindChildren("Menu"));
return sub_menus;
return mSubMenus;
}

void Menu::AddMenu(Menu* menu)
{
mSubMenus.AddElement(menu);
}

void Menu::AddAction(Action * action)
Expand All @@ -361,4 +372,6 @@ namespace shellanything
return mActions;
}

void AddMenu(Menu* menu);

} //namespace shellanything
2 changes: 1 addition & 1 deletion src/ObjectFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ namespace shellanything
delete menu;
return NULL;
}
menu->AddChild(submenu);
menu->AddMenu(submenu);
}

//find <icon> node under <menu>
Expand Down
2 changes: 1 addition & 1 deletion src/shellext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<subs.size(); i++)
{
Expand Down
12 changes: 6 additions & 6 deletions test/TestConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ namespace shellanything { namespace test
return c;
}

void QueryAllMenusRecursive(Menu * menu, Menu::MenuPtrList & list)
void QueryAllMenusRecursive(Menu * menu, MenuPtrList2 & list)
{
if (menu == NULL)
return;

list.push_back(menu);
list.AddElement(menu);

Menu::MenuPtrList submenus = menu->GetSubMenus();
MenuPtrList2 submenus = menu->GetSubMenus();
for(size_t i=0; i<submenus.size(); i++)
{
Menu * submenu = submenus[i];
QueryAllMenusRecursive(submenu, list);
}
}

void QueryAllMenusRecursive(Configuration * config, Menu::MenuPtrList & list)
void QueryAllMenusRecursive(Configuration * config, MenuPtrList2 & list)
{
if (config == NULL)
return;
Expand All @@ -104,7 +104,7 @@ namespace shellanything { namespace test
if (parent == NULL)
return NULL;

Menu::MenuPtrList menus = parent->GetSubMenus();
MenuPtrList2 menus = parent->GetSubMenus();
if (index >= menus.size())
return NULL; //out of bounds

Expand Down Expand Up @@ -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
Expand Down
56 changes: 28 additions & 28 deletions test/TestMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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] );
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion test/TestWin32Registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "rapidassist/strings.h"
#include "rapidassist/filesystem.h"
#include "rapidassist/testing.h"
#include "shellanything/Node.h"

namespace shellanything { namespace test
{
Expand Down

0 comments on commit 60df745

Please sign in to comment.