X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/433969811ec21a6036347f1be157e08f8f4720ec..8a2e3f80f67b0716b3d1854418b187943dcff11a:/src/propgrid/propgridpagestate.cpp diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index db836d605d..0803b12037 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -635,16 +635,21 @@ static int wxPG_SortFunc_ByLabel(wxPGProperty **pp1, wxPGProperty **pp2) #endif void wxPropertyGridPageState::DoSortChildren( wxPGProperty* p, - bool recursively ) + int flags ) { if ( !p ) p = m_properties; + // Can only sort items with children if ( !p->GetChildCount() ) return; - // Can only sort items with children - if ( p->GetChildCount() < 1 ) + // Never sort children of aggregate properties + if ( p->HasFlag(wxPG_PROP_AGGREGATE) ) + return; + + if ( (flags & wxPG_SORT_TOP_LEVEL_ONLY) + && !p->IsCategory() && !p->IsRoot() ) return; #if wxUSE_STL @@ -661,35 +666,52 @@ void wxPropertyGridPageState::DoSortChildren( wxPGProperty* p, p->m_children.Sort( wxPG_SortFunc_ByLabel ); #endif - // Fix indexes + // Fix indices p->FixIndicesOfChildren(); - if ( recursively && !p->HasFlag(wxPG_PROP_AGGREGATE) ) + if ( flags & wxPG_RECURSE ) { + // Apply sort recursively for ( unsigned int i=0; iGetChildCount(); i++ ) - DoSortChildren(p->Item(i)); + DoSortChildren(p->Item(i), flags); } } // ----------------------------------------------------------------------- -void wxPropertyGridPageState::DoSort() +void wxPropertyGridPageState::DoSort( int flags ) { - DoSortChildren( m_properties, true ); + DoSortChildren( m_properties, flags | wxPG_RECURSE ); // Sort categories as well (but we need not do it recursively) - if ( !IsInNonCatMode() ) + if ( IsInNonCatMode() ) { size_t i; - for ( i=0;iGetChildCount();i++) + for ( i=0;iItem(i); + wxPGProperty* p = m_regularArray.Item(i); if ( p->IsCategory() ) - DoSortChildren( p ); + DoSortChildren( p, 0 ); } } } +// ----------------------------------------------------------------------- + +bool wxPropertyGridPageState::PrepareAfterItemsAdded() +{ + if ( !m_itemsAdded ) return false; + + wxPropertyGrid* pg = GetGrid(); + + m_itemsAdded = 0; + + if ( pg->HasFlag(wxPG_AUTO_SORT) ) + DoSort(wxPG_SORT_TOP_LEVEL_ONLY); + + return true; +} + // ----------------------------------------------------------------------- // wxPropertyGridPageState splitter, column and hittest functions // -----------------------------------------------------------------------