Commit d9cdd294 authored by Erwan Tulou's avatar Erwan Tulou

skins2: use enum type for better clarity

parent fd930cde
...@@ -140,21 +140,24 @@ int CtrlTree::maxItems() ...@@ -140,21 +140,24 @@ 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 )
{ {
if( arg->i_type == 0 ) // Item update if( arg->type == arg->UpdateItem ) // Item update
{ {
if( arg->b_active_item ) if( arg->b_active_item )
autoScroll(); autoScroll();
makeImage(); if( isItemVisible( arg->i_id ) )
notifyLayout(); {
makeImage();
notifyLayout();
}
} }
else if ( arg->i_type == 1 ) // Global change or deletion else if ( arg->type == arg->ResetAll ) // Global change or deletion
{ {
m_firstPos = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); m_firstPos = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
makeImage(); makeImage();
notifyLayout(); notifyLayout();
} }
else if ( arg->i_type == 2 ) // Item-append else if ( arg->type == arg->AppendItem ) // Item-append
{ {
if( m_flat && m_firstPos->size() ) if( m_flat && m_firstPos->size() )
{ {
...@@ -169,7 +172,7 @@ void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree, ...@@ -169,7 +172,7 @@ void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree,
notifyLayout(); notifyLayout();
} }
} }
else if( arg->i_type == 3 ) // item-del else if( arg->type == arg->DeleteItem ) // item-del
{ {
/* Make sure firstPos is valid */ /* Make sure firstPos is valid */
VarTree::Iterator it_old = m_firstPos; VarTree::Iterator it_old = m_firstPos;
......
...@@ -35,9 +35,18 @@ ...@@ -35,9 +35,18 @@
/// Description of an update to the tree /// Description of an update to the tree
typedef struct tree_update typedef struct tree_update
{ {
int i_type; enum type_t
int i_id; {
bool b_active_item; UpdateItem,
AppendItem,
DeleteItem,
ResetAll,
};
enum type_t type;
int i_id;
bool b_active_item;
} tree_update; } tree_update;
/// Tree variable /// Tree variable
......
...@@ -57,7 +57,7 @@ void Playtree::delSelected() ...@@ -57,7 +57,7 @@ void Playtree::delSelected()
} }
/// \todo Do this better (handle item-deleted) /// \todo Do this better (handle item-deleted)
tree_update descr; tree_update descr;
descr.i_type = 3; descr.type = tree_update::DeleteItem;
notify( &descr ); notify( &descr );
it = begin(); it = begin();
while( it != end() ) while( it != end() )
...@@ -114,7 +114,7 @@ void Playtree::onChange() ...@@ -114,7 +114,7 @@ void Playtree::onChange()
{ {
buildTree(); buildTree();
tree_update descr; tree_update descr;
descr.i_type = 1; descr.type = tree_update::ResetAll;
notify( &descr ); notify( &descr );
} }
...@@ -129,7 +129,7 @@ void Playtree::onUpdateItem( int id ) ...@@ -129,7 +129,7 @@ void Playtree::onUpdateItem( int id )
it->setString( UStringPtr( pName ) ); it->setString( UStringPtr( pName ) );
tree_update descr; tree_update descr;
descr.i_type = 0; descr.type = tree_update::UpdateItem;
descr.i_id = id; descr.i_id = id;
descr.b_active_item = false; descr.b_active_item = false;
notify( &descr ); notify( &descr );
...@@ -149,7 +149,7 @@ void Playtree::onUpdateCurrent( bool b_active ) ...@@ -149,7 +149,7 @@ void Playtree::onUpdateCurrent( bool b_active )
it->setPlaying( false ); it->setPlaying( false );
tree_update descr; tree_update descr;
descr.i_type = 0; descr.type = tree_update::UpdateItem;
descr.i_id = it->getId(); descr.i_id = it->getId();
descr.b_active_item = false; descr.b_active_item = false;
notify( &descr ); notify( &descr );
...@@ -175,7 +175,7 @@ void Playtree::onUpdateCurrent( bool b_active ) ...@@ -175,7 +175,7 @@ void Playtree::onUpdateCurrent( bool b_active )
playlist_Unlock( m_pPlaylist ); playlist_Unlock( m_pPlaylist );
tree_update descr; tree_update descr;
descr.i_type = 0; descr.type = tree_update::UpdateItem;
descr.i_id = current->i_id; descr.i_id = current->i_id;
descr.b_active_item = true; descr.b_active_item = true;
notify( &descr ); notify( &descr );
...@@ -192,7 +192,7 @@ void Playtree::onDelete( int i_id ) ...@@ -192,7 +192,7 @@ void Playtree::onDelete( int i_id )
item->setDeleted( true ); item->setDeleted( true );
tree_update descr; tree_update descr;
descr.i_type = 3; descr.type = tree_update::DeleteItem;
descr.i_id = i_id; descr.i_id = i_id;
notify( &descr ); notify( &descr );
...@@ -223,7 +223,7 @@ void Playtree::onAppend( playlist_add_t *p_add ) ...@@ -223,7 +223,7 @@ void Playtree::onAppend( playlist_add_t *p_add )
playlist_Unlock( m_pPlaylist ); playlist_Unlock( m_pPlaylist );
tree_update descr; tree_update descr;
descr.i_type = 2; descr.type = tree_update::AppendItem;
descr.i_id = p_add->i_item; descr.i_id = p_add->i_item;
notify( &descr ); notify( &descr );
} }
......
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