Skip to content

Various menus improvements #6706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ public void rebuildBoardsMenu() throws Exception {
// The first custom menu is the "Board" selection submenu
JMenu boardMenu = new JMenu(tr("Board"));
boardMenu.putClientProperty("removeOnWindowDeactivation", true);
MenuScroller.setScrollerFor(boardMenu);
MenuScroller.setScrollerFor(boardMenu).setTopFixedCount(1);

boardMenu.add(new JMenuItem(new AbstractAction(tr("Boards Manager...")) {
public void actionPerformed(ActionEvent actionevent) {
Expand Down
1 change: 1 addition & 0 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ public void actionPerformed(ActionEvent e) {

base.rebuildProgrammerMenu();
programmersMenu = new JMenu(tr("Programmer"));
MenuScroller.setScrollerFor(programmersMenu);
base.getProgrammerMenus().stream().forEach(programmersMenu::add);
toolsMenu.add(programmersMenu);

Expand Down
25 changes: 23 additions & 2 deletions app/src/processing/app/tools/MenuScroller.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.awt.event.ActionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.event.KeyEvent;

/**
* A class that provides scrolling capabilities to a long menu dropdown or
Expand Down Expand Up @@ -40,6 +41,7 @@ public class MenuScroller {
private int bottomFixedCount;
private int firstIndex = 0;
private int keepVisibleIndex = -1;
private int accelerator = 1;

/**
* Registers a menu to be scrolled with the default number of items to
Expand Down Expand Up @@ -293,6 +295,25 @@ public MenuScroller(JPopupMenu menu, int scrollCount, int interval,
this.menu = menu;
menu.addPopupMenuListener(menuListener);
menu.addMouseWheelListener(mouseWheelListener);

ActionListener accel = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
accelerator = 6;
}
};

ActionListener decel = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
accelerator = 1;
}
};

KeyStroke keystroke_accel = KeyStroke.getKeyStroke(KeyEvent.VK_A, 0, false);
KeyStroke keystroke_decel = KeyStroke.getKeyStroke(KeyEvent.VK_A, 0, true);
menu.registerKeyboardAction(accel, "accel", keystroke_accel, JComponent.WHEN_IN_FOCUSED_WINDOW);
menu.registerKeyboardAction(decel, "decel", keystroke_decel, JComponent.WHEN_IN_FOCUSED_WINDOW);
}

/**
Expand Down Expand Up @@ -492,7 +513,7 @@ private int getMaximumDrawableMenuItems() {

private class MouseScrollListener implements MouseWheelListener {
public void mouseWheelMoved(MouseWheelEvent mwe) {
firstIndex += mwe.getWheelRotation();
firstIndex += mwe.getWheelRotation() * accelerator;
refreshMenu();
mwe.consume();
}
Expand Down Expand Up @@ -544,7 +565,7 @@ public MenuScrollTimer(final int increment, int interval) {

@Override
public void actionPerformed(ActionEvent e) {
firstIndex += increment;
firstIndex += increment * accelerator;
refreshMenu();
}
});
Expand Down