Changeset 7521 in josm


Ignore:
Timestamp:
2014-09-10T21:53:16+02:00 (10 years ago)
Author:
bastiK
Message:

fixed #10498 - do not rely on current selection when adding tags to primitives,
but pass list of primitives to method as parameter

Location:
trunk/src/org/openstreetmap/josm/io/remotecontrol
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/AddTagsDialog.java

    r7005 r7521  
    291291     * addtags=wikipedia:de%3DResidenzschloss Dresden|name:en%3DDresden Castle
    292292     */
    293     public static void addTags(final Map<String, String> args, final String sender) {
     293    public static void addTags(final Map<String, String> args, final String sender, final Collection<? extends OsmPrimitive> primitives) {
    294294        if (args.containsKey("addtags")) {
    295295            GuiHelper.executeByMainWorkerInEDT(new Runnable() {
     
    319319                            i++;
    320320                        }
    321                         addTags(keyValue, sender);
     321                        addTags(keyValue, sender, primitives);
    322322                    }
    323323                }
     
    333333     * @param sender is a string for skipping confirmations. Use epmty string for always confirmed adding.
    334334     */
    335     public static void addTags(String[][] keyValue, String sender) {
     335    public static void addTags(String[][] keyValue, String sender, Collection<? extends OsmPrimitive> primitives) {
    336336        if (trustedSenders.contains(sender)) {
    337337            if (Main.main.getCurrentDataSet() != null) {
    338                 Collection<OsmPrimitive> s = Main.main.getCurrentDataSet().getSelected();
    339338                for (String[] row : keyValue) {
    340                     Main.main.undoRedo.add(new ChangePropertyCommand(s, row[0], row[1]));
     339                    Main.main.undoRedo.add(new ChangePropertyCommand(primitives, row[0], row[1]));
    341340                }
    342341            }
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java

    r6536 r7521  
    55
    66import java.awt.Point;
     7import java.util.Collections;
    78import java.util.Map;
    89
     
    2930    private double lat;
    3031    private double lon;
     32   
     33    private Node node;
    3134
    3235    @Override
     
    8790        LatLon ll = new LatLon(lat, lon);
    8891
    89         Node nd = null;
     92        node = null;
    9093
    9194        if (Main.isDisplayingMapView()) {
    9295            Point p = Main.map.mapView.getPoint(ll);
    93             nd = Main.map.mapView.getNearestNode(p, OsmPrimitive.isUsablePredicate);
    94             if (nd!=null && nd.getCoor().greatCircleDistance(ll) > Main.pref.getDouble("remotecontrol.tolerance", 0.1)) {
    95                 nd = null; // node is too far
     96            node = Main.map.mapView.getNearestNode(p, OsmPrimitive.isUsablePredicate);
     97            if (node!=null && node.getCoor().greatCircleDistance(ll) > Main.pref.getDouble("remotecontrol.tolerance", 0.1)) {
     98                node = null; // node is too far
    9699            }
    97100        }
    98101
    99         if (nd==null) {
    100             nd = new Node(ll);
     102        if (node==null) {
     103            node = new Node(ll);
    101104            // Now execute the commands to add this node.
    102             Main.main.undoRedo.add(new AddCommand(nd));
     105            Main.main.undoRedo.add(new AddCommand(node));
    103106        }
    104107
    105         Main.main.getCurrentDataSet().setSelected(nd);
     108        Main.main.getCurrentDataSet().setSelected(node);
    106109        if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) {
    107110            AutoScaleAction.autoScale("selection");
     
    110113        }
    111114        // parse parameter addtags=tag1=value1|tag2=vlaue2
    112         AddTagsDialog.addTags(args, sender);
     115        AddTagsDialog.addTags(args, sender, Collections.singleton(node));
    113116    }
    114117
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java

    r7509 r7521  
    77import java.util.ArrayList;
    88import java.util.Arrays;
     9import java.util.Collections;
    910import java.util.HashMap;
    1011import java.util.LinkedList;
     
    3637
    3738    private final List<LatLon> allCoordinates = new ArrayList<>();
     39   
     40    private Way way;
    3841
    3942    /**
     
    6972        GuiHelper.runInEDTAndWait(new Runnable() {
    7073            @Override public void run() {
    71                 addWay();
     74                way = addWay();
    7275            }
    7376        });
    7477        // parse parameter addtags=tag1=value1|tag2=value2
    75         AddTagsDialog.addTags(args, sender);
     78        AddTagsDialog.addTags(args, sender, Collections.singleton(way));
    7679    }
    7780
     
    150153     * This function creates the way with given coordinates of nodes
    151154     */
    152     private void addWay() {
     155    private Way addWay() {
    153156        addedNodes = new HashMap<>();
    154157        Way way = new Way();
     
    167170            Main.map.mapView.repaint();
    168171        }
     172        return way;
    169173    }
    170174}
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java

    r7251 r7521  
    160160        }
    161161
     162        final Collection<OsmPrimitive> forTagAdd = new HashSet<>();
    162163        final Bounds bbox = new Bounds(minlat, minlon, maxlat, maxlon);
    163164        if (args.containsKey("select") && PermissionPrefWithDefault.CHANGE_SELECTION.isAllowed()) {
     
    174175                        if (p != null) {
    175176                            newSel.add(p);
     177                            forTagAdd.add(p);
    176178                        }
    177179                    }
     
    188190        } else if (args.containsKey("search") && PermissionPrefWithDefault.CHANGE_SELECTION.isAllowed()) {
    189191            try {
    190                 final DataSet ds = Main.main.getCurrentDataSet();
    191192                final SearchCompiler.Match search = SearchCompiler.compile(args.get("search"), false, false);
    192                 final Collection<OsmPrimitive> filteredPrimitives = Utils.filter(ds.allPrimitives(), search);
    193                 ds.setSelected(filteredPrimitives);
    194                 zoom(filteredPrimitives, bbox);
     193                Main.worker.submit(new Runnable() {
     194                    @Override
     195                    public void run() {
     196                        final DataSet ds = Main.main.getCurrentDataSet();
     197                        final Collection<OsmPrimitive> filteredPrimitives = Utils.filter(ds.allPrimitives(), search);
     198                        ds.setSelected(filteredPrimitives);
     199                        forTagAdd.addAll(filteredPrimitives);
     200                        zoom(filteredPrimitives, bbox);
     201                    }
     202                });
    195203            } catch (SearchCompiler.ParseError ex) {
    196204                Main.error(ex);
     
    219227        }
    220228
    221         AddTagsDialog.addTags(args, sender);
     229        AddTagsDialog.addTags(args, sender, forTagAdd);
    222230    }
    223231
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandler.java

    r7005 r7521  
    22package org.openstreetmap.josm.io.remotecontrol.handler;
    33
     4import java.util.Collection;
     5import java.util.HashSet;
    46import static org.openstreetmap.josm.tools.I18n.tr;
    57
     
    810
    911import org.openstreetmap.josm.Main;
     12import org.openstreetmap.josm.data.osm.DataSet;
     13import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1014import org.openstreetmap.josm.data.osm.PrimitiveId;
    1115import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
     
    6872                public void run() {
    6973                    final List<PrimitiveId> downloaded = task.getDownloadedId();
     74                    final DataSet ds = Main.main.getCurrentDataSet();
    7075                    if(downloaded != null) {
    7176                        GuiHelper.runInEDT(new Runnable() {
    7277                            @Override
    7378                            public void run() {
    74                                 Main.main.getCurrentDataSet().setSelected(downloaded);
     79                                ds.setSelected(downloaded);
    7580                            }
    7681                        });
    7782                    }
    78                     AddTagsDialog.addTags(args, sender);
     83                    Collection<OsmPrimitive> downlPrim = new HashSet<>();
     84                    for (PrimitiveId id : downloaded) {
     85                        downlPrim.add(ds.getPrimitiveById(id));
     86                    }
     87                    AddTagsDialog.addTags(args, sender, downlPrim);
    7988                    ps.clear();
    8089                }
Note: See TracChangeset for help on using the changeset viewer.