Ticket #12357: CopyTagsAction.patch
File CopyTagsAction.patch, 10.0 KB (added by , 8 years ago) |
---|
-
new file src/org/openstreetmap/josm/actions/CopyTagsAction.java
diff --git a/src/org/openstreetmap/josm/actions/CopyTagsAction.java b/src/org/openstreetmap/josm/actions/CopyTagsAction.java new file mode 100644 index 0000000..ef7231d
- + 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 javax.swing.JOptionPane; 12 13 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 16 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 17 import org.openstreetmap.josm.tools.Shortcut; 18 import org.openstreetmap.josm.tools.Utils; 19 import java.util.Set; 20 import java.util.TreeSet; 21 22 /** 23 * Copy OSM primitives to clipboard in order to paste them, or their tags, somewhere else. 24 * @since 404 25 */ 26 public final class CopyTagsAction extends JosmAction { 27 28 /** 29 * Constructs a new {@code CopyTagsAction}. 30 */ 31 public CopyTagsAction() { 32 super(tr("Copy Tags"), "copy", 33 tr("Copy all tags of selected objects to paste buffer."), 34 createShortcut(), true); 35 putValue("help", ht("/Action/CopyTags")); 36 } 37 38 public static Shortcut createShortcut() { 39 return Shortcut.registerShortcut("system:copytags", tr("Edit: {0}", tr("Copy Tags")), KeyEvent.VK_T, Shortcut.CTRL_SHIFT); 40 } 41 42 @Override 43 public void actionPerformed(ActionEvent e) { 44 if (isEmptySelection()) return; 45 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 46 copy(getEditLayer(), selection); 47 } 48 49 /** 50 * Copies the tags of object to the clipboard. The output by this function 51 * looks similar to: key=value\nkey=value 52 * @param source The OSM data layer source 53 * @param primitives The OSM primitives to copy 54 */ 55 public static void copy(OsmDataLayer source, Collection<OsmPrimitive> primitives) { 56 Set<String> values = new TreeSet<>(); 57 for (OsmPrimitive p : primitives) { 58 Collection<String> s = p.getTagsAsString(); 59 if (s != null) values.addAll(s); 60 } 61 if (!values.isEmpty()) Utils.copyToClipboard(Utils.join("\n", values)); 62 } 63 64 @Override 65 protected void updateEnabledState() { 66 if (getCurrentDataSet() == null) { 67 setEnabled(false); 68 } else { 69 updateEnabledState(getCurrentDataSet().getSelected()); 70 } 71 } 72 73 @Override 74 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 75 setEnabled(selection != null && !selection.isEmpty()); 76 } 77 78 private static boolean isEmptySelection() { 79 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 80 if (sel.isEmpty()) { 81 JOptionPane.showMessageDialog( 82 Main.parent, 83 tr("Please select something to copy."), 84 tr("Information"), 85 JOptionPane.INFORMATION_MESSAGE 86 ); 87 return true; 88 } 89 return false; 90 } 91 } -
src/org/openstreetmap/josm/actions/HelpAction.java
diff --git a/src/org/openstreetmap/josm/actions/HelpAction.java b/src/org/openstreetmap/josm/actions/HelpAction.java index 7874504..f936f25 100644
a b public class HelpAction extends JosmAction { 31 31 32 32 private HelpAction(boolean shortcut) { 33 33 super(tr("Help"), "help", null, 34 shortcut ? Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1, Shortcut.DIRECT) : null,34 shortcut ? createShortcut() : null, 35 35 true); 36 36 setEnabled(!Main.isOffline(OnlineResource.JOSM_WEBSITE)); 37 37 } 38 38 39 public static Shortcut createShortcut() { 40 return Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1, Shortcut.DIRECT); 41 } 42 39 43 /** 40 44 * Constructs a new {@code HelpAction} without assigning a shortcut. 41 45 * @return a new {@code HelpAction} -
src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
diff --git a/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java b/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java index 090fbd6..d855daa 100644
a b import java.util.Collections; 10 10 import java.util.Date; 11 11 import java.util.HashMap; 12 12 import java.util.HashSet; 13 import java.util.LinkedList; 14 import java.util.List; 13 15 import java.util.Map; 14 16 import java.util.Map.Entry; 15 17 import java.util.Objects; … … import java.util.concurrent.atomic.AtomicLong; 18 20 19 21 import org.openstreetmap.josm.tools.LanguageInfo; 20 22 import org.openstreetmap.josm.tools.Utils; 23 import org.openstreetmap.josm.data.osm.Tag; 21 24 22 25 /** 23 26 * Abstract class to represent common features of the datatypes primitives. … … public abstract class AbstractPrimitive implements IPrimitive { 746 749 return result; 747 750 } 748 751 752 public Collection<Tag> getTags() { 753 List<Tag> tags = new LinkedList<>(); 754 for (Entry<String, String> kv : getKeys().entrySet()) { 755 tags.add(new Tag(kv.getKey(), kv.getValue())); 756 } 757 return tags; 758 } 759 760 public Collection<String> getTagsAsString() { 761 List<String> tagStrings = new LinkedList<>(); 762 for (Tag tag : getTags()) { 763 tagStrings.add(tag.toString()); 764 } 765 return tagStrings; 766 } 767 749 768 /** 750 769 * Replies true, if the map of key/value pairs of this primitive is not empty. 751 770 * -
src/org/openstreetmap/josm/gui/MainMenu.java
diff --git a/src/org/openstreetmap/josm/gui/MainMenu.java b/src/org/openstreetmap/josm/gui/MainMenu.java index 40ec6d0..aa7eadd 100644
a b import org.openstreetmap.josm.actions.ChangesetManagerToggleAction; 34 34 import org.openstreetmap.josm.actions.CloseChangesetAction; 35 35 import org.openstreetmap.josm.actions.CombineWayAction; 36 36 import org.openstreetmap.josm.actions.CopyAction; 37 import org.openstreetmap.josm.actions.CopyTagsAction; 37 38 import org.openstreetmap.josm.actions.CopyCoordinatesAction; 38 39 import org.openstreetmap.josm.actions.CreateCircleAction; 39 40 import org.openstreetmap.josm.actions.CreateMultipolygonAction; … … public class MainMenu extends JMenuBar { 188 189 public final RedoAction redo = new RedoAction(); 189 190 /** Edit / Copy */ 190 191 public final CopyAction copy = new CopyAction(); 192 /** Edit / Copy Tags */ 193 public final JosmAction copyTags = new CopyTagsAction(); 191 194 /** Edit / Copy Coordinates */ 192 195 public final JosmAction copyCoordinates = new CopyCoordinatesAction(); 193 196 /** Edit / Paste */ … … public class MainMenu extends JMenuBar { 669 672 Main.main.undoRedo.addCommandQueueListener(redo); 670 673 editMenu.addSeparator(); 671 674 add(editMenu, copy); 675 add(editMenu, copyTags, true); 672 676 add(editMenu, copyCoordinates, true); 673 677 add(editMenu, paste); 674 678 add(editMenu, pasteTags); -
src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
diff --git a/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java b/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java index 0ea557b..212ba1d 100644
a b public class LayerListDialog extends ToggleDialog { 285 285 } 286 286 }); 287 287 288 // Show/Activate layer on Enterkey press288 // Show/Activate layer on Space key press 289 289 InputMapUtils.addSpacebarAction(layerList, showHideLayerAction); 290 290 291 291 createLayout(layerList, true, Arrays.asList( -
src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
diff --git a/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java b/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java index efcf1ec..2b334a1 100644
a b import javax.swing.table.TableModel; 52 52 import javax.swing.table.TableRowSorter; 53 53 54 54 import org.openstreetmap.josm.Main; 55 import org.openstreetmap.josm.actions.CopyTagsAction; 56 import org.openstreetmap.josm.actions.HelpAction; 55 57 import org.openstreetmap.josm.actions.JosmAction; 56 58 import org.openstreetmap.josm.actions.relation.DownloadMembersAction; 57 59 import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction; … … implements SelectionChangedListener, MapView.EditLayerChangeListener, DataSetLis 1122 1124 1123 1125 class HelpAction extends AbstractAction { 1124 1126 HelpAction() { 1125 putValue(NAME, tr("Go to OSM wiki for tag help (F1)"));1127 putValue(NAME, tr("Go to OSM wiki for tag help")); 1126 1128 putValue(SHORT_DESCRIPTION, tr("Launch browser with wiki help for selected object")); 1127 1129 putValue(SMALL_ICON, ImageProvider.get("dialogs", "search")); 1130 org.openstreetmap.josm.actions.HelpAction.createShortcut().setAccelerator(this); 1128 1131 } 1129 1132 1130 1133 @Override … … implements SelectionChangedListener, MapView.EditLayerChangeListener, DataSetLis 1328 1331 CopyAllKeyValueAction() { 1329 1332 putValue(NAME, tr("Copy all Keys/Values")); 1330 1333 putValue(SHORT_DESCRIPTION, tr("Copy the key and value of all the tags to clipboard")); 1334 CopyTagsAction.createShortcut().setAccelerator(this); 1331 1335 } 1332 1336 1333 1337 @Override 1334 1338 protected Collection<String> getString(OsmPrimitive p, String key) { 1335 List<String> r = new LinkedList<>(); 1336 for (Entry<String, String> kv : p.getKeys().entrySet()) { 1337 r.add(new Tag(kv.getKey(), kv.getValue()).toString()); 1338 } 1339 return r; 1339 return p.getTagsAsString(); 1340 1340 } 1341 1341 } 1342 1342