コード例 #1
0
        public static void JoinGlossAffixesOfInflVariantTypes(IEnumerable <ILexEntryType> variantEntryTypesRs, IWritingSystem wsGloss,
                                                              out ITsIncStrBldr sbJoinedGlossPrepend,
                                                              out ITsIncStrBldr sbJoinedGlossAppend)
        {
            sbJoinedGlossPrepend = TsIncStrBldrClass.Create();
            sbJoinedGlossAppend  = TsIncStrBldrClass.Create();

            const string sSeparator = kDefaultSeparatorLexEntryInflTypeGlossAffix;

            foreach (var leit in variantEntryTypesRs.Where(let => (let as ILexEntryInflType) != null)
                     .Select(let => (let as ILexEntryInflType)))
            {
                var       cache  = leit.Cache;
                var       wsUser = cache.ServiceLocator.WritingSystemManager.UserWritingSystem;
                int       wsActual1;
                ITsString tssGlossPrepend =
                    leit.GlossPrepend.GetAlternativeOrBestTss(wsGloss.Handle, out wsActual1);
                if (tssGlossPrepend.Length != 0)
                {
                    AppendGlossAffix(sbJoinedGlossPrepend, tssGlossPrepend, true, sSeparator, wsUser);
                }

                ITsString tssGlossAppend =
                    leit.GlossAppend.GetAlternativeOrBestTss(wsGloss.Handle, out wsActual1);
                if (tssGlossAppend.Length != 0)
                {
                    AppendGlossAffix(sbJoinedGlossAppend, tssGlossAppend, false, sSeparator, wsUser);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Get what would be produced for the headword of the specified entry in the specified WS,
        /// if it had the specified homograph number. (This is useful when overriding homograph
        /// numbers because items are omitted in a particular publication.) Use the specified default
        /// Citation Form if no Cf or Lf is present in the entry, and return an empty string for the
        /// whole method if there is no real or default Cf.
        /// </summary>
        public static ITsString HeadWordForWsAndHn(ILexEntry entry, int wsVern, int nHomograph, string defaultCf,
                                                   HomographConfiguration.HeadwordVariant hv)
        {
            var hc           = entry.Services.GetInstance <HomographConfiguration>();
            var citationForm = CitationFormWithAffixTypeStaticForWs(entry, wsVern, defaultCf);

            if (String.IsNullOrEmpty(citationForm))
            {
                return(entry.Cache.TsStrFactory.EmptyString(wsVern));
            }
            var tisb = TsIncStrBldrClass.Create();

            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsVern);
            if (hc.HomographNumberBefore)
            {
                InsertHomographNumber(tisb, nHomograph, hc, hv);
            }
            tisb.Append(citationForm);

            // (EricP) Tried to automatically update the homograph number, but doing that here will
            // steal away manual changes to the HomographNumber column. Also suppressing PropChanged
            // is necessary when HomographNumber column is enabled, otherwise changing the entry index can hang.
            //using (new IgnorePropChanged(cache, PropChangedHandling.SuppressView))
            //{
            //	  ValidateExistingHomographs(CollectHomographs(cache, ShortName1StaticForWs(cache, hvo, wsVern), 0, morphType));
            //}

            if (!hc.HomographNumberBefore)
            {
                InsertHomographNumber(tisb, nHomograph, hc, hv);
            }
            return(tisb.GetString());
        }
コード例 #3
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");
        }
コード例 #4
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);
        }
コード例 #5
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());
        }
コード例 #6
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;
        }
コード例 #7
0
        ITsString CreateFeatureLine(IFsClosedValue value)
        {
            ITsIncStrBldr featLine = TsIncStrBldrClass.Create();

            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());
        }
コード例 #8
0
 public void DontShowMessageBoxForAsserts()
 {
     using (DebugProcs debugProcs = new DebugProcs(false))
     {
         ITsIncStrBldr bldr = TsIncStrBldrClass.Create();
         // asserts - this brings up a message box if ShowAssertMessageBox doesn't work
         bldr.SetIntPropValues(1, 0, 0);
     }
 }
コード例 #9
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;
                    }
                }
            }
        }
コード例 #10
0
        public void ReportHook()
        {
            using (DummyDebugProcs debugProcs = new DummyDebugProcs(false))
            {
                ITsIncStrBldr bldr = TsIncStrBldrClass.Create();
                // next line asserts
                bldr.SetIntPropValues(1, 0, 0);

                Assert.IsTrue(debugProcs.m_fHandlerCalled);
            }
        }
コード例 #11
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(ILexReference lr)
        {
            CheckDisposed();
            if (lr == null)
            {
                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
            {
                var mainWindow = Mediator.PropertyTable.GetValue("window") as Form;
                using (new WaitCursor(mainWindow))
                {
                    using (var dlg = new ConfirmDeleteObjectDlg(m_mediator.HelpTopicProvider))
                    {
                        var ui = CmObjectUi.MakeUi(m_cache, lr.Hvo);

                        //We need this to determine which kind of relation we are deleting
                        var lrtOwner = lr.Owner as ILexRefType;

                        var userWs = m_cache.WritingSystemFactory.UserWs;
                        var tisb   = TsIncStrBldrClass.Create();
                        tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs);

                        switch ((LexRefTypeTags.MappingTypes)lrtOwner.MappingType)
                        {
                        case LexRefTypeTags.MappingTypes.kmtSenseTree:
                        case LexRefTypeTags.MappingTypes.kmtEntryTree:
                        case LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree:
                        case LexRefTypeTags.MappingTypes.kmtSenseUnidirectional:
                        case LexRefTypeTags.MappingTypes.kmtEntryUnidirectional:
                        case LexRefTypeTags.MappingTypes.kmtEntryOrSenseUnidirectional:
                            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs);
                            tisb.Append(String.Format(LexEdStrings.ksDeleteLexTree, StringUtils.kChHardLB));
                            dlg.SetDlgInfo(ui, m_cache, Mediator, tisb.GetString());
                            break;

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

                        if (DialogResult.Yes == dlg.ShowDialog(mainWindow))
                        {
                            UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoDeleteRelation, LexEdStrings.ksRedoDeleteRelation, m_obj, () =>
                            {
                                m_cache.DomainDataByFlid.DeleteObj(lr.Hvo);
                            });
                            //Update the display because we have removed this slice from the Lexical entry.
                            UpdateForDelete(lr);
                        }
                    }
                }
            }
        }
コード例 #12
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles a complex string that contains multiple runs with optional multiple
        /// text props applied.
        /// </summary>
        /// <param name="xml">The XML.</param>
        /// <param name="lgwsf">The writing system factory.</param>
        /// <returns>The created TsString</returns>
        /// ------------------------------------------------------------------------------------
        private static ITsString HandleComplexString(XElement xml, ILgWritingSystemFactory lgwsf)
        {
            var runs = xml.Elements("Run");

            if (runs.Count() == 0)
            {
                if (xml.Name.LocalName == "AStr" && xml.Attributes().Count() == 1)
                {
                    // This duplicates a little bit of code from HandleSimpleRun, but I wanted to keep that really simple
                    // and fast, and this case hardly ever happens...maybe not at all in real life.
                    XAttribute wsAttribute = xml.Attributes().First();
                    if (wsAttribute.Name.LocalName != "ws")
                    {
                        return(null);                        // we handle only single runs with only the ws attribute.
                    }
                    // Make sure the text is in the decomposed form (FWR-148)
                    string runText = Icu.Normalize(xml.Value, Icu.UNormalizationMode.UNORM_NFD);
                    return(s_strFactory.MakeString(runText, GetWsForId(wsAttribute.Value, lgwsf)));
                }
                return(null);                   // If we don't have any runs, we don't have a string!
            }

            var strBldr = TsIncStrBldrClass.Create();

            foreach (XElement runElement in runs)
            {
                if (runElement == null)
                {
                    throw new XmlSchemaException("TsString XML must contain a <Run> element contained in a <" + xml.Name.LocalName + "> element");
                }
                string runText = runElement.Value;
                if (runElement.Attribute("ws") == null && (runText.Length == 0 || runText[0] > 13))
                {
                    throw new XmlSchemaException("Run element must contain a ws attribute. Run text: " + runElement.Value);
                }

                // Make sure the text is in the decomposed form (FWR-148)
                runText = Icu.Normalize(runText, Icu.UNormalizationMode.UNORM_NFD);
                bool isOrcNeeded = TsPropsSerializer.GetPropAttributesForElement(runElement, lgwsf, strBldr);

                // Add an ORC character, if needed, for the run
                if (runText.Length == 0 && isOrcNeeded)
                {
                    runText = StringUtils.kszObject;
                }

                // Add the text with the properties to the builder
                strBldr.Append(runText);
            }

            return(strBldr.GetString());
        }
コード例 #13
0
        public void StringServices_CrawlRunsCanDeleteAllRuns()
        {
            var           wsEn       = Cache.WritingSystemFactory.GetWsFromStr("en");
            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) == wsEn ? null : run));
            Assert.That(result, Is.Null);
        }
コード例 #14
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);
        }
コード例 #15
0
        /// <summary>
        /// Get what would be produced for the headword of the specified entry in the specified WS,
        /// if it had the specified homograph number. (This is useful when overriding homograph
        /// numbers because items are omitted in a particular publication.) Use the specified default
        /// Citation Form if no Cf or Lf is present in the entry, and return an empty string for the
        /// whole method if there is no real or default Cf.
        /// </summary>
        public static ITsString HeadWordForWsAndHn(ILexEntry entry, int wsVern, int nHomograph, string defaultCf,
                                                   HomographConfiguration.HeadwordVariant hv)
        {
            var citationForm = CitationFormWithAffixTypeStaticForWs(entry, wsVern, defaultCf);

            if (String.IsNullOrEmpty(citationForm))
            {
                return(entry.Cache.TsStrFactory.EmptyString(wsVern));
            }
            var tisb = TsIncStrBldrClass.Create();

            AddHeadwordForWsAndHn(entry, wsVern, nHomograph, hv, tisb, citationForm);
            return(tisb.GetString());
        }
コード例 #16
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();
        }
コード例 #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 = TsIncStrBldrClass.Create();
                strBldr.Append(string.Empty);
                return(strBldr.GetString());
            }

            ITsStrFactory tsf = TsStrFactoryClass.Create();

            return(tsf.MakeString(string.Empty, ws));
        }
コード例 #18
0
        public void StringServices_CrawlRunsCanSuccessfullyDoNothingWithMultipleRuns()
        {
            var           wsEn       = Cache.WritingSystemFactory.GetWsFromStr("en");
            var           wsFr       = Cache.WritingSystemFactory.GetWsFromStr("fr");
            var           tssFactory = Cache.TsStrFactory;
            var           begin      = tssFactory.MakeString("beginning", wsEn);
            var           end        = tssFactory.MakeString("end", wsEn);
            ITsIncStrBldr tisb       = TsIncStrBldrClass.Create();

            tisb.AppendTsString(begin);
            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"));
        }
コード例 #19
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());
        }
コード例 #20
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);
        }
コード例 #21
0
ファイル: StVc.cs プロジェクト: sillsdev/WorldPad
        /// ------------------------------------------------------------------------------------
        /// <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());
        }
コード例 #22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="glossAffixAccessor">GlossPrepend or GlossAppend</param>
        /// <param name="wsGloss"></param>
        /// <param name="wsUser"></param>
        /// <returns></returns>
        public static ITsString AddTssGlossAffix(TsIncStrBldr sb, IMultiUnicode glossAffixAccessor,
                                                 IWritingSystem wsGloss, IWritingSystem wsUser)
        {
            if (sb == null)
            {
                sb = TsIncStrBldrClass.Create();
            }
            int       wsActual1;
            ITsString tssGlossPrepend = glossAffixAccessor.GetAlternativeOrBestTss(wsGloss.Handle, out wsActual1);

            if (tssGlossPrepend != null && tssGlossPrepend.Length != 0)
            {
                bool isPrepend = (glossAffixAccessor.Flid == LexEntryInflTypeTags.kflidGlossPrepend);
                AppendGlossAffix(sb, tssGlossPrepend, isPrepend, kDefaultSeparatorLexEntryInflTypeGlossAffix, wsUser);
            }
            return(tssGlossPrepend);
        }
コード例 #23
0
        private void CreateSearcher()
        {
            int control = 0;

            for (; m_curPossIndex < m_possibilities.Count; m_curPossIndex++)
            {
                // Every so often see whether the user has typed something that makes our search irrelevant.
                if (control++ % 50 == 0 && ShouldAbort())
                {
                    return;
                }

                ICmPossibility poss = m_possibilities[m_curPossIndex];
                ITsString      name = null;
                foreach (int ws in WritingSystemServices.GetWritingSystemIdsFromLabel(m_cache, m_displayWs, m_cache.ServiceLocator.WritingSystemManager.UserWritingSystem,
                                                                                      poss.Hvo, CmPossibilityTags.kflidName, null))
                {
                    ITsString tss = poss.Name.StringOrNull(ws);
                    if (tss != null && tss.Length > 0)
                    {
                        name = tss;
                        m_searcher.Add(poss, 0, tss);
                        break;
                    }
                }

                foreach (int ws in WritingSystemServices.GetWritingSystemIdsFromLabel(m_cache, m_displayWs, m_cache.ServiceLocator.WritingSystemManager.UserWritingSystem,
                                                                                      poss.Hvo, CmPossibilityTags.kflidAbbreviation, null))
                {
                    ITsString tss = poss.Abbreviation.StringOrNull(ws);
                    if (tss != null && tss.Length > 0)
                    {
                        m_searcher.Add(poss, 0, tss);
                        if (name != null)
                        {
                            var tisb = TsIncStrBldrClass.Create();
                            tisb.AppendTsString(tss);
                            tisb.AppendTsString(m_cache.TsStrFactory.MakeString(" - ", m_cache.DefaultUserWs));
                            tisb.AppendTsString(name);
                            m_searcher.Add(poss, 0, tisb.GetString());
                        }
                        break;
                    }
                }
            }
        }
コード例 #24
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);
        }
コード例 #25
0
        public void CreateFromStringRep_BT_MultiCharStylePara()
        {
            CheckDisposed();
            SetupBackTrans();

            ITsIncStrBldr strBldr = TsIncStrBldrClass.Create();

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

            // Setup expected results for the footnote
            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Emphasis");       // run 1
            strBldr.Append("Test Text");
            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null);             // run 2
            strBldr.Append("No char style");
            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Quoted Text");    // run 3
            strBldr.Append("Ahh!!!!!!");
            m_footnotePara.Contents.UnderlyingTsString = strBldr.GetString();

            // ... and now set up the expected results for the back translations of the footnote.
            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);

            // Define text representation and create a footnote from it.
            string footnoteRep = @"<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>";

            StFootnote footnote = StFootnote.CreateFromStringRep(m_book,
                                                                 (int)ScrBook.ScrBookTags.kflidFootnotes, footnoteRep, 0, "Note Marker");

            CompareFootnote(footnote);
        }
コード例 #26
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());
        }
コード例 #27
0
        ITsString CreateVariableLine(IPhFeatureConstraint var, bool polarity)
        {
            int varIndex = GetVarIndex(var);

            if (varIndex == -1)
            {
                return(m_questions);
            }

            ITsIncStrBldr varLine = TsIncStrBldrClass.Create();

            if (!polarity)
            {
                varLine.AppendTsString(m_cache.TsStrFactory.MakeString("-", m_cache.DefaultUserWs));
            }
            varLine.AppendTsString(m_cache.TsStrFactory.MakeString(VariableNames[varIndex], m_cache.DefaultUserWs));
            varLine.Append(" ");
            varLine.AppendTsString(var.FeatureRA == null ? m_questions : var.FeatureRA.Abbreviation.BestAnalysisAlternative);
            return(varLine.GetString());
        }
コード例 #28
0
        ITsString CreateVariableLine(IPhFeatureConstraint var, bool polarity)
        {
            int varIndex = GetVarIndex(var);

            if (varIndex == -1)
            {
                return(m_questions);
            }

            ITsIncStrBldr varLine = TsIncStrBldrClass.Create();

            if (!polarity)
            {
                varLine.Append("-");
            }
            varLine.AppendTsString(m_cache.MakeUserTss(VARIABLE_NAMES[varIndex]));
            varLine.Append(" ");
            varLine.AppendTsString(var.FeatureRAHvo == 0 ? m_questions : var.FeatureRA.Abbreviation.BestAnalysisAlternative);
            return(varLine.GetString());
        }
コード例 #29
0
        public static ITsString SpanStrToTsString(string source, int mainWs, ILgWritingSystemFactory wsf)
        {
            // How to build up an ITsString via an ITsIncStrBldr -
            // 1. Use SetIntPropValues or SetStrPropValues to set a property "to be applied to any subsequent append operations".
            // 2. THEN use Append(string s) to add a string, which will "pick up" the properties set in step 1.
            // See ScrFootnoteFactory.CreateRunFromStringRep() in FdoFactoryAdditions.cs for a good example.
            if (source == null)
            {
                return(null);
            }
            List <Run>    runs    = GetSpanRuns(source);
            ITsIncStrBldr builder = TsIncStrBldrClass.Create();

            // Will become: ITsIncStrBldr builder = TsStringUtils.MakeIncStrBldr();  // Add "using SIL.CoreImpl;" when this line is uncommented.
            foreach (Run run in runs)
            {
                builder.ClearProps();                 // Make sure there aren't leftover properties from previous run
                // To remove a string property, you set it to null, so we can just use StyleName directly whether or not it's null.
                builder.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, run.StyleName);
                int runWs = (run.Lang == null) ? mainWs : wsf.GetWsFromStr(run.Lang);
                builder.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, runWs);
                // We don't care about Guids in this function, so run.Guid is ignored
                // But we do need to set any other int or string properties that were in the original
                if (run.IntProperties != null)
                {
                    foreach (KeyValuePair <int, IntProperty> prop in run.IntProperties)
                    {
                        builder.SetIntPropValues(prop.Key, prop.Value.Variation, prop.Value.Value);
                    }
                }
                if (run.StringProperties != null)
                {
                    foreach (KeyValuePair <int, string> prop in run.StringProperties)
                    {
                        builder.SetStrPropValue(prop.Key, prop.Value);
                    }
                }
                builder.Append(run.Content);
            }
            return(builder.GetString());
        }
コード例 #30
0
        public void GetTextRepresentation_MultiCharStylePara()
        {
            CheckDisposed();

            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!!!!!!");

            // 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.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><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);
        }