Example #1
0
            /// ------------------------------------------------------------------------------------
            /// <summary>
            ///
            /// </summary>
            /// <param name="vwenv"></param>
            /// <param name="hvo"></param>
            /// <param name="frag"></param>
            /// ------------------------------------------------------------------------------------
            public override void Display(IVwEnv vwenv, int hvo, int frag)
            {
                CheckDisposed();

                int       hvoOuter, tag, ihvo;
                ITsString tss;

                switch (frag)
                {
                case 1:                         // A ScrBook; display the title.
                    vwenv.AddObjProp((int)ScrBook.ScrBookTags.kflidTitle, this, 2);
                    break;

                case 2:                         // An StText; display the paragraphs.
                    vwenv.GetOuterObject(vwenv.EmbeddingLevel - 1, out hvoOuter, out tag, out ihvo);
                    tss = TsStringHelper.MakeTSS(
                        "Hvo = " + hvoOuter + "; Tag = " + tag + "; Ihvo = " + ihvo,
                        InMemoryFdoCache.s_wsHvos.Fr);
                    vwenv.AddString(tss);
                    vwenv.AddObjVecItems((int)StText.StTextTags.kflidParagraphs, this, 3);
                    break;

                case 3:                         // StTxtPara, display details of our outer object
                    vwenv.GetOuterObject(vwenv.EmbeddingLevel - 1, out hvoOuter, out tag, out ihvo);
                    tss = TsStringHelper.MakeTSS(
                        "Hvo = " + hvoOuter + "; Tag = " + tag + "; Ihvo = " + ihvo,
                        InMemoryFdoCache.s_wsHvos.Fr);
                    vwenv.AddString(tss);
                    break;

                default:
                    throw new ApplicationException("Unexpected frag in DummyCollectorEnvVc");
                }
            }
            /// ------------------------------------------------------------------------------------
            /// <summary>
            ///
            /// </summary>
            /// <param name="vwenv"></param>
            /// <param name="hvo"></param>
            /// <param name="frag"></param>
            /// ------------------------------------------------------------------------------------
            public override void Display(IVwEnv vwenv, int hvo, int frag)
            {
                int       frWs = vwenv.DataAccess.WritingSystemFactory.GetWsFromStr("fr");
                int       hvoOuter, tag, ihvo;
                ITsString tss;

                switch (frag)
                {
                case 1:                         // A ScrBook; display the title.
                    vwenv.AddObjProp(ScrBookTags.kflidTitle, this, 2);
                    break;

                case 2:                         // An StText; display the paragraphs.
                    vwenv.GetOuterObject(vwenv.EmbeddingLevel - 1, out hvoOuter, out tag, out ihvo);
                    tss = TsStringHelper.MakeTSS(
                        "Hvo = " + hvoOuter + "; Tag = " + tag + "; Ihvo = " + ihvo,
                        frWs);
                    vwenv.AddString(tss);
                    vwenv.AddObjVecItems(StTextTags.kflidParagraphs, this, 3);
                    break;

                case 3:                         // StTxtPara, display details of our outer object
                    vwenv.GetOuterObject(vwenv.EmbeddingLevel - 1, out hvoOuter, out tag, out ihvo);
                    tss = TsStringHelper.MakeTSS(
                        "Hvo = " + hvoOuter + "; Tag = " + tag + "; Ihvo = " + ihvo,
                        frWs);
                    vwenv.AddString(tss);
                    break;

                default:
                    throw new ApplicationException("Unexpected frag in DummyCollectorEnvVc");
                }
            }
Example #3
0
        public void UserPromptForSectionHeadWithEmptyPara()
        {
            CheckDisposed();

            // Set up section head with an empty paragraph
            IScrSection section = m_inMemoryCache.AddSectionToMockedBook(m_book.Hvo);
            StTxtPara   para    = m_inMemoryCache.AddSectionHeadParaToSection(section.Hvo, "",
                                                                              ScrStyleNames.SectionHead);

            section.AdjustReferences();
            Options.ShowEmptyParagraphPromptsSetting = true;

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

            CreateExpectedUserPrompt(stVc, para.Hvo,
                                     (int)ScrSection.ScrSectionTags.kflidHeading, (int)StTxtPara.StTxtParaTags.kflidContents);

            IVwEnv vwEnv      = (IVwEnv)m_vwenvMock.MockInstance;
            bool   fTextAdded = stVc.CallInsertUserPrompt(vwEnv, para.Hvo);

            Assert.IsTrue(fTextAdded, "User prompt not added");
            ITsString text = stVc.DisplayVariant(vwEnv, SimpleRootSite.kTagUserPrompt, null,
                                                 (int)ScrSection.ScrSectionTags.kflidHeading);

            string difference;
            bool   fEqual = TsStringHelper.TsStringsAreEqual(
                ExpectedUserPrompt("Type section head here", m_inMemoryCache.Cache.DefaultVernWs),
                text, out difference);

            Assert.IsTrue(fEqual, difference);
            m_vwenvMock.Verify();
        }
Example #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Compares the given footnote with the values in m_footnote.
        /// </summary>
        /// <param name="footnote">The footnote to compare</param>
        /// ------------------------------------------------------------------------------------
        private void CompareFootnote(StFootnote footnote)
        {
            Assert.AreEqual(m_footnote.DisplayFootnoteMarker, footnote.DisplayFootnoteMarker,
                            "Display footnote marker values did not match");
            Assert.AreEqual(m_footnote.DisplayFootnoteReference, footnote.DisplayFootnoteReference,
                            "Display footnote reference values did not match");
            Assert.AreEqual(m_footnote.FootnoteMarker.Text, footnote.FootnoteMarker.Text);
            Assert.AreEqual(m_footnote.ParagraphsOS.Count, footnote.ParagraphsOS.Count,
                            "Footnote paragraph count did not match");

            string diff = string.Empty;

            for (int i = 0; i < m_footnote.ParagraphsOS.Count; i++)
            {
                StTxtPara expectedPara = (StTxtPara)m_footnote.ParagraphsOS[i];
                StTxtPara actualPara   = (StTxtPara)footnote.ParagraphsOS[i];
                bool      result       = TsTextPropsHelper.PropsAreEqual(expectedPara.StyleRules,
                                                                         actualPara.StyleRules, out diff);
                Assert.IsTrue(result, "paragraph " + i + " stylerules differed in: " + diff);

                result = TsStringHelper.TsStringsAreEqual(expectedPara.Contents.UnderlyingTsString,
                                                          actualPara.Contents.UnderlyingTsString, out diff);
                Assert.IsTrue(result, "paragraph " + i + " differed in: " + diff);

                CompareFootnoteTrans((CmTranslation)expectedPara.GetBT(), (CmTranslation)actualPara.GetBT(),
                                     actualPara.Hvo);
            }
        }
Example #5
0
        public void UserPromptForBookTitleWithEmptyPara()
        {
            // Set up title with an empty paragraph
            IStText title = AddTitleToMockedBook(m_book, string.Empty, Cache.DefaultVernWs);

            Options.ShowEmptyParagraphPromptsSetting = true;

            int         defVernWs = Cache.DefaultVernWs;
            DummyTeStVc stVc      = new DummyTeStVc(Cache, defVernWs);

            CreateExpectedUserPrompt(stVc, title.ParagraphsOS[0].Hvo,
                                     ScrBookTags.kflidTitle, StTxtParaTags.kflidContents);

            m_vwenvMock.Stub(x => x.CurrentObject()).Return(title.ParagraphsOS[0].Hvo);
            bool fTextAdded = stVc.CallInsertUserPrompt(m_vwenvMock, title[0]);

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

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

            Assert.IsTrue(fEqual, difference);
            m_vwenvMock.VerifyAllExpectations();
        }
Example #6
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();
        }
Example #7
0
        public void UserPromptForSectionHeadWithEmptyPara()
        {
            // Set up section head with an empty paragraph
            IScrSection section = AddSectionToMockedBook(m_book);
            IStTxtPara  para    = AddSectionHeadParaToSection(section, "",
                                                              ScrStyleNames.SectionHead);

            Options.ShowEmptyParagraphPromptsSetting = true;
            int         defVernWs = Cache.DefaultVernWs;
            DummyTeStVc stVc      = new DummyTeStVc(Cache, defVernWs);

            CreateExpectedUserPrompt(stVc, para.Hvo,
                                     ScrSectionTags.kflidHeading, StTxtParaTags.kflidContents);

            bool fTextAdded = stVc.CallInsertUserPrompt(m_vwenvMock, para);

            Assert.IsTrue(fTextAdded, "User prompt not added");
            ITsString text = stVc.DisplayVariant(m_vwenvMock, SimpleRootSite.kTagUserPrompt,
                                                 ScrSectionTags.kflidHeading);

            string difference;
            bool   fEqual = TsStringHelper.TsStringsAreEqual(
                ExpectedUserPrompt("Type section head here", defVernWs),
                text, out difference);

            Assert.IsTrue(fEqual, difference);
            m_vwenvMock.VerifyAllExpectations();
        }
Example #8
0
        public void UpdateUserPrompt_Vern_Typing()
        {
            // Set up section head with an empty paragraph
            IScrSection section = AddSectionToMockedBook(m_book);
            IStTxtPara  para    = AddSectionHeadParaToSection(section, "",
                                                              ScrStyleNames.SectionHead);

            IVwRootBox   rootb;
            IVwSelection vwsel;
            IVwRootSite  rootsite;

            SetUpResultsForUpdateUserPromptTests(4, "t", out rootb, out vwsel, out rootsite);

            int defVernWs = Cache.DefaultVernWs;

            DummyTeStVc   stVc    = new DummyTeStVc(Cache, defVernWs, rootb);
            ITsIncStrBldr strBdlr = TsIncStrBldrClass.Create();

            strBdlr.SetIntPropValues(SimpleRootSite.ktptUserPrompt, (int)FwTextPropVar.ktpvDefault, 1);
            strBdlr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, Cache.DefaultUserWs);
            strBdlr.Append("t");
            ITsString tssTyped    = strBdlr.GetString();
            ITsString tssExpected = TsStringUtils.MakeTss("t", defVernWs);

            // Now simulate the user typing over the user prompt
            stVc.UpdateProp(vwsel, para.Hvo, SimpleRootSite.kTagUserPrompt, 0, tssTyped);

            // verify that the text is in the paragraph and that there is no longer a user prompt.
            string diff;

            Assert.IsTrue(TsStringHelper.TsStringsAreEqual(tssExpected, para.Contents, out diff), diff);

            m_vwenvMock.VerifyAllExpectations();
            VerifyArgsSentToRequestSelectionAtEndOfUow(rootsite, rootb, 0, 4, StTxtParaTags.kflidContents, "t");
        }
Example #9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Compares the given footnote with the values in m_footnote.
        /// </summary>
        /// <param name="footnote">The footnote to compare</param>
        /// ------------------------------------------------------------------------------------
        private void CompareFootnote(IStFootnote footnote)
        {
            Assert.AreEqual(m_footnote.MarkerType, footnote.MarkerType);
            if (footnote.MarkerType == FootnoteMarkerTypes.SymbolicFootnoteMarker)
            {
                AssertEx.AreTsStringsEqual(m_footnote.FootnoteMarker, footnote.FootnoteMarker);
            }
            Assert.AreEqual(m_footnote.ParagraphsOS.Count, footnote.ParagraphsOS.Count,
                            "Footnote paragraph count did not match");

            string diff = string.Empty;

            for (int i = 0; i < m_footnote.ParagraphsOS.Count; i++)
            {
                IStTxtPara expectedPara = (IStTxtPara)m_footnote.ParagraphsOS[i];
                IStTxtPara actualPara   = (IStTxtPara)footnote.ParagraphsOS[i];
                bool       result       = TsTextPropsHelper.PropsAreEqual(expectedPara.StyleRules,
                                                                          actualPara.StyleRules, out diff);
                Assert.IsTrue(result, "paragraph " + i + " stylerules differed in: " + diff);

                result = TsStringHelper.TsStringsAreEqual(expectedPara.Contents,
                                                          actualPara.Contents, out diff);
                Assert.IsTrue(result, "paragraph " + i + " differed in: " + diff);

                CompareFootnoteTrans(expectedPara.GetBT(), actualPara);
            }
        }
        public void DeleteFootnoteWithoutORC()
        {
            IScrBook book = (IScrBook)m_scr.ScriptureBooksOS[0];
            int      originalFootnoteCount = book.FootnotesOS.Count;
            // Insert a new footnote into the collection and view
            IScrFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().Create();

            book.FootnotesOS.Insert(0, footnote);

            IScrTxtPara para = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle(
                footnote, ScrStyleNames.CrossRefFootnoteParagraph);

            para.Contents = TsStringHelper.MakeTSS("My footnote", Cache.DefaultVernWs);
            m_footnoteView.RefreshDisplay();
            MakeFootnoteSelection(0, 0, 0);

            // verify that a footnote was added to the collection
            Assert.AreEqual(originalFootnoteCount + 1, book.FootnotesOS.Count);

            m_footnoteView.DeleteFootnote();

            // verify that the footnote was deleted
            Assert.AreEqual(originalFootnoteCount, book.FootnotesOS.Count);
            Assert.IsFalse(footnote.IsValidObject);
        }
Example #11
0
        public void TestFwTextBoxSize()
        {
            using (var textBox = new FwTextBox())
            {
                textBox.AdjustStringHeight = true;
                textBox.controlID          = null;
                textBox.Enabled            = false;
                textBox.TabStop            = false;
                textBox.BackColor          = System.Drawing.SystemColors.Control;
                textBox.HasBorder          = false;
                textBox.Location           = new System.Drawing.Point(5, 5);
                textBox.Size     = new System.Drawing.Size(100, 30);
                textBox.Dock     = System.Windows.Forms.DockStyle.Fill;
                textBox.Visible  = true;
                textBox.WordWrap = false;

                textBox.Tss = TsStringHelper.MakeTSS("Test", m_hvoEnglishWs);
                Assert.LessOrEqual(textBox.PreferredHeight, textBox.Height, "The simple string should fit within the default height.");
                Assert.LessOrEqual(textBox.PreferredWidth, textBox.Width, "The simple string should fit within the default width.");

                textBox.Tss = TsStringHelper.MakeTSS("This is a very long string that should be larger than the default box size in some way or other.", m_hvoEnglishWs);
                Console.WriteLine("PreferredHeight 2 = {0}", textBox.PreferredHeight);
                Console.WriteLine("PreferredWidth 2 = {0}", textBox.PreferredWidth);
                Assert.LessOrEqual(textBox.PreferredHeight, textBox.Height, "The longer string should still fit within the default height (for no wordwrapping).");
                Assert.Greater(textBox.PreferredWidth, textBox.Width, "The longer string should not fit within the default width (for no wordwrapping)");

                textBox.WordWrap = true;
                textBox.Tss      = TsStringHelper.MakeTSS("This is a very long string that should be even larger than the default box size in some way or other.", m_hvoEnglishWs);
                Console.WriteLine("PreferredHeight 3 = {0}", textBox.PreferredHeight);
                Console.WriteLine("PreferredWidth 3 = {0}", textBox.PreferredWidth);
                Assert.Greater(textBox.PreferredHeight, textBox.Height, "The longest string should not fit within the default height (for wordwrapping).");
                Assert.LessOrEqual(textBox.PreferredWidth, textBox.Width, "The longest string should fit with the default width (for wordwrapping).");
            }
        }
Example #12
0
        public void PasteIntoMultiStringFieldDoesNotFlattenWsStyle()
        {
            var args = new FwPasteFixTssEventArgs(m_tss, new TextSelInfo((IVwSelection)null));

            // Veryify that we are testing  with a field of the correct type (if this fails the model changed)
            Assert.AreEqual((int)CellarPropertyType.MultiString, Cache.MetaDataCacheAccessor.GetFieldType(LexSenseTags.kflidGeneralNote));
            //SUT
            InnerLabeledMultiStringView.EliminateExtraStyleAndWsInfo(Cache.MetaDataCacheAccessor, args, LexSenseTags.kflidGeneralNote);
            string differences;

            Assert.True(TsStringHelper.TsStringsAreEqual(m_tss, args.TsString, out differences), differences);
        }
Example #13
0
        public void PasteIntoMultiUnicodeFieldFlattensWsStyle()
        {
            var args = new FwPasteFixTssEventArgs(m_tss, new TextSelInfo((IVwSelection)null));

            // Veryify that we are testing  with a field of the correct type (if this fails the model changed)
            Assert.AreEqual((int)CellarPropertyType.MultiUnicode, Cache.MetaDataCacheAccessor.GetFieldType(LexEntryTags.kflidCitationForm));
            //SUT
            InnerLabeledMultiStringView.EliminateExtraStyleAndWsInfo(Cache.MetaDataCacheAccessor, args, LexEntryTags.kflidCitationForm);
            string differences;

            Assert.False(TsStringHelper.TsStringsAreEqual(m_tss, args.TsString, out differences), differences);
            Assert.That(differences, Is.StringContaining("TsStrings have different number of runs"));
        }
Example #14
0
        public void Add_EmptyObjectCollection_CollectionContainsSingleElement()
        {
            using (var listBox = new FwListBox())
            {
                using (var collection = new FwListBox.ObjectCollection(listBox))
                {
                    ITsString testString = TsStringHelper.MakeTSS("test", m_hvoEnglishWs);

                    // The Test
                    collection.Add(testString);

                    Assert.AreEqual(1, collection.Count);
                    Assert.IsTrue(collection.Contains(testString));
                }
            }
        }
Example #15
0
        public void IsHighlighted_CollectionWithSingleElement_ReturnsTrue()
        {
            using (var listBox = new FwListBox())
            {
                using (var innerFwListBox = new InnerFwListBox(listBox))
                {
                    ITsString testString1 = TsStringHelper.MakeTSS("test1", m_hvoEnglishWs);
                    listBox.Items.Add(testString1);
                    innerFwListBox.MakeRoot();
                    listBox.HighlightedIndex = 0;

                    // The Test
                    Assert.AreEqual(true, innerFwListBox.IsHighlighted(0));
                }
            }
        }
Example #16
0
        public void Clear_CollectionWithSingleElement_CollectionShouldBeEmpty()
        {
            using (var listBox = new FwListBox())
            {
                using (var collection = new FwListBox.ObjectCollection(listBox))
                {
                    ITsString testString = TsStringHelper.MakeTSS("test", m_hvoEnglishWs);
                    collection.Add(testString);

                    // The Test
                    collection.Clear();

                    Assert.AreEqual(0, collection.Count);
                    Assert.IsFalse(collection.Contains(testString));
                }
            }
        }
Example #17
0
        public void UserPromptChangeWSWhenTyping()
        {
            CheckDisposed();

            // Set up section head with an empty paragraph
            IScrSection section = m_inMemoryCache.AddSectionToMockedBook(m_book.Hvo);
            StTxtPara   para    = m_inMemoryCache.AddSectionHeadParaToSection(section.Hvo, "",
                                                                              ScrStyleNames.SectionHead);

            section.AdjustReferences();

            Options.ShowEmptyParagraphPromptsSetting = true;
            DynamicMock rootb = new DynamicMock(typeof(IVwRootBox));

            rootb.SetupResult("IsCompositionInProgress", false);
            DynamicMock vwsel       = new DynamicMock(typeof(IVwSelection));
            IVwRootBox  mockRootbox = (IVwRootBox)rootb.MockInstance;

            vwsel.SetupResult("RootBox", mockRootbox);
            vwsel.SetupResult("CLevels", 4, typeof(bool));
            vwsel.Ignore("AllTextSelInfo");
#if DEBUG
            vwsel.SetupResult("IsValid", true);
#endif

            DummyTeStVc   stVc = new DummyTeStVc(m_inMemoryCache.Cache, m_inMemoryCache.Cache.DefaultAnalWs, mockRootbox);
            ITsStrFactory tsf  = TsStrFactoryClass.Create();
            ITsString     tssVal;
            tssVal = tsf.MakeString("TEST", m_inMemoryCache.Cache.DefaultVernWs);

            // Now simulate the user typing over the user prompt
            stVc.UpdateProp((IVwSelection)vwsel.MockInstance, para.Hvo, SimpleRootSite.kTagUserPrompt, 0, tssVal);

            // verify that the text is in the paragraph and that there is no longer a user prompt.
            ITsPropsBldr ttpBldr = TsPropsBldrClass.Create();
            ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                     (int)FwTextPropVar.ktpvDefault, m_inMemoryCache.Cache.DefaultAnalWs);
            ITsStrBldr bldr = TsStrBldrClass.Create();
            bldr.Replace(0, 0, "TEST", ttpBldr.GetTextProps());
            string diff;
            Assert.IsTrue(TsStringHelper.TsStringsAreEqual(bldr.GetString(),
                                                           para.Contents.UnderlyingTsString, out diff), diff);

            m_vwenvMock.Verify();
        }
Example #18
0
        public void UserPromptForBackTranslation()
        {
            CheckDisposed();

            // Set up a section and paragraph with text
            IScrSection section = m_inMemoryCache.AddSectionToMockedBook(m_book.Hvo);
            StTxtPara   para    = m_inMemoryCache.AddParaToMockedSectionContent(section.Hvo,
                                                                                ScrStyleNames.NormalParagraph);

            section.AdjustReferences();

            m_inMemoryCache.AddRunToMockedPara(para, "Some paragraph text.", null);

            // Add an empty translation to the paragraph
            int            wsBT  = m_inMemoryCache.Cache.DefaultAnalWs;
            ICmTranslation trans = m_inMemoryCache.AddBtToMockedParagraph(para, wsBT);

            m_inMemoryCache.AddRunToMockedTrans(trans, wsBT, string.Empty, null);

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

            CreateExpectedUserPrompt(stVc, trans.Hvo,
                                     (int)CmTranslation.CmTranslationTags.kflidTranslation,
                                     (int)CmTranslation.CmTranslationTags.kflidTranslation);

            // verify that the prompt gets added
            IVwEnv vwEnv      = (IVwEnv)m_vwenvMock.MockInstance;
            bool   fTextAdded = stVc.CallInsertBackTranslationUserPrompt(vwEnv, trans.Hvo);

            Assert.IsTrue(fTextAdded, "User prompt not added");

            // verify the contents of the prompt
            ITsString text = stVc.DisplayVariant(vwEnv, SimpleRootSite.kTagUserPrompt, null,
                                                 (int)CmTranslation.CmTranslationTags.kflidTranslation);
            string difference;
            bool   fEqual = TsStringHelper.TsStringsAreEqual(
                ExpectedUserPrompt("Type back translation here", m_inMemoryCache.Cache.DefaultAnalWs),
                text, out difference);

            Assert.IsTrue(fEqual, difference);

            // verify the mock - is this useful?
            m_vwenvMock.Verify();
        }
Example #19
0
        public void SetIndex_CollectionWithSingleElement_ValueShouldHaveChanged()
        {
            using (var listBox = new FwListBox())
            {
                using (var collection = new FwListBox.ObjectCollection(listBox))
                {
                    ITsString testString1 = TsStringHelper.MakeTSS("test1", m_hvoEnglishWs);
                    ITsString testString2 = TsStringHelper.MakeTSS("test2", m_hvoEnglishWs);
                    collection.Add(testString1);

                    // The Test
                    collection[0] = testString2;

                    Assert.AreEqual(1, collection.Count);
                    Assert.IsFalse(collection.Contains(testString1));
                    Assert.IsTrue(collection.Contains(testString2));
                }
            }
        }
Example #20
0
        public void FootnoteTranslationTest()
        {
            // get an existing footnote
            IScrBook    book     = m_scr.ScriptureBooksOS[1];      // book of James
            IStFootnote footnote = book.FootnotesOS[0];
            StTxtPara   para     = (StTxtPara)footnote.ParagraphsOS[0];

            // add a translation to the footnote
            ICmTranslation translation = para.GetOrCreateBT();

            translation.Translation.AnalysisDefaultWritingSystem.UnderlyingTsString =
                TsStringHelper.MakeTSS("abcde", m_fdoCache.DefaultAnalWs);

            FwStyleSheet styleSheet = new FwStyleSheet();

            styleSheet.Init(m_fdoCache, m_scr.Hvo,
                            (int)Scripture.ScriptureTags.kflidStyles);

            // Prepare the test by creating a footnote view
            using (DummyFootnoteView footnoteView = new DummyFootnoteView(m_fdoCache, true))
            {
                footnoteView.StyleSheet = styleSheet;
                footnoteView.Visible    = false;

                // We don't actually want to show it, but we need to force the view to create the root
                // box and lay it out so that various test stuff can happen properly.
                footnoteView.MakeRoot();
                footnoteView.CallLayout();

                // Select the footnote marker and some characters of the footnote paragraph
                footnoteView.RootBox.MakeSimpleSel(true, true, false, true);
                SelectionHelper selHelper = SelectionHelper.GetSelectionInfo(null, footnoteView);

                // Now the real test:
                IVwSelection sel = footnoteView.RootBox.Selection.GrowToWord();
                ITsString    tss;
                sel.GetSelectionString(out tss, string.Empty);
                Assert.AreEqual("abcde", tss.Text);
            }
        }
Example #21
0
        public void FootnoteTranslationTest()
        {
            // get an existing footnote
            IScrBook     book     = m_scr.ScriptureBooksOS[1];     // book of Exodus
            IScrFootnote footnote = AddFootnote(book, (IStTxtPara)book.TitleOA.ParagraphsOS[0], 0, "This is a footnote");
            IStTxtPara   para     = (IStTxtPara)footnote.ParagraphsOS[0];

            // add a translation to the footnote
            ICmTranslation translation = para.GetOrCreateBT();
            int            analWs      = Cache.DefaultAnalWs;

            translation.Translation.set_String(analWs, TsStringHelper.MakeTSS("abcde", analWs));

            FwStyleSheet styleSheet = new FwStyleSheet();

            styleSheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles);

            // Prepare the test by creating a footnote view
            using (DummyFootnoteView footnoteView = new DummyFootnoteView(Cache, true))
            {
                footnoteView.StyleSheet = styleSheet;
                footnoteView.Visible    = false;

                // We don't actually want to show it, but we need to force the view to create the root
                // box and lay it out so that various test stuff can happen properly.
                footnoteView.MakeRoot();
                footnoteView.CallLayout();

                // Select the footnote marker and some characters of the footnote paragraph
                footnoteView.RootBox.MakeSimpleSel(true, true, false, true);

                // Now the real test:
                IVwSelection sel = footnoteView.RootBox.Selection.GrowToWord();
                ITsString    tss;
                sel.GetSelectionString(out tss, string.Empty);
                Assert.AreEqual("abcde", tss.Text);
            }
        }
Example #22
0
        public void UserPromptForBackTranslation()
        {
            // Set up a section and paragraph with text
            IScrSection section = AddSectionToMockedBook(m_book);
            IStTxtPara  para    = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(para, "Some paragraph text.", null);

            // Add an empty translation to the paragraph
            int            wsBT  = Cache.DefaultAnalWs;
            ICmTranslation trans = AddBtToMockedParagraph(para, wsBT);

            AddRunToMockedTrans(trans, wsBT, string.Empty, null);

            DummyTeStVc stVc = new DummyTeStVc(Cache, wsBT);

            CreateExpectedUserPrompt(stVc, trans.Hvo, CmTranslationTags.kflidTranslation,
                                     CmTranslationTags.kflidTranslation);

            // verify that the prompt gets added
            bool fTextAdded = stVc.CallInsertBackTranslationUserPrompt(m_vwenvMock, trans);

            Assert.IsTrue(fTextAdded, "User prompt not added");

            // verify the contents of the prompt
            ITsString text = stVc.DisplayVariant(m_vwenvMock, SimpleRootSite.kTagUserPrompt,
                                                 CmTranslationTags.kflidTranslation);
            string difference;
            bool   fEqual = TsStringHelper.TsStringsAreEqual(
                ExpectedUserPrompt("Type back translation here", wsBT),
                text, out difference);

            Assert.IsTrue(fEqual, difference);

            // verify the mock - is this useful?
            m_vwenvMock.VerifyAllExpectations();
        }
Example #23
0
        public void DeleteFootnoteWithoutORC()
        {
            CheckDisposed();

            ScrBook book = (ScrBook)m_scr.ScriptureBooksOS[0];
            int     originalFootnoteCount = book.FootnotesOS.Count;
            // Insert a new footnote into the collection and view
            StFootnote footnote = (StFootnote)book.FootnotesOS.InsertAt(new StFootnote(), 0);
            StTxtPara  para     = (StTxtPara)footnote.ParagraphsOS.Append(new StTxtPara());

            para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.CrossRefFootnoteParagraph);
            para.Contents.UnderlyingTsString = TsStringHelper.MakeTSS("My footnote", Cache.DefaultVernWs);
            m_footnoteView.RefreshDisplay();
            MakeFootnoteSelection(0, 0, 0);

            // verify that a footnote was added to the collection
            Assert.AreEqual(originalFootnoteCount + 1, book.FootnotesOS.Count);

            m_footnoteView.DeleteFootnote();

            // verify that the footnote was deleted
            Assert.AreEqual(originalFootnoteCount, book.FootnotesOS.Count);
            Assert.IsFalse(Cache.IsRealObject(footnote.Hvo, StFootnote.kClassId));
        }
Example #24
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <param name="vwenv"></param>
        /// <param name="hvo"></param>
        /// <param name="frag"></param>
        /// ------------------------------------------------------------------------------------
        public override void Display(IVwEnv vwenv, int hvo, int frag)
        {
            if ((m_displayType & DisplayType.kLiteralStringLabels) != 0)
            {
                ITsStrFactory factory = TsStrFactoryClass.Create();
                vwenv.AddString(factory.MakeString("Label" + m_counter++, m_wsDefault));
            }
            switch (frag)
            {
            case 1:                     // the root; display the subitems, first using non-lazy view, then lazy one.
                if ((m_displayType & DisplayType.kBookFootnoteDetailsSeparateParas) == DisplayType.kBookFootnoteDetailsSeparateParas)
                {
                    vwenv.AddObjVecItems(m_flid, this, 10);
                }
                if ((m_displayType & DisplayType.kBookFootnoteDetailsSinglePara) == DisplayType.kBookFootnoteDetailsSinglePara)
                {
                    vwenv.AddObjVecItems(m_flid, this, 11);
                }
                else
                {
                    if ((m_displayType & DisplayType.kNormal) == DisplayType.kNormal)
                    {
                        vwenv.AddObjVecItems(m_flid, this, 3);
                    }
                    if ((m_displayType & DisplayType.kLazy) == DisplayType.kLazy)
                    {
                        vwenv.AddObjVecItems(m_flid, this, 2);
                    }
                }
                if ((m_displayType & DisplayType.kBookTitle) == DisplayType.kBookTitle)
                {
                    vwenv.AddObjProp(ScrBookTags.kflidTitle, this, 3);
                }
                if (m_displayType == DisplayType.kOuterObjDetails)
                {
                    vwenv.AddObjVecItems(m_flid, this, 6);
                }
                break;

            case 2:                     // An StText, display paragraphs lazily
                if ((m_displayType & DisplayType.kWithTopMargin) == DisplayType.kWithTopMargin)
                {
                    vwenv.AddLazyVecItems(StTextTags.kflidParagraphs, this, 4);
                }
                vwenv.AddLazyVecItems(StTextTags.kflidParagraphs, this, 5);
                break;

            case 3:                     // An StText, display paragraphs not lazily.
                if ((m_displayType & DisplayType.kWithTopMargin) == DisplayType.kWithTopMargin)
                {
                    vwenv.AddObjVecItems(StTextTags.kflidParagraphs, this, 4);
                }
                vwenv.AddObjVecItems(StTextTags.kflidParagraphs, this, 5);
                if ((m_displayType & DisplayType.kDuplicateParagraphs) != 0)
                {
                    vwenv.AddObjVecItems(StTextTags.kflidParagraphs, this, 5);
                }
                break;

            case 4:                     // StTxtPara, display contents with top margin
                if ((m_displayType & DisplayType.kMappedPara) == DisplayType.kMappedPara)
                {
                    vwenv.OpenMappedPara();
                }
                vwenv.set_IntProperty((int)FwTextPropType.ktptMarginTop,
                                      (int)FwTextPropVar.ktpvMilliPoint, kMarginTop);
                vwenv.AddStringProp(StTxtParaTags.kflidContents, null);
                vwenv.AddStringProp(StTxtParaTags.kflidContents, null);
                vwenv.AddStringProp(StTxtParaTags.kflidContents, null);
                if ((m_displayType & DisplayType.kMappedPara) == DisplayType.kMappedPara)
                {
                    vwenv.CloseParagraph();
                }
                break;

            case 5:                     // StTxtPara, display contents without top margin
                                        //vwenv.set_IntProperty((int)FwTextPropType.ktptFontSize,
                                        //    (int)FwTextPropVar.ktpvMilliPoint, 15000);
                if ((m_displayType & DisplayType.kMappedPara) == DisplayType.kMappedPara)
                {
                    vwenv.OpenMappedPara();
                }
                vwenv.AddStringProp(StTxtParaTags.kflidContents, null);
                vwenv.AddStringProp(StTxtParaTags.kflidContents, null);
                vwenv.AddStringProp(StTxtParaTags.kflidContents, null);
                if ((m_displayType & DisplayType.kMappedPara) == DisplayType.kMappedPara)
                {
                    vwenv.CloseParagraph();
                }
                break;

            case 6:                     // StTxtPara, display details of our outer object
                int hvoOuter, tag, ihvo;
                vwenv.GetOuterObject(vwenv.EmbeddingLevel - 1, out hvoOuter, out tag, out ihvo);
                ITsString tss = TsStringHelper.MakeTSS("Hvo = " + hvoOuter + "; Tag = " + tag + "; Ihvo = " + ihvo,
                                                       m_wsDefault);
                vwenv.AddString(tss);
                break;

            case ScrBookTags.kflidSections:
                vwenv.AddObjVecItems(ScrBookTags.kflidSections, this,
                                     ScrSectionTags.kflidContent);
                break;

            case ScrSectionTags.kflidHeading:
            case ScrSectionTags.kflidContent:
                if ((m_displayType & DisplayType.kNormal) == DisplayType.kNormal)
                {
                    vwenv.AddObjProp(frag, this, 3);
                }
                if ((m_displayType & DisplayType.kLazy) == DisplayType.kLazy)
                {
                    vwenv.AddObjProp(frag, this, 2);
                }
                break;

            case 7:                     // ScrBook
                vwenv.OpenDiv();
                vwenv.AddObjVecItems(ScrBookTags.kflidFootnotes, this, 8);
                vwenv.CloseDiv();
                break;

            case 8:                     // StFootnote
                vwenv.AddObjVecItems(StTextTags.kflidParagraphs, this,
                                     9);
                break;

            case 9:                     // StTxtPara
                vwenv.AddStringProp(StTxtParaTags.kflidContents, null);
                break;

            case 10:
                // Display a Footnote by displaying its "FootnoteMarker" in a paragraph
                // by itself, followed by the sequence of paragraphs.
                vwenv.AddStringProp(StFootnoteTags.kflidFootnoteMarker, null);
                vwenv.AddObjVecItems(StTextTags.kflidParagraphs, this,
                                     9);
                break;

            case 11:
                // Display a Footnote by displaying its "FootnoteMarker" followed by the
                // contents of its first paragraph (similar to the way footnotes are displayed in
                // real life.
                vwenv.AddObjVecItems(StTextTags.kflidParagraphs, this, 12);
                break;

            case 12:                     // Footnote paragraph with marker
                vwenv.OpenMappedTaggedPara();
                // The footnote marker is not editable.
                vwenv.set_IntProperty((int)FwTextPropType.ktptEditable,
                                      (int)FwTextPropVar.ktpvEnum,
                                      (int)TptEditable.ktptNotEditable);

                // add a read-only space after the footnote marker
                vwenv.set_IntProperty((int)FwTextPropType.ktptEditable,
                                      (int)FwTextPropVar.ktpvEnum,
                                      (int)TptEditable.ktptNotEditable);
                ITsStrFactory strFactory = TsStrFactoryClass.Create();
                vwenv.AddString(strFactory.MakeString(" ", DefaultWs));
                vwenv.AddStringProp(StTxtParaTags.kflidContents, null);
                vwenv.CloseParagraph();
                break;

            default:
                throw new ApplicationException("Unexpected frag in DummyBasicViewVc");
            }
        }