KiCad PCB EDA Suite
TOOL_ACTION Class Reference

Represent a single user 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, BITMAPS aIcon=static_cast< BITMAPS >(0), 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
 Return name of the action. More...
 
int GetDefaultHotKey () const
 Return the default hotkey (if any) for the action. More...
 
int GetHotKey () const
 Return the hotkey keycode which initiates the action. More...
 
void SetHotKey (int aKeycode)
 
int GetId () const
 Return the unique id of the TOOL_ACTION object. More...
 
int GetUIId () const
 
TOOL_EVENT MakeEvent () const
 Return the event associated with the action (i.e. More...
 
wxString GetLabel () const
 
wxString GetMenuItem () const
 
wxString GetDescription (bool aIncludeHotkey=true) const
 
TOOL_ACTION_SCOPE GetScope () const
 
void * GetParam () const
 
std::string GetToolName () const
 Return name of the tool associated with the action. More...
 
bool IsActivation () const
 Return true if the action is intended to activate a tool. More...
 
bool IsNotification () const
 Return true if the action is a notification. More...
 
const BITMAPS GetIcon () const
 Return an icon associated with the action. More...
 

Static Public Member Functions

static int GetBaseUIId ()
 

Protected Member Functions

 TOOL_ACTION ()
 

Protected Attributes

std::string m_name
 
TOOL_ACTION_SCOPE m_scope
 
const int m_defaultHotKey
 
int m_hotKey
 
const std::string m_legacyName
 
wxString m_label
 
wxString m_tooltip
 
BITMAPS m_icon
 
int m_id
 
TOOL_ACTION_FLAGS m_flags
 
void * m_param
 

Static Protected Attributes

static constexpr int ACTION_BASE_UI_ID = 20000
 Name of the action (convention is "app.tool.actionName") More...
 

Friends

class ACTION_MANAGER
 Base ID to use inside the user interface system to offset the action IDs. More...
 

Detailed Description

Represent 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 49 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,
BITMAPS  aIcon = static_cast<BITMAPS>( 0 ),
TOOL_ACTION_FLAGS  aFlags = AF_NONE,
void *  aParam = nullptr 
)

Definition at line 32 of file tool_action.cpp.

35  :
36  m_name( aName ),
37  m_scope( aScope ),
38  m_defaultHotKey( aDefaultHotKey ),
39  m_legacyName( aLegacyHotKeyName ),
40  m_label( aLabel ),
41  m_tooltip( aTooltip ),
42  m_icon( aIcon ),
43  m_id( -1 ),
44  m_flags( aFlags ),
45  m_param( aParam )
46 {
47  SetHotKey( aDefaultHotKey );
48  ACTION_MANAGER::GetActionList().push_back( this );
49 }
wxString m_label
Definition: tool_action.h:190
static std::list< TOOL_ACTION * > & GetActionList()
Return list of TOOL_ACTIONs.
std::string m_name
Definition: tool_action.h:183
const std::string m_legacyName
Definition: tool_action.h:188
TOOL_ACTION_SCOPE m_scope
Definition: tool_action.h:184
void SetHotKey(int aKeycode)
Definition: tool_action.cpp:95
BITMAPS m_icon
Definition: tool_action.h:192
wxString m_tooltip
Definition: tool_action.h:191
TOOL_ACTION_FLAGS m_flags
Definition: tool_action.h:196
void * m_param
Definition: tool_action.h:197
const int m_defaultHotKey
Definition: tool_action.h:186

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

◆ ~TOOL_ACTION()

TOOL_ACTION::~TOOL_ACTION ( )

Definition at line 64 of file tool_action.cpp.

65 {
66  ACTION_MANAGER::GetActionList().remove( this );
67 }
static std::list< TOOL_ACTION * > & GetActionList()
Return 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 52 of file tool_action.cpp.

52  :
53  m_scope( AS_GLOBAL ),
54  m_defaultHotKey( 0 ),
56  m_id( -1 ),
57  m_flags( AF_NONE ),
58  m_param( nullptr )
59 {
60  SetHotKey( 0 );
61 }
TOOL_ACTION_SCOPE m_scope
Definition: tool_action.h:184
void SetHotKey(int aKeycode)
Definition: tool_action.cpp:95
BITMAPS m_icon
Definition: tool_action.h:192
Global action (toolbar/main menu event, global shortcut)
Definition: tool_event.h:151
TOOL_ACTION_FLAGS m_flags
Definition: tool_action.h:196
void * m_param
Definition: tool_action.h:197
const int m_defaultHotKey
Definition: tool_action.h:186

References INVALID_BITMAP, and SetHotKey().

Member Function Documentation

◆ GetBaseUIId()

static int TOOL_ACTION::GetBaseUIId ( )
inlinestatic

Definition at line 117 of file tool_action.h.

117 { return ACTION_BASE_UI_ID; }
static constexpr int ACTION_BASE_UI_ID
Name of the action (convention is "app.tool.actionName")
Definition: tool_action.h:180

References ACTION_BASE_UI_ID.

Referenced by ACTION_GROUP::GetUIId(), ACTION_MENU::OnMenuEvent(), and ACTION_TOOLBAR::onToolEvent().

◆ GetDefaultHotKey()

int TOOL_ACTION::GetDefaultHotKey ( ) const
inline

Return the default hotkey (if any) for the action.

Definition at line 88 of file tool_action.h.

88 { return m_defaultHotKey; }
const int m_defaultHotKey
Definition: tool_action.h:186

References m_defaultHotKey.

◆ GetDescription()

wxString TOOL_ACTION::GetDescription ( bool  aIncludeHotkey = true) const

Definition at line 84 of file tool_action.cpp.

85 {
86  wxString tooltip = wxGetTranslation( m_tooltip );
87 
88  if( aIncludeHotkey && GetHotKey() )
89  tooltip += wxString::Format( wxT( " (%s)" ), KeyNameFromKeyCode( GetHotKey() ) );
90 
91  return tooltip;
92 }
wxString m_tooltip
Definition: tool_action.h:191
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
int GetHotKey() const
Return the hotkey keycode which initiates the action.
Definition: tool_action.h:93

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

Referenced by ACTION_MENU::Add(), ACTION_TOOLBAR::Add(), ACTION_TOOLBAR_PALETTE::AddAction(), PANEL_KICAD_LAUNCHER::CreateLaunchers(), and ACTION_TOOLBAR::doSelectAction().

◆ GetHotKey()

int TOOL_ACTION::GetHotKey ( ) const
inline

Return the hotkey keycode which initiates the action.

Definition at line 93 of file tool_action.h.

93 { return m_hotKey; }

References m_hotKey.

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

◆ GetIcon()

const BITMAPS TOOL_ACTION::GetIcon ( ) const
inline

Return an icon associated with the action.

It is used in context menu.

Definition at line 169 of file tool_action.h.

170  {
171  return m_icon;
172  }
BITMAPS m_icon
Definition: tool_action.h:192

References m_icon.

Referenced by ACTION_MENU::Add(), ACTION_TOOLBAR::Add(), ACTION_TOOLBAR_PALETTE::AddAction(), ACTION_TOOLBAR::AddButton(), ACTION_TOOLBAR::AddGroup(), and ACTION_TOOLBAR::doSelectAction().

◆ GetId()

int TOOL_ACTION::GetId ( ) const
inline

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

103 { return m_id; }

References m_id.

Referenced by CONDITIONAL_MENU::AddCheckItem(), CONDITIONAL_MENU::AddItem(), ACTION_MANAGER::GetCondition(), ACTION_MANAGER::GetHotKey(), TOOL_EVENT::IsCancelInteractive(), TOOL_EVENT::IsPointEditor(), APPEARANCE_CONTROLS::onNetclassContextMenu(), ACTION_TOOLBAR::SelectAction(), ACTION_MANAGER::SetConditions(), ACTION_GROUP::SetDefaultAction(), and ACTION_MANAGER::UpdateHotKeys().

◆ GetLabel()

wxString TOOL_ACTION::GetLabel ( ) const

Definition at line 70 of file tool_action.cpp.

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

References m_label.

Referenced by PANEL_KICAD_LAUNCHER::CreateLaunchers(), TOOLS_HOLDER::PushTool(), and WIDGET_HOTKEY_LIST::resolveKeyConflicts().

◆ GetMenuItem()

wxString TOOL_ACTION::GetMenuItem ( ) const

Definition at line 76 of file tool_action.cpp.

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

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

Referenced by ACTION_MENU::Add().

◆ GetName()

const std::string& TOOL_ACTION::GetName ( void  ) const
inline

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

83 { return m_name; }
std::string m_name
Definition: tool_action.h:183

References m_name.

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

◆ GetParam()

void* TOOL_ACTION::GetParam ( ) const
inline

Definition at line 139 of file tool_action.h.

139 { return m_param; }
void * m_param
Definition: tool_action.h:197

References m_param.

◆ GetScope()

TOOL_ACTION_SCOPE TOOL_ACTION::GetScope ( ) const
inline

Definition at line 137 of file tool_action.h.

137 { return m_scope; }
TOOL_ACTION_SCOPE m_scope
Definition: tool_action.h:184

References m_scope.

◆ GetToolName()

std::string TOOL_ACTION::GetToolName ( ) const

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

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

References m_name.

◆ GetUIId()

◆ IsActivation()

bool TOOL_ACTION::IsActivation ( ) const
inline

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

Definition at line 151 of file tool_action.h.

152  {
153  return m_flags & AF_ACTIVATE;
154  }
Action activates a tool.
Definition: tool_event.h:158
TOOL_ACTION_FLAGS m_flags
Definition: tool_action.h:196

References AF_ACTIVATE.

Referenced by MakeEvent().

◆ IsNotification()

bool TOOL_ACTION::IsNotification ( ) const
inline

Return true if the action is a notification.

Definition at line 159 of file tool_action.h.

160  {
161  return m_flags & AF_NOTIFY;
162  }
Action is a notification (it is by default passed to all tools)
Definition: tool_event.h:159
TOOL_ACTION_FLAGS m_flags
Definition: tool_action.h:196

References AF_NOTIFY.

Referenced by MakeEvent().

◆ MakeEvent()

TOOL_EVENT TOOL_ACTION::MakeEvent ( ) const
inline

Return the event associated with the action (i.e.

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

Definition at line 123 of file tool_action.h.

124  {
125  if( IsActivation() )
127  else if( IsNotification() )
129  else
131  }
bool IsActivation() const
Return true if the action is intended to activate a tool.
Definition: tool_action.h:151
std::string m_name
Definition: tool_action.h:183
TOOL_ACTION_SCOPE m_scope
Definition: tool_action.h:184
Generic, UI-independent tool event.
Definition: tool_event.h:173
bool IsNotification() const
Return true if the action is a notification.
Definition: tool_action.h:159
void * m_param
Definition: tool_action.h:197

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

Referenced by PANEL_KICAD_LAUNCHER::CreateLaunchers(), EDIT_TOOL::Duplicate(), TOOL_EVENT::IsAction(), EE_SELECTION_TOOL::Main(), ACTION_TOOLBAR::onPaletteEvent(), DIALOG_SCH_FIND::OnReplace(), TOOLS_HOLDER::PopTool(), TOOL_MANAGER::RunAction(), ROUTER_TOOL::setTransitions(), and BOARD_EDITOR_CONTROL::setTransitions().

◆ operator!=()

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

Definition at line 70 of file tool_action.h.

71  {
72  return m_id != aRhs.m_id;
73  }

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

66  {
67  return m_id == aRhs.m_id;
68  }

References m_id.

◆ SetHotKey()

void TOOL_ACTION::SetHotKey ( int  aKeycode)

Definition at line 95 of file tool_action.cpp.

96 {
97  m_hotKey = aKeycode;
98 }

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

Base ID to use inside the user interface system to offset the action IDs.

Definition at line 177 of file tool_action.h.

Member Data Documentation

◆ ACTION_BASE_UI_ID

constexpr int TOOL_ACTION::ACTION_BASE_UI_ID = 20000
staticprotected

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

Definition at line 180 of file tool_action.h.

Referenced by GetBaseUIId(), and GetUIId().

◆ m_defaultHotKey

const int TOOL_ACTION::m_defaultHotKey
protected

Definition at line 186 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 196 of file tool_action.h.

◆ m_hotKey

int TOOL_ACTION::m_hotKey
protected

◆ m_icon

BITMAPS TOOL_ACTION::m_icon
protected

Definition at line 192 of file tool_action.h.

Referenced by GetIcon().

◆ m_id

int TOOL_ACTION::m_id
protected

Definition at line 194 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 188 of file tool_action.h.

Referenced by ACTION_MANAGER::processHotKey().

◆ m_name

std::string TOOL_ACTION::m_name
protected

◆ m_param

void* TOOL_ACTION::m_param
protected

Definition at line 197 of file tool_action.h.

Referenced by GetParam().

◆ m_scope

TOOL_ACTION_SCOPE TOOL_ACTION::m_scope
protected

Definition at line 184 of file tool_action.h.

Referenced by GetScope().

◆ m_tooltip

wxString TOOL_ACTION::m_tooltip
protected

Definition at line 191 of file tool_action.h.

Referenced by GetDescription().


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