diff --git a/src/help.cpp b/src/help.cpp index 4b1d7f77..06a2b008 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -204,6 +204,9 @@ void Help::GetKeybindings() *w << DisplayKeys(Key.ToggleFindMode) << "Toggle find mode (normal/wrapped)\n"; *w << DisplayKeys(Key.GoToContainingDir) << "Locate song in browser\n"; *w << DisplayKeys(Key.GoToMediaLibrary) << "Locate current song in media library\n"; +# ifdef HAVE_TAGLIB_H + *w << DisplayKeys(Key.GoToTagEditor) << "Locate current song in tag editor\n"; +# endif // HAVE_TAGLIB_H *w << DisplayKeys(Key.ToggleDisplayMode) << "Toggle display mode\n"; *w << DisplayKeys(Key.ToggleInterface) << "Toggle user interface\n"; *w << DisplayKeys(Key.GoToPosition) << "Go to given position in current song (in % by default)\n"; diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 0dc76e8b..d1dfd72f 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -1614,6 +1614,14 @@ int main(int argc, char *argv[]) if (s) myLibrary->LocateSong(*s); } +# ifdef HAVE_TAGLIB_H + else if (Keypressed(input, Key.GoToTagEditor)) + { + CHECK_MPD_MUSIC_DIR; + if (Song *s = myScreen->CurrentSong()) + myTagEditor->LocateSong(*s); + } +# endif // HAVE_TAGLIB_H else if (Keypressed(input, Key.GoToPosition)) { if (!Mpd.GetTotalTime()) diff --git a/src/settings.cpp b/src/settings.cpp index 2c0ec045..c9e141b8 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -224,6 +224,7 @@ void NcmpcppKeys::SetDefaults() GoToNowPlaying[0] = 'o'; GoToContainingDir[0] = 'G'; GoToMediaLibrary[0] = '~'; + GoToTagEditor[0] = 'E'; ToggleAutoCenter[0] = 'U'; ToggleDisplayMode[0] = 'p'; ToggleInterface[0] = '\\'; @@ -303,6 +304,7 @@ void NcmpcppKeys::SetDefaults() GoToNowPlaying[1] = NullKey; GoToContainingDir[1] = NullKey; GoToMediaLibrary[1] = NullKey; + GoToTagEditor[1] = NullKey; ToggleAutoCenter[1] = NullKey; ToggleDisplayMode[1] = NullKey; ToggleInterface[1] = NullKey; diff --git a/src/settings.h b/src/settings.h index e6b6d954..d2824630 100644 --- a/src/settings.h +++ b/src/settings.h @@ -128,6 +128,7 @@ struct NcmpcppKeys int GoToNowPlaying[2]; int GoToContainingDir[2]; int GoToMediaLibrary[2]; + int GoToTagEditor[2]; int ToggleAutoCenter[2]; int ToggleDisplayMode[2]; int ToggleInterface[2]; diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index e428367d..801292de 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -847,6 +847,63 @@ void TagEditor::PrevColumn() } } +void TagEditor::LocateSong(const MPD::Song &s) +{ + if (s.GetDirectory().empty()) + return; + + if (LeftColumn == Albums) + { + Config.albums_in_tag_editor = false; + if (w == LeftColumn) + w = Dirs; + LeftColumn = Dirs; + } + + if (Global::myScreen != this) + SwitchTo(); + + // go to right directory + if (itsBrowsedDir != s.GetDirectory()) + { + itsBrowsedDir = s.GetDirectory(); + itsBrowsedDir = itsBrowsedDir.substr(0, itsBrowsedDir.find('/')); + if (itsBrowsedDir.empty()) + itsBrowsedDir = "/"; + Dirs->Clear(); + Update(); + } + if (itsBrowsedDir == "/") + Dirs->Reset(); // go to the first pos, which is "." (music dir root) + + // highlight directory we need and get files from it + std::string dir = ExtractTopDirectory(s.GetDirectory()); + for (size_t i = 0; i < Dirs->Size(); ++i) + { + if ((*Dirs)[i].first == dir) + { + Dirs->Highlight(i); + break; + } + } + Tags->Clear(); + Update(); + + // go to the right column + NextColumn(); + NextColumn(); + + // highlight our file + for (size_t i = 0; i < Tags->Size(); ++i) + { + if ((*Tags)[i].GetHash() == s.GetHash()) + { + Tags->Highlight(i); + break; + } + } +} + void TagEditor::ReadTags(MPD::Song &s) { TagLib::FileRef f(s.GetFile().c_str()); diff --git a/src/tag_editor.h b/src/tag_editor.h index 1caa61e6..61c2404d 100644 --- a/src/tag_editor.h +++ b/src/tag_editor.h @@ -68,6 +68,8 @@ class TagEditor : public Screen void NextColumn(); void PrevColumn(); + void LocateSong(const MPD::Song &s); + Menu *LeftColumn; Menu *Albums; Menu *Dirs;