/// <summary> /// Transforms an array of strings into an array of viewmodel items /// Drive 'C:\' , 'Folder', 'SubFolder', etc... /// and returns these items, or null, if path verified (path is invalid, does not exist etc). /// </summary> /// <param name="parent">The parent item under which all other parent items /// are to be displayed. Caller must ensure that parent item exists and is visible /// in the current structure, before calling this method.</param> /// <param name="folders">array of strings indicating folder parts to return /// viewmodel items for.</param> /// <returns>An array of viewmodel items or null.</returns> private ITreeItemViewModel[] NavigatePath( ITreeItemViewModel parent , string[] folders) { int iMatchIdx = 0; ITreeItemViewModel[] pathFolders = new ITreeItemViewModel[folders.Count()]; pathFolders[0] = parent; int iNext = iMatchIdx + 1; for (; iNext < folders.Count(); iNext++) { if (parent.HasDummyChild == true) { parent.ChildrenLoad(); } var nextChild = parent.ChildTryGet(folders[iNext]); if (nextChild != null) { pathFolders[iNext] = nextChild; parent = nextChild; } else { return(null); // could not find target } } return(pathFolders); }
/// <summary> /// Add a new folder indicated by <paramref name="dir"/> as path /// into the sub-folder viewmodel collection of this folder item. /// </summary> /// <param name="dir"></param> /// <param name="parentItem"></param> /// <returns></returns> internal static TreeItemViewModel AddFolder(string dir, ITreeItemViewModel parentItem) { try { DirectoryInfo di = new DirectoryInfo(dir); // create the sub-structure only if this is not a hidden directory // if ((di.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) // { var newFolder = new FolderViewModel(dir, parentItem); parentItem.ChildAdd(newFolder); return(newFolder); // } } catch (UnauthorizedAccessException ae) { parentItem.ShowNotification(FileSystemModels.Local.Strings.STR_MSG_UnknownError, ae.Message); } catch (Exception e) { parentItem.ShowNotification(FileSystemModels.Local.Strings.STR_MSG_UnknownError, e.Message); } return(null); }
/// <summary> /// Load all sub-folders into the Folders collection of the /// given <paramref name="parentItem"/>. /// </summary> /// <param name="parentItem"></param> internal static void LoadFolders(ITreeItemViewModel parentItem) { try { parentItem.ChildrenClear(); foreach (string dir in Directory.GetDirectories(parentItem.ItemPath)) { try { FolderViewModel.AddFolder(dir, parentItem); } catch (UnauthorizedAccessException ae) { parentItem.ShowNotification(FileSystemModels.Local.Strings.STR_MSG_UnknownError, ae.Message); } catch (IOException ie) { parentItem.ShowNotification(FileSystemModels.Local.Strings.STR_MSG_UnknownError, ie.Message); } } } catch (UnauthorizedAccessException ae) { parentItem.ShowNotification(FileSystemModels.Local.Strings.STR_MSG_UnknownError, ae.Message); } catch (IOException ie) { parentItem.ShowNotification(FileSystemModels.Local.Strings.STR_MSG_UnknownError, ie.Message); } }
/// <summary> /// Adds the folder item into the collection of sub-folders of this folder. /// </summary> /// <param name="item"></param> public void ChildAdd(ITreeItemViewModel item) { Application.Current.Dispatcher.Invoke(() => { _Folders.AddItem(item); }); }
protected void OnSelectedItemChanged(ITreeItemViewModel newValue, ITreeItemViewModel oldValue) { var handler = SelectedItemChanged; if (handler != null) { handler(null, new SelectedChangedEventArgs(newValue, oldValue)); } }
public SelectedChangedEventArgs(ITreeItemViewModel newValue, ITreeItemViewModel oldValue) { if (newValue == null) { throw new ArgumentNullException("newValue"); } NewValue = newValue; OldValue = oldValue; }
public TreeItemViewModel( TreeItem model, ColumnPropertyInfos <TreeItemViewModel> columnPropertyInfos, ITreeItemViewModel parent = null) { this.Parent = parent; this.Children = new ObservableCollection <ITreeItemViewModel>(); this.model = model; this.ColomnProperties = new ColumnProperties <TreeItemViewModel>(this, columnPropertyInfos); }
/// <summary> /// Construct an item viewmodel from a path. /// </summary> /// <param name="model"></param> /// <param name="parent"></param> /// <returns></returns> public TreeItemViewModel(IPathModel model, ITreeItemViewModel parent) : this() { _Parent = parent; _Folders.AddItem(DummyChild); _Model = model.Clone() as IPathModel; // Names of Logical drives cannot be changed with this if (_Model.PathType == FSItemType.LogicalDrive) { this.IsReadOnly = true; } }
/// <summary> /// Adds or removes the <paramref name="item"/> from the bookmarks collection /// at thr receivers (subscriber) end of the event chain. /// /// <see cref="RequestEditBookmarkedFolders"/> event. /// </summary> /// <param name="item"></param> /// <param name="action"></param> private void EditRecentFolder_Executed( ITreeItemViewModel item, EditBookmarkEvent.RecentFolderAction action) { if (item == null) { return; } // Tell client via event to get rid of this entry if (this.RequestEditBookmarkedFolders != null) { this.RequestEditBookmarkedFolders(this, new EditBookmarkEvent( PathFactory.Create(item.ItemPath, FSItemType.Folder), action)); } }
/// <summary> /// Expand folder for the very first time (using the process background viewmodel). /// </summary> /// <param name="expandedItem"></param> private async Task ExpandDummyFolderAsync(ITreeItemViewModel expandedItem) { if (expandedItem != null && _IsExpanding == false) { if (expandedItem.HasDummyChild == true) { _IsExpanding = true; try { if ((expandedItem is TreeItemViewModel) == true) { var item = expandedItem as TreeItemViewModel; item.ChildrenClear(); // Requery sub-folders of this item await item.ChildrenLoadAsync(); } } finally { _IsExpanding = false; } } } }
/// <summary> /// Constructs a drive's viewmodel. /// </summary> public DriveViewModel(IPathModel model, ITreeItemViewModel parent) : base(model, parent) { }
/// <summary> /// Construct a <seealso cref="FolderViewModel"/> item that represents a Windows /// file system folder object (eg.: FolderPath = 'C:\Temp\', FolderName = 'Temp'). /// </summary> /// <param name="dir"></param> /// <param name="parent"></param> /// <returns></returns> internal FolderViewModel(string dir, ITreeItemViewModel parent) : this(PathFactory.Create(dir, FSItemType.Folder), parent) { }
/// <summary> /// Construct a folder viewmodel item from a path. /// </summary> /// <param name="model"></param> /// <param name="parent"></param> /// <returns></returns> public FolderViewModel(IPathModel model, ITreeItemViewModel parent) : base(model, parent) { }
protected TreeItemViewModel(string dir, FSItemType ItemType, ITreeItemViewModel parent) : this(PathFactory.Create(dir, ItemType), parent) { }