public TranslationViewModel(int bookId) { selectChapterCommand = null; selectedChapter = null; selectedChapterContent = null; LoadBook(bookId); }
private void SelectChapter(ChapterViewModel chapterViewModel) { if (selectedChapter != null) selectedChapter.IsSelected = false; selectedChapter = chapterViewModel; selectedChapter.IsTreeItemExpanded = true; selectedChapter.IsSelected = true; SelectedChapterContent = new ChapterContentViewModel(selectedChapter.HtmlContent, images, styleSheets, fonts); }
private List<ChapterViewModel> GetChapters(List<EpubChapter> epubChapters) { List<ChapterViewModel> result = new List<ChapterViewModel>(); foreach (EpubChapter epubChapter in epubChapters) { List<ChapterViewModel> subChapters = GetChapters(epubChapter.SubChapters); ChapterViewModel chapterViewModel = new ChapterViewModel(epubChapter.Title, subChapters, epubChapter.HtmlContent); result.Add(chapterViewModel); } return result; }
private List<ChapterViewModel> GetChapters(List<EpubChapter> epubChapters) { List<ChapterViewModel> result = new List<ChapterViewModel>(); for (int index = 0; index < epubChapters.Count; index++) { EpubChapter epubChapter = epubChapters[index]; List<ChapterViewModel> subChapters = GetChapters(epubChapter.SubChapters); ChapterViewModel chapterViewModel = new ChapterViewModel(epubChapter.Title, subChapters, epubChapter.HtmlContent, epubChapter.ContentFileName); result.Add(chapterViewModel); } return result; }
public BookViewModel(int bookId) { bookModel = new BookModel(); epubBook = bookModel.OpenBook(bookId); Contents = new ObservableCollection<ChapterViewModel>(bookModel.GetChapters(epubBook)); images = epubBook.Content.Images.ToDictionary(imageFile => imageFile.Key, imageFile => imageFile.Value.Content); styleSheets = epubBook.Content.Css.ToDictionary(cssFile => cssFile.Key, cssFile => cssFile.Value.Content); fonts = epubBook.Content.Fonts.ToDictionary(fontFile => fontFile.Key, fontFile => fontFile.Value.Content); selectChapterCommand = null; selectedChapter = null; selectedChapterContent = null; if (Contents.Any()) SelectChapter(Contents.First()); }
public BookViewModel(int bookId) { bookModel = new BookModel(); epubBook = bookModel.OpenBook(bookId); Contents = new ObservableCollection <ChapterViewModel>(bookModel.GetChapters(epubBook)); images = epubBook.Content.Images.ToDictionary(imageFile => imageFile.Key, imageFile => imageFile.Value.Content); styleSheets = epubBook.Content.Css.ToDictionary(cssFile => cssFile.Key, cssFile => cssFile.Value.Content); fonts = epubBook.Content.Fonts.ToDictionary(fontFile => fontFile.Key, fontFile => fontFile.Value.Content); selectChapterCommand = null; selectedChapter = null; selectedChapterContent = null; if (Contents.Any()) { SelectChapter(Contents.First()); } }
public void LoadBook(int bookId, bool append = false) { var epubBook = bookModel.OpenBook(bookId); Contents = Contents.AddRange(bookModel.GetChapters(epubBook)); images = images.AddRange(epubBook.Content.Images.ToDictionary(imageFile => imageFile.Key, imageFile => imageFile.Value.Content)); styleSheets = styleSheets.AddRange(epubBook.Content.Css.ToDictionary(cssFile => cssFile.Key, cssFile => cssFile.Value.Content)); fonts = fonts.AddRange(epubBook.Content.Fonts.ToDictionary(fontFile => fontFile.Key, fontFile => fontFile.Value.Content)); selectChapterCommand = null; selectedChapter = null; selectedChapterContent = null; if (Contents.Any()) { SelectChapter(Contents.First()); } }
private List<ChapterViewModel> GetChapters(List<EpubChapter> epubChapters, List<EpubChapter> epubChapters1, List<EpubChapter> epubChapters2) { List<ChapterViewModel> result = new List<ChapterViewModel>(); for (int index = 0; index < epubChapters.Count; index++) { EpubChapter epubChapter1 = epubChapters1[index]; List<ChapterViewModel> subChapters1 = GetChapters(epubChapter1.SubChapters); EpubChapter epubChapter2 = epubChapters2[index]; List<ChapterViewModel> subChapters2 = GetChapters(epubChapter2.SubChapters); EpubChapter epubChapter0 = epubChapters[index]; List<ChapterViewModel> subChapters0 = GetChapters(epubChapter0.SubChapters, epubChapter1.SubChapters, epubChapter2.SubChapters); ChapterViewModel chapterViewModel1 = new ChapterViewModel(epubChapter1.Title, subChapters1, epubChapter1.HtmlContent, epubChapter1.HtmlId); ChapterViewModel chapterViewModel2 = new ChapterViewModel(epubChapter2.Title, subChapters2, epubChapter2.HtmlContent, epubChapter2.HtmlId); ChapterViewModel chapterViewModel = new ChapterViewModel(epubChapter0.Title, subChapters0, epubChapter0.HtmlContent, epubChapter0.HtmlId, new List<ChapterViewModel> { chapterViewModel1, chapterViewModel2 }); result.Add(chapterViewModel); } return result; }
private void SelectChapter(ChapterViewModel chapterViewModel) { if (string.IsNullOrEmpty(chapterViewModel.HtmlId)) { bool samePage = false; if (selectedChapter != null) { selectedChapter.IsSelected = false; if (selectedChapter == chapterViewModel || (!string.IsNullOrEmpty(selectedChapter.HtmlId) && chapterViewModel.ParentChapter == selectedChapter)) { selectedChapter = null; selectedChapterContent = null; samePage = true; } } selectedChapter = chapterViewModel; selectedChapter.IsTreeItemExpanded = true; selectedChapter.IsSelected = true; SelectedChapterContent = new ChapterContentViewModel(selectedChapter.HtmlContent, images, styleSheets, fonts); if (BookView.View != null && samePage) BookView.View.ScrollTo(""); } else { if (selectedChapter == null) { selectedChapter = chapterViewModel.ParentChapter; } else selectedChapter.IsSelected = false; selectedChapter = chapterViewModel; selectedChapter.IsTreeItemExpanded = true; selectedChapter.IsSelected = true; if (SelectedChapterContent.HtmlContent != chapterViewModel.ParentChapter.HtmlContent) SelectedChapterContent = new ChapterContentViewModel(chapterViewModel.ParentChapter.HtmlContent, images, styleSheets, fonts); Task.Run(async () => { await Task.Delay(100); if (BookView.View != null) BookView.View.ScrollTo(chapterViewModel.HtmlId); }); // SelectedElement = chapterViewModel.HtmlContent; } }
public void LoadBook(int bookId, bool append = false) { var epubBook = bookModel.OpenBook(bookId); Contents = Contents.AddRange(bookModel.GetChapters(epubBook)); images = images.AddRange(epubBook.Content.Images.ToDictionary(imageFile => imageFile.Key, imageFile => imageFile.Value.Content)); styleSheets = styleSheets.AddRange(epubBook.Content.Css.ToDictionary(cssFile => cssFile.Key, cssFile => cssFile.Value.Content)); fonts = fonts.AddRange(epubBook.Content.Fonts.ToDictionary(fontFile => fontFile.Key, fontFile => fontFile.Value.Content)); selectChapterCommand = null; selectedChapter = null; selectedChapterContent = null; if (Contents.Any()) SelectChapter(Contents.First()); }
private void SelectChapter(ChapterViewModel chapterViewModel) { if (string.IsNullOrEmpty(chapterViewModel.HtmlId)) { bool samePage = false; if (selectedChapter != null) { selectedChapter.IsSelected = false; if (selectedChapter == chapterViewModel || (!string.IsNullOrEmpty(selectedChapter.HtmlId) && chapterViewModel.ParentChapter == selectedChapter)) { selectedChapter = null; selectedChapterContent = null; samePage = true; } } selectedChapter = chapterViewModel; selectedChapter.IsTreeItemExpanded = true; selectedChapter.IsSelected = true; SelectedChapterContent = new ChapterContentViewModel(selectedChapter.HtmlContent, images, styleSheets, fonts); SelectedChapterContent1 = new ChapterContentViewModel(selectedChapter.RelatedChapters[0].HtmlContent, images, styleSheets, fonts); SelectedChapterContent2 = new ChapterContentViewModel(selectedChapter.RelatedChapters[1].HtmlContent, images, styleSheets, fonts); if (TranslationView.View != null && samePage) { TranslationView.View.ScrollTo(""); } } else { if (selectedChapter == null) { selectedChapter = chapterViewModel.ParentChapter; } else { selectedChapter.IsSelected = false; } selectedChapter = chapterViewModel; selectedChapter.IsTreeItemExpanded = true; selectedChapter.IsSelected = true; if (SelectedChapterContent.HtmlContent != chapterViewModel.ParentChapter.HtmlContent) { SelectedChapterContent = new ChapterContentViewModel(chapterViewModel.ParentChapter.HtmlContent, images, styleSheets, fonts); } if (SelectedChapterContent1.HtmlContent != chapterViewModel.RelatedChapters[0].ParentChapter.HtmlContent) { SelectedChapterContent1 = new ChapterContentViewModel(chapterViewModel.RelatedChapters[0].ParentChapter.HtmlContent, images, styleSheets, fonts); } if (SelectedChapterContent2.HtmlContent != chapterViewModel.RelatedChapters[1].ParentChapter.HtmlContent) { SelectedChapterContent2 = new ChapterContentViewModel(chapterViewModel.RelatedChapters[1].ParentChapter.HtmlContent, images, styleSheets, fonts); } Task.Run(async() => { await Task.Delay(100); if (TranslationView.View != null) { TranslationView.View.ScrollTo(chapterViewModel.HtmlId); } }); } }