Changeset 1514 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2009-03-25T09:43:40+01:00 (16 years ago)
Author:
stoecker
Message:

close #1187 - pasting tags between object types - patch by xeen

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
2 edited

Legend:

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

    r1351 r1514  
    1818import org.openstreetmap.josm.data.SelectionChangedListener;
    1919import org.openstreetmap.josm.data.osm.DataSet;
     20import org.openstreetmap.josm.data.osm.DataSource;
    2021import org.openstreetmap.josm.data.osm.Relation;
    2122import org.openstreetmap.josm.data.osm.RelationMember;
     
    4546    public void actionPerformed(ActionEvent e) {
    4647        if(noSelection()) return;
    47        
     48
    4849        Main.pasteBuffer = copyData();
    4950        Main.main.menu.paste.setEnabled(true); /* now we have a paste buffer we can make paste available */
     
    5354        }
    5455    }
    55    
     56
    5657    public static DataSet copyData() {
    5758        /* New pasteBuffer - will be assigned to the global one at the end */
     
    5960        final HashMap<OsmPrimitive,OsmPrimitive> map = new HashMap<OsmPrimitive,OsmPrimitive>();
    6061        /* temporarily maps old nodes to new so we can do a true deep copy */
    61        
     62
    6263        if(noSelection()) return pasteBuffer;
    63        
     64
    6465        /* scan the selected objects, mapping them to copies; when copying a way or relation,
    6566         * the copy references the copies of their child objects */
     
    8788                    nodes.add((Node)map.get(n));
    8889                }
    89                 wnew.nodes.clear();
    9090                wnew.nodes.addAll(nodes);
    9191                pasteBuffer.addPrimitive(wnew);
     
    109109                for (OsmPrimitive osm : Main.ds.getSelected())
    110110                    osm.visit(this);
     111
     112                // Used internally only (in PasteTagsAction), therefore no need to translate these
     113                if(Main.ds.getSelectedNodes().size() > 0)
     114                    pasteBuffer.dataSources.add(new DataSource(null, "Copied Nodes"));
     115                if(Main.ds.getSelectedWays().size() > 0)
     116                    pasteBuffer.dataSources.add(new DataSource(null, "Copied Ways"));
     117                if(Main.ds.getSelectedRelations().size() > 0)
     118                    pasteBuffer.dataSources.add(new DataSource(null, "Copied Relations"));
    111119            }
    112120        }.visitAll();
    113        
     121
    114122        return pasteBuffer;
    115123    }
     
    118126        setEnabled(! newSelection.isEmpty());
    119127    }
    120    
     128
    121129    private static boolean noSelection() {
    122130        Collection<OsmPrimitive> sel = Main.ds.getSelected();
  • trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java

    r1169 r1514  
    1919import org.openstreetmap.josm.data.SelectionChangedListener;
    2020import org.openstreetmap.josm.data.osm.DataSet;
     21import org.openstreetmap.josm.data.osm.DataSource;
    2122import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2223import org.openstreetmap.josm.tools.Shortcut;
     
    3637        /* scan the paste buffer, and add tags to each of the selected objects.
    3738         * If a tag already exists, it is overwritten */
    38         if (selectionSubset != null && ! selectionSubset.isEmpty()) {
    39             for (Iterator<? extends OsmPrimitive> it = pasteBufferSubset.iterator(); it.hasNext();) {
    40                 OsmPrimitive osm = it.next();
    41                 Map<String, String> m = osm.keys;
    42                 if(m != null)
    43                 {
    44                     for (String key : m.keySet()) {
    45                         if (! key.equals("created_by"))
    46                             clist.add(new ChangePropertyCommand(selectionSubset, key, osm.keys.get(key)));
    47                     }
    48                 }
     39        if (selectionSubset == null || selectionSubset.isEmpty())
     40            return;
     41
     42        for (Iterator<? extends OsmPrimitive> it = pasteBufferSubset.iterator(); it.hasNext();) {
     43            OsmPrimitive osm = it.next();
     44            Map<String, String> m = osm.keys;
     45            if(m == null)
     46                continue;
     47
     48            for (String key : m.keySet()) {
     49                if (! key.equals("created_by"))
     50                    clist.add(new ChangePropertyCommand(selectionSubset, key, osm.keys.get(key)));
    4951            }
    5052        }
     
    5355    public void actionPerformed(ActionEvent e) {
    5456        Collection<Command> clist = new LinkedList<Command>();
    55         pasteKeys(clist, Main.pasteBuffer.nodes, Main.ds.getSelectedNodes());
    56         pasteKeys(clist, Main.pasteBuffer.ways, Main.ds.getSelectedWays());
    57         pasteKeys(clist, Main.pasteBuffer.relations, Main.ds.getSelectedRelations());
     57        String pbSource = "Multiple Sources";
     58        if(Main.pasteBuffer.dataSources.size() == 1)
     59            pbSource = ((DataSource) Main.pasteBuffer.dataSources.toArray()[0]).origin;
     60
     61        boolean pbNodes = Main.pasteBuffer.nodes.size() > 0;
     62        boolean pbWays  = Main.pasteBuffer.ways.size() > 0;
     63
     64        boolean seNodes = Main.ds.getSelectedNodes().size() > 0;
     65        boolean seWays  = Main.ds.getSelectedWays().size() > 0;
     66        boolean seRels  = Main.ds.getSelectedRelations().size() > 0;
     67
     68        if(!seNodes && seWays && !seRels && pbNodes && pbSource.equals("Copied Nodes")) {
     69            // Copy from nodes to ways
     70            pasteKeys(clist, Main.pasteBuffer.nodes, Main.ds.getSelectedWays());
     71        } else if(seNodes && !seWays && !seRels && pbWays && pbSource.equals("Copied Ways")) {
     72            // Copy from ways to nodes
     73            pasteKeys(clist, Main.pasteBuffer.ways, Main.ds.getSelectedNodes());
     74        } else {
     75            // Copy from equal to equal
     76            pasteKeys(clist, Main.pasteBuffer.nodes, Main.ds.getSelectedNodes());
     77            pasteKeys(clist, Main.pasteBuffer.ways, Main.ds.getSelectedWays());
     78            pasteKeys(clist, Main.pasteBuffer.relations, Main.ds.getSelectedRelations());
     79        }
    5880        Main.main.undoRedo.add(new SequenceCommand(tr("Paste Tags"), clist));
    5981        Main.ds.setSelected(Main.ds.getSelected()); // to force selection listeners, in particular the tag panel, to update
Note: See TracChangeset for help on using the changeset viewer.