source: josm/trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java@ 11192

Last change on this file since 11192 was 10737, checked in by Don-vip, 8 years ago

fix #12900 - Conflicts in pasted tags cannot be resolved, cannot be resolved to "none" (patch by michael2402) - gsoc-core

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.awt.event.KeyEvent;
9import java.util.Collection;
10
11import org.openstreetmap.josm.data.osm.DataSet;
12import org.openstreetmap.josm.data.osm.OsmPrimitive;
13import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler;
14import 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 */
24public 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}
Note: See TracBrowser for help on using the repository browser.