Changeset 34770 in osm
- Timestamp:
- 2018-12-07T16:58:49+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/UndoSelectionAction.java
r33297 r34770 30 30 } 31 31 32 private int myAutomaticSelectionHash;33 32 private Collection<OsmPrimitive> lastSel; 34 33 private int index; 34 35 35 @Override 36 36 public void actionPerformed(ActionEvent e) { … … 39 39 LinkedList<Collection<? extends OsmPrimitive>> history = ds.getSelectionHistory(); 40 40 if (history == null || history.isEmpty()) return; // empty history 41 if (lastSel != null) { 42 Collection<OsmPrimitive> selection = ds.getSelected(); 43 if (selection.containsAll(lastSel) && lastSel.containsAll(selection)) { 44 // repeated action 45 } else { 46 index = -1; 47 } 48 } 49 41 50 int num = history.size(); 51 int k = 0; 42 52 43 Collection<OsmPrimitive> selection = ds.getSelected();44 45 if (selection != null && selection.hashCode() != myAutomaticSelectionHash) {46 // manual selection or another pluging selection noticed47 index = history.indexOf(lastSel);48 // first is selected, next list is previous selection49 }50 int k = 0;51 53 Set<OsmPrimitive> newsel = new HashSet<>(); 52 do{54 while (k < num) { 53 55 if (index+1 < history.size()) index++; else index = 0; 54 56 Collection<? extends OsmPrimitive> histsel = history.get(index); … … 56 58 newsel.clear(); 57 59 newsel.addAll(histsel); 58 newsel.retainAll(ds.allNonDeletedPrimitives()); 59 if (!newsel.isEmpty()) break; 60 newsel.removeIf(p -> p == null || p.isDeleted()); 60 61 k++; 61 } while (k < num); 62 if (!newsel.isEmpty()) { 63 if (newsel.containsAll(ds.getSelected()) && ds.getSelected().containsAll(newsel)) { 64 // ignore no-change selection 65 continue; 66 } 67 break; 68 } 69 } 62 70 71 // set new selection (is added to history) 63 72 ds.setSelected(newsel); 64 73 lastSel = ds.getSelected(); 65 myAutomaticSelectionHash = lastSel.hashCode();66 // remember last automatic selection67 74 } 68 75 } … … 70 77 @Override 71 78 protected void updateEnabledState() { 72 setEnabled(getLayerManager().getEditDataSet() != null); 79 DataSet ds = getLayerManager().getEditDataSet(); 80 lastSel = null; 81 index = -1; 82 setEnabled(ds != null && ds.getSelectionHistory().isEmpty()); 73 83 } 74 84 }
Note:
See TracChangeset
for help on using the changeset viewer.