fix searching with / and ? keys
This commit is contained in:
183
src/ncmpcpp.cpp
183
src/ncmpcpp.cpp
@@ -2974,62 +2974,151 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
else if (Keypressed(input, Key.FindForward) || Keypressed(input, Key.FindBackward))
|
else if (Keypressed(input, Key.FindForward) || Keypressed(input, Key.FindBackward))
|
||||||
{
|
{
|
||||||
if ((current_screen != csHelp && current_screen != csSearcher)
|
if ((current_screen == csHelp
|
||||||
|| (current_screen == csSearcher && !mSearcher->Current().first))
|
|| current_screen == csSearcher
|
||||||
|
|| current_screen == csTinyTagEditor
|
||||||
|
|| wCurrent == mEditorTagTypes)
|
||||||
|
&& (current_screen != csSearcher
|
||||||
|
|| mSearcher->Current().first))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
string how = Keypressed(input, Key.FindForward) ? "forward" : "backward";
|
||||||
|
found_pos = -1;
|
||||||
|
vFoundPositions.clear();
|
||||||
|
LockStatusbar();
|
||||||
|
Statusbar() << "Find " << how << ": ";
|
||||||
|
string findme = wFooter->GetString();
|
||||||
|
UnlockStatusbar();
|
||||||
|
timer = time(NULL);
|
||||||
|
if (findme.empty())
|
||||||
|
continue;
|
||||||
|
ToLower(findme);
|
||||||
|
|
||||||
|
ShowMessage("Searching...");
|
||||||
|
List *mList = reinterpret_cast<Menu<Song> *>(wCurrent);
|
||||||
|
for (size_t i = (wCurrent == mSearcher ? search_engine_static_options : 0); i < mList->Size(); i++)
|
||||||
{
|
{
|
||||||
string how = Keypressed(input, Key.FindForward) ? "forward" : "backward";
|
string name;
|
||||||
found_pos = -1;
|
switch (current_screen)
|
||||||
vFoundPositions.clear();
|
|
||||||
LockStatusbar();
|
|
||||||
Statusbar() << "Find " << how << ": ";
|
|
||||||
string findme = wFooter->GetString();
|
|
||||||
UnlockStatusbar();
|
|
||||||
timer = time(NULL);
|
|
||||||
if (findme.empty())
|
|
||||||
continue;
|
|
||||||
ToLower(findme);
|
|
||||||
|
|
||||||
ShowMessage("Searching...");
|
|
||||||
List *mList = reinterpret_cast<Menu<Song> *>(wCurrent);
|
|
||||||
for (size_t i = (wCurrent == mSearcher ? search_engine_static_options-1 : 0); i < mList->Size(); i++)
|
|
||||||
{
|
{
|
||||||
string name;
|
case csPlaylist:
|
||||||
switch (current_screen)
|
name = mPlaylist->at(i).toString(Config.song_list_format);
|
||||||
|
break;
|
||||||
|
case csBrowser:
|
||||||
|
switch (mBrowser->at(i).type)
|
||||||
|
{
|
||||||
|
case itDirectory:
|
||||||
|
name = mBrowser->at(i).name;
|
||||||
|
break;
|
||||||
|
case itSong:
|
||||||
|
name = mBrowser->at(i).song->toString(Config.song_list_format);
|
||||||
|
break;
|
||||||
|
case itPlaylist:
|
||||||
|
name = Config.browser_playlist_prefix.Str();
|
||||||
|
name += mBrowser->at(i).name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case csSearcher:
|
||||||
|
name = mSearcher->at(i).second->toString(Config.song_list_format);
|
||||||
|
break;
|
||||||
|
case csLibrary:
|
||||||
|
if (wCurrent == mLibArtists)
|
||||||
|
name = mLibArtists->at(i);
|
||||||
|
else if (wCurrent == mLibAlbums)
|
||||||
|
name = mLibAlbums->at(i).first;
|
||||||
|
else
|
||||||
|
name = mLibSongs->at(i).toString(Config.song_library_format);
|
||||||
|
break;
|
||||||
|
case csPlaylistEditor:
|
||||||
|
if (wCurrent == mPlaylistList)
|
||||||
|
name = mPlaylistList->at(i);
|
||||||
|
else
|
||||||
|
name = mPlaylistEditor->at(i).toString(Config.song_list_format);
|
||||||
|
break;
|
||||||
|
case csTagEditor:
|
||||||
|
if (wCurrent == mEditorLeftCol)
|
||||||
|
name = mEditorLeftCol->at(i).first;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const Song &s = mEditorTags->at(i);
|
||||||
|
switch (mEditorTagTypes->Choice())
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
name = s.GetTitle();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
name = s.GetArtist();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
name = s.GetAlbum();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
name = s.GetYear();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
name = s.GetTrack();
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
name = s.GetGenre();
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
name = s.GetComposer();
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
name = s.GetPerformer();
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
name = s.GetDisc();
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
name = s.GetComment();
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
if (s.GetNewName().empty())
|
||||||
|
name = s.GetName();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
name = s.GetName();
|
||||||
|
name += " -> ";
|
||||||
|
name += s.GetNewName();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ToLower(name);
|
||||||
|
if (name.find(findme) != string::npos && !mList->isStatic(i))
|
||||||
|
{
|
||||||
|
vFoundPositions.push_back(i);
|
||||||
|
if (Keypressed(input, Key.FindForward)) // forward
|
||||||
{
|
{
|
||||||
case csPlaylist:
|
if (found_pos < 0 && i >= mList->Choice())
|
||||||
name = mPlaylist->at(i).toString(Config.columns_in_playlist ? Config.song_columns_list_format : Config.song_list_format);
|
found_pos = vFoundPositions.size()-1;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
ToLower(name);
|
else // backward
|
||||||
if (name.find(findme) != string::npos && !mList->isStatic(i))
|
|
||||||
{
|
{
|
||||||
vFoundPositions.push_back(i);
|
if (i <= mList->Choice())
|
||||||
if (Keypressed(input, Key.FindForward)) // forward
|
found_pos = vFoundPositions.size()-1;
|
||||||
{
|
|
||||||
if (found_pos < 0 && i >= mList->Choice())
|
|
||||||
found_pos = vFoundPositions.size()-1;
|
|
||||||
}
|
|
||||||
else // backward
|
|
||||||
{
|
|
||||||
if (i <= mList->Choice())
|
|
||||||
found_pos = vFoundPositions.size()-1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ShowMessage("Searching finished!");
|
}
|
||||||
|
ShowMessage("Searching finished!");
|
||||||
|
|
||||||
if (Config.wrapped_search ? vFoundPositions.empty() : found_pos < 0)
|
if (Config.wrapped_search ? vFoundPositions.empty() : found_pos < 0)
|
||||||
ShowMessage("Unable to find \"%s\"", findme.c_str());
|
ShowMessage("Unable to find \"%s\"", findme.c_str());
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
mList->Highlight(vFoundPositions[found_pos < 0 ? 0 : found_pos]);
|
||||||
|
if (wCurrent == mPlaylist)
|
||||||
{
|
{
|
||||||
mList->Highlight(vFoundPositions[found_pos < 0 ? 0 : found_pos]);
|
timer = time(NULL);
|
||||||
if (wCurrent == mPlaylist)
|
mPlaylist->Highlighting(1);
|
||||||
{
|
|
||||||
timer = time(NULL);
|
|
||||||
mPlaylist->Highlighting(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user