diff --git a/include/wx/propgrid/propgridpagestate.h b/include/wx/propgrid/propgridpagestate.h index 4218f1f90b..6ffafbd5c1 100644 --- a/include/wx/propgrid/propgridpagestate.h +++ b/include/wx/propgrid/propgridpagestate.h @@ -714,6 +714,10 @@ protected: */ void DoInvalidateChildrenNames(wxPGProperty* p, bool recursive); + /** Check if property contains given sub-category */ + bool IsChildCategory(wxPGProperty* p, + wxPropertyCategory* cat, bool recursive); + /** If visible, then this is pointer to wxPropertyGrid. This shall *never* be NULL to indicate that this state is not visible. */ diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index 25edfe733e..a211ea7164 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -1926,6 +1926,31 @@ void wxPropertyGridPageState::DoInvalidateChildrenNames(wxPGProperty* p, } } +bool wxPropertyGridPageState::IsChildCategory(wxPGProperty* p, + wxPropertyCategory* cat, + bool recursive) +{ + if (p->IsCategory()) + { + for( unsigned int i = 0; i < p->GetChildCount(); i++ ) + { + wxPGProperty* child = p->Item(i); + + if (child->IsCategory() && child == cat) + { + return true; + } + + if ( recursive && IsChildCategory(child, cat, recursive) ) + { + return true; + } + } + } + + return false; +} + void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) { wxCHECK_RET( item->GetParent(), @@ -1963,6 +1988,16 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) wxPG_SEL_DELETING|wxPG_SEL_NOVALIDATE); } + // If deleted category or its sub-category is + // a current category then reset current category marker. + if ( item->IsCategory() ) + { + if (item == m_currentCategory || IsChildCategory(item, m_currentCategory, true)) + { + m_currentCategory = NULL; + } + } + // Must defer deletion? Yes, if handling a wxPG event. if ( pg && pg->m_processedEvent ) { @@ -1994,6 +2029,9 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) // Otherwise crash can happen. wxASSERT_MSG( !DoIsPropertySelected(item) && !item->IsChildSelected(true), wxT("Failed to unselect deleted property") ); + // Don't attempt to delete current category. + wxASSERT_MSG( !item->IsCategory() || item != m_currentCategory, + wxT("Current category cannot be deleted") ); // Prevent property and its children from being re-selected item->SetFlag(wxPG_PROP_BEING_DELETED); @@ -2001,18 +2039,10 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) unsigned int indinparent = item->GetIndexInParent(); - wxPGProperty* pwc = (wxPGProperty*)item; - // Delete children if ( item->GetChildCount() && !item->HasFlag(wxPG_PROP_AGGREGATE) ) { // deleting a category - if ( item->IsCategory() ) - { - if ( pwc == m_currentCategory ) - m_currentCategory = NULL; - } - item->DeleteChildren(); }