]> git.sesse.net Git - vlc/commitdiff
* Implements sorting by licking on table column headers in the playlist
authorBenjamin Pracht <bigben@videolan.org>
Tue, 14 Dec 2004 18:00:51 +0000 (18:00 +0000)
committerBenjamin Pracht <bigben@videolan.org>
Tue, 14 Dec 2004 18:00:51 +0000 (18:00 +0000)
* Update TODO

modules/gui/macosx/playlist.h
modules/gui/macosx/playlist.m

index 1049166da09f0443c238882327c67af586b3723e..fdb57545ca9a61f223e3bee99302445e94a1e254 100644 (file)
@@ -61,6 +61,8 @@
     NSMutableDictionary * o_outline_dict;
 
     bool b_selected_item_met;
+    bool b_isSortDescending;
+    id o_tc_sortColumn;
 }
 
 - (IBAction)handlePopUp:(id)sender;
index dc085148eb4b5a1ea324bdf41df2d25771f1d17f..904cd9d79f1919ef532035ebc65162ad2bf1b64a 100644 (file)
  *****************************************************************************/
 
 /* TODO
- * connect delegates, actions and outlets in IB
- * implement delete by backspace
- * implement playlist item rightclick menu
- * implement sorting
  * add 'icons' for different types of nodes? (http://www.cocoadev.com/index.pl?IconAndTextInTableCell)
  * create a new 'playlist toggle' that hides the playlist and in effect give you the old controller
  * create a new search field build with pictures from the 'regular' search field, so it can be emulated on 10.2
@@ -140,6 +136,7 @@ belongs to an Apple hidden private API, and then can "disapear" at any time*/
     }
 
     o_outline_dict = [[NSMutableDictionary alloc] init];
+    o_tc_sortColumn = nil;
 
     [self initStrings];
     //[self playlistUpdated];
@@ -172,6 +169,17 @@ belongs to an Apple hidden private API, and then can "disapear" at any time*/
 
 - (void)playlistUpdated
 {
+    unsigned int i;
+
+    /* Clear indications of any existing column sorting*/
+    for( i = 0 ; i < [[o_outline_view tableColumns] count] ; i++ )
+    {
+        [o_outline_view setIndicatorImage:nil inTableColumn:
+                            [[o_outline_view tableColumns] objectAtIndex:i]];
+    }
+
+    [o_outline_view setHighlightedTableColumn:nil];
+    o_tc_sortColumn = nil;
     [o_outline_dict removeAllObjects];
     [o_outline_view reloadData];
 }
@@ -663,6 +671,77 @@ belongs to an Apple hidden private API, and then can "disapear" at any time*/
                                                                 pointerValue];
 }
 
+- (void) outlineView:(NSTableView*)o_tv
+                  didClickTableColumn:(NSTableColumn *)o_tc
+{
+    intf_thread_t * p_intf = VLCIntf;
+    playlist_t *p_playlist =
+        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+                                       FIND_ANYWHERE );
+    playlist_view_t * p_view  = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
+    int i_mode = 0, i_type;
+
+    if( p_playlist == NULL )
+    {
+        return;
+    }
+
+    /* Check whether the selected table column header corresponds to a
+       sortable table column*/
+    if ( !(o_tc == o_tc_name || o_tc == o_tc_author))
+    {
+        return;
+    }
+
+    if( o_tc_sortColumn == o_tc )
+    {
+        b_isSortDescending = !b_isSortDescending;
+    }
+    else
+    {
+        b_isSortDescending = VLC_FALSE;
+    }
+
+    if (o_tc == o_tc_name)
+    {
+        i_mode = SORT_TITLE;
+    }
+    else if (o_tc == o_tc_author)
+    {
+        i_mode = SORT_AUTHOR;
+    }
+
+    if (b_isSortDescending)
+    {
+        i_type = ORDER_REVERSE;
+    }
+    else
+    {
+        i_type = ORDER_NORMAL;
+    }
+
+    vlc_mutex_lock(&p_playlist->object_lock );
+    playlist_RecursiveNodeSort(p_playlist, p_view->p_root, i_mode, i_type);
+    vlc_mutex_unlock(&p_playlist->object_lock );
+
+    vlc_object_release( p_playlist );
+    [self playlistUpdated];
+
+    o_tc_sortColumn = o_tc;
+    [o_outline_view setHighlightedTableColumn:o_tc];
+
+    if (b_isSortDescending)
+    {
+        [o_outline_view setIndicatorImage:o_descendingSortingImage
+                                                        inTableColumn:o_tc];
+    }
+    else
+    {
+        [o_outline_view setIndicatorImage:o_ascendingSortingImage
+                                                        inTableColumn:o_tc];
+    }
+}
+
 @end
 
 @implementation VLCPlaylist (NSOutlineViewDataSource)