Enable Escape & Enter for confirm dialog when delete a component
Closes
Fixes
@@ -39,6 +39,8 @@ import com.google.appinventor.shared.simple.ComponentDatabaseInterface;
import com.google.appinventor.shared.storage.StorageUtil;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.dom.client.FocusEvent;
+import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
@@ -46,6 +48,7 @@ import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
@@ -248,6 +251,20 @@ public abstract class MockComponent extends Composite implements PropertyChangeL
add(contentPanel);
}
+ @Override
+ protected void onPreviewNativeEvent(NativePreviewEvent event) {
+ super.onPreviewNativeEvent(event);
+ switch (event.getTypeInt()) {
+ case Event.ONKEYDOWN:
+ if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
+ hide();
+ } else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
+ hide();
+ MockComponent.this.delete();
+ }
+ break;
+ }
+ }
}
// Component database: information about components (including their properties and events)
