Changeset 19483 in josm


Ignore:
Timestamp:
2026-02-03T07:29:02+01:00 (7 hours ago)
Author:
GerdP
Message:

see #24516: Improve Autocompletion
Allow to exclude value auto-completion for certain keys specifed in a preference using a filter.

  • Implement new preference properties.autocomplete.exclude-keys
  • add menu entry in the dialog that pops up when you right click on a tag key in the "Add Tag dialog"
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r19115 r19483  
    7070import org.openstreetmap.josm.data.UndoRedoHandler;
    7171import org.openstreetmap.josm.data.osm.DataSet;
     72import org.openstreetmap.josm.data.osm.Filter;
    7273import org.openstreetmap.josm.data.osm.OsmDataManager;
    7374import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    147148    public static final ListProperty PROPERTY_RECENT_TAGS = new ListProperty("properties.recent-tags",
    148149            Collections.emptyList());
    149     /** The preference list of tags which should not be remembered, since r9940 */
     150    /** The preference filter of tags which should not be remembered, since r9940 */
    150151    public static final StringProperty PROPERTY_TAGS_TO_IGNORE = new StringProperty("properties.recent-tags.ignore",
     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",
    151155            new SearchSetting().writeToString());
    152156
     
    183187    final RecentTagCollection recentTags = new RecentTagCollection(MAX_LRU_TAGS_NUMBER);
    184188    SearchSetting tagsToIgnore;
     189    SearchSetting noAutocomplete;
    185190
    186191    /**
     
    241246        this.tagData = propertyData;
    242247        this.valueCount = valueCount;
     248        this.noAutocomplete = SearchSetting.readFromString(NO_AUTOCOMPLETE_KEYS.get());
    243249    }
    244250
     
    737743        }
    738744
     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
    739762        protected void addEventListeners() {
    740763            // OK on Enter in values
     
    778801            // update the values combobox orientation if the key changed
    779802            values.applyComponentOrientation(OrientationAction.getNamelikeOrientation(keys.getText()));
     803            // update the auto-completion setting for the given tag key
     804            values.setAutocompleteEnabled(autocompleteValuesForKey(keys.getText()));
    780805        }
    781806
     
    11631188                add(new IgnoreTagAction(tr("Ignore tag ''{0}''", t), t));
    11641189                add(new EditIgnoreTagsAction());
     1190                add(new EditExcludeAutocompleteValues(t));
    11651191            }
    11661192        }
     
    11901216
    11911217            EditIgnoreTagsAction() {
    1192                 super(tr("Edit ignore list"));
     1218                super(tr("Edit ignore filter"));
    11931219            }
    11941220
    11951221            @Override
    11961222            public void actionPerformed(ActionEvent e) {
    1197                 final SearchSetting newTagsToIngore = SearchAction.showSearchDialog(tagsToIgnore);
     1223                final SearchSetting newTagsToIngore = SearchAction.showSearchDialog(new Filter(tagsToIgnore));
    11981224                if (newTagsToIngore == null) {
    11991225                    return;
     
    12051231                } catch (SearchParseError parseError) {
    12061232                    warnAboutParseError(parseError);
     1233                }
     1234            }
     1235        }
     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());
    12071256                }
    12081257            }
Note: See TracChangeset for help on using the changeset viewer.