Ticket #14862: 14862-v2.patch
File 14862-v2.patch, 2.7 KB (added by , 6 years ago) |
---|
-
src/org/openstreetmap/josm/plugins/utilsplugin2/actions/TagBufferAction.java
20 20 import org.openstreetmap.josm.command.SequenceCommand; 21 21 import org.openstreetmap.josm.data.UndoRedoHandler; 22 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 24 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter; 25 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 26 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 27 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 23 28 import org.openstreetmap.josm.tools.Shortcut; 24 29 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 25 30 … … 28 33 * 29 34 * @author Zverik 30 35 */ 31 public class TagBufferAction extends JosmAction {36 public class TagBufferAction extends JosmAction implements DataSetListenerAdapter.Listener { 32 37 private static final String TITLE = tr("Copy tags from previous selection"); 33 38 private static final Predicate<OsmPrimitive> IS_TAGGED_PREDICATE = object -> object.isTagged(); 34 39 private Map<String, String> tags = new HashMap<>(); 35 40 private Map<String, String> currentTags = new HashMap<>(); 36 41 private Set<OsmPrimitive> selectionBuf = new HashSet<>(); 42 private final DataSetListenerAdapter dataSetListenerAdapter = new DataSetListenerAdapter(this); 37 43 38 44 /** 39 45 * Constructs a new {@code TagBufferAction}. … … 45 51 true, false); 46 52 // The fields are not initialized while the super constructor is running, so we have to call this afterwards: 47 53 installAdapters(); 54 DatasetEventManager.getInstance().addDatasetListener(dataSetListenerAdapter, FireMode.IMMEDIATELY); 48 55 } 49 56 50 57 @Override … … 77 84 setEnabled(false); 78 85 if (selectionBuf != null) 79 86 selectionBuf.clear(); 80 } else 87 } else { 81 88 updateEnabledState(getLayerManager().getEditDataSet().getSelected()); 89 } 82 90 } 83 91 84 92 @Override … … 137 145 } 138 146 } 139 147 } 148 149 @Override 150 public void processDatasetEvent(AbstractDatasetChangedEvent event) { 151 if (event instanceof TagsChangedEvent) { 152 TagsChangedEvent e = (TagsChangedEvent) event; 153 if (!e.getPrimitive().isSelected() || e.getPrimitive().getKeys().isEmpty()) 154 return; 155 currentTags.clear(); 156 currentTags.putAll(e.getPrimitive().getKeys()); 157 } 158 } 140 159 }