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 #include <algorithm>
29 
30 TOOL_ACTION::TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope,
31  int aDefaultHotKey, const wxString aMenuItem, const wxString& aMenuDesc,
32  const BITMAP_OPAQUE* aIcon, TOOL_ACTION_FLAGS aFlags, void* aParam ) :
33  m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ),
34  m_menuItem( aMenuItem ), m_menuDescription( aMenuDesc ),
35  m_icon( aIcon ), m_id( -1 ), m_flags( aFlags ), m_param( aParam )
36 {
37  ACTION_MANAGER::GetActionList().push_back( this );
38 }
39 
40 
42 {
43  ACTION_MANAGER::GetActionList().remove( this );
44 }
45 
46 
47 std::string TOOL_ACTION::GetToolName() const
48 {
49  int dotCount = std::count( m_name.begin(), m_name.end(), '.' );
50 
51  switch( dotCount )
52  {
53  case 0:
54  assert( false ); // Invalid action name format
55  return "";
56 
57  case 1:
58  return m_name;
59 
60  case 2:
61  return m_name.substr( 0, m_name.rfind( '.' ) );
62 
63  default:
64  assert( false ); // TODO not implemented
65  return "";
66  }
67 }
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:47
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:30