Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember category expansion state when regenerating music list #1083

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions src/courtroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,17 @@ void Courtroom::enter_courtroom()
// Todo: multithread this due to some servers having large as hell music list
void Courtroom::list_music()
{
// remember collapsed categories
QStringList collapsed_categories;
for (int i = 0; i < ui_music_list->topLevelItemCount(); ++i)
{
const auto pCategory = ui_music_list->topLevelItem(i);
if (!pCategory->isExpanded())
{
collapsed_categories.append(pCategory->text(0));
}
}

ui_music_list->clear();
// ui_music_search->setText("");

Expand Down Expand Up @@ -1767,9 +1778,23 @@ void Courtroom::list_music()
}
}

ui_music_list->expandAll(); // Needs to somehow remember which categories were
// expanded/collapsed if the music list didn't
// change since last time
ui_music_list->expandAll();

// restore expanded state from before the list was reset
// disable animations while we do this
bool was_animated = ui_music_list->isAnimated();
ui_music_list->setAnimated(false);
for (int i = 0; i < ui_music_list->topLevelItemCount(); ++i)
{
const auto pCategory = ui_music_list->topLevelItem(i);
if (collapsed_categories.contains(pCategory->text(0)))
{
pCategory->setExpanded(false);
}
}
// restore animated state
ui_music_list->setAnimated(was_animated);

if (ui_music_search->text() != "")
{
on_music_search_edited(ui_music_search->text());
Expand Down