Ignore:
Timestamp:
2010-10-24T15:07:01+02:00 (13 years ago)
Author:
jttt
Message:

Fix #5579 allow paste tags in the relation editor

File:
1 edited

Legend:

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

    r3385 r3640  
    2323import org.openstreetmap.josm.data.osm.PrimitiveData;
    2424import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy;
     25import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy.PasteBufferChangedListener;
     26import org.openstreetmap.josm.data.osm.Tag;
    2527import org.openstreetmap.josm.data.osm.TagCollection;
    26 import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy.PasteBufferChangedListener;
    2728import org.openstreetmap.josm.gui.conflict.tags.PasteTagsConflictResolverDialog;
    2829import org.openstreetmap.josm.tools.Shortcut;
     
    4243        private final Collection<PrimitiveData> source;
    4344        private final Collection<OsmPrimitive> target;
    44         private final List<Command> commands = new ArrayList<Command>();
     45        private final List<Tag> commands = new ArrayList<Tag>();
    4546
    4647        public TagPaster(Collection<PrimitiveData> source, Collection<OsmPrimitive> target) {
     
    100101        }
    101102
    102         protected Command buildChangeCommand(Collection<? extends OsmPrimitive> selection, TagCollection tc) {
    103             List<Command> commands = new ArrayList<Command>();
     103        protected void buildChangeCommand(Collection<? extends OsmPrimitive> selection, TagCollection tc) {
    104104            for (String key : tc.getKeys()) {
    105                 String value = tc.getValues(key).iterator().next();
    106                 value = value.equals("") ? null : value;
    107                 commands.add(new ChangePropertyCommand(selection,key,value));
    108             }
    109             if (!commands.isEmpty()) {
    110                 String title1 = trn("Pasting {0} tag", "Pasting {0} tags", tc.getKeys().size(), tc.getKeys().size());
    111                 String title2 = trn("to {0} primitive", "to {0} primtives", selection.size(), selection.size());
    112                 return new SequenceCommand(
    113                         title1 + " " + title2,
    114                         commands
    115                 );
    116             }
    117             return null;
     105                commands.add(new Tag(key, tc.getValues(key).iterator().next()));
     106            }
    118107        }
    119108
     
    166155                if (dialog.isCanceled())
    167156                    return;
    168                 Command cmd = buildChangeCommand(target, dialog.getResolution());
    169                 commands.add(cmd);
     157                buildChangeCommand(target, dialog.getResolution());
    170158            } else {
    171159                // no conflicts in the source tags to resolve. Just apply the tags
    172160                // to the target primitives
    173161                //
    174                 Command cmd = buildChangeCommand(target, tc);
    175                 commands.add(cmd);
     162                buildChangeCommand(target, tc);
    176163            }
    177164        }
     
    218205                for (OsmPrimitiveType type:OsmPrimitiveType.values()) {
    219206                    if (hasSourceTagsByType(type) && hasTargetPrimitives(type.getOsmClass())) {
    220                         Command cmd = buildChangeCommand(target, getSourceTagsByType(type));
    221                         commands.add(cmd);
     207                        buildChangeCommand(target, getSourceTagsByType(type));
    222208                    }
    223209                }
     
    236222                for (OsmPrimitiveType type:OsmPrimitiveType.values()) {
    237223                    if (hasSourceTagsByType(type) && hasTargetPrimitives(type.getOsmClass())) {
    238                         Command cmd = buildChangeCommand(OsmPrimitive.getFilteredList(target, type.getOsmClass()), dialog.getResolution(type));
    239                         commands.add(cmd);
     224                        buildChangeCommand(OsmPrimitive.getFilteredList(target, type.getOsmClass()), dialog.getResolution(type));
    240225                    }
    241226                }
     
    243228        }
    244229
    245         public List<Command> execute() {
     230        public List<Tag> execute() {
    246231            commands.clear();
    247232            if (isHeteogeneousSource()) {
     
    256241
    257242    public void actionPerformed(ActionEvent e) {
    258         if (getCurrentDataSet().getSelected().isEmpty())
     243        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
     244
     245        if (selection.isEmpty())
    259246            return;
    260         TagPaster tagPaster = new TagPaster(Main.pasteBuffer.getDirectlyAdded(), getCurrentDataSet().getSelected());
    261         for (Command c:tagPaster.execute()) {
    262             Main.main.undoRedo.add(c);
    263         }
     247
     248        TagPaster tagPaster = new TagPaster(Main.pasteBuffer.getDirectlyAdded(), selection);
     249
     250        List<Command> commands = new ArrayList<Command>();
     251        for (Tag tag: tagPaster.execute()) {
     252            commands.add(new ChangePropertyCommand(selection, tag.getKey(), "".equals(tag.getValue())?null:tag.getValue()));
     253        }
     254        if (!commands.isEmpty()) {
     255            String title1 = trn("Pasting {0} tag", "Pasting {0} tags", commands.size(), commands.size());
     256            String title2 = trn("to {0} primitive", "to {0} primtives", selection.size(), selection.size());
     257            Main.main.undoRedo.add(
     258                    new SequenceCommand(
     259                            title1 + " " + title2,
     260                            commands
     261                    ));
     262        }
     263
    264264    }
    265265
Note: See TracChangeset for help on using the changeset viewer.