MediaPlayer: No automatic playlist sorting, sort through right-click drag
Disable automatic sorting of items dragged onto the playlist. Instead, offer sorting of new items by a submenu from a right-click drag. Change-Id: I8b7e241eb9a6335cdcebfc51267e5484f762e700 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3414 Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
59bd13bc5e
commit
516510a226
@@ -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)
|
||||
|
||||
@@ -15,7 +15,8 @@ public:
|
||||
ImportPLItemsCommand(
|
||||
Playlist* playlist,
|
||||
const BMessage* refsMessage,
|
||||
int32 toIndex);
|
||||
int32 toIndex,
|
||||
bool sortItems);
|
||||
virtual ~ImportPLItemsCommand();
|
||||
|
||||
virtual status_t InitCheck();
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -10,8 +10,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Autolock.h>
|
||||
#include <Catalog.h>
|
||||
#include <GradientLinear.h>
|
||||
#include <MenuItem.h>
|
||||
#include <Message.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <ScrollBar.h>
|
||||
#include <ScrollView.h>
|
||||
#include <Shape.h>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#ifndef PLAYLIST_LIST_VIEW_H
|
||||
#define PLAYLIST_LIST_VIEW_H
|
||||
|
||||
#include <PopUpMenu.h>
|
||||
|
||||
#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
|
||||
|
||||
Reference in New Issue
Block a user