Skip to content

Commit

Permalink
Modified Action.h and created ActionPtrList based on ListsDeclaration…
Browse files Browse the repository at this point in the history
….inc and ListsBody.inc.

Implemented clear() in ListsDeclaration.inc and ListsBody.inc for std::vector and std::list code compatibility.
For #102
  • Loading branch information
end2endzone committed Dec 30, 2021
1 parent 9b6d925 commit 7904429
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 33 deletions.
15 changes: 9 additions & 6 deletions include/shellanything/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#define SA_ACTION_H

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

namespace shellanything
{
Expand All @@ -37,11 +36,6 @@ namespace shellanything
class Action
{
public:
/// <summary>
/// A list of Action class pointers.
/// </summary>
typedef std::vector<Action*> ActionPtrList;

Action();
virtual ~Action();

Expand All @@ -62,4 +56,13 @@ namespace shellanything

} //namespace shellanything

/// <summary>
/// A list of Action pointer.
/// </summary>
#define SA_LISTS_CLASS_NAME ActionPtrList
#define SA_LISTS_BASE_TYPE Action *
#include "shellanything/ListsDeclaration.inc"
#undef SA_LISTS_BASE_TYPE
#undef SA_LISTS_CLASS_NAME

#endif //SA_ACTION_H
5 changes: 2 additions & 3 deletions include/shellanything/DefaultSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include "shellanything/Action.h"
#include <string>
#include <vector>
#include <stdint.h>

namespace shellanything
Expand Down Expand Up @@ -58,10 +57,10 @@ namespace shellanything
/// <summary>
/// Get the list of action of the menu.
/// </summary>
const Action::ActionPtrList & GetActions() const;
const ActionPtrList & GetActions() const;

private:
Action::ActionPtrList mActions;
ActionPtrList mActions;
};

} //namespace shellanything
Expand Down
2 changes: 2 additions & 0 deletions include/shellanything/ListsBody.inc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* SOFTWARE.
*********************************************************************************/

#include <vector>

namespace shellanything
{

Expand Down
1 change: 1 addition & 0 deletions include/shellanything/ListsDeclaration.inc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
/// Remove all elements in the list.
/// </summary>
void Clear();
inline void clear() { Clear(); } // for std::vector and std::list code compatibility.

/// <summary>
/// Get an element from an index.
Expand Down
4 changes: 2 additions & 2 deletions include/shellanything/Menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ namespace shellanything
/// <summary>
/// Get the list of action of the menu.
/// </summary>
const Action::ActionPtrList & GetActions() const;
const ActionPtrList & GetActions() const;

/// <summary>
/// Add a new sub menu to the menu. The menu instance takes ownership of the sub menu.
Expand All @@ -282,7 +282,7 @@ namespace shellanything
std::string mName;
int mNameMaxLength;
std::string mDescription;
Action::ActionPtrList mActions;
ActionPtrList mActions;
MenuPtrList2 mSubMenus;
};

Expand Down
9 changes: 9 additions & 0 deletions src/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ namespace shellanything
}

} //namespace shellanything

/// <summary>
/// A list of Action pointer.
/// </summary>
#define SA_LISTS_CLASS_NAME ActionPtrList
#define SA_LISTS_BASE_TYPE Action *
#include "shellanything/ListsBody.inc"
#undef SA_LISTS_BASE_TYPE
#undef SA_LISTS_CLASS_NAME
22 changes: 11 additions & 11 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@

using namespace tinyxml2;

/// <summary>
/// A list of Configuration pointer.
/// </summary>
#define SA_LISTS_CLASS_NAME ConfigurationPtrList
#define SA_LISTS_BASE_TYPE Configuration *
#include "shellanything/ListsBody.inc"
#undef SA_LISTS_BASE_TYPE
#undef SA_LISTS_CLASS_NAME

namespace shellanything
{
std::string GetXmlEncoding(XMLDocument & doc, std::string & error)
Expand Down Expand Up @@ -301,7 +292,7 @@ namespace shellanything
//configuration have default properties assigned
LOG(INFO) << __FUNCTION__ << "(), initializing default properties of configuration file '" << mFilePath.c_str() << "'...";

const shellanything::Action::ActionPtrList & actions = mDefaults->GetActions();
const shellanything::ActionPtrList & actions = mDefaults->GetActions();

//convert 'actions' to a list of <const shellanything::ActionProperty *>
typedef std::vector<const ActionProperty *> ActionPropertyPtrList;
Expand Down Expand Up @@ -384,4 +375,13 @@ namespace shellanything
mMenus.AddElement(menu);
}

} //namespace shellanything
} //namespace shellanything

/// <summary>
/// A list of Configuration pointer.
/// </summary>
#define SA_LISTS_CLASS_NAME ConfigurationPtrList
#define SA_LISTS_BASE_TYPE Configuration *
#include "shellanything/ListsBody.inc"
#undef SA_LISTS_BASE_TYPE
#undef SA_LISTS_CLASS_NAME
4 changes: 2 additions & 2 deletions src/DefaultSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ namespace shellanything

void DefaultSettings::AddAction(Action * action)
{
mActions.push_back(action);
mActions.AddElement(action);
}

const Action::ActionPtrList & DefaultSettings::GetActions() const
const ActionPtrList & DefaultSettings::GetActions() const
{
return mActions;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@ namespace shellanything

void Menu::AddAction(Action * action)
{
mActions.push_back(action);
mActions.AddElement(action);
}

const Action::ActionPtrList & Menu::GetActions() const
const ActionPtrList & Menu::GetActions() const
{
return mActions;
}
Expand Down
2 changes: 1 addition & 1 deletion src/shellext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ HRESULT STDMETHODCALLTYPE CContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO lpcm
LOG(INFO) << __FUNCTION__ << "(), executing action(s) for menu '" << title.c_str() << "'...";

//execute actions
const shellanything::Action::ActionPtrList & actions = menu->GetActions();
const shellanything::ActionPtrList & actions = menu->GetActions();
for(size_t i=0; i<actions.size(); i++)
{
LOG(INFO) << __FUNCTION__ << "(), executing action " << (i+1) << " of " << actions.size() << ".";
Expand Down
12 changes: 6 additions & 6 deletions test/TestObjectFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace shellanything { namespace test
if (!m)
return NULL;

Action::ActionPtrList actions = m->GetActions();
ActionPtrList actions = m->GetActions();
for(size_t i=0; i<actions.size(); i++)
{
Action * action = actions[i];
Expand All @@ -65,7 +65,7 @@ namespace shellanything { namespace test
if (!m)
return NULL;

Action::ActionPtrList actions = m->GetActions();
ActionPtrList actions = m->GetActions();
for(size_t i=0; i<actions.size(); i++)
{
Action * action = actions[i];
Expand All @@ -82,7 +82,7 @@ namespace shellanything { namespace test
if (!m)
return NULL;

Action::ActionPtrList actions = m->GetActions();
ActionPtrList actions = m->GetActions();
for(size_t i=0; i<actions.size(); i++)
{
Action * action = actions[i];
Expand All @@ -99,7 +99,7 @@ namespace shellanything { namespace test
if (!m)
return NULL;

Action::ActionPtrList actions = m->GetActions();
ActionPtrList actions = m->GetActions();
for(size_t i=0; i<actions.size(); i++)
{
Action * action = actions[i];
Expand All @@ -116,7 +116,7 @@ namespace shellanything { namespace test
if (!m)
return NULL;

Action::ActionPtrList actions = m->GetActions();
ActionPtrList actions = m->GetActions();
for(size_t i=0; i<actions.size(); i++)
{
Action * action = actions[i];
Expand All @@ -133,7 +133,7 @@ namespace shellanything { namespace test
if (!m)
return NULL;

Action::ActionPtrList actions = m->GetActions();
ActionPtrList actions = m->GetActions();
for(size_t i=0; i<actions.size(); i++)
{
Action * action = actions[i];
Expand Down

0 comments on commit 7904429

Please sign in to comment.