private void tvwLibraryFolders_ItemExpanded(object sender, RoutedEventArgs e) { TreeViewItem item = e.OriginalSource as TreeViewItem; if (item != null) { if ((item.Items.Count == 1) && (((TreeViewItem)item.Items[0]).Header is DummyTreeItem)) { tvwLibraryFolders.Cursor = Cursors.Wait; item.Items.Clear(); LibraryFolder aFolder = item.Header as LibraryFolder; VirtualFolder vf = new VirtualFolder(aFolder.FullPath); Async.Queue("LibraryFoldersExpand", () => { foreach (string folder in vf.Folders) { getLibrarySubDirectories(folder, item); } }, () => { Dispatcher.Invoke(DispatcherPriority.Background, (System.Windows.Forms.MethodInvoker)(() => { tvwLibraryFolders.Cursor = Cursors.Hand; })); }); } } }
private void RefreshItems() { folderList.Items.Clear(); List<VirtualFolder> vfs = new List<VirtualFolder>(); int i = 0; //use this to fill in sortorder if not there foreach (var filename in Directory.GetFiles(config.InitialFolder)) { try { if (filename.ToLowerInvariant().EndsWith(".vf") || filename.ToLowerInvariant().EndsWith(".lnk")) { //add to our sorted list VirtualFolder vf = new VirtualFolder(filename); if (vf.SortName == null) { //give it a sortorder if its not there vf.SortName = i.ToString("D3"); vf.Save(); } vfs.Add(vf); i = i + 10; } //else // throw new ArgumentException("Invalid virtual folder file extension: " + filename); } catch (ArgumentException) { Logger.ReportWarning("Ignored file: " + filename); } catch (Exception e) { MessageBox.Show("Invalid file detected in the initial folder!" + e.ToString()); // TODO : alert about dodgy VFs and delete them } } vfs.Sort((a,b) => a.SortName.CompareTo(b.SortName)); //now add our items in sorted order foreach (VirtualFolder v in vfs) folderList.Items.Add(v); }