Commit 3776bb0a authored by Evan W. Patton's avatar Evan W. Patton Committed by Susan Rati Lane

Cancel focusing on TreeItems in Tree widgets (#1848)

Change-Id: Ib3e663aae8135694ddf423611ebcf7a7caffbd39
parent 43a74f92
...@@ -63,6 +63,7 @@ import com.google.gwt.user.client.Window; ...@@ -63,6 +63,7 @@ import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox; import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Focusable;
import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Image;
...@@ -739,6 +740,28 @@ public abstract class MockComponent extends Composite implements PropertyChangeL ...@@ -739,6 +740,28 @@ public abstract class MockComponent extends Composite implements PropertyChangeL
return container; return container;
} }
private final Focusable nullFocusable = new Focusable() {
@Override
public int getTabIndex() {
return 0;
}
@Override
public void setAccessKey(char key) {
}
@Override
public void setFocus(boolean focused) {
}
@Override
public void setTabIndex(int index) {
}
};
/** /**
* Constructs a tree item for the component which will be displayed in the * Constructs a tree item for the component which will be displayed in the
* source structure explorer. * source structure explorer.
...@@ -751,7 +774,12 @@ public abstract class MockComponent extends Composite implements PropertyChangeL ...@@ -751,7 +774,12 @@ public abstract class MockComponent extends Composite implements PropertyChangeL
// used to get HTML for the iconImage. AbstractImagePrototype requires // used to get HTML for the iconImage. AbstractImagePrototype requires
// an ImageResource, which we don't necessarily have. // an ImageResource, which we don't necessarily have.
TreeItem itemNode = new TreeItem( TreeItem itemNode = new TreeItem(
new HTML("<span>" + iconImage.getElement().getString() + getName() + "</span>")); new HTML("<span>" + iconImage.getElement().getString() + getName() + "</span>")) {
@Override
protected Focusable getFocusable() {
return nullFocusable;
}
};
itemNode.setUserObject(sourceStructureExplorerItem); itemNode.setUserObject(sourceStructureExplorerItem);
return itemNode; return itemNode;
} }
......
...@@ -37,6 +37,7 @@ public class SourceStructureExplorer extends Composite { ...@@ -37,6 +37,7 @@ public class SourceStructureExplorer extends Composite {
// Initialize UI elements // Initialize UI elements
tree = new Tree(Ode.getImageBundle()); tree = new Tree(Ode.getImageBundle());
tree.setAnimationEnabled(true); tree.setAnimationEnabled(true);
tree.setScrollOnSelectEnabled(false);
tree.addCloseHandler(new CloseHandler<TreeItem>() { tree.addCloseHandler(new CloseHandler<TreeItem>() {
@Override @Override
public void onClose(CloseEvent<TreeItem> event) { public void onClose(CloseEvent<TreeItem> event) {
......
...@@ -12,6 +12,7 @@ import com.google.appinventor.client.explorer.commands.ProjectNodeCommand; ...@@ -12,6 +12,7 @@ import com.google.appinventor.client.explorer.commands.ProjectNodeCommand;
import com.google.appinventor.client.widgets.ContextMenu; import com.google.appinventor.client.widgets.ContextMenu;
import com.google.appinventor.shared.rpc.project.ProjectNode; import com.google.appinventor.shared.rpc.project.ProjectNode;
import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
import java.util.List; import java.util.List;
...@@ -31,7 +32,7 @@ public final class ProjectNodeContextMenu { ...@@ -31,7 +32,7 @@ public final class ProjectNodeContextMenu {
* @param node node for which to show the context menu * @param node node for which to show the context menu
* @param host widget to anchor context menu to * @param host widget to anchor context menu to
*/ */
public static void show(final ProjectNode node, Widget host) { public static void show(final ProjectNode node, Widget host, int clientX, int clientY) {
List<CommandRegistry.Entry> entries = Ode.getCommandRegistry().get(node); List<CommandRegistry.Entry> entries = Ode.getCommandRegistry().get(node);
if (entries.isEmpty()) { if (entries.isEmpty()) {
...@@ -40,8 +41,8 @@ public final class ProjectNodeContextMenu { ...@@ -40,8 +41,8 @@ public final class ProjectNodeContextMenu {
final ContextMenu menu = new ContextMenu(); final ContextMenu menu = new ContextMenu();
// Position the context menu to the East of the host widget. // Position the context menu to the East of the host widget.
menu.setPopupPosition(host.getAbsoluteLeft() + host.getOffsetWidth(), menu.setPopupPosition(Window.getScrollLeft() + clientX,
host.getAbsoluteTop()); Window.getScrollTop() + clientY);
for (final CommandRegistry.Entry entry : entries) { for (final CommandRegistry.Entry entry : entries) {
final ProjectNodeCommand cmd = entry.getCommand(); final ProjectNodeCommand cmd = entry.getCommand();
......
...@@ -22,8 +22,11 @@ import com.google.appinventor.shared.rpc.project.youngandroid.YoungAndroidProjec ...@@ -22,8 +22,11 @@ import com.google.appinventor.shared.rpc.project.youngandroid.YoungAndroidProjec
import com.google.appinventor.shared.storage.StorageUtil; import com.google.appinventor.shared.storage.StorageUtil;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseMoveHandler;
import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler; import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Image;
...@@ -47,6 +50,8 @@ public class AssetList extends Composite implements ProjectChangeListener { ...@@ -47,6 +50,8 @@ public class AssetList extends Composite implements ProjectChangeListener {
private long projectId; private long projectId;
private Project project; private Project project;
private YoungAndroidAssetsFolder assetsFolder; private YoungAndroidAssetsFolder assetsFolder;
private int clientX;
private int clientY;
/** /**
* Creates a new AssetList * Creates a new AssetList
...@@ -81,6 +86,15 @@ public class AssetList extends Composite implements ProjectChangeListener { ...@@ -81,6 +86,15 @@ public class AssetList extends Composite implements ProjectChangeListener {
initWidget(panel); initWidget(panel);
assetList.setScrollOnSelectEnabled(false);
assetList.sinkEvents(Event.ONMOUSEMOVE);
assetList.addMouseMoveHandler(new MouseMoveHandler() {
@Override
public void onMouseMove(MouseMoveEvent event) {
clientX = event.getClientX();
clientY = event.getClientY();
}
});
assetList.addSelectionHandler(new SelectionHandler<TreeItem>() { assetList.addSelectionHandler(new SelectionHandler<TreeItem>() {
@Override @Override
public void onSelection(SelectionEvent<TreeItem> event) { public void onSelection(SelectionEvent<TreeItem> event) {
...@@ -88,7 +102,7 @@ public class AssetList extends Composite implements ProjectChangeListener { ...@@ -88,7 +102,7 @@ public class AssetList extends Composite implements ProjectChangeListener {
ProjectNode node = (ProjectNode) selected.getUserObject(); ProjectNode node = (ProjectNode) selected.getUserObject();
// The actual menu is determined by what is registered for the filenode // The actual menu is determined by what is registered for the filenode
// type in CommandRegistry.java // type in CommandRegistry.java
ProjectNodeContextMenu.show(node, selected.getWidget()); ProjectNodeContextMenu.show(node, selected.getWidget(), clientX, clientY);
}}); }});
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment