From 1bcbbb41cd1e036443c922e174538431a801f69d Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 9 Feb 2017 23:25:58 +0100 Subject: [PATCH] Fixed double menu entries in context menus --- common/tool/context_menu.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/common/tool/context_menu.cpp b/common/tool/context_menu.cpp index 9211ea8ae8..0a54162c3f 100644 --- a/common/tool/context_menu.cpp +++ b/common/tool/context_menu.cpp @@ -61,8 +61,8 @@ void CONTEXT_MENU::setupEvents() void CONTEXT_MENU::SetTitle( const wxString& aTitle ) { - // Unfortunately wxMenu::SetTitle() does nothing, but saves the title.. (at least wxGTK) - wxMenu::SetTitle( aTitle ); + // Unfortunately wxMenu::SetTitle() does not work very well, so this is an alternative version + m_title = aTitle; // Update the menu title if( m_titleDisplayed ) @@ -72,29 +72,31 @@ void CONTEXT_MENU::SetTitle( const wxString& aTitle ) void CONTEXT_MENU::DisplayTitle( bool aDisplay ) { - const wxString& title = wxMenu::GetTitle(); - - if( ( !aDisplay || title.IsEmpty() ) && m_titleDisplayed ) + if( ( !aDisplay || m_title.IsEmpty() ) && m_titleDisplayed ) { // Destroy the menu entry keeping the title.. - Destroy( FindItemByPosition( 0 ) ); + wxMenuItem* item = FindItemByPosition( 0 ); + wxASSERT( item->GetLabel() == GetTitle() ); + Destroy( item ); // ..and separator - Destroy( FindItemByPosition( 0 ) ); + item = FindItemByPosition( 0 ); + wxASSERT( item->IsSeparator() ); + Destroy( item ); m_titleDisplayed = false; } - else if( aDisplay && !title.IsEmpty() ) + else if( aDisplay && !m_title.IsEmpty() ) { if( m_titleDisplayed ) { // Simply update the title - FindItemByPosition( 0 )->SetItemLabel( title ); + FindItemByPosition( 0 )->SetItemLabel( m_title ); } else { // Add a separator and a menu entry to display the title InsertSeparator( 0 ); - Insert( 0, new wxMenuItem( this, wxID_NONE, title, wxEmptyString, wxITEM_NORMAL ) ); + Insert( 0, new wxMenuItem( this, wxID_NONE, m_title, wxEmptyString, wxITEM_NORMAL ) ); m_titleDisplayed = true; } } @@ -152,18 +154,18 @@ std::list CONTEXT_MENU::Add( CONTEXT_MENU* aMenu, bool aExpand ) } else { - wxASSERT_MSG( !menuCopy->GetTitle().IsEmpty(), "Set a title for CONTEXT_MENU using SetTitle()" ); + wxASSERT_MSG( !menuCopy->m_title.IsEmpty(), "Set a title for CONTEXT_MENU using SetTitle()" ); if( aMenu->m_icon ) { - wxMenuItem* newItem = new wxMenuItem( this, -1, menuCopy->GetTitle() ); + wxMenuItem* newItem = new wxMenuItem( this, -1, menuCopy->m_title ); newItem->SetBitmap( KiBitmap( aMenu->m_icon ) ); newItem->SetSubMenu( menuCopy ); items.push_back( Append( newItem ) ); } else { - items.push_back( AppendSubMenu( menuCopy, menuCopy->GetTitle() ) ); + items.push_back( AppendSubMenu( menuCopy, menuCopy->m_title ) ); } } @@ -380,14 +382,14 @@ OPT_TOOL_EVENT CONTEXT_MENU::findToolAction( int aId ) void CONTEXT_MENU::copyFrom( const CONTEXT_MENU& aMenu ) { - SetTitle( aMenu.GetTitle() ); m_icon = aMenu.m_icon; + m_title = aMenu.m_title; m_titleDisplayed = aMenu.m_titleDisplayed; m_selected = -1; // aMenu.m_selected; m_tool = aMenu.m_tool; m_toolActions = aMenu.m_toolActions; - // Copy all the menu entries + // Copy all menu entries for( int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i ) { wxMenuItem* item = aMenu.FindItemByPosition( i );