- Timestamp:
- 2009-03-25T09:43:40+01:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CopyAction.java
r1351 r1514 18 18 import org.openstreetmap.josm.data.SelectionChangedListener; 19 19 import org.openstreetmap.josm.data.osm.DataSet; 20 import org.openstreetmap.josm.data.osm.DataSource; 20 21 import org.openstreetmap.josm.data.osm.Relation; 21 22 import org.openstreetmap.josm.data.osm.RelationMember; … … 45 46 public void actionPerformed(ActionEvent e) { 46 47 if(noSelection()) return; 47 48 48 49 Main.pasteBuffer = copyData(); 49 50 Main.main.menu.paste.setEnabled(true); /* now we have a paste buffer we can make paste available */ … … 53 54 } 54 55 } 55 56 56 57 public static DataSet copyData() { 57 58 /* New pasteBuffer - will be assigned to the global one at the end */ … … 59 60 final HashMap<OsmPrimitive,OsmPrimitive> map = new HashMap<OsmPrimitive,OsmPrimitive>(); 60 61 /* temporarily maps old nodes to new so we can do a true deep copy */ 61 62 62 63 if(noSelection()) return pasteBuffer; 63 64 64 65 /* scan the selected objects, mapping them to copies; when copying a way or relation, 65 66 * the copy references the copies of their child objects */ … … 87 88 nodes.add((Node)map.get(n)); 88 89 } 89 wnew.nodes.clear();90 90 wnew.nodes.addAll(nodes); 91 91 pasteBuffer.addPrimitive(wnew); … … 109 109 for (OsmPrimitive osm : Main.ds.getSelected()) 110 110 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")); 111 119 } 112 120 }.visitAll(); 113 121 114 122 return pasteBuffer; 115 123 } … … 118 126 setEnabled(! newSelection.isEmpty()); 119 127 } 120 128 121 129 private static boolean noSelection() { 122 130 Collection<OsmPrimitive> sel = Main.ds.getSelected(); -
trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java
r1169 r1514 19 19 import org.openstreetmap.josm.data.SelectionChangedListener; 20 20 import org.openstreetmap.josm.data.osm.DataSet; 21 import org.openstreetmap.josm.data.osm.DataSource; 21 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 23 import org.openstreetmap.josm.tools.Shortcut; … … 36 37 /* scan the paste buffer, and add tags to each of the selected objects. 37 38 * 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))); 49 51 } 50 52 } … … 53 55 public void actionPerformed(ActionEvent e) { 54 56 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 } 58 80 Main.main.undoRedo.add(new SequenceCommand(tr("Paste Tags"), clist)); 59 81 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.