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();
|
List *mList = myScreen->GetList();
|
||||||
|
|
||||||
if (!mList)
|
if (mList)
|
||||||
continue;
|
{
|
||||||
|
LockStatusbar();
|
||||||
LockStatusbar();
|
Statusbar() << "Find " << (Keypressed(input, Key.FindForward) ? "forward" : "backward") << ": ";
|
||||||
Statusbar() << "Find " << (Keypressed(input, Key.FindForward) ? "forward" : "backward") << ": ";
|
string findme = wFooter->GetString(mList->GetSearchConstraint());
|
||||||
string findme = wFooter->GetString(mList->GetSearchConstraint());
|
UnlockStatusbar();
|
||||||
UnlockStatusbar();
|
myPlaylist->UpdateTimer();
|
||||||
myPlaylist->UpdateTimer();
|
|
||||||
|
if (!findme.empty())
|
||||||
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...");
|
ShowMessage("Searching...");
|
||||||
|
Screen<Scrollpad> *s = static_cast<Screen<Scrollpad> *>(myScreen);
|
||||||
bool success = mList->Search(findme, myScreen == mySearcher ? SearchEngine::StaticOptions : 0, REG_ICASE | Config.regex_type);
|
s->Main()->RemoveFormatting(fmtReverse);
|
||||||
|
s->Main()->RemoveFormatting(fmtReverseEnd);
|
||||||
if (findme.empty())
|
ShowMessage("%s", s->Main()->SetFormatting(fmtReverse, findme, fmtReverseEnd) || findme.empty() ? "Done!" : "No matching patterns found");
|
||||||
continue;
|
s->Main()->Flush();
|
||||||
|
}
|
||||||
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 (Keypressed(input, Key.NextFoundPosition) || Keypressed(input, Key.PrevFoundPosition))
|
else if (Keypressed(input, Key.NextFoundPosition) || Keypressed(input, Key.PrevFoundPosition))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -100,9 +100,9 @@ void Scrollpad::Flush()
|
|||||||
itsBuffer.SetTemp(0);
|
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()
|
void Scrollpad::Recreate()
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ namespace NCurses
|
|||||||
virtual ~Scrollpad() { }
|
virtual ~Scrollpad() { }
|
||||||
|
|
||||||
void Flush();
|
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(); }
|
std::basic_string<my_char_t> Content() { return itsBuffer.Str(); }
|
||||||
|
|
||||||
virtual void Refresh();
|
virtual void Refresh();
|
||||||
@@ -52,7 +53,7 @@ namespace NCurses
|
|||||||
Scrollpad &operator<<(std::ostream &(*os)(std::ostream &));
|
Scrollpad &operator<<(std::ostream &(*os)(std::ostream &));
|
||||||
|
|
||||||
# ifdef _UTF8
|
# 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);
|
Scrollpad &operator<<(const std::string &s);
|
||||||
# endif // _UTF8
|
# endif // _UTF8
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,19 @@ namespace NCurses
|
|||||||
{
|
{
|
||||||
return Position < f.Position;
|
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;
|
std::basic_ostringstream<C> itsString;
|
||||||
@@ -50,7 +63,8 @@ namespace NCurses
|
|||||||
basic_buffer(const basic_buffer &b);
|
basic_buffer(const basic_buffer &b);
|
||||||
|
|
||||||
std::basic_string<C> Str() const;
|
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 SetTemp(std::basic_string<C> *);
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
@@ -83,23 +97,34 @@ template <typename C> std::basic_string<C> NCurses::basic_buffer<C>::Str() const
|
|||||||
return itsString.str();
|
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();
|
std::basic_string<C> base = itsString.str();
|
||||||
FormatPos fp;
|
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.Value = vb;
|
||||||
fp.Position = i;
|
fp.Position = i;
|
||||||
itsFormat.push_back(fp);
|
itsFormat.push_back(fp);
|
||||||
|
i += s.length();
|
||||||
fp.Value = ve;
|
fp.Value = ve;
|
||||||
fp.Position = i+s.length();
|
fp.Position = i;
|
||||||
itsFormat.push_back(fp);
|
itsFormat.push_back(fp);
|
||||||
if (!for_each)
|
if (!for_each)
|
||||||
break;
|
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)
|
template <typename C> void NCurses::basic_buffer<C>::SetTemp(std::basic_string<C> *tmp)
|
||||||
|
|||||||
Reference in New Issue
Block a user