diff --git a/src/browser.cpp b/src/browser.cpp index 02a54d09..d31a45cd 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -333,6 +333,28 @@ namespace } } +void Browser::LocateSong(const MPD::Song &s) +{ + if (s.GetDirectory().empty()) + return; + + Config.local_browser = !s.IsFromDB(); + + string option = s.toString(Config.song_status_format); + locale_to_utf(option); + if (itsBrowsedDir != s.GetDirectory()) + GetDirectory(s.GetDirectory()); + for (size_t i = 0; i < w->Size(); i++) + { + if (w->at(i).type == itSong && option == w->at(i).song->toString(Config.song_status_format)) + { + w->Highlight(i); + break; + } + } + SwitchTo(); +} + void Browser::GetDirectory(string dir, string subdir) { if (dir.empty()) diff --git a/src/browser.h b/src/browser.h index b7c667a9..0bbcfb5b 100644 --- a/src/browser.h +++ b/src/browser.h @@ -50,6 +50,7 @@ class Browser : public Screen< Menu > const std::string &CurrentDir() { return itsBrowsedDir; } + void LocateSong(const MPD::Song &); void GetDirectory(std::string, std::string = "/"); void ChangeBrowseMode(); void UpdateItemList(); diff --git a/src/help.cpp b/src/help.cpp index 32add389..b3b9f276 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -174,7 +174,7 @@ void Help::GetKeybindings() *w << DisplayKeys(Key.PrevFoundPosition) << "Go to previous found position\n"; *w << DisplayKeys(Key.NextFoundPosition) << "Go to next found position\n"; *w << DisplayKeys(Key.ToggleFindMode) << "Toggle find mode (normal/wrapped)\n"; - *w << DisplayKeys(Key.GoToContainingDir) << "Go to directory containing current item\n"; + *w << DisplayKeys(Key.GoToContainingDir) << "Locate song in browser\n"; *w << DisplayKeys(Key.ToggleDisplayMode) << "Toggle display mode\n"; # ifdef HAVE_TAGLIB_H *w << DisplayKeys(Key.EditTags) << "Edit song's tags/playlist's name\n"; @@ -208,6 +208,7 @@ void Help::GetKeybindings() *w << DisplayKeys(Key.Space) << "Add item to playlist\n"; if (Mpd->GetHostname()[0] == '/') // are we connected to unix socket? *w << DisplayKeys(Key.SwitchTagTypeList) << "Browse MPD database/local filesystem\n"; + *w << DisplayKeys(Key.GoToNowPlaying) << "Locate currently playing song\n"; *w << DisplayKeys(Key.GoToParentDir) << "Go to parent directory\n"; *w << DisplayKeys(Key.Delete) << "Delete playlist\n\n\n"; diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index f0fff226..bec3613b 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -987,14 +987,21 @@ int main(int argc, char *argv[]) } else if (Keypressed(input, Key.GoToNowPlaying)) { - if (myScreen != myPlaylist || !myPlaylist->isPlaying()) - continue; - if (myPlaylist->Main()->isFiltered()) + if (myScreen == myPlaylist && myPlaylist->isPlaying()) { - ShowMessage("%s", MPD::Message::FunctionDisabledFilteringEnabled); - continue; + if (myPlaylist->Main()->isFiltered()) + { + ShowMessage("%s", MPD::Message::FunctionDisabledFilteringEnabled); + continue; + } + myPlaylist->Main()->Highlight(myPlaylist->NowPlaying); + } + else if (myScreen == myBrowser) + { + const Song *s = myPlaylist->NowPlayingSong(); + if (s) + myBrowser->LocateSong(*s); } - myPlaylist->Main()->Highlight(myPlaylist->NowPlaying); } else if (Keypressed(input, Key.ToggleRepeat)) { @@ -1189,24 +1196,8 @@ int main(int argc, char *argv[]) else if (Keypressed(input, Key.GoToContainingDir)) { Song *s = myScreen->CurrentSong(); - - if (!s || s->GetDirectory().empty()) - continue; - - Config.local_browser = !s->IsFromDB(); - - string option = s->toString(Config.song_status_format); - locale_to_utf(option); - myBrowser->GetDirectory(s->GetDirectory()); - for (size_t i = 0; i < myBrowser->Main()->Size(); i++) - { - if (myBrowser->Main()->at(i).type == itSong && option == myBrowser->Main()->at(i).song->toString(Config.song_status_format)) - { - myBrowser->Main()->Highlight(i); - break; - } - } - myBrowser->SwitchTo(); + if (s) + myBrowser->LocateSong(*s); } else if (Keypressed(input, Key.StartSearching)) {