diff --git a/app/src/processing/app/contrib/ContributionListing.java b/app/src/processing/app/contrib/ContributionListing.java index 38d19966f..09cc733f0 100644 --- a/app/src/processing/app/contrib/ContributionListing.java +++ b/app/src/processing/app/contrib/ContributionListing.java @@ -50,7 +50,7 @@ public class ContributionListing { List listeners; final List advertisedContributions; - Map> librariesByCategory; + private Map> librariesByCategory; Map librariesByImportHeader; // TODO: Every contribution is getting added twice // and nothing is replaced ever. [akarshit 151031] @@ -210,29 +210,6 @@ public class ContributionListing { } - /** - * @param filter Filter for either the contrib type or whether it's an update. - */ - protected Set getCategories(Contribution.Filter filter) { - Set outgoing = new HashSet<>(); - - Set categorySet = librariesByCategory.keySet(); - for (String categoryName : categorySet) { - for (Contribution contrib : librariesByCategory.get(categoryName)) { - if (filter.matches(contrib)) { - // TODO still not sure why category would be coming back null [fry] - // http://code.google.com/p/processing/issues/detail?id=1387 - if (categoryName != null && !categoryName.trim().isEmpty()) { - outgoing.add(categoryName); - } - break; - } - } - } - return outgoing; - } - - public boolean matches(Contribution contrib, String typed) { String search = ".*" + typed.toLowerCase() + ".*"; diff --git a/app/src/processing/app/contrib/ContributionTab.java b/app/src/processing/app/contrib/ContributionTab.java index c82d8dd75..e4602c37b 100644 --- a/app/src/processing/app/contrib/ContributionTab.java +++ b/app/src/processing/app/contrib/ContributionTab.java @@ -230,20 +230,40 @@ public class ContributionTab extends JPanel { } + private Set listCategories() { + Set categories = new HashSet<>(); + + for (Contribution c : contribListing.allContributions) { + if (filter.matches(c)) { + for (String category : c.getCategories()) { + categories.add(category); + } + } + } + return categories; + } + + protected void updateCategoryChooser() { if (categoryChooser != null) { categoryChooser.removeAllItems(); - List categories = new ArrayList<>(contribListing.getCategories(filter)); - Collections.sort(categories); - boolean categoriesFound = false; - categoryChooser.addItem(ManagerFrame.ANY_CATEGORY); - for (String s : categories) { - categoryChooser.addItem(s); - if (!s.equals(Contribution.UNKNOWN_CATEGORY)) { - categoriesFound = true; + + Set categories = listCategories(); + if (categories.size() == 1 && + categories.contains(Contribution.UNKNOWN_CATEGORY)) { + // no unique categories + categoryChooser.setVisible(false); + + } else { + categoryChooser.addItem(ManagerFrame.ANY_CATEGORY); + + String[] list = categories.toArray(String[]::new); + Arrays.sort(list); + for (String category : list) { + categoryChooser.addItem(category); } + categoryChooser.setVisible(true); } - categoryChooser.setVisible(categoriesFound); } } diff --git a/todo.txt b/todo.txt index 47bd61208..cb3b7fdb5 100755 --- a/todo.txt +++ b/todo.txt @@ -42,6 +42,8 @@ X remove insane overbuilt search in contribs X sure, we have over a hundred libraries, but we don't have millions X search by contrib type (is:) wasn't even working properly X removing accents was trashing some input too +X redo category tallying for contribs (Libraries only anyway?) +X gets rid of maze of code that's storing libraries by their category _ allow update of the current Mode