mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-22 11:52:14 +01:00
Library manager: update filters combo box only if there are changes
The filters content is unlikely to change, so just prevent it from live updating it because it has some side effects: - it's slow - it changes the selection back to the default and it's very tricky to make it re-select the previous selection. Fixes #10439
This commit is contained in:
parent
ea84e7383a
commit
42865229c2
@ -35,6 +35,7 @@ import java.awt.Dialog;
|
|||||||
import java.awt.Frame;
|
import java.awt.Frame;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -130,48 +131,46 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public void updateUI() {
|
private Collection<String> oldCategories = new ArrayList<>();
|
||||||
DropdownItem<ContributedLibraryReleases> previouslySelectedCategory = (DropdownItem<ContributedLibraryReleases>) categoryChooser.getSelectedItem();
|
private Collection<String> oldTypes = new ArrayList<>();
|
||||||
DropdownItem<ContributedLibraryReleases> previouslySelectedType = (DropdownItem<ContributedLibraryReleases>) typeChooser.getSelectedItem();
|
|
||||||
|
|
||||||
categoryChooser.removeActionListener(categoryChooserActionListener);
|
public void updateUI() {
|
||||||
typeChooser.removeActionListener(typeChooserActionListener);
|
// Check if categories or types have changed
|
||||||
|
Collection<String> categories = BaseNoGui.librariesIndexer.getIndex().getCategories();
|
||||||
|
List<String> types = new LinkedList<>(BaseNoGui.librariesIndexer.getIndex().getTypes());
|
||||||
|
Collections.sort(types, new LibraryTypeComparator());
|
||||||
|
|
||||||
|
if (categories.equals(oldCategories) && types.equals(oldTypes)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
oldCategories = categories;
|
||||||
|
oldTypes = types;
|
||||||
|
|
||||||
// Load categories
|
// Load categories
|
||||||
categoryFilter = x -> true;
|
categoryFilter = x -> true;
|
||||||
|
categoryChooser.removeActionListener(categoryChooserActionListener);
|
||||||
categoryChooser.removeAllItems();
|
categoryChooser.removeAllItems();
|
||||||
categoryChooser.addItem(new DropdownAllLibraries());
|
categoryChooser.addItem(new DropdownAllLibraries());
|
||||||
Collection<String> categories = BaseNoGui.librariesIndexer.getIndex().getCategories();
|
|
||||||
for (String category : categories) {
|
for (String category : categories) {
|
||||||
categoryChooser.addItem(new DropdownLibraryOfCategoryItem(category));
|
categoryChooser.addItem(new DropdownLibraryOfCategoryItem(category));
|
||||||
}
|
}
|
||||||
|
|
||||||
categoryChooser.setEnabled(categoryChooser.getItemCount() > 1);
|
categoryChooser.setEnabled(categoryChooser.getItemCount() > 1);
|
||||||
|
|
||||||
categoryChooser.addActionListener(categoryChooserActionListener);
|
categoryChooser.addActionListener(categoryChooserActionListener);
|
||||||
if (previouslySelectedCategory != null) {
|
categoryChooser.setSelectedIndex(0);
|
||||||
categoryChooser.setSelectedItem(previouslySelectedCategory);
|
|
||||||
} else {
|
|
||||||
categoryChooser.setSelectedIndex(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Load types
|
||||||
typeFilter = x -> true;
|
typeFilter = x -> true;
|
||||||
|
typeChooser.removeActionListener(typeChooserActionListener);
|
||||||
typeChooser.removeAllItems();
|
typeChooser.removeAllItems();
|
||||||
typeChooser.addItem(new DropdownAllLibraries());
|
typeChooser.addItem(new DropdownAllLibraries());
|
||||||
typeChooser.addItem(new DropdownUpdatableLibrariesItem());
|
typeChooser.addItem(new DropdownUpdatableLibrariesItem());
|
||||||
typeChooser.addItem(new DropdownInstalledLibraryItem());
|
typeChooser.addItem(new DropdownInstalledLibraryItem());
|
||||||
List<String> types = new LinkedList<>(BaseNoGui.librariesIndexer.getIndex().getTypes());
|
|
||||||
Collections.sort(types, new LibraryTypeComparator());
|
|
||||||
for (String type : types) {
|
for (String type : types) {
|
||||||
typeChooser.addItem(new DropdownLibraryOfTypeItem(type));
|
typeChooser.addItem(new DropdownLibraryOfTypeItem(type));
|
||||||
}
|
}
|
||||||
typeChooser.setEnabled(typeChooser.getItemCount() > 1);
|
typeChooser.setEnabled(typeChooser.getItemCount() > 1);
|
||||||
typeChooser.addActionListener(typeChooserActionListener);
|
typeChooser.addActionListener(typeChooserActionListener);
|
||||||
if (previouslySelectedType != null) {
|
typeChooser.setSelectedIndex(0);
|
||||||
typeChooser.setSelectedItem(previouslySelectedType);
|
|
||||||
} else {
|
|
||||||
typeChooser.setSelectedIndex(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
filterField.setEnabled(contribModel.getRowCount() > 0);
|
filterField.setEnabled(contribModel.getRowCount() > 0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user