Ticket #740: josm-search-feedback.diff

File josm-search-feedback.diff, 2.0 KB (added by dnaber, 18 years ago)
  • home/dnaber/workspace/JOSM/src/org/openstreetmap/josm/actions/search/SearchAction.java

     
    8787                try {
    8888                        Collection<OsmPrimitive> sel = Main.ds.getSelected();
    8989                        SearchCompiler.Match matcher = SearchCompiler.compile(search, caseSensitive);
     90                        int foundMatches = 0;
    9091                        for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) {
    9192                                if (mode == SearchMode.replace) {
    92                                         if (matcher.match(osm))
     93                                        if (matcher.match(osm)) {
    9394                                                sel.add(osm);
    94                                         else
     95                                                foundMatches++;
     96                                        } else {
    9597                                                sel.remove(osm);
    96                                 } else if (mode == SearchMode.add && !osm.selected && matcher.match(osm))
     98                                        }
     99                                } else if (mode == SearchMode.add && !osm.selected && matcher.match(osm)) {
    97100                                        sel.add(osm);
    98                                 else if (mode == SearchMode.remove && osm.selected && matcher.match(osm))
     101                                        foundMatches++;
     102                                } else if (mode == SearchMode.remove && osm.selected && matcher.match(osm)) {
    99103                                        sel.remove(osm);
     104                                        foundMatches++;
     105                                }
    100106                        }
    101107                        Main.ds.setSelected(sel);
     108                        if (foundMatches == 0) {
     109                                String msg = null;
     110                                if (mode == SearchMode.replace) {
     111                                        msg = tr("No match found for ''{0}''", search);
     112                                } else if (mode == SearchMode.add) {
     113                                        msg = tr("Nothing added to selection by searching for ''{0}''", search);
     114                                } else if (mode == SearchMode.remove) {
     115                                        msg = tr("Nothing removed from selection by searching for ''{0}''", search);
     116                                }
     117                                Main.map.statusLine.setHelpText(msg);
     118                                JOptionPane.showMessageDialog(Main.parent, msg);
     119                        } else {
     120                                Main.map.statusLine.setHelpText(tr("Found {0} matches", foundMatches));
     121                        }
    102122                } catch (SearchCompiler.ParseError e) {
    103123                        JOptionPane.showMessageDialog(Main.parent, e.getMessage());
    104124                }