Changeset 2892 in josm for trunk/src


Ignore:
Timestamp:
2010-01-25T22:15:44+01:00 (10 years ago)
Author:
bastiK
Message:

fixed #3135 - ability to copy id of selected object to copy-paste buffer

File:
1 edited

Legend:

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

    r2323 r2892  
    66import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    77
     8import java.awt.Toolkit;
     9import java.awt.datatransfer.Clipboard;
     10import java.awt.datatransfer.ClipboardOwner;
     11import java.awt.datatransfer.StringSelection;
     12import java.awt.datatransfer.Transferable;
    813import java.awt.event.ActionEvent;
    914import java.awt.event.KeyEvent;
     
    3540    public void actionPerformed(ActionEvent e) {
    3641        if(isEmptySelection()) return;
     42        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
    3743
    38         Main.pasteBuffer.makeCopy(getCurrentDataSet().getSelected());
     44        /* copy ids to the clipboard */
     45        StringBuilder idsBuilder = new StringBuilder();
     46        for (OsmPrimitive p : selection) {
     47            idsBuilder.append(p.getId()+",");
     48        }
     49        String ids = idsBuilder.substring(0, idsBuilder.length() - 1);
     50        try {
     51            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
     52                    new StringSelection(ids.toString()), new ClipboardOwner() {
     53                        public void lostOwnership(Clipboard clipboard, Transferable contents) {}
     54                    }
     55            );
     56        }
     57        catch (RuntimeException x) {}
     58       
     59        Main.pasteBuffer.makeCopy(selection);
    3960        Main.pasteSource = getEditLayer();
    4061        Main.main.menu.paste.setEnabled(true); /* now we have a paste buffer we can make paste available */
Note: See TracChangeset for help on using the changeset viewer.