public void Load() { Items.Clear(); AllFolderKeywords.Clear(); Dictionary<int, string> paths = new Dictionary<int, string>(); foreach (var dir in ACore.Db.Directories.OrderBy(x => x.Path)) { if (!Directory.Exists(dir.Path)) continue; if (!ACore.CanViewerSeeThisDirectory(dir.Path)) continue; var path = GetFolderKeywordKeyPath(dir.Path); if (string.IsNullOrEmpty(path)) continue; paths.Add(dir.Id, path); } foreach (var keyPath in paths.Select(p => p.Value).Distinct().OrderBy(p => p)) { FolderKeyword newItem = new FolderKeyword { IconName = "appbar_folder", FullPath = keyPath, FolderIdList = paths.Where(p => p.Value.Equals(keyPath)).Select(p => p.Key).ToList() }; if (!newItem.FullPath.Contains("\\")) { newItem.Title = newItem.FullPath; Items.Add(newItem); AllFolderKeywords.Add(newItem); } else { newItem.Title = newItem.FullPath.Substring(newItem.FullPath.LastIndexOf('\\') + 1); FolderKeyword parentFolderKeyword = GetFolderKeywordByKeyPath(newItem.FullPath.Substring(0, newItem.FullPath.LastIndexOf('\\')), true); if (parentFolderKeyword == null) continue; newItem.Parent = parentFolderKeyword; parentFolderKeyword.Items.Add(newItem); AllFolderKeywords.Add(newItem); } } }
public FolderKeyword CreateFolderKeyword(ObservableCollection<BaseTreeViewItem> root, FolderKeyword parent, string name) { string kFullPath = parent == null ? name : $"{parent.FullPath}/{name}"; FolderKeyword newFolderKeyword = new FolderKeyword { IconName = "appbar_folder", FullPath = kFullPath, Title = name, Parent = parent }; root.Add(newFolderKeyword); return newFolderKeyword; }