Ticket #6935: searchkeyvalue.patch

File searchkeyvalue.patch, 3.5 KB (added by ij, 14 years ago)

Patch, but couldn't test it with latest due to unrelated compilation failure in trunk

  • src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

     
    101101import org.openstreetmap.josm.tools.OpenBrowser;
    102102import org.openstreetmap.josm.tools.Shortcut;
    103103import org.openstreetmap.josm.tools.Utils;
     104import org.openstreetmap.josm.actions.search.SearchAction.SearchMode;
     105import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;
    104106
    105107/**
    106108 * This dialog displays the properties of the current selected primitives.
     
    181183    private CopyValueAction copyValueAction = new CopyValueAction();
    182184    private CopyKeyValueAction copyKeyValueAction = new CopyKeyValueAction();
    183185    private CopyAllKeyValueAction copyAllKeyValueAction = new CopyAllKeyValueAction();
     186    private SearchAction searchActionAny = new SearchAction(false);
     187    private SearchAction searchActionSame = new SearchAction(true);
    184188    private AddAction addAction = new AddAction();
    185189
    186190    @Override
     
    615619        propertyMenu.add(copyKeyValueAction);
    616620        propertyMenu.add(copyAllKeyValueAction);
    617621        propertyMenu.addSeparator();
     622        propertyMenu.add(searchActionSame);
     623        propertyMenu.add(searchActionAny);       
     624        propertyMenu.addSeparator();
    618625        propertyMenu.add(helpAction);
    619626       
    620627        propertyData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")});
     
    14111418            return r;
    14121419        }
    14131420    }
     1421
     1422    class SearchAction extends AbstractAction {
     1423        final boolean sameType;
     1424
     1425        public SearchAction(boolean sameType) {
     1426            this.sameType = sameType;
     1427            if (sameType) {
     1428                putValue(NAME, tr("Search Key/Value keep type"));
     1429                putValue(SHORT_DESCRIPTION, tr("Search with the key and value of the selected tag, keep type"));
     1430            } else {
     1431                putValue(NAME, tr("Search Key/Value"));
     1432                putValue(SHORT_DESCRIPTION, tr("Search with the key and value of the selected tag"));
     1433            }
     1434        }
     1435
     1436        public void actionPerformed(ActionEvent e) {
     1437            if (propertyTable.getSelectedRowCount() != 1) {
     1438                return;
     1439            }
     1440            String key = propertyData.getValueAt(propertyTable.getSelectedRow(), 0).toString();
     1441            Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
     1442            if (sel.isEmpty()) {
     1443                return;
     1444            }
     1445            String sep = "";
     1446            String s = "";
     1447            for (OsmPrimitive p : sel) {
     1448                String val = p.get(key);
     1449                if (val == null) {
     1450                    continue;
     1451                }
     1452                String t = "";
     1453                if (!sameType) {
     1454                    t = "";
     1455                } else if (p instanceof Node) {
     1456                    t = "type:node ";
     1457                } else if (p instanceof Way) {
     1458                    t = "type:way ";
     1459                } else if (p instanceof Relation) {
     1460                    t = "type:relation ";
     1461                }
     1462                s += sep + "(" + t + "\"" + key + "\"=\"" + val + "\")";
     1463                sep = " OR ";
     1464            }
     1465
     1466            SearchSetting ss = new SearchSetting(s, SearchMode.replace, true, false, false);
     1467            org.openstreetmap.josm.actions.search.SearchAction.searchWithoutHistory(ss);
     1468        }
     1469    }
    14141470}