/// <summary> /// Adds another item into the collection of file/folder items /// and ensures the operation is performed on the dispatcher thread. /// </summary> private void CurrentItemAdd(IFolderItemViewModel item) { Application.Current.Dispatcher.Invoke(() => { _CurrentItems.Add(item); }); }
private IFolderItemViewModel InitializeView(IPathModel newPath) { string pathroot = string.Empty; IFolderItemViewModel selectedItem = null; string[] dirs; if (newPath == null) { if (string.IsNullOrEmpty(CurrentFolder) == false) { return(null); // No parameter available at this time ... } else { try { newPath = PathFactory.Create(CurrentFolder); } catch { } } } pathroot = newPath.PathRoot; dirs = PathFactory.GetDirectories(newPath.Path); // add drives foreach (string s in Directory.GetLogicalDrives()) { IFolderItemViewModel info = FolderControlsLib.Factory.CreateLogicalDrive(s); CurrentItemsAdd(info); // add items under current folder if we currently create the root folder of the current path if (string.Compare(pathroot, s, true) == 0) { for (int i = 1; i < dirs.Length; i++) { try { string curdir = PathFactory.Join(dirs, 0, i + 1); var curPath = PathFactory.Create(curdir); var info2 = new FolderItemViewModel(curPath, dirs[i]); CurrentItemsAdd(info2); } catch // Non-existing/unknown items will throw an exception here... { } } selectedItem = _CurrentItems.Last(); } } return(selectedItem); }
/// <summary> /// Adds another item into the collection of file/folder items /// and ensures the operation is performed on the dispatcher thread. /// </summary> private IFolderItemViewModel CurrentItemsAdd(IFolderItemViewModel item) { Application.Current.Dispatcher.Invoke(() => { _CurrentItems.AddItem(item.ItemPath, item); _CurrentItems.Sort(it => it.ItemPath); }); return(item); }
/// <summary> /// Can be invoked to refresh the currently visible set of data. /// </summary> public bool PopulateView(IPathModel newPath) { lock (this._LockObject) { try { CurrentItemClear(); // add drives string pathroot = string.Empty; if (newPath == null) { if (string.IsNullOrEmpty(this.CurrentFolder) == false) { try { pathroot = System.IO.Path.GetPathRoot(CurrentFolder); } catch { pathroot = string.Empty; } } } else { pathroot = System.IO.Path.GetPathRoot(newPath.Path); } foreach (string s in Directory.GetLogicalDrives()) { IFolderItemViewModel info = FolderControlsLib.Factory.CreateLogicalDrive(s); CurrentItemAdd(info); // add items under current folder if we currently create the root folder of the current path if (string.IsNullOrEmpty(pathroot) == false && string.Compare(pathroot, s, true) == 0) { string[] dirs; if (newPath == null) { dirs = PathFactory.GetDirectories(CurrentFolder); } else { dirs = PathFactory.GetDirectories(newPath.Path); } for (int i = 1; i < dirs.Length; i++) { try { string curdir = PathFactory.Join(dirs, 0, i + 1); var curPath = PathFactory.Create(curdir); info = new FolderItemViewModel(curPath, dirs[i], false); CurrentItemAdd(info); } catch // Non-existing/unknown items will thrown an exception here... { } } SelectedItem = _CurrentItems.Last(); } } // Force a selection on to the control when there is no selected item, yet if (this._CurrentItems != null && SelectedItem == null) { if (this._CurrentItems.Count > 0) { this.SelectedItem = this._CurrentItems.Last(); } } return(true); } catch (Exception exp) { Console.WriteLine("{0} -> {1}", exp.Message, exp.StackTrace); return(false); } } }