Commit 99e52289 authored by Maciej Suminski's avatar Maciej Suminski

Moved the list of TOOL_ACTIONs to ACTION_MANAGER.

parent 1cd3cfa2
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
ACTION_MANAGER::ACTION_MANAGER( TOOL_MANAGER* aToolManager ) : ACTION_MANAGER::ACTION_MANAGER( TOOL_MANAGER* aToolManager ) :
m_toolMgr( aToolManager ) m_toolMgr( aToolManager )
{ {
// Register known actions
std::list<TOOL_ACTION*>& actionList = GetActionList();
BOOST_FOREACH( TOOL_ACTION* action, actionList )
RegisterAction( action );
} }
......
...@@ -23,6 +23,24 @@ ...@@ -23,6 +23,24 @@
*/ */
#include <tool/tool_action.h> #include <tool/tool_action.h>
#include <tool/action_manager.h>
TOOL_ACTION::TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope,
int aDefaultHotKey, const wxString aMenuItem, const wxString& aMenuDesc,
const BITMAP_OPAQUE* aIcon, TOOL_ACTION_FLAGS aFlags, void* aParam ) :
m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ),
m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ), m_menuDescription( aMenuDesc ),
m_icon( aIcon ), m_id( -1 ), m_flags( aFlags ), m_param( aParam )
{
ACTION_MANAGER::GetActionList().push_back( this );
}
TOOL_ACTION::~TOOL_ACTION()
{
ACTION_MANAGER::GetActionList().remove( this );
}
std::string TOOL_ACTION::GetToolName() const std::string TOOL_ACTION::GetToolName() const
{ {
......
...@@ -202,11 +202,6 @@ TOOL_MANAGER::TOOL_MANAGER() : ...@@ -202,11 +202,6 @@ TOOL_MANAGER::TOOL_MANAGER() :
m_passEvent( false ) m_passEvent( false )
{ {
m_actionMgr = new ACTION_MANAGER( this ); m_actionMgr = new ACTION_MANAGER( this );
// Register known actions
std::list<TOOL_ACTION*>& actionList = GetActionList();
BOOST_FOREACH( TOOL_ACTION* action, actionList )
RegisterAction( action );
} }
......
...@@ -90,6 +90,19 @@ public: ...@@ -90,6 +90,19 @@ public:
*/ */
bool RunHotKey( int aHotKey ) const; bool RunHotKey( int aHotKey ) const;
/**
* Returns list of TOOL_ACTIONs. TOOL_ACTIONs add themselves to the list upon their
* creation.
* @return List of TOOL_ACTIONs.
*/
static std::list<TOOL_ACTION*>& GetActionList()
{
// TODO I am afraid this approach won't work when we reach multitab version of kicad.
static std::list<TOOL_ACTION*> actionList;
return actionList;
}
private: private:
///> Tool manager needed to run actions ///> Tool manager needed to run actions
TOOL_MANAGER* m_toolMgr; TOOL_MANAGER* m_toolMgr;
......
...@@ -26,11 +26,13 @@ ...@@ -26,11 +26,13 @@
#ifndef __CONTEXT_MENU_H #ifndef __CONTEXT_MENU_H
#define __CONTEXT_MENU_H #define __CONTEXT_MENU_H
#include <wx/menu.h>
#include <tool/tool_action.h>
#include <map> #include <map>
#include <list>
#include <boost/function.hpp> #include <boost/function.hpp>
#include <wx/menu.h>
#include <tool/tool_action.h>
class TOOL_INTERACTIVE; class TOOL_INTERACTIVE;
/** /**
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include <string> #include <string>
#include <cassert> #include <cassert>
#include <tool/tool_manager.h> #include <tool/tool_event.h>
struct BITMAP_OPAQUE; struct BITMAP_OPAQUE;
...@@ -49,18 +49,9 @@ public: ...@@ -49,18 +49,9 @@ public:
TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT, TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT,
int aDefaultHotKey = 0, const wxString aMenuItem = wxEmptyString, int aDefaultHotKey = 0, const wxString aMenuItem = wxEmptyString,
const wxString& aMenuDesc = wxEmptyString, const BITMAP_OPAQUE* aIcon = NULL, const wxString& aMenuDesc = wxEmptyString, const BITMAP_OPAQUE* aIcon = NULL,
TOOL_ACTION_FLAGS aFlags = AF_NONE, void* aParam = NULL ) : TOOL_ACTION_FLAGS aFlags = AF_NONE, void* aParam = NULL );
m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ),
m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ), m_menuDescription( aMenuDesc ),
m_icon( aIcon ), m_id( -1 ), m_flags( aFlags ), m_param( aParam )
{
TOOL_MANAGER::GetActionList().push_back( this );
}
~TOOL_ACTION() ~TOOL_ACTION();
{
TOOL_MANAGER::GetActionList().remove( this );
}
bool operator==( const TOOL_ACTION& aRhs ) const bool operator==( const TOOL_ACTION& aRhs ) const
{ {
......
...@@ -308,19 +308,6 @@ public: ...@@ -308,19 +308,6 @@ public:
*/ */
std::string GetClipboard() const; std::string GetClipboard() const;
/**
* Returns list of TOOL_ACTIONs. TOOL_ACTIONs add themselves to the list upon their
* creation.
* @return List of TOOL_ACTIONs.
*/
static std::list<TOOL_ACTION*>& GetActionList()
{
// TODO I am afraid this approach won't work when we reach multitab version of kicad.
static std::list<TOOL_ACTION*> actionList;
return actionList;
}
private: private:
struct TOOL_STATE; struct TOOL_STATE;
typedef std::pair<TOOL_EVENT_LIST, TOOL_STATE_FUNC> TRANSITION; typedef std::pair<TOOL_EVENT_LIST, TOOL_STATE_FUNC> TRANSITION;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <pcbnew.h> #include <pcbnew.h>
#include <tools/common_actions.h> #include <tools/common_actions.h>
#include <tool/tool_manager.h>
#include <pcb_draw_panel_gal.h> #include <pcb_draw_panel_gal.h>
/* Execute a remote command send by Eeschema via a socket, /* Execute a remote command send by Eeschema via a socket,
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <dialogs/dialog_pns_length_tuning_settings.h> #include <dialogs/dialog_pns_length_tuning_settings.h>
#include <tool/context_menu.h> #include <tool/context_menu.h>
#include <tool/tool_manager.h>
#include <tools/common_actions.h> #include <tools/common_actions.h>
#include "pns_segment.h" #include "pns_segment.h"
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <base_units.h> #include <base_units.h>
#include <tool/context_menu.h> #include <tool/context_menu.h>
#include <tool/tool_manager.h>
#include <tools/common_actions.h> #include <tools/common_actions.h>
#include <ratsnest_data.h> #include <ratsnest_data.h>
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <tool/action_manager.h> #include <tool/action_manager.h>
#include <pcbnew_id.h> #include <pcbnew_id.h>
#include <layers_id_colors_and_visibility.h> #include <layers_id_colors_and_visibility.h>
#include <bitmaps.h>
#include <wx/defs.h> #include <wx/defs.h>
// These members are static in class COMMON_ACTIONS: Build them here: // These members are static in class COMMON_ACTIONS: Build them here:
......
...@@ -294,6 +294,6 @@ public: ...@@ -294,6 +294,6 @@ public:
static boost::optional<TOOL_EVENT> TranslateLegacyId( int aId ); static boost::optional<TOOL_EVENT> TranslateLegacyId( int aId );
}; };
void registerAllTools ( TOOL_MANAGER *aToolManager ); void registerAllTools( TOOL_MANAGER* aToolManager );
#endif #endif
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "module_tools.h" #include "module_tools.h"
#include "selection_tool.h" #include "selection_tool.h"
#include "common_actions.h" #include "common_actions.h"
#include <tool/tool_manager.h>
#include <class_draw_panel_gal.h> #include <class_draw_panel_gal.h>
#include <view/view_controls.h> #include <view/view_controls.h>
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "pcb_editor_control.h" #include "pcb_editor_control.h"
#include "common_actions.h" #include "common_actions.h"
#include <tool/tool_manager.h>
#include "selection_tool.h" #include "selection_tool.h"
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "placement_tool.h" #include "placement_tool.h"
#include "common_actions.h" #include "common_actions.h"
#include "selection_tool.h" #include "selection_tool.h"
#include <tool/tool_manager.h>
#include <wxPcbStruct.h> #include <wxPcbStruct.h>
#include <class_board.h> #include <class_board.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment