Changeset 18456 in josm


Ignore:
Timestamp:
2022-05-25T23:09:41+02:00 (2 years ago)
Author:
taylor.smock
Message:

Fix #22065: Mac users cannot deselect with ctrl

From the Mac OS HIG guidelines, "[as] much as possible,
avoid using the Control key as a modifier."

In this case, we were using ctrl to deselect elements (and
we disabled this on Mac), merge nodes, scale, and rotate.

All of those now use (meta) instead of ctrl on Mac.

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

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

    r17157 r18456  
    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
     
    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     * {@code true} if the platform specific menu key was pressed ("ctrl" on Linux/Windows, "cmd" on Mac)
     45     * @see PlatformHook#getMenuShortcutKeyMaskEx()
     46     * @since xxx
     47     */
     48    protected boolean platformMenuShortcutKeyMask;
    3649
    3750    /**
     
    155168
    156169    /**
    157      * Update internal ctrl, alt, shift mask from given extended modifiers mask.
     170     * Update internal ctrl, alt, shift, meta mask from given extended modifiers mask.
    158171     * @param modifiers event extended modifiers mask
    159172     * @since 12517
     
    163176        alt = (modifiers & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_GRAPH_DOWN_MASK)) != 0;
    164177        shift = (modifiers & InputEvent.SHIFT_DOWN_MASK) != 0;
     178        meta = (modifiers & InputEvent.META_DOWN_MASK) != 0;
     179        platformMenuShortcutKeyMask = (modifiers & PlatformManager.getPlatform().getMenuShortcutKeyMaskEx()) != 0;
    165180    }
    166181
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r18274 r18456  
    44import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    55import static org.openstreetmap.josm.tools.I18n.tr;
     6import static org.openstreetmap.josm.tools.I18n.trc;
    67import static org.openstreetmap.josm.tools.I18n.trn;
    78
     
    910import java.awt.Point;
    1011import java.awt.Rectangle;
     12import java.awt.event.InputEvent;
    1113import java.awt.event.KeyEvent;
    1214import java.awt.event.MouseEvent;
     
    288290
    289291        // CTRL toggles selection, but if while dragging CTRL means merge
    290         final boolean isToggleMode = ctrl && !dragInProgress();
     292        final boolean isToggleMode = platformMenuShortcutKeyMask && !dragInProgress();
    291293        if (c.isPresent() && (isToggleMode || !c.get().isSelected())) {
    292294            // only highlight primitives that will change the selection
     
    318320                // only consider merge if ctrl is pressed and there are nodes in
    319321                // the selection that could be merged
    320                 if (!ctrl || getLayerManager().getEditDataSet().getSelectedNodes().isEmpty()) {
     322                if (!platformMenuShortcutKeyMask || getLayerManager().getEditDataSet().getSelectedNodes().isEmpty()) {
    321323                    c = "move";
    322324                    break;
     
    333335            if (shift) {
    334336                c += "_add";
    335             } else if (ctrl) {
     337            } else if (platformMenuShortcutKeyMask) {
    336338                c += osm == null || osm.isSelected() ? "_rm" : "_add";
    337339            }
     
    346348            if (lassoMode) {
    347349                c = "lasso";
     350            } else if (shift) {
     351                c = "rect_add";
     352            } else if (platformMenuShortcutKeyMask) {
     353                c = "rect_rm";
    348354            } else {
    349                 c = "rect" + (shift ? "_add" : (ctrl && !PlatformManager.isPlatformOsx() ? "_rm" : ""));
     355                c = "rect";
    350356            }
    351357            break;
     
    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;
     
    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();
     
    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()) {
     
    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    }
     
    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
     
    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
     
    10181025    @Override
    10191026    public String getModeHelpText() {
     1027        // There needs to be a better way
     1028        final String menuKey;
     1029        switch (PlatformManager.getPlatform().getMenuShortcutKeyMaskEx()) {
     1030        case InputEvent.CTRL_DOWN_MASK:
     1031            menuKey = trc("SelectAction help", "Ctrl");
     1032            break;
     1033        case InputEvent.META_DOWN_MASK:
     1034            menuKey = trc("SelectAction help", "Meta");
     1035            break;
     1036        default:
     1037            throw new IllegalStateException("Unknown platform menu shortcut key for " + PlatformManager.getPlatform().getOSDescription());
     1038        }
     1039        final String type = this.lassoMode ? trc("SelectAction help", "lasso") : trc("SelectAction help", "rectangle");
    10201040        if (mouseDownButton == MouseEvent.BUTTON1 && mouseReleaseTime < mouseDownTime) {
    10211041            if (mode == Mode.SELECT)
    1022                 return tr("Release the mouse button to select the objects in the rectangle.");
     1042                return tr("Release the mouse button to select the objects in the {0}.", type);
    10231043            else if (mode == Mode.MOVE && (System.currentTimeMillis() - mouseDownTime >= initialMoveDelay)) {
    10241044                final DataSet ds = getLayerManager().getEditDataSet();
    10251045                final boolean canMerge = ds != null && !ds.getSelectedNodes().isEmpty();
    1026                 final String mergeHelp = canMerge ? (' ' + tr("Ctrl to merge with nearest node.")) : "";
     1046                final String mergeHelp = canMerge ? (' ' + tr("{0} to merge with nearest node.", menuKey)) : "";
    10271047                return tr("Release the mouse button to stop moving.") + mergeHelp;
    10281048            } else if (mode == Mode.ROTATE)
     
    10311051                return tr("Release the mouse button to stop scaling.");
    10321052        }
    1033         return tr("Move objects by dragging; Shift to add to selection (Ctrl to toggle); Shift-Ctrl to rotate selected; " +
    1034                   "Alt-Ctrl to scale selected; or change selection");
     1053        return tr("Move objects by dragging; Shift to add to selection ({0} to toggle); Shift-{0} to rotate selected; " +
     1054                "Alt-{0} to scale selected; or change selection", menuKey);
    10351055    }
    10361056
     
    11071127                        // true nearest primitive on mousePressed right away
    11081128                        if (cycleList.size() == 2 && !waitForMouseUpParameter) {
    1109                             if (!(osm.equals(old) || osm.isNew() || ctrl)) {
     1129                            if (!(osm.equals(old) || osm.isNew() || platformMenuShortcutKeyMask)) {
    11101130                                cyclePrims = false;
    11111131                                osm = old;
     
    11551175                        foundInDS = nxt;
    11561176                        // first selected primitive in cycleList is found
    1157                         if (cyclePrims || ctrl) {
     1177                        if (cyclePrims || platformMenuShortcutKeyMask) {
    11581178                            ds.clearSelection(foundInDS); // deselect it
    11591179                            nxt = i.hasNext() ? i.next() : first;
     
    11661186
    11671187            // if "no-alt-cycling" is enabled, Ctrl-Click arrives here.
    1168             if (ctrl) {
     1188            if (platformMenuShortcutKeyMask) {
    11691189                // a member of cycleList was found in the current dataset selection
    11701190                if (foundInDS != null) {
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectLassoAction.java

    r18122 r18456  
    5555        return MainApplication.getMap().mapModeSelect.layerIsSupported(l);
    5656    }
     57
     58    @Override
     59    public String getModeHelpText() {
     60        return MainApplication.getMap().mapModeSelect.getModeHelpText();
     61    }
    5762}
  • trunk/src/org/openstreetmap/josm/gui/SelectionManager.java

    r16438 r18456  
    2727import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable;
    2828import org.openstreetmap.josm.tools.ColorHelper;
     29import org.openstreetmap.josm.tools.PlatformManager;
    2930
    3031/**
     
    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();
Note: See TracChangeset for help on using the changeset viewer.