Menu CreateMenu(bool importantOnly) { if (TagModel != null) { Menu menu = new Menu(); bool itemsAdded = false; bool needsSeparator = false; foreach (StringTagDescription[] tags in TagModel.GetTagsGrouped()) { itemsAdded = false; foreach (StringTagDescription tag in tags) { if (tag.Important != importantOnly) { continue; } if (itemsAdded && needsSeparator) { SeparatorMenuItem sep = new SeparatorMenuItem(); needsSeparator = false; menu.Add(sep); } MenuItem item = new MenuItem(tag.Description); string tagString = tag.Name; item.ButtonPressEvent += delegate { InsertTag(tagString); }; menu.Add(item); itemsAdded = true; } needsSeparator = true; } if (importantOnly) { Menu subMenu = CreateMenu(false); if (subMenu.Children.Length > 0) { SeparatorMenuItem sep = new SeparatorMenuItem(); menu.Add(sep); MenuItem item = new MenuItem(GettextCatalog.GetString("More")); item.Submenu = subMenu; menu.Add(item); } } menu.ShowAll(); return(menu); } return(null); }
ContextMenu CreateMenu(bool importantOnly) { ContextMenu menu = new ContextMenu(); bool itemsAdded = false; bool needsSeparator = false; foreach (StringTagDescription[] tags in TagModel.GetTagsGrouped()) { itemsAdded = false; foreach (StringTagDescription tag in tags) { if (tag.Important != importantOnly) { continue; } if (itemsAdded && needsSeparator) { var sep = new SeparatorContextMenuItem(); needsSeparator = false; menu.Add(sep); } var item = new ContextMenuItem(tag.Description); string tagString = tag.Name; item.Clicked += delegate { InsertTag(tagString); }; menu.Add(item); itemsAdded = true; } needsSeparator = true; } if (importantOnly) { var subMenu = CreateMenu(false); if (subMenu.Items.Count > 0) { var sep = new SeparatorContextMenuItem(); menu.Add(sep); var item = new ContextMenuItem(GettextCatalog.GetString("More")); item.SubMenu = subMenu; menu.Add(item); } } return(menu); }