new feature: allow searching in help, lyrics and info screens
This commit is contained in:
@@ -1596,32 +1596,46 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
List *mList = myScreen->GetList();
|
||||
|
||||
if (!mList)
|
||||
continue;
|
||||
|
||||
LockStatusbar();
|
||||
Statusbar() << "Find " << (Keypressed(input, Key.FindForward) ? "forward" : "backward") << ": ";
|
||||
string findme = wFooter->GetString(mList->GetSearchConstraint());
|
||||
UnlockStatusbar();
|
||||
myPlaylist->UpdateTimer();
|
||||
|
||||
if (!findme.empty())
|
||||
if (mList)
|
||||
{
|
||||
LockStatusbar();
|
||||
Statusbar() << "Find " << (Keypressed(input, Key.FindForward) ? "forward" : "backward") << ": ";
|
||||
string findme = wFooter->GetString(mList->GetSearchConstraint());
|
||||
UnlockStatusbar();
|
||||
myPlaylist->UpdateTimer();
|
||||
|
||||
if (!findme.empty())
|
||||
ShowMessage("Searching...");
|
||||
|
||||
bool success = mList->Search(findme, myScreen == mySearcher ? SearchEngine::StaticOptions : 0, REG_ICASE | Config.regex_type);
|
||||
|
||||
if (findme.empty())
|
||||
continue;
|
||||
|
||||
success ? ShowMessage("Searching finished!") : ShowMessage("Unable to find \"%s\"", findme.c_str());
|
||||
|
||||
if (Keypressed(input, Key.FindForward))
|
||||
mList->NextFound(Config.wrapped_search);
|
||||
else
|
||||
mList->PrevFound(Config.wrapped_search);
|
||||
|
||||
if (myScreen == myPlaylist)
|
||||
myPlaylist->EnableHighlighting();
|
||||
}
|
||||
else if (myScreen == myHelp || myScreen == myLyrics || myScreen == myInfo)
|
||||
{
|
||||
LockStatusbar();
|
||||
Statusbar() << "Find: ";
|
||||
string findme = wFooter->GetString();
|
||||
UnlockStatusbar();
|
||||
|
||||
ShowMessage("Searching...");
|
||||
|
||||
bool success = mList->Search(findme, myScreen == mySearcher ? SearchEngine::StaticOptions : 0, REG_ICASE | Config.regex_type);
|
||||
|
||||
if (findme.empty())
|
||||
continue;
|
||||
|
||||
success ? ShowMessage("Searching finished!") : ShowMessage("Unable to find \"%s\"", findme.c_str());
|
||||
|
||||
if (Keypressed(input, Key.FindForward))
|
||||
mList->NextFound(Config.wrapped_search);
|
||||
else
|
||||
mList->PrevFound(Config.wrapped_search);
|
||||
|
||||
if (myScreen == myPlaylist)
|
||||
myPlaylist->EnableHighlighting();
|
||||
Screen<Scrollpad> *s = static_cast<Screen<Scrollpad> *>(myScreen);
|
||||
s->Main()->RemoveFormatting(fmtReverse);
|
||||
s->Main()->RemoveFormatting(fmtReverseEnd);
|
||||
ShowMessage("%s", s->Main()->SetFormatting(fmtReverse, findme, fmtReverseEnd) || findme.empty() ? "Done!" : "No matching patterns found");
|
||||
s->Main()->Flush();
|
||||
}
|
||||
}
|
||||
else if (Keypressed(input, Key.NextFoundPosition) || Keypressed(input, Key.PrevFoundPosition))
|
||||
{
|
||||
|
||||
@@ -100,9 +100,9 @@ void Scrollpad::Flush()
|
||||
itsBuffer.SetTemp(0);
|
||||
}
|
||||
|
||||
void Scrollpad::SetFormatting(short vb, const std::basic_string<my_char_t> &s, short ve, bool for_each)
|
||||
bool Scrollpad::SetFormatting(short vb, const std::basic_string<my_char_t> &s, short ve, bool for_each)
|
||||
{
|
||||
itsBuffer.SetFormatting(vb, s, ve, for_each);
|
||||
return itsBuffer.SetFormatting(vb, s, ve, for_each);
|
||||
}
|
||||
|
||||
void Scrollpad::Recreate()
|
||||
|
||||
@@ -34,7 +34,8 @@ namespace NCurses
|
||||
virtual ~Scrollpad() { }
|
||||
|
||||
void Flush();
|
||||
void SetFormatting(short, const std::basic_string<my_char_t> &, short, bool for_each = 1);
|
||||
bool SetFormatting(short, const std::basic_string<my_char_t> &, short, bool for_each = 1);
|
||||
void RemoveFormatting(short value) { itsBuffer.RemoveFormatting(value); }
|
||||
std::basic_string<my_char_t> Content() { return itsBuffer.Str(); }
|
||||
|
||||
virtual void Refresh();
|
||||
@@ -52,7 +53,7 @@ namespace NCurses
|
||||
Scrollpad &operator<<(std::ostream &(*os)(std::ostream &));
|
||||
|
||||
# ifdef _UTF8
|
||||
void SetFormatting(short vb, const std::string &s, short ve, bool for_each = 1) { SetFormatting(vb, ToWString(s), ve, for_each); }
|
||||
bool SetFormatting(short vb, const std::string &s, short ve, bool for_each = 1) { return SetFormatting(vb, ToWString(s), ve, for_each); }
|
||||
Scrollpad &operator<<(const std::string &s);
|
||||
# endif // _UTF8
|
||||
|
||||
|
||||
@@ -39,6 +39,19 @@ namespace NCurses
|
||||
{
|
||||
return Position < f.Position;
|
||||
}
|
||||
|
||||
struct hasValue
|
||||
{
|
||||
hasValue(short value) : itsValue(value) { }
|
||||
|
||||
bool operator()(const FormatPos &fp)
|
||||
{
|
||||
return fp.Value == itsValue;
|
||||
}
|
||||
|
||||
private:
|
||||
short itsValue;
|
||||
};
|
||||
};
|
||||
|
||||
std::basic_ostringstream<C> itsString;
|
||||
@@ -50,7 +63,8 @@ namespace NCurses
|
||||
basic_buffer(const basic_buffer &b);
|
||||
|
||||
std::basic_string<C> Str() const;
|
||||
void SetFormatting(short vb, const std::basic_string<C> &s, short ve, bool for_each = 1);
|
||||
bool SetFormatting(short vb, const std::basic_string<C> &s, short ve, bool for_each = 1);
|
||||
void RemoveFormatting(short value);
|
||||
void SetTemp(std::basic_string<C> *);
|
||||
void Clear();
|
||||
|
||||
@@ -83,23 +97,34 @@ template <typename C> std::basic_string<C> NCurses::basic_buffer<C>::Str() const
|
||||
return itsString.str();
|
||||
}
|
||||
|
||||
template <typename C> void NCurses::basic_buffer<C>::SetFormatting(short vb, const std::basic_string<C> &s, short ve, bool for_each)
|
||||
template <typename C> bool NCurses::basic_buffer<C>::SetFormatting(short vb, const std::basic_string<C> &s, short ve, bool for_each)
|
||||
{
|
||||
if (s.empty())
|
||||
return false;
|
||||
bool result = false;
|
||||
std::basic_string<C> base = itsString.str();
|
||||
FormatPos fp;
|
||||
|
||||
for (size_t i = base.find(s); i != std::basic_string<C>::npos; i = base.find(s))
|
||||
for (size_t i = base.find(s); i != std::basic_string<C>::npos; i = base.find(s, i))
|
||||
{
|
||||
base[i] = 0;
|
||||
result = true;
|
||||
fp.Value = vb;
|
||||
fp.Position = i;
|
||||
itsFormat.push_back(fp);
|
||||
i += s.length();
|
||||
fp.Value = ve;
|
||||
fp.Position = i+s.length();
|
||||
fp.Position = i;
|
||||
itsFormat.push_back(fp);
|
||||
if (!for_each)
|
||||
break;
|
||||
}
|
||||
itsFormat.sort();
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename C> void NCurses::basic_buffer<C>::RemoveFormatting(short value)
|
||||
{
|
||||
itsFormat.remove_if(typename FormatPos::hasValue(value));
|
||||
}
|
||||
|
||||
template <typename C> void NCurses::basic_buffer<C>::SetTemp(std::basic_string<C> *tmp)
|
||||
|
||||
Reference in New Issue
Block a user