private async Task InternalPopulateViewAsync(IPathModel newPath , bool sendNotification) { IsBrowsing = true; try { if (sendNotification == true && this.SelectedItem != null) { if (BrowseEvent != null) { BrowseEvent(this, new BrowsingEventArgs(newPath, true, BrowseResult.Unknown)); } } await Task.Run(() => { bool result = false; result = PopulateView(newPath); if (sendNotification == true && this.SelectedItem != null) { if (BrowseEvent != null) { BrowseEvent(this, new BrowsingEventArgs( newPath, false, (result == true ? BrowseResult.Complete : BrowseResult.InComplete))); } } }); } finally { IsBrowsing = false; } }
/// <summary> /// Transforms a path model into an array of normalized viewmodel items /// Drive 'C:\' , 'Folder', 'SubFolder', etc... /// and returns these items, or null, if path cannot be split (path is invalid, does not exist etc). /// </summary> /// <param name="inputPath">Path to split into viewmodel items</param> /// <param name="ct">This token can be used to cancel the process if the /// token was supplied and the method has been called in a Task context.</param> /// <returns>An array of viewmodel items or null.</returns> private ITreeItemViewModel[] SelectDirectory( IPathModel inputPath, CancellationToken ct = default(CancellationToken)) { try { // Check if a given path exists var exists = PathFactory.DirectoryPathExists(inputPath.Path); if (exists == false) { return(null); } // Transform string into array of normalized path elements // Drive 'C:\' , 'Folder', 'SubFolder', etc... var folders = PathFactory.GetDirectories(inputPath.Path); if (folders != null) { // Find the drive that is the root of this path var drive = this._Root.TryGet(folders[0]); return(NavigatePath(drive, folders)); } return(null); } catch (Exception) { throw; } }
/// <summary> /// Event type class constructor from parameter /// </summary> public EditBookmarkEvent(IPathModel path, RecentFolderAction action = RecentFolderAction.Add) : this() { this.Folder = path; this.Action = action; }
/// <summary> /// Controller can start browser process if IsBrowsing = false /// </summary> /// <param name="newPath"></param> /// <returns></returns> async Task <bool> INavigateable.NavigateToAsync(IPathModel location) { return(await Task.Run(() => { return NavigateTo(location, false); })); }
/// <summary> /// Method executes when item is renamed /// -> model name is required to be renamed and dependend /// properties are updated. /// </summary> /// <param name="model"></param> private void ResetModel(IPathModel model) { var oldModel = _Model; _Model = model.Clone() as IPathModel; if (oldModel == null && model == null) { return; } if (oldModel == null && model != null || oldModel != null && model == null) { RaisePropertyChanged(() => ItemType); RaisePropertyChanged(() => ItemName); RaisePropertyChanged(() => ItemPath); return; } if (oldModel.PathType != _Model.PathType) { RaisePropertyChanged(() => ItemType); } if (string.Compare(oldModel.Name, _Model.Name, true) != 0) { RaisePropertyChanged(() => ItemName); } if (string.Compare(oldModel.Path, _Model.Path, true) != 0) { RaisePropertyChanged(() => ItemPath); } }
/// <summary> /// class constructor /// </summary> /// <param name="model"></param> /// <param name="itemName"></param> public FolderItemViewModel(IPathModel model, string itemName) : this() { _PathObject = model.Clone() as IPathModel; ItemName = itemName; }
/// <summary> /// Rename the name of a folder or file into a new name. /// /// This includes renaming the item in the file system. /// </summary> /// <param name="newFolderName"></param> public void RenameFileOrFolder(string newFolderName) { try { if (newFolderName != null) { IPathModel newFolderPath; if (PathFactory.RenameFileOrDirectory(this._PathObject, newFolderName, out newFolderPath) == true) { this._PathObject = newFolderPath; this.ItemName = newFolderPath.Name; } } } catch (Exception exp) { Logger.Error(string.Format("Rename into '{0}' was not succesful.", newFolderName), exp); base.ShowNotification(FileSystemModels.Local.Strings.STR_RenameFolderErrorTitle, exp.Message); } finally { this.RaisePropertyChanged(() => this.ItemPath); } }
/// <summary> /// Create a new folder new standard sub folder in <paramref name="folderPath"/>. /// The new folder has a standard name like 'New folder n'. /// </summary> /// <param name="folderPath"></param> /// <param name="newDefaultFolderName">Compute default name for new folder</param> /// <returns>PathModel object to new folder or null</returns> public static IPathModel CreateDir(IPathModel folderPath, string newDefaultFolderName = "New Folder") { var newFolderName = newDefaultFolderName; var newFolderPath = newFolderName; try { if (System.IO.Directory.Exists(folderPath.Path) == false) { return(null); } // Compute default name for new folder newFolderPath = System.IO.Path.Combine(folderPath.Path, newDefaultFolderName); for (int i = 1; System.IO.Directory.Exists(newFolderPath) == true; i++) { newFolderName = string.Format("{0} {1}", newDefaultFolderName, i); newFolderPath = System.IO.Path.Combine(folderPath.Path, newFolderName); } // Create that new folder System.IO.Directory.CreateDirectory(newFolderPath); return(new PathModel(newFolderPath, FSItemType.Folder)); } catch (Exception exp) { throw new Exception(string.Format("'{0}'", newFolderPath), exp); } }
/// <summary> /// Parameterized class constructor. /// </summary> public BrowseRequest(IPathModel newLocation, CancellationToken cancelToken = default(CancellationToken)) : this() { NewLocation = newLocation.Clone() as IPathModel; CancelTok = cancelToken; }
public Path(string inputPath) { _model = GetPathModel(inputPath); if (!(_model is AbsolutePathModel)) { throw new InvalidPathException("Cannot build Path object based on relative path"); } }
/// <summary> /// Call this method to initialize viewmodel items that might need to display /// progress information (e.g. call this in OnLoad() method of view) /// </summary> /// <param name="path"></param> public void InitializeViewModel(IPathModel path) { // Navigate demo controller without Treeview to this location FolderView.NavigateToFolder(path); // Navigate demo controller with Treeview to this location FolderTreeView.NavigateToFolder(path); }
void IPathBuilder.AddSubdirectory(string subdirectory) { if (_model == null) { _model = new RelativePathModel(); } _model.AddSubdirectory(subdirectory); }
void IPathBuilder.AddParentDirectory() { if (_model == null) { _model = new RelativePathModel(); } _model.MoveToParentDirectory(); }
/// <summary> /// Rename an existing directory into the <paramref name="newFolderName"/>. /// </summary> /// <param name="source"></param> /// <param name="newFolderName"></param> /// <param name="newFolderPathName"></param> /// <returns>false Item to be renamed does not exist or something else is not as expected, otherwise true</returns> public static bool RenameFileOrDirectory(IPathModel source, string newFolderName, out IPathModel newFolderPathName) { return(PathModel.RenameFileOrDirectory(source, newFolderName, out newFolderPathName)); }
/// <summary> /// class constructor /// </summary> /// <param name="curdir"></param> /// <param name="itemName"></param> /// <param name="itemType"></param> public ListItemViewModel(string curdir, FSItemType itemType, string itemName) : this() { this._PathObject = PathFactory.Create(curdir, itemType); this.ItemName = itemName; }
/// <summary> /// class constructor /// </summary> /// <param name="curdir"></param> /// <param name="itemType"></param> /// <param name="itemName"></param> /// <param name="indentation"></param> public LVItemViewModel(string curdir, FSItemType itemType, string itemName, int indentation = 0) : this() { this._PathObject = PathFactory.Create(curdir, itemType); this.ItemName = itemName; }
/// <summary> /// class constructor /// </summary> /// <param name="model"></param> /// <param name="itemName"></param> /// <param name="isReadOnly"></param> public LVItemViewModel(IPathModel model, string itemName, bool isReadOnly = false) : this() { _PathObject = model.Clone() as IPathModel; ItemName = itemName; IsReadOnly = isReadOnly; }
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> /// Event type class constructor from parameter /// </summary> public BrowsingEventArgs(IPathModel location, bool isBrowsing, BrowseResult result = BrowseResult.Unknown) : this() { Location = location; IsBrowsing = isBrowsing; Result = result; }
/// <summary> /// Standard <seealso cref="TreeItemViewModel"/> constructor /// </summary> protected TreeItemViewModel() : base() { _IsExpanded = _IsSelected = false; _Model = null; // Add dummy folder by default to make tree view show expander by default _Folders = new SortableObservableDictionaryCollection(); }
/// <summary> /// Parameterized class constructor. /// </summary> public FinalBrowseResult(IPathModel requestedLocation, Guid requestId = default(System.Guid), BrowseResult result = BrowseResult.Unknown ) : this() { RequestedLocation = requestedLocation; Result = result; RequestId = requestId; }
/// <summary> /// Sets the current folder to a new folder (with or without adjustments of History). /// </summary> /// <param name="path"></param> /// <param name="bSetHistory"></param> public void SetCurrentFolder(string path, bool bSetHistory) { try { this.CurrentFolder = PathFactory.Create(path); } catch { } }
void IPathBuilder.CreateRootDirectory() { if (_model == null) { _model = new AbsolutePathModel(); } else { throw new InvalidOperationException("Bad command!"); } }
/// <summary> /// Can be invoked to refresh the currently visible set of data. /// </summary> public FinalBrowseResult PopulateView(BrowseRequest request) { IPathModel newPath = request.NewLocation; // Make sure the task always processes the last input but is not started twice _SlowStuffSemaphore.WaitAsync(); try { if (request.CancelTok != null) { request.CancelTok.ThrowIfCancellationRequested(); } // Initialize view with current path if (_CurrentItems.Count() == 0) { CurrentItemsClear(); SelectedItem = InitializeView(newPath); } else { var match = _CurrentItems.TryGet(newPath.Path); if (match != null) { SelectedItem = match; } else { var folderItem = new FolderItemViewModel(newPath, newPath.Name); SelectedItem = CurrentItemsAdd(folderItem); } } // Force a selection on to the control when there is no selected item, yet // Select last item in the list (hoping this is what we want...) if (_CurrentItems.Count > 0 && SelectedItem == null) { SelectedItem = _CurrentItems.Last(); } return(FinalBrowseResult.FromRequest(request, BrowseResult.Complete)); } catch (Exception exp) { //// Console.WriteLine("{0} -> {1}", exp.Message, exp.StackTrace); var result = FinalBrowseResult.FromRequest(request, BrowseResult.InComplete); result.UnexpectedError = exp; return(result); } finally { _SlowStuffSemaphore.Release(); } }
private void SetCurrentLocation(IPathModel pmodel) { try { _CurrentFolder = pmodel.Clone() as IPathModel; } catch { } RaisePropertyChanged(() => CurrentFolder); }
/// <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> /// Determine whether two <seealso cref="PathModel"/> objects describe the same /// location/item in the file system or not. /// /// Method implements <seealso cref="IComparable{IPathModel}"/> interface. /// </summary> /// <param name="path"></param> /// <returns></returns> public int CompareTo(IPathModel path) { if (PathModel.Compare(this, path) == true) { return(0); } else { string spath = PathModel.NormalizePath(path.Path); string thispath = PathModel.NormalizePath(this.Path); return(string.Compare(spath, thispath, true)); } }
internal void DoCd(IPathModel pathModel) { foreach (var subdirectory in _subdirectories) { if (subdirectory == SimpleFileSystemEnvironment.ParentDirectoryAlias) { pathModel.MoveToParentDirectory(); } else { pathModel.AddSubdirectory(subdirectory); } } }
/// <summary> /// Copy constructor /// </summary> /// <param name="copyThis"></param> public ListItemViewModel(ListItemViewModel copyThis) : this() { if (copyThis == null) { return; } _ItemName = copyThis._ItemName; _PathObject = copyThis._PathObject.Clone() as IPathModel; _VolumeLabel = copyThis._VolumeLabel; ShowIcon = copyThis.ShowIcon; }
/// <summary> /// Rename an existing directory into the <paramref name="newFolderName"/>. /// </summary> /// <param name="source"></param> /// <param name="newFolderName"></param> /// <param name="newFolderPathName"></param> /// <returns>false Item to be renamed does not exist or something else is not as expected, otherwise true</returns> public static bool RenameFileOrDirectory(IPathModel source, string newFolderName, out IPathModel newFolderPathName) { newFolderPathName = null; switch (source.PathType) { case FSItemType.Folder: if (System.IO.Directory.Exists(source.Path)) { DirectoryInfo di = new DirectoryInfo(source.Path); string parent = di.Parent.FullName; string newFolderPath = System.IO.Path.Combine(parent, newFolderName); newFolderPathName = new PathModel(newFolderPath, source.PathType); System.IO.Directory.Move(source.Path, newFolderPathName.Path); return(true); } break; case FSItemType.File: if (System.IO.File.Exists(source.Path)) { string parent = System.IO.Directory.GetParent(source.Path).FullName; newFolderPathName = new PathModel(System.IO.Path.Combine(parent, newFolderName), source.PathType); System.IO.Directory.Move(source.Path, newFolderPathName.Path); return(true); } break; case FSItemType.LogicalDrive: case FSItemType.Unknown: default: break; } // Item to be renamed does not exist or something else is not as expected return(false); }