Ejemplo n.º 1
0
        public void GoodMultiUnicodeTest()
        {
            // Start with expected information.
            Assert.AreEqual(0, Cache.LangProject.MainCountry.StringCount, "Wrong number of alternatives for Cache.LangProject.MainCountryAccessor");

            // Create a good string.
            var           english = Cache.LangProject.CurrentAnalysisWritingSystems.First();
            ITsIncStrBldr tisb    = TsStringUtils.MakeIncStrBldr();

            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, english.Handle);
            tisb.Append("Mexico");
            Cache.LangProject.MainCountry.set_String(english.Handle, tisb.GetString());

            // Make sure it is in there now.
            Assert.AreEqual(1, Cache.LangProject.MainCountry.StringCount, "Wrong number of alternatives for Cache.LangProject.MainCountryAccessor");
            int ws;
            var mexico = Cache.LangProject.MainCountry.GetStringFromIndex(0, out ws);

            Assert.AreEqual(english.Handle, ws, "Wrong writing system.");
            Assert.AreEqual("Mexico", mexico.Text, "Wrong text.");

            // Add the same ws string, but with different text.
            tisb = TsStringUtils.MakeIncStrBldr();
            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, english.Handle);
            tisb.Append("Guatemala");
            Cache.LangProject.MainCountry.set_String(english.Handle, tisb.GetString());

            // Make sure it is in there now.
            Assert.AreEqual(1, Cache.LangProject.MainCountry.StringCount, "Wrong number of alternatives for Cache.LangProject.MainCountryAccessor");
            var guatemala = Cache.LangProject.MainCountry.GetStringFromIndex(0, out ws);

            Assert.AreEqual(english.Handle, ws, "Wrong writing system.");
            Assert.AreEqual("Guatemala", guatemala.Text, "Wrong text.");
        }
Ejemplo n.º 2
0
        public void AppendAlternativesTest()
        {
            var           english = Cache.LangProject.CurrentAnalysisWritingSystems.ElementAt(0);
            var           spanish = Cache.LangProject.CurrentAnalysisWritingSystems.ElementAt(1);
            ITsIncStrBldr tisb    = TsStringUtils.MakeIncStrBldr();

            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, english.Handle);
            tisb.Append("Mexico");
            Cache.LangProject.MainCountry.set_String(english.Handle, tisb.GetString());

            tisb = TsStringUtils.MakeIncStrBldr();
            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, spanish.Handle);
            tisb.Append("Mejico");
            Cache.LangProject.MainCountry.set_String(spanish.Handle, tisb.GetString());

            tisb = TsStringUtils.MakeIncStrBldr();
            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, english.Handle);
            tisb.Append("Saltillo");
            Cache.LangProject.FieldWorkLocation.set_String(english.Handle, tisb.GetString());

            Cache.LangProject.FieldWorkLocation.AppendAlternatives(Cache.LangProject.MainCountry);
            Assert.AreEqual("Saltillo Mexico", Cache.LangProject.FieldWorkLocation.get_String(english.Handle).Text);
            Assert.AreEqual("Mejico", Cache.LangProject.FieldWorkLocation.get_String(spanish.Handle).Text);

            tisb = TsStringUtils.MakeIncStrBldr();
            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, spanish.Handle);
            tisb.Append("Saltillo");
            Cache.LangProject.FieldWorkLocation.set_String(spanish.Handle, tisb.GetString());

            ((ITsMultiString)Cache.LangProject.MainCountry).set_String(english.Handle, null);

            Cache.LangProject.FieldWorkLocation.AppendAlternatives(Cache.LangProject.MainCountry);
            Assert.AreEqual("Saltillo Mexico", Cache.LangProject.FieldWorkLocation.get_String(english.Handle).Text);
            Assert.AreEqual("Saltillo Mejico", Cache.LangProject.FieldWorkLocation.get_String(spanish.Handle).Text);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a TsString with the entry headword and a sense number if there
        /// are more than one senses.
        /// </summary>
        public ITsString OwnerOutlineNameForWs(ILexSense sense, int wsVern, HomographConfiguration.HeadwordVariant hv)
        {
            var entry = sense.Entry;
            int hn;

            if (!m_homographNumbers.TryGetValue(entry.Hvo, out hn))
            {
                hn = entry.HomographNumber;                 // unknown entry, use its own HN instead of our override
            }
            ITsIncStrBldr tisb = TsIncStrBldrClass.Create();

            tisb.AppendTsString(StringServices.HeadWordForWsAndHn(entry, wsVern, hn, "", hv));
            var hc = sense.Services.GetInstance <HomographConfiguration>();

            if (hc.ShowSenseNumber(hv) && HasMoreThanOneSense(entry))
            {
                // These int props may not be needed, but they're safe.
                tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0,
                                      Cache.DefaultAnalWs);
                tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                     HomographConfiguration.ksSenseReferenceNumberStyle);
                tisb.Append(" ");
                tisb.Append(GetSenseNumber(sense));
            }
            return(tisb.GetString());
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Merge two MultiUnicodeAccessor objects.
 /// These cases are handled:
 ///		1. If an alternative exists in both objects, nothing is merged.
 ///		2. If the main object (this) is missing an alternative, and the 'source' has it, then add it to 'this'.
 ///		3. If the main object has an alternative, then do nothing.
 /// </summary>
 /// <param name="source"></param>
 /// <param name="fConcatenateIfBoth"></param>
 /// <param name="sep">separator to use if concatenating</param>
 public void MergeAlternatives(IMultiStringAccessor source, bool fConcatenateIfBoth, string sep)
 {
     if (source == null)
     {
         return;                 // Nothing to do.
     }
     foreach (var lws in m_object.Services.WritingSystemManager.WritingSystems)
     {
         var ws     = lws.Handle;
         var myAlt  = get_String(ws);
         var srcAlt = source.get_String(ws);
         if ((myAlt == null || myAlt.Length == 0) &&
             (srcAlt != null && srcAlt.Length != 0))
         {
             set_String(ws, srcAlt);
         }
         else if (!fConcatenateIfBoth)
         {
             continue;
         }
         else if (myAlt != null && myAlt.Length != 0 &&
                  srcAlt != null && srcAlt.Length != 0 &&
                  !myAlt.Equals(srcAlt))
         {
             ITsIncStrBldr newBldr = TsStringUtils.MakeIncStrBldr();
             newBldr.AppendTsString(get_String(ws));
             newBldr.Append(sep);
             newBldr.AppendTsString(source.get_String(ws));
             set_String(ws, newBldr.GetString());
         }
     }
 }
Ejemplo n.º 5
0
        public void GetTextRepresentation_MultiCharStylePara()
        {
            ITsIncStrBldr strBldr = m_footnotePara.Contents.GetIncBldr();

            // run 1
            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                    "Emphasis");
            strBldr.Append("Test Text");

            // run 2
            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                    null);
            strBldr.Append("No char style");

            // run 3
            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                    "Quoted Text");
            strBldr.Append("Ahh!!!!!!");

            // run 4
            strBldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                     (int)FwTextPropVar.ktpvDefault, m_wsDe);
            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                    "Untranslated Word");
            strBldr.Append(" untranslated");

            m_footnotePara.Contents = strBldr.GetString();

            string result = m_footnote.TextRepresentation;

            Assert.AreEqual("<FN><M>a</M><P><PS>Note General Paragraph</PS>" +
                            "<RUN WS='fr' CS='Emphasis'>Test Text</RUN><RUN WS='fr'>No char style</RUN>" +
                            "<RUN WS='fr' CS='Quoted Text'>Ahh!!!!!!</RUN>" +
                            "<RUN WS='de' CS='Untranslated Word'> untranslated</RUN></P></FN>", result);
        }
Ejemplo n.º 6
0
        private void AddNumberingNowOrDelayed(bool fDelayNumber, ITsString tss, out ITsString tssDelayedNumber)
        {
            if (fDelayNumber)
            {
                m_viewConstructor.DelayNumFlag = true;

                ITsIncStrBldr tisb = tss.GetIncBldr();
                tisb.Append("  ");                 // add some padding for separation
                tssDelayedNumber   = tisb.GetString();
                m_hvoDelayedNumber = m_hvo;
            }
            else
            {
                m_viewConstructor.DelayNumFlag = false;

                OutputItemNumber(m_vwEnv, tss);
                tssDelayedNumber = null;
            }
            // This groups senses by placing graminfo before the number, and omitting it if the same as the
            // previous sense in the entry.  This isn't yet supported by the UI, but may well be requested in
            // the future.  (See LT-9663.)
            //if (fGramInfoBeforeNumber)
            //{
            //    tssDelayedNumber = tss;
            //    if (fFirst)
            //        m_hvoGroupedValue = 0;
            //}
            //else if (!m_fDelayNumber)
            //{
            //    m_vwEnv.AddString(tss);
            //    tssDelayedNumber = null;
            //}
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Crawls all runs in the specified string. The run modifier is called for each run in the
        /// specified string. If the run modifier returns <c>null</c>, the run is removed from
        /// the string. If all runs are removed, this method returns <c>null</c>.
        /// </summary>
        /// <param name="str">The string.</param>
        /// <param name="runModifier">The run modifier.</param>
        /// <returns></returns>
        public static ITsString CrawlRuns(ITsString str, Func <ITsString, ITsString> runModifier)
        {
            ITsIncStrBldr tisb     = TsIncStrBldrClass.Create();
            bool          modified = false;
            bool          empty    = true;

            for (int i = 0; i < str.RunCount; i++)
            {
                int ichMin, ichLim;
                str.GetBoundsOfRun(i, out ichMin, out ichLim);
                ITsString oldRun = str.GetSubstring(ichMin, ichLim);
                ITsString newRun = runModifier(oldRun);
                if (newRun != null)
                {
                    if (modified || newRun != oldRun)
                    {
                        tisb.AppendTsString(newRun);
                        modified = true;
                    }
                    empty = false;
                }
                else
                {
                    modified = true;
                }
            }

            if (empty)
            {
                return(null);
            }

            return(modified ? tisb.GetString() : str);
        }
Ejemplo n.º 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");
        }
Ejemplo n.º 9
0
        public ITsString CreateFromStr(XmlNode strNode)
        {
            ITsIncStrBldr tisb = TsStringUtils.MakeIncStrBldr();

            ProcessRunElements(strNode.ChildNodes, tisb);

            return(tisb.GetString());
        }
Ejemplo n.º 10
0
        ITsString CreateFeatureLine(IFsClosedValue value)
        {
            ITsIncStrBldr featLine = TsStringUtils.MakeIncStrBldr();

            featLine.AppendTsString(value.ValueRA != null ? value.ValueRA.Abbreviation.BestAnalysisAlternative : m_questions);
            featLine.Append(" ");
            featLine.AppendTsString(value.FeatureRA != null ? value.FeatureRA.Abbreviation.BestAnalysisAlternative : m_questions);
            return(featLine.GetString());
        }
Ejemplo n.º 11
0
        public void SetDlgInfo(CmObjectUi obj, FdoCache cache, XCore.Mediator mediator)
        {
            CheckDisposed();

            StringTable strings = mediator.StringTbl;

            m_cache = cache;
            IVwStylesheet stylesheet = FontHeightAdjuster.StyleSheetFromMediator(mediator);

            Debug.Assert(obj != null);
            Debug.Assert(obj.Object != null);

            Text = String.Format(FdoUiStrings.ksDeleteX, strings.GetString(obj.ClassName, "ClassNames"));

            // Set the s_helpTopic based on the window title and rearrange the buttons if neccesary
            switch (obj.ClassName)
            {
            case "WfiWordform":
                s_helpTopic = "khtpDeleteWordform";
                break;
            }
            if (s_helpTopic != null)
            {
                buttonHelp.Visible = true;
                buttonHelp.Enabled = true;
                this.helpProvider  = new System.Windows.Forms.HelpProvider();
                this.helpProvider.HelpNamespace = FwApp.App.HelpFile;
                this.helpProvider.SetHelpKeyword(this, FwApp.App.GetHelpString(s_helpTopic, 0));
                this.helpProvider.SetHelpNavigator(this, System.Windows.Forms.HelpNavigator.Topic);
            }
            else
            {
                m_deleteButton.Location = m_cancelButton.Location;
                m_cancelButton.Location = buttonHelp.Location;
            }

            //Use an FWTextBox so that strings of different writing systems will
            //be displayed with the correct stylesheet settings.
            m_descriptionBox3.WritingSystemFactory = m_cache.LanguageWritingSystemFactoryAccessor;
            m_descriptionBox3.WritingSystemCode    = m_cache.LangProject.DefaultUserWritingSystem;
            m_descriptionBox3.StyleSheet           = stylesheet;
            ITsIncStrBldr tisb3 = TsIncStrBldrClass.Create();

            tisb3.AppendTsString(obj.Object.DeletionTextTSS);
            m_descriptionBox3.Tss = tisb3.GetString();

            m_descriptionBox4.WritingSystemFactory = m_cache.LanguageWritingSystemFactoryAccessor;
            m_descriptionBox4.WritingSystemCode    = m_cache.LangProject.DefaultUserWritingSystem;
            m_descriptionBox4.StyleSheet           = stylesheet;
            ITsIncStrBldr tisb4 = TsIncStrBldrClass.Create();

            tisb4.AppendTsString(m_cache.MakeUserTss(" "));             //this is the default for m_descriptionBox4
            m_descriptionBox4.Tss = tisb4.GetString();

            m_deleteButton.Enabled = obj.Object.CanDelete;
            label2.Visible         = m_deleteButton.Enabled;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// This method is called when a user selects Delete Relation on a Lexical Relation slice.
        /// For: Pair relation (eg. Antonym)
        ///     tree relation (parts/whole when deleting a Parts slice)
        /// </summary>
        /// <param name="hvo"></param>
        public void DeleteReference(int hvo)
        {
            CheckDisposed();
            if (hvo <= 0)
            {
                throw new ConfigurationException("Slice:GetObjectHvoForMenusToOperateOn is either messed up or should not have been called, because it could not find the object to be deleted.", m_configurationNode);
            }
            else
            {
                Form mainWindow = (Form)Mediator.PropertyTable.GetValue("window");
                mainWindow.Cursor = Cursors.WaitCursor;
                using (ConfirmDeleteObjectDlg dlg = new ConfirmDeleteObjectDlg())
                {
                    CmObjectUi    ui = CmObjectUi.MakeUi(m_cache, hvo);
                    ILexReference lr = LexReference.CreateFromDBObject(m_cache, hvo);

                    //We need this to determine which kind of relation we are deleting
                    LexRefType lrtOwner =
                        (LexRefType)CmObject.CreateFromDBObject(m_cache, lr.OwnerHVO);

                    int           analWs = m_cache.DefaultAnalWs;
                    int           userWs = m_cache.DefaultUserWs;
                    ITsIncStrBldr tisb   = TsIncStrBldrClass.Create();
                    tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs);

                    switch ((LexRefType.MappingTypes)lrtOwner.MappingType)
                    {
                    case LexRefType.MappingTypes.kmtSenseTree:
                    case LexRefType.MappingTypes.kmtEntryTree:
                    case LexRefType.MappingTypes.kmtEntryOrSenseTree:
                        tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs);
                        tisb.Append(String.Format(LexEdStrings.ksDeleteLexTree, "\x2028"));
                        dlg.SetDlgInfo(ui, m_cache, Mediator, tisb.GetString());
                        break;

                    default:
                        dlg.SetDlgInfo(ui, m_cache, Mediator);
                        break;
                    }

                    if (DialogResult.Yes == dlg.ShowDialog(mainWindow))
                    {
                        lr.DeleteUnderlyingObject();
                        //Update the display because we have removed this slice from the Lexical entry.
                        UpdateForDelete(hvo);

                        mainWindow.Cursor = Cursors.Default;
                    }
                    else                     //If the user selected Cancel in the delete dialog do nothing
                    {
                        mainWindow.Cursor = Cursors.Default;
                        return;
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public ITsString CreateFromAStr(XmlNode aStrNode, out int wsAStr)
        {
            wsAStr = m_wsCache[aStrNode.Attributes["ws"].Value];
            ITsIncStrBldr tisb = TsStringUtils.MakeIncStrBldr();

            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsAStr);
            ProcessRunElements(aStrNode.ChildNodes, tisb);

            return(tisb.GetString());
        }
Ejemplo n.º 14
0
        public ITsString CreateFromStr(XmlNode strNode)
        {
            CheckDisposed();

            ITsIncStrBldr tisb = m_tsf.GetIncBldr();

            ProcessRunElements(strNode.ChildNodes, tisb);

            return(tisb.GetString());
        }
Ejemplo n.º 15
0
        public void GetTextRepresentation_charStylePara()
        {
            ITsIncStrBldr strBldr = m_footnotePara.Contents.GetIncBldr();

            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                    "Emphasis");
            strBldr.Append("Test Text");
            m_footnotePara.Contents = strBldr.GetString();
            Assert.AreEqual("<FN><M>a</M><P><PS>Note General Paragraph</PS>" +
                            "<RUN WS='fr' CS='Emphasis'>Test Text</RUN></P></FN>",
                            m_footnote.TextRepresentation);
        }
Ejemplo n.º 16
0
        public void StringServices_CrawlRunsCanDeleteAllRuns()
        {
            var           wsEn  = Cache.WritingSystemFactory.GetWsFromStr("en");
            var           begin = TsStringUtils.MakeString("beginning", wsEn);
            ITsIncStrBldr tisb  = TsStringUtils.MakeIncStrBldr();

            tisb.AppendTsString(begin);
            ITsString result = null;

            Assert.DoesNotThrow(() => result = StringServices.CrawlRuns(tisb.GetString(), run => run.get_WritingSystemAt(0) == wsEn ? null : run));
            Assert.That(result, Is.Null);
        }
Ejemplo n.º 17
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the default value for a cell in the row for new records.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public ITsString GetDefaultNewRowValue(int rowIndex)
        {
            int ws = GetWritingSystemHandle(rowIndex);

            if (ws <= 0)
            {
                ITsIncStrBldr strBldr = TsStringUtils.MakeIncStrBldr();
                strBldr.Append(string.Empty);
                return(strBldr.GetString());
            }

            return(TsStringUtils.EmptyString(ws));
        }
Ejemplo n.º 18
0
        private ITsString TitleForWs(int ws)
        {
            ITsString tssTitle = null;

            if (ScriptureServices.ScriptureIsResponsibleFor(this))
            {
                Scripture scripture = Cache.LangProject.TranslatedScriptureOA as Scripture;
                if (scripture != null)
                {
                    tssTitle = scripture.BookChapterVerseBridgeAsTss(this, ws);
                    if (OwningFlid == ScrSectionTags.kflidHeading)
                    {
                        string sFmt = Strings.ksSectionHeading;
                        int    iMin = sFmt.IndexOf("{0}");
                        if (iMin < 0)
                        {
                            tssTitle = m_cache.MakeUserTss(sFmt);
                        }
                        else
                        {
                            ITsIncStrBldr tisb = TsIncStrBldrClass.Create();
                            if (iMin > 0)
                            {
                                tisb.AppendTsString(m_cache.MakeUserTss(sFmt.Substring(0, iMin)));
                            }
                            tisb.AppendTsString(tssTitle);
                            if (iMin + 3 < sFmt.Length)
                            {
                                tisb.AppendTsString(m_cache.MakeUserTss(sFmt.Substring(iMin + 3)));
                            }
                            tssTitle = tisb.GetString();
                        }
                    }
                }
            }
            else if (Owner is IText)
            {
                IText text = Owner as IText;
                tssTitle = text.Name.get_String(ws);
            }
            else
            {
                // throw?
            }
            if (tssTitle == null)
            {
                tssTitle = TsStrFactoryClass.Create().EmptyString(Cache.DefaultAnalWs);
            }
            return(tssTitle);
        }
Ejemplo n.º 19
0
        public void StringServices_CrawlRunsCanSuccessfullyDoNothing()
        {
            var           wsEn       = Cache.WritingSystemFactory.GetWsFromStr("en");
            var           wsFr       = Cache.WritingSystemFactory.GetWsFromStr("fr");
            var           tssFactory = Cache.TsStrFactory;
            var           begin      = tssFactory.MakeString("beginning", wsEn);
            ITsIncStrBldr tisb       = TsIncStrBldrClass.Create();

            tisb.AppendTsString(begin);
            ITsString result = null;

            Assert.DoesNotThrow(() => result = StringServices.CrawlRuns(tisb.GetString(), run => run.get_WritingSystemAt(0) == wsFr ? null : run));
            Assert.That(result.Text, Is.StringMatching("beginning"));
        }
Ejemplo n.º 20
0
        public void SerializeTsStringToXml_MultiStringLaterRunsLessProps()
        {
            ITsIncStrBldr tisb = TsStringUtils.MakeIncStrBldr();

            tisb.SetIntValue(FwTextPropType.ktptWs, FwTextPropVar.ktpvDefault, EnWS);
            tisb.SetStringValue(FwTextPropType.ktptNamedStyle, "Monkey");
            tisb.Append("This is a ");
            tisb.ClearProps();
            tisb.SetIntValue(FwTextPropType.ktptWs, FwTextPropVar.ktpvDefault, EsWS);
            tisb.Append("Laa yra la m\u00E9n");
            ITsString tss = tisb.GetString();
            string    xml = TsStringSerializer.SerializeTsStringToXml(tss, WritingSystemManager, EnWS);

            Assert.That(StripNewLines(xml), Is.EqualTo("<AStr ws=\"en\"><Run ws=\"en\" namedStyle=\"Monkey\">This is a </Run><Run ws=\"es\">Laa yra la m\u00E9n</Run></AStr>"));
        }
Ejemplo n.º 21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="strings"></param>
        /// <param name="obj"></param>
        /// <param name="cache"></param>
        /// <param name="mediator"></param>
        /// <param name="tssNote">a second message, in addition to what's in obj.Object.DeletionTextTss</param>
        public void SetDlgInfo(CmObjectUi obj, FdoCache cache, XCore.Mediator mediator, ITsString tssNote)
        {
            CheckDisposed();

            Debug.Assert(obj != null);
            Debug.Assert(obj.Object != null);

            //do not change the order of the following two lines of code
            //because m_descritiptionBox4.Tss is given a default value first.
            SetDlgInfo(obj, cache, mediator);
            ITsIncStrBldr tisb = TsIncStrBldrClass.Create();

            tisb.AppendTsString(tssNote);
            m_descriptionBox4.Tss = tisb.GetString();
        }
Ejemplo n.º 22
0
        public void CountTest()
        {
            // Start with expected information.
            Assert.AreEqual(2, Cache.LangProject.Description.StringCount, "Wrong number of alternatives for Cache.LangProject.DescriptionAccessor");

            // Create a good string.
            CoreWritingSystemDefinition german = Cache.ServiceLocator.WritingSystemManager.Get("de");

            ITsIncStrBldr tisb = TsStringUtils.MakeIncStrBldr();

            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, german.Handle);
            tisb.Append("Deutchland");
            Cache.LangProject.Description.set_String(german.Handle, tisb.GetString());
            //// Make sure it is in there now.
            Assert.AreEqual(3, Cache.LangProject.Description.StringCount, "Wrong number of alternatives for Cache.LangProject.DescriptionAccessor");

            //// Add the same ws string, but with different text.
            tisb = TsStringUtils.MakeIncStrBldr();
            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, german.Handle);
            tisb.Append("heilige");
            Cache.LangProject.Description.set_String(german.Handle, tisb.GetString());
            //// Make sure it is in there now.
            Assert.AreEqual(3, Cache.LangProject.Description.StringCount, "Wrong number of alternatives for Cache.LangProject.DescriptionAccessor");
        }
Ejemplo n.º 23
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the default value for a cell in the row for new records.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public ITsString GetDefaultNewRowValue(int rowIndex)
        {
            int ws = GetWritingSystemHandle(rowIndex);

            if (ws <= 0)
            {
                ITsIncStrBldr strBldr = TsIncStrBldrClass.Create();
                strBldr.Append(string.Empty);
                return(strBldr.GetString());
            }

            ITsStrFactory tsf = TsStrFactoryClass.Create();

            return(tsf.MakeString(string.Empty, ws));
        }
Ejemplo n.º 24
0
        public ITsString CreateFeatureLine(ITsString name, ITsString value, bool negated)
        {
            ITsIncStrBldr featLine = TsIncStrBldrClass.Create();

            featLine.AppendTsString(name);
            featLine.Append(": ");
            if (value != null)
            {
                if (negated)
                {
                    featLine.AppendTsString(m_tsf.MakeString("!", m_cache.DefaultUserWs));
                }
                featLine.AppendTsString(value);
            }
            return(featLine.GetString());
        }
Ejemplo n.º 25
0
        public void SerializeTsStringToXml_WithLinkDoesNotWriteObjData()
        {
            Guid          expectedGuid = Guid.NewGuid();
            ITsIncStrBldr tisb         = TsStringUtils.MakeIncStrBldr();

            tisb.SetIntValue(FwTextPropType.ktptWs, FwTextPropVar.ktpvDefault, EnWS);
            tisb.Append("This is a link:");
            tisb.ClearProps();
            tisb.SetIntValue(FwTextPropType.ktptWs, FwTextPropVar.ktpvDefault, EnWS);
            tisb.SetStringValue(FwTextPropType.ktptObjData, CreateObjData(FwObjDataTypes.kodtNameGuidHot, expectedGuid.ToByteArray()));
            tisb.Append(StringUtils.kChObject.ToString());
            ITsString tss = tisb.GetString();
            string    xml = TsStringSerializer.SerializeTsStringToXml(tss, WritingSystemManager, writeObjData: false);

            Assert.That(StripNewLines(xml), Is.EqualTo("<Str><Run ws=\"en\">This is a link:</Run></Str>"));
        }
Ejemplo n.º 26
0
        public void GetTextRepresentation_charStylePara()
        {
            CheckDisposed();

            ITsIncStrBldr strBldr = TsIncStrBldrClass.Create();

            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                    "Emphasis");
            strBldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                     (int)FwTextPropVar.ktpvDefault, m_vernWs);
            strBldr.Append("Test Text");
            m_footnotePara.Contents.UnderlyingTsString = strBldr.GetString();
            string result = m_footnote.GetTextRepresentation();

            Assert.AreEqual(@"<FN><M>o</M><ShowMarker/><P><PS>Note General Paragraph</PS>" +
                            "<RUN WS='fr' CS='Emphasis'>Test Text</RUN></P></FN>", result);
        }
Ejemplo n.º 27
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Display the footnote marker
        /// </summary>
        /// <param name="vwenv">View environment</param>
        /// ------------------------------------------------------------------------------------
        private void DisplayFootnoteMarker(IVwEnv vwenv)
        {
            // The footnote marker is not editable.
            vwenv.set_IntProperty((int)FwTextPropType.ktptEditable,
                                  (int)FwTextPropVar.ktpvEnum,
                                  (int)TptEditable.ktptNotEditable);
            vwenv.AddStringProp((int)StFootnote.StFootnoteTags.kflidFootnoteMarker, null);

            // add a read-only space after the footnote marker
            vwenv.set_IntProperty((int)FwTextPropType.ktptEditable,
                                  (int)FwTextPropVar.ktpvEnum,
                                  (int)TptEditable.ktptNotEditable);
            ITsIncStrBldr strBldr = TsIncStrBldrClass.Create();

            strBldr.Append(" ");
            vwenv.AddString(strBldr.GetString());
        }
Ejemplo n.º 28
0
        public void StringServices_CrawlRunsCanDeleteFromMiddle()
        {
            var           wsEn   = Cache.WritingSystemFactory.GetWsFromStr("en");
            var           wsFr   = Cache.WritingSystemFactory.GetWsFromStr("fr");
            var           begin  = TsStringUtils.MakeString("beginning", wsEn);
            var           middle = TsStringUtils.MakeString("middle", wsFr);
            var           end    = TsStringUtils.MakeString("end", wsEn);
            ITsIncStrBldr tisb   = TsStringUtils.MakeIncStrBldr();

            tisb.AppendTsString(begin);
            tisb.AppendTsString(middle);
            tisb.AppendTsString(end);
            ITsString result = null;

            Assert.DoesNotThrow(() => result = StringServices.CrawlRuns(tisb.GetString(), run => run.get_WritingSystemAt(0) == wsFr ? null : run));
            Assert.That(result.Text, Is.StringMatching("beginningend"));
        }
Ejemplo n.º 29
0
        public void GetTextRepresentation_BT_MultiCharStylePara()
        {
            CheckDisposed();
            SetupBackTrans();

            ITsIncStrBldr strBldr = TsIncStrBldrClass.Create();

            strBldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                     (int)FwTextPropVar.ktpvDefault, m_vernWs);

            // run 1
            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                    "Emphasis");
            strBldr.Append("Test Text");

            // run 2
            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                    null);
            strBldr.Append("No char style");

            // run 3
            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                    "Quoted Text");
            strBldr.Append("Ahh!!!!!!");

            m_footnotePara.Contents.UnderlyingTsString = strBldr.GetString();

            // Now add back translations with and without character styles.
            m_scrInMemoryCache.AddRunToMockedTrans(m_trans, m_wsEs, "Spanish", null);
            m_scrInMemoryCache.AddRunToMockedTrans(m_trans, m_wsEs, m_vernWs, " back ", ScrStyleNames.UntranslatedWord);
            m_scrInMemoryCache.AddRunToMockedTrans(m_trans, m_wsEs, " translation!", "Emphasis");

            m_scrInMemoryCache.AddRunToMockedTrans(m_trans, m_wsDe, "German!", "Emphasis");
            m_scrInMemoryCache.AddRunToMockedTrans(m_trans, m_wsDe, m_vernWs, " back ", ScrStyleNames.UntranslatedWord);
            m_scrInMemoryCache.AddRunToMockedTrans(m_trans, m_wsDe, " translation", null);

            string result = m_footnote.GetTextRepresentation();

            Assert.AreEqual(@"<FN><M>o</M><ShowMarker/><P><PS>Note General Paragraph</PS>" +
                            @"<RUN WS='fr' CS='Emphasis'>Test Text</RUN><RUN WS='fr'>No char style</RUN>" +
                            "<RUN WS='fr' CS='Quoted Text'>Ahh!!!!!!</RUN>" +
                            "<TRANS WS='es'><RUN WS='es'>Spanish</RUN><RUN WS='fr' CS='Untranslated Word'> back </RUN><RUN WS='es' CS='Emphasis'> translation!</RUN></TRANS>" +
                            "<TRANS WS='de'><RUN WS='de' CS='Emphasis'>German!</RUN><RUN WS='fr' CS='Untranslated Word'> back </RUN><RUN WS='de'> translation</RUN></TRANS>" +
                            "</P></FN>", result);
        }
Ejemplo n.º 30
0
        public ResolveKeyTermRenderingImportConflictDlg(IWin32Window owner, IChkRef occurrence,
                                                        string existingRendering, string importedRendering, IVwStylesheet ss) : this()
        {
            FdoCache     cache  = occurrence.Cache;
            IScripture   scr    = cache.LangProject.TranslatedScriptureOA;
            ScrReference scrRef = (new ScrReference(occurrence.Ref, scr.Versification));

            m_owner                = owner;
            m_lblAnalysis.Text     = occurrence.OwnerOfClass <IChkTerm>().Name.AnalysisDefaultWritingSystem.Text;
            m_lblOriginal.Text     = occurrence.KeyWord.Text;
            m_lblScrReference.Text = scrRef.ToString();
            m_btnExisting.Text     = String.Format(m_btnExisting.Text, existingRendering);
            m_btnImported.Text     = String.Format(m_btnImported.Text, importedRendering);

            // We do this outside the designer-controlled code because it does funny things
            // to FwMultiParaTextBox, owing to the need for a writing system factory, and some
            // properties it should not persist but I can't persuade it not to.
//			IStText text = new NonEditableMultiTss(TeEditingHelper.GetVerseText(cache.LangProject.TranslatedScriptureOA, scrRef).ToString(true, " "));
            //m_verseTextLabel = new FwMultiParaTextBox(text, ss);
            m_verseTextLabel = new FwLabel();
            m_verseTextLabel.WritingSystemFactory = cache.WritingSystemFactory; // set ASAP.
            m_verseTextLabel.WritingSystemCode    = cache.DefaultVernWs;
            m_verseTextLabel.StyleSheet           = ss;                         // before setting text, otherwise it gets confused about height needed.
            m_verseTextLabel.Location             = new Point(0, 0);
            m_verseTextLabel.Name      = "m_textBox";
            m_verseTextLabel.Dock      = DockStyle.Fill;
            m_verseTextLabel.TabIndex  = 0;
            m_verseTextLabel.TextAlign = ContentAlignment.TopLeft;
            //m_verseTextLabel.BorderStyle = BorderStyle.None;
            //m_textBox.SuppressEnter = true;
            m_pnlActualVerseText.Controls.Add(m_verseTextLabel);
            // ENHANCE: Figure out how to get each part (paragraph) of the verse onm its own line. Using newlines or hard line breaks doesn't work.
            ITsIncStrBldr bldr = TsIncStrBldrClass.Create();

            foreach (TeEditingHelper.VerseTextSubstring verseTextSubstring in TeEditingHelper.GetVerseText(cache.LangProject.TranslatedScriptureOA, scrRef))
            {
                bldr.AppendTsString(verseTextSubstring.Tss);
                bldr.Append(StringUtils.kChHardLB.ToString());
            }
            m_verseTextLabel.Tss = bldr.GetString();
            //m_verseTextLabel.Tss = TeEditingHelper.GetVerseText(cache.LangProject.TranslatedScriptureOA, scrRef).ToString(true, StringUtils.kChHardLB.ToString());
        }