[PATCH setup 08/13] Show the count of packages in a category
Jon Turney
jon.turney@dronecode.org.uk
Sun Aug 5 22:10:00 GMT 2018
---
PickCategoryLine.cc | 8 ++++++--
PickCategoryLine.h | 4 +++-
PickView.cc | 4 ++--
3 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/PickCategoryLine.cc b/PickCategoryLine.cc
index ec15b4a..736e3c6 100644
--- a/PickCategoryLine.cc
+++ b/PickCategoryLine.cc
@@ -18,14 +18,18 @@
#include "PickView.h"
#include "window.h"
#include "package_meta.h"
+#include <sstream>
const std::string
PickCategoryLine::get_text (int col_num) const
{
if (col_num == pkgname_col)
{
- std::string s = (cat_tree->collapsed() ? "[+] " : "[-] ") + cat_tree->category().first;
- return s;
+ std::ostringstream s;
+ s << (cat_tree->collapsed() ? "[+] " : "[-] ") << cat_tree->category().first;
+ if (pkgcount)
+ s << " (" << pkgcount << ")";
+ return s.str();
}
else if (col_num == new_col)
{
diff --git a/PickCategoryLine.h b/PickCategoryLine.h
index 6c18018..ec160f9 100644
--- a/PickCategoryLine.h
+++ b/PickCategoryLine.h
@@ -23,8 +23,9 @@
class PickCategoryLine: public ListViewLine
{
public:
- PickCategoryLine (PickView & aView, CategoryTree * _tree) :
+ PickCategoryLine (PickView & aView, CategoryTree * _tree, int _pkgcount) :
cat_tree (_tree),
+ pkgcount(_pkgcount),
theView (aView)
{
};
@@ -38,6 +39,7 @@ public:
private:
CategoryTree * cat_tree;
+ int pkgcount;
PickView & theView;
};
diff --git a/PickView.cc b/PickView.cc
index 967d53b..6e1af0c 100644
--- a/PickView.cc
+++ b/PickView.cc
@@ -169,12 +169,12 @@ PickView::insert_category (CategoryTree *cat_tree)
return;
// if it's not the "All" category
+ int packageCount = 0;
bool hasContents = false;
bool isAll = casecompare(cat->first, "All") == 0;
if (!isAll)
{
// count the number of packages in this category
- int packageCount = 0;
for (std::vector <packagemeta *>::const_iterator i = cat->second.begin ();
i != cat->second.end () ; ++i)
{
@@ -197,7 +197,7 @@ PickView::insert_category (CategoryTree *cat_tree)
return;
// insert line for the category
- contents.push_back(new PickCategoryLine(*this, cat_tree));
+ contents.push_back(new PickCategoryLine(*this, cat_tree, packageCount));
// if not collapsed
if (!cat_tree->collapsed())
--
2.17.0
More information about the Cygwin-apps
mailing list