Ignore:
Timestamp:
2013-05-10T17:13:24+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #8690 - After copying some primitives, only select those that have been directly selected (and not all that have been created) -> Copying a way only selects the new way

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java

    r5926 r5953  
    1616import org.openstreetmap.josm.data.osm.PrimitiveData;
    1717import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     18import org.openstreetmap.josm.tools.CheckParameterUtil;
    1819
    1920/**
    2021 * Add primitives to a data layer.
    21  *
     22 * @since 2305
    2223 */
    2324public class AddPrimitivesCommand extends Command {
    2425
    2526    private List<PrimitiveData> data = new ArrayList<PrimitiveData>();
     27    private Collection<PrimitiveData> toSelect = new ArrayList<PrimitiveData>();
    2628
    2729    // only filled on undo
    2830    private List<OsmPrimitive> createdPrimitives = null;
     31    private Collection<OsmPrimitive> createdPrimitivesToSelect = null;
    2932
     33    /**
     34     * Constructs a new {@code AddPrimitivesCommand} to add data to the current edit layer.
     35     * @param data The OSM primitives data to add. Must not be {@code null}
     36     */
    3037    public AddPrimitivesCommand(List<PrimitiveData> data) {
    31         this.data.addAll(data);
     38        this(data, data);
     39    }
     40
     41    /**
     42     * Constructs a new {@code AddPrimitivesCommand} to add data to the current edit layer.
     43     * @param data The OSM primitives to add. Must not be {@code null}
     44     * @param toSelect The OSM primitives to select at the end. Can be {@code null}
     45     * @since 5953
     46     */
     47    public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect) {
     48        init(data, toSelect);
     49    }
     50
     51    /**
     52     * Constructs a new {@code AddPrimitivesCommand} to add data to the given layer.
     53     * @param data The OSM primitives data to add. Must not be {@code null}
     54     * @param toSelect The OSM primitives to select at the end. Can be {@code null}
     55     * @param layer The target data layer. Must not be {@code null}
     56     */
     57    public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect, OsmDataLayer layer) {
     58        super(layer);
     59        init(data, toSelect);
    3260    }
    3361   
    34     public AddPrimitivesCommand(List<PrimitiveData> data, OsmDataLayer layer) {
    35         super(layer);
     62    private final void init(List<PrimitiveData> data, List<PrimitiveData> toSelect) {
     63        CheckParameterUtil.ensureParameterNotNull(data, "data");
    3664        this.data.addAll(data);
     65        if (toSelect != null) {
     66            this.toSelect.addAll(toSelect);
     67        }
    3768    }
    3869
    39     @SuppressWarnings("null")
    4070    @Override public boolean executeCommand() {
    41         List<OsmPrimitive> newPrimitives;
     71        Collection<OsmPrimitive> primitivesToSelect;
    4272        if (createdPrimitives == null) { // first time execution
    43             newPrimitives = new ArrayList<OsmPrimitive>(data.size());
     73            List<OsmPrimitive> newPrimitives = new ArrayList<OsmPrimitive>(data.size());
     74            primitivesToSelect = new ArrayList<OsmPrimitive>(toSelect.size());
    4475
    4576            for (PrimitiveData pd : data) {
     
    5687                }
    5788                newPrimitives.add(primitive);
     89                if (toSelect.contains(pd)) {
     90                    primitivesToSelect.add(primitive);
     91                }
    5892            }
    5993
    60             //Then load ways and relations
     94            // Then load ways and relations
    6195            for (int i=0; i<newPrimitives.size(); i++) {
    6296                if (!(newPrimitives.get(i) instanceof Node)) {
     
    70104                getLayer().data.addPrimitive(osm);
    71105            }
    72             newPrimitives = createdPrimitives;
     106            primitivesToSelect = createdPrimitivesToSelect;
    73107        }
    74108
    75         getLayer().data.setSelected(newPrimitives);
     109        getLayer().data.setSelected(primitivesToSelect);
    76110        return true;
    77111    }
     
    82116        if (createdPrimitives == null) {
    83117            createdPrimitives = new ArrayList<OsmPrimitive>(data.size());
     118            createdPrimitivesToSelect = new ArrayList<OsmPrimitive>(toSelect.size());
    84119           
    85             for (PrimitiveData p : data) {
    86                 createdPrimitives.add(ds.getPrimitiveById(p));
     120            for (PrimitiveData pd : data) {
     121                OsmPrimitive p = ds.getPrimitiveById(pd);
     122                createdPrimitives.add(p);
     123                if (toSelect.contains(pd)) {
     124                    createdPrimitivesToSelect.add(p);
     125                }
    87126            }
    88127            createdPrimitives = PurgeCommand.topoSort(createdPrimitives);
     
    92131            }
    93132            data = null;
     133            toSelect = null;
    94134           
    95135        } else {
Note: See TracChangeset for help on using the changeset viewer.