From 651f50a26d52e64d90438c033af14669b52be1c0 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Sun, 10 Apr 2022 22:35:39 -0400 Subject: [PATCH] Change the behavior of ACTION_MENU::Add to require clones if required outside the function Fix https://gitlab.com/kicad/code/kicad/-/issues/10994 --- common/tool/action_menu.cpp | 11 +++++------ eeschema/menubar.cpp | 2 +- gerbview/menubar.cpp | 8 ++++---- kicad/menubar.cpp | 2 +- pagelayout_editor/menubar.cpp | 2 +- pcbnew/menubar_pcb_editor.cpp | 2 +- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/common/tool/action_menu.cpp b/common/tool/action_menu.cpp index 897709581b..ea4e0ca6e2 100644 --- a/common/tool/action_menu.cpp +++ b/common/tool/action_menu.cpp @@ -183,21 +183,20 @@ wxMenuItem* ACTION_MENU::Add( const TOOL_ACTION& aAction, bool aIsCheckmarkEntry wxMenuItem* ACTION_MENU::Add( ACTION_MENU* aMenu ) { - ACTION_MENU* menuCopy = aMenu->Clone(); - m_submenus.push_back( menuCopy ); + m_submenus.push_back( aMenu ); - wxASSERT_MSG( !menuCopy->m_title.IsEmpty(), wxT( "Set a title for ACTION_MENU using SetTitle()" ) ); + wxASSERT_MSG( !aMenu->m_title.IsEmpty(), wxT( "Set a title for ACTION_MENU using SetTitle()" ) ); if( !!aMenu->m_icon ) { - wxMenuItem* newItem = new wxMenuItem( this, -1, menuCopy->m_title ); + wxMenuItem* newItem = new wxMenuItem( this, -1, aMenu->m_title ); AddBitmapToMenuItem( newItem, KiBitmap( aMenu->m_icon ) ); - newItem->SetSubMenu( menuCopy ); + newItem->SetSubMenu( aMenu ); return Append( newItem ); } else { - return AppendSubMenu( menuCopy, menuCopy->m_title ); + return AppendSubMenu( aMenu, aMenu->m_title ); } } diff --git a/eeschema/menubar.cpp b/eeschema/menubar.cpp index 3843f615e8..bbea599815 100644 --- a/eeschema/menubar.cpp +++ b/eeschema/menubar.cpp @@ -72,7 +72,7 @@ void SCH_EDIT_FRAME::ReCreateMenuBar() fileMenu->Add( ACTIONS::doNew ); fileMenu->Add( ACTIONS::open ); - wxMenuItem* item = fileMenu->Add( openRecentMenu ); + wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() ); // Add the file menu condition here since it needs the item ID for the submenu ACTION_CONDITIONS cond; diff --git a/gerbview/menubar.cpp b/gerbview/menubar.cpp index c1985ccfc0..2adf7b6494 100644 --- a/gerbview/menubar.cpp +++ b/gerbview/menubar.cpp @@ -73,7 +73,7 @@ void GERBVIEW_FRAME::ReCreateMenuBar() } fileMenu->Add( GERBVIEW_ACTIONS::openGerber ); - wxMenuItem* gbrItem = fileMenu->Add( openRecentGbrMenu ); + wxMenuItem* gbrItem = fileMenu->Add( openRecentGbrMenu->Clone() ); RegisterUIUpdateHandler( gbrItem->GetId(), FileHistoryCond( recentGbrFiles) ); @@ -91,7 +91,7 @@ void GERBVIEW_FRAME::ReCreateMenuBar() } fileMenu->Add( GERBVIEW_ACTIONS::openDrillFile ); - wxMenuItem* drillItem = fileMenu->Add( openRecentDrlMenu ); + wxMenuItem* drillItem = fileMenu->Add( openRecentDrlMenu->Clone() ); RegisterUIUpdateHandler( drillItem->GetId(), FileHistoryCond( m_drillFileHistory ) ); @@ -109,7 +109,7 @@ void GERBVIEW_FRAME::ReCreateMenuBar() } fileMenu->Add( GERBVIEW_ACTIONS::openJobFile ); - wxMenuItem* jobItem = fileMenu->Add( openRecentJobMenu ); + wxMenuItem* jobItem = fileMenu->Add( openRecentJobMenu->Clone() ); RegisterUIUpdateHandler( jobItem->GetId(), FileHistoryCond( m_jobFileHistory ) ); @@ -127,7 +127,7 @@ void GERBVIEW_FRAME::ReCreateMenuBar() } fileMenu->Add( GERBVIEW_ACTIONS::openZipFile ); - wxMenuItem* zipItem = fileMenu->Add( openRecentZipMenu ); + wxMenuItem* zipItem = fileMenu->Add( openRecentZipMenu->Clone() ); RegisterUIUpdateHandler( zipItem->GetId(), FileHistoryCond( m_zipFileHistory ) ); #undef FileHistoryCond diff --git a/kicad/menubar.cpp b/kicad/menubar.cpp index 734753c131..4c4390e215 100644 --- a/kicad/menubar.cpp +++ b/kicad/menubar.cpp @@ -79,7 +79,7 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar() fileMenu->Add( KICAD_MANAGER_ACTIONS::openProject ); - wxMenuItem* item = fileMenu->Add( openRecentMenu ); + wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() ); // Add the file menu condition here since it needs the item ID for the submenu ACTION_CONDITIONS cond; diff --git a/pagelayout_editor/menubar.cpp b/pagelayout_editor/menubar.cpp index c4994daec2..80b7f5239d 100644 --- a/pagelayout_editor/menubar.cpp +++ b/pagelayout_editor/menubar.cpp @@ -68,7 +68,7 @@ void PL_EDITOR_FRAME::ReCreateMenuBar() fileMenu->Add( ACTIONS::doNew ); fileMenu->Add( ACTIONS::open ); - wxMenuItem* item = fileMenu->Add( openRecentMenu ); + wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() ); // Add the file menu condition here since it needs the item ID for the submenu ACTION_CONDITIONS cond; diff --git a/pcbnew/menubar_pcb_editor.cpp b/pcbnew/menubar_pcb_editor.cpp index e34cc02c03..c6bda35868 100644 --- a/pcbnew/menubar_pcb_editor.cpp +++ b/pcbnew/menubar_pcb_editor.cpp @@ -74,7 +74,7 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() fileMenu->Add( ACTIONS::doNew ); fileMenu->Add( ACTIONS::open ); - wxMenuItem* item = fileMenu->Add( openRecentMenu ); + wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() ); // Add the file menu condition here since it needs the item ID for the submenu ACTION_CONDITIONS cond;