Ticket #1669: DontUseMainPastebufferForDuplicate.patch
| File DontUseMainPastebufferForDuplicate.patch, 4.3 KB (added by , 17 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/CopyAction.java
43 43 } 44 44 45 45 public void actionPerformed(ActionEvent e) { 46 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 47 if (sel.isEmpty()) { 48 JOptionPane.showMessageDialog(Main.parent, 49 tr("Please select something to copy.")); 50 return; 46 if(noSelection()) return; 47 48 Main.pasteBuffer = copyData(); 49 Main.main.menu.paste.setEnabled(true); /* now we have a paste buffer we can make paste available */ 50 51 for(JosmAction a : listeners) { 52 a.pasteBufferChanged(Main.pasteBuffer); 51 53 } 52 54 } 55 56 public static DataSet copyData() { 53 57 /* New pasteBuffer - will be assigned to the global one at the end */ 54 58 final DataSet pasteBuffer = new DataSet(); 55 59 final HashMap<OsmPrimitive,OsmPrimitive> map = new HashMap<OsmPrimitive,OsmPrimitive>(); 56 60 /* temporarily maps old nodes to new so we can do a true deep copy */ 57 61 62 if(noSelection()) return pasteBuffer; 63 58 64 /* scan the selected objects, mapping them to copies; when copying a way or relation, 59 65 * the copy references the copies of their child objects */ 60 66 new Visitor(){ … … 104 110 osm.visit(this); 105 111 } 106 112 }.visitAll(); 107 108 Main.pasteBuffer = pasteBuffer; 109 Main.main.menu.paste.setEnabled(true); /* now we have a paste buffer we can make paste available */ 110 111 for(JosmAction a : listeners) { 112 a.pasteBufferChanged(Main.pasteBuffer); 113 } 113 114 return pasteBuffer; 114 115 } 115 116 116 117 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 117 118 setEnabled(! newSelection.isEmpty()); 118 119 } 120 121 private static boolean noSelection() { 122 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 123 if (sel.isEmpty()) { 124 JOptionPane.showMessageDialog(Main.parent, 125 tr("Please select something to copy.")); 126 return true; 127 } 128 return false; 129 } 119 130 } -
src/org/openstreetmap/josm/actions/DuplicateAction.java
21 21 tr("Duplicate selection by copy and immediate paste."), 22 22 Shortcut.registerShortcut("system:duplicate", tr("Edit: {0}", tr("Duplicate")), KeyEvent.VK_D, Shortcut.GROUP_MENU), true); 23 23 setEnabled(false); 24 DataSet.selListeners.add(this);24 DataSet.selListeners.add(this); 25 25 } 26 26 27 27 public void actionPerformed(ActionEvent e) { 28 Main.main.menu.copy.actionPerformed(e); 29 Main.main.menu.paste.actionPerformed(e); 28 org.openstreetmap.josm.actions.PasteAction.pasteData(org.openstreetmap.josm.actions.CopyAction.copyData(), e); 30 29 } 31 30 32 31 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { -
src/org/openstreetmap/josm/actions/PasteAction.java
30 30 public PasteAction() { 31 31 super(tr("Paste"), "paste", tr("Paste contents of paste buffer."), 32 32 Shortcut.registerShortcut("system:paste", tr("Edit: {0}", tr("Paste")), KeyEvent.VK_V, Shortcut.GROUP_MENU), true); 33 setEnabled(false);33 setEnabled(false); 34 34 } 35 35 36 36 public void actionPerformed(ActionEvent e) { 37 DataSet pasteBuffer = Main.pasteBuffer; 38 37 pasteData(Main.pasteBuffer, e); 38 } 39 40 public static void pasteData(DataSet pasteBuffer, ActionEvent e) { 39 41 /* Find the middle of the pasteBuffer area */ 40 42 double maxEast = -1E100, minEast = 1E100, maxNorth = -1E100, minNorth = 1E100; 41 43 for (Node n : pasteBuffer.nodes) {
