Changeset 9940 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-03-06T17:12:42+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r9696 r9940 773 773 return Collections.<ActionParameter<?>>singletonList(new SearchSettingsActionParameter(SEARCH_EXPRESSION)); 774 774 } 775 776 public static String escapeStringForSearch(String s) {777 return s.replace("\\", "\\\\").replace("\"", "\\\"");778 }779 775 } -
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r9930 r9940 1745 1745 return searchFlags; 1746 1746 } 1747 1748 static String escapeStringForSearch(String s) { 1749 return s.replace("\\", "\\\\").replace("\"", "\\\""); 1750 } 1751 1752 /** 1753 * Builds a search string for the given tag. If value is empty, the existence of the key is checked. 1754 * 1755 * @param key the tag key 1756 * @param value the tag value 1757 * @return a search string for the given tag 1758 */ 1759 public static String buildSearchStringForTag(String key, String value) { 1760 final String forKey = '"' + escapeStringForSearch(key) + '"' + '='; 1761 if (value == null || value.isEmpty()) { 1762 return forKey + "*"; 1763 } else { 1764 return forKey + '"' + escapeStringForSearch(value) + '"'; 1765 } 1766 } 1747 1767 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r9894 r9940 1401 1401 String token = new StringBuilder(t).append(val).toString(); 1402 1402 if (consideredTokens.add(token)) { 1403 s.append(sep).append('(').append(t).append('"').append( 1404 org.openstreetmap.josm.actions.search.SearchAction.escapeStringForSearch(key)).append("\"=\"").append( 1405 org.openstreetmap.josm.actions.search.SearchAction.escapeStringForSearch(val)).append("\")"); 1403 s.append(sep).append('(').append(t).append(SearchCompiler.buildSearchStringForTag(key, val)).append(")"); 1406 1404 sep = " OR "; 1407 1405 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/RecentTagCollection.java
r9939 r9940 8 8 import java.util.Map; 9 9 10 import org.openstreetmap.josm.actions.search.SearchAction; 11 import org.openstreetmap.josm.actions.search.SearchCompiler; 10 12 import org.openstreetmap.josm.data.osm.Tag; 11 13 import org.openstreetmap.josm.data.preferences.CollectionProperty; … … 14 16 15 17 private final Map<Tag, Void> recentTags; 18 private SearchCompiler.Match tagsToIgnore; 16 19 17 20 RecentTagCollection(final int capacity) { … … 23 26 } 24 27 }; 28 tagsToIgnore = new SearchCompiler.Never(); 25 29 } 26 30 … … 31 35 String key = it.next(); 32 36 String value = it.next(); 33 recentTags.put(new Tag(key, value), null);37 add(new Tag(key, value)); 34 38 } 35 39 } … … 44 48 } 45 49 46 public void add(Tag key) { 47 recentTags.put(key, null); 50 public void add(Tag tag) { 51 if (!tagsToIgnore.match(tag)) { 52 recentTags.put(tag, null); 53 } 48 54 } 49 55 … … 55 61 return new ArrayList<>(recentTags.keySet()); 56 62 } 63 64 public void setTagsToIgnore(SearchCompiler.Match tagsToIgnore) { 65 this.tagsToIgnore = tagsToIgnore; 66 final Iterator<Tag> it = recentTags.keySet().iterator(); 67 while (it.hasNext()) { 68 if (tagsToIgnore.match(it.next())) { 69 it.remove(); 70 } 71 } 72 } 73 74 public void setTagsToIgnore(SearchAction.SearchSetting tagsToIgnore) throws SearchCompiler.ParseError { 75 setTagsToIgnore(tagsToIgnore.text.isEmpty() ? new SearchCompiler.Never() : SearchCompiler.compile(tagsToIgnore)); 76 } 77 78 public SearchAction.SearchSetting ignoreTag(Tag tagToIgnore, SearchAction.SearchSetting settingToUpdate) throws SearchCompiler.ParseError { 79 final String forTag = SearchCompiler.buildSearchStringForTag(tagToIgnore.getKey(), tagToIgnore.getValue()); 80 settingToUpdate.text = settingToUpdate.text.isEmpty() 81 ? forTag 82 : settingToUpdate.text + " OR " + forTag; 83 setTagsToIgnore(settingToUpdate); 84 return settingToUpdate; 85 } 57 86 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
r9939 r9940 37 37 import java.util.List; 38 38 import java.util.Map; 39 import java.util.Objects; 39 40 import java.util.TreeMap; 40 41 … … 57 58 import javax.swing.KeyStroke; 58 59 import javax.swing.ListCellRenderer; 60 import javax.swing.SwingUtilities; 59 61 import javax.swing.table.DefaultTableModel; 60 62 import javax.swing.text.JTextComponent; … … 62 64 import org.openstreetmap.josm.Main; 63 65 import org.openstreetmap.josm.actions.JosmAction; 66 import org.openstreetmap.josm.actions.search.SearchAction; 67 import org.openstreetmap.josm.actions.search.SearchCompiler; 64 68 import org.openstreetmap.josm.command.ChangePropertyCommand; 65 69 import org.openstreetmap.josm.command.Command; … … 71 75 import org.openstreetmap.josm.data.preferences.EnumProperty; 72 76 import org.openstreetmap.josm.data.preferences.IntegerProperty; 77 import org.openstreetmap.josm.data.preferences.StringProperty; 73 78 import org.openstreetmap.josm.gui.ExtendedDialog; 74 79 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; … … 125 130 DEFAULT_LRU_TAGS_NUMBER); 126 131 /** The preference storage of recent tags */ 127 public static final CollectionProperty COLLECTION_PROPERTY= new CollectionProperty("properties.recent-tags",132 public static final CollectionProperty PROPERTY_RECENT_TAGS = new CollectionProperty("properties.recent-tags", 128 133 Collections.<String>emptyList()); 134 public static final StringProperty PROPERTY_TAGS_TO_IGNORE = new StringProperty("properties.recent-tags.ignore", 135 new SearchAction.SearchSetting().writeToString()); 129 136 130 137 /** … … 159 166 160 167 final RecentTagCollection recentTags = new RecentTagCollection(MAX_LRU_TAGS_NUMBER); 168 SearchAction.SearchSetting tagsToIgnore; 161 169 162 170 // Copy of recently added tags, used to cache initial status … … 286 294 */ 287 295 public void loadTagsIfNeeded() { 296 loadTagsToIgnore(); 288 297 if (PROPERTY_REMEMBER_TAGS.get() && recentTags.isEmpty()) { 289 recentTags.loadFromPreference(COLLECTION_PROPERTY); 290 } 298 recentTags.loadFromPreference(PROPERTY_RECENT_TAGS); 299 } 300 } 301 302 void loadTagsToIgnore() { 303 final SearchAction.SearchSetting searchSetting = Utils.firstNonNull( 304 SearchAction.SearchSetting.readFromString(PROPERTY_TAGS_TO_IGNORE.get()), new SearchAction.SearchSetting()); 305 if (!Objects.equals(tagsToIgnore, searchSetting)) { 306 try { 307 tagsToIgnore = searchSetting; 308 recentTags.setTagsToIgnore(tagsToIgnore); 309 } catch (SearchCompiler.ParseError parseError) { 310 warnAboutParseError(parseError); 311 tagsToIgnore = new SearchAction.SearchSetting(); 312 recentTags.setTagsToIgnore(new SearchCompiler.Never()); 313 } 314 } 315 } 316 317 private void warnAboutParseError(SearchCompiler.ParseError parseError) { 318 Main.warn(parseError); 319 JOptionPane.showMessageDialog( 320 Main.parent, 321 parseError.getMessage(), 322 tr("Error"), 323 JOptionPane.ERROR_MESSAGE 324 ); 291 325 } 292 326 … … 296 330 public void saveTagsIfNeeded() { 297 331 if (PROPERTY_REMEMBER_TAGS.get() && !recentTags.isEmpty()) { 298 recentTags.saveToPreference( COLLECTION_PROPERTY);332 recentTags.saveToPreference(PROPERTY_RECENT_TAGS); 299 333 } 300 334 } … … 924 958 public void mouseClicked(MouseEvent e) { 925 959 action.actionPerformed(null); 926 if (e.isShiftDown()) { 960 if (SwingUtilities.isRightMouseButton(e)) { 961 new TagPopupMenu(t).show(e.getComponent(), e.getX(), e.getY()); 962 } else if (e.isShiftDown()) { 927 963 // add tags on Shift-Click 928 964 performTagAdding(); … … 952 988 } 953 989 990 class TagPopupMenu extends JPopupMenu { 991 992 TagPopupMenu(Tag t) { 993 add(new IgnoreTagAction(tr("Ignore key ''{0}''", t.getKey()), new Tag(t.getKey(), ""))); 994 add(new IgnoreTagAction(tr("Ignore tag ''{0}''", t), t)); 995 add(new EditIgnoreTagsAction()); 996 } 997 } 998 999 class IgnoreTagAction extends AbstractAction { 1000 final Tag tag; 1001 1002 IgnoreTagAction(String name, Tag tag) { 1003 super(name); 1004 this.tag = tag; 1005 } 1006 1007 @Override 1008 public void actionPerformed(ActionEvent e) { 1009 try { 1010 recentTags.ignoreTag(tag, tagsToIgnore); 1011 PROPERTY_TAGS_TO_IGNORE.put(tagsToIgnore.writeToString()); 1012 } catch (SearchCompiler.ParseError parseError) { 1013 throw new IllegalStateException(parseError); 1014 } 1015 } 1016 } 1017 1018 class EditIgnoreTagsAction extends AbstractAction { 1019 1020 EditIgnoreTagsAction() { 1021 super(tr("Edit ignore list")); 1022 } 1023 1024 @Override 1025 public void actionPerformed(ActionEvent e) { 1026 final SearchAction.SearchSetting newTagsToIngore = SearchAction.showSearchDialog(tagsToIgnore); 1027 if (newTagsToIngore == null) { 1028 return; 1029 } 1030 try { 1031 tagsToIgnore = newTagsToIngore; 1032 recentTags.setTagsToIgnore(tagsToIgnore); 1033 PROPERTY_TAGS_TO_IGNORE.put(tagsToIgnore.writeToString()); 1034 } catch (SearchCompiler.ParseError parseError) { 1035 warnAboutParseError(parseError); 1036 } 1037 } 1038 } 1039 954 1040 public void destroyActions() { 955 1041 for (JosmAction action : recentTagsActions) {
Note:
See TracChangeset
for help on using the changeset viewer.