Ignore:
Timestamp:
2016-08-07T22:52:29+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #13290 - pasting from other layer changes objects position (modified patch by michael2402) - gsoc-core

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

Legend:

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

    r10682 r10766  
    1010import java.util.Collection;
    1111
    12 import org.openstreetmap.josm.Main;
    1312import org.openstreetmap.josm.data.osm.OsmPrimitive;
    14 import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler;
    1513import org.openstreetmap.josm.gui.datatransfer.PrimitiveTransferable;
    1614import org.openstreetmap.josm.gui.datatransfer.data.PrimitiveTransferData;
     
    2018 * An action that duplicates the given nodes. They are not added to the clipboard.
    2119 */
    22 public final class DuplicateAction extends JosmAction {
     20public final class DuplicateAction extends AbstractPasteAction {
    2321
    2422    /**
     
    3533    public void actionPerformed(ActionEvent e) {
    3634        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));
    3936    }
    4037
  • trunk/src/org/openstreetmap/josm/actions/PasteAction.java

    r10682 r10766  
    66import static org.openstreetmap.josm.tools.I18n.tr;
    77
    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;
    138import java.awt.event.KeyEvent;
    149
    1510import 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;
    1911import org.openstreetmap.josm.tools.Shortcut;
    2012
     
    2315 * @since 404
    2416 */
    25 public final class PasteAction extends JosmAction implements FlavorListener {
    26 
    27     private final OsmTransferHandler transferHandler;
     17public final class PasteAction extends AbstractPasteAction {
    2818
    2919    /**
     
    3121     */
    3222    public PasteAction() {
    33         super(tr("Paste"), "paste", tr("Paste contents of paste buffer."),
     23        super(tr("Paste"), "paste", tr("Paste contents of clipboard."),
    3424                Shortcut.registerShortcut("system:paste", tr("Edit: {0}", tr("Paste")), KeyEvent.VK_V, Shortcut.CTRL), true);
    3525        putValue("help", ht("/Action/Paste"));
     
    3727        Main.registerActionShortcut(this,
    3828                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     @Override
    44     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 menu
    52         // 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 it
    54         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     @Override
    66     protected void updateEnabledState() {
    67         setEnabled(getLayerManager().getEditDataSet() != null && transferHandler.isDataAvailable());
    68     }
    69 
    70     @Override
    71     public void flavorsChanged(FlavorEvent e) {
    72         updateEnabledState();
    7329    }
    7430}
Note: See TracChangeset for help on using the changeset viewer.