new feature: allow searching in help, lyrics and info screens

This commit is contained in:
Andrzej Rybczak
2009-04-18 04:34:23 +02:00
parent 0978f2c228
commit 88fa887776
4 changed files with 74 additions and 34 deletions

View File

@@ -1596,9 +1596,8 @@ int main(int argc, char *argv[])
{
List *mList = myScreen->GetList();
if (!mList)
continue;
if (mList)
{
LockStatusbar();
Statusbar() << "Find " << (Keypressed(input, Key.FindForward) ? "forward" : "backward") << ": ";
string findme = wFooter->GetString(mList->GetSearchConstraint());
@@ -1623,6 +1622,21 @@ int main(int argc, char *argv[])
if (myScreen == myPlaylist)
myPlaylist->EnableHighlighting();
}
else if (myScreen == myHelp || myScreen == myLyrics || myScreen == myInfo)
{
LockStatusbar();
Statusbar() << "Find: ";
string findme = wFooter->GetString();
UnlockStatusbar();
ShowMessage("Searching...");
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))
{
List *mList = myScreen->GetList();

View File

@@ -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()

View File

@@ -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

View File

@@ -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)