diff --git a/common/rc_item.cpp b/common/rc_item.cpp index 423cee7619..a007c135fc 100644 --- a/common/rc_item.cpp +++ b/common/rc_item.cpp @@ -525,6 +525,7 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo /// Keep a vector of elements to free after wxWidgets is definitely done accessing them std::vector to_delete; + std::vector expanded; if( aCurrentOnly && !current_item ) { @@ -532,6 +533,17 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo return; } + // wxWidgets 3.1.x on MacOS (at least) loses the expanded state of the tree when deleting + // items. + if( m_view && aCurrentOnly ) + { + for( RC_TREE_NODE* node : m_tree ) + { + if( m_view->IsExpanded( ToItem( node ) ) ) + expanded.push_back( node ); + } + } + int lastGood = -1; bool itemDeleted = false; @@ -597,7 +609,23 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo } if( m_view && aCurrentOnly && lastGood >= 0 ) - m_view->Select( ToItem( m_tree[ lastGood ] ) ); + { + for( RC_TREE_NODE* node : expanded ) + { + wxDataViewItem item = ToItem( node ); + + if( item.IsOk() ) + m_view->Expand( item ); + } + + wxDataViewItem selItem = ToItem( m_tree[ lastGood ] ); + m_view->Select( selItem ); + + // wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED doesn't get propogated from the Select() + // call on (at least) MSW. + wxDataViewEvent selectEvent( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, m_view, selItem ); + m_view->ProcessCommand( selectEvent ); + } for( RC_TREE_NODE* item : to_delete ) delete( item );