Changeset 18842 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2023-09-25T17:34:00+02:00 (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
r18692 r18842 73 73 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 74 74 import org.openstreetmap.josm.data.osm.Tag; 75 import org.openstreetmap.josm.data.osm.Tagged; 75 76 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 76 77 import org.openstreetmap.josm.data.osm.search.SearchParseError; … … 82 83 import org.openstreetmap.josm.data.preferences.StringProperty; 83 84 import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem; 85 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 84 86 import org.openstreetmap.josm.gui.ExtendedDialog; 85 87 import org.openstreetmap.josm.gui.IExtendedDialog; … … 278 280 try { 279 281 activeDataSet.beginUpdate(); 280 sel = OsmDataManager.getInstance().getInProgressSelection(); 281 if (Utils.isEmpty(sel)) 282 Collection<OsmPrimitive> selection = OsmDataManager.getInstance().getInProgressSelection(); 283 this.sel = selection; 284 if (Utils.isEmpty(selection)) 282 285 return; 283 286 … … 287 290 288 291 addDialog.destroyActions(); 289 if (addDialog.getValue() == 1) 290 addDialog.performTagAdding(); 291 else 292 // Remote control can cause the selection to change, see #23191. 293 if (addDialog.getValue() == 1 && (selection == sel || warnSelectionChanged())) { 294 addDialog.performTagAdding(selection); 295 } else { 292 296 addDialog.undoAllTagsAdding(); 297 } 293 298 } finally { 294 299 activeDataSet.endUpdate(); … … 373 378 public void loadTagsIfNeeded() { 374 379 loadTagsToIgnore(); 375 if (PROPERTY_REMEMBER_TAGS.get() && recentTags.isEmpty()) { 380 if (Boolean.TRUE.equals(PROPERTY_REMEMBER_TAGS.get()) && recentTags.isEmpty()) { 376 381 recentTags.loadFromPreference(PROPERTY_RECENT_TAGS); 377 382 } … … 407 412 */ 408 413 public void saveTagsIfNeeded() { 409 if (PROPERTY_REMEMBER_TAGS.get() && !recentTags.isEmpty()) { 414 if (Boolean.TRUE.equals(PROPERTY_REMEMBER_TAGS.get()) && !recentTags.isEmpty()) { 410 415 recentTags.saveToPreference(PROPERTY_RECENT_TAGS); 411 416 } … … 449 454 return selectedItem.toString(); 450 455 return getEditItem(cb); 456 } 457 458 /** 459 * Warn user about a selection change 460 * @return {@code true} if the user wants to apply the tag change to the old selection 461 */ 462 private static boolean warnSelectionChanged() { 463 return ConditionalOptionPaneUtil.showConfirmationDialog("properties.selection-changed", 464 MainApplication.getMainFrame(), 465 tr("Data selection has changed since the dialog was opened"), 466 tr("Apply tag change to old selection?"), 467 JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, JOptionPane.YES_OPTION); 451 468 } 452 469 … … 506 523 /** 507 524 * This hack allows the comboboxes to have their own orientation. 508 * 525 * <p> 509 526 * The problem is that 510 527 * {@link org.openstreetmap.josm.gui.ExtendedDialog#showDialog ExtendedDialog} calls 511 528 * {@code applyComponentOrientation} very late in the dialog construction process 512 529 * thus overwriting the orientation the components have chosen for themselves. 513 * 530 * <p> 514 531 * This stops the propagation of {@code applyComponentOrientation}, thus all 515 532 * components may (and have to) set their own orientation. … … 794 811 /** 795 812 * This hack allows the comboboxes to have their own orientation. 796 * 813 * <p> 797 814 * The problem is that 798 815 * {@link org.openstreetmap.josm.gui.ExtendedDialog#showDialog ExtendedDialog} calls 799 816 * {@code applyComponentOrientation} very late in the dialog construction process 800 817 * thus overwriting the orientation the components have chosen for themselves. 801 * 818 * <p> 802 819 * This stops the propagation of {@code applyComponentOrientation}, thus all 803 820 * components may (and have to) set their own orientation. … … 1187 1204 */ 1188 1205 public final void performTagAdding() { 1206 Collection<OsmPrimitive> selection = sel; 1207 if (!Utils.isEmpty(selection)) { 1208 performTagAdding(selection); 1209 } 1210 } 1211 1212 /** 1213 * Read tags from comboboxes and add it to all selected objects 1214 * @param selection The selection to perform tag adding on 1215 * @since 18842 1216 */ 1217 private void performTagAdding(Collection<OsmPrimitive> selection) { 1189 1218 String key = getEditItem(keys); 1190 1219 String value = getEditItem(values); 1191 1220 if (key.isEmpty() || value.isEmpty()) 1192 1221 return; 1193 for ( OsmPrimitiveosm : sel) {1222 for (Tagged osm : selection) { 1194 1223 String val = osm.get(key); 1195 1224 if (val != null && !val.equals(value)) { … … 1203 1232 } 1204 1233 recentTags.add(new Tag(key, value)); 1205 valueCount.put(key, new TreeMap< String, Integer>());1234 valueCount.put(key, new TreeMap<>()); 1206 1235 AutoCompletionManager.rememberUserInput(key, value, false); 1207 1236 commandCount++; 1208 UndoRedoHandler.getInstance().add(new ChangePropertyCommand(sel, key, value)); 1237 UndoRedoHandler.getInstance().add(new ChangePropertyCommand(selection, key, value)); 1209 1238 changedKey = key; 1210 1239 clearEntries(); … … 1216 1245 } 1217 1246 1247 /** 1248 * Undo all tag add commands that this dialog has created 1249 */ 1218 1250 public void undoAllTagsAdding() { 1219 1251 UndoRedoHandler.getInstance().undo(commandCount);
Note:
See TracChangeset
for help on using the changeset viewer.