From 96c8d995dd29b56b6e9b6f71f149ab90d17bba79 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 17 Jun 2025 23:00:47 +0100 Subject: [PATCH] Don't reset current tool in group when rebuilding toolbars. Fixes https://gitlab.com/kicad/code/kicad/-/issues/21125 --- common/tool/action_toolbar.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/common/tool/action_toolbar.cpp b/common/tool/action_toolbar.cpp index c78149b8a2..5f36808c78 100644 --- a/common/tool/action_toolbar.cpp +++ b/common/tool/action_toolbar.cpp @@ -263,6 +263,14 @@ void ACTION_TOOLBAR::ApplyConfiguration( const TOOLBAR_CONFIGURATION& aConfig ) { wxASSERT( GetParent() ); + std::map currentGroupItems; + + for( const auto& [id, group] : m_actionGroups ) + { + if( m_toolActions[group->GetUIId()] ) + currentGroupItems[group->GetName()] = m_toolActions[group->GetUIId()]->GetName(); + } + // Remove existing tools ClearToolbar(); @@ -284,9 +292,11 @@ void ACTION_TOOLBAR::ApplyConfiguration( const TOOLBAR_CONFIGURATION& aConfig ) case TOOLBAR_ITEM_TYPE::TB_GROUP: { // Add a group of items to the toolbar + std::string groupName = item.m_GroupName.ToStdString(); std::vector tools; + const TOOL_ACTION* defaultTool = nullptr; - for( auto& groupItem : item.m_GroupItems ) + for( TOOLBAR_ITEM& groupItem : item.m_GroupItems ) { switch( groupItem.m_Type ) { @@ -294,7 +304,7 @@ void ACTION_TOOLBAR::ApplyConfiguration( const TOOLBAR_CONFIGURATION& aConfig ) case TOOLBAR_ITEM_TYPE::SPACER: case TOOLBAR_ITEM_TYPE::TB_GROUP: case TOOLBAR_ITEM_TYPE::CONTROL: - wxASSERT_MSG( false, "Unsupported group item type" ); + wxFAIL_MSG( wxT( "Unsupported group item type" ) ); continue; case TOOLBAR_ITEM_TYPE::TOOL: @@ -302,15 +312,23 @@ void ACTION_TOOLBAR::ApplyConfiguration( const TOOLBAR_CONFIGURATION& aConfig ) if( !grpAction ) { - wxASSERT_MSG( false, wxString::Format( "Unable to find group tool %s", groupItem.m_ActionName ) ); + wxFAIL_MSG( wxString::Format( wxT( "Unable to find group tool %s" ), groupItem.m_ActionName ) ); continue; } tools.push_back( grpAction ); + + if( currentGroupItems[groupName] == groupItem.m_ActionName ) + defaultTool = grpAction; } } - AddGroup( std::make_unique( item.m_GroupName.ToStdString(), tools ) ); + std::unique_ptr group = std::make_unique( groupName, tools ); + + if( defaultTool ) + group->SetDefaultAction( *defaultTool ); + + AddGroup( std::move( group ) ); break; } @@ -322,7 +340,7 @@ void ACTION_TOOLBAR::ApplyConfiguration( const TOOLBAR_CONFIGURATION& aConfig ) if( !factory ) { - wxASSERT_MSG( false, wxString::Format( "Unable to find control factory for %s", item.m_ControlName ) ); + wxFAIL_MSG( wxString::Format( wxT( "Unable to find control factory for %s" ), item.m_ControlName ) ); continue; } @@ -337,7 +355,7 @@ void ACTION_TOOLBAR::ApplyConfiguration( const TOOLBAR_CONFIGURATION& aConfig ) if( !action ) { - wxASSERT_MSG( false, wxString::Format( "Unable to find toolbar tool %s", item.m_ActionName ) ); + wxFAIL_MSG( wxString::Format( wxT( "Unable to find toolbar tool %s" ), item.m_ActionName ) ); continue; }