src/playlist/*:give id to nodes as well. triger item-delete variable on item

deletion (not intf-change)
modules/gui/wxwindows/*: clever item deletion using item-deleted
parent 48ad6e8d
......@@ -57,6 +57,8 @@ static int ItemChanged( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * );
static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t oval, vlc_value_t nval, void *param );
static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t oval, vlc_value_t nval, void *param );
/*****************************************************************************
......@@ -103,6 +105,7 @@ enum
/* custom events */
UpdateItem_Event,
AppendItem_Event,
RemoveItem_Event,
MenuDummy_Event = wxID_HIGHEST + 999,
......@@ -178,9 +181,11 @@ public:
PlaylistItem( playlist_item_t *_p_item ) : wxTreeItemData()
{
p_item = _p_item;
i_id = p_item->input.i_id;
}
protected:
playlist_item_t *p_item;
int i_id;
friend class Playlist;
};
......@@ -378,6 +383,7 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
var_AddCallback( p_playlist, "item-change", ItemChanged, this );
var_AddCallback( p_playlist, "item-append", ItemAppended, this );
var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
vlc_object_release( p_playlist );
......@@ -399,6 +405,7 @@ Playlist::~Playlist()
var_DelCallback( p_playlist, "item-change", ItemChanged, this );
var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
vlc_object_release( p_playlist );
}
......@@ -625,6 +632,17 @@ void Playlist::UpdateItem( int i )
vlc_object_release(p_playlist);
}
void Playlist::RemoveItem( int i )
{
if( i <= 0 ) return; /* Sanity check */
wxTreeItemId item = FindItem( treectrl->GetRootItem(), i );
if( item.IsOk() )
{
treectrl->Delete( item );
}
}
/**********************************************************************
......@@ -642,27 +660,76 @@ wxTreeItemId Playlist::FindItem( wxTreeItemId root, playlist_item_t *p_item )
p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( root );
if( !p_item )
{
wxTreeItemId dummy;
return dummy;
}
if( p_wxcurrent->p_item == p_item )
{
return root;
}
if( !p_item )
while( item.IsOk() )
{
p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( item );
if( p_wxcurrent->p_item == p_item )
{
return item;
}
if( treectrl->ItemHasChildren( item ) )
{
wxTreeItemId search = FindItem( item, p_item );
if( search.IsOk() )
{
return search;
}
}
item = treectrl->GetNextChild( root, cookie );
}
/* Not found */
wxTreeItemId dummy;
return dummy;
}
/* Find a wxItem from a playlist id */
wxTreeItemId Playlist::FindItem( wxTreeItemId root, int i_id )
{
long cookie;
PlaylistItem *p_wxcurrent;
wxTreeItemId search;
wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
wxTreeItemId child;
p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( root );
if( i_id < 0 )
{
wxTreeItemId dummy;
return dummy;
}
if( !p_wxcurrent )
{
wxTreeItemId dummy;
return dummy;
}
if( p_wxcurrent->i_id == i_id )
{
return root;
}
while( item.IsOk() )
{
p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( item );
if( p_wxcurrent->p_item == p_item )
if( p_wxcurrent->i_id == i_id )
{
return item;
}
if( treectrl->ItemHasChildren( item ) )
{
wxTreeItemId search = FindItem( item, p_item );
wxTreeItemId search = FindItem( item, i_id );
if( search.IsOk() )
{
return search;
......@@ -1502,6 +1569,9 @@ void Playlist::OnPlaylistEvent( wxCommandEvent& event )
case AppendItem_Event:
AppendItem( event );
break;
case RemoveItem_Event:
RemoveItem( event.GetInt() );
break;
}
}
......@@ -1549,6 +1619,17 @@ static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
return 0;
}
static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t old_val, vlc_value_t new_val, void *param )
{
Playlist *p_playlist_dialog = (Playlist *)param;
wxCommandEvent event( wxEVT_PLAYLIST, RemoveItem_Event );
event.SetInt( new_val.i_int );
p_playlist_dialog->AddPendingEvent( event );
return 0;
}
static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t oval, vlc_value_t nval, void *param )
......
......@@ -784,6 +784,7 @@ public:
bool b_need_update;
private:
void RemoveItem( int );
void DeleteItem( int item );
void DeleteNode( playlist_item_t *node );
......@@ -864,6 +865,7 @@ private:
/* Search (internal) */
int CountItems( wxTreeItemId);
wxTreeItemId FindItem( wxTreeItemId, playlist_item_t * );
wxTreeItemId FindItem( wxTreeItemId, int );
wxTreeItemId FindItemByName( wxTreeItemId, wxString,
wxTreeItemId, vlc_bool_t *);
......
......@@ -516,6 +516,7 @@ int playlist_ItemToNode( playlist_t *p_playlist,playlist_item_t *p_item )
}
}
vlc_mutex_unlock( &p_playlist->object_lock );
var_SetInteger( p_playlist, "item-change", p_item->input.i_id );
return VLC_SUCCESS;
}
......@@ -598,6 +599,7 @@ int playlist_Delete( playlist_t * p_playlist, int i_id )
{
return VLC_EGENERIC;
}
var_SetInteger( p_playlist, "item-deleted", i_id );
/* Check if it is the current item */
if( p_playlist->status.p_item == p_item )
......@@ -628,9 +630,6 @@ int playlist_Delete( playlist_t * p_playlist, int i_id )
vlc_mutex_unlock( &p_playlist->object_lock );
val.b_bool = VLC_TRUE;
var_Set( p_playlist, "intf-change", val );
return VLC_SUCCESS;
}
......
......@@ -83,6 +83,10 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent )
val.i_int = -1;
var_Set( p_playlist, "item-change", val );
var_Create( p_playlist, "item-deleted", VLC_VAR_INTEGER );
val.i_int = -1;
var_Set( p_playlist, "item-deleted", val );
var_Create( p_playlist, "item-append", VLC_VAR_ADDRESS );
var_Create( p_playlist, "playlist-current", VLC_VAR_INTEGER );
......
......@@ -276,6 +276,7 @@ playlist_item_t * playlist_NodeCreate( playlist_t *p_playlist, int i_view,
p_item->input.i_options = 0;
p_item->input.i_categories = 0;
p_item->input.pp_categories = NULL;
p_item->input.i_id = ++p_playlist->i_last_id;
p_item->pp_parents = NULL;
p_item->i_parents = 0;
......@@ -365,6 +366,7 @@ int playlist_NodeDelete( playlist_t *p_playlist, playlist_item_t *p_root,
playlist_Delete( p_playlist, p_root->pp_children[i]->input.i_id );
}
}
var_SetInteger( p_playlist, "item-deleted", p_root->input.i_id );
/* Delete the node */
for( i = 0 ; i< p_root->i_parents; i++ )
{
......
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