Expose the PopupPanel hide command used by GlobalKey This way applications can setup a binding on the same key that is used to open the dialog to close it, making that key a toggle key. By using the same command class, the help for the dialog will show the various different methods of closing the dialog aliased under a single entry. Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/src/main/java/com/google/gwtexpui/globalkey/client/GlobalKey.java b/src/main/java/com/google/gwtexpui/globalkey/client/GlobalKey.java index 16c2970..a50f205 100644 --- a/src/main/java/com/google/gwtexpui/globalkey/client/GlobalKey.java +++ b/src/main/java/com/google/gwtexpui/globalkey/client/GlobalKey.java
@@ -86,13 +86,7 @@ assert panel.isShowing(); assert active == global; active = new State(panel); - active.add(new KeyCommand(0, KeyCodes.KEY_ESCAPE, Util.C - .closeCurrentDialog()) { - @Override - public void onKeyPress(final KeyPressEvent event) { - panel.hide(); - } - }); + active.add(new HidePopupPanelCommand(0, KeyCodes.KEY_ESCAPE, panel)); panel.addCloseHandler(restoreGlobal); }
diff --git a/src/main/java/com/google/gwtexpui/globalkey/client/HidePopupPanelCommand.java b/src/main/java/com/google/gwtexpui/globalkey/client/HidePopupPanelCommand.java new file mode 100644 index 0000000..6d9c50e --- /dev/null +++ b/src/main/java/com/google/gwtexpui/globalkey/client/HidePopupPanelCommand.java
@@ -0,0 +1,33 @@ +// Copyright (C) 2009 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gwtexpui.globalkey.client; + +import com.google.gwt.event.dom.client.KeyPressEvent; +import com.google.gwt.user.client.ui.PopupPanel; + +/** Hides the given popup panel when invoked. */ +public class HidePopupPanelCommand extends KeyCommand { + private final PopupPanel panel; + + public HidePopupPanelCommand(int mask, int key, PopupPanel panel) { + super(mask, key, Util.C.closeCurrentDialog()); + this.panel = panel; + } + + @Override + public void onKeyPress(final KeyPressEvent event) { + panel.hide(); + } +}