internal void BuildTreeNodes() { treeCategories.Clear(); allCategories = new Dictionary <string, IList <string> >(); List <string> rootCategories = new List <string>(); foreach (string imageName in ImageNames) { foreach (CategoryString category in Categories) { string categoryName = category.Name; IList <string> categoryContent; if (!allCategories.TryGetValue(categoryName, out categoryContent)) { categoryContent = new List <string>(); allCategories.Add(categoryName, categoryContent); } if (("_" + imageName + "_").Contains("_" + categoryName + "_")) { categoryContent.Add(imageName); } if (imageName.StartsWith(categoryName) && !rootCategories.Contains(categoryName)) { rootCategories.Add(categoryName); } } } List <string> simpleCategories = new List <string>(); foreach (KeyValuePair <string, IList <string> > category in allCategories) { if (category.Value.Count < 2) { simpleCategories.Add(category.Key); } } foreach (string category in simpleCategories) { CategoryString categoryString = null; foreach (CategoryString cat in Categories) { if (cat.Name == category) { categoryString = cat; break; } } Categories.Remove(categoryString); allCategories.Remove(category); if (rootCategories.Contains(category)) { rootCategories.Remove(category); } } ImagesGroupNode rootCategory = new ImagesGroupNode(this, null, ""); rootCategory.FillImageCategoriesTree(allCategories, ImageNames, rootCategories); ImageCategories.Add(rootCategory); }
internal void FillImageCategoriesTree(IDictionary <string, IList <string> > categories, List <string> imageNames, ICollection <string> currentLevelChildren) { List <string> nextLevelChildren = new List <string>(currentLevelChildren); if (ParentCategory != null && ParentCategory.ParentCategory == null) { nextLevelChildren = new List <string>(categories.Keys); } nextLevelChildren.Remove(Name); List <string> nextLevelImageTreeNodes = new List <string>(imageNames); Dictionary <string, List <string> > childCategoriesImageNames = new Dictionary <string, List <string> >(); foreach (string imageName in imageNames) { images.Add(new ImagePreviewObject(Owner, imageName)); foreach (string categoryName in nextLevelChildren) { if (categoryName != Name) { if (!childCategoriesImageNames.ContainsKey(categoryName)) { childCategoriesImageNames.Add(categoryName, new List <string>()); } if (categories[categoryName].Contains(imageName)) { childCategoriesImageNames[categoryName].Add(imageName); nextLevelImageTreeNodes.Remove(imageName); } } } } foreach (string childCategoryName in childCategoriesImageNames.Keys) { if (childCategoriesImageNames[childCategoryName].Count == 1) { if (!nextLevelImageTreeNodes.Contains(childCategoriesImageNames[childCategoryName][0])) { nextLevelImageTreeNodes.Add(childCategoriesImageNames[childCategoryName][0]); } } else if (childCategoriesImageNames[childCategoryName].Count > 1) { ImagesGroupNode childCategory = new ImagesGroupNode(Owner, this, childCategoryName); ChildCategories.Add(childCategory); childCategory.FillImageCategoriesTree(categories, childCategoriesImageNames[childCategoryName], nextLevelChildren); } } foreach (string nextLevelImageTreeNode in nextLevelImageTreeNodes) { ImageNode imageTreeNode = new ImageNode(Owner, nextLevelImageTreeNode); ChildCategories.Add(imageTreeNode); } }
public ImagesGroupNode(ImageSourceBrowserBase owner, ImagesGroupNode parent, string category) : base(owner, category) { ParentCategory = parent; }