diff --git a/common/lib_tree_model.cpp b/common/lib_tree_model.cpp index b3e6e49b6a..1e79850620 100644 --- a/common/lib_tree_model.cpp +++ b/common/lib_tree_model.cpp @@ -92,7 +92,7 @@ void LIB_TREE_NODE::SortNodes() std::sort( m_Children.begin(), m_Children.end(), []( std::unique_ptr& a, std::unique_ptr& b ) { - return Compare( *a, *b ) > 0; + return Compare( *a, *b ); } ); for( std::unique_ptr& node: m_Children ) @@ -100,27 +100,38 @@ void LIB_TREE_NODE::SortNodes() } -int LIB_TREE_NODE::Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aNode2 ) +bool LIB_TREE_NODE::Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aNode2 ) { if( aNode1.m_Type != aNode2.m_Type ) - return 0; + return aNode1.m_Type < aNode2.m_Type; // Recently used sorts at top if( aNode1.m_Name.StartsWith( wxT( "-- " ) ) ) - return 1; + { + if( aNode2.m_Name.StartsWith( wxT( "-- " ) ) ) + { + return aNode1.m_IntrinsicRank > aNode2.m_IntrinsicRank; + } + else + { + return true; + } + } else if( aNode2.m_Name.StartsWith( wxT( "-- " ) ) ) - return 0; + { + return false; + } // Pinned nodes go next if( aNode1.m_Pinned && !aNode2.m_Pinned ) - return 1; + return true; else if( aNode2.m_Pinned && !aNode1.m_Pinned ) - return -1; + return false; - if( aNode1.m_Parent != aNode2.m_Parent ) - return 0; + if( aNode1.m_IntrinsicRank != aNode2.m_IntrinsicRank ) + return aNode1.m_IntrinsicRank > aNode2.m_IntrinsicRank; - return aNode1.m_IntrinsicRank - aNode2.m_IntrinsicRank; + return reinterpret_cast( &aNode1 ) < reinterpret_cast( &aNode2 ); } diff --git a/include/lib_tree_model.h b/include/lib_tree_model.h index fa9be1eff4..f8c7e1639b 100644 --- a/include/lib_tree_model.h +++ b/include/lib_tree_model.h @@ -101,10 +101,9 @@ public: void SortNodes(); /** - * Compare two nodes. Returns negative if aNode1 < aNode2, zero if aNode1 == - * aNode2, or positive if aNode1 > aNode2. + * Compare two nodes. Returns true if aNode1 < aNode2. */ - static int Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aNode2 ); + static bool Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aNode2 ); LIB_TREE_NODE(); virtual ~LIB_TREE_NODE() {}