Changeset 16699 in josm


Ignore:
Timestamp:
2020-06-21T15:39:43+02:00 (3 weeks ago)
Author:
simon04
Message:

fix #19392 - Presets opened from relation editor need to pass selection to preset_link

Location:
trunk/src/org/openstreetmap/josm/gui/tagging/presets
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

    r16585 r16699  
    1414import java.util.ArrayList;
    1515import java.util.Collection;
    16 import java.util.Collections;
    1716import java.util.EnumSet;
    1817import java.util.LinkedHashSet;
     
    386385    public void actionPerformed(ActionEvent e) {
    387386        DataSet ds = OsmDataManager.getInstance().getEditDataSet();
    388         Collection<OsmPrimitive> participants = Collections.emptyList();
    389         if (ds != null) {
    390             participants = ds.getSelected();
    391         }
    392 
    393         // Display dialog even if no data layer (used by preset-tagging-tester plugin)
    394         Collection<OsmPrimitive> sel = createSelection(participants);
    395         int answer = showDialog(sel, supportsRelation());
    396 
    397387        if (ds == null) {
    398388            return;
    399389        }
     390        showAndApply(ds.getSelected());
     391    }
     392
     393    /**
     394     * {@linkplain #showDialog Show preset dialog}, apply changes
     395     * @param primitives the primitives
     396     */
     397    public void showAndApply(Collection<OsmPrimitive> primitives) {
     398        // Display dialog even if no data layer (used by preset-tagging-tester plugin)
     399        Collection<OsmPrimitive> sel = createSelection(primitives);
     400        int answer = showDialog(sel, supportsRelation());
    400401
    401402        if (!sel.isEmpty() && answer == DIALOG_ANSWER_APPLY) {
     
    407408            Relation calculated = null;
    408409            if (getChangedTags().stream().anyMatch(t -> "boundary".equals(t.get("type")) || "multipolygon".equals(t.get("type")))) {
    409                 Pair<Relation, Relation> res = CreateMultipolygonAction.createMultipolygonRelation(ds.getSelectedWays(), true);
     410                Collection<Way> ways = Utils.filteredCollection(primitives, Way.class);
     411                Pair<Relation, Relation> res = CreateMultipolygonAction.createMultipolygonRelation(ways, true);
    410412                if (res != null) {
    411413                    calculated = res.b;
     
    413415            }
    414416            final Relation r = calculated != null ? calculated : new Relation();
    415             final Collection<RelationMember> members = new LinkedHashSet<>();
    416             members.addAll(r.getMembers());
     417            final Collection<RelationMember> members = new LinkedHashSet<>(r.getMembers());
    417418            for (Tag t : getChangedTags()) {
    418419                r.put(t.getKey(), t.getValue());
    419420            }
    420             for (OsmPrimitive osm : ds.getSelected()) {
     421            for (OsmPrimitive osm : primitives) {
    421422                if (r == calculated && osm instanceof Way)
    422423                    continue;
     
    432433                    MainApplication.getLayerManager().getEditLayer(), r, members).setVisible(true));
    433434        }
    434         ds.setSelected(ds.getSelected()); // force update
     435        if (!primitives.isEmpty()) {
     436            DataSet ds = primitives.iterator().next().getDataSet();
     437            ds.setSelected(primitives); // force update
     438        }
    435439    }
    436440
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetLink.java

    r16280 r16699  
    2828    static final class TaggingPresetMouseAdapter extends MouseAdapter {
    2929        private final TaggingPreset t;
     30        private final Collection<OsmPrimitive> sel;
    3031
    31         TaggingPresetMouseAdapter(TaggingPreset t) {
     32        TaggingPresetMouseAdapter(TaggingPreset t, Collection<OsmPrimitive> sel) {
    3233            this.t = t;
     34            this.sel = sel;
    3335        }
    3436
    3537        @Override
    3638        public void mouseClicked(MouseEvent e) {
    37             t.actionPerformed(null);
     39            t.showAndApply(sel);
    3840        }
    3941    }
     
    5860            TaggingPreset t = found.get();
    5961            JLabel lbl = new TaggingPresetLabel(t);
    60             lbl.addMouseListener(new TaggingPresetMouseAdapter(t));
     62            lbl.addMouseListener(new TaggingPresetMouseAdapter(t, sel));
    6163            p.add(lbl, GBC.eol().fill(GBC.HORIZONTAL));
    6264        }
Note: See TracChangeset for help on using the changeset viewer.