예제 #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initialize a new note.
        /// </summary>
        /// <param name="guidAnnotationType">GUID representing the type of annotation.</param>
        /// <param name="startRef">beginning reference note refers to</param>
        /// <param name="endRef">ending reference note refers to</param>
        /// <param name="beginObj">beginning object note refers to</param>
        /// <param name="endObj">ending object note refers to</param>
        /// <param name="wsSelector">The writing system selector.</param>
        /// <param name="startOffset">The starting character offset.</param>
        /// <param name="endOffset">The ending character offset.</param>
        /// <param name="bldrQuote">Para builder to use to build the Quote paragraph</param>
        /// <param name="bldrDiscussion">Para builder to use to build the Discussion
        /// paragraph</param>
        /// <param name="bldrRecommendation">Para builder to use to build the
        /// Recommendation paragraph</param>
        /// <param name="bldrResolution">Para builder to use to build the Resolution
        /// paragraph</param>
        /// ------------------------------------------------------------------------------------
        public void InitializeNote(Guid guidAnnotationType, BCVRef startRef, BCVRef endRef,
                                   ICmObject beginObj, ICmObject endObj, int wsSelector, int startOffset, int endOffset,
                                   StTxtParaBldr bldrQuote, StTxtParaBldr bldrDiscussion, StTxtParaBldr bldrRecommendation,
                                   StTxtParaBldr bldrResolution)
        {
            AnnotationTypeRA = new CmAnnotationDefn(Cache, guidAnnotationType);
            BeginObjectRA    = beginObj;
            EndObjectRA      = endObj;
            BeginRef         = startRef;
            EndRef           = endRef;
            WsSelector       = wsSelector;
            BeginOffset      = startOffset;
            EndOffset        = endOffset;

            // Now, initialize all the texts
            QuoteOA = new StJournalText();
            InitializeText(bldrQuote, QuoteOA);

            DiscussionOA = new StJournalText();
            InitializeText(bldrDiscussion, DiscussionOA);

            RecommendationOA = new StJournalText();
            InitializeText(bldrRecommendation, RecommendationOA);

            ResolutionOA = new StJournalText();
            InitializeText(bldrResolution, ResolutionOA);
        }
예제 #2
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);
        }
예제 #3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="T:ScrAnnotationInfo"/> class.
 /// </summary>
 /// <param name="guidAnnotationType">GUID representing the annotation type.</param>
 /// <param name="bldrDiscussion">A single Tsstring builder for a one-paragraph
 /// discussion.</param>
 /// <param name="ichOffset">character offset where this annotation belongs in the
 /// "owning" para.</param>
 /// <param name="startReference">The starting Scripture reference of the annotation.</param>
 /// <param name="endReference">The ending Scripture reference of the annotation.</param>
 /// ------------------------------------------------------------------------------------
 public ScrAnnotationInfo(Guid guidAnnotationType, StTxtParaBldr bldrDiscussion,
                          int ichOffset, int startReference, int endReference)
     : this(guidAnnotationType,
            new List <StTxtParaBldr>(new StTxtParaBldr[] { bldrDiscussion }), null, null, null,
            ichOffset, startReference, endReference, DateTime.MinValue)
 {
 }
예제 #4
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Insert a new check result annotation at its correct position in the list.
 /// </summary>
 /// <param name="startRef">beginning reference note refers to</param>
 /// <param name="endRef">ending reference note refers to</param>
 /// <param name="beginObject">id of beginning object note refers to</param>
 /// <param name="endObject">id of ending object note refers to</param>
 /// <param name="checkId">The check id.</param>
 /// <param name="bldrQuote">Para builder to use for the cited text paragraph</param>
 /// <param name="bldrDiscussion">Para builder to use to build the Discussion
 /// paragraph</param>
 /// <returns>note inserted into annotation list</returns>
 /// ------------------------------------------------------------------------------------
 public IScrScriptureNote InsertErrorAnnotation(BCVRef startRef, BCVRef endRef,
                                                ICmObject beginObject, ICmObject endObject, Guid checkId,
                                                StTxtParaBldr bldrQuote, StTxtParaBldr bldrDiscussion)
 {
     return(InsertNote(startRef, endRef, beginObject, endObject, checkId,
                       0, 0, bldrQuote, bldrDiscussion, null, null, GetInsertIndexForRef(startRef)));
 }
예제 #5
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Convert each of the child paragraphs into an ITsString object, and add that object
        /// to the given list. If the paragraph's writing system cannot be found, then the
        /// specified default writing system is used.
        /// </summary>
        /// -----------------------------------------------------------------------------------
        public StTxtParaBldr BuildParagraph(FwStyleSheet styleSheet, int wsDefault)
        {
            StTxtParaBldr bldr;
            int           wsPara = (string.IsNullOrEmpty(IcuLocale) ?
                                    wsDefault : ScrNoteImportManager.GetWsForLocale(IcuLocale));

            bldr = new StTxtParaBldr(styleSheet.Cache);
            string stylename = (string.IsNullOrEmpty(StyleName) ?
                                ScrStyleNames.Remark : StyleName);

            bldr.ParaStylePropsProxy = StyleProxyListManager.GetXmlParaStyleProxy(
                stylename, ContextValues.Annotation, wsDefault);

            foreach (XmlTextRun run in Runs)
            {
                int ws = (string.IsNullOrEmpty(run.IcuLocale) ?
                          wsPara : ScrNoteImportManager.GetWsForLocale(run.IcuLocale));

                run.AddToParaBldr(bldr, ws, styleSheet);
            }

            // OXES supports mixed text so this is designed to handle text that
            // is found in the "para" tag but not in any "span" or "a" tag.
            if (!string.IsNullOrEmpty(m_text))
            {
                XmlTextRun extraText = new XmlTextRun();
                extraText.Text = m_text;
                extraText.AddToParaBldr(bldr, wsPara, styleSheet);
            }

            return(bldr);
        }
예제 #6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Append a new section to the given book, having the specified text as the section
        /// head. The new section will have an empty content text created also.
        /// </summary>
        /// <param name="scrInMemoryCache">in-memory cache to use for testing</param>
        /// <param name="book">The book to which the section is to be appended</param>
        /// <param name="sSectionHead">The text of the new section head. Can be a simple string
        /// or a format string. (See CreateText for the definition of the format string)</param>
        /// <param name="paraStyleName">paragraph style to apply to the section head</param>
        /// <returns>The newly created section</returns>
        /// ------------------------------------------------------------------------------------
        internal static ScrSection CreateSection(ScrInMemoryFdoCache scrInMemoryCache, IScrBook book,
                                                 string sSectionHead, string paraStyleName)
        {
            // Create a section
            ScrSection section = new ScrSection();

            book.SectionsOS.Append(section);

            // Create a section head for this section
            section.HeadingOA = new StText();

            if (sSectionHead.Length == 0 || sSectionHead[0] != '\\')
            {
                // create a simple section head with no character style
                StTxtParaBldr paraBldr = new StTxtParaBldr(scrInMemoryCache.Cache);
                paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(paraStyleName);
                paraBldr.AppendRun(sSectionHead,
                                   StyleUtils.CharStyleTextProps(null, scrInMemoryCache.Cache.DefaultVernWs));
                paraBldr.CreateParagraph(section.HeadingOAHvo);
            }
            else
            {
                // Create a more complex section head from the given format string
                // insert a new para in the title
                StTxtPara para = new StTxtPara();
                section.HeadingOA.ParagraphsOS.Append(para);
                // set the para's fields
                scrInMemoryCache.AddFormatTextToMockedPara(book, para, sSectionHead, scrInMemoryCache.Cache.DefaultVernWs);
                para.StyleRules = StyleUtils.ParaStyleTextProps(paraStyleName);
            }

            section.ContentOA = new StText();
            section.AdjustReferences();
            return(section);
        }
예제 #7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initialize a new note.
        /// </summary>
        /// <param name="guidAnnotationType">GUID representing the type of annotation.</param>
        /// <param name="startRef">beginning reference note refers to</param>
        /// <param name="endRef">ending reference note refers to</param>
        /// <param name="beginObj">beginning object note refers to</param>
        /// <param name="endObj">ending object note refers to</param>
        /// <param name="startOffset">The starting character offset.</param>
        /// <param name="endOffset">The ending character offset.</param>
        /// <param name="bldrQuote">Para builder to use to build the Quote paragraph</param>
        /// <param name="bldrDiscussion">Para builder to use to build the Discussion
        /// paragraph</param>
        /// <param name="bldrRecommendation">Para builder to use to build the
        /// Recommendation paragraph</param>
        /// <param name="bldrResolution">Para builder to use to build the Resolution
        /// paragraph</param>
        /// ------------------------------------------------------------------------------------
        public void InitializeNote(Guid guidAnnotationType, BCVRef startRef, BCVRef endRef,
                                   ICmObject beginObj, ICmObject endObj, int startOffset, int endOffset,
                                   StTxtParaBldr bldrQuote, StTxtParaBldr bldrDiscussion, StTxtParaBldr bldrRecommendation,
                                   StTxtParaBldr bldrResolution)
        {
            AnnotationTypeRA = Services.GetInstance <ICmAnnotationDefnRepository>().GetObject(guidAnnotationType);
            BeginObjectRA    = beginObj;
            EndObjectRA      = endObj;
            BeginRef         = startRef;
            EndRef           = endRef;
            BeginOffset      = startOffset;
            EndOffset        = endOffset;

            // Now, initialize all the texts
            QuoteOA = new StJournalText();
            InitializeText(bldrQuote, QuoteOA);

            DiscussionOA = new StJournalText();
            InitializeText(bldrDiscussion, DiscussionOA);

            RecommendationOA = new StJournalText();
            InitializeText(bldrRecommendation, RecommendationOA);

            ResolutionOA = new StJournalText();
            InitializeText(bldrResolution, ResolutionOA);
        }
예제 #8
0
        public void AppendParagraph()
        {
            CheckDisposed();

            // Build an StTxtPara
            StTxtParaBldr        bldr  = new StTxtParaBldr(Cache);
            IParaStylePropsProxy proxy = new DummyProxy("Para Meister");

            bldr.ParaStylePropsProxy = proxy;
            ITsTextProps textProps = StyleUtils.CharStyleTextProps(null,
                                                                   Cache.LanguageEncodings.Item(0).Hvo);

            bldr.AppendRun("Run 1", textProps);

            StText text  = new StText(Cache, m_text.Hvo);
            int    iPara = text.ParagraphsOS.Count;

            StTxtPara para = bldr.CreateParagraph(text.Hvo);

            // verify paragraph's state
            Assert.IsNotNull(para);
            Assert.AreEqual(proxy.Props, para.StyleRules);
            AssertEx.RunIsCorrect(para.Contents.UnderlyingTsString, 0, "Run 1", null,
                                  m_wsArbitrary);
            Assert.AreEqual(para.Hvo, text.ParagraphsOS[iPara].Hvo);
            // Builder should now be cleared
            Assert.AreEqual(0, bldr.Length);
        }
예제 #9
0
        /// <summary>
        /// attach an annotation describing this failure to the object. *Does Not* remove previous annotations!
        /// </summary>
        /// <remarks> I say it does not remove previous annotations because I haven't thought about how much smarts
        ///  it would take to only remove once associated with this particular failure. So I am stipulating for now that
        ///  the caller should first remove all of the kinds of indications which it might create.</remarks>
        /// <returns></returns>
        protected ICmBaseAnnotation MakeAnnotation()
        {
            //	callar should do something like this:CmBaseAnnotation.RemoveAnnotationsForObject(m_object.Cache, m_object.Hvo);

            ICmBaseAnnotation annotation = (ICmBaseAnnotation)m_cache.LangProject.AnnotationsOC.Add(new CmBaseAnnotation());

            annotation.CompDetails = m_xmlDescription;

            annotation.TextOA = new StText();
            using (StTxtParaBldr paraBldr = new StTxtParaBldr(m_cache))
            {
                //review: I have no idea what this is as to be
                paraBldr.ParaProps = StyleUtils.ParaStyleTextProps("Paragraph");
                //todo: this pretends that the default analysis writing system is also the user
                // interface 1.  but I don't really know what's the right thing to do.
                paraBldr.AppendRun(m_explanation,
                                   StyleUtils.CharStyleTextProps(null, m_cache.DefaultAnalWs));
                paraBldr.CreateParagraph(annotation.TextOAHvo);
            }             // Dispose() frees ICU resources.

            annotation.BeginObjectRA = m_object;
            annotation.Flid          = m_flid;
            annotation.CompDetails   = m_xmlDescription;
            annotation.SourceRA      = m_cache.LangProject.ConstraintCheckerAgent;
            // Although we generated a PropChanged when we actually created the annotation, we need another
            // one now that all its properties have been set, as there may be a filter that excludes it
            // until those properties. Simulate removing and re-adding the new annotation (presumed to be
            // at the end of the collection).
            int chvo = m_cache.LangProject.AnnotationsOC.Count;

            m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_cache.LangProject.Hvo,
                                (int)LangProject.LangProjectTags.kflidAnnotations, chvo - 1, 1, 1);
            return(annotation);
        }
예제 #10
0
        public void CreateTwoParagraphs()
        {
            CheckDisposed();

            // Build First StTxtPara
            StTxtParaBldr        bldr  = new StTxtParaBldr(Cache);
            IParaStylePropsProxy proxy = new DummyProxy("MyParaStyle");

            bldr.ParaStylePropsProxy = proxy;
            ITsTextProps textProps = StyleUtils.CharStyleTextProps(null, m_wsArbitrary);

            bldr.AppendRun("Para 1", textProps);
            StText    text  = new StText(Cache, m_text.Hvo);
            int       iPara = text.ParagraphsOS.Count;
            StTxtPara para1 = bldr.CreateParagraph(text.Hvo, iPara);

            // verify paragraph 1
            AssertEx.RunIsCorrect(para1.Contents.UnderlyingTsString, 0, "Para 1", null,
                                  m_wsArbitrary);

            // Build Second StTxtPara -- Builder should have been cleared
            textProps = StyleUtils.CharStyleTextProps("BringBrangBrung", m_wsArbitrary);
            bldr.AppendRun("Para 2", textProps);
            StTxtPara para2 = bldr.CreateParagraph(text.Hvo, iPara + 1);

            Assert.AreEqual(text.ParagraphsOS[iPara].Hvo, para1.Hvo);
            Assert.AreEqual(text.ParagraphsOS[iPara + 1].Hvo, para2.Hvo);

            // Re-verify paragraph 1
            AssertEx.RunIsCorrect(para1.Contents.UnderlyingTsString, 0, "Para 1", null,
                                  m_wsArbitrary);
            // verify paragraph 2
            AssertEx.RunIsCorrect(para2.Contents.UnderlyingTsString, 0, "Para 2",
                                  "BringBrangBrung", m_wsArbitrary);
        }
예제 #11
0
        public void AppendTwoRuns_WithAndWithoutNamedCharStyles()
        {
            CheckDisposed();

            // Build an StTxtPara
            StTxtParaBldr        bldr  = new StTxtParaBldr(Cache);
            IParaStylePropsProxy proxy = new DummyProxy("Para Meister");

            bldr.ParaStylePropsProxy = proxy;
            ITsTextProps textProps = StyleUtils.CharStyleTextProps(null, m_wsArbitrary);

            bldr.AppendRun("Run 1 ", textProps);
            textProps = StyleUtils.CharStyleTextProps("Italic Run", m_wsArbitrary);
            // verify its length
            Assert.AreEqual(6, bldr.Length);
            // add another run
            bldr.AppendRun("Run 2", textProps);
            StTxtPara para = bldr.CreateParagraph(m_text.Hvo, 1);

            // verify paragraph's state
            Assert.IsNotNull(para);
            Assert.AreEqual(proxy.Props, para.StyleRules);
            AssertEx.RunIsCorrect(para.Contents.UnderlyingTsString, 0, "Run 1 ", null, m_wsArbitrary);
            AssertEx.RunIsCorrect(para.Contents.UnderlyingTsString, 1, "Run 2", "Italic Run", m_wsArbitrary);
            // Builder should now be cleared
            Assert.AreEqual(0, bldr.Length);
        }
예제 #12
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Helper function to add an empty noraml paragraph to the given section.
        /// </summary>
        /// <param name="section">The section where the empty paragraph will be added.</param>
        /// <param name="style">The style for the added paragraph.</param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        protected StTxtPara AddEmptyPara(IScrSection section, string style)
        {
            StTxtParaBldr paraBldr = new StTxtParaBldr(Cache);

            paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(style);
            return(paraBldr.CreateParagraph(section.ContentOA.Hvo));
        }
예제 #13
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Inserts a Scriture annotation for the book currently being imported.
        /// </summary>
        /// <param name="bcvStartReference">The starting BCV reference.</param>
        /// <param name="bcvEndReference">The ending BCV reference.</param>
        /// <param name="obj">The object being annotated (either a paragraph or a ScrBook)</param>
        /// <param name="bldr">The paragraph builder containing the guts of the annotation
        /// description</param>
        /// <param name="guidNoteType">The GUID representing the CmAnnotationDefn to use for
        /// the type</param>
        /// <returns>The newly created annotation</returns>
        /// ------------------------------------------------------------------------------------
        public IScrScriptureNote InsertNote(int bcvStartReference, int bcvEndReference,
                                            ICmObject obj, StTxtParaBldr bldr, Guid guidNoteType)
        {
            IScrScriptureNote note = m_annotations.InsertImportedNote(
                bcvStartReference, bcvEndReference, obj, obj, guidNoteType, bldr);

            return(note);
        }
예제 #14
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sets the cited text for checking error annotation.
        /// </summary>
        /// <param name="citedText">The cited text.</param>
        /// <param name="ws">The writing system.</param>
        /// <returns>Quote for the ScrScriptureNote</returns>
        /// ------------------------------------------------------------------------------------
        private StTxtParaBldr SetCitedText(string citedText, int ws)
        {
            StTxtParaBldr quote = new StTxtParaBldr(m_cache);

            quote.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.Remark);
            // ENHANCE: Cache the run props using a hash table for each writing system
            quote.AppendRun(citedText, StyleUtils.CharStyleTextProps(null, ws));
            return(quote);
        }
예제 #15
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Insert a new note at its correct position in the list.
        /// </summary>
        /// <param name="startRef">beginning reference note refers to</param>
        /// <param name="endRef">ending reference note refers to</param>
        /// <param name="beginObject">id of beginning object note refers to</param>
        /// <param name="endObject">id of ending object note refers to</param>
        /// <param name="guidNoteType">The GUID representing the CmAnnotationDefn to use for
        /// the type</param>
        /// <param name="bldrQuote">Para builder to use to build the Quote paragraph</param>
        /// <param name="bldrDiscussion">Para builder to use to build the Discussion
        ///  paragraph</param>
        /// <param name="bldrRecommendation">Para builder to use to build the
        ///  Recommendation paragraph</param>
        /// <param name="bldrResolution">Para builder to use to build the Resolution
        ///  paragraph</param>
        /// <returns>note inserted into annotation list</returns>
        /// ------------------------------------------------------------------------------------
        public IScrScriptureNote InsertNote(BCVRef startRef, BCVRef endRef,
                                            ICmObject beginObject, ICmObject endObject, Guid guidNoteType, StTxtParaBldr bldrQuote,
                                            StTxtParaBldr bldrDiscussion, StTxtParaBldr bldrRecommendation,
                                            StTxtParaBldr bldrResolution)
        {
            int insertIndex;

            return(InsertNote(startRef, endRef, beginObject, endObject, guidNoteType, -1, 0,
                              bldrQuote, bldrDiscussion, bldrRecommendation, bldrResolution, out insertIndex));
        }
예제 #16
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sets the error message.
        /// </summary>
        /// <param name="formattedMsg">The localized and formatted message.</param>
        /// <returns>Discussion for the ScrScriptureNote</returns>
        /// ------------------------------------------------------------------------------------
        private StTxtParaBldr SetErrorMessage(string formattedMsg)
        {
            StTxtParaBldr discussion = new StTxtParaBldr(m_cache);

            discussion.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.Remark);
            // ENHANCE: Cache the run props for the UI writing system
            discussion.AppendRun(formattedMsg,
                                 StyleUtils.CharStyleTextProps(null, m_cache.DefaultUserWs));
            return(discussion);
        }
예제 #17
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initialize the text for the paragraph with the specified builder, or create an
 /// empty paragraph if the builder is null.
 /// </summary>
 /// <param name="bldr">paragraph builder</param>
 /// <param name="text">StText</param>
 /// ------------------------------------------------------------------------------------
 private void InitializeText(StTxtParaBldr bldr, IStText text)
 {
     if (bldr == null)
     {
         IStTxtPara para = text.AddNewTextPara(ScrStyleNames.Remark);
         para.Contents = TsStringUtils.MakeTss(String.Empty, Cache.DefaultAnalWs);
     }
     else
     {
         bldr.CreateParagraph(text);
     }
 }
예제 #18
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adds to para BLDR.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        internal override void AddToParaBldr(StTxtParaBldr bldr, int ws, FwStyleSheet styleSheet)
        {
            if (string.IsNullOrEmpty(Href))
            {
                throw new Exception("OXESA validation found an invalid URL.");
            }

            bool fSucceeded = EditingHelper.AddHyperlink(bldr.StringBuilder,
                                                         ws, Text, Href, styleSheet);

            Debug.Assert(fSucceeded);
        }
예제 #19
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initialize the text for the paragraph with the specified builder, or create an
 /// empty paragraph if the builder is null.
 /// </summary>
 /// <param name="bldr">paragraph builder</param>
 /// <param name="text">StText</param>
 /// ------------------------------------------------------------------------------------
 private void InitializeText(StTxtParaBldr bldr, IStText text)
 {
     if (bldr == null)
     {
         IStTxtPara para = (StTxtPara)text.ParagraphsOS.Append(new StTxtPara());
         para.Contents.UnderlyingTsString = StringUtils.MakeTss(String.Empty, Cache.DefaultAnalWs);
         para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.Remark);
     }
     else
     {
         bldr.CreateParagraph(text.Hvo);
     }
 }
예제 #20
0
        public void FindOrCreateAnnotation_GuidNotFound()
        {
            StTxtParaBldr     bldr    = new StTxtParaBldr(Cache);
            ScrAnnotationInfo annInfo = new ScrAnnotationInfo(CmAnnotationDefnTags.kguidAnnConsultantNote,
                                                              bldr, 0, 01001001, 01001002);
            IScrScriptureNote newNote = ScrNoteImportManager.FindOrCreateAnnotation(annInfo, Guid.NewGuid());

            Assert.IsNotNull(newNote);
            Assert.IsNull(newNote.BeginObjectRA);
            Assert.IsNull(newNote.EndObjectRA);
            Assert.AreEqual(01001001, newNote.BeginRef);
            Assert.AreEqual(01001002, newNote.EndRef);
        }
예제 #21
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Create a new section, to be owned by the given book. The section will be an intro
        /// section if the isIntro flag is set to <code>true</code>
        /// The contents of the first content paragraph are filled with a single run as
        /// requested. The start and end references for the section are set based on where it's
        /// being inserted in the book.
        /// </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="contentText">The text to be used as the first para in the new section
        /// content</param>
        /// <param name="contentTextProps">The character properties to be applied to the first
        /// para in the new section content</param>
        /// <param name="isIntro">True to create an intro section, false to create a
        /// normal scripture section</param>
        /// <returns>Created section</returns>
        /// ------------------------------------------------------------------------------------
        public static IScrSection CreateScrSection(IScrBook book, int iSection, string contentText,
                                                   ITsTextProps contentTextProps, bool isIntro)
        {
            Debug.Assert(book != null);

            IScrSection section = CreateSectionWithHeadingPara(book, iSection, isIntro);

            // Insert the section contents.
            using (StTxtParaBldr bldr = new StTxtParaBldr(book.Cache))
            {
                bldr.ParaProps = StyleUtils.ParaStyleTextProps(
                    isIntro ? ScrStyleNames.IntroParagraph : ScrStyleNames.NormalParagraph);
                bldr.AppendRun(contentText, contentTextProps);
                bldr.CreateParagraph(section.ContentOAHvo);
            }             // Dispose() frees ICU resources.
            return(section);
        }
예제 #22
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);
        }
예제 #23
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Insert a new note at its correct position in the list.
        /// </summary>
        /// <param name="startRef">beginning reference note refers to</param>
        /// <param name="endRef">ending reference note refers to</param>
        /// <param name="beginObject">id of beginning object to which annotation refers</param>
        /// <param name="endObject">id of ending object to which annotation refers</param>
        /// <param name="guidNoteType">The GUID representing the CmAnnotationDefn to use for
        /// the type</param>
        /// <param name="startOffset">The starting character offset (or -1 to insert a note
        /// after all existing notes having the same start ref).</param>
        /// <param name="endOffset">The ending character offset.</param>
        /// <param name="bldrQuote">Para builder to use to build the Quote paragraph</param>
        /// <param name="bldrDiscussion">Para builder to use to build the Discussion
        /// paragraph</param>
        /// <param name="bldrRecommendation">Para builder to use to build the
        /// Recommendation paragraph</param>
        /// <param name="bldrResolution">Para builder to use to build the Resolution
        /// paragraph</param>
        /// <param name="insertIndex">out: index where annotation was inserted into
        /// annotation list</param>
        /// <returns>note inserted into annotation list</returns>
        /// ------------------------------------------------------------------------------------
        public IScrScriptureNote InsertNote(BCVRef startRef, BCVRef endRef,
                                            ICmObject beginObject, ICmObject endObject, Guid guidNoteType,
                                            int startOffset, int endOffset, StTxtParaBldr bldrQuote, StTxtParaBldr bldrDiscussion,
                                            StTxtParaBldr bldrRecommendation, StTxtParaBldr bldrResolution, out int insertIndex)
        {
            // Determine where to insert the new annotation.
            insertIndex = (startOffset < 0 ? GetInsertIndexForRef(startRef) :
                           GetNewNotesInsertIndex(startRef, beginObject, startOffset));

            if (startOffset < 0)
            {
                startOffset = 0;
            }

            return(InsertNote(startRef, endRef, beginObject, endObject, guidNoteType,
                              startOffset, endOffset, bldrQuote, bldrDiscussion, bldrRecommendation,
                              bldrResolution, insertIndex));
        }
예제 #24
0
        public void RemoveOwnedObjectsForString_Simple()
        {
            CheckDisposed();

            StTxtParaBldr paraBldr = new StTxtParaBldr(Cache);

            paraBldr.ParaProps = StyleUtils.ParaStyleTextProps("Normal");
            paraBldr.AppendRun("Test Paragraph",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            StTxtPara para = paraBldr.CreateParagraph(m_currentText.Hvo);

            m_inMemoryCache.AddFootnote(m_currentFootnotesOS, para, 10, null);
            Assert.AreEqual(1, m_currentFootnotesOS.Count);

            para.RemoveOwnedObjectsForString(5, 12);

            Assert.AreEqual(0, m_currentFootnotesOS.Count);
        }
예제 #25
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Insert a new note at its correct position in the list.
        /// </summary>
        /// <param name="startRef">beginning reference note refers to</param>
        /// <param name="endRef">ending reference note refers to</param>
        /// <param name="beginObject">id of beginning object to which annotation refers</param>
        /// <param name="endObject">id of ending object to which annotation refers</param>
        /// <param name="guidNoteType">The GUID representing the CmAnnotationDefn to use for
        /// the type</param>
        /// <param name="startOffset">The starting character offset.</param>
        /// <param name="endOffset">The ending character offset.</param>
        /// <param name="bldrQuote">Para builder to use to build the Quote paragraph</param>
        /// <param name="bldrDiscussion">Para builder to use to build the Discussion
        /// paragraph</param>
        /// <param name="bldrRecommendation">Para builder to use to build the
        /// Recommendation paragraph</param>
        /// <param name="bldrResolution">Para builder to use to build the Resolution
        /// paragraph</param>
        /// <param name="insertIndex">index where annotation is to be inserted into
        /// annotation list</param>
        /// <returns>note inserted into annotation list</returns>
        /// ------------------------------------------------------------------------------------
        public IScrScriptureNote InsertNote(BCVRef startRef, BCVRef endRef,
                                            ICmObject beginObject, ICmObject endObject, Guid guidNoteType,
                                            int startOffset, int endOffset, StTxtParaBldr bldrQuote, StTxtParaBldr bldrDiscussion,
                                            StTxtParaBldr bldrRecommendation, StTxtParaBldr bldrResolution, int insertIndex)
        {
            IScrScriptureNote annotation = new ScrScriptureNote();

            NotesOS.Insert(insertIndex, annotation);

            // Initialize the annotation.
            ((ScrScriptureNote)annotation).InitializeNote(guidNoteType, startRef, endRef,
                                                          beginObject, endObject, startOffset, endOffset,
                                                          bldrQuote, bldrDiscussion, bldrRecommendation, bldrResolution);

            annotation.SourceRA = annotation.AnnotationType == NoteType.CheckingError ?
                                  m_cache.LangProject.DefaultComputerAgent : m_cache.LangProject.DefaultUserAgent;

            return(annotation);
        }
예제 #26
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);
        }
예제 #27
0
        public void CreateParagraphEmpty()
        {
            CheckDisposed();

            // create an StTxtPara
            StTxtParaBldr        bldr  = new StTxtParaBldr(Cache);
            IParaStylePropsProxy proxy = new DummyProxy("EmptyPara");

            bldr.ParaStylePropsProxy = proxy;
            ITsTextProps textProps = StyleUtils.CharStyleTextProps(null, m_wsArbitrary);

            bldr.AppendRun(string.Empty, textProps);
            Assert.AreEqual(0, bldr.Length);
            StTxtPara para = bldr.CreateParagraph(m_text.Hvo, 1);

            // verify paragraph's state
            Assert.IsNotNull(para);
            Assert.AreEqual(proxy.Props, para.StyleRules);
            Assert.AreEqual(1, para.Contents.UnderlyingTsString.RunCount);
            Assert.IsNull(para.Contents.Text);
        }
예제 #28
0
        public void TrimTrailingSpaceWithNoSpaceAtEnd()
        {
            CheckDisposed();

            // Build an StTxtPara
            using (StTxtParaBldr bldr = new StTxtParaBldr(Cache))
            {
                IParaStylePropsProxy proxy = new DummyProxy("Whatever");
                bldr.ParaStylePropsProxy = proxy;
                ITsTextProps textProps = StyleUtils.CharStyleTextProps(null, m_wsArbitrary);
                bldr.AppendRun("My run", textProps);
                Assert.AreEqual(6, bldr.Length);
                // Attempt to trim the space off the end -- nothing should happen.
                bldr.TrimTrailingSpaceInPara();
                Assert.AreEqual(6, bldr.Length);
                StTxtPara para = bldr.CreateParagraph(m_text.Hvo, 1);
                // verify paragraph contents
                AssertEx.RunIsCorrect(para.Contents.UnderlyingTsString, 0, "My run", null,
                                      m_wsArbitrary);
            }             // Dispose() frees ICU resources.
        }
예제 #29
0
        public void VerseIterator_InitialText()
        {
            // Create section 1 for Genesis.
            IScrSection section1 = CreateSection(m_genesis, "My aching head!", 01001001, 01001001);

            // build paragraph for section 1
            StTxtParaBldr paraBldr = new StTxtParaBldr(Cache);

            paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph;
            paraBldr.AppendRun("Some initial text. ",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            paraBldr.AppendRun("5-6", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber,
                                                                    Cache.DefaultVernWs));
            paraBldr.AppendRun("Verses 5-6.",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            IScrTxtPara hvoS1Para = (IScrTxtPara)paraBldr.CreateParagraph(section1.ContentOA);


            // Create an iterator to test
            m_bookMerger.CreateVerseIteratorForStText(section1.ContentOA);

            // Verify section 1 content
            ScrVerse scrVerse = m_bookMerger.NextVerseInStText();

            Assert.AreEqual(hvoS1Para, scrVerse.Para);
            Assert.AreEqual(01001001, scrVerse.StartRef);
            Assert.AreEqual(01001001, scrVerse.EndRef);
            Assert.AreEqual("Some initial text. ", scrVerse.Text.Text);
            Assert.AreEqual(0, scrVerse.VerseStartIndex);

            scrVerse = m_bookMerger.NextVerseInStText();
            Assert.AreEqual(hvoS1Para, scrVerse.Para);
            Assert.AreEqual(01001005, scrVerse.StartRef);
            Assert.AreEqual(01001006, scrVerse.EndRef);
            Assert.AreEqual("5-6Verses 5-6.", scrVerse.Text.Text);
            Assert.AreEqual(19, scrVerse.VerseStartIndex);

            Assert.IsNull(m_bookMerger.NextVerseInStText());
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Inserts a note referencing the currently selected paragraph.
        /// </summary>
        /// <param name="noteType">Type of note</param>
        /// <param name="startRef">reference at beginning of selection</param>
        /// <param name="endRef">reference at end of selection</param>
        /// <param name="topObj">The object where quoted text begins.</param>
        /// <param name="bottomObj">The object where quoted text ends.</param>
        /// <param name="startOffset">The starting character offset.</param>
        /// <param name="endOffset">The ending character offset.</param>
        /// <param name="tssQuote">The text of the quote.</param>
        /// <returns>The inserted note</returns>
        /// ------------------------------------------------------------------------------------
        public virtual IScrScriptureNote InsertNote(ICmAnnotationDefn noteType, BCVRef startRef,
                                                    BCVRef endRef, ICmObject topObj, ICmObject bottomObj,
                                                    int startOffset, int endOffset, ITsString tssQuote)
        {
            CheckDisposed();

            int iPos;

            IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[startRef.Book - 1];

            StTxtParaBldr quoteParaBldr = new StTxtParaBldr(m_cache);

            quoteParaBldr.ParaStyleName = ScrStyleNames.Remark;
            quoteParaBldr.StringBuilder.ReplaceTsString(0, 0, tssQuote);
            IScrScriptureNote annotation = annotations.InsertNote(startRef, endRef, topObj, bottomObj,
                                                                  noteType.Guid, startOffset, endOffset, quoteParaBldr, null, null, null,
                                                                  out iPos);

            RegisterScrollCallBack(startRef.Book, iPos);

            // REVIEW: Do we need to create a synch record?
            return(annotation);
        }