KiCad PCB EDA Suite
TOOL_ACTION Class Reference

TOOL_ACTION. More...

#include <tool_action.h>

Inheritance diagram for TOOL_ACTION:
GESTURE_PSEUDO_ACTION

Public Member Functions

 TOOL_ACTION (const std::string &aName, TOOL_ACTION_SCOPE aScope=AS_CONTEXT, int aDefaultHotKey=0, const std::string &aLegacyHotKeyName="", const wxString &aMenuText=wxEmptyString, const wxString &aTooltip=wxEmptyString, const BITMAP_OPAQUE *aIcon=nullptr, TOOL_ACTION_FLAGS aFlags=AF_NONE, void *aParam=nullptr)
 
 ~TOOL_ACTION ()
 
 TOOL_ACTION (const TOOL_ACTION &)=delete
 
TOOL_ACTIONoperator= (const TOOL_ACTION &)=delete
 
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 GetDefaultHotKey () const
 Function GetDefaultHotKey() Returns the default hotkey (if any) for the action. More...
 
int GetHotKey () const
 Function GetHotKey() Returns the hotkey keycode which initiates the action. More...
 
void SetHotKey (int aKeycode)
 
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...
 
wxString GetLabel () const
 
wxString GetMenuItem () const
 
wxString GetDescription () const
 
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...
 

Protected Member Functions

 TOOL_ACTION ()
 

Protected Attributes

std::string m_name
 Name of the action (convention is "app.tool.actionName") More...
 
TOOL_ACTION_SCOPE m_scope
 
const int m_defaultHotKey
 
int m_hotKey
 
const std::string m_legacyName
 
wxString m_label
 
wxString m_tooltip
 
const BITMAP_OPAQUEm_icon
 
int m_id
 
TOOL_ACTION_FLAGS m_flags
 
void * m_param
 

Friends

class ACTION_MANAGER
 

Detailed Description

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() [1/3]

TOOL_ACTION::TOOL_ACTION ( const std::string &  aName,
TOOL_ACTION_SCOPE  aScope = AS_CONTEXT,
int  aDefaultHotKey = 0,
const std::string &  aLegacyHotKeyName = "",
const wxString &  aMenuText = wxEmptyString,
const wxString &  aTooltip = wxEmptyString,
const BITMAP_OPAQUE aIcon = nullptr,
TOOL_ACTION_FLAGS  aFlags = AF_NONE,
void *  aParam = nullptr 
)

Definition at line 31 of file tool_action.cpp.

34  :
35  m_name( aName ),
36  m_scope( aScope ),
37  m_defaultHotKey( aDefaultHotKey ),
38  m_legacyName( aLegacyHotKeyName ),
39  m_label( aLabel ),
40  m_tooltip( aTooltip ),
41  m_icon( aIcon ),
42  m_id( -1 ),
43  m_flags( aFlags ),
44  m_param( aParam )
45 {
46  SetHotKey( aDefaultHotKey );
47  ACTION_MANAGER::GetActionList().push_back( this );
48 }
wxString m_label
Definition: tool_action.h:167
const BITMAP_OPAQUE * m_icon
Definition: tool_action.h:169
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.actionName")
Definition: tool_action.h:160
const std::string m_legacyName
Definition: tool_action.h:165
TOOL_ACTION_SCOPE m_scope
Definition: tool_action.h:161
void SetHotKey(int aKeycode)
Definition: tool_action.cpp:94
wxString m_tooltip
Definition: tool_action.h:168
TOOL_ACTION_FLAGS m_flags
Definition: tool_action.h:173
void * m_param
Definition: tool_action.h:174
const int m_defaultHotKey
Definition: tool_action.h:163

References ACTION_MANAGER::GetActionList(), and SetHotKey().

◆ ~TOOL_ACTION()

TOOL_ACTION::~TOOL_ACTION ( )

Definition at line 63 of file tool_action.cpp.

64 {
65  ACTION_MANAGER::GetActionList().remove( this );
66 }
static std::list< TOOL_ACTION * > & GetActionList()
Function GetActionList() Returns list of TOOL_ACTIONs.

References ACTION_MANAGER::GetActionList().

◆ TOOL_ACTION() [2/3]

TOOL_ACTION::TOOL_ACTION ( const TOOL_ACTION )
delete

◆ TOOL_ACTION() [3/3]

TOOL_ACTION::TOOL_ACTION ( )
protected

Definition at line 51 of file tool_action.cpp.

51  :
52  m_scope( AS_GLOBAL ),
53  m_defaultHotKey( 0 ),
54  m_icon( nullptr ),
55  m_id( -1 ),
56  m_flags( AF_NONE ),
57  m_param( nullptr )
58 {
59  SetHotKey( 0 );
60 }
const BITMAP_OPAQUE * m_icon
Definition: tool_action.h:169
TOOL_ACTION_SCOPE m_scope
Definition: tool_action.h:161
void SetHotKey(int aKeycode)
Definition: tool_action.cpp:94
All active tools
Definition: tool_event.h:147
TOOL_ACTION_FLAGS m_flags
Definition: tool_action.h:173
void * m_param
Definition: tool_action.h:174
const int m_defaultHotKey
Definition: tool_action.h:163

References SetHotKey().

Member Function Documentation

◆ GetDefaultHotKey()

int TOOL_ACTION::GetDefaultHotKey ( ) const
inline

Function GetDefaultHotKey() Returns the default hotkey (if any) for the action.

Definition at line 84 of file tool_action.h.

84 { return m_defaultHotKey; }
const int m_defaultHotKey
Definition: tool_action.h:163

References m_defaultHotKey.

◆ GetDescription()

wxString TOOL_ACTION::GetDescription ( ) const

Definition at line 83 of file tool_action.cpp.

84 {
85  wxString tooltip = wxGetTranslation( m_tooltip );
86 
87  if( GetHotKey() )
88  tooltip += wxString::Format( wxT( " (%s)" ), KeyNameFromKeyCode( GetHotKey() ) );
89 
90  return tooltip;
91 }
wxString m_tooltip
Definition: tool_action.h:168
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...
int GetHotKey() const
Function GetHotKey() Returns the hotkey keycode which initiates the action.
Definition: tool_action.h:90

References Format(), GetHotKey(), KeyNameFromKeyCode(), and m_tooltip.

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

◆ GetHotKey()

int TOOL_ACTION::GetHotKey ( ) const
inline

Function GetHotKey() Returns the hotkey keycode which initiates the action.

Definition at line 90 of file tool_action.h.

90 { return m_hotKey; }

References m_hotKey.

Referenced by GetDescription(), PCB_LAYER_BOX_SELECTOR::Resync(), DIALOG_GRID_SETTINGS::TransferDataToWindow(), and ACTION_MANAGER::UpdateHotKeys().

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

150  {
151  return m_icon;
152  }
const BITMAP_OPAQUE * m_icon
Definition: tool_action.h:169

References m_icon.

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

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

100 { return m_id; }

References m_id.

Referenced by ACTION_TOOLBAR::Add(), ACTION_TOOLBAR::AddButton(), CONDITIONAL_MENU::AddCheckItem(), CONDITIONAL_MENU::AddItem(), ACTION_TOOLBAR::AddToolContextMenu(), ACTION_MANAGER::GetHotKey(), ACTION_MENU::getMenuId(), TOOL_EVENT::IsCancelInteractive(), TOOL_EVENT::IsPointEditor(), ACTION_TOOLBAR::SetToolBitmap(), ACTION_TOOLBAR::Toggle(), and ACTION_MANAGER::UpdateHotKeys().

◆ GetLabel()

wxString TOOL_ACTION::GetLabel ( ) const

Definition at line 69 of file tool_action.cpp.

70 {
71  return wxGetTranslation( m_label );
72 }
wxString m_label
Definition: tool_action.h:167

References m_label.

Referenced by TOOLS_HOLDER::PushTool(), and WIDGET_HOTKEY_LIST::ResolveKeyConflicts().

◆ GetMenuItem()

wxString TOOL_ACTION::GetMenuItem ( ) const

Definition at line 75 of file tool_action.cpp.

76 {
77  wxString label = wxGetTranslation( m_label );
78  label.Replace( "&", "&&" );
79  return AddHotkeyName( label, m_hotKey, IS_HOTKEY );
80 }
wxString m_label
Definition: tool_action.h:167
wxString AddHotkeyName(const wxString &aText, int aHotKey, HOTKEY_ACTION_TYPE aStyle)
AddHotkeyName.

References AddHotkeyName(), IS_HOTKEY, m_hotKey, and m_label.

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. Convention is "app.tool.actionName".

Returns
Name of the action.

Definition at line 78 of file tool_action.h.

78 { return m_name; }
std::string m_name
Name of the action (convention is "app.tool.actionName")
Definition: tool_action.h:160

References m_name.

Referenced by ACTION_TOOLBAR::AddButton(), HOTKEY_STORE::GetAppName(), TOOL_EVENT::IsCancelInteractive(), TOOLS_HOLDER::IsCurrentTool(), ACTION_MANAGER::RegisterAction(), and ACTION_MANAGER::RunHotKey().

◆ GetScope()

TOOL_ACTION_SCOPE TOOL_ACTION::GetScope ( ) const
inline

Definition at line 121 of file tool_action.h.

121 { return m_scope; }
TOOL_ACTION_SCOPE m_scope
Definition: tool_action.h:161

References m_scope.

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

101 {
102  int dotCount = std::count( m_name.begin(), m_name.end(), '.' );
103 
104  switch( dotCount )
105  {
106  case 0:
107  assert( false ); // Invalid action name format
108  return "";
109 
110  case 1:
111  return m_name;
112 
113  case 2:
114  return m_name.substr( 0, m_name.rfind( '.' ) );
115 
116  default:
117  assert( false ); // TODO not implemented
118  return "";
119  }
120 }
std::string m_name
Name of the action (convention is "app.tool.actionName")
Definition: tool_action.h:160

References m_name.

◆ IsActivation()

bool TOOL_ACTION::IsActivation ( ) const
inline

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

Definition at line 133 of file tool_action.h.

134  {
135  return m_flags & AF_ACTIVATE;
136  }
TOOL_ACTION_FLAGS m_flags
Definition: tool_action.h:173

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

142  {
143  return m_flags & AF_NOTIFY;
144  }
Action activates a tool
Definition: tool_event.h:155
TOOL_ACTION_FLAGS m_flags
Definition: tool_action.h:173

References AF_NOTIFY, and m_flags.

Referenced by MakeEvent().

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

108  {
109  if( IsActivation() )
111  else if( IsNotification() )
113  else
115  }
bool IsActivation() const
Returns true if the action is intended to activate a tool.
Definition: tool_action.h:133
std::string m_name
Name of the action (convention is "app.tool.actionName")
Definition: tool_action.h:160
TOOL_ACTION_SCOPE m_scope
Definition: tool_action.h:161
TOOL_EVENT.
Definition: tool_event.h:171
bool IsNotification() const
Returns true if the action is a notification.
Definition: tool_action.h:141
void * m_param
Definition: tool_action.h:174

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(), DIALOG_SCH_FIND::OnReplace(), TOOLS_HOLDER::PopTool(), TOOL_MANAGER::RunAction(), ROUTER_TOOL::setTransitions(), GERBVIEW_ACTIONS::TranslateLegacyId(), and PCB_ACTIONS::TranslateLegacyId().

◆ operator!=()

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

Definition at line 66 of file tool_action.h.

67  {
68  return m_id != aRhs.m_id;
69  }

References m_id.

◆ operator=()

TOOL_ACTION& TOOL_ACTION::operator= ( const TOOL_ACTION )
delete

◆ 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  }

References m_id.

◆ SetHotKey()

void TOOL_ACTION::SetHotKey ( int  aKeycode)

Definition at line 94 of file tool_action.cpp.

95 {
96  m_hotKey = aKeycode;
97 }

References m_hotKey.

Referenced by ACTION_MANAGER::processHotKey(), HOTKEY_STORE::SaveAllHotkeys(), and TOOL_ACTION().

Friends And Related Function Documentation

◆ ACTION_MANAGER

friend class ACTION_MANAGER
friend

Definition at line 157 of file tool_action.h.

Member Data Documentation

◆ m_defaultHotKey

const int TOOL_ACTION::m_defaultHotKey
protected

Definition at line 163 of file tool_action.h.

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

◆ m_flags

TOOL_ACTION_FLAGS TOOL_ACTION::m_flags
protected

Definition at line 173 of file tool_action.h.

Referenced by IsActivation(), and IsNotification().

◆ m_hotKey

int TOOL_ACTION::m_hotKey
protected

◆ m_icon

const BITMAP_OPAQUE* TOOL_ACTION::m_icon
protected

Definition at line 169 of file tool_action.h.

Referenced by GetIcon().

◆ m_id

int TOOL_ACTION::m_id
protected

Definition at line 171 of file tool_action.h.

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

◆ m_label

wxString TOOL_ACTION::m_label
protected

◆ m_legacyName

const std::string TOOL_ACTION::m_legacyName
protected

Definition at line 165 of file tool_action.h.

Referenced by ACTION_MANAGER::processHotKey().

◆ m_name

std::string TOOL_ACTION::m_name
protected

Name of the action (convention is "app.tool.actionName")

Definition at line 160 of file tool_action.h.

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

◆ m_param

void* TOOL_ACTION::m_param
protected

Definition at line 174 of file tool_action.h.

Referenced by MakeEvent().

◆ m_scope

TOOL_ACTION_SCOPE TOOL_ACTION::m_scope
protected

Definition at line 161 of file tool_action.h.

Referenced by GetScope(), and MakeEvent().

◆ m_tooltip

wxString TOOL_ACTION::m_tooltip
protected

Definition at line 168 of file tool_action.h.

Referenced by GetDescription().


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