Changeset 10766 in josm
- Timestamp:
- 2016-08-07T22:52:29+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/DuplicateAction.java
r10682 r10766 10 10 import java.util.Collection; 11 11 12 import org.openstreetmap.josm.Main;13 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler;15 13 import org.openstreetmap.josm.gui.datatransfer.PrimitiveTransferable; 16 14 import org.openstreetmap.josm.gui.datatransfer.data.PrimitiveTransferData; … … 20 18 * An action that duplicates the given nodes. They are not added to the clipboard. 21 19 */ 22 public final class DuplicateAction extends JosmAction {20 public final class DuplicateAction extends AbstractPasteAction { 23 21 24 22 /** … … 35 33 public void actionPerformed(ActionEvent e) { 36 34 PrimitiveTransferData data = PrimitiveTransferData.getDataWithReferences(getLayerManager().getEditDataSet().getSelected()); 37 new OsmTransferHandler().pasteOn(Main.getLayerManager().getEditLayer(), 38 PasteAction.computePastePosition(e, getValue(NAME)), new PrimitiveTransferable(data)); 35 doPaste(e, new PrimitiveTransferable(data)); 39 36 } 40 37 -
trunk/src/org/openstreetmap/josm/actions/PasteAction.java
r10682 r10766 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 7 8 import java.awt.MouseInfo;9 import java.awt.Point;10 import java.awt.datatransfer.FlavorEvent;11 import java.awt.datatransfer.FlavorListener;12 import java.awt.event.ActionEvent;13 8 import java.awt.event.KeyEvent; 14 9 15 10 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm.data.coor.EastNorth;17 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;18 import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler;19 11 import org.openstreetmap.josm.tools.Shortcut; 20 12 … … 23 15 * @since 404 24 16 */ 25 public final class PasteAction extends JosmAction implements FlavorListener { 26 27 private final OsmTransferHandler transferHandler; 17 public final class PasteAction extends AbstractPasteAction { 28 18 29 19 /** … … 31 21 */ 32 22 public PasteAction() { 33 super(tr("Paste"), "paste", tr("Paste contents of paste buffer."),23 super(tr("Paste"), "paste", tr("Paste contents of clipboard."), 34 24 Shortcut.registerShortcut("system:paste", tr("Edit: {0}", tr("Paste")), KeyEvent.VK_V, Shortcut.CTRL), true); 35 25 putValue("help", ht("/Action/Paste")); … … 37 27 Main.registerActionShortcut(this, 38 28 Shortcut.registerShortcut("system:paste:cua", tr("Edit: {0}", tr("Paste")), KeyEvent.VK_INSERT, Shortcut.SHIFT)); 39 transferHandler = new OsmTransferHandler();40 ClipboardUtils.getClipboard().addFlavorListener(this);41 }42 43 @Override44 public void actionPerformed(ActionEvent e) {45 transferHandler.pasteOn(Main.getLayerManager().getEditLayer(), computePastePosition(e, getValue(NAME)));46 }47 48 static EastNorth computePastePosition(ActionEvent e, Object name) {49 // default to paste in center of map (pasted via menu or cursor not in MapView)50 EastNorth mPosition = Main.map.mapView.getCenter();51 // We previously checked for modifier to know if the action has been trigerred via shortcut or via menu52 // But this does not work if the shortcut is changed to a single key (see #9055)53 // Observed behaviour: getActionCommand() returns Action.NAME when triggered via menu, but shortcut text when triggered with it54 if (e != null && !name.equals(e.getActionCommand())) {55 final Point mp = MouseInfo.getPointerInfo().getLocation();56 final Point tl = Main.map.mapView.getLocationOnScreen();57 final Point pos = new Point(mp.x-tl.x, mp.y-tl.y);58 if (Main.map.mapView.contains(pos)) {59 mPosition = Main.map.mapView.getEastNorth(pos.x, pos.y);60 }61 }62 return mPosition;63 }64 65 @Override66 protected void updateEnabledState() {67 setEnabled(getLayerManager().getEditDataSet() != null && transferHandler.isDataAvailable());68 }69 70 @Override71 public void flavorsChanged(FlavorEvent e) {72 updateEnabledState();73 29 } 74 30 } -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r10611 r10766 74 74 import org.openstreetmap.josm.actions.OverpassDownloadAction; 75 75 import org.openstreetmap.josm.actions.PasteAction; 76 import org.openstreetmap.josm.actions.PasteAtSourcePositionAction; 76 77 import org.openstreetmap.josm.actions.PasteTagsAction; 77 78 import org.openstreetmap.josm.actions.PreferenceToggleAction; … … 195 196 /** Edit / Paste */ 196 197 public final PasteAction paste = new PasteAction(); 198 /** Edit / Paste at source */ 199 private final PasteAtSourcePositionAction pasteAtSource = new PasteAtSourcePositionAction(); 197 200 /** Edit / Paste Tags */ 198 201 public final PasteTagsAction pasteTags = new PasteTagsAction(); … … 680 683 add(editMenu, copyCoordinates, true); 681 684 add(editMenu, paste); 685 add(editMenu, pasteAtSource, true); 682 686 add(editMenu, pasteTags); 683 687 add(editMenu, duplicate); -
trunk/src/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandler.java
r10737 r10766 83 83 * Paste the current clipboard current at the given position 84 84 * @param editLayer The layer to paste on. 85 * @param mPosition The position to paste at. 85 * @param mPosition The position to paste at. If it is <code>null</code>, the original position will be used. 86 86 */ 87 87 public void pasteOn(OsmDataLayer editLayer, EastNorth mPosition) { … … 93 93 * Paste the given clipboard current at the given position 94 94 * @param editLayer The layer to paste on. 95 * @param mPosition The position to paste at. 95 * @param mPosition The position to paste at. If it is <code>null</code>, the original position will be used. 96 96 * @param transferable The transferable to use. 97 97 */ -
trunk/src/org/openstreetmap/josm/gui/datatransfer/importers/PrimitiveDataPaster.java
r10604 r10766 50 50 51 51 EastNorth center = pasteBuffer.getCenter(); 52 EastNorth offset = center == null ? null: pasteAt.subtract(center);52 EastNorth offset = center == null || pasteAt == null ? new EastNorth(0, 0) : pasteAt.subtract(center); 53 53 54 54 AddPrimitivesCommand command = createNewPrimitives(pasteBuffer, offset, layer);
Note:
See TracChangeset
for help on using the changeset viewer.