Changeset 1351 in josm


Ignore:
Timestamp:
2009-01-31T14:43:27+01:00 (13 years ago)
Author:
stoecker
Message:

close #1669. Patch by xeen

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

Legend:

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

    r1169 r1351  
    4444
    4545    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);
    5153        }
    52 
     54    }
     55   
     56    public static DataSet copyData() {
    5357        /* New pasteBuffer - will be assigned to the global one at the end */
    5458        final DataSet pasteBuffer = new DataSet();
    5559        final HashMap<OsmPrimitive,OsmPrimitive> map = new HashMap<OsmPrimitive,OsmPrimitive>();
    5660        /* temporarily maps old nodes to new so we can do a true deep copy */
    57 
     61       
     62        if(noSelection()) return pasteBuffer;
     63       
    5864        /* scan the selected objects, mapping them to copies; when copying a way or relation,
    5965         * the copy references the copies of their child objects */
     
    105111            }
    106112        }.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;
    114115    }
    115116
     
    117118        setEnabled(! newSelection.isEmpty());
    118119    }
     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    }
    119130}
  • trunk/src/org/openstreetmap/josm/actions/DuplicateAction.java

    r1169 r1351  
    1010
    1111import org.openstreetmap.josm.Main;
     12import org.openstreetmap.josm.actions.CopyAction;
     13import org.openstreetmap.josm.actions.PasteAction;
    1214import org.openstreetmap.josm.data.SelectionChangedListener;
    1315import org.openstreetmap.josm.data.osm.DataSet;
     
    2224            Shortcut.registerShortcut("system:duplicate", tr("Edit: {0}", tr("Duplicate")), KeyEvent.VK_D, Shortcut.GROUP_MENU), true);
    2325        setEnabled(false);
    24             DataSet.selListeners.add(this);
     26        DataSet.selListeners.add(this);
    2527    }
    2628
    2729    public void actionPerformed(ActionEvent e) {
    28         Main.main.menu.copy.actionPerformed(e);
    29         Main.main.menu.paste.actionPerformed(e);
     30        PasteAction.pasteData(CopyAction.copyData(), e);
    3031    }
    3132
  • trunk/src/org/openstreetmap/josm/actions/PasteAction.java

    r1205 r1351  
    3131        super(tr("Paste"), "paste", tr("Paste contents of paste buffer."),
    3232            Shortcut.registerShortcut("system:paste", tr("Edit: {0}", tr("Paste")), KeyEvent.VK_V, Shortcut.GROUP_MENU), true);
    33             setEnabled(false);
     33        setEnabled(false);
    3434    }
    3535
    3636    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) {
    3941        /* Find the middle of the pasteBuffer area */
    4042        double maxEast = -1E100, minEast = 1E100, maxNorth = -1E100, minNorth = 1E100;
Note: See TracChangeset for help on using the changeset viewer.