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 
47 {
48 public:
49  TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT,
50  int aDefaultHotKey = 0, const wxString aMenuItem = wxEmptyString,
51  const wxString& aMenuDesc = wxEmptyString, const BITMAP_OPAQUE* aIcon = NULL,
52  TOOL_ACTION_FLAGS aFlags = AF_NONE, void* aParam = NULL );
53 
54  ~TOOL_ACTION();
55 
56  bool operator==( const TOOL_ACTION& aRhs ) const
57  {
58  return m_id == aRhs.m_id;
59  }
60 
61  bool operator!=( const TOOL_ACTION& aRhs ) const
62  {
63  return m_id != aRhs.m_id;
64  }
65 
73  const std::string& GetName() const
74  {
75  return m_name;
76  }
77 
85  int GetId() const
86  {
87  return m_id;
88  }
89 
105  {
106  if( IsActivation() )
108  else if( IsNotification() )
110  else
112  }
113 
114  const wxString& GetMenuItem() const
115  {
116  return m_menuItem;
117  }
118 
119  void SetMenuItem( const wxString& aItem )
120  {
121  m_menuItem = aItem;
122  }
123 
124  const wxString& GetDescription() const
125  {
126  return m_menuDescription;
127  }
128 
129  void SetDescription( const wxString& aDescription )
130  {
131  m_menuDescription = aDescription;
132  }
133 
135  {
136  return m_scope;
137  }
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 
165  const BITMAP_OPAQUE* GetIcon() const
166  {
167  return m_icon;
168  }
169 
174  inline static int LegacyHotKey( int aHotKey )
175  {
176  assert( ( aHotKey & LEGACY_HK ) == 0 );
177 
178  return aHotKey | LEGACY_HK;
179  }
180 
181 private:
182  friend class ACTION_MANAGER;
183 
187  {
188  return m_defaultHotKey;
189  }
190 
192  std::string m_name;
193 
196 
198  const int m_defaultHotKey;
199 
201  wxString m_menuItem;
202 
205 
206  // Icon for menu entry
208 
210  int m_id;
211 
214 
216  void* m_param;
217 
220  static const int LEGACY_HK = 0x800000;
221 };
222 
223 #endif
PNG memory record (file in memory).
Definition: bitmap_types.h:38
const BITMAP_OPAQUE * m_icon
Definition: tool_action.h:207
bool operator==(const TOOL_ACTION &aRhs) const
Definition: tool_action.h:56
void SetDescription(const wxString &aDescription)
Definition: tool_action.h:129
bool operator!=(const TOOL_ACTION &aRhs) const
Definition: tool_action.h:61
const wxString & GetDescription() const
Definition: tool_action.h:124
Action activates a tool
Definition: tool_event.h:146
static int LegacyHotKey(int aHotKey)
Creates a hot key code that refers to a legacy hot key setting, instead of a particular key...
Definition: tool_action.h:174
Class ACTION_MANAGER.
TOOL_ACTION_SCOPE
Scope of tool actions.
Definition: tool_event.h:134
std::string m_name
Name of the action (convention is: app.[tool.]action.name)
Definition: tool_action.h:192
TOOL_ACTION_FLAGS
Flags for tool actions.
Definition: tool_event.h:142
TOOL_ACTION_SCOPE GetScope() const
Definition: tool_action.h:134
void SetMenuItem(const wxString &aItem)
Definition: tool_action.h:119
TOOL_ACTION_SCOPE m_scope
Scope of the action.
Definition: tool_action.h:195
Class TOOL_EVENT.
Definition: tool_event.h:162
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:220
const wxString & GetMenuItem() const
Definition: tool_action.h:114
const std::string & GetName() const
Function GetName() Returns name of the action.
Definition: tool_action.h:73
std::string GetToolName() const
Returns name of the tool associated with the action.
Definition: tool_action.cpp:45
bool IsNotification() const
Returns true if the action is a notification.
Definition: tool_action.h:157
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: tool_action.cpp:28
TOOL_EVENT MakeEvent() const
Function HasHotKey() Checks if the action has a hot key assigned.
Definition: tool_action.h:104
TOOL_ACTION_FLAGS m_flags
Action flags.
Definition: tool_action.h:213
bool IsActivation() const
Returns true if the action is intended to activate a tool.
Definition: tool_action.h:149
Class TOOL_ACTION.
Definition: tool_action.h:46
void * m_param
Generic parameter.
Definition: tool_action.h:216
const BITMAP_OPAQUE * GetIcon() const
Returns an icon associated with the action.
Definition: tool_action.h:165
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:85
int m_id
Unique ID for fast matching. Assigned by ACTION_MANAGER.
Definition: tool_action.h:210
int getDefaultHotKey()
Returns the hot key assigned in the object definition.
Definition: tool_action.h:186
wxString m_menuDescription
Pop-up help.
Definition: tool_action.h:204
wxString m_menuItem
Menu entry text.
Definition: tool_action.h:201
const int m_defaultHotKey
Default hot key that activates the action.
Definition: tool_action.h:198