Commit 8bb5eaa4 authored by Maciej Suminski's avatar Maciej Suminski

Better way of adding CONTEXT_MENU entries.

parent 1cbf03cb
......@@ -101,17 +101,28 @@ void CONTEXT_MENU::Add( const TOOL_ACTION& aAction )
{
/// ID numbers for tool actions need to have a value higher than m_actionId
int id = m_actionId + aAction.GetId();
wxString menuEntry;
wxMenuItem* item = new wxMenuItem( &m_menu, id,
wxString( aAction.GetMenuItem().c_str(), wxConvUTF8 ),
wxString( aAction.GetDescription().c_str(), wxConvUTF8 ), wxITEM_NORMAL );
if( aAction.HasHotKey() )
menuEntry = wxString( ( aAction.GetMenuItem() + '\t' +
getHotKeyDescription( aAction ) ).c_str(), wxConvUTF8 );
else
menuEntry = wxString( aAction.GetMenuItem().c_str(), wxConvUTF8 );
{
int key = aAction.GetHotKey() & ~MD_MODIFIER_MASK;
int mod = aAction.GetHotKey() & MD_MODIFIER_MASK;
wxAcceleratorEntryFlags flags = wxACCEL_NORMAL;
m_menu.Append( new wxMenuItem( &m_menu, id, menuEntry,
wxString( aAction.GetDescription().c_str(), wxConvUTF8 ), wxITEM_NORMAL ) );
switch( mod )
{
case MD_ALT: flags = wxACCEL_ALT; break;
case MD_CTRL: flags = wxACCEL_CTRL; break;
case MD_SHIFT: flags = wxACCEL_SHIFT; break;
}
item->SetAccel( new wxAcceleratorEntry( flags, key, id, item ) );
}
m_menu.Append( item );
m_toolActions[id] = &aAction;
}
......@@ -128,28 +139,6 @@ void CONTEXT_MENU::Clear()
}
std::string CONTEXT_MENU::getHotKeyDescription( const TOOL_ACTION& aAction ) const
{
int hotkey = aAction.GetHotKey();
std::string description = "";
if( hotkey & MD_ALT )
description += "ALT+";
if( hotkey & MD_CTRL )
description += "CTRL+";
if( hotkey & MD_SHIFT )
description += "SHIFT+";
// TODO dispatch keys such as Fx, TAB, PG_UP/DN, HOME, END, etc.
description += char( hotkey & ~MD_MODIFIER_MASK );
return description;
}
void CONTEXT_MENU::CMEventHandler::onEvent( wxEvent& aEvent )
{
TOOL_EVENT evt;
......
......@@ -128,14 +128,6 @@ private:
m_tool = aTool;
}
/**
* Function getHotKeyDescription()
* Returns a hot key in the string format accepted by wxMenu.
* @param aAction is the action with hot key to be translated..
* @return Hot key in the string format compatible with wxMenu.
*/
std::string getHotKeyDescription( const TOOL_ACTION& aAction ) const;
///> Flag indicating that the menu title was set up.
bool m_titleSet;
......
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