Commit f8f6fd41 authored by Maciej Suminski's avatar Maciej Suminski

Introduced a new type of action: TA_ACTIVATE to distinguish events activating...

Introduced a new type of action: TA_ACTIVATE to distinguish events activating tools from common tool actions.
parent 74522d5b
......@@ -228,6 +228,7 @@ set( COMMON_SRCS
math/math_util.cpp
tool/tool_action.cpp
tool/tool_base.cpp
tool/tool_manager.cpp
tool/tool_dispatcher.cpp
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <tool/tool_action.h>
std::string TOOL_ACTION::GetToolName() const
{
int dotCount = std::count( m_name.begin(), m_name.end(), '.' );
switch( dotCount )
{
case 0:
assert( false ); // Invalid action name format
return "";
case 1:
return m_name;
case 2:
return m_name.substr( 0, m_name.rfind( '.' ) );
default:
assert( false ); // TODO not implemented
return "";
}
}
......@@ -92,6 +92,7 @@ const std::string TOOL_EVENT::Format() const
{ TA_CONTEXT_MENU_CHOICE, "context-menu-choice" },
{ TA_UNDO_REDO, "undo-redo" },
{ TA_ACTION, "action" },
{ TA_ACTIVATE, "activate" },
{ 0, "" }
};
......
......@@ -294,7 +294,7 @@ bool TOOL_MANAGER::invokeTool( TOOL_BASE* aTool )
{
wxASSERT( aTool != NULL );
TOOL_EVENT evt( TC_COMMAND, TA_ACTION, aTool->GetName() );
TOOL_EVENT evt( TC_COMMAND, TA_ACTIVATE, aTool->GetName() );
ProcessEvent( evt );
return true;
......@@ -497,8 +497,11 @@ bool TOOL_MANAGER::dispatchStandardEvents( TOOL_EVENT& aEvent )
if( m_actionMgr->RunHotKey( aEvent.Modifier() | aEvent.KeyCode() ) )
return false; // hotkey event was handled so it does not go any further
}
else if( aEvent.Category() == TC_COMMAND ) // it may be a tool activation event
else if( aEvent.Action() == TA_ACTIVATE )
{
// Check if the tool name conforms to the the used tool name format
assert( std::count( aEvent.m_commandStr->begin(), aEvent.m_commandStr->end(), '.' ) == 1 );
dispatchActivation( aEvent );
// do not return false, as the event has to go on to the destined tool
}
......@@ -509,14 +512,12 @@ bool TOOL_MANAGER::dispatchStandardEvents( TOOL_EVENT& aEvent )
bool TOOL_MANAGER::dispatchActivation( TOOL_EVENT& aEvent )
{
// Look for the tool that has the same name as parameter in the processed command TOOL_EVENT
BOOST_FOREACH( TOOL_STATE* st, m_toolState | boost::adaptors::map_values )
std::map<std::string, TOOL_STATE*>::iterator tool = m_toolNameIndex.find( *aEvent.m_commandStr );
if( tool != m_toolNameIndex.end() )
{
if( st->theTool->GetName() == aEvent.m_commandStr )
{
runTool( st->theTool );
return true;
}
runTool( tool->second->theTool );
return true;
}
return false;
......
......@@ -132,7 +132,6 @@ public:
* Checks if the action has a hot key assigned.
*
* @return True if there is a hot key assigned, false otherwise.
*
*/
bool HasHotKey() const
{
......@@ -141,14 +140,17 @@ public:
/**
* Function MakeEvent()
* Returns the event associated with the action (ie. the event that will be sent after
* Returns the event associated with the action (i.e. the event that will be sent after
* activating the action).
*
* @return The event associated with the action.
*/
TOOL_EVENT MakeEvent() const
{
return TOOL_EVENT( TC_COMMAND, TA_ACTION, m_name, m_scope );
if( IsActivation() )
return TOOL_EVENT( TC_COMMAND, TA_ACTIVATE, m_name, m_scope );
else
return TOOL_EVENT( TC_COMMAND, TA_ACTION, m_name, m_scope );
}
const std::string& GetMenuItem() const
......@@ -181,9 +183,15 @@ public:
* stripped of the last part (e.g. for "pcbnew.InteractiveDrawing.drawCircle" it is
* "pcbnew.InteractiveDrawing").
*/
std::string GetToolName() const
std::string GetToolName() const;
/**
* Returns true if the action is intended to activate a tool.
*/
bool IsActivation() const
{
return m_name.substr( 0, m_name.rfind( '.' ) );
// Tool activation events are of format appName.toolName
return std::count( m_name.begin(), m_name.end(), '.' ) == 1;
}
private:
......
......@@ -91,9 +91,12 @@ enum TOOL_ACTIONS
// This event is sent *before* undo/redo command is performed.
TA_UNDO_REDO = 0x10000,
// Tool action (allows to control tools)
// Tool action (allows to control tools).
TA_ACTION = 0x20000,
// Tool activation event.
TA_ACTIVATE = 0x40000,
TA_ANY = 0xffffffff
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment