Changeset 34792 in osm for applications/editors/josm/plugins/utilsplugin2/src
- Timestamp:
- 2018-12-28T17:40:08+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/TagSourceAction.java
r34454 r34792 6 6 import java.awt.event.ActionEvent; 7 7 import java.awt.event.KeyEvent; 8 import java.util.ArrayList; 8 9 import java.util.Collection; 9 import java.util.HashSet; 10 import java.util.Set; 10 import java.util.List; 11 11 12 12 import org.openstreetmap.josm.actions.JosmAction; … … 25 25 private static final String TITLE = tr("Add Source Tag"); 26 26 private String source; 27 private Set<OsmPrimitive> selectionBuf = new HashSet<>(); 28 private boolean clickedTwice = false; 27 private List<OsmPrimitive> selectionBuf = new ArrayList<>(); 29 28 30 29 public TagSourceAction() { … … 45 44 UndoRedoHandler.getInstance().add(new ChangePropertyCommand(selection, "source", source)); 46 45 } 47 48 46 @Override 49 47 protected void updateEnabledState() { 50 48 if (getLayerManager().getEditDataSet() == null) { 51 49 setEnabled(false); 52 if (selectionBuf != null) 53 selectionBuf.clear(); 50 selectionBuf = new ArrayList<>(); 54 51 } else 55 52 updateEnabledState(getLayerManager().getEditDataSet().getSelected()); 56 53 } 57 54 55 58 56 @Override 59 57 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 60 if (selection == null || selection.isEmpty()) { 61 selectionBuf.clear(); 62 clickedTwice = false; 63 setEnabled(false); 64 return; 58 if (!selectionBuf.isEmpty()) { 59 String newSource = null; 60 for (OsmPrimitive p : selectionBuf) { 61 String s = p.get("source"); 62 if (s != null) { 63 if (newSource == null) 64 newSource = s; 65 else { 66 if (!newSource.equals(s)) { 67 newSource = null; 68 break; 69 } 70 } 71 } 72 } 73 if (newSource != null && !newSource.isEmpty()) { 74 source = newSource; 75 Config.getPref().put("sourcetag.value", source); 76 } 65 77 } 66 67 if (selectionBuf.size() == selection.size() && selectionBuf.containsAll(selection)) { 68 if (!clickedTwice) 69 clickedTwice = true; 70 else { 71 // tags may have been changed, get the source 72 String newSource = null; 73 for (OsmPrimitive p : selection) { 74 String value = p.get("source"); 75 if (value != null && newSource == null) 76 newSource = value; 77 else if (value != null ? !value.equals(newSource) : newSource != null) { 78 newSource = ""; 79 break; 80 } 81 } 82 if (newSource != null && newSource.length() > 0 && !newSource.equals(source)) { 83 source = newSource; 84 Config.getPref().put("sourcetag.value", source); 85 } 86 } 87 } else 88 clickedTwice = false; 89 selectionBuf.clear(); 90 selectionBuf.addAll(selection); 91 setEnabled(source != null && source.length() > 0); 78 selectionBuf = new ArrayList<>(selection); 79 setEnabled(!selection.isEmpty() && source != null && !source.isEmpty()); 92 80 } 93 81 }
Note:
See TracChangeset
for help on using the changeset viewer.