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 MakeEvent() Returns the event associated with the action (i.e. 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_OPAQUE * GetIcon () 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_OPAQUE * m_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::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 30 of file tool_action.cpp.

32  :
33  m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ),
34  m_menuItem( aMenuItem ), m_menuDescription( aMenuDesc ),
35  m_icon( aIcon ), m_id( -1 ), m_flags( aFlags ), m_param( aParam )
36 {
37  ACTION_MANAGER::GetActionList().push_back( this );
38 }
const BITMAP_OPAQUE * m_icon
Definition: tool_action.h:198
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:183
TOOL_ACTION_SCOPE m_scope
Scope of the action.
Definition: tool_action.h:186
TOOL_ACTION_FLAGS m_flags
Action flags.
Definition: tool_action.h:204
void * m_param
Generic parameter.
Definition: tool_action.h:207
int m_id
Unique ID for fast matching. Assigned by ACTION_MANAGER.
Definition: tool_action.h:201
wxString m_menuDescription
Pop-up help.
Definition: tool_action.h:195
wxString m_menuItem
Menu entry text.
Definition: tool_action.h:192
const int m_defaultHotKey
Default hot key that activates the action.
Definition: tool_action.h:189

References ACTION_MANAGER::GetActionList().

◆ ~TOOL_ACTION()

TOOL_ACTION::~TOOL_ACTION ( )

Definition at line 41 of file tool_action.cpp.

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

References ACTION_MANAGER::GetActionList().

Member Function Documentation

◆ getDefaultHotKey()

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 177 of file tool_action.h.

178  {
179  return m_defaultHotKey;
180  }
const int m_defaultHotKey
Default hot key that activates the action.
Definition: tool_action.h:189

References m_defaultHotKey.

Referenced by ACTION_MANAGER::processHotKey().

◆ GetDescription()

const wxString& TOOL_ACTION::GetDescription ( ) const
inline

Definition at line 115 of file tool_action.h.

116  {
117  return m_menuDescription;
118  }
wxString m_menuDescription
Pop-up help.
Definition: tool_action.h:195

References m_menuDescription.

Referenced by ACTION_TOOLBAR::Add(), and ACTION_MENU::Add().

◆ GetIcon()

const BITMAP_OPAQUE* TOOL_ACTION::GetIcon ( ) const
inline

Returns an icon associated with the action.

It is used in context menu.

Definition at line 156 of file tool_action.h.

157  {
158  return m_icon;
159  }
const BITMAP_OPAQUE * m_icon
Definition: tool_action.h:198

References m_icon.

Referenced by ACTION_TOOLBAR::Add(), and ACTION_MENU::Add().

◆ GetId()

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.

86  {
87  return m_id;
88  }
int m_id
Unique ID for fast matching. Assigned by ACTION_MANAGER.
Definition: tool_action.h:201

References m_id.

Referenced by ACTION_TOOLBAR::Add(), CONDITIONAL_MENU::AddCheckItem(), CONDITIONAL_MENU::AddItem(), ACTION_MANAGER::GetHotKey(), ACTION_MENU::getMenuId(), ACTION_TOOLBAR::Toggle(), and ACTION_MANAGER::UpdateHotKeys().

◆ GetMenuItem()

const wxString& TOOL_ACTION::GetMenuItem ( ) const
inline

Definition at line 105 of file tool_action.h.

106  {
107  return m_menuItem;
108  }
wxString m_menuItem
Menu entry text.
Definition: tool_action.h:192

References m_menuItem.

Referenced by ACTION_MENU::Add().

◆ GetName()

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.

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

References m_name.

Referenced by ACTION_MANAGER::RegisterAction().

◆ GetScope()

TOOL_ACTION_SCOPE TOOL_ACTION::GetScope ( ) const
inline

Definition at line 125 of file tool_action.h.

126  {
127  return m_scope;
128  }
TOOL_ACTION_SCOPE m_scope
Scope of the action.
Definition: tool_action.h:186

References m_scope.

Referenced by ACTION_MANAGER::UpdateHotKeys().

◆ GetToolName()

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 47 of file tool_action.cpp.

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

References m_name.

◆ IsActivation()

bool TOOL_ACTION::IsActivation ( ) const
inline

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

Definition at line 140 of file tool_action.h.

141  {
142  return m_flags & AF_ACTIVATE;
143  }
TOOL_ACTION_FLAGS m_flags
Action flags.
Definition: tool_action.h:204

References AF_ACTIVATE, and m_flags.

Referenced by MakeEvent().

◆ IsNotification()

bool TOOL_ACTION::IsNotification ( ) const
inline

Returns true if the action is a notification.

Definition at line 148 of file tool_action.h.

149  {
150  return m_flags & AF_NOTIFY;
151  }
Action activates a tool
Definition: tool_event.h:151
TOOL_ACTION_FLAGS m_flags
Action flags.
Definition: tool_action.h:204

References AF_NOTIFY, and m_flags.

Referenced by MakeEvent().

◆ LegacyHotKey()

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 165 of file tool_action.h.

166  {
167  assert( ( aHotKey & LEGACY_HK ) == 0 );
168 
169  return aHotKey | LEGACY_HK;
170  }
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:211

References LEGACY_HK.

◆ MakeEvent()

TOOL_EVENT TOOL_ACTION::MakeEvent ( ) const
inline

Function MakeEvent() Returns the event associated with the action (i.e.

the event that will be sent after activating the action).

Definition at line 95 of file tool_action.h.

96  {
97  if( IsActivation() )
99  else if( IsNotification() )
101  else
103  }
bool IsActivation() const
Returns true if the action is intended to activate a tool.
Definition: tool_action.h:140
std::string m_name
Name of the action (convention is: app.[tool.]action.name)
Definition: tool_action.h:183
TOOL_ACTION_SCOPE m_scope
Scope of the action.
Definition: tool_action.h:186
Class TOOL_EVENT.
Definition: tool_event.h:167
bool IsNotification() const
Returns true if the action is a notification.
Definition: tool_action.h:148
void * m_param
Generic parameter.
Definition: tool_action.h:207

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(), ROUTER_TOOL::setTransitions(), DIALOG_SET_GRID::TransferDataFromWindow(), CVPCB_ACTIONS::TranslateLegacyId(), GERBVIEW_ACTIONS::TranslateLegacyId(), EE_ACTIONS::TranslateLegacyId(), and PCB_ACTIONS::TranslateLegacyId().

◆ operator!=()

bool TOOL_ACTION::operator!= ( const TOOL_ACTION aRhs) const
inline

Definition at line 61 of file tool_action.h.

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:201

References m_id.

◆ operator==()

bool TOOL_ACTION::operator== ( const TOOL_ACTION aRhs) const
inline

Definition at line 56 of file tool_action.h.

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:201

References m_id.

◆ SetDescription()

void TOOL_ACTION::SetDescription ( const wxString &  aDescription)
inline

Definition at line 120 of file tool_action.h.

121  {
122  m_menuDescription = aDescription;
123  }
wxString m_menuDescription
Pop-up help.
Definition: tool_action.h:195

References m_menuDescription.

◆ SetMenuItem()

void TOOL_ACTION::SetMenuItem ( const wxString &  aItem)
inline

Definition at line 110 of file tool_action.h.

111  {
112  m_menuItem = aItem;
113  }
wxString m_menuItem
Menu entry text.
Definition: tool_action.h:192

References m_menuItem.

Friends And Related Function Documentation

◆ ACTION_MANAGER

friend class ACTION_MANAGER
friend

Definition at line 173 of file tool_action.h.

Member Data Documentation

◆ LEGACY_HK

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 211 of file tool_action.h.

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

◆ m_defaultHotKey

const int TOOL_ACTION::m_defaultHotKey
private

Default hot key that activates the action.

Definition at line 189 of file tool_action.h.

Referenced by getDefaultHotKey().

◆ m_flags

TOOL_ACTION_FLAGS TOOL_ACTION::m_flags
private

Action flags.

Definition at line 204 of file tool_action.h.

Referenced by IsActivation(), and IsNotification().

◆ m_icon

const BITMAP_OPAQUE* TOOL_ACTION::m_icon
private

Definition at line 198 of file tool_action.h.

Referenced by GetIcon().

◆ m_id

int TOOL_ACTION::m_id
private

Unique ID for fast matching. Assigned by ACTION_MANAGER.

Definition at line 201 of file tool_action.h.

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

◆ m_menuDescription

wxString TOOL_ACTION::m_menuDescription
private

Pop-up help.

Definition at line 195 of file tool_action.h.

Referenced by GetDescription(), and SetDescription().

◆ m_menuItem

wxString TOOL_ACTION::m_menuItem
private

Menu entry text.

Definition at line 192 of file tool_action.h.

Referenced by GetMenuItem(), and SetMenuItem().

◆ m_name

std::string TOOL_ACTION::m_name
private

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

Definition at line 183 of file tool_action.h.

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

◆ m_param

void* TOOL_ACTION::m_param
private

Generic parameter.

Definition at line 207 of file tool_action.h.

Referenced by MakeEvent().

◆ m_scope

TOOL_ACTION_SCOPE TOOL_ACTION::m_scope
private

Scope of the action.

Definition at line 186 of file tool_action.h.

Referenced by GetScope(), and MakeEvent().


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