Commit 4876dbea authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Storing the selected item position from a context menu.

parent 3ce3d22b
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
@@ -29,7 +29,7 @@
#include <cassert>
#include <cassert>


CONTEXT_MENU::CONTEXT_MENU() :
CONTEXT_MENU::CONTEXT_MENU() :
    m_titleSet( false ), m_handler( this ), m_tool( NULL )
    m_titleSet( false ), m_selected( -1 ), m_handler( this ), m_tool( NULL )
{
{
    m_menu.Connect( wxEVT_MENU_HIGHLIGHT, wxEventHandler( CMEventHandler::onEvent ),
    m_menu.Connect( wxEVT_MENU_HIGHLIGHT, wxEventHandler( CMEventHandler::onEvent ),
                     NULL, &m_handler );
                     NULL, &m_handler );
@@ -43,7 +43,7 @@ CONTEXT_MENU::CONTEXT_MENU() :




CONTEXT_MENU::CONTEXT_MENU( const CONTEXT_MENU& aMenu ) :
CONTEXT_MENU::CONTEXT_MENU( const CONTEXT_MENU& aMenu ) :
    m_titleSet( aMenu.m_titleSet ), m_handler( this ), m_tool( aMenu.m_tool )
    m_titleSet( aMenu.m_titleSet ), m_selected( -1 ), m_handler( this ), m_tool( aMenu.m_tool )
{
{
    m_menu.Connect( wxEVT_MENU_HIGHLIGHT, wxEventHandler( CMEventHandler::onEvent ),
    m_menu.Connect( wxEVT_MENU_HIGHLIGHT, wxEventHandler( CMEventHandler::onEvent ),
                     NULL, &m_handler );
                     NULL, &m_handler );
@@ -164,6 +164,9 @@ void CONTEXT_MENU::CMEventHandler::onEvent( wxEvent& aEvent )
    // One of menu entries was selected..
    // One of menu entries was selected..
    else if( type == wxEVT_COMMAND_MENU_SELECTED )
    else if( type == wxEVT_COMMAND_MENU_SELECTED )
    {
    {
        // Store the selected position
        m_menu->m_selected = aEvent.GetId();

        // Check if there is a TOOL_ACTION for the given ID
        // Check if there is a TOOL_ACTION for the given ID
        if( m_menu->m_toolActions.count( aEvent.GetId() ) == 1 )
        if( m_menu->m_toolActions.count( aEvent.GetId() ) == 1 )
        {
        {
+6 −3
Original line number Original line Diff line number Diff line
@@ -446,9 +446,12 @@ bool TOOL_MANAGER::ProcessEvent( TOOL_EVENT& aEvent )
            boost::scoped_ptr<CONTEXT_MENU> menu( new CONTEXT_MENU( *st->contextMenu ) );
            boost::scoped_ptr<CONTEXT_MENU> menu( new CONTEXT_MENU( *st->contextMenu ) );
            GetEditFrame()->PopupMenu( menu->GetMenu() );
            GetEditFrame()->PopupMenu( menu->GetMenu() );


            //
            // If nothing was chosen from the context menu, we must notify the tool as well
            if( menu->GetSelected() < 0 )
            {
                TOOL_EVENT evt( TC_COMMAND, TA_CONTEXT_MENU_CHOICE );
                TOOL_EVENT evt( TC_COMMAND, TA_CONTEXT_MENU_CHOICE );
                dispatchInternal( evt );
                dispatchInternal( evt );
            }


            break;
            break;
        }
        }
+14 −0
Original line number Original line Diff line number Diff line
@@ -78,6 +78,17 @@ public:
     */
     */
    void Clear();
    void Clear();


    /**
     * Function GetSelected()
     * Returns the position of selected item. If the returned value is negative, that means that
     * menu was dismissed.
     * @return The position of selected item in the context menu.
     */
    int GetSelected() const
    {
        return m_selected;
    }

    /**
    /**
     * Function GetMenu()
     * Function GetMenu()
     * Returns the instance of wxMenu object used to display the menu.
     * Returns the instance of wxMenu object used to display the menu.
@@ -131,6 +142,9 @@ private:
    ///> Instance of wxMenu used for display of the context menu.
    ///> Instance of wxMenu used for display of the context menu.
    wxMenu m_menu;
    wxMenu m_menu;


    ///> Stores the id number of selected item.
    int m_selected;

    ///> Instance of menu event handler.
    ///> Instance of menu event handler.
    CMEventHandler m_handler;
    CMEventHandler m_handler;


+1 −1

File changed.

Contains only whitespace changes.