final JsArray<Scope> funcs,
String indent,
Scope defaultFunction,
boolean includeNoFunctionsMessage)
{
MenuItem defaultMenuItem = null;
if (funcs.length() == 0 && includeNoFunctionsMessage)
{
String type = fileType_.canExecuteChunks() ? "chunks" : "functions";
MenuItem noFunctions = new MenuItem("(No " + type + " defined)",
false,
(Command) null);
noFunctions.setEnabled(false);
noFunctions.getElement().addClassName("disabled");
menu.addItem(noFunctions);
}
for (int i = 0; i < funcs.length(); i++)
{
final Scope func = funcs.get(i);
String childIndent = indent;
if (!StringUtil.isNullOrEmpty(func.getLabel()))
{
SafeHtmlBuilder labelBuilder = new SafeHtmlBuilder();
labelBuilder.appendHtmlConstant(indent);
labelBuilder.appendEscaped(func.getLabel());
final MenuItem menuItem = new MenuItem(
labelBuilder.toSafeHtml(),
new Command()
{
public void execute()
{
docDisplay_.navigateToPosition(toSourcePosition(func),
true);
}
});
menu.addItem(menuItem);
childIndent = indent + " ";
if (defaultFunction != null && defaultMenuItem == null &&
func.getLabel().equals(defaultFunction.getLabel()) &&
func.getPreamble().getRow() == defaultFunction.getPreamble().getRow() &&
func.getPreamble().getColumn() == defaultFunction.getPreamble().getColumn())
{
defaultMenuItem = menuItem;
}
}
MenuItem childDefaultMenuItem = addFunctionsToMenu(
menu,
func.getChildren(),
childIndent,
defaultMenuItem == null ? defaultFunction : null,
false);