]> git.sesse.net Git - vlc/commitdiff
Sort a node (alphabetically, all sub-nodes come first)
authorClément Stenac <zorglub@videolan.org>
Sun, 21 Nov 2004 17:45:09 +0000 (17:45 +0000)
committerClément Stenac <zorglub@videolan.org>
Sun, 21 Nov 2004 17:45:09 +0000 (17:45 +0000)
include/vlc_playlist.h
modules/gui/wxwindows/playlist.cpp
modules/gui/wxwindows/wxwindows.h
src/playlist/sort.c

index 9c81209fc1c097f77905eba2da217cdadc150d22..5f37e52c5d4b5cae283641d619bf99919f8ac0f6 100644 (file)
@@ -208,7 +208,8 @@ struct playlist_add_t
 
 #define SORT_ID 0
 #define SORT_TITLE 1
-#define SORT_AUTHOR 2
+#define SORT_TITLE_NODES_FIRST 2
+#define SORT_AUTHOR 3
 #define SORT_RANDOM 4
 #define SORT_DURATION 5
 
@@ -331,6 +332,7 @@ VLC_EXPORT( int, playlist_ItemAddOption, (playlist_item_t *, const char *) );
 VLC_EXPORT( int,  playlist_Sort, ( playlist_t *, int, int) );
 VLC_EXPORT( int,  playlist_Move, ( playlist_t *, int, int ) );
 VLC_EXPORT( int,  playlist_NodeGroup, ( playlist_t *, int,playlist_item_t *,playlist_item_t **,int, int, int ) );
+VLC_EXPORT( int,  playlist_NodeSort, ( playlist_t *, playlist_item_t *,int, int ) );
 
 /* Load/Save */
 VLC_EXPORT( int,  playlist_Import, ( playlist_t *, const char * ) );
index c997864337ba7d321ded87dc8869d95a7ea5c078..cc8bb708375950aa8c554c9a6d8d1ebf4a8538a9 100644 (file)
@@ -93,6 +93,7 @@ enum
 
     PopupPlay_Event,
     PopupPlayThis_Event,
+    PopupSort_Event,
     PopupDel_Event,
     PopupEna_Event,
     PopupInfo_Event,
@@ -154,6 +155,7 @@ BEGIN_EVENT_TABLE(Playlist, wxFrame)
     /* Popup events */
     EVT_MENU( PopupPlay_Event, Playlist::OnPopupPlay)
     EVT_MENU( PopupPlayThis_Event, Playlist::OnPopupPlay)
+    EVT_MENU( PopupSort_Event, Playlist::OnPopupSort)
     EVT_MENU( PopupDel_Event, Playlist::OnPopupDel)
     EVT_MENU( PopupEna_Event, Playlist::OnPopupEna)
     EVT_MENU( PopupInfo_Event, Playlist::OnPopupInfo)
@@ -276,6 +278,7 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
     popup_menu = new wxMenu;
     popup_menu->Append( PopupPlay_Event, wxU(_("Play")) );
     popup_menu->Append( PopupPlayThis_Event, wxU(_("Play this branch")) );
+    popup_menu->Append( PopupSort_Event, wxU(_("Sort this branch")) );
     popup_menu->Append( PopupDel_Event, wxU(_("Delete")) );
     popup_menu->Append( PopupEna_Event, wxU(_("Enable/Disable")) );
     popup_menu->Append( PopupInfo_Event, wxU(_("Info")) );
@@ -1452,6 +1455,26 @@ void Playlist::OnPopupDel( wxMenuEvent& event )
     }
 }
 
+void Playlist::OnPopupSort( wxMenuEvent& event )
+{
+    PlaylistItem *p_wxitem;
+
+    p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_popup_item );
+
+    if( p_wxitem->p_item->i_children >= 0 )
+    {
+        playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
+                                        VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
+
+        if( p_playlist )
+        {
+            playlist_NodeSort( p_playlist, p_wxitem->p_item,
+                               SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
+            vlc_object_release( p_playlist );
+        }
+    }
+}
+
 void Playlist::OnPopupEna( wxMenuEvent& event )
 {
     playlist_t *p_playlist =
index ad8edb1e07975a3c330af7d3d2484b854736c4c5..b4b898f0b7d21a633f88aa69664f36c344931b29 100644 (file)
@@ -829,6 +829,7 @@ private:
     /* Popup functions */
     void OnPopup( wxContextMenuEvent& event );
     void OnPopupPlay( wxMenuEvent& event );
+    void OnPopupSort( wxMenuEvent& event );
     void OnPopupDel( wxMenuEvent& event );
     void OnPopupEna( wxMenuEvent& event );
     void OnPopupInfo( wxMenuEvent& event );
index 255a3be078d72242575e7dd93e059dde4e3b538a..2833f396c060b88953fb6a94ddeaa9c6042c5ae3 100644 (file)
@@ -153,6 +153,26 @@ int playlist_ItemArraySort( playlist_t *p_playlist, int i_items,
             {
                 msg_Err( p_playlist,"META SORT not implemented" );
             }
+            else if( i_mode == SORT_TITLE_NODES_FIRST )
+            {
+                /* Alphabetic sort, all nodes first */
+
+                if( pp_items[i]->i_children == -1 &&
+                    pp_items[i_small]->i_children >= 0 )
+                {
+                    i_test = 1;
+                }
+                else if( pp_items[i]->i_children >= 0 &&
+                         pp_items[i_small]->i_children == -1 )
+                {
+                    i_test = -1;
+                }
+                else
+                {
+                    i_test = strcasecmp( pp_items[i]->input.psz_name,
+                                         pp_items[i_small]->input.psz_name );
+                }
+            }
 
             if( ( i_type == ORDER_NORMAL  && i_test < 0 ) ||
                 ( i_type == ORDER_REVERSE && i_test > 0 ) )