status: optimize filtering when chars are being taken from input queue
This commit is contained in:
@@ -1879,15 +1879,16 @@ void ApplyFilter::Run()
|
|||||||
using Global::wFooter;
|
using Global::wFooter;
|
||||||
|
|
||||||
Filterable *f = dynamic_cast<Filterable *>(myScreen);
|
Filterable *f = dynamic_cast<Filterable *>(myScreen);
|
||||||
|
std::string filter = f->currentFilter();
|
||||||
|
|
||||||
LockStatusbar();
|
LockStatusbar();
|
||||||
Statusbar() << NC::fmtBold << "Apply filter: " << NC::fmtBoldEnd;
|
Statusbar() << NC::fmtBold << "Apply filter: " << NC::fmtBoldEnd;
|
||||||
wFooter->setGetStringHelper(std::bind(StatusbarApplyFilterImmediately, f, _1));
|
wFooter->setGetStringHelper(StatusbarApplyFilterImmediately(f, ToWString(filter)));
|
||||||
wFooter->getString(f->currentFilter());
|
wFooter->getString(filter);
|
||||||
wFooter->setGetStringHelper(StatusbargetStringHelper);
|
wFooter->setGetStringHelper(StatusbargetStringHelper);
|
||||||
UnlockStatusbar();
|
UnlockStatusbar();
|
||||||
|
|
||||||
std::string filter = f->currentFilter();
|
filter = f->currentFilter();
|
||||||
if (filter.empty())
|
if (filter.empty())
|
||||||
{
|
{
|
||||||
myPlaylist->Items->clearFilterResults();
|
myPlaylist->Items->clearFilterResults();
|
||||||
|
|||||||
@@ -78,16 +78,23 @@ void StatusbargetStringHelper(const std::wstring &)
|
|||||||
TraceMpdStatus();
|
TraceMpdStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatusbarApplyFilterImmediately(Filterable *f, const std::wstring &ws)
|
void StatusbarApplyFilterImmediately::operator()(const std::wstring &ws)
|
||||||
{
|
{
|
||||||
static std::wstring cmp;
|
// if input queue is not empty, we don't want to update filter since next
|
||||||
if (cmp != ws)
|
// character will be taken from queue immediately, trigering this function
|
||||||
|
// again and thus making it inefficient, so let's apply filter only if
|
||||||
|
// "real" user input arrived. however, we want to apply filter if ENTER
|
||||||
|
// is next in queue, so its effects will be seen.
|
||||||
|
if (wFooter->inputQueue().empty() || wFooter->inputQueue().front() == KEY_ENTER)
|
||||||
{
|
{
|
||||||
cmp = ws;
|
if (m_ws != ws)
|
||||||
f->applyFilter(ToString(cmp));
|
{
|
||||||
myScreen->RefreshWindow();
|
m_ws = ws;
|
||||||
|
m_f->applyFilter(ToString(m_ws));
|
||||||
|
myScreen->RefreshWindow();
|
||||||
|
}
|
||||||
|
TraceMpdStatus();
|
||||||
}
|
}
|
||||||
TraceMpdStatus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LockProgressbar()
|
void LockProgressbar()
|
||||||
|
|||||||
13
src/status.h
13
src/status.h
@@ -46,7 +46,18 @@ void ShowMessage(const char *, ...) GNUC_PRINTF(1, 2);
|
|||||||
|
|
||||||
void StatusbarMPDCallback();
|
void StatusbarMPDCallback();
|
||||||
void StatusbargetStringHelper(const std::wstring &);
|
void StatusbargetStringHelper(const std::wstring &);
|
||||||
void StatusbarApplyFilterImmediately(Filterable *f, const std::wstring &ws);
|
|
||||||
|
struct StatusbarApplyFilterImmediately
|
||||||
|
{
|
||||||
|
StatusbarApplyFilterImmediately(Filterable *f, const std::wstring &filter)
|
||||||
|
: m_f(f), m_ws(filter) { }
|
||||||
|
|
||||||
|
void operator()(const std::wstring &ws);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Filterable *m_f;
|
||||||
|
std::wstring m_ws;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -174,6 +174,8 @@ std::string getEnclosedString(const std::string &s, char a, char b, size_t *pos)
|
|||||||
// we want to set pos to char after b if possible
|
// we want to set pos to char after b if possible
|
||||||
if (i < s.length())
|
if (i < s.length())
|
||||||
++i;
|
++i;
|
||||||
|
else // we reached end of string and didn't encounter closing char
|
||||||
|
result.clear();
|
||||||
}
|
}
|
||||||
if (pos != 0)
|
if (pos != 0)
|
||||||
*pos = i;
|
*pos = i;
|
||||||
|
|||||||
@@ -340,6 +340,9 @@ struct Window
|
|||||||
/// Push single character into input queue, so it can get consumed by ReadKey
|
/// Push single character into input queue, so it can get consumed by ReadKey
|
||||||
void pushChar(int ch);
|
void pushChar(int ch);
|
||||||
|
|
||||||
|
/// @return const reference to internal input queue
|
||||||
|
const std::queue<int> &inputQueue() { return m_input_queue; }
|
||||||
|
|
||||||
/// Scrolls the window by amount of lines given in its parameter
|
/// Scrolls the window by amount of lines given in its parameter
|
||||||
/// @param where indicates how many lines it has to scroll
|
/// @param where indicates how many lines it has to scroll
|
||||||
virtual void scroll(Where where);
|
virtual void scroll(Where where);
|
||||||
|
|||||||
Reference in New Issue
Block a user