diff --git a/include/wx/propgrid/propgrid.h b/include/wx/propgrid/propgrid.h index 2d744fe7c9..cda343f9f3 100644 --- a/include/wx/propgrid/propgrid.h +++ b/include/wx/propgrid/propgrid.h @@ -1808,6 +1808,10 @@ protected: /** Appearance of a unspecified value cell. */ wxPGCell m_unspecifiedAppearance; + /** List of properties to be deleted/removed in idle event handler. */ + wxArrayPGProperty m_deletedProperties; + wxArrayPGProperty m_removedProperties; + // // Temporary values // diff --git a/include/wx/propgrid/propgridiface.h b/include/wx/propgrid/propgridiface.h index a79f2a93b2..7b4041b4ca 100644 --- a/include/wx/propgrid/propgridiface.h +++ b/include/wx/propgrid/propgridiface.h @@ -240,18 +240,34 @@ public: bool ChangePropertyValue( wxPGPropArg id, wxVariant newValue ); /** - Deletes a property by id. If category is deleted, all children are - automatically deleted as well. - */ + Removes and deletes a property and any children. + + @param id + Pointer or name of a property. + + @remarks If you delete a property in a wxPropertyGrid event + handler, the actual deletion is postponed until the next + idle event. + + This functions deselects selected property, if any. + Validation failure option wxPG_VFB_STAY_IN_PROPERTY is not + respected, ie. selection is cleared even if editor had + invalid value. + */ void DeleteProperty( wxPGPropArg id ); /** - Removes and returns a property. + Removes a property. Does not delete the property object, but + instead returns it. @param id Pointer or name of a property. @remarks Removed property cannot have any children. + + Also, if you remove property in a wxPropertyGrid event + handler, the actual removal is postponed until the next + idle event. */ wxPGProperty* RemoveProperty( wxPGPropArg id ); diff --git a/interface/wx/propgrid/propgridiface.h b/interface/wx/propgrid/propgridiface.h index c8bdd55707..efd9067b68 100644 --- a/interface/wx/propgrid/propgridiface.h +++ b/interface/wx/propgrid/propgridiface.h @@ -135,11 +135,19 @@ public: bool ChangePropertyValue( wxPGPropArg id, wxVariant newValue ); /** - Deletes a property. + Removes and deletes a property and any children. - @remarks This functions deselects selected property, if any. Validation - failure option wxPG_VFB_STAY_IN_PROPERTY is not respected, ie. - selection is cleared even if editor had invalid value. + @param id + Pointer or name of a property. + + @remarks If you delete a property in a wxPropertyGrid event + handler, the actual deletion is postponed until the next + idle event. + + This functions deselects selected property, if any. + Validation failure option wxPG_VFB_STAY_IN_PROPERTY is not + respected, ie. selection is cleared even if editor had + invalid value. */ void DeleteProperty( wxPGPropArg id ); @@ -589,12 +597,17 @@ public: static void RegisterAdditionalEditors(); /** - Removes and returns a property. + Removes a property. Does not delete the property object, but + instead returns it. @param id Pointer or name of a property. @remarks Removed property cannot have any children. + + Also, if you remove property in a wxPropertyGrid event + handler, the actual removal is postponed until the next + idle event. */ wxPGProperty* RemoveProperty( wxPGPropArg id ); diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index ee5e0e92e3..389e7a88f2 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -4535,9 +4535,10 @@ bool wxPropertyGrid::SendEvent( int eventType, wxPGProperty* p, evt.SetCanVeto(true); } + wxPropertyGridEvent* prevProcessedEvent = m_processedEvent; m_processedEvent = &evt; m_eventObject->HandleWindowEvent(evt); - m_processedEvent = NULL; + m_processedEvent = prevProcessedEvent; return evt.WasVetoed(); } @@ -5639,6 +5640,27 @@ void wxPropertyGrid::OnIdle( wxIdleEvent& WXUNUSED(event) ) if ( tlp != m_tlp ) OnTLPChanging(tlp); } + + // + // Resolve pending property removals + if ( m_deletedProperties.size() > 0 ) + { + wxArrayPGProperty& arr = m_deletedProperties; + for ( unsigned int i=0; i 0 ) + { + wxArrayPGProperty& arr = m_removedProperties; + for ( unsigned int i=0; im_processedEvent ) + { + if ( doDelete ) + pg->m_deletedProperties.push_back(item); + else + pg->m_removedProperties.push_back(item); + return; + } + unsigned int indinparent = item->GetIndexInParent(); wxPGProperty* pwc = (wxPGProperty*)item; @@ -1867,8 +1879,6 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) wxASSERT( item->GetParentState() == this ); - wxPropertyGrid* pg = GetGrid(); - if ( DoIsPropertySelected(item) ) { if ( pg && pg->GetState() == this )