void InitializeToolBarItems() { if (!(guidToGroups is null)) { return; } var dict = new Dictionary <Guid, Dictionary <string, ToolBarItemGroupMD> >(); foreach (var md in GetToolBarItemMDs()) { string ownerGuidString; ownerGuidString = md.Metadata.OwnerGuid ?? ToolBarConstants.APP_TB_GUID; bool b = Guid.TryParse(ownerGuidString, out var ownerGuid); Debug.Assert(b, $"ToolBarItem: Couldn't parse OwnerGuid property: '{ownerGuidString}'"); if (!b) { continue; } b = !string.IsNullOrEmpty(md.Metadata.Group); Debug.Assert(b, "ToolBarItem: Group property is empty or null"); if (!b) { continue; } b = Menus.MenuService.ParseGroup(md.Metadata.Group !, out double groupOrder, out string groupName); Debug.Assert(b, "ToolBarItem: Group property must be of the format \"<order>,<name>\" where <order> is a System.Double"); if (!b) { continue; } if (!dict.TryGetValue(ownerGuid, out var groupDict)) { dict.Add(ownerGuid, groupDict = new Dictionary <string, ToolBarItemGroupMD>()); } if (!groupDict.TryGetValue(groupName, out var mdGroup)) { groupDict.Add(groupName, mdGroup = new ToolBarItemGroupMD(groupOrder)); } Debug.Assert(mdGroup.Order == groupOrder, $"ToolBarItem: Group order is different: {mdGroup.Order} vs {groupOrder}"); mdGroup.Items.Add(md); } guidToGroups = new Dictionary <Guid, List <ToolBarItemGroupMD> >(); foreach (var kv in dict) { var groups = new List <ToolBarItemGroupMD>(kv.Value.Select(a => a.Value).OrderBy(a => a.Order)); foreach (var g in groups) { g.Items.Sort((a, b) => a.Metadata.Order.CompareTo(b.Metadata.Order)); } guidToGroups.Add(kv.Key, groups); } }
void InitializeToolBarItems() { if (guidToGroups != null) return; var dict = new Dictionary<Guid, Dictionary<string, ToolBarItemGroupMD>>(); foreach (var md in GetToolBarItemMDs()) { string ownerGuidString, groupName; double groupOrder; ownerGuidString = md.Metadata.OwnerGuid ?? ToolBarConstants.APP_TB_GUID; Guid ownerGuid; bool b = Guid.TryParse(ownerGuidString, out ownerGuid); Debug.Assert(b, string.Format("ToolBarItem: Couldn't parse OwnerGuid property: '{0}'", ownerGuidString)); if (!b) continue; b = !string.IsNullOrEmpty(md.Metadata.Group); Debug.Assert(b, "ToolBarItem: Group property is empty or null"); if (!b) continue; b = Menus.MenuManager.ParseGroup(md.Metadata.Group, out groupOrder, out groupName); Debug.Assert(b, "ToolBarItem: Group property must be of the format \"<order>,<name>\" where <order> is a System.Double"); if (!b) continue; Dictionary<string, ToolBarItemGroupMD> groupDict; if (!dict.TryGetValue(ownerGuid, out groupDict)) dict.Add(ownerGuid, groupDict = new Dictionary<string, ToolBarItemGroupMD>()); ToolBarItemGroupMD mdGroup; if (!groupDict.TryGetValue(groupName, out mdGroup)) groupDict.Add(groupName, mdGroup = new ToolBarItemGroupMD(groupOrder)); Debug.Assert(mdGroup.Order == groupOrder, string.Format("ToolBarItem: Group order is different: {0} vs {1}", mdGroup.Order, groupOrder)); mdGroup.Items.Add(md); } guidToGroups = new Dictionary<Guid, List<ToolBarItemGroupMD>>(); foreach (var kv in dict) { var groups = new List<ToolBarItemGroupMD>(kv.Value.Select(a => a.Value).OrderBy(a => a.Order)); foreach (var g in groups) g.Items.Sort((a, b) => a.Metadata.Order.CompareTo(b.Metadata.Order)); guidToGroups.Add(kv.Key, groups); } }