value = null; // delete the key instead
}
if (key.equals(newkey) && tr("<different>").equals(value))
return;
if (key.equals(newkey) || value == null) {
Main.main.undoRedo.add(new ChangePropertyCommand(sel, newkey, value));
} else {
for (OsmPrimitive osm: sel) {
if (osm.get(newkey) != null) {
if (!warnOverwriteKey(tr("You changed the key from ''{0}'' to ''{1}''.", key, newkey),
"overwriteEditKey"))
return;
break;
}
}
Collection<Command> commands = new ArrayList<>();
commands.add(new ChangePropertyCommand(sel, key, null));
if (value.equals(tr("<different>"))) {
Map<String, List<OsmPrimitive>> map = new HashMap<>();
for (OsmPrimitive osm: sel) {
String val = osm.get(key);
if (val != null) {
if (map.containsKey(val)) {
map.get(val).add(osm);
} else {
List<OsmPrimitive> v = new ArrayList<>();
v.add(osm);
map.put(val, v);
}
}
}
for (Map.Entry<String, List<OsmPrimitive>> e: map.entrySet()) {
commands.add(new ChangePropertyCommand(e.getValue(), newkey, e.getKey()));
}
} else {
commands.add(new ChangePropertyCommand(sel, newkey, value));
}
Main.main.undoRedo.add(new SequenceCommand(
trn("Change properties of up to {0} object",
"Change properties of up to {0} objects", sel.size(), sel.size()),
commands));