Browse Source

Disable empty author and tag items in ModuleBrowser sidebar

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
25135df79c
1 changed files with 31 additions and 2 deletions
  1. +31
    -2
      src/app/ModuleBrowser.cpp

+ 31
- 2
src/app/ModuleBrowser.cpp View File

@@ -447,7 +447,7 @@ struct ModuleBrowser : widget::OpaqueWidget {
});
}

// Filter authors
// Filter ModelBoxes by author
if (!author.empty()) {
for (Widget *w : modelContainer->children) {
if (!w->visible)
@@ -459,7 +459,7 @@ struct ModuleBrowser : widget::OpaqueWidget {
}
}

// Filter tags
// Filter ModelBoxes by tag
if (!tag.empty()) {
for (Widget *w : modelContainer->children) {
if (!w->visible)
@@ -477,6 +477,35 @@ struct ModuleBrowser : widget::OpaqueWidget {
m->visible = false;
}
}

std::set<std::string> enabledAuthors;
std::set<std::string> enabledTags;

// Get list of enabled authors and tags for sidebar
for (Widget *w : modelContainer->children) {
ModelBox *m = dynamic_cast<ModelBox*>(w);
assert(m);
if (!m->visible)
continue;
enabledAuthors.insert(m->model->plugin->author);
for (const std::string &tag : m->model->tags) {
enabledTags.insert(tag);
}
}

// Enable author and tag items that are available in visible ModelBoxes
for (Widget *w : sidebar->authorList->children) {
AuthorItem *item = dynamic_cast<AuthorItem*>(w);
assert(item);
auto it = enabledAuthors.find(item->text);
item->disabled = (it == enabledAuthors.end());
}
for (Widget *w : sidebar->tagList->children) {
TagItem *item = dynamic_cast<TagItem*>(w);
assert(item);
auto it = enabledTags.find(item->text);
item->disabled = (it == enabledTags.end());
}
}
};



Loading…
Cancel
Save