Commit c580a341 authored by Erwan Tulou's avatar Erwan Tulou

skins2: playlist, fix issues when deletion is at stake

This patch does the following
   - do not reset m_firstPosition when not needed
   - fix corner case when playlist is flat (prone to crash)
     The node with a single leaf being deleted should become the
     next leaf. But, actually just forcing the rtree.begin()
     in any case is simpler and no problem here.
parent fadb461f
...@@ -138,8 +138,6 @@ int CtrlTree::maxItems() ...@@ -138,8 +138,6 @@ int CtrlTree::maxItems()
void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree, void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree,
tree_update *arg ) tree_update *arg )
{ {
m_firstPos = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
if( arg->i_type == 0 ) // Item update if( arg->i_type == 0 ) // Item update
{ {
if( arg->b_active_item ) if( arg->b_active_item )
...@@ -152,6 +150,8 @@ void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree, ...@@ -152,6 +150,8 @@ void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree,
/// \todo handle delete in a more clever way /// \todo handle delete in a more clever way
else if ( arg->i_type == 1 ) // Global change or deletion else if ( arg->i_type == 1 ) // Global change or deletion
{ {
m_firstPos = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
makeImage(); makeImage();
} }
else if ( arg->i_type == 2 ) // Item-append else if ( arg->i_type == 2 ) // Item-append
...@@ -168,14 +168,15 @@ void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree, ...@@ -168,14 +168,15 @@ void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree,
else if( arg->i_type == 3 ) // item-del else if( arg->i_type == 3 ) // item-del
{ {
/* Make sure firstPos and lastSelected are still valid */ /* Make sure firstPos and lastSelected are still valid */
while( m_firstPos->m_deleted && m_firstPos != m_rTree.root()->begin() ) while( m_firstPos->m_deleted &&
m_firstPos != (m_flat ? m_rTree.firstLeaf()
: m_rTree.begin()) )
{ {
m_firstPos = m_flat ? m_rTree.getPrevLeaf( m_firstPos ) m_firstPos = m_flat ? m_rTree.getPrevLeaf( m_firstPos )
: m_rTree.getPrevVisibleItem( m_firstPos ); : m_rTree.getPrevVisibleItem( m_firstPos );
} }
if( m_firstPos->m_deleted ) if( m_firstPos->m_deleted )
m_firstPos = m_flat ? m_rTree.firstLeaf() m_firstPos = m_rTree.begin();
: m_rTree.root()->begin();
if( arg->b_visible == true ) if( arg->b_visible == true )
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment