Ticket #18038: 18038.3.patch
| File 18038.3.patch, 4.5 KB (added by , 7 years ago) |
|---|
-
src/org/openstreetmap/josm/io/remotecontrol/AddTagsDialog.java
10 10 import java.awt.event.ActionEvent; 11 11 import java.awt.event.KeyEvent; 12 12 import java.awt.event.MouseEvent; 13 import java.util.Arrays; 13 14 import java.util.Collection; 14 15 import java.util.HashMap; 15 16 import java.util.HashSet; 16 import java.util.LinkedHashSet;17 17 import java.util.Map; 18 18 import java.util.Map.Entry; 19 19 import java.util.Set; 20 import java.util.stream.Collectors; 20 21 21 22 import javax.swing.AbstractAction; 22 23 import javax.swing.JCheckBox; … … 280 281 public static void addTags(final Map<String, String> args, final String sender, final Collection<? extends OsmPrimitive> primitives) { 281 282 if (args.containsKey("addtags")) { 282 283 GuiHelper.executeByMainWorkerInEDT(() -> { 283 Set<String> tagSet = new LinkedHashSet<>(); // preserve order, see #15704 284 for (String tag1 : args.get("addtags").split("\\|")) { 285 if (!tag1.trim().isEmpty() && tag1.contains("=")) { 286 tagSet.add(tag1.trim()); 287 } 288 } 289 if (!tagSet.isEmpty()) { 290 String[][] keyValue = new String[tagSet.size()][2]; 291 int i = 0; 292 for (String tag2 : tagSet) { 293 // support a = b===c as "a"="b===c" 294 String[] pair = tag2.split("\\s*=\\s*", 2); 295 keyValue[i][0] = pair[0]; 296 keyValue[i][1] = pair.length < 2 ? "" : pair[1]; 297 i++; 298 } 299 addTags(keyValue, sender, primitives); 300 } 284 addTags(parseUrlTagsToKeyValues(args.get("addtags")), sender, primitives); 301 285 }); 302 286 } 303 287 } 304 288 305 289 /** 290 * Convert a argument from a url to a series of tags 291 * @param urlSection A url section that looks like {@code tag1=value1|tag2=value2} 292 * @return An 2d array in the format of {@code [key][value]} 293 * @since xxx 294 */ 295 public static String[][] parseUrlTagsToKeyValues(String urlSection) { 296 Set<String> tagSet = Arrays.stream(urlSection.split("\\n")) 297 .map(String::trim) 298 .filter(tag -> !tag.isEmpty() && tag.contains("=")) 299 .collect(Collectors.toSet()); 300 301 String[][] keyValue = new String[][] {}; 302 if (!tagSet.isEmpty()) { 303 keyValue = new String[tagSet.size()][2]; 304 int i = 0; 305 for (String tag : tagSet) { 306 // support a = b===c as "a"="b===c" 307 String[] pair = tag.split("\\s*=\\s*", 2); 308 keyValue[i][0] = pair[0]; 309 keyValue[i][1] = pair.length < 2 ? "" : pair[1]; 310 i++; 311 } 312 } 313 return keyValue; 314 } 315 316 /** 306 317 * Ask user and add the tags he confirm. 307 318 * @param keyValue is a table or {{tag1,val1},{tag2,val2},...} 308 319 * @param sender is a string for skipping confirmations. Use empty string for always confirmed adding. -
src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java
224 224 zoom(Collections.<OsmPrimitive>emptySet(), bbox); 225 225 } 226 226 227 // This comes before the other changeset tags, so that they can be overridden 228 if (args.containsKey("changeset_tags")) { 229 MainApplication.worker.submit(() -> { 230 DataSet ds = MainApplication.getLayerManager().getEditDataSet(); 231 if (ds != null) { 232 String[][] newChangesetTags = AddTagsDialog.parseUrlTagsToKeyValues(args.get("changeset_tags")); 233 for (String[] key : newChangesetTags) { 234 ds.addChangeSetTag(key[0], key[1]); 235 } 236 } 237 }); 238 } 239 227 240 // add changeset tags after download if necessary 228 241 if (args.containsKey("changeset_comment") || args.containsKey("changeset_source") || args.containsKey("changeset_hashtags")) { 229 242 MainApplication.worker.submit(() -> {
