private void OnChanged(RxListChange <object> changes) { lock (locker) { if (changeMode == DbChangeMode.Load) { return; } changeMode = DbChangeMode.Save; try { foreach (var added in changes.Added) { for (var i = ItemNodes.Count - 1; i >= added.Index; i--) { ItemNodes[i].Directory.MoveTo(Path.Combine(Directory.FullName, i.ToString())); } ItemNodes.Insert(added.Index, new DbObjectNode(Database, (IRxObject)added.Value, new DirectoryInfo(Path.Combine(Directory.FullName, added.Value.ToString())))); } } finally { changeMode = DbChangeMode.None; } } }
public void AdjustNodePosition(Item item) { var nodes = ItemNodes.Where(x => x.Item == item); var foundCurrent = false; foreach (var node in nodes.ToList()) { if (node.Path.Equals(item.Path)) { foundCurrent = true; node.IsShadow = false; TreeListViewService.RefreshNode(node); continue; } if (node.Path.Equals(item.OriginalPath)) { node.IsShadow = true; TreeListViewService.RefreshNode(node); continue; } if (node.Parent is FolderTreeItem folder) { folder.SubItems.Remove(node); TreeListViewService.RefreshNode(folder); } else { Source.Remove(node); } ItemNodes.Remove(node); } if (!foundCurrent) { var rootFolders = Source.Select(x => x is FolderTreeItem folder ? folder : null).Where(x => x != null).ToList(); var parent = ProcessPath(item.Path.Trim(Path.DirectorySeparatorChar), rootFolders, null); foreach (var folder in rootFolders) { if (!Source.Contains(folder)) { Source.Add(folder); } } var itemNode = new ItemTreeItem(item, parent); ItemNodes.Add(itemNode); parent.SubItems.Add(itemNode); TreeListViewService.RefreshNode(parent); } }
public async Task RebuildNodes(IEnumerable <Item> items) { var nodes = await Task.Run(() => { var folders = new List <FolderTreeItem>(); foreach (var unit in items) { var parent = ProcessPath(unit.Path.Trim(Path.DirectorySeparatorChar), folders, null); var itemNode = new ItemTreeItem(unit, parent); ItemNodes.Add(itemNode); parent.SubItems.Add(itemNode); } return(folders); }); Source.Clear(); foreach (var folderTreeItem in nodes) { Source.Add(folderTreeItem); } }
protected override void OnFileSystemChanged(FileSystemEventArgs args) { base.OnFileSystemChanged(args); lock (locker) { changeMode = DbChangeMode.Load; try { if (args.FullPath != Directory.FullName) { var relativePath = args.FullPath.Substring(Directory.FullName.Length).TrimStart(Path.DirectorySeparatorChar); var parts = relativePath.Split(Path.DirectorySeparatorChar); if (parts.Length == 1) { switch (args.ChangeType) { case WatcherChangeTypes.Created: int index; if (int.TryParse(relativePath, out index)) { if (index >= ItemNodes.Count || ItemNodes[index] == null) { var obj = (IRxObject)Activator.CreateInstance(MetaData.ElementType); var node = new DbObjectNode(Database, obj, new DirectoryInfo(Path.Combine(Directory.FullName, index.ToString()))); while (index > ItemNodes.Count) { ItemNodes.Add(null); } while (index > List.Count) { List.Add(null); } if (index < ItemNodes.Count) { ItemNodes[index] = node; } else { ItemNodes.Add(node); } if (index < List.Count) { List[index] = obj; } else { List.Add(obj); } } } break; } } } } finally { changeMode = DbChangeMode.None; } } }