Make '?' toggle the help dialog closed
Bug: GERRIT-184
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/src/main/java/com/google/gwtexpui/globalkey/client/ShowHelpCommand.java b/src/main/java/com/google/gwtexpui/globalkey/client/ShowHelpCommand.java
index 0620244..f95c55e 100644
--- a/src/main/java/com/google/gwtexpui/globalkey/client/ShowHelpCommand.java
+++ b/src/main/java/com/google/gwtexpui/globalkey/client/ShowHelpCommand.java
@@ -15,12 +15,16 @@
package com.google.gwtexpui.globalkey.client;
import com.google.gwt.event.dom.client.KeyPressEvent;
+import com.google.gwt.event.logical.shared.CloseEvent;
+import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;
public class ShowHelpCommand extends KeyCommand {
public static final ShowHelpCommand INSTANCE = new ShowHelpCommand();
+ private static KeyHelpPopup current;
public ShowHelpCommand() {
super(0, '?', Util.C.showHelp());
@@ -28,7 +32,21 @@
@Override
public void onKeyPress(final KeyPressEvent event) {
+ if (current != null) {
+ // Already open? Close the dialog.
+ //
+ current.hide();
+ current = null;
+ return;
+ }
+
final KeyHelpPopup help = new KeyHelpPopup();
+ help.addCloseHandler(new CloseHandler<PopupPanel>() {
+ @Override
+ public void onClose(final CloseEvent<PopupPanel> event) {
+ current = null;
+ }
+ });
help.setPopupPositionAndShow(new PositionCallback() {
@Override
public void setPosition(final int pWidth, final int pHeight) {