mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
redo category tallying for contribs
This commit is contained in:
@@ -50,7 +50,7 @@ public class ContributionListing {
|
||||
|
||||
List<ChangeListener> listeners;
|
||||
final List<AvailableContribution> advertisedContributions;
|
||||
Map<String, List<Contribution>> librariesByCategory;
|
||||
private Map<String, List<Contribution>> librariesByCategory;
|
||||
Map<String, Contribution> 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<String> getCategories(Contribution.Filter filter) {
|
||||
Set<String> outgoing = new HashSet<>();
|
||||
|
||||
Set<String> 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() + ".*";
|
||||
|
||||
|
||||
@@ -230,20 +230,40 @@ public class ContributionTab extends JPanel {
|
||||
}
|
||||
|
||||
|
||||
private Set<String> listCategories() {
|
||||
Set<String> 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<String> 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<String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user