Changeset 3176 in josm for trunk


Ignore:
Timestamp:
2010-04-11T13:11:33+02:00 (10 years ago)
Author:
jttt
Message:

Fix #3952 Search history not remembered across restarts

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r3175 r3176  
    6666    }
    6767
    68     public static final LinkedList<SearchSetting> searchHistory = new LinkedList<SearchSetting>();
     68    private static LinkedList<SearchSetting> searchHistory = null;
     69
     70    public static Collection<SearchSetting> getSearchHistory() {
     71        if (searchHistory == null) {
     72            searchHistory = new LinkedList<SearchSetting>();
     73            for (String s: Main.pref.getCollection("search.history", Collections.<String>emptyList())) {
     74                SearchSetting ss = SearchSetting.readFromString(s);
     75                if (ss != null) {
     76                    searchHistory.add(ss);
     77                }
     78            }
     79        }
     80
     81        return searchHistory;
     82    }
     83
     84    public static void saveToHistory(SearchSetting s) {
     85        if(searchHistory.isEmpty() || !s.equals(searchHistory.getFirst())) {
     86            searchHistory.addFirst(new SearchSetting(s));
     87        }
     88        int maxsize = Main.pref.getInteger("search.history-size", DEFAULT_SEARCH_HISTORY_SIZE);
     89        while (searchHistory.size() > maxsize) {
     90            searchHistory.removeLast();
     91        }
     92        List<String> savedHistory = new ArrayList<String>();
     93        for (SearchSetting item: searchHistory) {
     94            savedHistory.add(item.writeToString());
     95        }
     96        Main.pref.putCollection("search.history", savedHistory);
     97    }
     98
     99    public static List<String> getSearchExpressionHistory() {
     100        ArrayList<String> ret = new ArrayList<String>(getSearchHistory().size());
     101        for (SearchSetting ss: getSearchHistory()) {
     102            ret.add(ss.text);
     103        }
     104        return ret;
     105    }
     106
     107
     108
     109
     110
    69111
    70112    private static SearchSetting lastSearch = null;
     
    88130            searchWithoutHistory((SearchSetting) parameters.get(SEARCH_EXPRESSION));
    89131        }
    90     }
    91 
    92     public static List<String> getSearchExpressionHistory() {
    93         ArrayList<String> ret = new ArrayList<String>(searchHistory.size());
    94         for (SearchSetting ss: searchHistory) {
    95             ret.add(ss.text);
    96         }
    97         return ret;
    98132    }
    99133
     
    222256     */
    223257    public static void searchWithHistory(SearchSetting s) {
    224         if(searchHistory.isEmpty() || !s.equals(searchHistory.getFirst())) {
    225             searchHistory.addFirst(new SearchSetting(s));
    226         }
    227         int maxsize = Main.pref.getInteger("search.history-size", DEFAULT_SEARCH_HISTORY_SIZE);
    228         while (searchHistory.size() > maxsize) {
    229             searchHistory.removeLast();
    230         }
     258        saveToHistory(s);
    231259        lastSearch = new SearchSetting(s);
    232260        search(s);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r3146 r3176  
    8383 */
    8484public class SelectionListDialog extends ToggleDialog  {
     85    @SuppressWarnings("unused")
    8586    static private final Logger logger = Logger.getLogger(SelectionListDialog.class.getName());
    8687
     
    639640     */
    640641    protected static class SearchMenuItem extends JMenuItem implements ActionListener {
    641         protected SearchSetting s;
     642        final protected SearchSetting s;
    642643
    643644        public SearchMenuItem(SearchSetting s) {
     
    658659    protected static class SearchPopupMenu extends JPopupMenu {
    659660        static public void launch(Component parent) {
    660             if (org.openstreetmap.josm.actions.search.SearchAction.searchHistory.isEmpty())
     661            if (org.openstreetmap.josm.actions.search.SearchAction.getSearchHistory().isEmpty())
    661662                return;
    662663            JPopupMenu menu = new SearchPopupMenu();
     
    666667
    667668        public SearchPopupMenu() {
    668             for (SearchSetting ss: org.openstreetmap.josm.actions.search.SearchAction.searchHistory) {
     669            for (SearchSetting ss: org.openstreetmap.josm.actions.search.SearchAction.getSearchHistory()) {
    669670                add(new SearchMenuItem(ss));
    670671            }
Note: See TracChangeset for help on using the changeset viewer.