fix highlighting and change search mode a bit

This commit is contained in:
unK
2008-08-29 01:39:03 +02:00
parent 8d8dadd2b1
commit f2bb625331
6 changed files with 52 additions and 30 deletions

View File

@@ -81,6 +81,8 @@
# #
#key_prev_found_position = ',' #key_prev_found_position = ','
# #
#key_toggle_find_mode = 'w'
#
#key_edit_tags = 'e' #key_edit_tags = 'e'
# #
#key_go_to_position = 'g' #key_go_to_position = 'g'

View File

@@ -70,12 +70,14 @@
# #
#browser_playlist_prefix = "[red]playlist[/red] " #browser_playlist_prefix = "[red]playlist[/red] "
# #
##### interface settings ##### ##### various settings #####
# #
#autocenter_mode = "no" #autocenter_mode = "no"
# #
#repeat_one_mode = "no" #repeat_one_mode = "no"
# #
#find_mode = "wrapped"
#
#header_visibility = "yes" #header_visibility = "yes"
# #
#statusbar_visibility = "yes" #statusbar_visibility = "yes"

View File

@@ -489,13 +489,11 @@ void Menu::Highlight(int which)
else else
return; return;
if (which >= itsHeight/2) if (which >= itsHeight/2 && itsOptions.size() > itsHeight)
{ {
itsBeginning = itsHighlight-itsHeight/2; itsBeginning = itsHighlight-itsHeight/2;
if (itsBeginning > itsOptions.size()-itsHeight) if (itsBeginning > itsOptions.size()-itsHeight)
itsBeginning = itsOptions.size()-itsHeight; itsBeginning = itsOptions.size()-itsHeight;
if (itsBeginning < 0)
itsBeginning = 0;
} }
else else
itsBeginning = 0; itsBeginning = 0;

View File

@@ -244,6 +244,7 @@ int main(int argc, char *argv[])
sHelp->Add(DisplayKeys(Key.FindBackward) + "Backward find\n"); sHelp->Add(DisplayKeys(Key.FindBackward) + "Backward find\n");
sHelp->Add(DisplayKeys(Key.PrevFoundPosition) + "Go to previous found position\n"); sHelp->Add(DisplayKeys(Key.PrevFoundPosition) + "Go to previous found position\n");
sHelp->Add(DisplayKeys(Key.NextFoundPosition) + "Go to next found position\n"); sHelp->Add(DisplayKeys(Key.NextFoundPosition) + "Go to next found position\n");
sHelp->Add(DisplayKeys(Key.ToggleFindMode) + "Toggle find mode\n");
sHelp->Add(DisplayKeys(Key.EditTags) + tag_screen_keydesc); sHelp->Add(DisplayKeys(Key.EditTags) + tag_screen_keydesc);
sHelp->Add(DisplayKeys(Key.GoToPosition) + "Go to chosen position in current song\n"); sHelp->Add(DisplayKeys(Key.GoToPosition) + "Go to chosen position in current song\n");
sHelp->Add(DisplayKeys(Key.Lyrics) + "Show/hide song's lyrics\n\n"); sHelp->Add(DisplayKeys(Key.Lyrics) + "Show/hide song's lyrics\n\n");
@@ -1549,7 +1550,7 @@ int main(int argc, char *argv[])
|| (current_screen == csSearcher && !vSearched.empty())) || (current_screen == csSearcher && !vSearched.empty()))
{ {
string how = Keypressed(input, Key.FindForward) ? "forward" : "backward"; string how = Keypressed(input, Key.FindForward) ? "forward" : "backward";
found_pos = 0; found_pos = -1;
vFoundPositions.clear(); vFoundPositions.clear();
Menu *mCurrent = static_cast<Menu *>(wCurrent); Menu *mCurrent = static_cast<Menu *>(wCurrent);
LOCK_STATUSBAR; LOCK_STATUSBAR;
@@ -1561,32 +1562,31 @@ int main(int argc, char *argv[])
continue; continue;
transform(findme.begin(), findme.end(), findme.begin(), tolower); transform(findme.begin(), findme.end(), findme.begin(), tolower);
if (Keypressed(input, Key.FindForward)) // forward for (int i = 1; i <= mCurrent->MaxChoice(); i++)
{ {
for (int i = mCurrent->GetChoice(); i <= mCurrent->MaxChoice(); i++) string name = mCurrent->GetOption(i);
transform(name.begin(), name.end(), name.begin(), tolower);
if (name.find(findme) != string::npos && !mCurrent->IsStatic(i))
{ {
string name = mCurrent->GetOption(i); vFoundPositions.push_back(i);
transform(name.begin(), name.end(), name.begin(), tolower); if (Keypressed(input, Key.FindForward)) // forward
if (name.find(findme) != string::npos && !mCurrent->IsStatic(i)) {
vFoundPositions.push_back(i); if (found_pos < 0 && i >= mCurrent->GetChoice())
} found_pos = vFoundPositions.size()-1;
} }
else // backward else // backward
{ {
for (int i = mCurrent->GetChoice(); i > 0; i--) if (i <= mCurrent->GetChoice())
{ found_pos = vFoundPositions.size()-1;
string name = mCurrent->GetOption(i); }
transform(name.begin(), name.end(), name.begin(), tolower);
if (name.find(findme) != string::npos && !mCurrent->IsStatic(i))
vFoundPositions.push_back(i);
} }
} }
if (vFoundPositions.empty()) if (Config.wrapped_search ? vFoundPositions.empty() : found_pos < 0)
ShowMessage("Unable to find \"" + findme + "\""); ShowMessage("Unable to find \"" + findme + "\"");
else else
{ {
mCurrent->Highlight(vFoundPositions.front()); mCurrent->Highlight(vFoundPositions[found_pos < 0 ? 0 : found_pos]);
mCurrent->Highlighting(1); mCurrent->Highlighting(1);
} }
} }
@@ -1602,19 +1602,29 @@ int main(int argc, char *argv[])
} }
catch (std::out_of_range) catch (std::out_of_range)
{ {
if (Keypressed(input, Key.NextFoundPosition)) if (Config.wrapped_search)
{ {
mCurrent->Highlight(vFoundPositions.front()); if (Keypressed(input, Key.NextFoundPosition))
found_pos = 0; {
mCurrent->Highlight(vFoundPositions.front());
found_pos = 0;
}
else
{
mCurrent->Highlight(vFoundPositions.back());
found_pos = vFoundPositions.size()-1;
}
} }
else else
{ found_pos = Keypressed(input, Key.NextFoundPosition) ? vFoundPositions.size()-1 : 0;
mCurrent->Highlight(vFoundPositions.back());
found_pos = vFoundPositions.size()-1;
}
} }
} }
} }
else if (Keypressed(input, Key.ToggleFindMode))
{
Config.wrapped_search = !Config.wrapped_search;
ShowMessage("Search mode: " + string(Config.wrapped_search ? "Wrapped" : "Normal"));
}
else if (Keypressed(input, Key.Lyrics)) else if (Keypressed(input, Key.Lyrics))
{ {
if (wCurrent == sLyrics) if (wCurrent == sLyrics)

View File

@@ -61,6 +61,7 @@ void DefaultKeys(ncmpcpp_keys &keys)
keys.FindBackward[0] = '?'; keys.FindBackward[0] = '?';
keys.NextFoundPosition[0] = '.'; keys.NextFoundPosition[0] = '.';
keys.PrevFoundPosition[0] = ','; keys.PrevFoundPosition[0] = ',';
keys.ToggleFindMode[0] = 'w';
keys.EditTags[0] = 'e'; keys.EditTags[0] = 'e';
keys.GoToPosition[0] = 'g'; keys.GoToPosition[0] = 'g';
keys.Lyrics[0] = 'l'; keys.Lyrics[0] = 'l';
@@ -109,6 +110,7 @@ void DefaultKeys(ncmpcpp_keys &keys)
keys.FindBackward[1] = null_key; keys.FindBackward[1] = null_key;
keys.NextFoundPosition[1] = null_key; keys.NextFoundPosition[1] = null_key;
keys.PrevFoundPosition[1] = null_key; keys.PrevFoundPosition[1] = null_key;
keys.ToggleFindMode[1] = null_key;
keys.EditTags[1] = null_key; keys.EditTags[1] = null_key;
keys.GoToPosition[1] = null_key; keys.GoToPosition[1] = null_key;
keys.Lyrics[1] = null_key; keys.Lyrics[1] = null_key;
@@ -147,6 +149,7 @@ void DefaultConfiguration(ncmpcpp_config &conf)
conf.statusbar_visibility = true; conf.statusbar_visibility = true;
conf.autocenter_mode = false; conf.autocenter_mode = false;
conf.repeat_one_mode = false; conf.repeat_one_mode = false;
conf.wrapped_search = true;
conf.set_window_title = true; conf.set_window_title = true;
conf.mpd_connection_timeout = 15; conf.mpd_connection_timeout = 15;
conf.crossfade_time = 5; conf.crossfade_time = 5;
@@ -330,6 +333,8 @@ void ReadKeys(ncmpcpp_keys &keys)
GetKeys(*it, keys.NextFoundPosition); GetKeys(*it, keys.NextFoundPosition);
else if (it->find("key_prev_found_position ") != string::npos) else if (it->find("key_prev_found_position ") != string::npos)
GetKeys(*it, keys.PrevFoundPosition); GetKeys(*it, keys.PrevFoundPosition);
else if (it->find("key_toggle_find_mode ") != string::npos)
GetKeys(*it, keys.ToggleFindMode);
else if (it->find("key_edit_tags ") != string::npos) else if (it->find("key_edit_tags ") != string::npos)
GetKeys(*it, keys.EditTags); GetKeys(*it, keys.EditTags);
else if (it->find("key_go_to_position ") != string::npos) else if (it->find("key_go_to_position ") != string::npos)
@@ -431,6 +436,9 @@ void ReadConfiguration(ncmpcpp_config &conf)
if (it->find("repeat_one_mode") != string::npos) if (it->find("repeat_one_mode") != string::npos)
conf.repeat_one_mode = v == "yes"; conf.repeat_one_mode = v == "yes";
if (it->find("find_mode") != string::npos)
conf.wrapped_search = v == "wrapped";
if (it->find("enable_window_title") != string::npos) if (it->find("enable_window_title") != string::npos)
conf.set_window_title = v == "yes"; conf.set_window_title = v == "yes";

View File

@@ -63,6 +63,7 @@ struct ncmpcpp_keys
int FindBackward[2]; int FindBackward[2];
int NextFoundPosition[2]; int NextFoundPosition[2];
int PrevFoundPosition[2]; int PrevFoundPosition[2];
int ToggleFindMode[2];
int EditTags[2]; int EditTags[2];
int GoToPosition[2]; int GoToPosition[2];
int Lyrics[2]; int Lyrics[2];
@@ -104,6 +105,7 @@ struct ncmpcpp_config
bool statusbar_visibility; bool statusbar_visibility;
bool autocenter_mode; bool autocenter_mode;
bool repeat_one_mode; bool repeat_one_mode;
bool wrapped_search;
int mpd_connection_timeout; int mpd_connection_timeout;
int crossfade_time; int crossfade_time;