/// <summary> /// Creates a new folder with a standard name (eg: 'New folder n'). /// </summary> /// <returns></returns> private LVItemViewModel CreateNewDirectory(string parentFolder) { //Logger.DebugFormat("CreateNewDirectory method with '{0}'", parentFolder); try { var model = PathFactory.Create(parentFolder, FSItemType.Folder); var newSubFolder = PathFactory.CreateDir(model); if (newSubFolder != null) { var newFolderVM = new LVItemViewModel(newSubFolder.Path, newSubFolder.PathType, newSubFolder.Name); _CurrentItems.Add(newFolderVM); return(newFolderVM); } } catch (Exception exp) { Logger.Error(string.Format("Creating new folder underneath '{0}' was not succesful.", parentFolder), exp); this.Notification.ShowNotification(FileSystemModels.Local.Strings.STR_CREATE_FOLDER_ERROR_TITLE, exp.Message); } return(null); }
/// <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(LVItemViewModel item) { Application.Current.Dispatcher.Invoke(() => { _CurrentItems.Add(item); }); }
/// <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( LVItemViewModel 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> /// 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(string parentFolder) { if (parentFolder == null) { return; } LVItemViewModel newSubFolder = this.CreateNewDirectory(parentFolder); if (newSubFolder != null) { this.SelectedItem = newSubFolder; // Do this with low priority (thanks for that tip to Joseph Leung) Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, (Action) delegate { newSubFolder.RequestEditMode(InplaceEditBoxLib.Events.RequestEditEvent.StartEditMode); }); } }
/// <summary> /// Fills the CurrentItems property for display in ItemsControl /// based view (ListBox, ListView etc.) /// /// This version is parameterized since the filterstring can be parsed /// seperately and does not need to b parsed each time when this method /// executes. /// </summary> private bool InternalPopulateView(string[] filterString , DirectoryInfo cur , bool showIcons) { //Logger.DebugFormat("InternalPopulateView method with filterString parameter"); try { // Retrieve and add (filtered) list of directories if (this.ShowFolders) { string[] directoryFilter = null; //// if (filterString != null) //// directoryFilter = new ArrayList(filterString).ToArray() as string[]; directoryFilter = null; foreach (DirectoryInfo dir in cur.SelectDirectoriesByFilter(directoryFilter)) { if (dir.Attributes.HasFlag(FileAttributes.Hidden) == true) { if (this.ShowHidden == false) { if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { continue; } } } var info = new LVItemViewModel(dir.FullName, FSItemType.Folder, dir.Name, showIcons); CurrentItemAdd(info); } } if (this.IsFiltered == false) // Do not apply the filter if it is not enabled { filterString = null; } // Retrieve and add (filtered) list of files in current directory foreach (FileInfo f in cur.SelectFilesByFilter(filterString)) { if (this.ShowHidden == false) { if (f.Attributes.HasFlag(FileAttributes.Hidden) == true) { if ((f.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { continue; } } } var info = new LVItemViewModel(f.FullName, FSItemType.File, f.Name, showIcons); CurrentItemAdd(info); } return(true); } catch { } return(false); }