Fix highlighting parent directory in filtered browser
This commit is contained in:
@@ -461,74 +461,60 @@ bool Browser::enterDirectory()
|
|||||||
|
|
||||||
void Browser::getDirectory(std::string directory)
|
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
|
|
||||||
if (m_current_directory != directory)
|
|
||||||
w.reset();
|
|
||||||
|
|
||||||
// check if it's a parent directory
|
|
||||||
if (isStringParentDirectory(directory))
|
|
||||||
{
|
{
|
||||||
directory.resize(directory.length()-3);
|
ScopedUnfilteredMenu<MPD::Item> sunfilter(ReapplyFilter::Yes, w);
|
||||||
directory = getParentDirectory(directory);
|
|
||||||
}
|
|
||||||
// when we go down to root, it can be empty
|
|
||||||
if (directory.empty())
|
|
||||||
directory = "/";
|
|
||||||
|
|
||||||
std::vector<MPD::Item> items;
|
m_scroll_beginning = 0;
|
||||||
if (m_local_browser)
|
w.clear();
|
||||||
getLocalDirectory(items, directory);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::copy(
|
|
||||||
std::make_move_iterator(Mpd.GetDirectory(directory)),
|
|
||||||
std::make_move_iterator(MPD::ItemIterator()),
|
|
||||||
std::back_inserter(items)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// sort items
|
// Reset the position if we change directories.
|
||||||
if (Config.browser_sort_mode != SortMode::NoOp)
|
if (m_current_directory != directory)
|
||||||
{
|
w.reset();
|
||||||
std::sort(items.begin(), items.end(),
|
|
||||||
LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the requested directory is not root, add parent directory
|
// Check if it's a parent directory.
|
||||||
if (!isRootDirectory(directory))
|
if (isStringParentDirectory(directory))
|
||||||
{
|
|
||||||
// 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:
|
directory.resize(directory.length()-3);
|
||||||
{
|
directory = getParentDirectory(directory);
|
||||||
w.addItem(std::move(item));
|
}
|
||||||
break;
|
// When we go down to root, it can be empty.
|
||||||
}
|
if (directory.empty())
|
||||||
case MPD::Item::Type::Directory:
|
directory = "/";
|
||||||
{
|
|
||||||
bool is_current = item.directory().path() == m_current_directory;
|
std::vector<MPD::Item> items;
|
||||||
w.addItem(std::move(item));
|
if (m_local_browser)
|
||||||
if (is_current)
|
getLocalDirectory(items, directory);
|
||||||
w.highlight(w.size()-1);
|
else
|
||||||
break;
|
{
|
||||||
}
|
std::copy(std::make_move_iterator(Mpd.GetDirectory(directory)),
|
||||||
case MPD::Item::Type::Song:
|
std::make_move_iterator(MPD::ItemIterator()),
|
||||||
{
|
std::back_inserter(items));
|
||||||
w.addItem(std::move(item));
|
}
|
||||||
break;
|
|
||||||
}
|
if (Config.browser_sort_mode != SortMode::NoOp)
|
||||||
|
{
|
||||||
|
std::sort(items.begin(), items.end(),
|
||||||
|
LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
w.addItem(MPD::Directory(directory + "/.."), NC::List::Properties::None);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &item : items)
|
||||||
|
w.addItem(std::move(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < w.size(); ++i)
|
||||||
|
{
|
||||||
|
if (w[i].value().type() == MPD::Item::Type::Directory
|
||||||
|
&& w[i].value().directory().path() == m_current_directory)
|
||||||
|
{
|
||||||
|
w.highlight(i);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_current_directory = directory;
|
m_current_directory = directory;
|
||||||
|
|||||||
Reference in New Issue
Block a user