Ticket #22948: 22948.patch

File 22948.patch, 2.8 KB (added by taylor.smock, 18 months ago)
  • src/org/openstreetmap/josm/gui/widgets/TextContextualPopupMenu.java

    Subject: [PATCH] Fix #22948: Add system shortcuts for undo/redo to text boxes
    ---
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/gui/widgets/TextContextualPopupMenu.java b/src/org/openstreetmap/josm/gui/widgets/TextContextualPopupMenu.java
    a b  
    77import java.awt.event.ActionEvent;
    88import java.awt.event.KeyEvent;
    99import java.beans.PropertyChangeListener;
     10import java.util.Optional;
    1011
    1112import javax.swing.AbstractAction;
    1213import javax.swing.Action;
     
    2526import org.openstreetmap.josm.tools.ImageProvider;
    2627import org.openstreetmap.josm.tools.Logging;
    2728import org.openstreetmap.josm.tools.PlatformManager;
     29import org.openstreetmap.josm.tools.Shortcut;
    2830
    2931/**
    3032 * A popup menu designed for text components. It displays the following actions:
     
    9799        if (!undoRedo) {
    98100            component.getDocument().addUndoableEditListener(undoEditListener);
    99101            if (!GraphicsEnvironment.isHeadless()) {
    100                 component.getInputMap().put(
    101                         KeyStroke.getKeyStroke(KeyEvent.VK_Z, PlatformManager.getPlatform().getMenuShortcutKeyMaskEx()), undoAction);
    102                 component.getInputMap().put(
    103                         KeyStroke.getKeyStroke(KeyEvent.VK_Y, PlatformManager.getPlatform().getMenuShortcutKeyMaskEx()), redoAction);
     102                final Optional<Shortcut> undoShortcut = Shortcut.listAll().stream()
     103                        .filter(shortcut -> "system:undo".equals(shortcut.getShortText())).findFirst();
     104                final Optional<Shortcut> redoShortcut = Shortcut.listAll().stream()
     105                        .filter(shortcut -> "system:redo".equals(shortcut.getShortText())).findFirst();
     106                if (undoShortcut.isPresent()) {
     107                    component.getInputMap().put(undoShortcut.get().getKeyStroke(), undoAction);
     108                } else {
     109                    component.getInputMap().put(
     110                            KeyStroke.getKeyStroke(KeyEvent.VK_Z, PlatformManager.getPlatform().getMenuShortcutKeyMaskEx()), undoAction);
     111                }
     112                if (redoShortcut.isPresent()) {
     113                    component.getInputMap().put(redoShortcut.get().getKeyStroke(), redoAction);
     114                } else {
     115                    component.getInputMap().put(
     116                            KeyStroke.getKeyStroke(KeyEvent.VK_Y, PlatformManager.getPlatform().getMenuShortcutKeyMaskEx()), redoAction);
     117                }
    104118            }
    105119            undoRedo = true;
    106120        }