Commit 94cc845b authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Added AF_ACTIVATE flag for TOOL_ACTIONs.

Reworked the way of processing events in TOOL_MANAGER class.
Added GetCommandStr() for TOOL_EVENT class.
parent 34fbde42
Loading
Loading
Loading
Loading
+36 −36
Original line number Diff line number Diff line
@@ -497,20 +497,14 @@ 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.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
    }

    return true;
}


bool TOOL_MANAGER::dispatchActivation( TOOL_EVENT& aEvent )
{
    if( aEvent.IsActivate() )
    {
        std::map<std::string, TOOL_STATE*>::iterator tool = m_toolNameIndex.find( *aEvent.m_commandStr );

@@ -519,34 +513,14 @@ bool TOOL_MANAGER::dispatchActivation( TOOL_EVENT& aEvent )
            runTool( tool->second->theTool );
            return true;
        }

    return false;
    }


void TOOL_MANAGER::finishTool( TOOL_STATE* aState )
{
    if( !aState->Pop() )        // if there are no other contexts saved on the stack
    {
        // find the tool and deactivate it
        std::deque<TOOL_ID>::iterator tool = std::find( m_activeTools.begin(), m_activeTools.end(),
                                                        aState->theTool->GetId() );

        if( tool != m_activeTools.end() )
            m_activeTools.erase( tool );
    }
    return false;
}


bool TOOL_MANAGER::ProcessEvent( TOOL_EVENT& aEvent )
void TOOL_MANAGER::dispatchContextMenu( TOOL_EVENT& aEvent )
{
    // Early dispatch of events destined for the TOOL_MANAGER
    if( !dispatchStandardEvents( aEvent ) )
        return false;

    dispatchInternal( aEvent );

    // popup menu handling
    BOOST_FOREACH( TOOL_ID toolId, m_activeTools )
    {
        TOOL_STATE* st = m_toolIdIndex[toolId];
@@ -577,6 +551,32 @@ bool TOOL_MANAGER::ProcessEvent( TOOL_EVENT& aEvent )
            break;
        }
    }
}


void TOOL_MANAGER::finishTool( TOOL_STATE* aState )
{
    if( !aState->Pop() )        // if there are no other contexts saved on the stack
    {
        // find the tool and deactivate it
        std::deque<TOOL_ID>::iterator tool = std::find( m_activeTools.begin(), m_activeTools.end(),
                                                        aState->theTool->GetId() );

        if( tool != m_activeTools.end() )
            m_activeTools.erase( tool );
    }
}


bool TOOL_MANAGER::ProcessEvent( TOOL_EVENT& aEvent )
{
    // Early dispatch of events destined for the TOOL_MANAGER
    if( !dispatchStandardEvents( aEvent ) )
        return false;

    dispatchInternal( aEvent );
    dispatchActivation( aEvent );
    dispatchContextMenu( aEvent );

    if( m_view->IsDirty() )
    {
+7 −6
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@
#include <string>
#include <cassert>

#include <tool/tool_base.h>
#include <tool/tool_manager.h>

/**
@@ -47,10 +46,10 @@ class TOOL_ACTION
public:
    TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT,
            int aDefaultHotKey = 0, const std::string& aMenuItem = std::string( "" ),
            const std::string& aMenuDesc = std::string( "" ) ) :
            const std::string& aMenuDesc = std::string( "" ), TOOL_ACTION_FLAGS aFlags = AF_NONE ) :
        m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ),
        m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ),
        m_menuDescription( aMenuDesc ), m_id( -1 )
        m_menuDescription( aMenuDesc ), m_id( -1 ), m_flags( aFlags )
    {
        TOOL_MANAGER::GetActionList().push_back( this );
    }
@@ -190,8 +189,7 @@ public:
     */
    bool IsActivation() const
    {
        // Tool activation events are of format appName.toolName
        return std::count( m_name.begin(), m_name.end(), '.' ) == 1;
        return m_flags & AF_ACTIVATE;
    }

private:
@@ -200,7 +198,7 @@ private:
    /// Name of the action (convention is: app.[tool.]action.name)
    std::string m_name;

    /// Scope of the action (ie. the event that is issued after activation).
    /// Scope of the action (i.e. the event that is issued after activation).
    TOOL_ACTION_SCOPE m_scope;

    /// Default hot key that activates the action.
@@ -221,6 +219,9 @@ private:
    /// Unique ID for fast matching. Assigned by ACTION_MANAGER.
    int m_id;

    /// Action flags
    TOOL_ACTION_FLAGS m_flags;

    /// Origin of the action
    // const TOOL_BASE* m_origin;

+18 −1
Original line number Diff line number Diff line
@@ -126,6 +126,13 @@ enum TOOL_ACTION_SCOPE
    AS_GLOBAL        ///> Global action (toolbar/main menu event, global shortcut)
};

/// Flags for tool actions
enum TOOL_ACTION_FLAGS
{
    AF_NONE     = 0,
    AF_ACTIVATE = 1  ///> Action activates a tool
};

/// Defines when a context menu is opened.
enum CONTEXT_MENU_TRIGGER
{
@@ -268,6 +275,11 @@ public:
        return m_actions == TA_CANCEL_TOOL;
    }

    bool IsActivate() const
    {
        return m_actions == TA_ACTIVATE;
    }

    ///> Returns information about key modifiers state (Ctrl, Alt, etc.)
    int Modifier( int aMask = MD_MODIFIER_MASK ) const
    {
@@ -334,11 +346,16 @@ public:
     */
    bool IsAction( const TOOL_ACTION* aAction ) const;

    boost::optional<int> GetCommandId()
    boost::optional<int> GetCommandId() const
    {
        return m_commandId;
    }

    boost::optional<std::string> GetCommandStr() const
    {
        return m_commandStr;
    }

private:
    friend class TOOL_MANAGER;

+10 −0
Original line number Diff line number Diff line
@@ -274,6 +274,10 @@ private:
    struct TOOL_STATE;
    typedef std::pair<TOOL_EVENT_LIST, TOOL_STATE_FUNC> TRANSITION;

    /**
     * Function dispatchInternal
     * Passes an event at first to the active tools, then to all others.
     */
    void dispatchInternal( TOOL_EVENT& aEvent );

    /**
@@ -292,6 +296,12 @@ private:
     */
    bool dispatchActivation( TOOL_EVENT& aEvent );

    /**
     * Function dispatchContextMenu()
     * Handles context menu related events.
     */
    void dispatchContextMenu( TOOL_EVENT& aEvent );

    /**
     * Function invokeTool()
     * Invokes a tool by sending a proper event (in contrary to runTool, which makes the tool run
+7 −7
Original line number Diff line number Diff line
@@ -480,7 +480,6 @@ void ROUTER_TOOL::updateEndItem( TOOL_EVENT& aEvent )
    VECTOR2I p = getView()->ToWorld( ctls->GetMousePosition() );
    VECTOR2I cp = ctls->GetCursorPosition();
    int layer;

    bool snapEnabled = !aEvent.Modifier( MD_SHIFT );

    m_router->EnableSnapping ( snapEnabled );
@@ -554,7 +553,7 @@ void ROUTER_TOOL::performRouting()

    while( OPT_TOOL_EVENT evt = Wait() )
    {
        if( evt->IsCancel() )
        if( evt->IsCancel() || evt->IsActivate() )
            break;
        else if( evt->Action() == TA_UNDO_REDO )
        {
@@ -663,7 +662,7 @@ int ROUTER_TOOL::Main( TOOL_EVENT& aEvent )
            m_needsSync = false;
        }

        if( evt->IsCancel() )
        if( evt->IsCancel() || evt->IsActivate() )
            break; // Finish
        else if( evt->Action() == TA_UNDO_REDO )
            m_needsSync = true;
@@ -677,7 +676,8 @@ int ROUTER_TOOL::Main( TOOL_EVENT& aEvent )
                performDragging();
            else
                performRouting();
        } else if ( evt->IsAction( &ACT_Drag ) )
        }
        else if ( evt->IsAction( &ACT_Drag ) )
            performDragging();

        handleCommonEvents( *evt );
@@ -715,7 +715,7 @@ void ROUTER_TOOL::performDragging()

    while( OPT_TOOL_EVENT evt = Wait() )
    {
        if( evt->IsCancel() )
        if( evt->IsCancel() || evt->IsActivate() )
            break;
        else if( evt->Action() == TA_UNDO_REDO )
        {
Loading