From b9c8a1e40c71386b6811707c7cdf3610d13ab03c Mon Sep 17 00:00:00 2001 From: Luca Milanesio Date: Wed, 17 Sep 2014 09:01:36 +0100 Subject: [PATCH] Fix TopMenu extensions for the Project Menu items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../java/com/google/gerrit/client/Gerrit.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java index 491a539e36..bfe3d0bb31 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java @@ -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())) {