private void FileSelected(string filePath) { FileBookmarks.Clear(); FilePath = filePath; ExtLib.Bookmarks.GetBookmarks(filePath).ForEach(x => FileBookmarks.Add(x)); PageNumber = ExtLib.Bookmarks.GetLastPage(filePath); }
private void DeSelectChildrenRecursively(IBookmark mark) { foreach (IBookmark child in FileBookmarks.Where(x => x.ParentId == mark.Id)) { child.IsSelected = false; DeSelectChildrenRecursively(child); } }
private void BookmarkAdded(IBookmark mark) { List <IBookmark> originalList = FileBookmarks.ToList(); List <IBookmark> parents = originalList.FindAll(x => x.StartPage <= mark.StartPage && x.EndPage > mark.EndPage); if (parents.Count > 0) { IBookmark parent = parents.First(x => x.Level == parents.Max(x => x.Level)); mark.Level = parent.Level + 1; mark.ParentId = parent.Id; List <IBookmark> siblings = originalList.FindAll(x => x.ParentId == parent.Id); if (siblings.Count < 1) { FileBookmarks.Insert(FileBookmarks.IndexOf(FileBookmarks.First(x => x.Id == parent.Id)) + 1, mark); } else { IBookmark closestSibling = siblings.FirstOrDefault(x => x.StartPage > mark.StartPage); if (closestSibling == null) { FileBookmarks.Insert(FileBookmarks.IndexOf(FileBookmarks.Last(x => x.ParentId == parent.Id)) + 1, mark); } else { FileBookmarks.Insert(FileBookmarks.IndexOf(FileBookmarks.First(x => x.Id == closestSibling.Id)) - 1, mark); } } } else { mark.ParentId = Guid.Empty; mark.Level = 1; IBookmark next = FileBookmarks.FirstOrDefault(x => x.Level == 0 && x.StartPage > mark.StartPage); if (next == null) { FileBookmarks.Add(mark); } else { FileBookmarks.Insert(FileBookmarks.IndexOf(next) - 1, mark); } } }
void ExecuteImportBookmarksCommand() { OpenFileDialog openFile = new OpenFileDialog(); openFile.Title = "Valitse kirjanmerkkitiedosto"; openFile.Filter = "Tekstitiedosto |*.txt"; openFile.InitialDirectory = Path.GetDirectoryName(FilePath); if (openFile.ShowDialog() != true) { return; } List <IBookmark> imported = ExtLib.Bookmarks.ImportBookmarks(openFile.FileName, PageNumber); FileBookmarks.Clear(); foreach (IBookmark import in imported) { FileBookmarks.Add(import); } }
void ExecuteDeleteCommand() { FileBookmarks.RemoveAll(x => x.IsSelected); }