public FormGroupsDictionaryViewer(IEnumerable <IGrouping <string, FileItem> > sourceDict) { InitializeComponent(); _sourceDictionary = FolderTreeItemsGrouping <string> .CreateDictionary(sourceDict); if (_sourceDictionary.Count == 0) { MessageBox.Show("No groups to display!"); Close(); return; } FillGroupsList(); }
private void UpdateItemsText() { textBoxItems.Text = ""; if (listBoxItems.SelectedItems.Count < 1) { SetCountersStatus(0, 0, 0, 0); return; } SetStatus("Reading group items..."); var pathsList = new List <string>(); var s = new StringBuilder(); FolderTreeItemsGrouping <string> itemsGroup; //Test if only one group is selected if (listBoxItems.SelectedItems.Count == 1) { itemsGroup = SelectedItemIndexToGroup(0); } else { //Multiple groups selected //Create a copy of the first selected group itemsGroup = FolderTreeItemsGrouping <string> .CreateCopy(SelectedItemIndexToGroup(0)); //Merge the data of the remaining groups into the copy of the first selected group for (var i = 1; i < listBoxItems.SelectedItems.Count; i++) { itemsGroup = itemsGroup.MergeItems(SelectedItemIndexToGroup(i)); } } var filesCount = itemsGroup.FilesCount; var foldersCount = itemsGroup.FoldersCount; var parentFoldersCount = itemsGroup.ParentFoldersCount; if (checkBoxShowParentFolders.Checked) { pathsList.AddRange(itemsGroup.ParentFolders().Select(item => item.ItemPath)); } if (checkBoxShowFolders.Checked) { pathsList.AddRange(itemsGroup.Folders().Select(item => item.ItemPath)); } if (checkBoxShowFiles.Checked) { pathsList.AddRange(itemsGroup.Files().Select(item => item.ItemPath)); } pathsList.Sort(); //Write the data of the group to the string builder s.Append("group <"); s.Append(itemsGroup.Key); s.AppendLine(">"); s.AppendLine("{"); if (pathsList.Count > 0) { foreach (var path in pathsList) { s.Append(" ").AppendLine(path); } } s.AppendLine("}"); s.AppendLine(); textBoxItems.Text = s.ToString(); SetCountersStatus(listBoxItems.SelectedItems.Count, filesCount, foldersCount, parentFoldersCount); SetStatus("Ready"); }