From 6c3c1c09b104eca53b3a5a513fad13d12cc184b7 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 12 Apr 2021 13:02:08 +0200 Subject: [PATCH] Make Custom menus scrollable Fixes #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). --- app/src/processing/app/Base.java | 1 + app/src/processing/app/tools/MenuScroller.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 732a8b02e..4578038f3 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1473,6 +1473,7 @@ public class Base { customMenu.putClientProperty("platform", getPlatformUniqueId(targetPlatform)); customMenu.putClientProperty("removeOnWindowDeactivation", true); boardsCustomMenus.add(customMenu); + MenuScroller.setScrollerFor(customMenu); } } } diff --git a/app/src/processing/app/tools/MenuScroller.java b/app/src/processing/app/tools/MenuScroller.java index 9e9aacbca..9acaa8548 100644 --- a/app/src/processing/app/tools/MenuScroller.java +++ b/app/src/processing/app/tools/MenuScroller.java @@ -16,6 +16,7 @@ import java.awt.event.ActionListener; 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 @@ -539,7 +540,7 @@ public class MenuScroller { } 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