Ticket #14923: preset-search.patch
File preset-search.patch, 5.2 KB (added by , 7 years ago) |
---|
-
josm/actions/search/SearchAction.java
454 454 .addKeyword("type:node", "type:node ", tr("all nodes")) 455 455 .addKeyword("type:way", "type:way ", tr("all ways")) 456 456 .addKeyword("type:relation", "type:relation ", tr("all relations")) 457 .addKeyword("preset:water", "preset:water", tr("all object that match the water preset")) 458 .addKeyword("preset:\"fast food\"", "preset:\"fast food\"", tr("all objects that match the fast food preset")) 457 459 .addKeyword("closed", "closed ", tr("all closed ways")) 458 460 .addKeyword("untagged", "untagged ", tr("object without useful tags")), 459 461 GBC.eol()); … … 888 890 public List<ActionParameter<?>> getActionParameters() { 889 891 return Collections.<ActionParameter<?>>singletonList(new SearchSettingsActionParameter(SEARCH_EXPRESSION)); 890 892 } 891 } 893 } 894 No newline at end of file -
josm/actions/search/SearchCompiler.java
38 38 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector; 39 39 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser; 40 40 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException; 41 import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; 42 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; 41 43 import org.openstreetmap.josm.tools.AlphanumComparator; 42 44 import org.openstreetmap.josm.tools.Geometry; 43 45 import org.openstreetmap.josm.tools.UncheckedParseException; … … 115 117 private final Collection<String> keywords = Arrays.asList("id", "version", "type", "user", "role", 116 118 "changeset", "nodes", "ways", "tags", "areasize", "waylength", "modified", "deleted", "selected", 117 119 "incomplete", "untagged", "closed", "new", "indownloadedarea", 118 "allindownloadedarea", "inview", "allinview", "timestamp", "nth", "nth%", "hasRole" );120 "allindownloadedarea", "inview", "allinview", "timestamp", "nth", "nth%", "hasRole", "preset"); 119 121 120 122 @Override 121 123 public Match get(String keyword, PushbackTokenizer tokenizer) throws ParseError { … … 151 153 return new Version(tokenizer); 152 154 case "type": 153 155 return new ExactType(tokenizer.readTextOrNumber()); 156 case "preset": 157 return new Preset(tokenizer.readTextOrNumber()); 154 158 case "user": 155 159 return new UserMatch(tokenizer.readTextOrNumber()); 156 160 case "role": … … 1554 1558 } 1555 1559 } 1556 1560 1561 /** 1562 * Matches presets. 1563 */ 1564 private static class Preset extends Match { 1565 private List<TaggingPreset> ps; 1566 1567 Preset(String presetName) throws ParseError { 1568 1569 if (presetName == null) 1570 throw new ParseError("Preset name cannot be null"); 1571 1572 Collection<TaggingPreset> ts = TaggingPresets.getTaggingPresets(); 1573 ps = new ArrayList<>(); 1574 1575 for (TaggingPreset t : ts) { 1576 String name = t.getSimpleName(); 1577 1578 if (name != null && name.equalsIgnoreCase(presetName)) ps.add(t); 1579 } 1580 1581 if (ps.isEmpty()) 1582 throw new ParseError(tr("Unknown preset name: ") + presetName); 1583 } 1584 1585 /** 1586 * Since presets can have common names, the primitive is considered to 1587 * belong to a certain preset if it matches at least one of them. 1588 */ 1589 @Override 1590 public boolean match(OsmPrimitive osm) { 1591 for (TaggingPreset p : ps) { 1592 if (p.test(osm)) return true; 1593 } 1594 1595 return false; 1596 } 1597 } 1598 1557 1599 public static class ParseError extends Exception { 1558 1600 public ParseError(String msg) { 1559 1601 super(msg); … … 1803 1845 return forKey + '"' + escapeStringForSearch(value) + '"'; 1804 1846 } 1805 1847 } 1806 } 1848 } 1849 No newline at end of file -
josm/gui/tagging/presets/TaggingPreset.java
173 173 } 174 174 175 175 /** 176 * Returns the non translated name without any prefixes. 177 * @return returns the non translated name without any prefixes. 178 */ 179 public String getSimpleName() { 180 return this.name; 181 } 182 183 /** 176 184 * Returns the preset icon (16px). 177 185 * @return The preset icon, or {@code null} if none defined 178 186 * @since 6403 … … 634 642 ToolbarPreferences.ActionParser actionParser = new ToolbarPreferences.ActionParser(null); 635 643 return actionParser.saveAction(new ToolbarPreferences.ActionDefinition(this)); 636 644 } 637 } 645 } 646 No newline at end of file