summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2009-07-07 16:20:18 -0700
committerShawn O. Pearce <sop@google.com>2009-07-10 08:39:42 -0700
commit7e83c7ace01c68fbac8265d3d3526b1faad2e639 (patch)
treef518c09ec00a40a4c19905d72d6efc38606ad66a
parent1c6a51cb5b8301a38240456ef330954995b6c3bd (diff)
downloadgwtexpui-7e83c7ace01c68fbac8265d3d3526b1faad2e639.tar.gz
Combine key groups with the same name
If two different KeyCommandSets have the same name for their sections, its likely because two different UI widgets wanted to register different bindings at once. It looks better to the end-user if we only display one set. Reviewed-by: Cedric Beust <cbeust@google.com> Signed-off-by: Shawn O. Pearce <sop@google.com>
-rw-r--r--src/main/java/com/google/gwtexpui/globalkey/client/KeyHelpPopup.java26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/main/java/com/google/gwtexpui/globalkey/client/KeyHelpPopup.java b/src/main/java/com/google/gwtexpui/globalkey/client/KeyHelpPopup.java
index 36b5858..66dd6df 100644
--- a/src/main/java/com/google/gwtexpui/globalkey/client/KeyHelpPopup.java
+++ b/src/main/java/com/google/gwtexpui/globalkey/client/KeyHelpPopup.java
@@ -30,9 +30,10 @@ import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
import com.google.gwtexpui.user.client.PluginSafePopupPanel;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
-import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
@@ -101,12 +102,9 @@ public class KeyHelpPopup extends PluginSafePopupPanel implements
}
private void populate(final Grid lists) {
- final Iterator<KeyCommandSet> setitr =
- GlobalKey.active.all.getSets().iterator();
int end[] = new int[5];
int column = 0;
- while (setitr.hasNext()) {
- final KeyCommandSet set = setitr.next();
+ for (final KeyCommandSet set : combinedSetsByName()) {
int row = end[column];
row = formatGroup(lists, row, column, set);
end[column] = row;
@@ -118,6 +116,24 @@ public class KeyHelpPopup extends PluginSafePopupPanel implements
}
}
+ /**
+ * @return an ordered collection of KeyCommandSet, combining sets which share
+ * the same name, so that each set name appears at most once.
+ */
+ private static Collection<KeyCommandSet> combinedSetsByName() {
+ final LinkedHashMap<String, KeyCommandSet> byName =
+ new LinkedHashMap<String, KeyCommandSet>();
+ for (final KeyCommandSet set : GlobalKey.active.all.getSets()) {
+ KeyCommandSet v = byName.get(set.getName());
+ if (v == null) {
+ v = new KeyCommandSet(set.getName());
+ byName.put(v.getName(), v);
+ }
+ v.add(set);
+ }
+ return byName.values();
+ }
+
private int formatGroup(final Grid lists, int row, final int col,
final KeyCommandSet set) {
if (set.isEmpty()) {