Fix TopMenu extensions for the Project Menu items

The behaviour of TopMenu extensions to the TopMenu projects menubar
was broken after the extension of “Project-aware” menu items I516f129dc
Even project agnostic items were incorrectly processed as
project-specific causing them to be hidden when there was no active
project selected.

The issue has been discussed on the mailing list (see [1]) and 
acknowledged to be a regression to be fixed. Issue can be easily 
reproduced looking at the cookbook-plugin: “Browse Repositories” 
TopMenu entry is hidden whilst it should be normally shown.
[1] https://groups.google.com/forum/#!topic/repo-discuss/nFBQFc0MS6E

Change-Id: I8adb59ddda3cae6fc5819c525580096002377c5b
This commit is contained in:
Luca Milanesio
2014-09-17 09:01:36 +01:00
parent b7fa82eeed
commit b9c8a1e40c

View File

@@ -103,6 +103,7 @@ public class Gerrit implements EntryPoint {
public static final SystemInfoService SYSTEM_SVC;
public static final EventBus EVENT_BUS = GWT.create(SimpleEventBus.class);
public static Themer THEMER = GWT.create(Themer.class);
public static final String PROJECT_NAME_MENU_VAR = "${projectName}";
private static String myHost;
private static GerritConfig myConfig;
@@ -773,15 +774,10 @@ public class Gerrit implements EntryPoint {
for (TopMenu menu : topMenuExtensions) {
String name = menu.getName();
LinkMenuBar existingBar = menuBars.get(name);
LinkMenuBar bar = existingBar != null ? existingBar : new LinkMenuBar();
if (GerritTopMenu.PROJECTS.menuName.equals(name)) {
for (TopMenuItem item : Natives.asList(menu.getItems())) {
addProjectLink(bar, item);
}
} else {
for (TopMenuItem item : Natives.asList(menu.getItems())) {
addExtensionLink(bar, item);
}
LinkMenuBar bar =
existingBar != null ? existingBar : new LinkMenuBar();
for (TopMenuItem item : Natives.asList(menu.getItems())) {
addMenuLink(bar, item);
}
if (existingBar == null) {
menuBars.put(name, bar);
@@ -909,7 +905,7 @@ public class Gerrit implements EntryPoint {
@Override
protected void onScreenLoad(Project.NameKey project) {
String p =
panel.replace("${projectName}",
panel.replace(PROJECT_NAME_MENU_VAR,
URL.encodeQueryString(project.get()));
if (!panel.startsWith("/x/") && !isAbsolute(panel)) {
UrlBuilder builder = new UrlBuilder();
@@ -969,6 +965,14 @@ public class Gerrit implements EntryPoint {
m.add(atag);
}
private static void addMenuLink(LinkMenuBar m, TopMenuItem item) {
if (item.getUrl().contains(PROJECT_NAME_MENU_VAR)) {
addProjectLink(m, item);
} else {
addExtensionLink(m, item);
}
}
private static void addExtensionLink(LinkMenuBar m, TopMenuItem item) {
if (item.getUrl().startsWith("#")
&& (item.getTarget() == null || item.getTarget().isEmpty())) {