add new movement keys: {Up,Down}{Album,Artist}

This commit is contained in:
Frank Blendinger
2010-03-04 15:10:58 +01:00
parent 331107387c
commit 6b5ed187a1
7 changed files with 162 additions and 0 deletions

View File

@@ -16,6 +16,14 @@
#
#key_down = 258 'j'
#
#key_up_album = '['
#
#key_down_album = ']'
#
#key_up_artist = '{'
#
#key_down_artist = '}'
#
#key_page_up = 339
#
#key_page_down = 338

View File

@@ -133,6 +133,10 @@ void Help::GetKeybindings()
*w << " " << fmtBold << "Keys - Movement\n -----------------------------------------\n" << fmtBoldEnd;
*w << DisplayKeys(Key.Up) << "Move Cursor up\n";
*w << DisplayKeys(Key.Down) << "Move Cursor down\n";
*w << DisplayKeys(Key.UpAlbum) << "Move Cursor up one album\n";
*w << DisplayKeys(Key.DownAlbum) << "Move Cursor down one album\n";
*w << DisplayKeys(Key.UpArtist) << "Move Cursor up one artist\n";
*w << DisplayKeys(Key.DownArtist) << "Move Cursor down one artist\n";
*w << DisplayKeys(Key.PageUp) << "Page up\n";
*w << DisplayKeys(Key.PageDown) << "Page down\n";
*w << DisplayKeys(Key.Home) << "Home\n";

View File

@@ -439,6 +439,51 @@ int main(int argc, char *argv[])
{
myScreen->Scroll(wDown, Key.Down);
}
else if (Keypressed(input, Key.UpAlbum) || Keypressed(input, Key.DownAlbum)
|| Keypressed(input, Key.UpArtist) || Keypressed(input, Key.DownArtist))
{
Menu<MPD::Song> *songs = NULL;
if (myScreen == myPlaylist && !myPlaylist->Items->Empty())
songs = myPlaylist->Items;
else if (myScreen->ActiveWindow() == myPlaylistEditor->Content)
songs = myPlaylistEditor->Content;
else if (myScreen == mySearcher)
mySearcher->Scroll(input);
if (songs && !songs->Empty())
{
size_t pos = songs->Choice();
if (Keypressed(input, Key.UpAlbum))
{
std::string album = songs->at(pos).GetAlbum();
while (pos > 0)
if (songs->at(--pos).GetAlbum() != album)
break;
}
else if (Keypressed(input, Key.DownAlbum))
{
std::string album = songs->at(pos).GetAlbum();
while (pos < songs->Size() - 1)
if (songs->at(++pos).GetAlbum() != album)
break;
}
else if (Keypressed(input, Key.UpArtist))
{
std::string artist = songs->at(pos).GetArtist();
while (pos > 0)
if (songs->at(--pos).GetArtist() != artist)
break;
}
else if (Keypressed(input, Key.DownArtist))
{
std::string artist = songs->at(pos).GetArtist();
while (pos < songs->Size() - 1)
if (songs->at(++pos).GetArtist() != artist)
break;
}
songs->Highlight(pos);
}
}
else if (Keypressed(input, Key.PageUp))
{
myScreen->Scroll(wPageUp, Key.PageUp);

View File

@@ -264,6 +264,90 @@ void SearchEngine::UpdateFoundList()
}
}
void SearchEngine::Scroll(int input)
{
size_t pos = w->Choice();
size_t oldpos = pos;
//w->Goto(pos);
//w->Goto(pos2);
//std::string album = w->at(pos).second->GetAlbum();
//ShowMessage("pos (choice): %i / pos2 (realchoice): %i / album: %s", pos, pos2, album.c_str());
//return;
// above the reset button
if (pos < StaticOptions - 4)
{
if (Keypressed(input, Key.UpAlbum) ||
Keypressed(input, Key.UpArtist))
w->Highlight(0);
else if (Keypressed(input, Key.DownAlbum) ||
Keypressed(input, Key.DownArtist))
w->Highlight(StaticOptions - 4); // reset
return;
}
// reset button
if (pos == StaticOptions - 4)
{
if (Keypressed(input, Key.UpAlbum) ||
Keypressed(input, Key.UpArtist))
w->Highlight(0);
else if (Keypressed(input, Key.DownAlbum) ||
Keypressed(input, Key.DownArtist))
w->Highlight(StaticOptions); // first search result
return;
}
// first search result
if (pos == StaticOptions)
{
if (Keypressed(input, Key.UpAlbum))
{
w->Highlight(StaticOptions - 4); // reset
return;
}
else if (Keypressed(input, Key.UpArtist))
{
w->Highlight(0);
return;
}
}
// we are in the search results at this point
if (pos >= StaticOptions)
{
if (Keypressed(input, Key.UpAlbum))
{
std::string album = w->at(pos).second->GetAlbum();
while (pos > StaticOptions)
if (w->at(--pos).second->GetAlbum() != album)
break;
}
else if (Keypressed(input, Key.DownAlbum))
{
std::string album = w->at(pos).second->GetAlbum();
while (pos < w->Size() - 1)
if (w->at(++pos).second->GetAlbum() != album)
break;
}
else if (Keypressed(input, Key.UpArtist))
{
std::string artist = w->at(pos).second->GetArtist();
while (pos > StaticOptions)
if (w->at(--pos).second->GetArtist() != artist)
break;
}
else if (Keypressed(input, Key.DownArtist))
{
std::string artist = w->at(pos).second->GetArtist();
while (pos < w->Size() - 1)
if (w->at(++pos).second->GetArtist() != artist)
break;
}
w->Highlight(pos);
}
}
void SearchEngine::Prepare()
{
for (size_t i = 0; i < w->Size(); ++i)

View File

@@ -48,6 +48,7 @@ class SearchEngine : public Screen< Menu< std::pair<Buffer *, MPD::Song *> > >
virtual List *GetList() { return w->Size() >= StaticOptions ? w : 0; }
void UpdateFoundList();
void Scroll(int);
static size_t StaticOptions;
static size_t SearchButton;

View File

@@ -150,6 +150,10 @@ void NcmpcppKeys::SetDefaults()
{
Up[0] = KEY_UP;
Down[0] = KEY_DOWN;
UpAlbum[0] = '[';
DownAlbum[0] = ']';
UpArtist[0] = '{';
DownArtist[0] = '}';
PageUp[0] = KEY_PPAGE;
PageDown[0] = KEY_NPAGE;
Home[0] = KEY_HOME;
@@ -224,6 +228,10 @@ void NcmpcppKeys::SetDefaults()
Up[1] = 'k';
Down[1] = 'j';
UpAlbum[1] = null_key;
DownAlbum[1] = null_key;
UpArtist[1] = null_key;
DownArtist[1] = null_key;
PageUp[1] = null_key;
PageDown[1] = null_key;
Home[1] = null_key;
@@ -418,6 +426,14 @@ void NcmpcppKeys::Read()
GetKeys(key, Up);
else if (key.find("key_down ") != std::string::npos)
GetKeys(key, Down);
else if (key.find("key_up_album ") != std::string::npos)
GetKeys(key, UpAlbum);
else if (key.find("key_down_album ") != std::string::npos)
GetKeys(key, DownAlbum);
else if (key.find("key_up_artist ") != std::string::npos)
GetKeys(key, UpArtist);
else if (key.find("key_down_artist ") != std::string::npos)
GetKeys(key, DownArtist);
else if (key.find("key_page_up ") != std::string::npos)
GetKeys(key, PageUp);
else if (key.find("key_page_down ") != std::string::npos)

View File

@@ -59,6 +59,10 @@ struct NcmpcppKeys
int Up[2];
int Down[2];
int UpAlbum[2];
int DownAlbum[2];
int UpArtist[2];
int DownArtist[2];
int PageUp[2];
int PageDown[2];
int Home[2];