Index: /trunk/data/tagging-preset.xsd
===================================================================
--- /trunk/data/tagging-preset.xsd	(revision 3838)
+++ /trunk/data/tagging-preset.xsd	(revision 3839)
@@ -1,30 +1,29 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://josm.openstreetmap.de/tagging-preset-1.0"
-	xmlns:tns="http://josm.openstreetmap.de/tagging-preset-1.0" elementFormDefault="qualified">
-
-	<!--
-		Localized attributes (for example de.description are not supported by
-		xsd, so every element needs <anyAttribute/>
-		To cover at least some common errors, elements have specified prohibited attributes
-	-->
-
-	<element name="annotations" type="tns:root"/>
-	<element name="presets" type="tns:root"/>
+	xmlns:tns="http://josm.openstreetmap.de/tagging-preset-1.0"
+	elementFormDefault="qualified">
+
+	<!-- Localized attributes (for example de.description are not supported 
+		by xsd, so every element needs <anyAttribute/> To cover at least some common 
+		errors, elements have specified prohibited attributes -->
+
+	<element name="annotations" type="tns:root" />
+	<element name="presets" type="tns:root" />
 
 	<complexType name="root">
 		<complexContent>
-			<extension base="tns:group">
+			<extension base="tns:group-parent">
 				<attribute name="author" type="string" />
 				<attribute name="version" type="string" />
 				<attribute name="shortdescription" type="string" />
 				<attribute name="description" type="string" />
-				<attribute name="link" type="string"/>
-
-				<anyAttribute processContents="skip"/>
+				<attribute name="link" type="string" />
+
+				<anyAttribute processContents="skip" />
 			</extension>
 		</complexContent>
 	</complexType>
 
-	<complexType name="group">
+	<complexType name="group-parent">
 		<sequence>
 			<choice minOccurs="1" maxOccurs="unbounded">
@@ -34,10 +33,17 @@
 			</choice>
 		</sequence>
-		<attribute name="name" type="string" />
 		<attribute name="icon" type="string" />
 
-		<attribute name="type" use="prohibited"/>
-		<attribute name="text" use="prohibited"/>
-		<anyAttribute processContents="skip"/>
+		<attribute name="type" use="prohibited" />
+		<attribute name="text" use="prohibited" />
+		<anyAttribute processContents="skip" />
+	</complexType>
+
+	<complexType name="group">
+		<complexContent>
+			<extension base="tns:group-parent">
+				<attribute name="name" type="string" use="required" />
+			</extension>
+		</complexContent>
 	</complexType>
 
@@ -53,10 +59,10 @@
 			<element name="roles" type="tns:roles" minOccurs="0" />
 		</sequence>
-		<attribute name="name" type="string" />
+		<attribute name="name" type="string" use="required" />
 		<attribute name="icon" type="string" />
 		<attribute name="type" type="string" />
 
-		<attribute name="text" use="prohibited"/>
-		<anyAttribute processContents="skip"/>
+		<attribute name="text" use="prohibited" />
+		<anyAttribute processContents="skip" />
 	</complexType>
 
@@ -78,6 +84,6 @@
 
 	<complexType name="key">
-		<attribute name="key" type="string" use="required"/>
-		<attribute name="value" type="string"/>
+		<attribute name="key" type="string" use="required" />
+		<attribute name="value" type="string" />
 	</complexType>
 
@@ -88,6 +94,6 @@
 		<attribute name="text_context" type="string" />
 
-		<attribute name="name" use="prohibited"/>
-		<anyAttribute processContents="skip"/>
+		<attribute name="name" use="prohibited" />
+		<anyAttribute processContents="skip" />
 	</complexType>
 
@@ -96,6 +102,6 @@
 		<attribute name="text_context" type="string" />
 
-		<attribute name="name" use="prohibited"/>
-		<anyAttribute processContents="skip"/>
+		<attribute name="name" use="prohibited" />
+		<anyAttribute processContents="skip" />
 	</complexType>
 
@@ -103,5 +109,5 @@
 
 	<complexType name="text">
-		<attribute name="key" type="string" use="required"/>
+		<attribute name="key" type="string" use="required" />
 		<attribute name="text" type="string" />
 		<attribute name="text_context" type="string" />
@@ -109,16 +115,17 @@
 		<attribute name="delete_if_empty" type="boolean" />
 		<attribute name="use_last_as_default" type="boolean" />
-		<attribute name="required" type="boolean"/>
-
-		<attribute name="type" use="prohibited"/>
-		<attribute name="name" use="prohibited"/>
-		<attribute name="value" use="prohibited"/>
-		<attribute name="values" use="prohibited"/>
-		<anyAttribute processContents="skip"/>
+		<attribute name="required" type="boolean" />
+
+		<attribute name="type" use="prohibited" />
+		<attribute name="name" use="prohibited" />
+		<attribute name="value" use="prohibited" />
+		<attribute name="values" use="prohibited" />
+		<anyAttribute processContents="skip" />
 	</complexType>
 
 	<complexType name="combo">
 		<sequence>
-			<element name="short_description" type="string" minOccurs="0" maxOccurs="unbounded"/>
+			<element name="short_description" type="string" minOccurs="0"
+				maxOccurs="unbounded" />
 		</sequence>
 		<attribute name="key" type="string" use="required" />
@@ -127,16 +134,16 @@
 		<attribute name="values" type="string" use="required" />
 		<attribute name="values_context" type="string" />
-		<attribute name="display_values" type="string"/>
+		<attribute name="display_values" type="string" />
 		<attribute name="default" type="string" />
 		<attribute name="editable" type="boolean" />
 		<attribute name="delete_if_empty" type="boolean" />
-		<attribute name="required" type="boolean"/>
-
-		<attribute name="type" use="prohibited"/>
-		<attribute name="value" use="prohibited"/>
-		<attribute name="name" use="prohibited"/>
-		<attribute name="delete-if-empty" use="prohibited"/>
-		<attribute name="display-values" use="prohibited"/>
-		<anyAttribute processContents="skip"/>
+		<attribute name="required" type="boolean" />
+
+		<attribute name="type" use="prohibited" />
+		<attribute name="value" use="prohibited" />
+		<attribute name="name" use="prohibited" />
+		<attribute name="delete-if-empty" use="prohibited" />
+		<attribute name="display-values" use="prohibited" />
+		<anyAttribute processContents="skip" />
 	</complexType>
 
@@ -147,16 +154,16 @@
 		<attribute name="values" type="string" use="required" />
 		<attribute name="values_context" type="string" />
-		<attribute name="display_values" type="string"/>
+		<attribute name="display_values" type="string" />
 		<attribute name="default" type="string" />
 		<attribute name="delimiter" type="string" />
 		<attribute name="delete_if_empty" type="boolean" />
-		<attribute name="required" type="boolean"/>
-
-		<attribute name="type" use="prohibited"/>
-		<attribute name="value" use="prohibited"/>
-		<attribute name="name" use="prohibited"/>
-		<attribute name="delete-if-empty" use="prohibited"/>
-		<attribute name="display-values" use="prohibited"/>
-		<anyAttribute processContents="skip"/>
+		<attribute name="required" type="boolean" />
+
+		<attribute name="type" use="prohibited" />
+		<attribute name="value" use="prohibited" />
+		<attribute name="name" use="prohibited" />
+		<attribute name="delete-if-empty" use="prohibited" />
+		<attribute name="display-values" use="prohibited" />
+		<anyAttribute processContents="skip" />
 	</complexType>
 
@@ -167,12 +174,12 @@
 		<attribute name="default" type="tns:check_default" />
 		<attribute name="use_last_as_default" type="boolean" />
-		<attribute name="required" type="boolean"/>
-		<attribute name="value_on" type="string"/>
-		<attribute name="value_off" type="string"/>
-
-		<attribute name="name" use="prohibited"/>
-		<attribute name="type" use="prohibited"/>
-		<attribute name="value" use="prohibited"/>
-		<anyAttribute processContents="skip"/>
+		<attribute name="required" type="boolean" />
+		<attribute name="value_on" type="string" />
+		<attribute name="value_off" type="string" />
+
+		<attribute name="name" use="prohibited" />
+		<attribute name="type" use="prohibited" />
+		<attribute name="value" use="prohibited" />
+		<anyAttribute processContents="skip" />
 	</complexType>
 
@@ -186,22 +193,22 @@
 	<complexType name="roles">
 		<sequence>
-			<element name="role" type="tns:role" minOccurs="1" maxOccurs="unbounded"/>
+			<element name="role" type="tns:role" minOccurs="1" maxOccurs="unbounded" />
 		</sequence>
 	</complexType>
 
 	<complexType name="role">
-		<attribute name="key" type="string"/>
-		<attribute name="text" type="string"/>
-		<attribute name="text_context" type="string"/>
-		<attribute name="requisite" type="tns:role_requisite"/>
-		<attribute name="type" type="string"/>
-		<attribute name="count" type="integer"/>
-		<attribute name="required" type="boolean"/>
+		<attribute name="key" type="string" />
+		<attribute name="text" type="string" />
+		<attribute name="text_context" type="string" />
+		<attribute name="requisite" type="tns:role_requisite" />
+		<attribute name="type" type="string" />
+		<attribute name="count" type="integer" />
+		<attribute name="required" type="boolean" />
 	</complexType>
 
 	<simpleType name="role_requisite">
 		<restriction base="string">
-			<enumeration value="required"/>
-			<enumeration value="optional"/>
+			<enumeration value="required" />
+			<enumeration value="optional" />
 		</restriction>
 	</simpleType>
Index: /trunk/src/org/openstreetmap/josm/data/AutosaveTask.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/AutosaveTask.java	(revision 3838)
+++ /trunk/src/org/openstreetmap/josm/data/AutosaveTask.java	(revision 3839)
@@ -7,5 +7,4 @@
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Date;
 import java.util.Deque;
@@ -274,5 +273,5 @@
                     moveToDeletedLayersFolder(f);
                 }
-            }          
+            }
         });
     }
Index: /trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java	(revision 3838)
+++ /trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java	(revision 3839)
@@ -11,5 +11,4 @@
 import java.awt.Image;
 import java.awt.Insets;
-import java.awt.Color;
 import java.awt.event.ActionEvent;
 import java.io.BufferedReader;
@@ -182,48 +181,48 @@
     }
 
-        protected static class PresetListEntry {
-            String value;
-            String display_value;
-            String short_description;
-
-            public String getListDisplay() {
-                if (value.equals(DIFFERENT))
-                    return "<b>"+DIFFERENT.replaceAll("<", "&lt;").replaceAll(">", "&gt;")+"</b>";
-
-                if (value.equals(""))
-                    return "&nbsp;";
-
-                StringBuilder res = new StringBuilder("<b>");
-                if (display_value != null) {
-                    res.append(display_value);
-                } else {
-                    res.append(value);
-                }
-                res.append("</b>");
-                if (short_description != null) {
-                    // wrap in table to restrict the text width
-                    res.append("<br><table><td width='232'>(").append(short_description).append(")</td></table>");
-                }
-                return res.toString();
-            }
-
-            public PresetListEntry(String value) {
-                this.value = value;
-                this.display_value = value;
-            }
-
-            public PresetListEntry(String value, String display_value) {
-                this.value = value;
-                this.display_value = display_value;
-            }
-
-            // toString is mainly used to initialize the Editor
-            @Override
-            public String toString() {
-                if (value.equals(DIFFERENT))
-                    return DIFFERENT;
-                return display_value.replaceAll("<.*>", ""); // remove additional markup, e.g. <br>
-            }
-        }
+    protected static class PresetListEntry {
+        String value;
+        String display_value;
+        String short_description;
+
+        public String getListDisplay() {
+            if (value.equals(DIFFERENT))
+                return "<b>"+DIFFERENT.replaceAll("<", "&lt;").replaceAll(">", "&gt;")+"</b>";
+
+            if (value.equals(""))
+                return "&nbsp;";
+
+            StringBuilder res = new StringBuilder("<b>");
+            if (display_value != null) {
+                res.append(display_value);
+            } else {
+                res.append(value);
+            }
+            res.append("</b>");
+            if (short_description != null) {
+                // wrap in table to restrict the text width
+                res.append("<br><table><td width='232'>(").append(short_description).append(")</td></table>");
+            }
+            return res.toString();
+        }
+
+        public PresetListEntry(String value) {
+            this.value = value;
+            this.display_value = value;
+        }
+
+        public PresetListEntry(String value, String display_value) {
+            this.value = value;
+            this.display_value = display_value;
+        }
+
+        // toString is mainly used to initialize the Editor
+        @Override
+        public String toString() {
+            if (value.equals(DIFFERENT))
+                return DIFFERENT;
+            return display_value.replaceAll("<.*>", ""); // remove additional markup, e.g. <br>
+        }
+    }
 
     public static class Text extends Item {
@@ -460,6 +459,6 @@
                 PresetListEntry e = new PresetListEntry(value_array[i]);
                 e.display_value = (locale_display_values == null)
-                        ? (values_context == null ? tr(display_array[i])
-                                : trc(values_context, display_array[i])) : display_array[i];
+                ? (values_context == null ? tr(display_array[i])
+                        : trc(values_context, display_array[i])) : display_array[i];
                 if (short_descriptions_array != null) {
                     e.short_description = locale_short_descriptions == null ? tr(short_descriptions_array[i])
@@ -633,9 +632,10 @@
                 int j = 0;
                 for (int i = 0; i < lm.getSize(); i++) {
-                    if (parts.contains((((PresetListEntry)lm.getElementAt(i)).value))) 
+                    if (parts.contains((((PresetListEntry)lm.getElementAt(i)).value))) {
                         intParts[j++]=i;
+                    }
                 }
                 setSelectedIndices(Arrays.copyOf(intParts, j));
-                // check if we have acutally managed to represent the full 
+                // check if we have acutally managed to represent the full
                 // value with our presets. if not, cop out; we will not offer
                 // a selection list that threatens to ruin the value.
@@ -647,6 +647,8 @@
             int[] si = getSelectedIndices();
             StringBuilder builder = new StringBuilder();
-            for (int i=0; i<si.length; i++) { 
-                if (i>0) builder.append(delimiter);
+            for (int i=0; i<si.length; i++) {
+                if (i>0) {
+                    builder.append(delimiter);
+                }
                 builder.append(((PresetListEntry)lm.getElementAt(si[i])).value);
             }
@@ -726,6 +728,6 @@
                 PresetListEntry e = new PresetListEntry(value_array[i]);
                 e.display_value = (locale_display_values == null)
-                        ? (values_context == null ? tr(display_array[i])
-                                : trc(values_context, display_array[i])) : display_array[i];
+                ? (values_context == null ? tr(display_array[i])
+                        : trc(values_context, display_array[i])) : display_array[i];
                 if (short_descriptions_array != null) {
                     e.short_description = locale_short_descriptions == null ? tr(short_descriptions_array[i])
Index: /trunk/src/org/openstreetmap/josm/tools/PresetTextComparator.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/tools/PresetTextComparator.java	(revision 3838)
+++ /trunk/src/org/openstreetmap/josm/tools/PresetTextComparator.java	(revision 3839)
@@ -7,8 +7,20 @@
 import javax.swing.JMenuItem;
 
+import org.openstreetmap.josm.Main;
+
 public class PresetTextComparator implements Comparator<JMenuItem>, Serializable {
-    //TODO add error checking and stuff
     public int compare(JMenuItem arg0, JMenuItem arg1) {
-        return arg0.getText().compareTo(arg1.getText());
+        if (Main.main.menu.presetSearchAction.equals(arg0.getAction()))
+            return -1;
+        else if (Main.main.menu.presetSearchAction.equals(arg0.getAction()))
+            return 1;
+        else if (arg0.getText() == arg1.getText())
+            return 0;
+        else if (arg0.getText() == null)
+            return -1;
+        else if (arg1.getText() == null)
+            return 1;
+        else
+            return arg0.getText().compareTo(arg1.getText());
     }
 
