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  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef __TOOL_ACTION_H
27 #define __TOOL_ACTION_H
28 
29 #include <string>
30 #include <cassert>
31 
32 #include <tool/tool_event.h>
33 
34 struct BITMAP_OPAQUE;
35 
45 {
46 public:
47  TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT,
48  int aDefaultHotKey = 0, const std::string& aLegacyHotKeyName = "",
49  const wxString& aMenuText = wxEmptyString, const wxString& aTooltip = wxEmptyString,
50  const BITMAP_OPAQUE* aIcon = nullptr, TOOL_ACTION_FLAGS aFlags = AF_NONE,
51  void* aParam = nullptr );
52 
53  ~TOOL_ACTION();
54 
55  // TOOL_ACTIONS are singletons; don't be copying them around....
56  TOOL_ACTION( const TOOL_ACTION& ) = delete;
57  TOOL_ACTION& operator= ( const TOOL_ACTION& ) = delete;
58 
59  bool operator==( const TOOL_ACTION& aRhs ) const
60  {
61  return m_id == aRhs.m_id;
62  }
63 
64  bool operator!=( const TOOL_ACTION& aRhs ) const
65  {
66  return m_id != aRhs.m_id;
67  }
68 
75  const std::string& GetName() const { return m_name; }
76 
80  int GetDefaultHotKey() const { return m_defaultHotKey; }
81 
85  int GetHotKey() const { return m_hotKey; }
86  void SetHotKey( int aKeycode );
87 
94  int GetId() const { return m_id; }
95 
96  /*
97  * Get the unique ID for this action in the user interface system. This is simply
98  * the action ID offset by @c ACTION_BASE_UI_ID.
99  *
100  * @return The unique ID number for use in the user interface system.
101  */
102  int GetUIId() const { return m_id + ACTION_BASE_UI_ID; }
103 
104  /*
105  * Get the base value used to offset the user interface IDs for the actions.
106  */
107  static int GetBaseUIId() { return ACTION_BASE_UI_ID; }
108 
114  {
115  if( IsActivation() )
117  else if( IsNotification() )
119  else
121  }
122 
123  wxString GetLabel() const;
124  wxString GetMenuItem() const;
125  wxString GetDescription( bool aIncludeHotkey = true ) const;
126 
127  TOOL_ACTION_SCOPE GetScope() const { return m_scope; }
128 
134  std::string GetToolName() const;
135 
139  bool IsActivation() const
140  {
141  return m_flags & AF_ACTIVATE;
142  }
143 
147  bool IsNotification() const
148  {
149  return m_flags & AF_NOTIFY;
150  }
151 
155  const BITMAP_OPAQUE* GetIcon() const
156  {
157  return m_icon;
158  }
159 
160 protected:
161  TOOL_ACTION();
162 
163  friend class ACTION_MANAGER;
164 
166  static constexpr int ACTION_BASE_UI_ID = 20000;
167 
169  std::string m_name;
171 
172  const int m_defaultHotKey; // Default hot key
173  int m_hotKey; // The curret hotkey (post-user-settings-application)
174  const std::string m_legacyName; // Name for reading legacy hotkey settings
175 
176  wxString m_label;
177  wxString m_tooltip;
178  const BITMAP_OPAQUE* m_icon; // Icon for the menu entry
179 
180  int m_id; // Unique ID for maps. Assigned by ACTION_MANAGER.
181 
183  void* m_param; // Generic parameter
184 };
185 
186 #endif
wxString m_label
Definition: tool_action.h:176
PNG memory record (file in memory).
Definition: bitmap_def.h:29
const BITMAP_OPAQUE * m_icon
Definition: tool_action.h:178
int GetUIId() const
Definition: tool_action.h:102
bool operator==(const TOOL_ACTION &aRhs) const
Definition: tool_action.h:59
Action activates a tool
Definition: tool_event.h:155
bool IsActivation() const
Returns true if the action is intended to activate a tool.
Definition: tool_action.h:139
ACTION_MANAGER.
TOOL_ACTION_SCOPE
Scope of tool actions.
Definition: tool_event.h:143
std::string m_name
Name of the action (convention is "app.tool.actionName")
Definition: tool_action.h:169
TOOL_ACTION_FLAGS
Flags for tool actions.
Definition: tool_event.h:151
static int GetBaseUIId()
Definition: tool_action.h:107
const BITMAP_OPAQUE * GetIcon() const
Returns an icon associated with the action.
Definition: tool_action.h:155
int GetDefaultHotKey() const
Returns the default hotkey (if any) for the action.
Definition: tool_action.h:80
TOOL_ACTION & operator=(const TOOL_ACTION &)=delete
bool operator!=(const TOOL_ACTION &aRhs) const
Definition: tool_action.h:64
const std::string m_legacyName
Definition: tool_action.h:174
TOOL_ACTION_SCOPE GetScope() const
Definition: tool_action.h:127
TOOL_ACTION_SCOPE m_scope
Definition: tool_action.h:170
TOOL_EVENT.
Definition: tool_event.h:171
bool IsNotification() const
Returns true if the action is a notification.
Definition: tool_action.h:147
void SetHotKey(int aKeycode)
Definition: tool_action.cpp:94
wxString m_tooltip
Definition: tool_action.h:177
static constexpr int ACTION_BASE_UI_ID
Base ID to use inside the user interface system to offset the action IDs.
Definition: tool_action.h:166
wxString GetDescription(bool aIncludeHotkey=true) const
Definition: tool_action.cpp:83
std::string GetToolName() const
Returns name of the tool associated with the action.
int GetId() const
Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:94
wxString GetLabel() const
Definition: tool_action.cpp:69
TOOL_ACTION_FLAGS m_flags
Definition: tool_action.h:182
Represents a single user action.
Definition: tool_action.h:44
void * m_param
Definition: tool_action.h:183
TOOL_EVENT MakeEvent() const
Returns the event associated with the action (i.e.
Definition: tool_action.h:113
wxString GetMenuItem() const
Definition: tool_action.cpp:75
int GetHotKey() const
Returns the hotkey keycode which initiates the action.
Definition: tool_action.h:85
const int m_defaultHotKey
Definition: tool_action.h:172
const std::string & GetName() const
Returns name of the action.
Definition: tool_action.h:75