Skip to content

Library Manager: don't reset the "Type" to "All" after updating a library #10767

Closed
@SlickNet

Description

@SlickNet

Updating individual libraries is a bit of a pain, but it is made worse when after selecting Type=Updatable, and clicking update on one library, the UI changes back to Type=All after that one update. Then you have to set it back to "Updateable"

Tested in 1.8.13

Activity

lhalf

lhalf commented on Apr 8, 2021

@lhalf

Hi - I'm a new contributor and thought I could try and implement a fix for this. I think I've found where this functionality is: Arduino/app/src/cc/arduino/contributions/libraries/ui/DropdownUpdatableLibrariesItem.java

Drop down updated list:

public class DropdownUpdatableLibrariesItem implements DropdownItem<ContributedLibraryReleases> {

  @Override
  public Predicate<ContributedLibraryReleases> getFilterPredicate() {
    return new Predicate<ContributedLibraryReleases>() {
      @Override
      public boolean test(ContributedLibraryReleases lib) {
        Optional<ContributedLibrary> mayInstalled = lib.getInstalled();
        if (!mayInstalled.isPresent()) {
          return false;
        }
        return !lib.getLatest().equals(mayInstalled.get());
      }
    };
  }

  @Override
  public String toString() {
    return tr("Updatable");
  }

}

And under: Arduino/app/src/cc/arduino/contributions/libraries/ui/DropdownAllLibraries.java

Dropdown all list:

public class DropdownAllLibraries implements DropdownItem<ContributedLibraryReleases> {

  public String toString() {
    return tr("All");
  }

  @Override
  public Predicate<ContributedLibraryReleases> getFilterPredicate() {
    return x -> true;
  }

}

Now these are the implementations, but after an update I assume a default will be selected again to "All".
I think this is done in: Arduino/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java

public void updateUI() {
    // 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
    categoryFilter = x -> true;
    categoryChooser.removeActionListener(categoryChooserActionListener);
    categoryChooser.removeAllItems();
    categoryChooser.addItem(new DropdownAllLibraries());
    for (String category : categories) {
      categoryChooser.addItem(new DropdownLibraryOfCategoryItem(category));
    }
    categoryChooser.setEnabled(categoryChooser.getItemCount() > 1);
    categoryChooser.addActionListener(categoryChooserActionListener);
    categoryChooser.setSelectedIndex(0);

    // Load types
    extraFilter = x -> true;
    typeChooser.removeActionListener(typeChooserActionListener);
    typeChooser.removeAllItems();
    typeChooser.addItem(new DropdownAllLibraries());
    typeChooser.addItem(new DropdownUpdatableLibrariesItem());
    typeChooser.addItem(new DropdownInstalledLibraryItem());
    for (String type : types) {
      typeChooser.addItem(new DropdownLibraryOfTypeItem(type));
    }
    typeChooser.setEnabled(typeChooser.getItemCount() > 1);
    typeChooser.addActionListener(typeChooserActionListener);
    typeChooser.setSelectedIndex(0);

    filterField.setEnabled(contribModel.getRowCount() > 0);
  }

I think the under the //Load categories section the default is to reload DropdownAllLibraries() ->we could save the currently selected dropdown type prior to the UI update, and update the UI with the same option instead of always updating to all libraries. Does this seem like a good fix?

added this to the Release 1.8.14 milestone on Apr 26, 2021
cmaglie

cmaglie commented on Apr 26, 2021

@cmaglie
Member

The fix for this issue is already on master and will be released with the IDE 1.8.14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Library Manager: don't reset the "Type" to "All" after updating a library · Issue #10767 · arduino/Arduino