Ticket #16411: copy_with_relations.patch
| File copy_with_relations.patch, 6.9 KB (added by , 8 years ago) |
|---|
-
utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/UtilsPlugin2.java
From 64f733610d4b28ef9133805acc01fa8f93932c7f Mon Sep 17 00:00:00 2001 From: Brian Hatchl <brian.hatchl@radiantsolutions.com> Date: Wed, 13 Jun 2018 17:38:37 -0400 Subject: [PATCH] Squashed commit of the following: commit f52b00c1ceeed2070570b7895548a256292acb5a Author: Brian Hatchl <brian.hatchl@radiantsolutions.com> Date: Wed Jun 13 17:13:41 2018 -0400 need to always include selected so we don't miss features that don't belong to relations in the selection commit 115a3f7c1e267eec25dce3e0329394eda9dda640 Author: Brian Hatchl <brian.hatchl@radiantsolutions.com> Date: Tue Jun 12 13:21:27 2018 -0400 make the relations selected to give a visual cue to what is copied commit e5218b2c7df76cad2aa3424eed97769984be2273 Author: Brian Hatchl <brian.hatchl@radiantsolutions.com> Date: Tue Jun 12 11:50:36 2018 -0400 Rename class and change shortcut to Ctrl+K so avoid conflict with opening Conflict Dialog. commit 9e92930179246ad0b3971784e533650200b5d84a Author: Brian Hatchl <brian.hatchl@radiantsolutions.com> Date: Mon Jun 11 15:07:01 2018 -0400 My suggested edits commit bdd2cb52a3dc5cc79caeac0ba69c73ec67f8d8df Author: montrosemotel@hotmail.com <montrosemotel@hotmail.com> Date: Wed May 30 11:35:40 2018 -0600 Fixes to 321. --- .../josm/plugins/utilsplugin2/UtilsPlugin2.java | 4 + .../actions/CopyWithRelationsAction.java | 86 ++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/CopyWithRelationsAction.java diff --git a/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/UtilsPlugin2.java b/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/UtilsPlugin2.java index 7f2a4df..48ca905 100644a b import org.openstreetmap.josm.plugins.PluginInformation; 14 14 import org.openstreetmap.josm.plugins.utilsplugin2.actions.AddIntersectionsAction; 15 15 import org.openstreetmap.josm.plugins.utilsplugin2.actions.AlignWayNodesAction; 16 16 import org.openstreetmap.josm.plugins.utilsplugin2.actions.CopyTagsAction; 17 import org.openstreetmap.josm.plugins.utilsplugin2.actions.CopyWithRelationsAction; 17 18 import org.openstreetmap.josm.plugins.utilsplugin2.actions.ExtractPointAction; 18 19 import org.openstreetmap.josm.plugins.utilsplugin2.actions.PasteRelationsAction; 19 20 import org.openstreetmap.josm.plugins.utilsplugin2.actions.SplitObjectAction; … … public class UtilsPlugin2 extends Plugin { 84 85 JMenuItem selectHighway; 85 86 JMenuItem selectAreaBoundary; 86 87 88 JMenuItem copyWithRelations; 89 87 90 JMenuItem selectURL; 88 91 89 92 JMenuItem drawArc; … … public class UtilsPlugin2 extends Plugin { 115 118 wiki = MainMenu.add(dataMenu, new OpenPageAction()); 116 119 latlon = MainMenu.add(toolsMenu, new LatLonAction()); 117 120 drawArc = MainMenu.add(toolsMenu, new CurveAction()); 121 copyWithRelations = MainMenu.add(toolsMenu, new CopyWithRelationsAction()); 118 122 119 123 selectionMenu.addSeparator(); 120 124 -
new file utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/CopyWithRelationsAction.java
diff --git a/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/CopyWithRelationsAction.java b/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/CopyWithRelationsAction.java new file mode 100644 index 0000000..24dfac9
- + 1 // License: GPL. For details, see LICENSE file. 2 // Author: Nick Tobin 3 package org.openstreetmap.josm.plugins.utilsplugin2.actions; 4 5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 8 import java.awt.event.ActionEvent; 9 import java.awt.event.KeyEvent; 10 import java.util.ArrayList; 11 import java.util.Collection; 12 13 import javax.swing.JOptionPane; 14 15 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm.actions.JosmAction; 17 import org.openstreetmap.josm.data.osm.DataSet; 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 import org.openstreetmap.josm.data.osm.Relation; 20 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils; 21 import org.openstreetmap.josm.gui.datatransfer.PrimitiveTransferable; 22 import org.openstreetmap.josm.gui.datatransfer.data.PrimitiveTransferData; 23 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 24 import org.openstreetmap.josm.tools.Shortcut; 25 26 /** 27 * Copy OSM primitives and any parent relations and members to clipboard in order to paste them, or their tags, somewhere else. 28 */ 29 public class CopyWithRelationsAction extends JosmAction { 30 31 private static final String label = "Copy with relations"; 32 /** 33 * Constructs a new {@code CopyWithRelationsAction}. 34 */ 35 public CopyWithRelationsAction() { 36 super(tr(label), "copy", 37 tr("Select and copy parent relations of selected objects to paste buffer."), 38 Shortcut.registerShortcut("system:copywithrelations", tr("Edit: {0}", tr(label)), KeyEvent.VK_K, Shortcut.CTRL), 39 true, CopyWithRelationsAction.class.getName(), true); 40 putValue("help", ht("/Action/CopyWithRelations")); 41 } 42 43 @Override 44 public void actionPerformed(ActionEvent e) { 45 DataSet set = getLayerManager().getEditDataSet(); 46 Collection<OsmPrimitive> selection = set.getSelected(); 47 Collection<Relation> relations = OsmPrimitive.getParentRelations(selection); 48 Collection<OsmPrimitive> copies = new ArrayList<>(); 49 copies.addAll(selection); //include selection so something is copied if no relations 50 if (!relations.isEmpty()) { 51 copies.addAll(relations); 52 set.setSelected(copies); 53 } 54 copy(getLayerManager().getEditLayer(), copies); 55 } 56 57 /** 58 * Copies the given primitive ids to the clipboard. The output by this function 59 * looks similar to: node 1089302677,node 1089303458,way 93793372 60 * @param source The OSM data layer source 61 * @param primitives The OSM primitives to copy 62 */ 63 public static void copy(OsmDataLayer source, Collection<OsmPrimitive> primitives) { 64 // copy ids to the clipboard 65 ClipboardUtils.copy(new PrimitiveTransferable(PrimitiveTransferData.getDataWithReferences(primitives), source)); 66 } 67 68 @Override 69 protected void updateEnabledState() { 70 updateEnabledStateOnCurrentSelection(); 71 } 72 73 @Override 74 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 75 setEnabled(selection != null && !selection.isEmpty()); 76 } 77 78 protected void showEmptySelectionWarning() { 79 JOptionPane.showMessageDialog( 80 Main.parent, 81 tr("Please select something to copy."), 82 tr("Information"), 83 JOptionPane.INFORMATION_MESSAGE 84 ); 85 } 86 } 87 No newline at end of file
