Ignore:
Timestamp:
2010-07-25T15:56:14+02:00 (14 years ago)
Author:
jttt
Message:

Support Copy&Paste in relation editor

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

Legend:

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

    r2892 r3384  
    33package org.openstreetmap.josm.actions;
    44
     5import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    56import static org.openstreetmap.josm.tools.I18n.tr;
    6 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    77
    88import java.awt.Toolkit;
     
    1414import java.awt.event.KeyEvent;
    1515import java.util.Collection;
    16 import java.util.LinkedList;
    1716
    1817import javax.swing.JOptionPane;
     
    2019import org.openstreetmap.josm.Main;
    2120import org.openstreetmap.josm.data.osm.OsmPrimitive;
     21import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2222import org.openstreetmap.josm.tools.Shortcut;
    2323
    2424public final class CopyAction extends JosmAction {
    25 
    26     private LinkedList<JosmAction> listeners;
    2725
    2826    public CopyAction() {
     
    3129                Shortcut.registerShortcut("system:copy", tr("Edit: {0}", tr("Copy")), KeyEvent.VK_C, Shortcut.GROUP_MENU), true);
    3230        putValue("help", ht("/Action/Copy"));
    33         listeners = new LinkedList<JosmAction>();
    34     }
    35 
    36     @Override public void addListener(JosmAction a) {
    37         listeners.add(a);
    3831    }
    3932
     
    4235        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
    4336
     37        copy(getEditLayer(), selection);
     38    }
     39
     40    public static void copy(OsmDataLayer source, Collection<OsmPrimitive> primitives) {
    4441        /* copy ids to the clipboard */
    4542        StringBuilder idsBuilder = new StringBuilder();
    46         for (OsmPrimitive p : selection) {
     43        for (OsmPrimitive p : primitives) {
    4744            idsBuilder.append(p.getId()+",");
    4845        }
     
    5653        }
    5754        catch (RuntimeException x) {}
    58        
    59         Main.pasteBuffer.makeCopy(selection);
    60         Main.pasteSource = getEditLayer();
    61         Main.main.menu.paste.setEnabled(true); /* now we have a paste buffer we can make paste available */
    6255
    63         for(JosmAction a : listeners) {
    64             a.pasteBufferChanged(Main.pasteBuffer);
    65         }
     56        Main.pasteBuffer.makeCopy(primitives);
     57        Main.pasteSource = source;
    6658    }
    6759
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r3327 r3384  
    1212import org.openstreetmap.josm.data.osm.DataSet;
    1313import org.openstreetmap.josm.data.osm.OsmPrimitive;
    14 import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy;
    1514import org.openstreetmap.josm.gui.MapView;
    1615import org.openstreetmap.josm.gui.layer.Layer;
     
    103102     * needs to be overridden to be useful
    104103     */
    105     public void pasteBufferChanged(PrimitiveDeepCopy newPasteBuffer) {
    106         return;
    107     }
    108 
    109     /**
    110      * needs to be overridden to be useful
    111      */
    112104    public void addListener(JosmAction a) {
    113105        return;
  • trunk/src/org/openstreetmap/josm/actions/PasteAction.java

    r2932 r3384  
    2323import org.openstreetmap.josm.data.osm.RelationMemberData;
    2424import org.openstreetmap.josm.data.osm.WayData;
     25import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy.PasteBufferChangedListener;
    2526import org.openstreetmap.josm.gui.ExtendedDialog;
    2627import org.openstreetmap.josm.gui.layer.Layer;
    2728import org.openstreetmap.josm.tools.Shortcut;
    2829
    29 public final class PasteAction extends JosmAction {
     30public final class PasteAction extends JosmAction implements PasteBufferChangedListener {
    3031
    3132    public PasteAction() {
     
    3334                Shortcut.registerShortcut("system:paste", tr("Edit: {0}", tr("Paste")), KeyEvent.VK_V, Shortcut.GROUP_MENU), true);
    3435        putValue("help", ht("/Action/Paste"));
     36        Main.pasteBuffer.addPasteBufferChangedListener(this);
    3537    }
    3638
     
    167169        setEnabled(!Main.pasteBuffer.isEmpty());
    168170    }
     171
     172    @Override
     173    public void pasteBufferChanged(PrimitiveDeepCopy pasteBuffer) {
     174        updateEnabledState();
     175    }
    169176}
  • trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java

    r2512 r3384  
    33package org.openstreetmap.josm.actions;
    44
     5import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    56import static org.openstreetmap.josm.tools.I18n.tr;
    6 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    77import static org.openstreetmap.josm.tools.I18n.trn;
    88
     
    2424import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy;
    2525import org.openstreetmap.josm.data.osm.TagCollection;
     26import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy.PasteBufferChangedListener;
    2627import org.openstreetmap.josm.gui.conflict.tags.PasteTagsConflictResolverDialog;
    2728import org.openstreetmap.josm.tools.Shortcut;
    2829
    29 public final class PasteTagsAction extends JosmAction {
     30public final class PasteTagsAction extends JosmAction implements PasteBufferChangedListener {
    3031
    3132    public PasteTagsAction(JosmAction copyAction) {
     
    3334                tr("Apply tags of contents of paste buffer to all selected items."),
    3435                Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")), KeyEvent.VK_V, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), true);
    35         copyAction.addListener(this);
     36        Main.pasteBuffer.addPasteBufferChangedListener(this);
    3637        putValue("help", ht("/Action/PasteTags"));
    3738    }
Note: See TracChangeset for help on using the changeset viewer.