KiCad PCB EDA Suite
TOOL_ACTION Class Reference

Class TOOL_ACTION. More...

#include <tool_action.h>

Public Member Functions

 TOOL_ACTION (const std::string &aName, TOOL_ACTION_SCOPE aScope=AS_CONTEXT, int aDefaultHotKey=0, const wxString aMenuItem=wxEmptyString, const wxString &aMenuDesc=wxEmptyString, const BITMAP_OPAQUE *aIcon=NULL, TOOL_ACTION_FLAGS aFlags=AF_NONE, void *aParam=NULL)
 
 ~TOOL_ACTION ()
 
bool operator== (const TOOL_ACTION &aRhs) const
 
bool operator!= (const TOOL_ACTION &aRhs) const
 
const std::string & GetName () const
 Function GetName() Returns name of the action. More...
 
int GetId () const
 Function GetId() Returns the unique id of the TOOL_ACTION object. More...
 
TOOL_EVENT MakeEvent () const
 Function HasHotKey() Checks if the action has a hot key assigned. More...
 
const wxString & GetMenuItem () const
 
void SetMenuItem (const wxString &aItem)
 
const wxString & GetDescription () const
 
void SetDescription (const wxString &aDescription)
 
TOOL_ACTION_SCOPE GetScope () const
 
std::string GetToolName () const
 Returns name of the tool associated with the action. More...
 
bool IsActivation () const
 Returns true if the action is intended to activate a tool. More...
 
bool IsNotification () const
 Returns true if the action is a notification. More...
 
const BITMAP_OPAQUEGetIcon () const
 Returns an icon associated with the action. More...
 

Static Public Member Functions

static int LegacyHotKey (int aHotKey)
 Creates a hot key code that refers to a legacy hot key setting, instead of a particular key. More...
 

Private Member Functions

int getDefaultHotKey ()
 Returns the hot key assigned in the object definition. More...
 

Private Attributes

std::string m_name
 Name of the action (convention is: app.[tool.]action.name) More...
 
TOOL_ACTION_SCOPE m_scope
 Scope of the action. More...
 
const int m_defaultHotKey
 Default hot key that activates the action. More...
 
wxString m_menuItem
 Menu entry text. More...
 
wxString m_menuDescription
 Pop-up help. More...
 
const BITMAP_OPAQUEm_icon
 
int m_id
 Unique ID for fast matching. Assigned by ACTION_MANAGER. More...
 
TOOL_ACTION_FLAGS m_flags
 Action flags. More...
 
void * m_param
 Generic parameter. More...
 

Static Private Attributes

static const int LEGACY_HK = 0x800000
 Flag to determine the hot key settings is not a particular key, but a reference to legacy hot key setting. More...
 

Friends

class ACTION_MANAGER
 

Detailed Description

Class TOOL_ACTION.

Represents a single user action. For instance:

  • changing layer to top by pressing PgUp
  • running the DRC from the menu and so on, and so forth.... Action class groups all necessary properties of an action, including explanation, icons, hotkeys, menu items, etc.

Definition at line 46 of file tool_action.h.

Constructor & Destructor Documentation

TOOL_ACTION::TOOL_ACTION ( const std::string &  aName,
TOOL_ACTION_SCOPE  aScope = AS_CONTEXT,
int  aDefaultHotKey = 0,
const wxString  aMenuItem = wxEmptyString,
const wxString &  aMenuDesc = wxEmptyString,
const BITMAP_OPAQUE aIcon = NULL,
TOOL_ACTION_FLAGS  aFlags = AF_NONE,
void *  aParam = NULL 
)

Definition at line 28 of file tool_action.cpp.

References ACTION_MANAGER::GetActionList().

30  :
31  m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ),
32  m_menuItem( aMenuItem ), m_menuDescription( aMenuDesc ),
33  m_icon( aIcon ), m_id( -1 ), m_flags( aFlags ), m_param( aParam )
34 {
35  ACTION_MANAGER::GetActionList().push_back( this );
36 }
const BITMAP_OPAQUE * m_icon
Definition: tool_action.h:207
static std::list< TOOL_ACTION * > & GetActionList()
Function GetActionList() Returns list of TOOL_ACTIONs.
std::string m_name
Name of the action (convention is: app.[tool.]action.name)
Definition: tool_action.h:192
TOOL_ACTION_SCOPE m_scope
Scope of the action.
Definition: tool_action.h:195
TOOL_ACTION_FLAGS m_flags
Action flags.
Definition: tool_action.h:213
void * m_param
Generic parameter.
Definition: tool_action.h:216
int m_id
Unique ID for fast matching. Assigned by ACTION_MANAGER.
Definition: tool_action.h:210
wxString m_menuDescription
Pop-up help.
Definition: tool_action.h:204
wxString m_menuItem
Menu entry text.
Definition: tool_action.h:201
const int m_defaultHotKey
Default hot key that activates the action.
Definition: tool_action.h:198
TOOL_ACTION::~TOOL_ACTION ( )

Definition at line 39 of file tool_action.cpp.

References ACTION_MANAGER::GetActionList().

40 {
41  ACTION_MANAGER::GetActionList().remove( this );
42 }
static std::list< TOOL_ACTION * > & GetActionList()
Function GetActionList() Returns list of TOOL_ACTIONs.

Member Function Documentation

int TOOL_ACTION::getDefaultHotKey ( )
inlineprivate

Returns the hot key assigned in the object definition.

It may refer to a legacy hot key setting (if LEGACY_HK flag is set).

Definition at line 186 of file tool_action.h.

References m_defaultHotKey.

Referenced by ACTION_MANAGER::processHotKey().

187  {
188  return m_defaultHotKey;
189  }
const int m_defaultHotKey
Default hot key that activates the action.
Definition: tool_action.h:198
const wxString& TOOL_ACTION::GetDescription ( ) const
inline

Definition at line 124 of file tool_action.h.

References m_menuDescription.

Referenced by CONTEXT_MENU::Add().

125  {
126  return m_menuDescription;
127  }
wxString m_menuDescription
Pop-up help.
Definition: tool_action.h:204
const BITMAP_OPAQUE* TOOL_ACTION::GetIcon ( ) const
inline

Returns an icon associated with the action.

It is used in context menu.

Definition at line 165 of file tool_action.h.

References m_icon.

Referenced by CONTEXT_MENU::Add().

166  {
167  return m_icon;
168  }
const BITMAP_OPAQUE * m_icon
Definition: tool_action.h:207
int TOOL_ACTION::GetId ( ) const
inline

Function GetId() Returns the unique id of the TOOL_ACTION object.

It is valid only after registering the TOOL_ACTION by ACTION_MANAGER.

Returns
The unique identification number. If the number is negative, then it is not valid.

Definition at line 85 of file tool_action.h.

References m_id.

Referenced by CONDITIONAL_MENU::AddItem(), ACTION_MANAGER::GetHotKey(), CONTEXT_MENU::getMenuId(), and ACTION_MANAGER::UpdateHotKeys().

86  {
87  return m_id;
88  }
int m_id
Unique ID for fast matching. Assigned by ACTION_MANAGER.
Definition: tool_action.h:210
const wxString& TOOL_ACTION::GetMenuItem ( ) const
inline

Definition at line 114 of file tool_action.h.

References m_menuItem.

Referenced by CONTEXT_MENU::Add().

115  {
116  return m_menuItem;
117  }
wxString m_menuItem
Menu entry text.
Definition: tool_action.h:201
const std::string& TOOL_ACTION::GetName ( void  ) const
inline

Function GetName() Returns name of the action.

It is the same one that is contained in TOOL_EVENT that is sent by activating the TOOL_ACTION.

Returns
Name of the action.

Definition at line 73 of file tool_action.h.

References m_name.

Referenced by ACTION_MANAGER::RegisterAction().

74  {
75  return m_name;
76  }
std::string m_name
Name of the action (convention is: app.[tool.]action.name)
Definition: tool_action.h:192
TOOL_ACTION_SCOPE TOOL_ACTION::GetScope ( ) const
inline

Definition at line 134 of file tool_action.h.

References m_scope.

Referenced by ACTION_MANAGER::UpdateHotKeys().

135  {
136  return m_scope;
137  }
TOOL_ACTION_SCOPE m_scope
Scope of the action.
Definition: tool_action.h:195
std::string TOOL_ACTION::GetToolName ( ) const

Returns name of the tool associated with the action.

It is basically the action name stripped of the last part (e.g. for "pcbnew.InteractiveDrawing.drawCircle" it is "pcbnew.InteractiveDrawing").

Definition at line 45 of file tool_action.cpp.

References m_name.

46 {
47  int dotCount = std::count( m_name.begin(), m_name.end(), '.' );
48 
49  switch( dotCount )
50  {
51  case 0:
52  assert( false ); // Invalid action name format
53  return "";
54 
55  case 1:
56  return m_name;
57 
58  case 2:
59  return m_name.substr( 0, m_name.rfind( '.' ) );
60 
61  default:
62  assert( false ); // TODO not implemented
63  return "";
64  }
65 }
std::string m_name
Name of the action (convention is: app.[tool.]action.name)
Definition: tool_action.h:192
bool TOOL_ACTION::IsActivation ( ) const
inline

Returns true if the action is intended to activate a tool.

Definition at line 149 of file tool_action.h.

References AF_ACTIVATE, and m_flags.

Referenced by MakeEvent().

150  {
151  return m_flags & AF_ACTIVATE;
152  }
TOOL_ACTION_FLAGS m_flags
Action flags.
Definition: tool_action.h:213
bool TOOL_ACTION::IsNotification ( ) const
inline

Returns true if the action is a notification.

Definition at line 157 of file tool_action.h.

References AF_NOTIFY, and m_flags.

Referenced by MakeEvent().

158  {
159  return m_flags & AF_NOTIFY;
160  }
Action activates a tool
Definition: tool_event.h:146
TOOL_ACTION_FLAGS m_flags
Action flags.
Definition: tool_action.h:213
static int TOOL_ACTION::LegacyHotKey ( int  aHotKey)
inlinestatic

Creates a hot key code that refers to a legacy hot key setting, instead of a particular key.

Parameters
aHotKeyis an ID of hot key to be referred (see hotkeys.h).

Definition at line 174 of file tool_action.h.

References LEGACY_HK.

175  {
176  assert( ( aHotKey & LEGACY_HK ) == 0 );
177 
178  return aHotKey | LEGACY_HK;
179  }
static const int LEGACY_HK
Flag to determine the hot key settings is not a particular key, but a reference to legacy hot key set...
Definition: tool_action.h:220
TOOL_EVENT TOOL_ACTION::MakeEvent ( ) const
inline

Function HasHotKey() Checks if the action has a hot key assigned.

Returns
True if there is a hot key assigned, false otherwise. Function MakeEvent() Returns the event associated with the action (i.e. the event that will be sent after activating the action).
The event associated with the action.

Definition at line 104 of file tool_action.h.

References IsActivation(), IsNotification(), m_name, m_param, m_scope, TA_ACTION, TA_ACTIVATE, TA_NONE, TC_COMMAND, and TC_MESSAGE.

Referenced by EDIT_TOOL::Duplicate(), TOOL_EVENT::IsAction(), TOOL_MANAGER::RunAction(), LENGTH_TUNER_TOOL::setTransitions(), ROUTER_TOOL::setTransitions(), COMMON_TOOLS::setTransitions(), DIALOG_SET_GRID::TransferDataFromWindow(), GERBVIEW_ACTIONS::TranslateLegacyId(), and PCB_ACTIONS::TranslateLegacyId().

105  {
106  if( IsActivation() )
108  else if( IsNotification() )
110  else
112  }
std::string m_name
Name of the action (convention is: app.[tool.]action.name)
Definition: tool_action.h:192
TOOL_ACTION_SCOPE m_scope
Scope of the action.
Definition: tool_action.h:195
Class TOOL_EVENT.
Definition: tool_event.h:162
bool IsNotification() const
Returns true if the action is a notification.
Definition: tool_action.h:157
bool IsActivation() const
Returns true if the action is intended to activate a tool.
Definition: tool_action.h:149
void * m_param
Generic parameter.
Definition: tool_action.h:216
bool TOOL_ACTION::operator!= ( const TOOL_ACTION aRhs) const
inline

Definition at line 61 of file tool_action.h.

References m_id.

62  {
63  return m_id != aRhs.m_id;
64  }
int m_id
Unique ID for fast matching. Assigned by ACTION_MANAGER.
Definition: tool_action.h:210
bool TOOL_ACTION::operator== ( const TOOL_ACTION aRhs) const
inline

Definition at line 56 of file tool_action.h.

References m_id.

57  {
58  return m_id == aRhs.m_id;
59  }
int m_id
Unique ID for fast matching. Assigned by ACTION_MANAGER.
Definition: tool_action.h:210
void TOOL_ACTION::SetDescription ( const wxString &  aDescription)
inline

Definition at line 129 of file tool_action.h.

References m_menuDescription.

130  {
131  m_menuDescription = aDescription;
132  }
wxString m_menuDescription
Pop-up help.
Definition: tool_action.h:204
void TOOL_ACTION::SetMenuItem ( const wxString &  aItem)
inline

Definition at line 119 of file tool_action.h.

References m_menuItem.

120  {
121  m_menuItem = aItem;
122  }
wxString m_menuItem
Menu entry text.
Definition: tool_action.h:201

Friends And Related Function Documentation

friend class ACTION_MANAGER
friend

Definition at line 182 of file tool_action.h.

Member Data Documentation

const int TOOL_ACTION::LEGACY_HK = 0x800000
staticprivate

Flag to determine the hot key settings is not a particular key, but a reference to legacy hot key setting.

Definition at line 220 of file tool_action.h.

Referenced by LegacyHotKey(), and ACTION_MANAGER::processHotKey().

const int TOOL_ACTION::m_defaultHotKey
private

Default hot key that activates the action.

Definition at line 198 of file tool_action.h.

Referenced by getDefaultHotKey().

TOOL_ACTION_FLAGS TOOL_ACTION::m_flags
private

Action flags.

Definition at line 213 of file tool_action.h.

Referenced by IsActivation(), and IsNotification().

const BITMAP_OPAQUE* TOOL_ACTION::m_icon
private

Definition at line 207 of file tool_action.h.

Referenced by GetIcon().

int TOOL_ACTION::m_id
private

Unique ID for fast matching. Assigned by ACTION_MANAGER.

Definition at line 210 of file tool_action.h.

Referenced by GetId(), operator!=(), and operator==().

wxString TOOL_ACTION::m_menuDescription
private

Pop-up help.

Definition at line 204 of file tool_action.h.

Referenced by GetDescription(), and SetDescription().

wxString TOOL_ACTION::m_menuItem
private

Menu entry text.

Definition at line 201 of file tool_action.h.

Referenced by GetMenuItem(), and SetMenuItem().

std::string TOOL_ACTION::m_name
private

Name of the action (convention is: app.[tool.]action.name)

Definition at line 192 of file tool_action.h.

Referenced by GetName(), GetToolName(), MakeEvent(), ACTION_MANAGER::RegisterAction(), and ACTION_MANAGER::UnregisterAction().

void* TOOL_ACTION::m_param
private

Generic parameter.

Definition at line 216 of file tool_action.h.

Referenced by MakeEvent().

TOOL_ACTION_SCOPE TOOL_ACTION::m_scope
private

Scope of the action.

Definition at line 195 of file tool_action.h.

Referenced by GetScope(), and MakeEvent().


The documentation for this class was generated from the following files: