Support 'id' attribute for menu items contributed by plugins

For menu items in the top menu that are contributed by plugins it is
now optionally possible to specify the 'id' attribute. Having the 'id'
attribute allows GWT UI plugins to manipulate the menu item. E.g. a
GWT plugin could open a dialog box when the user clicks on the menu
item:

  RootPanel rootPanel = RootPanel.get(MENU_ID);
  rootPanel.getElement().removeAttribute("href");
  rootPanel.addDomHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
      dialogBox.center();
      dialogBox.show();
    }
  }, ClickEvent.getType());

Change-Id: Icbe2a5c5af9c126a6dd2373b768cae651e482200
This commit is contained in:
Edwin Kempin
2013-11-06 09:10:47 +01:00
parent a04edc9610
commit 002c9cb5b2
4 changed files with 20 additions and 9 deletions

View File

@@ -181,7 +181,7 @@ CapabilityInfo
~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
The `CapabilityInfo` entity contains information about a capability. The `CapabilityInfo` entity contains information about a capability.
[options="header",width="50%",cols="1,5"] [options="header",width="50%",cols="1,6"]
|================================= |=================================
|Field Name |Description |Field Name |Description
|`kind` |`gerritcodereview#capability` |`kind` |`gerritcodereview#capability`
@@ -195,7 +195,7 @@ TopMenuEntryInfo
The `TopMenuEntryInfo` entity contains information about a top menu The `TopMenuEntryInfo` entity contains information about a top menu
entry. entry.
[options="header",width="50%",cols="1,5"] [options="header",width="50%",cols="1,6"]
|================================= |=================================
|Field Name |Description |Field Name |Description
|`name` |Name of the top menu entry. |`name` |Name of the top menu entry.
@@ -208,13 +208,14 @@ TopMenuItemInfo
The `TopMenuItemInfo` entity contains information about a menu item in The `TopMenuItemInfo` entity contains information about a menu item in
a top menu entry. a top menu entry.
[options="header",width="50%",cols="1,5"] [options="header",width="50%",cols="1,^1,5"]
|================================= |========================
|Field Name |Description |Field Name ||Description
|`url` |The URL of the menu item link. |`url` ||The URL of the menu item link.
|`name` |The name of the menu item. |`name` ||The name of the menu item.
|`target` |Target attribute of the menu item link. |`target` ||Target attribute of the menu item link.
|================================= |`id` |optional|The `id` attribute of the menu item link.
|========================
GERRIT GERRIT
------ ------

View File

@@ -38,15 +38,21 @@ public interface TopMenu {
public final String url; public final String url;
public final String name; public final String name;
public final String target; public final String target;
public final String id;
public MenuItem(String name, String url) { public MenuItem(String name, String url) {
this(name, url, "_blank"); this(name, url, "_blank");
} }
public MenuItem(String name, String url, String target) { public MenuItem(String name, String url, String target) {
this(name, url, target, null);
}
public MenuItem(String name, String url, String target, String id) {
this.url = url; this.url = url;
this.name = name; this.name = name;
this.target = target; this.target = target;
this.id = id;
} }
} }

View File

@@ -978,6 +978,9 @@ public class Gerrit implements EntryPoint {
private static void addExtensionLink(final LinkMenuBar m, final TopMenuItem item) { private static void addExtensionLink(final LinkMenuBar m, final TopMenuItem item) {
final Anchor atag = anchor(item.getName(), item.getUrl()); final Anchor atag = anchor(item.getName(), item.getUrl());
atag.setTarget(item.getTarget()); atag.setTarget(item.getTarget());
if (item.getId() != null) {
atag.getElement().setAttribute("id", item.getId());
}
m.add(atag); m.add(atag);
} }
} }

View File

@@ -20,6 +20,7 @@ public class TopMenuItem extends JavaScriptObject {
public final native String getName() /*-{ return this.name; }-*/; public final native String getName() /*-{ return this.name; }-*/;
public final native String getUrl() /*-{ return this.url; }-*/; public final native String getUrl() /*-{ return this.url; }-*/;
public final native String getTarget() /*-{ return this.target; }-*/; public final native String getTarget() /*-{ return this.target; }-*/;
public final native String getId() /*-{ return this.id; }-*/;
protected TopMenuItem() { protected TopMenuItem() {
} }