Changeset 18260 in josm
- Timestamp:
- 2021-10-09T15:05:34+02:00 (3 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItemGuiSupport.java
r18257 r18260 85 85 86 86 /** 87 * Returns true if all selected primitives matched this preset (before opening the dialog) 87 * Returns true if all selected primitives matched this preset (before opening the dialog). 88 * <p> 89 * This usually means that the preset dialog was opened from the Tags / Memberships panel as 90 * opposed to being opened by selection from the menu or toolbar or the search. 88 91 * 89 92 * @return true if the preset initially matched -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Combo.java
r18257 r18260 154 154 } 155 155 156 String valueToSelect = getInitialValue(usage); 157 if (valueToSelect != null) { 158 PresetListEntry selItem = find(valueToSelect); 159 if (selItem != null) { 160 combobox.setSelectedItem(selItem); 161 } else { 162 combobox.setText(valueToSelect); 163 } 164 } 156 String initialValue = getInitialValue(usage, support); 157 PresetListEntry selItem = find(initialValue); 158 if (selItem != null) { 159 combobox.setSelectedItem(selItem); 160 } else { 161 combobox.setText(initialValue); 162 } 163 165 164 combobox.addActionListener(l -> support.fireItemValueModified(this, key, getSelectedItem().value)); 166 165 combobox.addComponentListener(new ComponentListener()); -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java
r18258 r18260 23 23 24 24 import org.openstreetmap.josm.data.osm.Tag; 25 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 25 26 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetSelector; 26 27 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; … … 94 95 protected final Map<String, PresetListEntry> seenValues = new TreeMap<>(); 95 96 protected Usage usage; 96 /** Used to see if the user edited the value. May be null.*/97 /** Used to see if the user edited the value. */ 97 98 protected String originalValue; 98 99 … … 318 319 * Returns the initial value to use for this preset. 319 320 * <p> 320 * The initial value is the value shown in the control when the preset dialogs opens. 321 * The initial value is the value shown in the control when the preset dialog opens. For a 322 * discussion of all the options see the enclosed tickets. 321 323 * 322 324 * @param usage The key Usage 325 * @param support The support 323 326 * @return The initial value to use. 324 */ 325 protected String getInitialValue(Usage usage) { 327 * 328 * @see "https://josm.openstreetmap.de/ticket/5564" 329 * @see "https://josm.openstreetmap.de/ticket/12733" 330 * @see "https://josm.openstreetmap.de/ticket/17324" 331 */ 332 protected String getInitialValue(Usage usage, TaggingPresetItemGuiSupport support) { 326 333 String initialValue = null; 327 originalValue = null;334 originalValue = ""; 328 335 329 336 if (usage.hasUniqueValue()) { … … 335 342 initialValue = DIFFERENT; 336 343 originalValue = initialValue; 337 } else if ( PROP_FILL_DEFAULT.get() || isForceUseLastAsDefault()) {344 } else if (!usage.hadKeys() || isForceUseLastAsDefault() || PROP_FILL_DEFAULT.get()) { 338 345 // at this point no primitive had any value for this key 339 // use the last value no matter what 340 initialValue = LAST_VALUES.get(key); 341 } else if (!usage.hadKeys() && isUseLastAsDefault()) { 342 // use the last value only on objects with no keys at all 343 initialValue = LAST_VALUES.get(key); 344 } else if (!usage.hadKeys()) { 345 // use the default only on objects with no keys at all 346 initialValue = default_; 347 } 348 return initialValue; 346 if (!support.isPresetInitiallyMatches() && isUseLastAsDefault() && LAST_VALUES.containsKey(key)) { 347 initialValue = LAST_VALUES.get(key); 348 } else { 349 initialValue = default_; 350 } 351 } 352 return initialValue != null ? initialValue : ""; 349 353 } 350 354 … … 354 358 355 359 // no change if same as before 356 if (value.isEmpty() && originalValue == null)357 return;358 360 if (value.equals(originalValue)) 359 361 return; -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/MultiSelect.java
r18257 r18260 49 49 // disable if the selected primitives have different values 50 50 list.setEnabled(usage.hasUniqueValue() || usage.unused()); 51 String initialValue = getInitialValue(usage); 51 String initialValue = getInitialValue(usage, support); 52 52 53 53 // Add values from the preset. … … 62 62 63 63 // Select the values in the initial value. 64 if (initialValue != null&& !DIFFERENT.equals(initialValue)) {64 if (!initialValue.isEmpty() && !DIFFERENT.equals(initialValue)) { 65 65 for (String value : initialValue.split(String.valueOf(delimiter), -1)) { 66 66 PresetListEntry e = new PresetListEntry(value, this); -
trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/ComboTest.java
r18254 r18260 28 28 @RegisterExtension 29 29 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 30 public JOSMTestRules test = new JOSMTestRules().main().i18n("de"); 30 public JOSMTestRules test = new JOSMTestRules().preferences().main().i18n("de"); 31 31 32 32 /** … … 55 55 KeyedItem.LAST_VALUES.clear(); 56 56 KeyedItem.LAST_VALUES.put("addr:country", "AT"); 57 Combo.PROP_FILL_DEFAULT.put(false); 58 combo.use_last_as_default = 0; 57 59 58 combo.use_last_as_default = 0;59 60 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, way)); 60 61 assertEquals("", combo.getSelectedItem().value); … … 79 80 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT, waySI)); 80 81 assertEquals(Combo.DIFFERENT, combo.getSelectedItem().value); 82 83 Combo.PROP_FILL_DEFAULT.put(true); 84 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, way)); 85 assertEquals("AT", combo.getSelectedItem().value); 86 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayTagged)); 87 assertEquals("AT", combo.getSelectedItem().value); 88 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT)); 89 assertEquals("AT", combo.getSelectedItem().value); 90 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, waySI)); 91 assertEquals("SI", combo.getSelectedItem().value); 92 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT, waySI)); 93 assertEquals(Combo.DIFFERENT, combo.getSelectedItem().value); 94 Combo.PROP_FILL_DEFAULT.put(false); 81 95 combo.default_ = null; 82 96 … … 104 118 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT, waySI)); 105 119 assertEquals(Combo.DIFFERENT, combo.getSelectedItem().value); 120 combo.use_last_as_default = 0; 106 121 107 122 KeyedItem.LAST_VALUES.clear();
Note:
See TracChangeset
for help on using the changeset viewer.