~ubuntu-branches/ubuntu/utopic/vlc/utopic

« back to all changes in this revision

Viewing changes to modules/gui/macosx/playlist.m

  • Committer: Package Import Robot
  • Author(s): Benjamin Drung
  • Date: 2012-07-21 17:52:21 UTC
  • mfrom: (1.1.48) (3.5.44 sid)
  • Revision ID: package-import@ubuntu.com-20120721175221-53m5pclzo992kawy
Tags: 2.0.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * playlist.m: MacOS X interface module
3
3
 *****************************************************************************
4
4
* Copyright (C) 2002-2012 VLC authors and VideoLAN
5
 
 * $Id: 323ad29cab2c6499892a19f155893e92f76a775e $
 
5
 * $Id: bfbcb81a5e9e7a41d43a8c236e92807093514b6f $
6
6
 *
7
7
 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8
8
 *          Derk-Jan Hartman <hartman at videola/n dot org>
1552
1552
    /* Drag & Drop inside the playlist */
1553
1553
    if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1554
1554
    {
1555
 
        int i_row, i_removed_from_node = 0;
 
1555
        int i_row = 0;
1556
1556
        playlist_item_t *p_new_parent, *p_item = NULL;
1557
1557
        NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray: o_items_array];
1558
1558
        /* If the item is to be dropped as root item of the outline, make it a
1576
1576
        }
1577
1577
 
1578
1578
        NSUInteger count = [o_all_items count];
 
1579
        if( count == 0 )
 
1580
            return NO;
 
1581
 
 
1582
        playlist_item_t **pp_items = (playlist_item_t **)calloc( count, sizeof( playlist_item_t* ) );
 
1583
        if ( !pp_items )
 
1584
            return NO;
 
1585
 
 
1586
        PL_LOCK;
 
1587
        NSUInteger j = 0;
1579
1588
        for( NSUInteger i = 0; i < count; i++ )
1580
1589
        {
1581
 
            playlist_item_t *p_old_parent = NULL;
1582
 
            int i_old_index = 0;
1583
 
 
1584
1590
            p_item = [[o_all_items objectAtIndex:i] pointerValue];
1585
 
            p_old_parent = p_item->p_parent;
1586
 
            if( !p_old_parent )
1587
 
            continue;
1588
 
            /* We may need the old index later */
1589
 
            if( p_new_parent == p_old_parent )
1590
 
            {
1591
 
                for( NSInteger j = 0; j < p_old_parent->i_children; j++ )
1592
 
                {
1593
 
                    if( p_old_parent->pp_children[j] == p_item )
1594
 
                    {
1595
 
                        i_old_index = j;
1596
 
                        break;
1597
 
                    }
1598
 
                }
1599
 
            }
 
1591
            if( p_item )
 
1592
                pp_items[j++] = p_item;
 
1593
        }
1600
1594
 
1601
 
            PL_LOCK;
1602
 
            // Actually detach the item from the old position
1603
 
            if( playlist_NodeRemoveItem( p_playlist, p_item, p_old_parent ) ==
1604
 
                VLC_SUCCESS )
1605
 
            {
1606
 
                int i_new_index;
1607
 
                /* Calculate the new index */
1608
 
                if( index == -1 )
1609
 
                i_new_index = -1;
1610
 
                /* If we move the item in the same node, we need to take into
1611
 
                   account that one item will be deleted */
1612
 
                else
1613
 
                {
1614
 
                    if ((p_new_parent == p_old_parent && i_old_index < index + (int)i) )
1615
 
                    {
1616
 
                        i_removed_from_node++;
1617
 
                    }
1618
 
                    i_new_index = index + i - i_removed_from_node;
1619
 
                }
1620
 
                // Reattach the item to the new position
1621
 
                playlist_NodeInsert( p_playlist, p_item, p_new_parent, i_new_index );
1622
 
            }
 
1595
        if( j == 0 || playlist_TreeMoveMany( p_playlist, j, pp_items, p_new_parent, index ) != VLC_SUCCESS )
 
1596
        {
1623
1597
            PL_UNLOCK;
 
1598
            free( pp_items );
 
1599
            return NO;
1624
1600
        }
 
1601
 
 
1602
        PL_UNLOCK;
 
1603
        free( pp_items );
 
1604
 
1625
1605
        [self playlistUpdated];
1626
1606
        i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", [[o_all_items objectAtIndex: 0] pointerValue]]]];
1627
1607