MediaPlayer: Added simple shortcuts to playlist.

Fixes #6562.

Signed-off-by: Augustin Cavalier <[email protected]>
I tweaked some coding style and added back the missing
B_BACKSPACE shortcut.
This commit is contained in:
Guillermo Bonvehi
2015-12-17 16:52:38 -05:00
committed by Augustin Cavalier
parent a89ac5a653
commit 937aabf5a1
2 changed files with 94 additions and 3 deletions
@@ -363,10 +363,98 @@ PlaylistListView::KeyDown(const char* bytes, int32 numBytes)
if (numBytes < 1)
return;
if ((bytes[0] == B_BACKSPACE) || (bytes[0] == B_DELETE))
RemoveSelected();
BMessage* msg = Window()->CurrentMessage();
uint32 modifier = msg->FindInt32("modifiers");
DragSortableListView::KeyDown(bytes, numBytes);
int32 count;
int32 index;
switch (bytes[0]) {
case B_SPACE:
fController->TogglePlaying();
break;
case B_BACKSPACE:
case B_DELETE:
RemoveSelected();
break;
case B_ENTER:
count = CountItems();
if (count == 0)
break;
index = CurrentSelection(0);
if (index < 0)
break;
fPlaylist->SetCurrentItemIndex(index, true);
fController->Play();
break;
case B_ESCAPE:
fController->Stop();
break;
case B_RIGHT_ARROW:
if ((modifier & B_SHIFT_KEY) != 0)
_Wind(30000000LL, 5);
else
_Wind(5000000LL, 1);
break;
case B_LEFT_ARROW:
if ((modifier & B_SHIFT_KEY) != 0)
_Wind(-30000000LL, -5);
else
_Wind(-5000000LL, -1);
break;
default:
DragSortableListView::KeyDown(bytes, numBytes);
}
}
void
PlaylistListView::SkipBackward()
{
BAutolock _(fPlaylist);
int32 index = fPlaylist->CurrentItemIndex() - 1;
if (index < 0)
index = 0;
fPlaylist->SetCurrentItemIndex(index, true);
}
void
PlaylistListView::SkipForward()
{
BAutolock _(fPlaylist);
int32 index = fPlaylist->CurrentItemIndex() + 1;
if (index >= fPlaylist->CountItems())
index = fPlaylist->CountItems() - 1;
fPlaylist->SetCurrentItemIndex(index, true);
}
void
PlaylistListView::_Wind(bigtime_t howMuch, int64 frames)
{
if (!fController->Lock())
return;
if (frames != 0 && !fController->IsPlaying()) {
int64 newFrame = fController->CurrentFrame() + frames;
fController->SetFramePosition(newFrame);
} else {
bigtime_t seekTime = fController->TimePosition() + howMuch;
if (seekTime < 0) {
SkipBackward();
} else if (seekTime > fController->TimeDuration()) {
SkipForward();
} else
fController->SetTimePosition(seekTime);
}
fController->Unlock();
}
@@ -49,10 +49,13 @@ public:
void RemoveToTrash(int32 index);
void RemoveItemList(const BList& indices,
bool intoTrash);
virtual void SkipBackward();
virtual void SkipForward();
private:
class Item;
void _Wind(bigtime_t howMuch, int64 frames);
void _FullSync();
void _AddItem(PlaylistItem* item, int32 index);
void _RemoveItem(int32 index);