Ticket #24516: 24516-no-automplete-for-keys.patch
| File 24516-no-automplete-for-keys.patch, 4.5 KB (added by , 2 months ago) |
|---|
-
src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
146 146 /** The preference storage of recent tags */ 147 147 public static final ListProperty PROPERTY_RECENT_TAGS = new ListProperty("properties.recent-tags", 148 148 Collections.emptyList()); 149 /** The preference listof tags which should not be remembered, since r9940 */149 /** The preference filter of tags which should not be remembered, since r9940 */ 150 150 public static final StringProperty PROPERTY_TAGS_TO_IGNORE = new StringProperty("properties.recent-tags.ignore", 151 151 new SearchSetting().writeToString()); 152 /** The preference filter for tag keys for which values should not be auto-completed, since xxx */ 153 public static final StringProperty NO_AUTOCOMPLETE_KEYS = new StringProperty("properties.autocomplete.exclude-keys", 154 new SearchSetting().writeToString()); 152 155 153 156 /** 154 157 * What to do with recent tags where keys already exist … … 182 185 183 186 final RecentTagCollection recentTags = new RecentTagCollection(MAX_LRU_TAGS_NUMBER); 184 187 SearchSetting tagsToIgnore; 188 SearchSetting noAutocomplete; 185 189 186 190 /** 187 191 * Copy of recently added tags in sorted from newest to oldest order. … … 240 244 this.tagTable = tagTable; 241 245 this.tagData = propertyData; 242 246 this.valueCount = valueCount; 247 this.noAutocomplete = SearchSetting.readFromString(NO_AUTOCOMPLETE_KEYS.get()); 243 248 } 244 249 245 250 /** … … 736 741 } 737 742 } 738 743 744 /** 745 * Check if values should be auto-completed for the given tag key. 746 * @param key the key 747 * @return false if auto-completion is disabled or if the key matches the exclusion filter, true else 748 */ 749 private boolean autocompleteValuesForKey(String key) { 750 if (!AUTOCOMPLETE_VALUES.get()) 751 return false; 752 if (noAutocomplete == null || Utils.isEmpty(noAutocomplete.text)) 753 return true; 754 try { 755 return !SearchCompiler.compile(noAutocomplete).match(new Tag(key)); 756 } catch (SearchParseError parseError) { 757 throw new IllegalStateException(parseError); 758 } 759 } 760 739 761 protected void addEventListeners() { 740 762 // OK on Enter in values 741 763 values.getEditor().addActionListener(e -> buttonAction(0, null)); … … 777 799 public void focusLost(FocusEvent e) { 778 800 // update the values combobox orientation if the key changed 779 801 values.applyComponentOrientation(OrientationAction.getNamelikeOrientation(keys.getText())); 802 // update the auto-completion setting for the given tag key 803 values.setAutocompleteEnabled(autocompleteValuesForKey(keys.getText())); 780 804 } 781 805 782 806 protected void updateOkButtonIcon() { … … 1162 1186 add(new IgnoreTagAction(tr("Ignore key ''{0}''", t.getKey()), new Tag(t.getKey(), ""))); 1163 1187 add(new IgnoreTagAction(tr("Ignore tag ''{0}''", t), t)); 1164 1188 add(new EditIgnoreTagsAction()); 1189 add(new EditExcludeAutocompleteValues(t)); 1165 1190 } 1166 1191 } 1167 1192 … … 1208 1233 } 1209 1234 } 1210 1235 1236 class EditExcludeAutocompleteValues extends AbstractAction { 1237 final transient Tag tag; 1238 1239 EditExcludeAutocompleteValues(Tag tag) { 1240 super(tr("Edit stop-autocomplete values filter")); 1241 this.tag = tag; 1242 setEnabled(AUTOCOMPLETE_VALUES.get()); 1243 } 1244 1245 @Override 1246 public void actionPerformed(ActionEvent e) { 1247 SearchSetting initFilter = SearchSetting.fromString('"' + tag.getKey() + '"'); 1248 if (noAutocomplete != null && !Utils.isEmpty(noAutocomplete.text)) 1249 initFilter = noAutocomplete; 1250 final SearchSetting newNoAutocomplete = SearchAction.showSearchDialog(initFilter); 1251 if (newNoAutocomplete != null) { 1252 noAutocomplete = newNoAutocomplete; 1253 NO_AUTOCOMPLETE_KEYS.put(noAutocomplete.writeToString()); 1254 } 1255 } 1256 } 1257 1211 1258 /** 1212 1259 * Destroy the recentTagsActions. 1213 1260 */
