예제 #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a section with optional heading/content paragraphs.
        /// </summary>
        /// <param name="book">The book where the new section will be created</param>
        /// <param name="iSection">The zero-based index of the new section</param>
        /// <param name="isIntro">True to create an intro section, false to create a
        /// normal scripture section</param>
        /// <param name="createHeadingPara">if true, heading paragraph will be created</param>
        /// <param name="createContentPara">if true, content paragraph will be created</param>
        /// <returns>The newly created <see cref="ScrSection"/></returns>
        /// ------------------------------------------------------------------------------------
        private static ScrSection CreateSection(IScrBook book, int iSection, bool isIntro,
                                                bool createHeadingPara, bool createContentPara)
        {
            Debug.Assert(book != null);

            // Create an empty section. The end reference needs to be set to indicate to
            // AdjustReferences if the section is an intro section
            ScrSection section = (ScrSection)CreateEmptySection(book, iSection);

            section.VerseRefEnd = new ScrReference(book.CanonicalNum, 1, isIntro ? 0 : 1,
                                                   book.Cache.LangProject.TranslatedScriptureOA.Versification);
            section.AdjustReferences();

            // Add an empty paragraph to the section head.
            if (createHeadingPara)
            {
                string paraStyle =
                    isIntro ? ScrStyleNames.IntroSectionHead : ScrStyleNames.SectionHead;
                StTxtParaBldr.CreateEmptyPara(book.Cache, section.HeadingOAHvo, paraStyle,
                                              book.Cache.DefaultVernWs);
            }

            // Add an empty paragraph to the section content.
            if (createContentPara)
            {
                string paraStyle =
                    isIntro ? ScrStyleNames.IntroParagraph : ScrStyleNames.NormalParagraph;
                StTxtParaBldr.CreateEmptyPara(book.Cache, section.ContentOAHvo, paraStyle,
                                              book.Cache.DefaultVernWs);
            }

            return(section);
        }
예제 #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a new section using the contents of the given paragraph as it's heading
        /// and the remaining paragraphs of this section as it's content.
        /// </summary>
        /// <param name="iPara">Index of paragraph to be changed to section head.</param>
        /// <param name="cParagraphs">Number of paragraphs changed.</param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public IScrSection ChangeParagraphToSectionHead(int iPara, int cParagraphs)
        {
            ScrBook book     = OwningBook;
            int     iSection = 0;

            while (book.SectionsOS.HvoArray[iSection] != Hvo)
            {
                iSection++;
                Debug.Assert(iSection < book.SectionsOS.Count,
                             "Couldn't find index of section " + Hvo);
            }
            //Set up parameters depending on the type of change
            iSection++;              //New section follows original one.

            ScrSection newSection = (ScrSection)ScrSection.CreateEmptySection(book, iSection);

            // move paragraphs following the changed paragraphs, if any
            if (iPara + cParagraphs < ContentOA.ParagraphsOS.Count)
            {
                StText.MoveTextParagraphs(ContentOA, newSection.ContentOA, iPara + cParagraphs, false);
            }
            else
            {
                // if the paragraph was at the end of a section then we need to create a
                // blank content paragraph in the new section.
                string styleName =
                    IsIntro ? ScrStyleNames.IntroParagraph : ScrStyleNames.NormalParagraph;

                StTxtParaBldr.CreateEmptyPara(book.Cache, newSection.ContentOAHvo, styleName,
                                              Cache.DefaultVernWs);
            }

            // move paragraphs to section head
            StText.MoveTextParagraphs(ContentOA, newSection.HeadingOA, iPara, false);

            // Make sure the references are correct for both the sections.
            AdjustReferences();
            newSection.AdjustReferences();

            // notify views that new section exists
            m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, book.Hvo,
                                (int)ScrBook.ScrBookTags.kflidSections, iSection, 1, 0);

            return(newSection as IScrSection);
        }
예제 #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a new section using the contents of the given section heading as it's content
        /// and the remaining paragraphs above the selection will become the heading of the new
        /// section
        /// </summary>
        /// <param name="iPara">index of paragraph to be changed to section content</param>
        /// <param name="cParagraphs">number of paragraphs to move</param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public IScrSection ChangeParagraphToSectionContent(int iPara, int cParagraphs)
        {
            ScrBook book     = OwningBook;
            int     iSection = 0;

            while (book.SectionsOS.HvoArray[iSection] != Hvo)
            {
                iSection++;
                Debug.Assert(iSection < book.SectionsOS.Count,
                             "Couldn't find index of section " + Hvo);
            }
            ScrSection newSection = (ScrSection)ScrSection.CreateEmptySection(book, iSection);

            // move paragraphs preceding the changed paragraphs, if any
            if (iPara > 0)
            {
                StText.MoveTextParagraphs(HeadingOA, newSection.HeadingOA, iPara - 1, true);
            }
            else
            {
                // if the paragraph was at the beginning of a section then we need to create a
                // blank heading paragraph in the new section.
                string styleName =
                    IsIntro ? ScrStyleNames.IntroSectionHead : ScrStyleNames.SectionHead;

                StTxtParaBldr.CreateEmptyPara(book.Cache, newSection.HeadingOAHvo, styleName,
                                              Cache.DefaultVernWs);
            }

            // move paragraphs to section head
            StText.MoveTextParagraphs(HeadingOA, newSection.ContentOA, cParagraphs - 1, true);

            // Make sure the sections have correct references
            AdjustReferences();
            newSection.AdjustReferences();

            // notify views that new section exists
            m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, book.Hvo,
                                (int)ScrBook.ScrBookTags.kflidSections, iSection, 1, 0);

            return(newSection as IScrSection);
        }