Ticket #21148: JOSM-context-help.diff

File JOSM-context-help.diff, 1.7 KB (added by DevCharly, 5 years ago)
  • core/src/org/openstreetmap/josm/actions/HelpAction.java

     
    99import java.awt.event.KeyEvent;
    1010import java.util.Optional;
    1111
     12import javax.swing.MenuElement;
     13import javax.swing.MenuSelectionManager;
    1214import javax.swing.SwingUtilities;
    1315
    1416import org.openstreetmap.josm.gui.MainApplication;
     
    5052    public void actionPerformed(ActionEvent e) {
    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();
    5671                if (mouse != null) {