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

Storing the selected item position from a context menu.

parent 3ce3d22b
...@@ -29,7 +29,7 @@ ...@@ -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() : ...@@ -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 ) ...@@ -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 )
{ {
......
...@@ -147,7 +147,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti ...@@ -147,7 +147,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti
st->pressed = true; st->pressed = true;
evt = TOOL_EVENT( TC_MOUSE, TA_MOUSE_DOWN, args ); evt = TOOL_EVENT( TC_MOUSE, TA_MOUSE_DOWN, args );
} }
else if( up ) // Handle mouse button release else if( up ) // Handle mouse button release
{ {
st->pressed = false; st->pressed = false;
......
...@@ -446,9 +446,12 @@ bool TOOL_MANAGER::ProcessEvent( TOOL_EVENT& aEvent ) ...@@ -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
TOOL_EVENT evt( TC_COMMAND, TA_CONTEXT_MENU_CHOICE ); if( menu->GetSelected() < 0 )
dispatchInternal( evt ); {
TOOL_EVENT evt( TC_COMMAND, TA_CONTEXT_MENU_CHOICE );
dispatchInternal( evt );
}
break; break;
} }
......
...@@ -78,6 +78,17 @@ public: ...@@ -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: ...@@ -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;
......
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