Fix highlighting parent directory in filtered browser

master
Andrzej Rybczak 9 years ago
parent 7d502e42ba
commit 6d2ed00e6a
  1. 42
      src/screens/browser.cpp

@ -460,23 +460,24 @@ bool Browser::enterDirectory()
}
void Browser::getDirectory(std::string directory)
{
{
ScopedUnfilteredMenu<MPD::Item> sunfilter(ReapplyFilter::Yes, w);
m_scroll_beginning = 0;
w.clear();
// reset the position if we change directories
// Reset the position if we change directories.
if (m_current_directory != directory)
w.reset();
// check if it's a parent directory
// Check if it's a parent directory.
if (isStringParentDirectory(directory))
{
directory.resize(directory.length()-3);
directory = getParentDirectory(directory);
}
// when we go down to root, it can be empty
// When we go down to root, it can be empty.
if (directory.empty())
directory = "/";
@ -485,52 +486,37 @@ void Browser::getDirectory(std::string directory)
getLocalDirectory(items, directory);
else
{
std::copy(
std::make_move_iterator(Mpd.GetDirectory(directory)),
std::copy(std::make_move_iterator(Mpd.GetDirectory(directory)),
std::make_move_iterator(MPD::ItemIterator()),
std::back_inserter(items)
);
std::back_inserter(items));
}
// sort items
if (Config.browser_sort_mode != SortMode::NoOp)
{
std::sort(items.begin(), items.end(),
LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode)
);
LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode));
}
// if the requested directory is not root, add parent directory
// If the requested directory is not root, add parent directory.
if (!isRootDirectory(directory))
{
// make it so that display function doesn't have to handle special cases
// Make it so that display function doesn't have to handle special cases.
w.addItem(MPD::Directory(directory + "/.."), NC::List::Properties::None);
}
for (const auto &item : items)
{
switch (item.type())
{
case MPD::Item::Type::Playlist:
{
w.addItem(std::move(item));
break;
}
case MPD::Item::Type::Directory:
for (size_t i = 0; i < w.size(); ++i)
{
bool is_current = item.directory().path() == m_current_directory;
w.addItem(std::move(item));
if (is_current)
w.highlight(w.size()-1);
break;
}
case MPD::Item::Type::Song:
if (w[i].value().type() == MPD::Item::Type::Directory
&& w[i].value().directory().path() == m_current_directory)
{
w.addItem(std::move(item));
w.highlight(i);
break;
}
}
}
m_current_directory = directory;
}

Loading…
Cancel
Save