Ignore:
Timestamp:
2007-11-04T21:22:34+01:00 (18 years ago)
Author:
gebner
Message:

SelectAction: Fix shift-select and ctrl-select.

Before r452 if you wanted to move all the selected objects you had to
shift-click on the selection and then drag. r452 tried to remedy this
situation by clearing the selection if you didn't click on an already selected
object. This made it impossible to add something to the selection by
shift-clicking it.

This change postpones replacing the selection until after the mouse released,
i.e. when we know whether the user wanted to select or move.

File:
1 edited

Legend:

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

    r452 r454  
    4545        private Mode mode = null;
    4646        private long mouseDownTime = 0;
     47        private boolean didMove = false;
    4748
    4849        /**
     
    175176                Main.map.mapView.repaint();
    176177                mousePos = e.getPoint();
     178
     179                didMove = true;
    177180        }
    178181
     
    194197               
    195198                mouseDownTime = System.currentTimeMillis();
    196 
    197                 // find the object that was clicked on.
    198                 // if the object is not part of the current selection, clear current
    199                 // selection before proceeding.
    200                 Collection<OsmPrimitive> osmColl = null;
    201                 OsmPrimitive osm = Main.map.mapView.getNearest(e.getPoint());
    202                 if (osm == null) {
    203                         osmColl = Collections.emptySet();
    204                         Main.ds.setSelected();
    205                 } else {
    206                         osmColl = Collections.singleton(osm);
    207                         if (!Main.ds.getSelected().contains(osm)) Main.ds.setSelected();
    208                 }
    209                
     199                didMove = false;
     200
     201                Collection<OsmPrimitive> osmColl =
     202                        Main.map.mapView.getNearestCollection(e.getPoint());
     203
    210204                if (ctrl && shift) {
    211205                        if (Main.ds.getSelected().isEmpty()) selectPrims(osmColl, true, false);
     
    213207                        setCursor(ImageProvider.getCursor("rotate", null));
    214208                } else if (!osmColl.isEmpty()) {
    215                         if (Main.ds.getSelected().isEmpty()) selectPrims(osmColl, shift, ctrl);
     209                        // Only add to selection for now, we only do replace and remove in
     210                        // mouseReleased if the user didn't try to move.
     211                        selectPrims(osmColl, true, ctrl);
    216212                        mode = Mode.move;
    217213                } else {
     
    239235                if (mode == Mode.move) {
    240236                        boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
    241                         if (ctrl) {
     237                        boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
     238                        if (!didMove) {
     239                                selectPrims(
     240                                        Main.map.mapView.getNearestCollection(e.getPoint()),
     241                                        shift, ctrl);
     242                        } else if (ctrl) {
    242243                                Collection<OsmPrimitive> selection = Main.ds.getSelected();
    243244                                Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection);
Note: See TracChangeset for help on using the changeset viewer.