Ticket #1669: DontUseMainPastebufferForDuplicate.patch

File DontUseMainPastebufferForDuplicate.patch, 4.3 KB (added by xeen, 17 years ago)

This patch enables the copy/paste action to use any buffer. It changes the duplicateAction to use this new functionality.

  • src/org/openstreetmap/josm/actions/CopyAction.java

     
    4343    }
    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 */
    6066        new Visitor(){
     
    104110                    osm.visit(this);
    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
    116117    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    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}
  • src/org/openstreetmap/josm/actions/DuplicateAction.java

     
    2121            tr("Duplicate selection by copy and immediate paste."),
    2222            Shortcut.registerShortcut("system:duplicate", tr("Edit: {0}", tr("Duplicate")), KeyEvent.VK_D, Shortcut.GROUP_MENU), true);
    2323        setEnabled(false);
    24             DataSet.selListeners.add(this);
     24        DataSet.selListeners.add(this);
    2525    }
    2626
    2727    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);
    3029    }
    3130
    3231    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
  • src/org/openstreetmap/josm/actions/PasteAction.java

     
    3030    public PasteAction() {
    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;
    4143        for (Node n : pasteBuffer.nodes) {