Changeset 18111 in josm


Ignore:
Timestamp:
2021-08-02T02:17:16+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #21148 - fix context specific help (F1) usage in menus (patch by DevCharly)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/HelpAction.java

    r17188 r18111  
    1010import java.util.Optional;
    1111
     12import javax.swing.MenuElement;
     13import javax.swing.MenuSelectionManager;
    1214import javax.swing.SwingUtilities;
    1315
     
    5153        if (e.getActionCommand() == null) {
    5254            String topic;
    53             if (e.getSource() instanceof Component) {
     55            MenuElement[] menuPath = MenuSelectionManager.defaultManager().getSelectedPath();
     56            if (menuPath.length > 0) {
     57                // Get help topic from last element in selected menu path (usually a JMenuItem).
     58                // If a JMenu is selected, which shows a JPopupMenu, then the last path element
     59                // is a JPopupMenu and it is necessary to look also into previous path elements.
     60                topic = null;
     61                for (int i = menuPath.length - 1; i >= 0; i--) {
     62                    Component c = menuPath[i].getComponent();
     63                    topic = HelpUtil.getContextSpecificHelpTopic(c);
     64                    if (topic != null) {
     65                        break;
     66                    }
     67                }
     68            } else if (e.getSource() instanceof Component) {
    5469                Component c = SwingUtilities.getRoot((Component) e.getSource());
    5570                Point mouse = c.getMousePosition();
Note: See TracChangeset for help on using the changeset viewer.