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 std::string& aLegacyHotKeyName = "",
51  const wxString& aMenuText = wxEmptyString, const wxString& aTooltip = wxEmptyString,
52  const BITMAP_OPAQUE* aIcon = nullptr, TOOL_ACTION_FLAGS aFlags = AF_NONE,
53  void* aParam = nullptr );
54 
55  ~TOOL_ACTION();
56 
57  // TOOL_ACTIONS are singletons; don't be copying them around....
58  TOOL_ACTION( const TOOL_ACTION& ) = delete;
59  TOOL_ACTION& operator= ( const TOOL_ACTION& ) = delete;
60 
61  bool operator==( const TOOL_ACTION& aRhs ) const
62  {
63  return m_id == aRhs.m_id;
64  }
65 
66  bool operator!=( const TOOL_ACTION& aRhs ) const
67  {
68  return m_id != aRhs.m_id;
69  }
70 
78  const std::string& GetName() const { return m_name; }
79 
84  int GetDefaultHotKey() const { return m_defaultHotKey; }
85 
90  int GetHotKey() const { return m_hotKey; }
91  void SetHotKey( int aKeycode );
92 
100  int GetId() const { return m_id; }
101 
108  {
109  if( IsActivation() )
111  else if( IsNotification() )
113  else
115  }
116 
117  wxString GetLabel() const;
118  wxString GetMenuItem() const;
119  wxString GetDescription() const;
120 
121  TOOL_ACTION_SCOPE GetScope() const { return m_scope; }
122 
128  std::string GetToolName() const;
129 
133  bool IsActivation() const
134  {
135  return m_flags & AF_ACTIVATE;
136  }
137 
141  bool IsNotification() const
142  {
143  return m_flags & AF_NOTIFY;
144  }
145 
149  const BITMAP_OPAQUE* GetIcon() const
150  {
151  return m_icon;
152  }
153 
154 protected:
155  TOOL_ACTION();
156 
157  friend class ACTION_MANAGER;
158 
160  std::string m_name;
162 
163  const int m_defaultHotKey; // Default hot key
164  int m_hotKey; // The curret hotkey (post-user-settings-application)
165  const std::string m_legacyName; // Name for reading legacy hotkey settings
166 
167  wxString m_label;
168  wxString m_tooltip;
169  const BITMAP_OPAQUE* m_icon; // Icon for the menu entry
170 
171  int m_id; // Unique ID for maps. Assigned by ACTION_MANAGER.
172 
174  void* m_param; // Generic parameter
175 };
176 
177 #endif
wxString m_label
Definition: tool_action.h:167
PNG memory record (file in memory).
Definition: bitmap_def.h:29
const BITMAP_OPAQUE * m_icon
Definition: tool_action.h:169
bool operator==(const TOOL_ACTION &aRhs) const
Definition: tool_action.h:61
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:133
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:160
TOOL_ACTION_FLAGS
Flags for tool actions.
Definition: tool_event.h:151
const BITMAP_OPAQUE * GetIcon() const
Returns an icon associated with the action.
Definition: tool_action.h:149
int GetDefaultHotKey() const
Function GetDefaultHotKey() Returns the default hotkey (if any) for the action.
Definition: tool_action.h:84
wxString GetDescription() const
Definition: tool_action.cpp:83
TOOL_ACTION & operator=(const TOOL_ACTION &)=delete
bool operator!=(const TOOL_ACTION &aRhs) const
Definition: tool_action.h:66
const std::string m_legacyName
Definition: tool_action.h:165
TOOL_ACTION_SCOPE GetScope() const
Definition: tool_action.h:121
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 SetHotKey(int aKeycode)
Definition: tool_action.cpp:94
wxString m_tooltip
Definition: tool_action.h:168
std::string GetToolName() const
Returns name of the tool associated with the action.
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100
wxString GetLabel() const
Definition: tool_action.cpp:69
TOOL_ACTION_FLAGS m_flags
Definition: tool_action.h:173
TOOL_ACTION.
Definition: tool_action.h:46
void * m_param
Definition: tool_action.h:174
TOOL_EVENT MakeEvent() const
Function MakeEvent() Returns the event associated with the action (i.e.
Definition: tool_action.h:107
wxString GetMenuItem() const
Definition: tool_action.cpp:75
int GetHotKey() const
Function GetHotKey() Returns the hotkey keycode which initiates the action.
Definition: tool_action.h:90
const int m_defaultHotKey
Definition: tool_action.h:163
const std::string & GetName() const
Function GetName() Returns name of the action.
Definition: tool_action.h:78