---
core-dave/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java | 40 +++++-----
core-dave/src/org/openstreetmap/josm/data/osm/DataSet.java | 31 +++++--
2 files changed, 41 insertions(+), 30 deletions(-)
diff -puN src/org/openstreetmap/josm/gui/SelectionManager.java~fix-shift-selection src/org/openstreetmap/josm/gui/SelectionManager.java
diff -puN src/org/openstreetmap/josm/actions/mapmode/SelectAction.java~fix-shift-selection src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
|
a
|
b
|
public class SelectAction extends MapMod
|
| 498 | 498 | } |
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | | DataSet.fireSelectionChanged(selection); |
| | 501 | getCurrentDataSet().fireSelectionChanged(); |
| 502 | 502 | } |
| 503 | 503 | } |
| 504 | 504 | |
| … |
… |
public class SelectAction extends MapMod
|
| 514 | 514 | |
| 515 | 515 | public void selectPrims(Collection<OsmPrimitive> selectionList, boolean shift, |
| 516 | 516 | boolean ctrl, boolean released, boolean area) { |
| | 517 | DataSet ds = getCurrentDataSet(); |
| 517 | 518 | if ((shift && ctrl) || (ctrl && !released)) |
| 518 | 519 | return; // not allowed together |
| 519 | 520 | |
| 520 | | Collection<OsmPrimitive> curSel; |
| 521 | | if (!ctrl && !shift) { |
| 522 | | curSel = new LinkedList<OsmPrimitive>(); // new selection will replace the old. |
| | 521 | // plain clicks with no modifiers clear the selection |
| | 522 | if (!ctrl && !shift) |
| | 523 | ds.clearSelection(); |
| | 524 | |
| | 525 | if (ctrl) { |
| | 526 | // Ctrl on an item toggles its selection status, |
| | 527 | // but Ctrl on an *area* just clears those items |
| | 528 | // out of the selection. |
| | 529 | if (area) |
| | 530 | ds.clearSelection(selectionList); |
| | 531 | else |
| | 532 | ds.toggleSelected(selectionList); |
| 523 | 533 | } else { |
| 524 | | curSel = getCurrentDataSet().getSelected(); |
| | 534 | // This is either a plain click (which means we |
| | 535 | // previously cleared the selection), or a |
| | 536 | // shift-click where we are adding things to an |
| | 537 | // existing selection. |
| | 538 | ds.addSelected(selectionList); |
| 525 | 539 | } |
| 526 | | |
| 527 | | for (OsmPrimitive osm : selectionList) |
| 528 | | { |
| 529 | | if (ctrl) |
| 530 | | { |
| 531 | | if(curSel.contains(osm)) { |
| 532 | | curSel.remove(osm); |
| 533 | | } else if(!area) { |
| 534 | | curSel.add(osm); |
| 535 | | } |
| 536 | | } else { |
| 537 | | curSel.add(osm); |
| 538 | | } |
| 539 | | } |
| 540 | | getCurrentDataSet().setSelected(curSel); |
| | 540 | ds.fireSelectionChanged(); |
| 541 | 541 | Main.map.mapView.repaint(); |
| 542 | 542 | } |
| 543 | 543 | |
diff -puN src/org/openstreetmap/josm/data/osm/DataSet.java~fix-shift-selection src/org/openstreetmap/josm/data/osm/DataSet.java
|
a
|
b
|
public class DataSet implements Cloneabl
|
| 241 | 241 | |
| 242 | 242 | LinkedHashSet<OsmPrimitive> selectedPrimitives = new LinkedHashSet<OsmPrimitive>(); |
| 243 | 243 | |
| | 244 | public boolean toggleSelected(Collection<OsmPrimitive> osm) { |
| | 245 | for (OsmPrimitive o : osm) |
| | 246 | this.toggleSelected(o); |
| | 247 | return true; |
| | 248 | } |
| | 249 | public boolean toggleSelected(OsmPrimitive... osm) { |
| | 250 | return this.toggleSelected(Arrays.asList(osm)); |
| | 251 | } |
| 244 | 252 | public boolean toggleSelected(OsmPrimitive osm) { |
| 245 | 253 | if (!selectedPrimitives.remove(osm)) { |
| 246 | 254 | selectedPrimitives.add(osm); |
| … |
… |
public class DataSet implements Cloneabl
|
| 275 | 283 | public void setSelected(Collection<? extends OsmPrimitive> selection, boolean fireSelectionChangeEvent) { |
| 276 | 284 | selectedPrimitives = new LinkedHashSet<OsmPrimitive>(selection); |
| 277 | 285 | if (fireSelectionChangeEvent) { |
| 278 | | fireSelectionChanged(selection); |
| | 286 | fireSelectionChanged(); |
| 279 | 287 | } |
| 280 | 288 | } |
| 281 | 289 | |
| … |
… |
public class DataSet implements Cloneabl
|
| 313 | 321 | public void addSelected(Collection<? extends OsmPrimitive> selection, boolean fireSelectionChangeEvent) { |
| 314 | 322 | selectedPrimitives.addAll(selection); |
| 315 | 323 | if (fireSelectionChangeEvent) { |
| 316 | | fireSelectionChanged(selection); |
| | 324 | fireSelectionChanged(); |
| 317 | 325 | } |
| 318 | 326 | } |
| 319 | 327 | |
| … |
… |
public class DataSet implements Cloneabl
|
| 325 | 333 | } |
| 326 | 334 | List<OsmPrimitive> list = Arrays.asList(osm); |
| 327 | 335 | setSelected(list); |
| 328 | | fireSelectionChanged(list); |
| | 336 | fireSelectionChanged(); |
| 329 | 337 | } |
| 330 | 338 | |
| 331 | 339 | /** |
| … |
… |
public class DataSet implements Cloneabl
|
| 358 | 366 | public void clearSelection(OsmPrimitive... osm) { |
| 359 | 367 | clearSelection(Arrays.asList(osm)); |
| 360 | 368 | } |
| 361 | | private void clearSelection(Collection<? extends OsmPrimitive> list) { |
| | 369 | public void clearSelection(Collection<? extends OsmPrimitive> list) { |
| 362 | 370 | if (list == null) |
| 363 | 371 | return; |
| 364 | 372 | selectedPrimitives.removeAll(list); |
| 365 | 373 | } |
| | 374 | public void clearSelection() { |
| | 375 | selectedPrimitives = new LinkedHashSet<OsmPrimitive>(); |
| | 376 | } |
| 366 | 377 | |
| 367 | 378 | /** |
| 368 | 379 | * Return all selected items in the collection. |
| … |
… |
public class DataSet implements Cloneabl
|
| 379 | 390 | return sel; |
| 380 | 391 | } |
| 381 | 392 | |
| 382 | | /** |
| 383 | | * Remember to fire an selection changed event. A call to this will not fire the event |
| 384 | | * immediately. For more, |
| 385 | | * @see SelectionChangedListener |
| 386 | | */ |
| 387 | | public static void fireSelectionChanged(Collection<? extends OsmPrimitive> sel) { |
| | 393 | public void fireSelectionChanged() |
| | 394 | { |
| | 395 | __fireSelectionChanged(selectedPrimitives); |
| | 396 | } |
| | 397 | |
| | 398 | public static void __fireSelectionChanged(Collection<? extends OsmPrimitive> sel) { |
| 388 | 399 | for (SelectionChangedListener l : selListeners) { |
| 389 | 400 | l.selectionChanged(sel); |
| 390 | 401 | } |