diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index dc1e1b2837..2dc4688772 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -5798,23 +5798,37 @@ void wxPropertyGrid::OnIdle( wxIdleEvent& WXUNUSED(event) ) // // Resolve pending property removals - if ( m_deletedProperties.size() > 0 ) + // In order to determine whether deletion/removal + // was done we need to track the size of the list + // before and after the operation. + // (Note that lists are changed at every operation.) + size_t cntAfter = m_deletedProperties.size(); + while ( cntAfter > 0 ) { - wxArrayPGProperty& arr = m_deletedProperties; - for ( unsigned int i=0; i= cntBefore ) + break; } - if ( m_removedProperties.size() > 0 ) + cntAfter = m_removedProperties.size(); + while ( cntAfter > 0 ) { - wxArrayPGProperty& arr = m_removedProperties; - for ( unsigned int i=0; i= cntBefore ) + break; } } diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index c5f5789a29..4c8f482fa8 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -1964,9 +1964,40 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) // We can actually delete it now if ( doDelete ) + { + // Remove the item from both lists of pending operations. + // (Deleted item cannot be also the subject of further removal.) + int index = pg->m_deletedProperties.Index(item); + if ( index != wxNOT_FOUND ) + { + pg->m_deletedProperties.RemoveAt(index); + } + wxASSERT_MSG( pg->m_deletedProperties.Index(item) == wxNOT_FOUND, + wxT("Too many occurences of the item")); + + index = pg->m_removedProperties.Index(item); + if ( index != wxNOT_FOUND ) + { + pg->m_removedProperties.RemoveAt(index); + } + wxASSERT_MSG( pg->m_removedProperties.Index(item) == wxNOT_FOUND, + wxT("Too many occurences of the item")); + delete item; + } else + { + // Remove the item from the list of pending removals. + int index = pg->m_removedProperties.Index(item); + if ( index != wxNOT_FOUND ) + { + pg->m_removedProperties.RemoveAt(index); + } + wxASSERT_MSG( pg->m_removedProperties.Index(item) == wxNOT_FOUND, + wxT("Too many occurences of the item")); + item->OnDetached(this, pg); + } m_itemsAdded = 1; // Not a logical assignment (but required nonetheless).