]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/playlist.m
macosx: dynamically create context and main sub menu for playlist table header select...
[vlc] / modules / gui / macosx / playlist.m
index 809fafcb6ca6559c9c29b87dc52e93b8128dd478..2ec7746ae37bbb2c5ba2535aa5a8c27cd84435e9 100644 (file)
@@ -27,8 +27,6 @@
 /* TODO
  * add 'icons' for different types of nodes? (http://www.cocoadev.com/index.pl?IconAndTextInTableCell)
  * reimplement enable/disable item
- * create a new 'tool' button (see the gear button in the Finder window) for 'actions'
-   (adding service discovery, other views, new node/playlist, save node/playlist) stuff like that
  */
 
 
 #import "controls.h"
 #import "misc.h"
 #import "open.h"
+#import "MainMenu.h"
 
 #include <vlc_keys.h>
-#import <vlc_services_discovery.h>
 #import <vlc_osd.h>
 #import <vlc_interface.h>
 
 #include <vlc_url.h>
 
-
 /*****************************************************************************
  * VLCPlaylistView implementation
  *****************************************************************************/
@@ -88,7 +85,7 @@
 
         case NSEnterCharacter:
         case NSCarriageReturnCharacter:
-            [(VLCPlaylist *)[[VLCMain sharedInstance] playlist] playItem:self];
+            [(VLCPlaylist *)[[VLCMain sharedInstance] playlist] playItem:nil];
             break;
 
         default:
     }
 }
 
+- (BOOL)validateMenuItem:(NSMenuItem *)item
+{
+    if (([self numberOfSelectedRows] >= 1 && [item action] == @selector(delete:)) || [item action] == @selector(selectAll:))
+        return YES;
+
+    return NO;
+}
+
+- (BOOL) acceptsFirstResponder
+{
+    return YES;
+}
+
+- (BOOL) becomeFirstResponder
+{
+    [self setNeedsDisplay:YES];
+    return YES;
+}
+
+- (BOOL) resignFirstResponder
+{
+    [self setNeedsDisplay:YES];
+    return YES;
+}
+
+- (IBAction)delete:(id)sender
+{
+    [[[VLCMain sharedInstance] playlist] deleteItem: sender];
+}
+
 @end
 
 /*****************************************************************************
     [o_outline_view_other setDataSource: self];
     [o_outline_view_other setAllowsEmptySelection: NO];
 
-    [self initStrings];
-}
-
-- (void)initStrings
-{
-    [[o_tc_name headerCell] setStringValue:_NS("Name")];
-    [[o_tc_author headerCell] setStringValue:_NS("Author")];
-    [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
-
     [[o_tc_name_other headerCell] setStringValue:_NS("Name")];
     [[o_tc_author_other headerCell] setStringValue:_NS("Author")];
     [[o_tc_duration_other headerCell] setStringValue:_NS("Duration")];
     return p_current_root_item;
 }
 
-- (void)swapPlaylists:(id)newList
-{
-    if(newList != o_outline_view)
-    {
-        id o_outline_view_temp = o_outline_view;
-        id o_tc_author_temp = o_tc_author;
-        id o_tc_duration_temp = o_tc_duration;
-        id o_tc_name_temp = o_tc_name;
-        o_outline_view = o_outline_view_other;
-        o_tc_author = o_tc_author_other;
-        o_tc_duration = o_tc_duration_other;
-        o_tc_name = o_tc_name_other;
-        o_outline_view_other = o_outline_view_temp;
-        o_tc_author_other = o_tc_author_temp;
-        o_tc_duration_other = o_tc_duration_temp;
-        o_tc_name_other = o_tc_name_temp;
-    }
-}
-
 - (NSOutlineView *)outlineView
 {
     return o_outline_view;
 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
 {
     id o_value = nil;
+    char * psz_value;
     playlist_item_t *p_item;
 
     /* For error handling */
     }
 
     attempted_reload = NO;
+    NSString * o_identifier = [o_tc identifier];
 
-    if( [[o_tc identifier] isEqualToString:@"name"] )
+    if( [o_identifier isEqualToString:TRACKNUM_COLUMN] )
+    {
+        psz_value = input_item_GetTrackNumber( p_item->p_input ); \
+        if (psz_value) { \
+            o_value = [NSString stringWithUTF8String: psz_value]; \
+            free( psz_value ); \
+        }
+    }
+    else if( [o_identifier isEqualToString:TITLE_COLUMN] )
     {
         /* sanity check to prevent the NSString class from crashing */
         char *psz_title =  input_item_GetTitleFbName( p_item->p_input );
             free( psz_title );
         }
     }
-    else if( [[o_tc identifier] isEqualToString:@"artist"] )
+    else if( [o_identifier isEqualToString:ARTIST_COLUMN] )
     {
-        char *psz_artist = input_item_GetArtist( p_item->p_input );
-        if( psz_artist )
-            o_value = [NSString stringWithUTF8String: psz_artist];
-        free( psz_artist );
+        psz_value = input_item_GetArtist( p_item->p_input ); \
+        if (psz_value) { \
+            o_value = [NSString stringWithUTF8String: psz_value]; \
+            free( psz_value ); \
+        }
     }
-    else if( [[o_tc identifier] isEqualToString:@"duration"] )
+    else if( [o_identifier isEqualToString:@"duration"] )
     {
         char psz_duration[MSTRTIME_MAX_SIZE];
         mtime_t dur = input_item_GetDuration( p_item->p_input );
         else
             o_value = @"--:--";
     }
-    else if( [[o_tc identifier] isEqualToString:@"status"] )
+    else if( [o_identifier isEqualToString:GENRE_COLUMN] )
+    {
+        psz_value = input_item_GetGenre( p_item->p_input ); \
+        if (psz_value) { \
+            o_value = [NSString stringWithUTF8String: psz_value]; \
+            free( psz_value ); \
+        }
+    }
+    else if( [o_identifier isEqualToString:ALBUM_COLUMN] )
+    {
+        psz_value = input_item_GetAlbum( p_item->p_input ); \
+        if (psz_value) { \
+            o_value = [NSString stringWithUTF8String: psz_value]; \
+            free( psz_value ); \
+        }
+    }
+    else if( [o_identifier isEqualToString:DESCRIPTION_COLUMN] )
+    {
+        psz_value = input_item_GetDescription( p_item->p_input ); \
+        if (psz_value) { \
+            o_value = [NSString stringWithUTF8String: psz_value]; \
+            free( psz_value ); \
+        }
+    }
+    else if( [o_identifier isEqualToString:DATE_COLUMN] )
+    {
+        psz_value = input_item_GetDate( p_item->p_input ); \
+        if (psz_value) { \
+            o_value = [NSString stringWithUTF8String: psz_value]; \
+            free( psz_value ); \
+        }
+    }
+    else if( [o_identifier isEqualToString:LANGUAGE_COLUMN] )
+    {
+        psz_value = input_item_GetLanguage( p_item->p_input ); \
+        if (psz_value) { \
+            o_value = [NSString stringWithUTF8String: psz_value]; \
+            free( psz_value ); \
+        }
+    }
+    else if( [o_identifier isEqualToString:URI_COLUMN] )
+    {
+        psz_value = decode_URI(input_item_GetURI( p_item->p_input )); \
+        if (psz_value) { \
+            o_value = [NSString stringWithUTF8String: psz_value]; \
+            free( psz_value ); \
+        }
+    }
+    else if( [o_identifier isEqualToString:@"status"] )
     {
         if( input_item_HasErrorWhenReading( p_item->p_input ) )
         {
             [o_value setSize: NSMakeSize(16,16)];
         }
     }
+
     return o_value;
 }
 
 @end
 
 /*****************************************************************************
- * extension to NSOutlineView's interface to fix compilation warnings
- * and let us access these 2 functions properly
- * this uses a private Apple-API, but works fine on all current OSX releases
- * keep checking for compatiblity with future releases though
+ * An extension to NSOutlineView's interface to fix compilation warnings
+ * and let us access these 2 functions properly.
+ * This uses a private API, but works fine on all current OSX releases.
+ * Radar ID 11739459 request a public API for this. However, it is probably
+ * easier and faster to recreate similar looking bitmaps ourselves.
  *****************************************************************************/
 
 @interface NSOutlineView (UndocumentedSortImages)
  *****************************************************************************/
 @implementation VLCPlaylist
 
++ (void)initialize{
+    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+    NSMutableArray * o_columnArray = [[NSMutableArray alloc] init];
+    [o_columnArray addObject: [NSArray arrayWithObjects: TITLE_COLUMN, [NSNumber numberWithFloat: 190.], nil]];
+    [o_columnArray addObject: [NSArray arrayWithObjects: ARTIST_COLUMN, [NSNumber numberWithFloat: 95.], nil]];
+    [o_columnArray addObject: [NSArray arrayWithObjects: DURATION_COLUMN, [NSNumber numberWithFloat: 95.], nil]];
+    NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:[NSArray arrayWithArray:o_columnArray] forKey:@"PlaylistColumnSelection"];
+
+    [defaults registerDefaults:appDefaults];
+    [o_columnArray release];
+}
+
 - (id)init
 {
     self = [super init];
       @"VLCPlaylistItemPboardType", nil]];
     [o_outline_view_other setIntercellSpacing: NSMakeSize (0.0, 1.0)];
 
-    /* This uses private Apple API which works fine until 10.5.
-     * We need to keep checking in the future!
-     * These methods are being added artificially to NSOutlineView's interface above */
+    /* This uses a private API, but works fine on all current OSX releases.
+     * Radar ID 11739459 request a public API for this. However, it is probably
+     * easier and faster to recreate similar looking bitmaps ourselves. */
     o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
     o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
 
     o_tc_sortColumn = nil;
-#if 0
-    char ** ppsz_name;
-    char ** ppsz_services = vlc_sd_GetNames( VLCIntf, &ppsz_name, NULL );
-    if( !ppsz_services )
-        return;
 
-    for( i = 0; ppsz_services[i]; i++ )
+    NSArray * o_columnArray = [[NSUserDefaults standardUserDefaults] arrayForKey:@"PlaylistColumnSelection"];
+    NSUInteger count = [o_columnArray count];
+
+    id o_menu = [[VLCMain sharedInstance] mainMenu];
+    NSString * o_column;
+
+    NSMenu *o_context_menu = [o_menu setupPlaylistTableColumnsMenu];
+    [o_playlist_header setMenu: o_context_menu];
+
+    for (NSUInteger i = 0; i < count; i++)
     {
-        bool  b_enabled;
-        NSMenuItem  *o_lmi;
-
-        char * name = ppsz_name[i] ? ppsz_name[i] : ppsz_services[i];
-        /* Check whether to enable these menuitems */
-        b_enabled = playlist_IsServicesDiscoveryLoaded( p_playlist, ppsz_services[i] );
-
-        /* Create the menu entries used in the playlist menu */
-        o_lmi = [[o_mi_services submenu] addItemWithTitle:
-                 [NSString stringWithUTF8String: name]
-                                         action: @selector(servicesChange:)
-                                         keyEquivalent: @""];
-        [o_lmi setTarget: self];
-        [o_lmi setRepresentedObject: [NSString stringWithUTF8String: ppsz_services[i]]];
-        if( b_enabled ) [o_lmi setState: NSOnState];
-
-        /* Create the menu entries for the main menu */
-        o_lmi = [[o_mm_mi_services submenu] addItemWithTitle:
-                 [NSString stringWithUTF8String: name]
-                                         action: @selector(servicesChange:)
-                                         keyEquivalent: @""];
-        [o_lmi setTarget: self];
-        [o_lmi setRepresentedObject: [NSString stringWithUTF8String: ppsz_services[i]]];
-        if( b_enabled ) [o_lmi setState: NSOnState];
-
-        free( ppsz_services[i] );
-        free( ppsz_name[i] );
-    }
-    free( ppsz_services );
-    free( ppsz_name );
-#endif
+        o_column = [[o_columnArray objectAtIndex:i] objectAtIndex:0];
+        if ([o_column isEqualToString:@"status"])
+            continue;
+
+        [self setColumn: o_column state: NSOnState];
+        [o_menu setPlaylistColumnTableState: NSOnState forColumn: o_column];
+        [[o_outline_view tableColumnWithIdentifier: o_column] setWidth: [[[o_columnArray objectAtIndex:i] objectAtIndex:1] floatValue]];
+    }
+
+    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationWillTerminate:) name: NSApplicationWillTerminateNotification object: nil];
+}
+
+- (void)applicationWillTerminate:(NSNotification *)notification
+{
+    /* let's make sure we save the correct widths and positions, since this likely changed since the last time the user played with the column selection */
+    [self saveTableColumns];
 }
 
 - (void)searchfieldChanged:(NSNotification *)o_notification
 
 - (void)initStrings
 {
-    [super initStrings];
-
     [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
     [o_mi_play setTitle: _NS("Play")];
     [o_mi_delete setTitle: _NS("Delete")];
     [[o_mm_mi_revealInFinder menu] setAutoenablesItems: NO];
     [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
     [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
-    [o_mi_services setTitle: _NS("Services discovery")];
-    [o_mm_mi_services setTitle: _NS("Services discovery")];
 
     [o_search_field setToolTip: _NS("Search in Playlist")];
     [o_search_field_other setToolTip: _NS("Search in Playlist")];
     [[o_save_accessory_popup itemAtIndex:2] setTitle: _NS("HTML Playlist")];
 }
 
-- (void)swapPlaylists:(id)newList
-{
-    if(newList != o_outline_view)
-    {
-        id o_search_field_temp = o_search_field;
-        o_search_field = o_search_field_other;
-        o_search_field_other = o_search_field_temp;
-        [super swapPlaylists:newList];
-        [self playlistUpdated];
-    }
-}
-
 - (void)playlistUpdated
 {
     /* Clear indications of any existing column sorting */
     NSUInteger count = [[o_outline_view tableColumns] count];
     for( NSUInteger i = 0 ; i < count ; i++ )
     {
-        [o_outline_view setIndicatorImage:nil inTableColumn:
-                            [[o_outline_view tableColumns] objectAtIndex:i]];
+        [o_outline_view setIndicatorImage:nil inTableColumn: [[o_outline_view tableColumns] objectAtIndex:i]];
     }
 
     [o_outline_view setHighlightedTableColumn:nil];
     playlist_item_t *p_item;
     playlist_item_t *p_node = NULL;
 
+    // ignore clicks on column header when handling double action
+    if( sender != nil && [o_outline_view clickedRow] == -1 && sender != o_mi_play)
+        return;
+
     p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
 
     PL_LOCK;
 
 - (IBAction)revealItemInFinder:(id)sender
 {
-    playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
-    NSMutableString * o_mrl = nil;
+    NSIndexSet * selectedRows = [o_outline_view selectedRowIndexes];
+    NSUInteger count = [selectedRows count];
+    NSUInteger indexes[count];
+    [selectedRows getIndexes:indexes maxCount:count inIndexRange:nil];
 
-    if(! p_item || !p_item->p_input )
-        return;
+    NSMutableString * o_mrl;
+    playlist_item_t *p_item;
+    for (NSUInteger i = 0; i < count; i++) {
+        p_item = [[o_outline_view itemAtRow:indexes[i]] pointerValue];
 
-    char *psz_uri = decode_URI( input_item_GetURI( p_item->p_input ) );
-    if( psz_uri )
-        o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
+        if(! p_item || !p_item->p_input )
+            continue;
 
-    /* perform some checks whether it is a file and if it is local at all... */
-    NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
-    if( prefix_range.location != NSNotFound )
-        [o_mrl deleteCharactersInRange: prefix_range];
+        o_mrl = [[NSMutableString alloc] initWithFormat: @"%s", decode_URI( input_item_GetURI( p_item->p_input ))];
 
-    if( [o_mrl characterAtIndex:0] == '/' )
-        [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
+        /* perform some checks whether it is a file and if it is local at all... */
+        if ([o_mrl length] > 0)
+        {
+            NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
+            if( prefix_range.location != NSNotFound )
+                [o_mrl deleteCharactersInRange: prefix_range];
+
+            if( [o_mrl characterAtIndex:0] == '/' )
+                [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
+        }
+
+        [o_mrl release];
+    }
 }
 
 /* When called retrieves the selected outlineview row and plays that node or item */
     [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
     for (int i = 0; i < i_count; i++)
     {
-        p_item = [[o_outline_view itemAtRow: indexes[i]] pointerValue];   
-        [o_outline_view deselectRow: indexes[i]];
+        p_item = [[o_outline_view itemAtRow: indexes[i]] pointerValue];
 
         if( p_item && p_item->i_children == -1 )
             playlist_AskForArtEnqueue( p_playlist, p_item->p_input );
     [self playlistUpdated];
 }
 
-- (IBAction)servicesChange:(id)sender
-{
-    NSMenuItem *o_mi = (NSMenuItem *)sender;
-    NSString *o_string = [o_mi representedObject];
-    playlist_t * p_playlist = pl_Get( VLCIntf );
-    if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string UTF8String] ) )
-        playlist_ServicesDiscoveryAdd( p_playlist, [o_string UTF8String] );
-    else
-        playlist_ServicesDiscoveryRemove( p_playlist, [o_string UTF8String] );
-
-    [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
-                                          [o_string UTF8String] ) ? YES : NO];
-
-    [self playlistUpdated];
-    return;
-}
-
 - (IBAction)selectAll:(id)sender
 {
     [o_outline_view selectAll: nil];
 
 - (IBAction)recursiveExpandNode:(id)sender
 {
-    id o_item = [o_outline_view itemAtRow: [o_outline_view selectedRow]];
-    playlist_item_t *p_item = (playlist_item_t *)[o_item pointerValue];
+    NSIndexSet * selectedRows = [o_outline_view selectedRowIndexes];
+    NSUInteger count = [selectedRows count];
+    NSUInteger indexes[count];
+    [selectedRows getIndexes:indexes maxCount:count inIndexRange:nil];
 
-    if( ![[o_outline_view dataSource] outlineView: o_outline_view
-                                                    isItemExpandable: o_item] )
-    {
-        o_item = [o_outline_dict objectForKey: [NSString stringWithFormat: @"%p", p_item->p_parent]];
-    }
+    id o_item;
+    playlist_item_t *p_item;
+    for (NSUInteger i = 0; i < count; i++) {
+        o_item = [o_outline_view itemAtRow: indexes[i]];
+        p_item = (playlist_item_t *)[o_item pointerValue];
+
+        if( ![[o_outline_view dataSource] outlineView: o_outline_view isItemExpandable: o_item] )
+            o_item = [o_outline_dict objectForKey: [NSString stringWithFormat: @"%p", p_item->p_parent]];
 
-    /* We need to collapse the node first, since OSX refuses to recursively
-       expand an already expanded node, even if children nodes are collapsed. */
-    [o_outline_view collapseItem: o_item collapseChildren: YES];
-    [o_outline_view expandItem: o_item expandChildren: YES];
+        /* We need to collapse the node first, since OSX refuses to recursively
+         expand an already expanded node, even if children nodes are collapsed. */
+        [o_outline_view collapseItem: o_item collapseChildren: YES];
+        [o_outline_view expandItem: o_item expandChildren: YES];
+
+        selectedRows = [o_outline_view selectedRowIndexes];
+        [selectedRows getIndexes:indexes maxCount:count inIndexRange:nil];
+    }
 }
 
 - (NSMenu *)menuForEvent:(NSEvent *)o_event
     bool b_rows;
     bool b_item_sel;
 
-    pt = [o_outline_view convertPoint: [o_event locationInWindow]
-                                                 fromView: nil];
+    pt = [o_outline_view convertPoint: [o_event locationInWindow] fromView: nil];
     int row = [o_outline_view rowAtPoint:pt];
-    if( row != -1 )
+    if( row != -1 && ![[o_outline_view selectedRowIndexes] containsIndex: row] )
         [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
 
     b_item_sel = ( row != -1 && [o_outline_view selectedRow] != -1 );
     return( o_ctx_menu );
 }
 
-- (void)outlineView: (NSOutlineView *)o_tv
-                  didClickTableColumn:(NSTableColumn *)o_tc
+- (void)outlineView: (NSOutlineView *)o_tv didClickTableColumn:(NSTableColumn *)o_tc
 {
     int i_mode, i_type = 0;
     intf_thread_t *p_intf = VLCIntf;
+    NSString * o_identifier = [o_tc identifier];
 
     playlist_t *p_playlist = pl_Get( p_intf );
 
-    /* Check whether the selected table column header corresponds to a
-       sortable table column*/
-    if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
-    {
+    if( [o_identifier isEqualToString:TRACKNUM_COLUMN] )
+        i_mode = SORT_TRACK_NUMBER;
+    else if( [o_identifier isEqualToString:TITLE_COLUMN] )
+        i_mode = SORT_TITLE;
+    else if( [o_identifier isEqualToString:ARTIST_COLUMN] )
+        i_mode = SORT_ARTIST;
+    else if( [o_identifier isEqualToString:GENRE_COLUMN] )
+        i_mode = SORT_GENRE;
+    else if( [o_identifier isEqualToString:DURATION_COLUMN] )
+        i_mode = SORT_DURATION;
+    else if( [o_identifier isEqualToString:ALBUM_COLUMN] )
+        i_mode = SORT_ALBUM;
+    else if( [o_identifier isEqualToString:DESCRIPTION_COLUMN] )
+        i_mode = SORT_DESCRIPTION;
+    else if( [o_identifier isEqualToString:URI_COLUMN] )
+        i_mode = SORT_URI;
+    else
         return;
-    }
 
     if( o_tc_sortColumn == o_tc )
-    {
         b_isSortDescending = !b_isSortDescending;
-    }
     else
-    {
         b_isSortDescending = false;
-    }
-
-    if( o_tc == o_tc_name )
-    {
-        i_mode = SORT_TITLE;
-    }
-    else if( o_tc == o_tc_author )
-    {
-        i_mode = SORT_ARTIST;
-    }
 
     if( b_isSortDescending )
-    {
         i_type = ORDER_REVERSE;
-    }
     else
-    {
         i_type = ORDER_NORMAL;
-    }
 
     PL_LOCK;
     playlist_RecursiveNodeSort( p_playlist, [self currentPlaylistRoot], i_mode, i_type );
     [o_outline_view setHighlightedTableColumn:o_tc];
 
     if( b_isSortDescending )
-    {
-        [o_outline_view setIndicatorImage:o_descendingSortingImage
-                                                        inTableColumn:o_tc];
-    }
+        [o_outline_view setIndicatorImage:o_descendingSortingImage inTableColumn:o_tc];
     else
-    {
-        [o_outline_view setIndicatorImage:o_ascendingSortingImage
-                                                        inTableColumn:o_tc];
-    }
+        [o_outline_view setIndicatorImage:o_ascendingSortingImage inTableColumn:o_tc];
 }
 
 
 
     return o_playing_item;
 }
+
+- (NSArray *)draggedItems
+{
+    return [[o_nodes_array arrayByAddingObjectsFromArray: o_items_array] retain];
+}
+
+- (void)setColumn: (NSString *)o_column state: (NSInteger)i_state
+{
+    NSTableColumn * o_work_tc;
+
+    if (i_state == NSOnState)
+    {
+        o_work_tc = [[NSTableColumn alloc] initWithIdentifier: o_column];
+        [o_work_tc setEditable: NO];
+        [[o_work_tc dataCell] setFont: [NSFont controlContentFontOfSize:11.]];
+
+        /* we cannot use a makro here, because gettext isn't clever enough for that */
+        if ([o_column isEqualToString: TRACKNUM_COLUMN])
+        {
+            [o_work_tc setMaxWidth: 20.];
+            [[o_work_tc headerCell] setStringValue: @"#"];
+        }
+        else if ([o_column isEqualToString: TITLE_COLUMN])
+        {
+            [[o_work_tc headerCell] setStringValue: _NS("Name")];
+            [o_work_tc setResizingMask: NSTableColumnAutoresizingMask | NSTableColumnUserResizingMask];
+        }
+        else if ([o_column isEqualToString: ARTIST_COLUMN])
+            [[o_work_tc headerCell] setStringValue: _NS("Author")];
+        else if ([o_column isEqualToString: DURATION_COLUMN])
+            [[o_work_tc headerCell] setStringValue: _NS("Duration")];
+        else if ([o_column isEqualToString: GENRE_COLUMN])
+            [[o_work_tc headerCell] setStringValue: _NS("Genre")];
+        else if ([o_column isEqualToString: ALBUM_COLUMN])
+            [[o_work_tc headerCell] setStringValue: _NS("Album")];
+        else if ([o_column isEqualToString: DESCRIPTION_COLUMN])
+            [[o_work_tc headerCell] setStringValue: _NS("Description")];
+        else if ([o_column isEqualToString: DATE_COLUMN])
+            [[o_work_tc headerCell] setStringValue: _NS("Date")];
+        else if ([o_column isEqualToString: LANGUAGE_COLUMN])
+            [[o_work_tc headerCell] setStringValue: _NS("Language")];
+        else if ([o_column isEqualToString: URI_COLUMN])
+            [[o_work_tc headerCell] setStringValue: _NS("URI")];
+
+        [o_outline_view addTableColumn: o_work_tc];
+        [o_work_tc release];
+        [o_outline_view reloadData];
+        [o_outline_view setNeedsDisplay: YES];
+    }
+    else
+        [o_outline_view removeTableColumn: [o_outline_view tableColumnWithIdentifier: o_column]];
+}
+
+- (void)saveTableColumns
+{
+    NSMutableArray * o_arrayToSave = [[NSMutableArray alloc] init];
+    NSArray * o_columns = [[NSArray alloc] initWithArray:[o_outline_view tableColumns]];
+    NSUInteger count = [o_columns count];
+    NSTableColumn * o_currentColumn;
+    for (NSUInteger i = 0; i < count; i++)
+    {
+        o_currentColumn = [o_columns objectAtIndex: i];
+        [o_arrayToSave addObject: [NSArray arrayWithObjects: [o_currentColumn identifier], [NSNumber numberWithFloat: [o_currentColumn width]], nil]];
+    }
+    [[NSUserDefaults standardUserDefaults] setObject: o_arrayToSave forKey:@"PlaylistColumnSelection"];
+    [[NSUserDefaults standardUserDefaults] synchronize];
+    [o_columns release];
+    [o_arrayToSave release];
+}
+
 @end
 
 @implementation VLCPlaylist (NSOutlineViewDataSource)
     {
         id o_item = [items objectAtIndex: i];
 
-        /* Refuse to move items that are not in the General Node
-           (Service Discovery) */
-        if( (![self isItem: [o_item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO] &&
-            var_CreateGetBool( p_playlist, "media-library" ) && ![self isItem: [o_item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO]) ||
-            [o_item pointerValue] == p_playlist->p_local_category ||
-            [o_item pointerValue] == p_playlist->p_ml_category )
-        {
-            return NO;
-        }
         /* Fill the items and nodes to move in 2 different arrays */
         if( ((playlist_item_t *)[o_item pointerValue])->i_children > 0 )
             [o_nodes_array addObject: o_item];
     /* Drag & Drop inside the playlist */
     if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
     {
-        int i_row, i_removed_from_node = 0;
+        int i_row = 0;
         playlist_item_t *p_new_parent, *p_item = NULL;
-        NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray:
-                                                                o_items_array];
+        NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray: o_items_array];
         /* If the item is to be dropped as root item of the outline, make it a
            child of the respective general node, if is either the pl or the ml
            Else, choose the proposed parent as parent. */
         if( item == nil )
         {
-            if ([self currentPlaylistRoot] == p_playlist->p_local_category || [self currentPlaylistRoot] == p_playlist->p_ml_category) 
+            if ([self currentPlaylistRoot] == p_playlist->p_local_category || [self currentPlaylistRoot] == p_playlist->p_ml_category)
                 p_new_parent = [self currentPlaylistRoot];
             else
-                p_new_parent = p_playlist->p_local_category;
+                return NO;
         }
         else
             p_new_parent = [item pointerValue];
         }
 
         NSUInteger count = [o_all_items count];
+        if( count == 0 )
+            return NO;
+
+        playlist_item_t **pp_items = (playlist_item_t **)calloc( count, sizeof( playlist_item_t* ) );
+        if ( !pp_items )
+            return NO;
+
+        PL_LOCK;
+        NSUInteger j = 0;
         for( NSUInteger i = 0; i < count; i++ )
         {
-            playlist_item_t *p_old_parent = NULL;
-            int i_old_index = 0;
-
             p_item = [[o_all_items objectAtIndex:i] pointerValue];
-            p_old_parent = p_item->p_parent;
-            if( !p_old_parent )
-            continue;
-            /* We may need the old index later */
-            if( p_new_parent == p_old_parent )
-            {
-                for( NSInteger j = 0; j < p_old_parent->i_children; j++ )
-                {
-                    if( p_old_parent->pp_children[j] == p_item )
-                    {
-                        i_old_index = j;
-                        break;
-                    }
-                }
-            }
+            if( p_item )
+                pp_items[j++] = p_item;
+        }
 
-            PL_LOCK;
-            // Actually detach the item from the old position
-            if( playlist_NodeRemoveItem( p_playlist, p_item, p_old_parent ) ==
-                VLC_SUCCESS )
-            {
-                int i_new_index;
-                /* Calculate the new index */
-                if( index == -1 )
-                i_new_index = -1;
-                /* If we move the item in the same node, we need to take into
-                   account that one item will be deleted */
-                else
-                {
-                    if ((p_new_parent == p_old_parent && i_old_index < index + (int)i) )
-                    {
-                        i_removed_from_node++;
-                    }
-                    i_new_index = index + i - i_removed_from_node;
-                }
-                // Reattach the item to the new position
-                playlist_NodeInsert( p_playlist, p_item, p_new_parent, i_new_index );
-            }
+        if( j == 0 || playlist_TreeMoveMany( p_playlist, j, pp_items, p_new_parent, index ) != VLC_SUCCESS )
+        {
             PL_UNLOCK;
+            free( pp_items );
+            return NO;
         }
+
+        PL_UNLOCK;
+        free( pp_items );
+
         [self playlistUpdated];
         i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", [[o_all_items objectAtIndex: 0] pointerValue]]]];
 
 
     else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
     {
+        if ([self currentPlaylistRoot] != p_playlist->p_local_category && [self currentPlaylistRoot] != p_playlist->p_ml_category)
+            return NO;
+
         playlist_item_t *p_node = [item pointerValue];
 
         NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType]
     }
     return NO;
 }
-@end
-
 
+@end