private void Create(bool isFile, IDirectoryViewModel parent, string path) { int index = 0; if (isFile) { if (parent == null) { return; } if (!parent.Files.IsLoaded) { return; } string name = Path.GetFileName(path); for (int i = 0; i < parent.Files.Count; i++) { var file = parent.Files[i]; if (string.Compare(name, file.DisplayName, StringComparison.OrdinalIgnoreCase) < 0) { index = i; break; } } parent.Files.Insert(index, new FileViewModel(new FileInfo(path), parent)); } else { if (parent != null) { if (parent.SubDirectories.IsLoaded) { string name = Path.GetDirectoryName(path); for (int i = 0; i < parent.SubDirectories.Count; i++) { var directory = parent.SubDirectories[i]; if (String.Compare(name, directory.DisplayName, StringComparison.OrdinalIgnoreCase) < 0) { index = i; break; } } var newDirectory = new DirectoryViewModel(new DirectoryInfo(path), parent); parent.SubDirectories.Insert(index, newDirectory); AddDirectoryToWatch(newDirectory); } else { parent.UpdateHasItems(); } return; } } }
private void Delete(bool isFile, IDirectoryViewModel parent, IDirectoryViewModel child, string path) { int index; if (isFile) { if (parent != null) { if (parent.Files.IsLoaded) { index = FindFileIndex(parent, path); parent.Files.Remove(parent.Files[index]); } } } else { if (child == null) { if (parent != null) { parent.UpdateHasItems(); return; } return; } string selectedPathDirectory = PathHelper.NormalizePath(Top.SelectedDirectory.Path); string deletedPath = PathHelper.NormalizePath(path); if (PathHelper.Contains(selectedPathDirectory, deletedPath)) { Top.SelectedDirectory = child.Parent; } child.Parent.SubDirectories.Remove(child); DeleteFileSystemWatcher(child); } }
private void Create(bool isFile, IDirectoryViewModel parent, string path) { int index = 0; if (isFile) { if (parent == null) return; if (!parent.Files.IsLoaded) return; string name = Path.GetFileName(path); for (int i = 0; i < parent.Files.Count; i++) { var file = parent.Files[i]; if (string.Compare(name, file.DisplayName, StringComparison.OrdinalIgnoreCase) < 0) { index = i; break; } } parent.Files.Insert(index, new FileViewModel(new FileInfo(path), parent)); } else { if (parent != null) { if (parent.SubDirectories.IsLoaded) { string name = Path.GetDirectoryName(path); for (int i = 0; i < parent.SubDirectories.Count; i++) { var directory = parent.SubDirectories[i]; if (String.Compare(name, directory.DisplayName, StringComparison.OrdinalIgnoreCase) < 0) { index = i; break; } } var newDirectory = new DirectoryViewModel(new DirectoryInfo(path), parent); parent.SubDirectories.Insert(index, newDirectory); AddDirectoryToWatch(newDirectory); } else { parent.UpdateHasItems(); } return; } } }