// 递归查询生成菜单 // 这个写法在本应用中影响不大,毕竟菜单较少 // 在大型项目中,这个肯定不可取 // 大型项目要么异步加载菜单,要么一次全部提取后在应用中还原成树结构 private async Task <MenuDataItem[]> CreateMenu(MenuDataItem parent, int depth) { string _parent = (parent == null) ? "0" : parent.Key; List <MenuDataItem> items = new List <MenuDataItem>(); List <SFunctionEntity> roots = await service.ListByParentAsync(_parent); foreach (var r in roots) { MenuDataItem mi = CreateMenuItem(r); // 当前节点不是叶子节点,并且小于最大递归深度 if (!r.Leaf && depth < _maxDepth) { MenuDataItem[] children = await CreateMenu(mi, depth + 1); if (children.Any()) { mi.Children = children; } } items.Add(mi); } return(items.ToArray()); }
public virtual void PopulateMenu <T>() where T : IMenuItem, new() { ItemCount = data.Count; for (int Idx = 0; Idx < data.Count; Idx++) { IMenuItem _mi = new T(); MenuDataItem mdi = data[Idx]; //SavedGame.ScrollIdx = Idx; MenuItems.Add(_mi); //Initialize the item _mi.ContainingMenu = this; _mi.CreateGameObjects(mdi.Name, mdi.Type); _mi.OuterGameObject.name = "Menu_" + mdi.Name; _mi.Initialize(); Transform trSavedItem = _mi.OuterGameObject.transform; trSavedItem.SetParent(this.transform); _mi.Id = Idx; if (_mi.Id == 0) { trSavedItem.localPosition = Vector3.up * 3; trSavedItem.Rotate(10, -60, 0); } else { trSavedItem.localPosition = Vector3.right * (10 + _mi.Id * 5); } trSavedItem.Rotate(0, -90, 0); } }
private MenuDataItem CreateMenuItem(SFunctionEntity f) { MenuDataItem m = new MenuDataItem(); m.Key = f.Id; m.Name = f.Name; m.Path = f.Path; m.Icon = f.Icon; return(m); }
public override void GetData() { data = new List <IMenuDataItem>(); if (SaveLoadModel.savedGames.Count == 0) { GetDemoTrack(); //First time - put in the demo track } foreach (Game g in SaveLoadModel.savedGames) { MenuDataItem i = new MenuDataItem { Id = g.GameId, Name = g.Filename, IsMine = g.IsMine }; data.Add(g); } }
/// <summary> /// Recursively finds menu item to navigate to when a button is clicked on the UI. /// </summary> /// <param name="items">Collection of menu items.</param> /// <param name="stringToMatch">Item to search for in menu items collection.</param> /// <param name="item">Returns a menu item.</param> private void GetMenuDataItem(ObservableCollection<MenuDataItem> items, string stringToMatch, ref MenuDataItem item) { for (int i = 0; i < items.Count; i++) { if (items[i].MenuText.Contains(stringToMatch)) { item = items[i]; break; } else { if (items[i].SubMenuItems.Count > 0) { GetMenuDataItem(items[i].SubMenuItems, stringToMatch, ref item); } } } }
/// <summary> /// Handles click event of the buttons on the screen. /// </summary> /// <param name="sender">Source of the event.</param> /// <param name="e">Event arguments.</param> private void Button_Click(object sender, RoutedEventArgs e) { MenuDataItem item = new MenuDataItem(); FrameworkElement source = e.Source as FrameworkElement; switch (source.Name) { case "ButtonSecurity": GetMenuDataItem(m_menuDataItems, "Security", ref item); break; default: break; } if (item.MenuText != null) { item.Command.Execute(null); } }
private void ButtonQuickLink_Click(object sender, RoutedEventArgs e) { MenuDataItem item = new MenuDataItem(); string stringToMatch = ((Button)sender).Tag.ToString(); if (!string.IsNullOrEmpty(stringToMatch)) { if (stringToMatch == "Restart") { RestartService(); } else { GetMenuDataItem(m_menuDataItems, stringToMatch, ref item); if ((object)item.MenuText != null) { item.Command.Execute(null); } } } }
public virtual List <MenuDataItem> GetMenuDataItemByUserId(string systemName, string userId) { List <MenuDataItem> menuDataItemList = new List <MenuDataItem>(); SecPageEntity SecPageEntity = new SecPageEntity(); SecPageEntity.PageId = eContract.Common.Const.SysConst.C_Root_Parent_ID; SecPageEntity.SystemName = systemName; PageDomain baseDomain = new PageDomain(SecPageEntity); Dictionary <string, List <SecPageControlEntity> > allPageControls = SystemService.PageService.GetPageControls(0); foreach (PageDomain pageDomain in baseDomain.ChildsDomain) { if (GetPageIds(userId, systemName).Contains(pageDomain.SecPageEntity.PageId)) { MenuDataItem rootMenuDataItem = new MenuDataItem(pageDomain.SecPageEntity, null, null); Bind(systemName, rootMenuDataItem, pageDomain, userId, allPageControls); menuDataItemList.Add(rootMenuDataItem); } } return(menuDataItemList); }
MenuDataItem GetPage(List <MenuDataItem> menus, string pageName, bool isShopPage) { if (menus == null) { return(null); } foreach (MenuDataItem item in menus) { string itemPageName = item.Page.PageName; if (itemPageName == pageName) { return(item); } else { MenuDataItem page = GetPage(item.SubMenu, pageName, isShopPage); if (page != null) { return(page); } } } return(null); }
private MenuDataItem[] GetMenuDataItems(ApplicationMenuItemList menuItems) { if (menuItems != null && menuItems.Count > 0) { MenuDataItem[] antMenuItems; antMenuItems = new MenuDataItem[menuItems.Count]; for (int i = 0; i < antMenuItems.Length; i++) { MenuDataItem item = new MenuDataItem(); item.Path = menuItems[i].Url; item.Name = menuItems[i].DisplayName; item.Key = menuItems[i].Name; item.Icon = menuItems[i].Icon; antMenuItems[i] = item; if (menuItems[i].Items != null && menuItems[i].Items.Count > 0) { antMenuItems[i].Children = GetMenuDataItems(menuItems[i].Items); } } return(antMenuItems); } return(null); }
private void Bind(string systemName, MenuDataItem rootMenuDataItem, PageDomain pageDomain, string userId, Dictionary <string, List <SecPageControlEntity> > allPageControls) { foreach (PageDomain page in pageDomain.ChildsDomain) { if (GetPageIds(userId, systemName).Contains(page.SecPageEntity.PageId)) { List <SecPageControlEntity> controls = null; if (allPageControls.ContainsKey(page.SecPageEntity.PageId)) { controls = allPageControls[page.SecPageEntity.PageId]; } MenuDataItem childMenuDataItem = new MenuDataItem(page.SecPageEntity, rootMenuDataItem, controls); //foreach (PermissionDomain permissionDomain in page.PermissionDomainList) //{ // if (GetPermissionIds(userId).Contains(permissionDomain.SecPermissionEntity.PermissionId)) // { // childMenuDataItem.ValidControls.Add(permissionDomain.SecPermissionEntity); // } //} Bind(systemName, childMenuDataItem, page, userId, allPageControls); rootMenuDataItem.SubMenu.Add(childMenuDataItem); } } }
/// <summary> /// Recursively finds menu item to navigate to when a button is clicked on the UI. /// </summary> /// <param name="items">Collection of menu items.</param> /// <param name="stringToMatch">Item to search for in menu items collection.</param> /// <param name="item">Returns a menu item.</param> private void GetMenuDataItem(ObservableCollection <MenuDataItem> items, string stringToMatch, ref MenuDataItem item) { for (int i = 0; i < items.Count; i++) { if (items[i].UserControlPath.ToLower() == stringToMatch.ToLower()) { item = items[i]; break; } if (items[i].SubMenuItems.Count > 0) { GetMenuDataItem(items[i].SubMenuItems, stringToMatch, ref item); } } }
private void DoNavigation(MenuDataItem module) { NavigationService.Navigate(module.ModuleType.ToString()); }
/// <summary> /// Recursively finds menu item to navigate to when a button is clicked on the UI. /// </summary> /// <param name="items">Collection of menu items.</param> /// <param name="stringToMatch">Item to search for in menu items collection.</param> /// <param name="item">Returns a menu item.</param> private void GetMenuDataItem(ObservableCollection <MenuDataItem> items, string stringToMatch, ref MenuDataItem item) { for (int i = 0; i < items.Count; i++) { if (items[i].MenuText.Contains(stringToMatch)) { item = items[i]; break; } else { if (items[i].SubMenuItems.Count > 0) { GetMenuDataItem(items[i].SubMenuItems, stringToMatch, ref item); } } } }