Ticket #22065: 22065.2.patch

File 22065.2.patch, 10.9 KB (added by taylor.smock, 3 years ago)

Replace ctrl with platform specific equivalent in most places for SelectAction

  • src/org/openstreetmap/josm/actions/mapmode/MapMode.java

    diff --git a/src/org/openstreetmap/josm/actions/mapmode/MapMode.java b/src/org/openstreetmap/josm/actions/mapmode/MapMode.java
    index 3ad0d71e27..62383c04c7 100644
    a b import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;  
    2020import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
    2121import org.openstreetmap.josm.tools.ImageProvider;
    2222import org.openstreetmap.josm.tools.Logging;
     23import org.openstreetmap.josm.tools.PlatformHook;
     24import org.openstreetmap.josm.tools.PlatformManager;
    2325import org.openstreetmap.josm.tools.Shortcut;
    2426
    2527/**
    public abstract class MapMode extends JosmAction implements MouseListener, Mouse  
    3335    protected boolean ctrl;
    3436    protected boolean alt;
    3537    protected boolean shift;
     38    /**
     39     * {@code true} if the meta key was pressed (the "Windows" key or the Mac "Command" key)
     40     * @since xxx
     41     */
     42    protected boolean meta;
     43    /**
     44     * @see PlatformHook#getMenuShortcutKeyMaskEx()
     45     * @since xxx
     46     */
     47    protected boolean platformMenuShortcutKeyMask;
    3648
    3749    /**
    3850     * Constructor for mapmodes without a menu
    public abstract class MapMode extends JosmAction implements MouseListener, Mouse  
    154166    }
    155167
    156168    /**
    157      * Update internal ctrl, alt, shift mask from given extended modifiers mask.
     169     * Update internal ctrl, alt, shift, meta mask from given extended modifiers mask.
    158170     * @param modifiers event extended modifiers mask
    159171     * @since 12517
    160172     */
    public abstract class MapMode extends JosmAction implements MouseListener, Mouse  
    162174        ctrl = (modifiers & InputEvent.CTRL_DOWN_MASK) != 0;
    163175        alt = (modifiers & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_GRAPH_DOWN_MASK)) != 0;
    164176        shift = (modifiers & InputEvent.SHIFT_DOWN_MASK) != 0;
     177        meta = (modifiers & InputEvent.META_DOWN_MASK) != 0;
     178        platformMenuShortcutKeyMask = (modifiers & PlatformManager.getPlatform().getMenuShortcutKeyMaskEx()) != 0;
    165179    }
    166180
    167181    /**
  • src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    diff --git a/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java b/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
    index 6983b3d585..7d50a22ba3 100644
    a b public class SelectAction extends MapMode implements ModifierExListener, KeyPres  
    287287            return repaintIfRequired(newHighlight);
    288288
    289289        // CTRL toggles selection, but if while dragging CTRL means merge
    290         final boolean isToggleMode = ctrl && !dragInProgress();
     290        final boolean isToggleMode = platformMenuShortcutKeyMask && !dragInProgress();
    291291        if (c.isPresent() && (isToggleMode || !c.get().isSelected())) {
    292292            // only highlight primitives that will change the selection
    293293            // when clicked. I.e. don't highlight selected elements unless
    public class SelectAction extends MapMode implements ModifierExListener, KeyPres  
    317317            if (dragInProgress()) {
    318318                // only consider merge if ctrl is pressed and there are nodes in
    319319                // the selection that could be merged
    320                 if (!ctrl || getLayerManager().getEditDataSet().getSelectedNodes().isEmpty()) {
     320                if (!platformMenuShortcutKeyMask || getLayerManager().getEditDataSet().getSelectedNodes().isEmpty()) {
    321321                    c = "move";
    322322                    break;
    323323                }
    public class SelectAction extends MapMode implements ModifierExListener, KeyPres  
    332332            c = (osm instanceof Way) ? "way" : c;
    333333            if (shift) {
    334334                c += "_add";
    335             } else if (ctrl) {
     335            } else if (platformMenuShortcutKeyMask) {
    336336                c += osm == null || osm.isSelected() ? "_rm" : "_add";
    337337            }
    338338            break;
    public class SelectAction extends MapMode implements ModifierExListener, KeyPres  
    346346            if (lassoMode) {
    347347                c = "lasso";
    348348            } else {
    349                 c = "rect" + (shift ? "_add" : (ctrl && !PlatformManager.isPlatformOsx() ? "_rm" : ""));
     349                if (shift) {
     350                    c = "rect_add";
     351                } else if (platformMenuShortcutKeyMask) {
     352                    c = "rect_rm";
     353                } else {
     354                    c = "rect";
     355                }
    350356            }
    351357            break;
    352358        }
    public class SelectAction extends MapMode implements ModifierExListener, KeyPres  
    408414
    409415        // We don't want to change to draw tool if the user tries to (de)select
    410416        // stuff but accidentally clicks in an empty area when selection is empty
    411         cancelDrawMode = shift || ctrl;
     417        cancelDrawMode = shift || platformMenuShortcutKeyMask;
    412418        didMouseDrag = false;
    413419        initialMoveThresholdExceeded = false;
    414420        mouseDownTime = System.currentTimeMillis();
    public class SelectAction extends MapMode implements ModifierExListener, KeyPres  
    513519        if (mode == Mode.MOVE) {
    514520            // If ctrl is pressed we are in merge mode. Look for a nearby node,
    515521            // highlight it and adjust the cursor accordingly.
    516             final boolean canMerge = ctrl && !getLayerManager().getEditDataSet().getSelectedNodes().isEmpty();
     522            final boolean canMerge = platformMenuShortcutKeyMask && !getLayerManager().getEditDataSet().getSelectedNodes().isEmpty();
    517523            final OsmPrimitive p = canMerge ? findNodeToMergeTo(e.getPoint()) : null;
    518524            boolean needsRepaint = removeHighlighting();
    519525            if (p != null) {
    public class SelectAction extends MapMode implements ModifierExListener, KeyPres  
    669675     */
    670676    private void determineMapMode(boolean hasSelectionNearby) {
    671677        if (getLayerManager().getEditDataSet() != null) {
    672             if (shift && ctrl) {
     678            if (shift && platformMenuShortcutKeyMask) {
    673679                mode = Mode.ROTATE;
    674             } else if (alt && ctrl) {
     680            } else if (alt && platformMenuShortcutKeyMask) {
    675681                mode = Mode.SCALE;
    676682            } else if (hasSelectionNearby || dragInProgress()) {
    677683                mode = Mode.MOVE;
    public class SelectAction extends MapMode implements ModifierExListener, KeyPres  
    860866        } else {
    861867            // if small number of elements were moved,
    862868            updateKeyModifiers(e);
    863             if (ctrl) mergePrims(e.getPoint());
     869            if (platformMenuShortcutKeyMask) mergePrims(e.getPoint());
    864870        }
    865871    }
    866872
    public class SelectAction extends MapMode implements ModifierExListener, KeyPres  
    978984        // Virtual Ways: if non-empty the cursor is above a virtual node. So don't highlight
    979985        // anything if about to drag the virtual node (i.e. !released) but continue if the
    980986        // cursor is only released above a virtual node by accident (i.e. released). See #7018
    981         if (ds == null || (shift && ctrl) || (ctrl && !released) || (virtualManager.hasVirtualWaysToBeConstructed() && !released))
     987        if (ds == null || (shift && platformMenuShortcutKeyMask) || (platformMenuShortcutKeyMask && !released)
     988                || (virtualManager.hasVirtualWaysToBeConstructed() && !released))
    982989            return;
    983990
    984991        if (!released) {
    public class SelectAction extends MapMode implements ModifierExListener, KeyPres  
    988995            shift |= ds.getSelected().containsAll(prims);
    989996        }
    990997
    991         if (ctrl) {
     998        if (platformMenuShortcutKeyMask) {
    992999            // Ctrl on an item toggles its selection status,
    9931000            // but Ctrl on an *area* just clears those items
    9941001            // out of the selection.
    public class SelectAction extends MapMode implements ModifierExListener, KeyPres  
    11061113                        // special case:  for cycle groups of 2, we can toggle to the
    11071114                        // true nearest primitive on mousePressed right away
    11081115                        if (cycleList.size() == 2 && !waitForMouseUpParameter) {
    1109                             if (!(osm.equals(old) || osm.isNew() || ctrl)) {
     1116                            if (!(osm.equals(old) || osm.isNew() || platformMenuShortcutKeyMask)) {
    11101117                                cyclePrims = false;
    11111118                                osm = old;
    11121119                            } // else defer toggling to mouseRelease time in those cases:
    public class SelectAction extends MapMode implements ModifierExListener, KeyPres  
    11541161                    if (nxt.isSelected()) {
    11551162                        foundInDS = nxt;
    11561163                        // first selected primitive in cycleList is found
    1157                         if (cyclePrims || ctrl) {
     1164                        if (cyclePrims || platformMenuShortcutKeyMask) {
    11581165                            ds.clearSelection(foundInDS); // deselect it
    11591166                            nxt = i.hasNext() ? i.next() : first;
    11601167                            // return next one in cycle list (last->first)
    public class SelectAction extends MapMode implements ModifierExListener, KeyPres  
    11651172            }
    11661173
    11671174            // if "no-alt-cycling" is enabled, Ctrl-Click arrives here.
    1168             if (ctrl) {
     1175            if (platformMenuShortcutKeyMask) {
    11691176                // a member of cycleList was found in the current dataset selection
    11701177                if (foundInDS != null) {
    11711178                    // mouse was moved to a different selection group w/ a previous sel
  • src/org/openstreetmap/josm/gui/SelectionManager.java

    diff --git a/src/org/openstreetmap/josm/gui/SelectionManager.java b/src/org/openstreetmap/josm/gui/SelectionManager.java
    index 602f4491f9..0f9e4a0e92 100644
    a b import org.openstreetmap.josm.data.osm.Way;  
    2626import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
    2727import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable;
    2828import org.openstreetmap.josm.tools.ColorHelper;
     29import org.openstreetmap.josm.tools.PlatformManager;
    2930
    3031/**
    3132 * Manages the selection of a rectangle or a lasso loop. Listening to left and right mouse button
    public class SelectionManager implements MouseListener, MouseMotionListener, Pro  
    185186        if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() > 1 && MainApplication.getLayerManager().getActiveDataSet() != null) {
    186187            SelectByInternalPointAction.performSelection(MainApplication.getMap().mapView.getEastNorth(e.getX(), e.getY()),
    187188                    (e.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) != 0,
    188                     (e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) != 0);
     189                    (e.getModifiersEx() & PlatformManager.getPlatform().getMenuShortcutKeyMaskEx()) != 0);
    189190        } else if (e.getButton() == MouseEvent.BUTTON1) {
    190191            mousePosStart = mousePos = e.getPoint();
    191192