new feature: locate song in tag editor

This commit is contained in:
Andrzej Rybczak
2010-05-14 01:14:45 +02:00
parent b6e6ab1f61
commit e978cfcc8b
6 changed files with 73 additions and 0 deletions

View File

@@ -204,6 +204,9 @@ void Help::GetKeybindings()
*w << DisplayKeys(Key.ToggleFindMode) << "Toggle find mode (normal/wrapped)\n"; *w << DisplayKeys(Key.ToggleFindMode) << "Toggle find mode (normal/wrapped)\n";
*w << DisplayKeys(Key.GoToContainingDir) << "Locate song in browser\n"; *w << DisplayKeys(Key.GoToContainingDir) << "Locate song in browser\n";
*w << DisplayKeys(Key.GoToMediaLibrary) << "Locate current song in media library\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.ToggleDisplayMode) << "Toggle display mode\n";
*w << DisplayKeys(Key.ToggleInterface) << "Toggle user interface\n"; *w << DisplayKeys(Key.ToggleInterface) << "Toggle user interface\n";
*w << DisplayKeys(Key.GoToPosition) << "Go to given position in current song (in % by default)\n"; *w << DisplayKeys(Key.GoToPosition) << "Go to given position in current song (in % by default)\n";

View File

@@ -1614,6 +1614,14 @@ int main(int argc, char *argv[])
if (s) if (s)
myLibrary->LocateSong(*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)) else if (Keypressed(input, Key.GoToPosition))
{ {
if (!Mpd.GetTotalTime()) if (!Mpd.GetTotalTime())

View File

@@ -224,6 +224,7 @@ void NcmpcppKeys::SetDefaults()
GoToNowPlaying[0] = 'o'; GoToNowPlaying[0] = 'o';
GoToContainingDir[0] = 'G'; GoToContainingDir[0] = 'G';
GoToMediaLibrary[0] = '~'; GoToMediaLibrary[0] = '~';
GoToTagEditor[0] = 'E';
ToggleAutoCenter[0] = 'U'; ToggleAutoCenter[0] = 'U';
ToggleDisplayMode[0] = 'p'; ToggleDisplayMode[0] = 'p';
ToggleInterface[0] = '\\'; ToggleInterface[0] = '\\';
@@ -303,6 +304,7 @@ void NcmpcppKeys::SetDefaults()
GoToNowPlaying[1] = NullKey; GoToNowPlaying[1] = NullKey;
GoToContainingDir[1] = NullKey; GoToContainingDir[1] = NullKey;
GoToMediaLibrary[1] = NullKey; GoToMediaLibrary[1] = NullKey;
GoToTagEditor[1] = NullKey;
ToggleAutoCenter[1] = NullKey; ToggleAutoCenter[1] = NullKey;
ToggleDisplayMode[1] = NullKey; ToggleDisplayMode[1] = NullKey;
ToggleInterface[1] = NullKey; ToggleInterface[1] = NullKey;

View File

@@ -128,6 +128,7 @@ struct NcmpcppKeys
int GoToNowPlaying[2]; int GoToNowPlaying[2];
int GoToContainingDir[2]; int GoToContainingDir[2];
int GoToMediaLibrary[2]; int GoToMediaLibrary[2];
int GoToTagEditor[2];
int ToggleAutoCenter[2]; int ToggleAutoCenter[2];
int ToggleDisplayMode[2]; int ToggleDisplayMode[2];
int ToggleInterface[2]; int ToggleInterface[2];

View File

@@ -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) void TagEditor::ReadTags(MPD::Song &s)
{ {
TagLib::FileRef f(s.GetFile().c_str()); TagLib::FileRef f(s.GetFile().c_str());

View File

@@ -68,6 +68,8 @@ class TagEditor : public Screen<Window>
void NextColumn(); void NextColumn();
void PrevColumn(); void PrevColumn();
void LocateSong(const MPD::Song &s);
Menu<string_pair> *LeftColumn; Menu<string_pair> *LeftColumn;
Menu<string_pair> *Albums; Menu<string_pair> *Albums;
Menu<string_pair> *Dirs; Menu<string_pair> *Dirs;