Skip to content

Commit

Permalink
Make Custom menus scrollable
Browse files Browse the repository at this point in the history
Fixes arduino#11416

The patch on MenuScroller.java is needed to avoid a clash between custom menus with the same label.
This behaviour artificially increases the amount of objects that the scroller will calculate.
Eg. if two boards share the same custom menu, that menu will contain the properties for both the boards (since it's parsed twice).
  • Loading branch information
facchinm committed Apr 12, 2021
1 parent 57a931c commit 6c3c1c0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,7 @@ public void actionPerformed(ActionEvent actionevent) {
customMenu.putClientProperty("platform", getPlatformUniqueId(targetPlatform));
customMenu.putClientProperty("removeOnWindowDeactivation", true);
boardsCustomMenus.add(customMenu);
MenuScroller.setScrollerFor(customMenu);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/processing/app/tools/MenuScroller.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.event.KeyEvent;
import java.util.Arrays;

/**
* A class that provides scrolling capabilities to a long menu dropdown or
Expand Down Expand Up @@ -539,7 +540,7 @@ public void popupMenuCanceled(PopupMenuEvent e) {
}

private void setMenuItems() {
menuItems = menu.getComponents();
menuItems = Arrays.stream(menu.getComponents()).filter(x -> x.isVisible()).toArray(Component[]::new);
if (keepVisibleIndex >= topFixedCount
&& keepVisibleIndex <= menuItems.length - bottomFixedCount
&& (keepVisibleIndex > firstIndex + scrollCount
Expand Down

0 comments on commit 6c3c1c0

Please sign in to comment.