Ticket #6974: customSearchActionPermanent.patch

File customSearchActionPermanent.patch, 2.8 KB (added by akks, 15 years ago)
  • src/org/openstreetmap/josm/actions/search/SearchAction.java

     
    22package org.openstreetmap.josm.actions.search;
    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;
    78
     
    3536import org.openstreetmap.josm.data.osm.Filter;
    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;
    4042import org.openstreetmap.josm.tools.Property;
     
    185187        JCheckBox allElements = new JCheckBox(tr("all objects"), initialValues.allElements);
    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());
    190193        top.add(label, GBC.std().insets(0, 0, 5, 0));
     
    199202        {
    200203            left.add(allElements, GBC.eol());
    201204            left.add(regexSearch, GBC.eol());
     205            left.add(addOnToolbar, GBC.eol());
    202206        }
    203207
    204208        JPanel right = new JPanel();
     
    292296        initialValues.caseSensitive = caseSensitive.isSelected();
    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    }
    297318