Ejemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets Scripture reference for a selection
        /// </summary>
        /// <param name="helper">The selection helper that represents the selection</param>
        /// <param name="fInclusive"><c>true</c> if the reference returned should include the
        /// reference of the text of the verse where the selection is, even if that selection
        /// is not at the start of the verse; <c>false</c> if the reference should be that of
        /// the first full verse at or following the selection</param>
        /// <param name="scriptureRef">returns the scripture reference found</param>
        /// <returns>A TsString representing the reference of the selection, or null if the
        /// selection represents a book title or something weird.</returns>
        /// ------------------------------------------------------------------------------------
        private ITsString GetSelectionReference(SelectionHelper helper, bool fInclusive,
                                                out BCVRef scriptureRef)
        {
            scriptureRef = new BCVRef();
            if (helper != null && m_page.Publication != null && m_page.Publication is ScripturePublication)
            {
                int iParaLevel = helper.GetLevelForTag(StTextTags.kflidParagraphs);
                if (iParaLevel >= 0)
                {
                    int         hvo  = helper.LevelInfo[iParaLevel].hvo;
                    IScrTxtPara para =
                        m_cache.ServiceLocator.GetInstance <IScrTxtParaRepository>().GetObject(hvo);
                    // Look through the verses of the paragraph until we pass the location
                    // where the page break occurs. This verse reference will then be the
                    // first one on the page.
                    ScrVerse firstVerseOnPage = null;
                    int      ichPageBreak     = helper.IchAnchor;
                    foreach (ScrVerse verse in para)
                    {
                        if (!fInclusive)
                        {
                            firstVerseOnPage = verse;
                        }
                        if (verse.VerseStartIndex > ichPageBreak ||
                            (verse.VerseStartIndex == ichPageBreak && !fInclusive))
                        {
                            break;
                        }
                        if (fInclusive)
                        {
                            firstVerseOnPage = verse;
                        }
                    }

                    ITsString tssBookName = GetBookName(helper);
                    if (tssBookName != null)
                    {
                        ITsStrBldr bldr = tssBookName.GetBldr();
                        int        cch  = bldr.Length;
                        if (firstVerseOnPage != null)
                        {
                            if (firstVerseOnPage.StartRef.Verse != 0)
                            {
                                bldr.Replace(cch, cch,
                                             " " + m_scr.ChapterVerseRefAsString(firstVerseOnPage.StartRef),
                                             null);
                            }
                            scriptureRef = firstVerseOnPage.StartRef;
                        }
                        return(bldr.GetString());
                    }
                    //else
                    //{
                    //    // Probably no verses were found in the paragraph
                    //    IVwSelection sel = FindNextPara(helper);
                    //    helper = SelectionHelper.Create(sel, helper.RootSite);

                    //    return GetSelectionReference(helper, fInclusive, out scriptureRef);
                    //}
                }
            }
            return(null);
        }