diff --git a/src/apps/mediaplayer/playlist/ImportPLItemsCommand.cpp b/src/apps/mediaplayer/playlist/ImportPLItemsCommand.cpp index 8c906c4a25..cb451dc8cd 100644 --- a/src/apps/mediaplayer/playlist/ImportPLItemsCommand.cpp +++ b/src/apps/mediaplayer/playlist/ImportPLItemsCommand.cpp @@ -25,7 +25,7 @@ using std::nothrow; ImportPLItemsCommand::ImportPLItemsCommand(Playlist* playlist, - const BMessage* refsMessage, int32 toIndex) + const BMessage* refsMessage, int32 toIndex, bool sortItems) : PLItemsCommand(), fPlaylist(playlist), @@ -45,7 +45,7 @@ ImportPLItemsCommand::ImportPLItemsCommand(Playlist* playlist, return; Playlist temp; - temp.AppendItems(refsMessage); + temp.AppendItems(refsMessage, APPEND_INDEX_REPLACE_PLAYLIST, sortItems); fNewCount = temp.CountItems(); if (fNewCount <= 0) diff --git a/src/apps/mediaplayer/playlist/ImportPLItemsCommand.h b/src/apps/mediaplayer/playlist/ImportPLItemsCommand.h index f4cc895000..78dde99f5e 100644 --- a/src/apps/mediaplayer/playlist/ImportPLItemsCommand.h +++ b/src/apps/mediaplayer/playlist/ImportPLItemsCommand.h @@ -15,7 +15,8 @@ public: ImportPLItemsCommand( Playlist* playlist, const BMessage* refsMessage, - int32 toIndex); + int32 toIndex, + bool sortItems); virtual ~ImportPLItemsCommand(); virtual status_t InitCheck(); diff --git a/src/apps/mediaplayer/playlist/Playlist.cpp b/src/apps/mediaplayer/playlist/Playlist.cpp index 998c3880ae..8dfa6499eb 100644 --- a/src/apps/mediaplayer/playlist/Playlist.cpp +++ b/src/apps/mediaplayer/playlist/Playlist.cpp @@ -417,7 +417,8 @@ Playlist::RemoveListener(Listener* listener) void -Playlist::AppendItems(const BMessage* refsReceivedMessage, int32 appendIndex) +Playlist::AppendItems(const BMessage* refsReceivedMessage, int32 appendIndex, + bool sortItems) { // the playlist is replaced by the refs in the message // or the refs are appended at the appendIndex @@ -434,7 +435,7 @@ Playlist::AppendItems(const BMessage* refsReceivedMessage, int32 appendIndex) Playlist temporaryPlaylist; Playlist* playlist = add ? &temporaryPlaylist : this; - bool sortPlaylist = true; + bool hasSavedPlaylist = false; // TODO: This is not very fair, we should abstract from // entry ref representation and support more URLs. @@ -456,7 +457,7 @@ Playlist::AppendItems(const BMessage* refsReceivedMessage, int32 appendIndex) AppendPlaylistToPlaylist(ref, &subPlaylist); // Do not sort the whole playlist anymore, as that // will screw up the ordering in the saved playlist. - sortPlaylist = false; + hasSavedPlaylist = true; } else { if (_IsQuery(type)) AppendQueryToPlaylist(ref, &subPlaylist); @@ -470,7 +471,7 @@ Playlist::AppendItems(const BMessage* refsReceivedMessage, int32 appendIndex) // At least sort this subsection of the playlist // if the whole playlist is not sorted anymore. - if (!sortPlaylist) + if (sortItems && hasSavedPlaylist) subPlaylist.Sort(); } @@ -483,7 +484,8 @@ Playlist::AppendItems(const BMessage* refsReceivedMessage, int32 appendIndex) AdoptPlaylist(subPlaylist, subAppendIndex); subAppendIndex += subPlaylistCount; } - if (sortPlaylist) + + if (sortItems) playlist->Sort(); if (add) diff --git a/src/apps/mediaplayer/playlist/Playlist.h b/src/apps/mediaplayer/playlist/Playlist.h index b2f5982047..35fb47b36d 100644 --- a/src/apps/mediaplayer/playlist/Playlist.h +++ b/src/apps/mediaplayer/playlist/Playlist.h @@ -95,7 +95,8 @@ public: // support functions void AppendItems(const BMessage* refsReceivedMessage, int32 appendIndex - = APPEND_INDEX_REPLACE_PLAYLIST); + = APPEND_INDEX_REPLACE_PLAYLIST, + bool sortItems = false); static void AppendToPlaylistRecursive(const entry_ref& ref, Playlist* playlist); diff --git a/src/apps/mediaplayer/playlist/PlaylistListView.cpp b/src/apps/mediaplayer/playlist/PlaylistListView.cpp index cc28fa5e45..98736c1a01 100644 --- a/src/apps/mediaplayer/playlist/PlaylistListView.cpp +++ b/src/apps/mediaplayer/playlist/PlaylistListView.cpp @@ -10,8 +10,11 @@ #include #include +#include #include +#include #include +#include #include #include #include @@ -32,13 +35,17 @@ #include "RandomizePLItemsCommand.h" #include "RemovePLItemsCommand.h" +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "MediaPlayer-PlaylistListView" using std::nothrow; enum { DISPLAY_NAME = 0, - DISPLAY_PATH = 1 + DISPLAY_PATH = 1, + M_ADD_SORTED, + M_ADD_UNSORTED }; @@ -237,6 +244,7 @@ PlaylistListView::PlaylistListView(BRect frame, Playlist* playlist, { fPlaylist->AddListener(fPlaylistObserver); fController->AddListener(fControllerObserver); + _AddDropContextMenu(); SetFlags(Flags() | B_SUBPIXEL_PRECISE); } @@ -267,7 +275,6 @@ PlaylistListView::AttachedToWindow() void PlaylistListView::MessageReceived(BMessage* message) { -// message->PrintToStream(); switch (message->what) { // PlaylistObserver messages case MSG_PLAYLIST_ITEM_ADDED: @@ -508,8 +515,18 @@ PlaylistListView::DrawListItem(BView* owner, int32 index, BRect frame) const void PlaylistListView::ItemsReceived(const BMessage* message, int32 appendIndex) { + BPoint dropPoint; + bool sorting = false; + entry_ref ref; + + if (message->FindRef("refs", 1, &ref) == B_OK + && message->FindPoint("_drop_point_", &dropPoint) == B_OK + && message->GetInt32("buttons", 0) == 2) + if (_ShowDropContextMenu(dropPoint) == M_ADD_SORTED) + sorting = true; + if (fCommandStack->Perform(new (nothrow) ImportPLItemsCommand(fPlaylist, - message, appendIndex)) != B_OK) { + message, appendIndex, sorting)) != B_OK) { fPlaylist->NotifyImportFailed(); } } @@ -656,3 +673,27 @@ PlaylistListView::_SetPlaybackState(uint32 state) } +void +PlaylistListView::_AddDropContextMenu() +{ + fDropContextMenu = new BPopUpMenu("DropContext"); + + fDropContextMenu->AddItem(new BMenuItem(B_TRANSLATE("Add sorted"), + new BMessage(M_ADD_SORTED))); + fDropContextMenu->AddItem(new BMenuItem(B_TRANSLATE("Add unsorted"), + new BMessage(M_ADD_UNSORTED))); +} + + +uint32 +PlaylistListView::_ShowDropContextMenu(BPoint dropPoint) +{ + BMenuItem* item; + + item = fDropContextMenu->Go(dropPoint, true, true); + if (item != NULL) + return item->Command(); + return 0; +} + + diff --git a/src/apps/mediaplayer/playlist/PlaylistListView.h b/src/apps/mediaplayer/playlist/PlaylistListView.h index fabdb0f38e..8c8c9808fa 100644 --- a/src/apps/mediaplayer/playlist/PlaylistListView.h +++ b/src/apps/mediaplayer/playlist/PlaylistListView.h @@ -8,6 +8,8 @@ #ifndef PLAYLIST_LIST_VIEW_H #define PLAYLIST_LIST_VIEW_H +#include + #include "ListViews.h" class CommandStack; @@ -63,6 +65,9 @@ private: void _SetCurrentPlaylistIndex(int32 index); void _SetPlaybackState(uint32 state); + void _AddDropContextMenu(); + uint32 _ShowDropContextMenu(BPoint loc); + Playlist* fPlaylist; PlaylistObserver* fPlaylistObserver; @@ -76,6 +81,8 @@ private: font_height fFontHeight; Item* fLastClickedItem; + + BPopUpMenu* fDropContextMenu; }; #endif // PLAYLIST_LIST_VIEW_H