Skip to content

Commit f79a6c5

Browse files
author
Federico Fissore
committed
Library and Boards Manager: preserving filter selections
1 parent 7a97be4 commit f79a6c5

9 files changed

+65
-1
lines changed

Diff for: app/src/cc/arduino/contributions/libraries/ui/DropdownBuiltInLibrariesItem.java

+6
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@ public String toString() {
1717
public Predicate<DownloadableContribution> getFilterPredicate() {
1818
return new BuiltInPredicate();
1919
}
20+
21+
@Override
22+
public boolean equals(Object obj) {
23+
return obj instanceof DropdownBuiltInLibrariesItem;
24+
}
25+
2026
}

Diff for: app/src/cc/arduino/contributions/libraries/ui/DropdownInstalledLibraryItem.java

+6
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ public String toString() {
2424
public Predicate<ContributedLibrary> getFilterPredicate() {
2525
return new InstalledLibraryPredicate(index);
2626
}
27+
28+
@Override
29+
public boolean equals(Object obj) {
30+
return obj instanceof DropdownInstalledLibraryItem;
31+
}
32+
2733
}

Diff for: app/src/cc/arduino/contributions/libraries/ui/DropdownLibraryOfCategoryItem.java

+6
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ public String toString() {
2121
public Predicate<ContributedLibrary> getFilterPredicate() {
2222
return new CategoryPredicate(category);
2323
}
24+
25+
@Override
26+
public boolean equals(Object obj) {
27+
return obj instanceof DropdownLibraryOfCategoryItem && ((DropdownLibraryOfCategoryItem) obj).category.equals(category);
28+
}
29+
2430
}

Diff for: app/src/cc/arduino/contributions/libraries/ui/DropdownLibraryOfTypeItem.java

+6
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,10 @@ public String toString() {
2222
public Predicate<ContributedLibrary> getFilterPredicate() {
2323
return new TypePredicate(type);
2424
}
25+
26+
@Override
27+
public boolean equals(Object obj) {
28+
return obj instanceof DropdownLibraryOfTypeItem && ((DropdownLibraryOfTypeItem) obj).type.equals(type);
29+
}
30+
2531
}

Diff for: app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import cc.arduino.contributions.libraries.ContributedLibrary;
3232
import cc.arduino.contributions.libraries.LibrariesIndexer;
33+
import cc.arduino.contributions.packages.DownloadableContribution;
3334
import cc.arduino.contributions.packages.ui.InstallerJDialogUncaughtExceptionHandler;
3435
import cc.arduino.contributions.ui.*;
3536
import cc.arduino.utils.Progress;
@@ -124,6 +125,10 @@ public void updateIndexFilter(String[] filters, Predicate<ContributedLibrary>...
124125

125126
public void setIndexer(LibrariesIndexer indexer) {
126127
this.indexer = indexer;
128+
129+
DropdownItem<DownloadableContribution> previouslySelectedCategory = (DropdownItem<DownloadableContribution>) categoryChooser.getSelectedItem();
130+
DropdownItem<DownloadableContribution> previouslySelectedType = (DropdownItem<DownloadableContribution>) typeChooser.getSelectedItem();
131+
127132
categoryChooser.removeActionListener(categoryChooserActionListener);
128133
typeChooser.removeActionListener(typeChooserActionListener);
129134

@@ -144,7 +149,11 @@ public void setIndexer(LibrariesIndexer indexer) {
144149
categoryChooser.setEnabled(categoryChooser.getItemCount() > 1);
145150

146151
categoryChooser.addActionListener(categoryChooserActionListener);
147-
categoryChooser.setSelectedIndex(0);
152+
if (previouslySelectedCategory != null) {
153+
categoryChooser.setSelectedItem(previouslySelectedCategory);
154+
} else {
155+
categoryChooser.setSelectedIndex(0);
156+
}
148157

149158
typeFilter = null;
150159
typeChooser.removeAllItems();
@@ -156,6 +165,11 @@ public void setIndexer(LibrariesIndexer indexer) {
156165
}
157166
typeChooser.setEnabled(typeChooser.getItemCount() > 1);
158167
typeChooser.addActionListener(typeChooserActionListener);
168+
if (previouslySelectedType != null) {
169+
typeChooser.setSelectedItem(previouslySelectedType);
170+
} else {
171+
typeChooser.setSelectedIndex(0);
172+
}
159173

160174
filterField.setEnabled(contribModel.getRowCount() > 0);
161175

Diff for: app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java

+9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import cc.arduino.contributions.packages.ContributedPlatform;
3232
import cc.arduino.contributions.packages.ContributionInstaller;
3333
import cc.arduino.contributions.packages.ContributionsIndexer;
34+
import cc.arduino.contributions.packages.DownloadableContribution;
35+
import cc.arduino.contributions.ui.DropdownItem;
3436
import cc.arduino.contributions.ui.FilteredAbstractTableModel;
3537
import cc.arduino.contributions.ui.InstallerJDialog;
3638
import cc.arduino.contributions.ui.InstallerTableCell;
@@ -88,6 +90,8 @@ public ContributionManagerUI(Frame parent) {
8890
}
8991

9092
public void setIndexer(ContributionsIndexer indexer) {
93+
DropdownItem<DownloadableContribution> previouslySelectedCategory = (DropdownItem<DownloadableContribution>) categoryChooser.getSelectedItem();
94+
9195
categoryChooser.removeActionListener(categoryChooserActionListener);
9296

9397
getContribModel().setIndex(indexer.getIndex());
@@ -105,6 +109,11 @@ public void setIndexer(ContributionsIndexer indexer) {
105109
for (String s : categories) {
106110
categoryChooser.addItem(new DropdownCoreOfCategoryItem(s));
107111
}
112+
if (previouslySelectedCategory != null) {
113+
categoryChooser.setSelectedItem(previouslySelectedCategory);
114+
} else {
115+
categoryChooser.setSelectedIndex(0);
116+
}
108117

109118
// Create ConstributionInstaller tied with the provided index
110119
installer = new ContributionInstaller(indexer) {

Diff for: app/src/cc/arduino/contributions/packages/ui/DropdownAllCoresItem.java

+5
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ public String toString() {
1717
public Predicate<ContributedPlatform> getFilterPredicate() {
1818
return new NoopPredicate<ContributedPlatform>();
1919
}
20+
21+
@Override
22+
public boolean equals(Object obj) {
23+
return obj instanceof DropdownAllCoresItem;
24+
}
2025
}

Diff for: app/src/cc/arduino/contributions/packages/ui/DropdownCoreOfCategoryItem.java

+6
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ public String toString() {
2121
public Predicate<ContributedPlatform> getFilterPredicate() {
2222
return new CategoryPredicate(category);
2323
}
24+
25+
@Override
26+
public boolean equals(Object obj) {
27+
return obj instanceof DropdownCoreOfCategoryItem && ((DropdownCoreOfCategoryItem) obj).category.equals(category);
28+
}
29+
2430
}

Diff for: app/src/cc/arduino/contributions/ui/DropdownAllItem.java

+6
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@ public String toString() {
1717
public Predicate<DownloadableContribution> getFilterPredicate() {
1818
return new NoopPredicate<DownloadableContribution>();
1919
}
20+
21+
@Override
22+
public boolean equals(Object obj) {
23+
return obj instanceof DropdownAllItem;
24+
}
25+
2026
}

0 commit comments

Comments
 (0)