Bloom.Edit.EditingModel.DeterminePageWhichWouldPrecedeNextInsertion C# (CSharp) Method

DeterminePageWhichWouldPrecedeNextInsertion() public method

public DeterminePageWhichWouldPrecedeNextInsertion ( ) : IPage
return IPage
        public IPage DeterminePageWhichWouldPrecedeNextInsertion()
        {
            if (_view != null)
            {
                var pagesStartingWithCurrentSelection =
                    CurrentBook.GetPages().SkipWhile(p => p.Id != _pageSelection.CurrentSelection.Id);
                var candidates = pagesStartingWithCurrentSelection.ToArray();
                for (int i = 0; i < candidates.Length - 1; i++)
                {
                    if (!candidates[i + 1].Required)
                    {
                        return candidates[i];
                    }
                }
                var pages = CurrentBook.GetPages();
                // ReSharper disable PossibleMultipleEnumeration
                if (!pages.Any())
                {
                    var exception = new ApplicationException(
                        string.Format(
                            @"CurrentBook.GetPages() gave no pages (BL-262 repro).
                                      Book is '{0}'\r\nErrors known to book=[{1}]\r\n{2}\r\n{3}",
                            CurrentBook.TitleBestForUserDisplay,
                            CurrentBook.CheckForErrors(),
                            CurrentBook.RawDom.OuterXml,
                            new StackTrace().ToString()));

                    ErrorReport.NotifyUserOfProblem(exception,
                                                    "There was a problem looking through the pages of this book. If you can send emails, please click 'details' and send this report to the developers.");
                    return null;
                }
                IPage lastGuyWHoCanHaveAnInsertionAfterHim = pages.Last(p => !p.IsBackMatter);
                // ReSharper restore PossibleMultipleEnumeration
                return lastGuyWHoCanHaveAnInsertionAfterHim;
            }
            return null;
        }

Usage Example

Example #1
0
        public void SelectThumbnailWithoutSendingEvent(IPage page)
        {
            _pageWeThinkShouldBeSelected = page;
            try
            {
                _dontForwardSelectionEvent = true;
                _thumbNailList.SelectPage(page);
            }
            finally
            {
                _dontForwardSelectionEvent = false;
            }

            _thumbNailList.SetPageInsertionPoint(_model.DeterminePageWhichWouldPrecedeNextInsertion());
        }