Changeset 4587 in josm


Ignore:
Timestamp:
Nov 7, 2011 1:12:19 PM (19 months ago)
Author:
stoecker
Message:

fix #6974 - patch by akks - Ability to add custom search from search dialog

File:
1 edited

Legend:

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

    r4543 r4587  
    33 
    44import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 
     5import org.openstreetmap.josm.gui.preferences.ToolbarPreferences.ActionParser; 
    56import static org.openstreetmap.josm.tools.I18n.tr; 
    67import static org.openstreetmap.josm.tools.I18n.trc; 
     
    3637import org.openstreetmap.josm.data.osm.OsmPrimitive; 
    3738import org.openstreetmap.josm.gui.ExtendedDialog; 
     39import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; 
    3840import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 
    3941import org.openstreetmap.josm.tools.GBC; 
     
    186188        allElements.setToolTipText(tr("Also include incomplete and deleted objects in search.")); 
    187189        final JCheckBox regexSearch   = new JCheckBox(tr("regular expression"), initialValues.regexSearch); 
     190        final JCheckBox addOnToolbar  = new JCheckBox(tr("Add toolbar button"), false);  
    188191 
    189192        JPanel top = new JPanel(new GridBagLayout()); 
     
    200203            left.add(allElements, GBC.eol()); 
    201204            left.add(regexSearch, GBC.eol()); 
     205            left.add(addOnToolbar, GBC.eol());  
    202206        } 
    203207 
     
    293297        initialValues.allElements = allElements.isSelected(); 
    294298        initialValues.regexSearch = regexSearch.isSelected(); 
     299         
     300        if (addOnToolbar.isSelected()) { 
     301            ToolbarPreferences.ActionDefinition aDef =  
     302                    new ToolbarPreferences.ActionDefinition(Main.main.menu.search); 
     303            aDef.getParameters().put("searchExpression", initialValues); 
     304            // parametrized action definition is now composed 
     305            ActionParser actionParser = new ToolbarPreferences.ActionParser(null); 
     306            String res = actionParser.saveAction(aDef); 
     307             
     308            Collection<String> t = new LinkedList<String>(Main.pref.getCollection("toolbar")); 
     309            if (t!=null) { 
     310                // add custom search button to toolbar preferences 
     311                if (!t.contains(res)) t.add(res); 
     312                Main.pref.putCollection("toolbar", t); 
     313                Main.toolbar.refreshToolbarControl(); 
     314            } 
     315        } 
    295316        return initialValues; 
    296317    } 
Note: See TracChangeset for help on using the changeset viewer.