KiCad PCB EDA Suite
tool_action.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013-2015 CERN
5  * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8  * @author Maciej Suminski <maciej.suminski@cern.ch>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #ifndef __TOOL_ACTION_H
29 #define __TOOL_ACTION_H
30 
31 #include <string>
32 #include <cassert>
33 
34 #include <tool/tool_event.h>
35 
36 struct BITMAP_OPAQUE;
37 
50 {
51 public:
52  TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT,
53  int aDefaultHotKey = 0, const std::string& aLegacyHotKeyName = "",
54  const wxString& aMenuText = wxEmptyString,
55  const wxString& aTooltip = wxEmptyString,
56  const BITMAP_OPAQUE* aIcon = nullptr, TOOL_ACTION_FLAGS aFlags = AF_NONE,
57  void* aParam = nullptr );
58 
59  ~TOOL_ACTION();
60 
61  // TOOL_ACTIONS are singletons; don't be copying them around....
62  TOOL_ACTION( const TOOL_ACTION& ) = delete;
63  TOOL_ACTION& operator= ( const TOOL_ACTION& ) = delete;
64 
65  bool operator==( const TOOL_ACTION& aRhs ) const
66  {
67  return m_id == aRhs.m_id;
68  }
69 
70  bool operator!=( const TOOL_ACTION& aRhs ) const
71  {
72  return m_id != aRhs.m_id;
73  }
74 
83  const std::string& GetName() const { return m_name; }
84 
88  int GetDefaultHotKey() const { return m_defaultHotKey; }
89 
93  int GetHotKey() const { return m_hotKey; }
94  void SetHotKey( int aKeycode );
95 
103  int GetId() const { return m_id; }
104 
105  /*
106  * Get the unique ID for this action in the user interface system.
107  *
108  * This is simply the action ID offset by @c ACTION_BASE_UI_ID.
109  *
110  * @return The unique ID number for use in the user interface system.
111  */
112  int GetUIId() const { return m_id + ACTION_BASE_UI_ID; }
113 
114  /*
115  * Get the base value used to offset the user interface IDs for the actions.
116  */
117  static int GetBaseUIId() { return ACTION_BASE_UI_ID; }
118 
124  {
125  if( IsActivation() )
127  else if( IsNotification() )
129  else
131  }
132 
133  wxString GetLabel() const;
134  wxString GetMenuItem() const;
135  wxString GetDescription( bool aIncludeHotkey = true ) const;
136 
137  TOOL_ACTION_SCOPE GetScope() const { return m_scope; }
138 
144  std::string GetToolName() const;
145 
149  bool IsActivation() const
150  {
151  return m_flags & AF_ACTIVATE;
152  }
153 
157  bool IsNotification() const
158  {
159  return m_flags & AF_NOTIFY;
160  }
161 
167  const BITMAP_OPAQUE* GetIcon() const
168  {
169  return m_icon;
170  }
171 
172 protected:
173  TOOL_ACTION();
174 
175  friend class ACTION_MANAGER;
176 
178  static constexpr int ACTION_BASE_UI_ID = 20000;
179 
181  std::string m_name;
183 
184  const int m_defaultHotKey; // Default hot key
185  int m_hotKey; // The current hotkey (post-user-settings-application)
186  const std::string m_legacyName; // Name for reading legacy hotkey settings
187 
188  wxString m_label;
189  wxString m_tooltip;
190  const BITMAP_OPAQUE* m_icon; // Icon for the menu entry
191 
192  int m_id; // Unique ID for maps. Assigned by ACTION_MANAGER.
193 
195  void* m_param; // Generic parameter
196 };
197 
198 #endif
wxString m_label
Definition: tool_action.h:188
PNG memory record (file in memory).
Definition: bitmap_def.h:29
const BITMAP_OPAQUE * m_icon
Definition: tool_action.h:190
int GetUIId() const
Definition: tool_action.h:112
Action belongs to a particular tool (i.e. a part of a pop-up menu)
Definition: tool_event.h:146
bool operator==(const TOOL_ACTION &aRhs) const
Definition: tool_action.h:65
Action is a notification (it is by default passed to all tools)
Definition: tool_event.h:156
bool IsActivation() const
Return true if the action is intended to activate a tool.
Definition: tool_action.h:149
Manage TOOL_ACTION objects.
TOOL_ACTION_SCOPE
Scope of tool actions.
Definition: tool_event.h:144
std::string m_name
Definition: tool_action.h:181
TOOL_ACTION_FLAGS
Flags for tool actions.
Definition: tool_event.h:152
static int GetBaseUIId()
Definition: tool_action.h:117
const BITMAP_OPAQUE * GetIcon() const
Return an icon associated with the action.
Definition: tool_action.h:167
int GetDefaultHotKey() const
Return the default hotkey (if any) for the action.
Definition: tool_action.h:88
Action activates a tool.
Definition: tool_event.h:155
TOOL_ACTION & operator=(const TOOL_ACTION &)=delete
bool operator!=(const TOOL_ACTION &aRhs) const
Definition: tool_action.h:70
const std::string m_legacyName
Definition: tool_action.h:186
TOOL_ACTION_SCOPE GetScope() const
Definition: tool_action.h:137
TOOL_ACTION_SCOPE m_scope
Definition: tool_action.h:182
Generic, UI-independent tool event.
Definition: tool_event.h:170
bool IsNotification() const
Return true if the action is a notification.
Definition: tool_action.h:157
void SetHotKey(int aKeycode)
Definition: tool_action.cpp:94
wxString m_tooltip
Definition: tool_action.h:189
static constexpr int ACTION_BASE_UI_ID
Name of the action (convention is "app.tool.actionName")
Definition: tool_action.h:178
wxString GetDescription(bool aIncludeHotkey=true) const
Definition: tool_action.cpp:83
std::string GetToolName() const
Return name of the tool associated with the action.
int GetId() const
Return the unique id of the TOOL_ACTION object.
Definition: tool_action.h:103
wxString GetLabel() const
Definition: tool_action.cpp:69
TOOL_ACTION_FLAGS m_flags
Definition: tool_action.h:194
Represent a single user action.
Definition: tool_action.h:49
void * m_param
Definition: tool_action.h:195
TOOL_EVENT MakeEvent() const
Return the event associated with the action (i.e.
Definition: tool_action.h:123
wxString GetMenuItem() const
Definition: tool_action.cpp:75
int GetHotKey() const
Return the hotkey keycode which initiates the action.
Definition: tool_action.h:93
const int m_defaultHotKey
Definition: tool_action.h:184
const std::string & GetName() const
Return name of the action.
Definition: tool_action.h:83