Changeset 9940 in josm for trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
- Timestamp:
- 2016-03-06T17:12:42+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.