Beispiel #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Insert end of paragraph or section marks, if needed. Highlight the markers if
        /// they are part of a diff range in a paragraph split, merge or structure change.
        /// </summary>
        /// <param name="vwenv"></param>
        /// <param name="hvoPara"></param>
        /// ------------------------------------------------------------------------------------
        protected override void InsertEndOfParaMarks(IVwEnv vwenv, int hvoPara)
        {
            Difference rootDiff = m_Differences.CurrentDifference;
            bool       fParaNeedsBoundaryHighlight = NeedsBoundaryHighlight(rootDiff, hvoPara);

            if (m_target == LayoutViewTarget.targetDraft && fParaNeedsBoundaryHighlight)
            {
                // Set up for an end mark.

                // If this is the last paragraph of a section then insert an
                // end of section mark, otherwise insert a paragraph mark.
                VwBoundaryMark boundaryMark;
                StTxtPara      para      = new StTxtPara(m_cache, hvoPara);
                StText         text      = new StText(m_cache, para.OwnerHVO);
                int[]          paraArray = text.ParagraphsOS.HvoArray;
                if (hvoPara == paraArray[paraArray.Length - 1])
                {
                    boundaryMark = fParaNeedsBoundaryHighlight ? VwBoundaryMark.endofSectionHighlighted :
                                   VwBoundaryMark.endOfSection;              // "§"
                }
                else
                {
                    boundaryMark = fParaNeedsBoundaryHighlight ? VwBoundaryMark.endOfParagraphHighlighted :
                                   VwBoundaryMark.endOfParagraph;              // "¶"
                }
                vwenv.SetParagraphMark(boundaryMark);
            }
        }
Beispiel #2
0
        public void FindPrevBackTrans_SecondBookTitleToFirstBook()
        {
            CheckDisposed();

            // add new book with a BT
            IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(3, "Leviticus");
            StText   text = m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, "Title for Leviticus");

            m_scrInMemoryCache.AddBtToMockedParagraph((StTxtPara)text.ParagraphsOS[0],
                                                      Cache.DefaultAnalWs);

            // add BT for last para of first book
            ScrTxtPara para = new ScrTxtPara(Cache, m_book.SectionsOS[2].ContentOA.ParagraphsOS.HvoArray[0]);

            m_inMemoryCache.AddBtToMockedParagraph(para, Cache.DefaultAnalWs);
            m_btDraftView.RefreshDisplay();

            m_btDraftView.SetInsertionPoint((int)ScrBook.ScrBookTags.kflidTitle, 1, 0);

            m_btDraftView.CallPrevUnfinishedBackTrans();
            SelectionHelper helper = m_btDraftView.EditingHelper.CurrentSelection;

            Assert.AreEqual(0, helper.IchAnchor);
            Assert.AreEqual(0, m_btDraftView.TeEditingHelper.BookIndex);
            Assert.AreEqual(2, m_btDraftView.TeEditingHelper.SectionIndex);
            Assert.AreEqual(0, m_btDraftView.ParagraphIndex);
            Assert.AreEqual((int)ScrSection.ScrSectionTags.kflidContent,
                            m_btDraftView.EditingHelper.CurrentSelection.LevelInfo[2].tag);
            Assert.IsFalse(m_btDraftView.TeEditingHelper.InBookTitle);
        }
Beispiel #3
0
        public void UserPromptForBookTitleWithEmptyPara()
        {
            CheckDisposed();

            // Set up title with an empty paragraph
            StText title = m_inMemoryCache.AddTitleToMockedBook(m_book.Hvo, m_emptyTsString,
                                                                StyleUtils.ParaStyleTextProps(ScrStyleNames.MainBookTitle));

            Options.ShowEmptyParagraphPromptsSetting = true;

            DummyTeStVc stVc = new DummyTeStVc(m_inMemoryCache.Cache, m_inMemoryCache.Cache.DefaultVernWs);

            CreateExpectedUserPrompt(stVc, title.ParagraphsOS.FirstItem.Hvo,
                                     (int)ScrBook.ScrBookTags.kflidTitle, (int)StTxtPara.StTxtParaTags.kflidContents);

            m_vwenvMock.ExpectAndReturn("CurrentObject", title.ParagraphsOS.FirstItem.Hvo);
            IVwEnv vwEnv      = (IVwEnv)m_vwenvMock.MockInstance;
            bool   fTextAdded = stVc.CallInsertUserPrompt(vwEnv,
                                                          title.ParagraphsOS.FirstItem.Hvo);

            Assert.IsTrue(fTextAdded, "User prompt not added");
            ITsString text = stVc.DisplayVariant(vwEnv, SimpleRootSite.kTagUserPrompt, null,
                                                 (int)ScrBook.ScrBookTags.kflidTitle);

            string difference;
            bool   fEqual = TsStringHelper.TsStringsAreEqual(
                ExpectedUserPrompt("Type book title for Philemon here", m_inMemoryCache.Cache.DefaultVernWs),
                text, out difference);

            Assert.IsTrue(fEqual, difference);
            m_vwenvMock.Verify();
        }
Beispiel #4
0
                public override void ShowObject(int hvoRoot, string layoutName)
                {
                    int hvoShowObj = hvoRoot;
                    int clsid      = Cache.GetClassOfObject(hvoRoot);
                    int hvoStText  = 0;

                    if (clsid == CmBaseAnnotation.kClassId)                     // RecordClerk is tracking the annotation
                    {
                        // This pane, as well as knowing how to work with a record list of Texts, knows
                        // how to work with one of CmBaseAnnotations, that is, a list of occurrences of
                        // a word.
                        int annHvo  = hvoRoot;
                        int hvoPara = Cache.MainCacheAccessor.get_ObjectProp(annHvo, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginObject);
                        hvoStText  = Cache.GetOwnerOfObject(hvoPara);
                        hvoShowObj = hvoStText;
                    }
                    else
                    {
                        hvoStText = hvoRoot;
                    }
                    StText stText = new StText(Cache, hvoStText);

                    if (stText.OwningFlid == (int)FDO.Ling.Text.TextTags.kflidContents)
                    {
                        hvoShowObj = stText.OwnerHVO;
                    }
                    base.ShowObject(hvoShowObj, layoutName);
                }
        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);
        }
        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);
        }
Beispiel #7
0
        public void FindNextBackTrans_SectionContentToTitle()
        {
            CheckDisposed();

            // add new book
            IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(3, "Leviticus");
            StText   text = m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, "Title for Leviticus");
            // add BT for last para of first book
            ScrTxtPara para = new ScrTxtPara(Cache, m_book.SectionsOS[2].ContentOA.ParagraphsOS.HvoArray[0]);

            m_inMemoryCache.AddBtToMockedParagraph(para, Cache.DefaultAnalWs);

            // add BT for title para of the last book
            para = new ScrTxtPara(Cache, text.ParagraphsOS.HvoArray[0]);
            m_inMemoryCache.AddBtToMockedParagraph(para, Cache.DefaultAnalWs);
            m_btDraftView.RefreshDisplay();

            int iLastSectionInExodus = m_book.SectionsOS.Count - 1;

            m_btDraftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidContent,
                                            0, iLastSectionInExodus,
                                            m_book.SectionsOS[iLastSectionInExodus].ContentOA.ParagraphsOS.Count - 1);

            m_btDraftView.CallNextUnfinishedBackTrans();
            SelectionHelper helper = m_btDraftView.EditingHelper.CurrentSelection;

            Assert.AreEqual(0, helper.IchAnchor);
            Assert.AreEqual(1, m_btDraftView.TeEditingHelper.BookIndex);
            Assert.AreEqual(-1, m_btDraftView.TeEditingHelper.SectionIndex);
            Assert.AreEqual(0, m_btDraftView.ParagraphIndex);
            Assert.IsTrue(m_btDraftView.TeEditingHelper.InBookTitle);
        }
Beispiel #8
0
        /// <summary>
        /// Analyze the StText indicated by hvoText. Return an array of ITsStrings
        /// representing the words of the text. Add to gni the information it
        /// needs about the occurrences of each word.
        /// </summary>
        public void Init()
        {
            // Get a data cache
            m_cache = FDO.FdoCache.Create("TestLangProj");
            m_txt   = new StText(m_cache, m_hvoText);
            BuildConcData();

            this.mainControl = new MultiLevelConc(m_cache, m_alCharSummaries);

            this.SuspendLayout();
            //
            //  mainControl
            //
            this.mainControl.BackColor = System.Drawing.SystemColors.Window;
            this.mainControl.ForeColor = System.Drawing.SystemColors.WindowText;
            this.mainControl.Location  = new System.Drawing.Point(16, 32);            // Review JohnT: compute from container info?
            this.mainControl.Name      = "ConcSampleSub";
            this.mainControl.Dock      = DockStyle.Fill;
            //this.mainControl.Size = new System.Drawing.Size(232, 192); // Review JohnT: compute from container info?
            this.mainControl.TabIndex = 0;

            //
            // Main window (after contained view, following model of HellowView; maybe so
            // we get an appropriate OnSize for the contained view when sizing the main one?
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize        = new System.Drawing.Size(400, 400);
            this.Controls.Add(this.mainControl);
            this.Name = "ConcSample";             // Revie JohnT: what's the use of each of these?
            this.Text = "ConcSample";

            this.ResumeLayout(false);
        }
Beispiel #9
0
        public override void Initialize()
        {
            CheckDisposed();
            base.Initialize();
            //m_inMemoryCache.InitializeAnnotationDefs();
            InstallVirtuals(@"Language Explorer\Configuration\Words\AreaConfiguration.xml",
                            new string[] { "SIL.FieldWorks.IText.ParagraphSegmentsVirtualHandler", "SIL.FieldWorks.IText.OccurrencesInTextsVirtualHandler" });
            m_wsVern  = Cache.DefaultVernWs;
            m_wsTrans = Cache.DefaultAnalWs;
            m_text    = new Text();
            Cache.LangProject.TextsOC.Add(m_text);
            m_para = new StTxtPara();
            StText text = new StText();

            m_text.ContentsOA = text;
            text.ParagraphsOS.Append(m_para);
            m_trans = new CmTranslation();
            m_para.TranslationsOC.Add(m_trans);
            kflidFT       = StTxtPara.SegmentFreeTranslationFlid(Cache);
            kflidSegments = StTxtPara.SegmentsFlid(Cache);
            m_btPoss      = Cache.LangProject.TranslationTagsOA.LookupPossibilityByGuid(
                LangProject.kguidTranBackTranslation);
            m_trans.TypeRA        = m_btPoss;
            m_fWasUseScriptDigits = Cache.LangProject.TranslatedScriptureOA.UseScriptDigits;
            Cache.LangProject.TranslatedScriptureOA.UseScriptDigits = false;
            // do we need to set status?
        }
Beispiel #10
0
 public void Dispose()
 {
     m_stText    = null;
     m_tsf       = null;
     m_text      = null;
     m_firstPara = null;
     m_cache     = null;
 }
Beispiel #11
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Constructs ParaNode map using the paragraph.
        /// </summary>
        /// <param name="para">The given paragraph.</param>
        /// ------------------------------------------------------------------------------------
        private void ConstructFromPara(StTxtPara para)
        {
            // Get the iPara first
            m_location[kParaIndex] = para.IndexInOwner;

            // Prepare to get the others
            StText text       = new StText(para.Cache, para.OwnerHVO);
            int    hvoOwner   = para.Cache.GetOwnerOfObject(text.Hvo);
            int    ownerClass = para.Cache.GetClassOfObject(hvoOwner);

            // If the ownerClass is a book, we know that sections are not relevant
            // to this paragraph and can process accordingly
            if (ownerClass == ScrBook.kClassId)
            {
                // If we've got a title, we can set the rest in short order
                // (we know that there are no sections)
                Debug.Assert(text.OwningFlid == (int)ScrBook.ScrBookTags.kflidTitle);
                m_location[kSectionFlidIndex] = 0;
                m_location[kSectionIndex]     = 0;
                m_location[kBookFlidIndex]    = kTitle;

                ScrBook book = new ScrBook(para.Cache, text.OwnerHVO);
                m_location[kBookIndex] = book.IndexInOwner;
            }
            // Otherwise, we'll need to use the section data
            else if (ownerClass == ScrSection.kClassId)
            {
                // Since we have sections, get the flid and set others based upon it
                int sectionFlid = text.OwningFlid;
                if (sectionFlid == (int)ScrSection.ScrSectionTags.kflidHeading)
                {
                    m_location[kSectionFlidIndex] = kHeading;
                }
                else if (sectionFlid == (int)ScrSection.ScrSectionTags.kflidContent)
                {
                    m_location[kSectionFlidIndex] = kContent;
                }
                // If it was not one of these types, something is wrong, it's an invalid
                // flid
                else
                {
                    Debug.Assert(false);
                }

                ScrSection section = new ScrSection(para.Cache, text.OwnerHVO);
                m_location[kSectionIndex]  = section.IndexInOwner;
                m_location[kBookFlidIndex] = kSections;

                m_location[kBookIndex] = section.OwningBook.IndexInOwner;
            }
            else
            {
                Debug.Assert(false);
            }

            // default char offset
            m_location[kCharIndex] = 0;
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adds a paragraph to the database
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected IStTxtPara AddParagraph()
        {
            IStText text = new StText(Cache, m_inMemoryCache.NewHvo(StFootnote.kClassId));

            m_inMemoryCache.CacheAccessor.AppendToFdoVector(m_hvoRoot, m_flidContainingTexts,
                                                            text.Hvo);

            return(m_scrInMemoryCache.AddParaToMockedText(text.Hvo, string.Empty));
        }
Beispiel #13
0
 public DiscourseTestHelper(FdoCache cache)
 {
     m_cache           = cache;
     m_tsf             = TsStrFactoryClass.Create();
     m_text            = (Text)Cache.LangProject.TextsOC.Add(new Text());
     m_stText          = new StText();
     m_text.ContentsOA = m_stText;
     m_firstPara       = MakeParagraph();
 }
Beispiel #14
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Moves one or more paragraphs from the content of one section to the beginning of
        /// the heading of the following section. The paragraphs from the given index to the
        /// last content paragraph are moved.
        /// </summary>
        /// <param name="cache">the fdocache</param>
        /// <param name="book">the current book</param>
        /// <param name="iSection">index of the section we move paragraphs from</param>
        /// <param name="indexFirstPara">index of the first content paragraph to be moved</param>
        /// ------------------------------------------------------------------------------------
        public static void MoveContentParasToNextSectionHeading(FdoCache cache, ScrBook book,
                                                                int iSection, int indexFirstPara)
        {
            Debug.Assert(iSection < book.SectionsOS.Count - 1);
            IScrSection origSection = book.SectionsOS[iSection];
            IScrSection nextSection = book.SectionsOS[iSection + 1];

            // Copy the paragraphs from the section content to the next section heading
            StText.MoveTextParagraphs(origSection.ContentOA, nextSection.HeadingOA,
                                      indexFirstPara, false);
        }
Beispiel #15
0
        public void MoveAllParagraphs()
        {
            CheckDisposed();

            int cHeadingParas = m_section.HeadingOA.ParagraphsOS.Count;
            int cContentParas = m_section.ContentOA.ParagraphsOS.Count;

            StText.MoveTextContents(m_section.HeadingOA, m_section.ContentOA, false);

            Assert.AreEqual(cContentParas + cHeadingParas, m_section.ContentOA.ParagraphsOS.Count);
            Assert.AreEqual(0, m_section.HeadingOA.ParagraphsOS.Count);
        }
Beispiel #16
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Moves the requested number of paragraphs from the heading of one section to the end
        /// of the content of the previous section.
        /// </summary>
        /// <param name="cache">the fdocache</param>
        /// <param name="book">the current book</param>
        /// <param name="iSection">index of the section we move paragraphs from</param>
        /// <param name="indexLastPara">index of the last heading paragraph to be moved</param>
        /// <returns>number of paragraphs in previous section before move (use as index
        /// of first moved paragraph)</returns>
        /// ------------------------------------------------------------------------------------
        public static int MoveHeadingToPreviousSectionContent(FdoCache cache, ScrBook book,
                                                              int iSection, int indexLastPara)
        {
            IScrSection prevSection    = book.SectionsOS[iSection - 1];
            IScrSection origSection    = book.SectionsOS[iSection];           //this*************
            int         cInitParaCount = prevSection.ContentOA.ParagraphsOS.Count;

            // Copy the paragraphs from the section heading to the previous section content
            StText.MoveTextParagraphs(origSection.HeadingOA, prevSection.ContentOA,
                                      indexLastPara, true);

            return(cInitParaCount);
        }
Beispiel #17
0
        public void EnterKey_InBtSectionTitle()
        {
            CheckDisposed();

            IScrBook book  = m_scrInMemoryCache.AddBookToMockedScripture(2, "Exodus");
            StText   title = m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, "Exodus");

            m_btDraftView.BookFilter.Insert(0, book.Hvo);
            IScrSection section  = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo);
            StTxtPara   headPara = m_scrInMemoryCache.AddSectionHeadParaToSection(
                section.Hvo, "The first section", ScrStyleNames.SectionHead);

            // Construct a parent paragraph
            StTxtPara parentPara = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo,
                                                                                    ScrStyleNames.NormalParagraph);

            m_scrInMemoryCache.AddRunToMockedPara(parentPara, "1", ScrStyleNames.ChapterNumber);
            m_scrInMemoryCache.AddRunToMockedPara(parentPara, "1", ScrStyleNames.VerseNumber);
            m_scrInMemoryCache.AddRunToMockedPara(parentPara, "uno ", null);
            section.AdjustReferences();

            // Construct the initial back translation.
            int            wsBt       = m_inMemoryCache.Cache.DefaultAnalWs;
            ICmTranslation titleTrans = m_inMemoryCache.AddBtToMockedParagraph((StTxtPara)title.ParagraphsOS[0], wsBt);

            m_inMemoryCache.AddRunToMockedTrans(titleTrans, wsBt, "Exodo", ScrStyleNames.MainBookTitle);
            ICmTranslation headingTrans = m_inMemoryCache.AddBtToMockedParagraph(headPara, wsBt);

            m_inMemoryCache.AddRunToMockedTrans(headingTrans, wsBt, "BT heading", ScrStyleNames.Header);
            ICmTranslation paraTrans = m_inMemoryCache.AddBtToMockedParagraph(parentPara, wsBt);

            m_inMemoryCache.AddRunToMockedTrans(paraTrans, wsBt, "one", null);

            // Set IP at the start of the title.
            m_btDraftView.Refresh();
            m_btDraftView.RootBox.MakeSimpleSel(true, false, false, true);
            m_btDraftView.OnKeyPress(new KeyPressEventArgs('\r'));

            // Verify that the selection has moved to the start of the BT of the section Head.
            IVwSelection vwsel = m_btDraftView.RootBox.Selection;
            int          ich, hvo, textTag, enc;
            bool         fAssocPrev;
            ITsString    tss;

            vwsel.TextSelInfo(false, out tss, out ich, out fAssocPrev, out hvo, out textTag,
                              out enc);
            Assert.AreEqual((int)CmTranslation.CmTranslationTags.kflidTranslation, textTag);
            Assert.AreEqual(headingTrans.Hvo, hvo, "Current paragraph should first section head.");
            Assert.AreEqual(0, ich);             // selection is at start of paragraph
        }
Beispiel #18
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Merges the heading and content of this section into the previous section content.
        /// </summary>
        /// <param name="cache">the fdocache</param>
        /// <param name="book">the current book</param>
        /// <param name="iSection">index of the section to be moved</param>
        /// <returns>number of paragraphs in previous section before merge (use as index
        /// of first moved paragraph)</returns>
        /// ------------------------------------------------------------------------------------
        public static int MergeIntoPreviousSectionContent(FdoCache cache, ScrBook book, int iSection)
        {
            ScrSection prevSection    = (ScrSection)book.SectionsOS[iSection - 1];
            ScrSection origSection    = (ScrSection)book.SectionsOS[iSection];
            int        cInitParaCount = prevSection.ContentOA.ParagraphsOS.Count;

            StText.MoveTextContents(origSection.HeadingOA, prevSection.ContentOA, true);
            StText.MoveTextContents(origSection.ContentOA, prevSection.ContentOA, true);

            book.SectionsOS.RemoveAt(iSection);

            // Number of paragraphs originally in the target section
            return(cInitParaCount);
        }
Beispiel #19
0
        public override void Initialize()
        {
            CheckDisposed();
            base.Initialize();
            m_inMemoryCache.InitializeAnnotationDefs();
            InstallVirtuals(@"Language Explorer\Configuration\Words\AreaConfiguration.xml",
                            new string[] { "SIL.FieldWorks.IText.ParagraphSegmentsVirtualHandler", "SIL.FieldWorks.IText.OccurrencesInTextsVirtualHandler" });
            m_text = new Text();
            Cache.LangProject.TextsOC.Add(m_text);
            m_para = new StTxtPara();
            StText text = new StText();

            m_text.ContentsOA = text;
            text.ParagraphsOS.Append(m_para);
        }
Beispiel #20
0
        public bool OnParseWordsInCurrentText(object argument)
        {
            CheckDisposed();

            StText text = CurrentText;

            if (text != null)
            {
                if (Connection == null)
                {
                    ConnectToParser(false);
                }
                UpdateWordformsInText(text);
            }
            return(true);               //we handled this.
        }
Beispiel #21
0
        public void FindNextBackTrans_SectionContentToNextBook_TitleFinished()
        {
            CheckDisposed();

            // add new book
            IScrBook    book    = m_scrInMemoryCache.AddBookToMockedScripture(3, "Leviticus");
            StText      text    = m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, "Title for Leviticus");
            IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo);

            m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Heading",
                                                           ScrStyleNames.SectionHead);
            // add BT for last para of first book
            ScrTxtPara para = new ScrTxtPara(Cache, m_book.SectionsOS[2].ContentOA.ParagraphsOS.HvoArray[0]);

            m_inMemoryCache.AddBtToMockedParagraph(para, Cache.DefaultAnalWs);

            // add BT for title para of the last book
            para = new ScrTxtPara(Cache, text.ParagraphsOS.HvoArray[0]);
            ICmTranslation trans = m_inMemoryCache.AddBtToMockedParagraph(para,
                                                                          Cache.DefaultAnalWs);

            m_btDraftView.SetTransStatus(trans, BackTranslationStatus.Finished);

            // add BT for the first section head of the last book
            para = new ScrTxtPara(Cache, book.SectionsOS[0].HeadingOA.ParagraphsOS.HvoArray[0]);
            m_inMemoryCache.AddBtToMockedParagraph(para, Cache.DefaultAnalWs);
            m_btDraftView.RefreshDisplay();

            int iLastSectionInExodus = m_book.SectionsOS.Count - 1;

            m_btDraftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidContent,
                                            0, iLastSectionInExodus,
                                            m_book.SectionsOS[iLastSectionInExodus].ContentOA.ParagraphsOS.Count - 1);

            m_btDraftView.CallNextUnfinishedBackTrans();
            SelectionHelper helper = m_btDraftView.EditingHelper.CurrentSelection;

            Assert.AreEqual(0, helper.IchAnchor);
            Assert.AreEqual(1, m_btDraftView.TeEditingHelper.BookIndex);
            Assert.AreEqual(0, m_btDraftView.TeEditingHelper.SectionIndex);
            Assert.AreEqual(0, m_btDraftView.ParagraphIndex);
            Assert.AreEqual((int)ScrSection.ScrSectionTags.kflidHeading,
                            m_btDraftView.EditingHelper.CurrentSelection.LevelInfo[2].tag);
            Assert.IsFalse(m_btDraftView.TeEditingHelper.InBookTitle);
        }
Beispiel #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);
        }
Beispiel #23
0
        /// <summary>
        /// Put all (unique) wordforms of the text in the medium priority queue of the Parser
        /// </summary>
        /// <param name="text"></param>
        public void UpdateWordformsInText(StText text)
        {
            CheckDisposed();

            int[] aiWordformHvos = text.UniqueWordforms();

            ParserConnection con = Connection;

            if (con != null)
            {
                ParserScheduler parser = con.Parser;
                if (parser != null)
                {
                    parser.LoadGrammarAndLexiconIfNeeded();
                    parser.ScheduleWordformsForUpdate(aiWordformHvos, WordWorks.Parser.ParserScheduler.Priority.soon);
                }
            }
        }
        public void PasteSelectionSpanningTwoSections()
        {
            StText title = m_scrInMemoryCache.AddTitleToMockedBook(m_gen.Hvo, "paragraph with main title style");

            m_hvoRoot = title.Hvo;

            // The IntroParagraph style in a book title would be illegal in TE, but we're not TE.
            // We're just a test that needs two paragraphs with different styles.
            StTxtPara titlePara2 = m_scrInMemoryCache.AddParaToMockedText(m_hvoRoot, ScrStyleNames.IntroParagraph);

            m_scrInMemoryCache.AddRunToMockedPara(titlePara2, "paragraph with different style",
                                                  m_inMemoryCache.Cache.DefaultVernWs);

            ShowForm();

            // Make a selection from the top of the view to the bottom.
            IVwSelection sel0 = m_basicView.RootBox.MakeSimpleSel(true, false, false, false);
            IVwSelection sel1 = m_basicView.RootBox.MakeSimpleSel(false, false, false, false);

            m_basicView.RootBox.MakeRangeSelection(sel0, sel1, true);

            // Copy the selection and then paste it over the existing selection.
            // This is an illegal paste, so the paste will fail.
            // However, we expect the contents to remain intact.
            Assert.IsTrue(m_basicView.EditingHelper.CopySelection());
            // Select just a single word in the text to confirm the paste operation better.
            sel0.GrowToWord();
            m_basicView.m_OnInsertDiffParasResponse  = VwInsertDiffParaResponse.kidprFail;
            m_inMemoryCache.MockActionHandler.Strict = true;
            m_inMemoryCache.MockActionHandler.Expect("BeginUndoTask", "&Undo Paste", "&Redo Paste");
            // We don't really CARE whether we get these additional Begin/EndUndoTask calls, but we do, so we have to 'expect' them.
            // There is only one EndUndoTask because we intentionally make the paste fail (by having the mock return kidprFail).
            m_inMemoryCache.MockActionHandler.Expect("BeginUndoTask", "&Undo Typing", "&Redo Typing");
            m_inMemoryCache.MockActionHandler.Expect("EndUndoTask");
            //m_inMemoryCache.MockActionHandler.Expect("AddAction", new IsAnything());
            m_inMemoryCache.MockActionHandler.Expect("Rollback", 0);
            m_basicView.EditingHelper.PasteClipboard(false);

            m_inMemoryCache.MockActionHandler.Verify();
            // GrowToWord causes a Char Property Engine to be created, and somehow the test runner fails if we don't
            // shut the factory down.
            m_inMemoryCache.Cache.LanguageWritingSystemFactoryAccessor.Shutdown();
        }
Beispiel #25
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);
        }
 public override void Initialize()
 {
     CheckDisposed();
     base.Initialize();
     InstallVirtuals(@"Language Explorer\Configuration\Words\AreaConfiguration.xml",
                     new string[] { "SIL.FieldWorks.IText.ParagraphSegmentsVirtualHandler", "SIL.FieldWorks.IText.OccurrencesInTextsVirtualHandler" });
     m_wsVern  = Cache.DefaultVernWs;
     m_wsTrans = Cache.DefaultAnalWs;
     m_book    = new ScrBook();
     Cache.LangProject.TranslatedScriptureOA.ScriptureBooksOS.Append(m_book);
     m_section = new ScrSection();
     m_book.SectionsOS.Append(m_section);
     m_para = new StTxtPara();
     m_text = new StText();
     m_section.ContentOA = m_text;
     m_text.ParagraphsOS.Append(m_para);
     m_hvoSegDefn  = CmAnnotationDefn.TextSegment(Cache).Hvo;
     m_hvoFtDefn   = Cache.GetIdFromGuid(new Guid(LangProject.kguidAnnFreeTranslation));
     kflidFT       = StTxtPara.SegmentFreeTranslationFlid(Cache);
     kflidSegments = StTxtPara.SegmentsFlid(Cache);
 }
        public void NonScriptureText()
        {
            IText text = new Text();

            Cache.LangProject.TextsOC.Add(text);
            StText sttext = new StText();

            text.ContentsOA = sttext;
            m_para          = new StTxtPara();
            sttext.ParagraphsOS.Append(m_para);
            string paraContents = "Das buch ist rot";
            string trans        = "The book is red";

            m_para.Contents.UnderlyingTsString = m_tsf.MakeString(paraContents, m_wsVern);
            ICmIndirectAnnotation ft      = MakeFt(m_para, trans, 0, paraContents.Length);
            FreeTransEditMonitor  monitor = new FreeTransEditMonitor(Cache, m_wsTrans);            // BEFORE propChanged!

            Cache.PropChanged(ft.Hvo, (int)CmAnnotation.CmAnnotationTags.kflidComment, 0, 0, 0);
            monitor.LoseFocus();
            Assert.AreEqual(0, m_para.TranslationsOC.Count, "monitor should not make CmTranslation for non-Scripture");
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adjusts the references of the section and creates any needed BT's
        /// </summary>
        /// <param name="hvoText">The StText that was changed</param>
        /// <param name="ivMin">the starting index where the change occurred</param>
        /// <param name="cvIns">the number of paragraphs inserted</param>
        /// <param name="cvDel">the number of paragraphs deleted</param>
        /// ------------------------------------------------------------------------------------
        protected override void DoEffectsOfPropChange(int hvoText, int ivMin, int cvIns, int cvDel)
        {
            if (cvIns == 0 && cvDel == 0)
            {
                return;                 // Nothing actually changed
            }
            int    flid = m_cache.GetOwningFlidOfObject(hvoText);
            StText text = new StText(m_cache, hvoText, false, false);
            FdoOwningSequence <IStPara> paras = text.ParagraphsOS;

            // Create back translations for any new paragraphs
            if (flid == (int)ScrSection.ScrSectionTags.kflidContent ||
                flid == (int)ScrSection.ScrSectionTags.kflidHeading ||
                flid == (int)ScrBook.ScrBookTags.kflidTitle)
            {
                for (int iPara = ivMin; iPara < ivMin + cvIns; iPara++)
                {
                    ScrTxtPara para = new ScrTxtPara(m_cache, paras.HvoArray[iPara]);
                    para.GetOrCreateBT();
                }
            }

            // Adjust section references for section contents if we have some paragraphs left
            if (flid == (int)ScrSection.ScrSectionTags.kflidContent && paras.Count > 0)
            {
                ScrTxtPara.AdjustSectionRefsForStTextParaChg(text, ivMin);
            }

            // If we show boundary markers and we insert or delete a paragraph, we have to
            // update the marker of the previous paragraph as well, as that might
            // now be no longer the last paragraph (and thus needs to show the paragraph
            // marker instead of the section marker).
            if (((cvIns > 0 && cvDel == 0) || (cvIns == 0 && cvDel > 0)) && ivMin > 0 &&
                Options.ShowFormatMarksSetting)
            {
                text.Cache.PropChanged(null, PropChangeType.kpctNotifyAll, hvoText,
                                       (int)StText.StTextTags.kflidParagraphs, ivMin - 1, 1, 1);
            }
        }
Beispiel #29
0
        /// ------------------------------------------------------------------------------------
        /// <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);
        }
Beispiel #30
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Makes a selection from one paragraph to another paragraph.
        /// NOTE: This selects the entirety of both paragraphs.
        /// </summary>
        /// <param name="para1">The first paragraph.</param>
        /// <param name="para2">The last paragraph.</param>
        /// <param name="view">DraftView or FootnoteView</param>
        /// ------------------------------------------------------------------------------------
        private SelectionHelper MakeSelection(StTxtPara para1, StTxtPara para2, IVwRootSite view)
        {
            Debug.Assert(view != null);
            Debug.Assert(para1.OwningFlid == (int)StText.StTextTags.kflidParagraphs);
            Debug.Assert(para2.OwningFlid == (int)StText.StTextTags.kflidParagraphs);

            SelectionHelper helper = new SelectionHelper();
            StText          text1  = new StText(m_fdoCache, para1.OwnerHVO);
            StText          text2  = new StText(m_fdoCache, para2.OwnerHVO);

            // build the anchor part of the selection
            SetupSelectionFor(helper, text1, para1, SelectionHelper.SelLimitType.Anchor,
                              (FwRootSite)view);

            // build the end part of the selection
            SetupSelectionFor(helper, text2, para2, SelectionHelper.SelLimitType.End,
                              (FwRootSite)view);
            helper.IchAnchor = 0;
            helper.IchEnd    = para2.Contents.Length;

            return(helper);
        }