/// ------------------------------------------------------------------------------------ /// <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); }
/// ------------------------------------------------------------------------------------ /// <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); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Divides the current section into two sections with section index iSection and /// iSection + 1. Moves the selected paragraphs from the heading of /// the current section into the content of the current section. /// </summary> /// <param name="iSection">index of the current section</param> /// <param name="iParaStart">index of the first heading paragraph to be moved into /// content</param> /// <param name="iParaEnd">index of the last heading paragraph to be moved into /// content</param> /// ------------------------------------------------------------------------------------ public void SplitSectionHeading(int iSection, int iParaStart, int iParaEnd) { // Create empty section after the current section ScrSection newSection = (ScrSection)ScrSection.CreateEmptySection(OwningBook, iSection + 1); // Move Heading and Content to new section: // the heading paras after selection, StText.MoveTextParagraphs(this.HeadingOA, newSection.HeadingOA, iParaEnd + 1, false); // all content paras StText.MoveTextParagraphs(this.ContentOA, newSection.ContentOA, 0, false); // Move current selection in heading to content // note: because we already moved the "heading paras after selection" // we will now move all paras from start of selection MoveHeadingParasToContent(iParaStart); // Adjust references for the two sections AdjustReferences(); newSection.AdjustReferences(); Cache.PropChanged(OwnerHVO, (int)ScrBook.ScrBookTags.kflidSections, iSection + 1, 1, 0); }