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,
|
ImportPLItemsCommand::ImportPLItemsCommand(Playlist* playlist,
|
||||||
const BMessage* refsMessage, int32 toIndex)
|
const BMessage* refsMessage, int32 toIndex, bool sortItems)
|
||||||
:
|
:
|
||||||
PLItemsCommand(),
|
PLItemsCommand(),
|
||||||
fPlaylist(playlist),
|
fPlaylist(playlist),
|
||||||
@@ -45,7 +45,7 @@ ImportPLItemsCommand::ImportPLItemsCommand(Playlist* playlist,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Playlist temp;
|
Playlist temp;
|
||||||
temp.AppendItems(refsMessage);
|
temp.AppendItems(refsMessage, APPEND_INDEX_REPLACE_PLAYLIST, sortItems);
|
||||||
|
|
||||||
fNewCount = temp.CountItems();
|
fNewCount = temp.CountItems();
|
||||||
if (fNewCount <= 0)
|
if (fNewCount <= 0)
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ public:
|
|||||||
ImportPLItemsCommand(
|
ImportPLItemsCommand(
|
||||||
Playlist* playlist,
|
Playlist* playlist,
|
||||||
const BMessage* refsMessage,
|
const BMessage* refsMessage,
|
||||||
int32 toIndex);
|
int32 toIndex,
|
||||||
|
bool sortItems);
|
||||||
virtual ~ImportPLItemsCommand();
|
virtual ~ImportPLItemsCommand();
|
||||||
|
|
||||||
virtual status_t InitCheck();
|
virtual status_t InitCheck();
|
||||||
|
|||||||
@@ -417,7 +417,8 @@ Playlist::RemoveListener(Listener* listener)
|
|||||||
|
|
||||||
|
|
||||||
void
|
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
|
// the playlist is replaced by the refs in the message
|
||||||
// or the refs are appended at the appendIndex
|
// or the refs are appended at the appendIndex
|
||||||
@@ -434,7 +435,7 @@ Playlist::AppendItems(const BMessage* refsReceivedMessage, int32 appendIndex)
|
|||||||
|
|
||||||
Playlist temporaryPlaylist;
|
Playlist temporaryPlaylist;
|
||||||
Playlist* playlist = add ? &temporaryPlaylist : this;
|
Playlist* playlist = add ? &temporaryPlaylist : this;
|
||||||
bool sortPlaylist = true;
|
bool hasSavedPlaylist = false;
|
||||||
|
|
||||||
// TODO: This is not very fair, we should abstract from
|
// TODO: This is not very fair, we should abstract from
|
||||||
// entry ref representation and support more URLs.
|
// entry ref representation and support more URLs.
|
||||||
@@ -456,7 +457,7 @@ Playlist::AppendItems(const BMessage* refsReceivedMessage, int32 appendIndex)
|
|||||||
AppendPlaylistToPlaylist(ref, &subPlaylist);
|
AppendPlaylistToPlaylist(ref, &subPlaylist);
|
||||||
// Do not sort the whole playlist anymore, as that
|
// Do not sort the whole playlist anymore, as that
|
||||||
// will screw up the ordering in the saved playlist.
|
// will screw up the ordering in the saved playlist.
|
||||||
sortPlaylist = false;
|
hasSavedPlaylist = true;
|
||||||
} else {
|
} else {
|
||||||
if (_IsQuery(type))
|
if (_IsQuery(type))
|
||||||
AppendQueryToPlaylist(ref, &subPlaylist);
|
AppendQueryToPlaylist(ref, &subPlaylist);
|
||||||
@@ -470,7 +471,7 @@ Playlist::AppendItems(const BMessage* refsReceivedMessage, int32 appendIndex)
|
|||||||
|
|
||||||
// At least sort this subsection of the playlist
|
// At least sort this subsection of the playlist
|
||||||
// if the whole playlist is not sorted anymore.
|
// if the whole playlist is not sorted anymore.
|
||||||
if (!sortPlaylist)
|
if (sortItems && hasSavedPlaylist)
|
||||||
subPlaylist.Sort();
|
subPlaylist.Sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,7 +484,8 @@ Playlist::AppendItems(const BMessage* refsReceivedMessage, int32 appendIndex)
|
|||||||
AdoptPlaylist(subPlaylist, subAppendIndex);
|
AdoptPlaylist(subPlaylist, subAppendIndex);
|
||||||
subAppendIndex += subPlaylistCount;
|
subAppendIndex += subPlaylistCount;
|
||||||
}
|
}
|
||||||
if (sortPlaylist)
|
|
||||||
|
if (sortItems)
|
||||||
playlist->Sort();
|
playlist->Sort();
|
||||||
|
|
||||||
if (add)
|
if (add)
|
||||||
|
|||||||
@@ -95,7 +95,8 @@ public:
|
|||||||
// support functions
|
// support functions
|
||||||
void AppendItems(const BMessage* refsReceivedMessage,
|
void AppendItems(const BMessage* refsReceivedMessage,
|
||||||
int32 appendIndex
|
int32 appendIndex
|
||||||
= APPEND_INDEX_REPLACE_PLAYLIST);
|
= APPEND_INDEX_REPLACE_PLAYLIST,
|
||||||
|
bool sortItems = false);
|
||||||
|
|
||||||
static void AppendToPlaylistRecursive(const entry_ref& ref,
|
static void AppendToPlaylistRecursive(const entry_ref& ref,
|
||||||
Playlist* playlist);
|
Playlist* playlist);
|
||||||
|
|||||||
@@ -10,8 +10,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
|
#include <Catalog.h>
|
||||||
#include <GradientLinear.h>
|
#include <GradientLinear.h>
|
||||||
|
#include <MenuItem.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
|
#include <PopUpMenu.h>
|
||||||
#include <ScrollBar.h>
|
#include <ScrollBar.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
#include <Shape.h>
|
#include <Shape.h>
|
||||||
@@ -32,13 +35,17 @@
|
|||||||
#include "RandomizePLItemsCommand.h"
|
#include "RandomizePLItemsCommand.h"
|
||||||
#include "RemovePLItemsCommand.h"
|
#include "RemovePLItemsCommand.h"
|
||||||
|
|
||||||
|
#undef B_TRANSLATION_CONTEXT
|
||||||
|
#define B_TRANSLATION_CONTEXT "MediaPlayer-PlaylistListView"
|
||||||
|
|
||||||
using std::nothrow;
|
using std::nothrow;
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
DISPLAY_NAME = 0,
|
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);
|
fPlaylist->AddListener(fPlaylistObserver);
|
||||||
fController->AddListener(fControllerObserver);
|
fController->AddListener(fControllerObserver);
|
||||||
|
_AddDropContextMenu();
|
||||||
|
|
||||||
SetFlags(Flags() | B_SUBPIXEL_PRECISE);
|
SetFlags(Flags() | B_SUBPIXEL_PRECISE);
|
||||||
}
|
}
|
||||||
@@ -267,7 +275,6 @@ PlaylistListView::AttachedToWindow()
|
|||||||
void
|
void
|
||||||
PlaylistListView::MessageReceived(BMessage* message)
|
PlaylistListView::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
// message->PrintToStream();
|
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
// PlaylistObserver messages
|
// PlaylistObserver messages
|
||||||
case MSG_PLAYLIST_ITEM_ADDED:
|
case MSG_PLAYLIST_ITEM_ADDED:
|
||||||
@@ -508,8 +515,18 @@ PlaylistListView::DrawListItem(BView* owner, int32 index, BRect frame) const
|
|||||||
void
|
void
|
||||||
PlaylistListView::ItemsReceived(const BMessage* message, int32 appendIndex)
|
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,
|
if (fCommandStack->Perform(new (nothrow) ImportPLItemsCommand(fPlaylist,
|
||||||
message, appendIndex)) != B_OK) {
|
message, appendIndex, sorting)) != B_OK) {
|
||||||
fPlaylist->NotifyImportFailed();
|
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
|
#ifndef PLAYLIST_LIST_VIEW_H
|
||||||
#define PLAYLIST_LIST_VIEW_H
|
#define PLAYLIST_LIST_VIEW_H
|
||||||
|
|
||||||
|
#include <PopUpMenu.h>
|
||||||
|
|
||||||
#include "ListViews.h"
|
#include "ListViews.h"
|
||||||
|
|
||||||
class CommandStack;
|
class CommandStack;
|
||||||
@@ -63,6 +65,9 @@ private:
|
|||||||
void _SetCurrentPlaylistIndex(int32 index);
|
void _SetCurrentPlaylistIndex(int32 index);
|
||||||
void _SetPlaybackState(uint32 state);
|
void _SetPlaybackState(uint32 state);
|
||||||
|
|
||||||
|
void _AddDropContextMenu();
|
||||||
|
uint32 _ShowDropContextMenu(BPoint loc);
|
||||||
|
|
||||||
Playlist* fPlaylist;
|
Playlist* fPlaylist;
|
||||||
PlaylistObserver* fPlaylistObserver;
|
PlaylistObserver* fPlaylistObserver;
|
||||||
|
|
||||||
@@ -76,6 +81,8 @@ private:
|
|||||||
|
|
||||||
font_height fFontHeight;
|
font_height fFontHeight;
|
||||||
Item* fLastClickedItem;
|
Item* fLastClickedItem;
|
||||||
|
|
||||||
|
BPopUpMenu* fDropContextMenu;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLAYLIST_LIST_VIEW_H
|
#endif // PLAYLIST_LIST_VIEW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user