1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.KeyEvent;
|
---|
9 | import java.util.Collection;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
12 | import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler;
|
---|
13 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Action, to paste all tags from one primitive to another.
|
---|
17 | *
|
---|
18 | * It will take the primitive from the copy-paste buffer an apply all its tags
|
---|
19 | * to the selected primitive(s).
|
---|
20 | *
|
---|
21 | * @author David Earl
|
---|
22 | */
|
---|
23 | public final class PasteTagsAction extends JosmAction {
|
---|
24 |
|
---|
25 | private static final String HELP = ht("/Action/PasteTags");
|
---|
26 | private final OsmTransferHandler transferHandler = new OsmTransferHandler();
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Constructs a new {@code PasteTagsAction}.
|
---|
30 | */
|
---|
31 | public PasteTagsAction() {
|
---|
32 | super(tr("Paste Tags"), "pastetags",
|
---|
33 | tr("Apply tags of contents of paste buffer to all selected items."),
|
---|
34 | Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")),
|
---|
35 | KeyEvent.VK_V, Shortcut.CTRL_SHIFT), true);
|
---|
36 | putValue("help", HELP);
|
---|
37 | }
|
---|
38 |
|
---|
39 | @Override
|
---|
40 | public void actionPerformed(ActionEvent e) {
|
---|
41 | Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected();
|
---|
42 |
|
---|
43 | if (selection.isEmpty())
|
---|
44 | return;
|
---|
45 |
|
---|
46 | transferHandler.pasteTags(selection);
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | protected void updateEnabledState() {
|
---|
51 | updateEnabledStateOnCurrentSelection();
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
|
---|
56 | updateEnabledStateOnModifiableSelection(selection);
|
---|
57 | }
|
---|
58 | }
|
---|