* Implemented a "refs catcher" that will catch refs received through a
B_REFS_RECEIVED within a short amount of time (0.5 seconds right now) and send them to the last window to be appended to the playlist. This allows to select multiple media files in Tracker and get them inside a playlist of a single window instead of spawning many individual ones (like when filtering for an album, selecting all tracks and opening them by hitting enter). * Introduce special append index values APPEND_INDEX_REPLACE_PLAYLIST (-1, does the same as before) and APPEND_INDEX_APPEND_LAST. The latter is used when appending through a RefsReceived() call and ensures that the index is evaluated at the actual insertion time (in ImportPLItemsCommand::Perform()) as by the time this function is called the playlist count may have changed already due to multiple RefsReceived() invokations, which would then mess up the order. This makes the above item work as expected. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35352 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
497aa62c2f
commit
eeeef45c69
@ -196,9 +196,40 @@ MainApp::RefsReceived(BMessage* message)
|
||||
// or double clicked a file that's handled by this app.
|
||||
// Command line arguments are also redirected to here by
|
||||
// ArgvReceived() but without MIME type check.
|
||||
// For each file we create a new window and send it a
|
||||
// B_REFS_RECEIVED message with a single file.
|
||||
NewWindow(message);
|
||||
|
||||
// If multiple refs are received in short succession we
|
||||
// combine them into a single window/playlist. Tracker
|
||||
// will send multiple messages when opening a multi-
|
||||
// selection for example and we don't want to spawn large
|
||||
// numbers of windows when someone just tries to open an
|
||||
// album. We use half a second time and prolong it for
|
||||
// each new ref received.
|
||||
static bigtime_t sLastRefsReceived = 0;
|
||||
static MainWin* sLastRefsWindow = NULL;
|
||||
|
||||
if (system_time() - sLastRefsReceived < 500000) {
|
||||
// Find the last opened window
|
||||
for (int32 i = CountWindows() - 1; i >= 0; i--) {
|
||||
MainWin* playerWindow = dynamic_cast<MainWin*>(WindowAt(i));
|
||||
if (playerWindow == NULL)
|
||||
continue;
|
||||
|
||||
if (playerWindow != sLastRefsWindow) {
|
||||
// The window has changed since the last refs
|
||||
sLastRefsReceived = 0;
|
||||
sLastRefsWindow = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
message->AddBool("append to playlist", true);
|
||||
playerWindow->PostMessage(message);
|
||||
sLastRefsReceived = system_time();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
sLastRefsWindow = NewWindow(message);
|
||||
sLastRefsReceived = system_time();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1122,9 +1122,13 @@ MainWin::_RefsReceived(BMessage* message)
|
||||
// the playlist is replaced by dropped files
|
||||
// or the dropped files are appended to the end
|
||||
// of the existing playlist if <shift> is pressed
|
||||
bool append = false;
|
||||
if (message->FindBool("append to playlist", &append) != B_OK)
|
||||
append = modifiers() & B_SHIFT_KEY;
|
||||
|
||||
BAutolock _(fPlaylist);
|
||||
int32 appendIndex = modifiers() & B_SHIFT_KEY ?
|
||||
fPlaylist->CountItems() : -1;
|
||||
int32 appendIndex = append ? APPEND_INDEX_APPEND_LAST
|
||||
: APPEND_INDEX_REPLACE_PLAYLIST;
|
||||
message->AddInt32("append_index", appendIndex);
|
||||
|
||||
// forward the message to the playlist window,
|
||||
|
@ -66,7 +66,7 @@ ImportPLItemsCommand::ImportPLItemsCommand(Playlist* playlist,
|
||||
|
||||
fPlaylingIndex = fPlaylist->CurrentItemIndex();
|
||||
|
||||
if (fToIndex < 0) {
|
||||
if (fToIndex == APPEND_INDEX_REPLACE_PLAYLIST) {
|
||||
fOldCount = fPlaylist->CountItems();
|
||||
if (fOldCount > 0) {
|
||||
fOldItems = new (nothrow) PlaylistItem*[fOldCount];
|
||||
@ -112,8 +112,11 @@ ImportPLItemsCommand::Perform()
|
||||
|
||||
fItemsAdded = true;
|
||||
|
||||
if (fToIndex == APPEND_INDEX_APPEND_LAST)
|
||||
fToIndex = fPlaylist->CountItems();
|
||||
|
||||
int32 index = fToIndex;
|
||||
if (fToIndex < 0) {
|
||||
if (fToIndex == APPEND_INDEX_REPLACE_PLAYLIST) {
|
||||
fPlaylist->MakeEmpty(false);
|
||||
index = 0;
|
||||
}
|
||||
@ -142,7 +145,7 @@ ImportPLItemsCommand::Undo()
|
||||
|
||||
fItemsAdded = false;
|
||||
|
||||
if (fToIndex < 0) {
|
||||
if (fToIndex == APPEND_INDEX_REPLACE_PLAYLIST) {
|
||||
// remove new items from playlist and restore old refs
|
||||
fPlaylist->MakeEmpty(false);
|
||||
for (int32 i = 0; i < fOldCount; i++) {
|
||||
|
@ -409,10 +409,13 @@ Playlist::RemoveListener(Listener* listener)
|
||||
void
|
||||
Playlist::AppendRefs(const BMessage* refsReceivedMessage, int32 appendIndex)
|
||||
{
|
||||
// the playlist ist 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
|
||||
// in the existing playlist
|
||||
bool add = appendIndex >= 0;
|
||||
if (appendIndex == APPEND_INDEX_APPEND_LAST)
|
||||
appendIndex = CountItems();
|
||||
|
||||
bool add = appendIndex != APPEND_INDEX_REPLACE_PLAYLIST;
|
||||
|
||||
if (!add)
|
||||
MakeEmpty();
|
||||
|
@ -33,6 +33,10 @@ class BString;
|
||||
struct entry_ref;
|
||||
|
||||
|
||||
// special append index values
|
||||
#define APPEND_INDEX_REPLACE_PLAYLIST -1
|
||||
#define APPEND_INDEX_APPEND_LAST -2
|
||||
|
||||
extern const uint32 kPlaylistMagicBytes;
|
||||
extern const char* kTextPlaylistMimeString;
|
||||
extern const char* kBinaryPlaylistMimeString;
|
||||
@ -95,7 +99,8 @@ public:
|
||||
|
||||
// support functions
|
||||
void AppendRefs(const BMessage* refsReceivedMessage,
|
||||
int32 appendIndex = -1);
|
||||
int32 appendIndex
|
||||
= APPEND_INDEX_REPLACE_PLAYLIST);
|
||||
static void AppendToPlaylistRecursive(const entry_ref& ref,
|
||||
Playlist* playlist);
|
||||
static void AppendPlaylistToPlaylist(const entry_ref& ref,
|
||||
|
@ -142,7 +142,7 @@ PlaylistWindow::MessageReceived(BMessage* message)
|
||||
|
||||
case B_REFS_RECEIVED:
|
||||
// Used for when we open a playlist from playlist window
|
||||
message->AddInt32("append_index", -1);
|
||||
message->AddInt32("append_index", APPEND_INDEX_REPLACE_PLAYLIST);
|
||||
case B_SIMPLE_DATA: {
|
||||
// only accept this message when it comes from the
|
||||
// player window, _not_ when it is dropped in this window
|
||||
|
Loading…
Reference in New Issue
Block a user