From b66ed5e5d738e0e83c2ced183914cef3bd5f72fc Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 29 Jun 2020 17:27:11 +0200 Subject: [PATCH] LibraryManager: correctly apply "type" and "category" filters together Previously changing "Category" would filter libraries by the selected category but without applying the "Type" previously selected. For instance selecting Type="Installed" and Category="Communication" will display *all* the libraries belonging to "communication" instead of the installed only. This commit fix this behavior. --- .../contributions/libraries/ui/LibraryManagerUI.java | 11 ++++------- .../cc/arduino/contributions/ui/InstallerJDialog.java | 3 ++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java b/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java index f168d11c2..67221f91c 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java +++ b/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java @@ -41,7 +41,6 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Optional; -import java.util.function.Predicate; import javax.swing.Box; import javax.swing.JComboBox; @@ -67,7 +66,6 @@ public class LibraryManagerUI extends InstallerJDialog typeFilter; @Override protected FilteredAbstractTableModel createContribModel() { @@ -116,17 +114,16 @@ public class LibraryManagerUI extends InstallerJDialog selected = (DropdownItem) typeChooser.getSelectedItem(); previousRowAtPoint = -1; - if (selected != null && typeFilter != selected.getFilterPredicate()) { - typeFilter = selected.getFilterPredicate(); + if (selected != null && extraFilter != selected.getFilterPredicate()) { + extraFilter = selected.getFilterPredicate(); if (contribTable.getCellEditor() != null) { contribTable.getCellEditor().stopCellEditing(); } - updateIndexFilter(filters, categoryFilter.and(typeFilter)); + updateIndexFilter(filters, categoryFilter.and(extraFilter)); } } }; @@ -159,7 +156,7 @@ public class LibraryManagerUI extends InstallerJDialog true; + extraFilter = x -> true; typeChooser.removeActionListener(typeChooserActionListener); typeChooser.removeAllItems(); typeChooser.addItem(new DropdownAllLibraries()); diff --git a/app/src/cc/arduino/contributions/ui/InstallerJDialog.java b/app/src/cc/arduino/contributions/ui/InstallerJDialog.java index 3c0ff31c6..8abff8f34 100644 --- a/app/src/cc/arduino/contributions/ui/InstallerJDialog.java +++ b/app/src/cc/arduino/contributions/ui/InstallerJDialog.java @@ -81,6 +81,7 @@ public abstract class InstallerJDialog extends JDialog { protected final FilterJTextField filterField; protected final JPanel filtersContainer; // Currently selected category and filters + protected Predicate extraFilter = x -> true; protected Predicate categoryFilter; protected String[] filters; protected final String noConnectionErrorMessage; @@ -337,7 +338,7 @@ public abstract class InstallerJDialog extends JDialog { if (contribTable.getCellEditor() != null) { contribTable.getCellEditor().stopCellEditing(); } - updateIndexFilter(filters, categoryFilter); + updateIndexFilter(filters, categoryFilter.and(extraFilter)); } } };