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