/// <summary> /// Create a new folder with a standard name /// 'New folder n' underneath this folder. /// </summary> /// <returns>a viewmodel of the newly created directory or null</returns> public override ITreeItemViewModel CreateNewDirectory() { lock (_LockObject) { try { string defaultFolderName = FileSystemModels.Local.Strings.STR_NEW_DEFAULT_FOLDER_NAME; var model = PathFactory.Create(ItemPath, FSItemType.Folder); var newSubFolder = PathFactory.CreateDir(model, defaultFolderName); if (newSubFolder != null) { var item = new FolderViewModel(newSubFolder, this); ChildAdd(item); return(item); } } catch (Exception exp) { this.ShowNotification(FileSystemModels.Local.Strings.STR_MSG_UnknownError, exp.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> /// 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> /// 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> /// <returns></returns> private FolderViewModel AddFolder(string dir) { 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 = FolderViewModel.ConstructFolderFolderViewModel(dir); AddFolder(newFolder); return(newFolder); } } catch (UnauthorizedAccessException ae) { this.ShowNotification(FileSystemModels.Local.Strings.STR_MSG_UnknownError, ae.Message); } catch (Exception e) { this.ShowNotification(FileSystemModels.Local.Strings.STR_MSG_UnknownError, e.Message); } return(null); }
internal static void AddFolder(FolderViewModel f, FolderViewModel item) { Application.Current.Dispatcher.Invoke(() => { f.AddFolder(item); }); }
/// <summary> /// Create a new folder with a standard name /// 'New folder n' underneath this folder. /// </summary> /// <returns>a viewmodel of the newly created directory or null</returns> public IFolderViewModel CreateNewDirectory() { Logger.DebugFormat("Detail: Create new directory with standard name."); lock (mLockObject) { try { string defaultFolderName = FileSystemModels.Local.Strings.STR_NEW_DEFAULT_FOLDER_NAME; var newSubFolder = PathModel.CreateDir(new PathModel(FolderPath, FSItemType.Folder), defaultFolderName); if (newSubFolder != null) { var newFolder = new FolderViewModel(newSubFolder); Folders.Add(newFolder.FolderName, newFolder); return(newFolder); } } catch (Exception exp) { this.ShowNotification(FileSystemModels.Local.Strings.STR_MSG_UnknownError, exp.Message); } } return(null); }
/// <summary> /// Requery all child items - this can be useful when we /// expand a folder for the very first time. Here we use task library with /// async to enable synchronization. This is for parts of other commands /// such as New Folder command which requires expansion of sub-folder /// items before actual New Folder command can execute. /// </summary> /// <param name="expandedItem"></param> /// <returns></returns> private async Task <bool> RequeryChildItems(FolderViewModel expandedItem) { await Task.Run(() => { expandedItem.ClearFolders(); // Requery sub-folders of this item expandedItem.LoadFolders(); }); return(true); }
/// <summary> /// Create a new folder underneath the given parent folder. This method creates /// the folder with a standard name (eg 'New folder n') on disk and selects it /// in editing mode to give users a chance for renaming it right away. /// </summary> /// <param name="parentFolder"></param> private void CreateFolderCommandNewFolder(FolderViewModel parentFolder) { if (parentFolder == null) { return; } // Cast this to access internal methods and setters var newSubFolder = parentFolder.CreateNewDirectory() as FolderViewModel; ////this.SelectedFolder = newSubFolder.FolderPath; ////this.SetSelectedFolder(newSubFolder.FolderPath, true); if (newSubFolder != null) { // Do this with low priority (thanks for that tip to Joseph Leung) Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, (Action) delegate { newSubFolder.IsSelected = true; newSubFolder.RequestEditMode(InplaceEditBoxLib.Events.RequestEditEvent.StartEditMode); }); } }
private FolderViewModel CreateFolderItem(PathModel model) { var f = new FolderViewModel(model); return(f); }
public override async Task <int> ChildrenLoadAsync() { await Task.Run(() => { FolderViewModel.LoadFolders(this); }); return(base.ChildrenCount); }
/// <summary> /// Load all sub-folders into the Folders collection. /// </summary> public override void ChildrenLoad() { FolderViewModel.LoadFolders(this); }