d9c0f041ef8d20a692c76de48b9a94308021b8f2 .../ui/internal/keys/model/KeyController.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/model/KeyController.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/model/KeyController.java index b2511a9..bcc4e89 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/model/KeyController.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/model/KeyController.java @@ -16,6 +16,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; +import java.util.Arrays; +import java.util.Comparator; import java.util.Map; import java.util.ResourceBundle; import org.eclipse.core.commands.CommandManager; @@ -511,6 +513,42 @@ public class KeyController { new FileOutputStream(filePath), "UTF-8")); //$NON-NLS-1$ final Object[] bindingElements = bindingModel.getBindings() .toArray(); + + class BindingElementComparator implements Comparator { + int compareObject(Object o1, Object o2) { + if (o1 == null && o2 == null) { + return 0; + } else if (o1 == null) { + return -1; + } else if (o2 == null) { + return 1; + } else { + return o1.hashCode() - o2.hashCode(); + } + } + + int compareString(String o1, String o2) { + if (o1 != null && o2 != null) { + return o1.compareTo(o2); + } + return compareObject(o1, o2); + } + + public int compare(Object o1, Object o2) { + final BindingElement BE1 = (BindingElement) o1; + final BindingElement BE2 = (BindingElement) o2; + + if (BE1 != null && BE2 != null) { + return compareString(BE1.getId(), BE2.getId()); + } else if (BE1 == null && BE2 == null) { + return compareObject(o1, o2); + } else { + return compareObject(BE1, BE2); + } + } + } + + Arrays.sort(bindingElements, new BindingElementComparator()); for (int i = 0; i < bindingElements.length; i++) { final BindingElement be = (BindingElement) bindingElements[i]; if (be.getTrigger() == null @@ -518,6 +556,8 @@ public class KeyController { continue; } StringBuffer buffer = new StringBuffer(); + buffer.append(ESCAPED_QUOTE + be.getId() + + ESCAPED_QUOTE + DELIMITER); buffer.append(ESCAPED_QUOTE + Util.replaceAll(be.getCategory(), ESCAPED_QUOTE, REPLACEMENT)