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.DataSet;
|
---|
12 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
13 | import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler;
|
---|
14 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Action, to paste all tags from one primitive to another.
|
---|
18 | *
|
---|
19 | * It will take the primitive from the copy-paste buffer an apply all its tags
|
---|
20 | * to the selected primitive(s).
|
---|
21 | *
|
---|
22 | * @author David Earl
|
---|
23 | */
|
---|
24 | public final class PasteTagsAction extends JosmAction {
|
---|
25 |
|
---|
26 | private static final String HELP = ht("/Action/PasteTags");
|
---|
27 | private final OsmTransferHandler transferHandler = new OsmTransferHandler();
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Constructs a new {@code PasteTagsAction}.
|
---|
31 | */
|
---|
32 | public PasteTagsAction() {
|
---|
33 | super(tr("Paste Tags"), "pastetags",
|
---|
34 | tr("Apply tags of contents of paste buffer to all selected items."),
|
---|
35 | Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")),
|
---|
36 | KeyEvent.VK_V, Shortcut.CTRL_SHIFT), true);
|
---|
37 | putValue("help", HELP);
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Override
|
---|
41 | public void actionPerformed(ActionEvent e) {
|
---|
42 | Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected();
|
---|
43 |
|
---|
44 | if (selection.isEmpty())
|
---|
45 | return;
|
---|
46 |
|
---|
47 | transferHandler.pasteTags(selection);
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | protected void updateEnabledState() {
|
---|
52 | DataSet ds = getLayerManager().getEditDataSet();
|
---|
53 | if (ds == null) {
|
---|
54 | setEnabled(false);
|
---|
55 | return;
|
---|
56 | }
|
---|
57 | // buffer listening slows down the program and is not very good for arbitrary text in buffer
|
---|
58 | setEnabled(!ds.selectionEmpty());
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Override
|
---|
62 | protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
|
---|
63 | setEnabled(selection != null && !selection.isEmpty());
|
---|
64 | }
|
---|
65 | }
|
---|