From 668674c1e2301c2bc946c3fe3936599fd269d4fe Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 19 Feb 2009 20:18:53 +0000 Subject: [PATCH] If a selected item is about to be deleted, try to select the next one first, otherwise the parent, like the wxMSW does git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59035 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/treectlg.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index ca183a7905..393231673c 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -1775,6 +1775,16 @@ void wxGenericTreeCtrl::Delete(const wxTreeItemId& itemId) } wxGenericTreeItem *parent = item->GetParent(); + + // if the selected item will be deleted, select the parent ... + wxGenericTreeItem *to_be_selected = parent; + if (parent) + { + // .. unless there is a next sibling like wxMSW does it + int pos = parent->GetChildren().Index( item ); + if ((int)(parent->GetChildren().GetCount()) > pos+1) + to_be_selected = parent->GetChildren().Item( pos+1 ); + } // don't keep stale pointers around! if ( IsDescendantOf(item, m_key_current) ) @@ -1791,7 +1801,7 @@ void wxGenericTreeCtrl::Delete(const wxTreeItemId& itemId) // a different item, in idle time. if ( m_select_me && IsDescendantOf(item, m_select_me) ) { - m_select_me = parent; + m_select_me = to_be_selected; } if ( IsDescendantOf(item, m_current) ) @@ -1802,7 +1812,7 @@ void wxGenericTreeCtrl::Delete(const wxTreeItemId& itemId) // m_current = parent; m_current = NULL; - m_select_me = parent; + m_select_me = to_be_selected; } // remove the item from the tree -- 2.45.2