// Copyright (C) 2010 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.client.account;

import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.api.ExtensionSettingsScreen;
import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.client.ui.MenuScreen;
import com.google.gerrit.common.PageLinks;

public abstract class SettingsScreen extends MenuScreen {
  public SettingsScreen() {
    setRequiresSignIn(true);

    link(Util.C.tabAccountSummary(), PageLinks.SETTINGS);
    link(Util.C.tabPreferences(), PageLinks.SETTINGS_PREFERENCES);
    link(Util.C.tabWatchedProjects(), PageLinks.SETTINGS_PROJECTS);
    link(Util.C.tabContactInformation(), PageLinks.SETTINGS_CONTACT);
    if (Gerrit.info().hasSshd()) {
      link(Util.C.tabSshKeys(), PageLinks.SETTINGS_SSHKEYS);
    }
    if (Gerrit.info().auth().isHttpPasswordSettingsEnabled()) {
      link(Util.C.tabHttpAccess(), PageLinks.SETTINGS_HTTP_PASSWORD);
    }
    link(Util.C.tabWebIdentities(), PageLinks.SETTINGS_WEBIDENT);
    link(Util.C.tabMyGroups(), PageLinks.SETTINGS_MYGROUPS);
    if (Gerrit.info().auth().useContributorAgreements()) {
      link(Util.C.tabAgreements(), PageLinks.SETTINGS_AGREEMENTS);
    }

    for (String pluginName : ExtensionSettingsScreen.Definition.plugins()) {
      for (ExtensionSettingsScreen.Definition def :
          Natives.asList(ExtensionSettingsScreen.Definition.get(pluginName))) {
        link(def.getMenu(), PageLinks.toSettings(pluginName, def.getPath()));
      }
    }
  }

  @Override
  protected void onInitUI() {
    super.onInitUI();
    setPageTitle(Util.C.settingsHeading());
  }
}

@@ -882,16 +882,65 @@
 Links;%0A%0A
+import java.util.HashSet;%0Aimport java.util.Set;%0A%0A
 public a
@@ -996,71 +996,249 @@
 %0A  p
-ublic SettingsScreen() %7B%0A    setRequiresSignIn(true);%0A%0A    link
+rivate final Set%3CString%3E allMenuNames;%0A  private final Set%3CString%3E ambiguousMenuNames;%0A%0A  public SettingsScreen() %7B%0A    setRequiresSignIn(true);%0A%0A    allMenuNames = new HashSet%3C%3E();%0A    ambiguousMenuNames = new HashSet%3C%3E();%0A%0A    linkByGerrit
 (Uti
@@ -1283,32 +1283,40 @@
 TINGS);%0A    link
+ByGerrit
 (Util.C.tabPrefe
@@ -1358,32 +1358,40 @@
 ENCES);%0A    link
+ByGerrit
 (Util.C.tabWatch
@@ -1434,32 +1434,40 @@
 JECTS);%0A    link
+ByGerrit
 (Util.C.tabConta
@@ -1549,32 +1549,40 @@
 ()) %7B%0A      link
+ByGerrit
 (Util.C.tabSshKe
@@ -1688,32 +1688,40 @@
 ()) %7B%0A      link
+ByGerrit
 (Util.C.tabHttpA
@@ -1770,32 +1770,40 @@
 ;%0A    %7D%0A    link
+ByGerrit
 (Util.C.tabWebId
@@ -1844,32 +1844,40 @@
 IDENT);%0A    link
+ByGerrit
 (Util.C.tabMyGro
@@ -1982,16 +1982,24 @@
     link
+ByGerrit
 (Util.C.
@@ -2275,13 +2275,364 @@
     
-link(
+if (!allMenuNames.add(def.getMenu())) %7B%0A          ambiguousMenuNames.add(def.getMenu());%0A        %7D%0A      %7D%0A    %7D%0A%0A    for (String pluginName : ExtensionSettingsScreen.Definition.plugins()) %7B%0A      for (ExtensionSettingsScreen.Definition def :%0A          Natives.asList(ExtensionSettingsScreen.Definition.get(pluginName))) %7B%0A        linkByPlugin(pluginName, 
 def.
@@ -2641,16 +2641,28 @@
 tMenu(),
+%0A           
  PageLin
@@ -2723,16 +2723,326 @@
  %7D%0A  %7D%0A%0A
+  private void linkByGerrit(String text, String target) %7B%0A    allMenuNames.add(text);%0A    link(text, target);%0A  %7D%0A%0A  private void linkByPlugin(String pluginName, String text, String target) %7B%0A    if (ambiguousMenuNames.contains(text)) %7B%0A      text += %22 (%22+ pluginName + %22)%22;%0A    %7D%0A    link(text, target);%0A  %7D%0A%0A
   @Overr

Include plugin name into ambiguous user settings menu names