KiCad PCB EDA Suite
tool_action.cpp
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 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <tool/tool_action.h>
26 #include <tool/action_manager.h>
27 
28 TOOL_ACTION::TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope,
29  int aDefaultHotKey, const wxString aMenuItem, const wxString& aMenuDesc,
30  const BITMAP_OPAQUE* aIcon, TOOL_ACTION_FLAGS aFlags, void* aParam ) :
31  m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ),
32  m_menuItem( aMenuItem ), m_menuDescription( aMenuDesc ),
33  m_icon( aIcon ), m_id( -1 ), m_flags( aFlags ), m_param( aParam )
34 {
35  ACTION_MANAGER::GetActionList().push_back( this );
36 }
37 
38 
40 {
41  ACTION_MANAGER::GetActionList().remove( this );
42 }
43 
44 
45 std::string TOOL_ACTION::GetToolName() const
46 {
47  int dotCount = std::count( m_name.begin(), m_name.end(), '.' );
48 
49  switch( dotCount )
50  {
51  case 0:
52  assert( false ); // Invalid action name format
53  return "";
54 
55  case 1:
56  return m_name;
57 
58  case 2:
59  return m_name.substr( 0, m_name.rfind( '.' ) );
60 
61  default:
62  assert( false ); // TODO not implemented
63  return "";
64  }
65 }
PNG memory record (file in memory).
Definition: bitmap_types.h:38
TOOL_ACTION_SCOPE
Scope of tool actions.
Definition: tool_event.h:134
static std::list< TOOL_ACTION * > & GetActionList()
Function GetActionList() Returns list of TOOL_ACTIONs.
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
std::string GetToolName() const
Returns name of the tool associated with the action.
Definition: tool_action.cpp:45
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