Keep children of collapsed item selected in wxGenericTreeCtrl

Collapsing a branch shouldn't deselect all the items under it in
multi-selection mode: this doesn't seem to be useful or otherwise make
sense and makes the generic version gratuitously incompatible with the
native MSW one.

Closes #10239.

Closes https://github.com/wxWidgets/wxWidgets/pull/1581
This commit is contained in:
Vadim Zeitlin
2019-10-01 00:06:03 +02:00
parent 239f045a3f
commit 73cab0bd4e
2 changed files with 13 additions and 1 deletions

View File

@@ -1752,6 +1752,9 @@ void wxGenericTreeCtrl::ChildrenClosing(wxGenericTreeItem* item)
if ( item != m_current && IsDescendantOf(item, m_current) ) if ( item != m_current && IsDescendantOf(item, m_current) )
{ {
// Don't leave the only selected item invisible, but do leave selected
// items selected if we can have many of them.
if ( !HasFlag(wxTR_MULTIPLE) )
m_current->SetHilight( false ); m_current->SetHilight( false );
m_current = NULL; m_current = NULL;
m_select_me = item; m_select_me = item;

View File

@@ -244,6 +244,15 @@ void TreeCtrlTestCase::SelectItemMulti()
m_tree->UnselectItem(m_child1); m_tree->UnselectItem(m_child1);
CPPUNIT_ASSERT( !m_tree->IsSelected(m_child1) ); CPPUNIT_ASSERT( !m_tree->IsSelected(m_child1) );
CPPUNIT_ASSERT( m_tree->IsSelected(m_child2) ); CPPUNIT_ASSERT( m_tree->IsSelected(m_child2) );
// collapsing a branch with selected items should still leave them selected
m_tree->Expand(m_child1);
m_tree->SelectItem(m_grandchild);
CHECK( m_tree->IsSelected(m_grandchild) );
m_tree->Collapse(m_child1);
CHECK( m_tree->IsSelected(m_grandchild) );
m_tree->Expand(m_child1);
CHECK( m_tree->IsSelected(m_grandchild) );
} }
void TreeCtrlTestCase::ItemClick() void TreeCtrlTestCase::ItemClick()