+ /* FIXME: having this Rebuild() is dirty */
+ Rebuild( true );
+}
+
+#if wxUSE_DRAG_AND_DROP
+PlaylistFileDropTarget::PlaylistFileDropTarget( Playlist *p ):p( p ){}
+
+/********************************************************************
+ * File Drag And Drop handling
+ ********************************************************************/
+bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y,
+ const wxArrayString& filenames )
+{
+ int i_pos = 0;
+ playlist_item_t *p_dest;
+
+ LockPlaylist( p->p_intf->p_sys, p->p_playlist );
+
+ /* find the destination node and position in that node */
+ const wxPoint pt( x, y );
+ wxTreeItemId item = p->treectrl->HitTest( pt );
+
+ if( !item.IsOk() )
+ {
+ /* We were droped below the last item so we append to the
+ * general node */
+ msg_Err( p->p_playlist, "USE OF P_GENERAL" );
+ p_dest = p->p_playlist->p_local_category;
+ i_pos = PLAYLIST_END;
+ }
+ else
+ {
+ PlaylistItem *p_plitem =
+ (PlaylistItem *)p->treectrl->GetItemData( item );
+ p_dest = playlist_ItemGetById( p->p_playlist, p_plitem->i_id, true );
+
+ if( p_dest->i_children == -1 )
+ {
+ /* This is a leaf. Append right after it
+ * We thus need to find the parrent node and the position of the
+ * leaf in its children list */
+ wxTreeItemId parent = p->treectrl->GetItemParent( item );
+ PlaylistItem *p_parent =
+ (PlaylistItem *)p->treectrl->GetItemData( parent );
+ if( !p_parent )
+ {
+ UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
+ return FALSE;
+ }
+ playlist_item_t *p_node =
+ playlist_ItemGetById( p->p_playlist, p_parent->i_id, true );
+ if( !p_node )
+ {
+ UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
+ return FALSE;
+ }
+ for( i_pos = 0; i_pos < p_node->i_children; i_pos++ )
+ {
+ if( p_node->pp_children[i_pos] == p_dest ) break;
+ }
+ p_dest = p_node;
+ }
+ }
+
+ UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
+
+ /* Put the items in the playlist node */
+ for( size_t i = 0; i < filenames.GetCount(); i++ )
+ {
+ char *psz_utf8 = wxDnDFromLocale( filenames[i] );
+ input_item_t *p_input = input_ItemNew( p->p_playlist,
+ psz_utf8, psz_utf8 );
+ int i_ret = ( playlist_BothAddInput( p->p_playlist, p_input, p_dest,
+ PLAYLIST_PREPARSE, i_pos, NULL, NULL, pl_Unlocked ) != VLC_SUCCESS );
+ vlc_gc_decref( p_input );
+ wxDnDLocaleFree( psz_utf8 );
+ if( i_ret != VLC_SUCCESS )
+ return FALSE;
+ }
+
+ /* FIXME: having this Rebuild() is dirty */
+ p->Rebuild( true );
+
+ return TRUE;