示例#1
0
        internal string LinkRef(int hvo)
        {
            ICmObjectRepository repo = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>();

            if (!repo.IsValidObjectId(hvo))
            {
                return(null);
            }
            Guid       guid = repo.GetObject(hvo).Guid;
            FwLinkArgs link = new FwLinkArgs("lexiconEdit", guid);

            return(link.ToString());
        }
示例#2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // Get the checked occurrences;
            List <int> occurrences = m_rbv.CheckedItems;

            if (occurrences == null || occurrences.Count == 0)
            {
                // do nothing.
                return;
            }
            List <int> uniqueSegments =
                (from fake in occurrences
                 select m_clerk.VirtualListPublisher.get_ObjectProp(fake, ConcDecorator.kflidSegment)).Distinct().ToList
                    ();
            int insertIndex = m_owningSense.ExamplesOS.Count;             // by default, insert at the end.

            if (m_les != null)
            {
                // we were given a LexExampleSentence, so set our insertion index after the given one.
                insertIndex = m_owningSense.ExamplesOS.IndexOf(m_les) + 1;
            }

            UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoAddExamples, LexEdStrings.ksRedoAddExamples,
                                        m_cache.ActionHandlerAccessor,
                                        () =>
            {
                int cNewExamples = 0;
                ILexExampleSentence newLexExample = null;
                foreach (int segHvo in uniqueSegments)
                {
                    var seg = m_cache.ServiceLocator.GetObject(segHvo) as ISegment;
                    if (cNewExamples == 0 && m_les != null &&
                        m_les.Example.BestVernacularAlternative.Text == "***" &&
                        (m_les.TranslationsOC == null || m_les.TranslationsOC.Count == 0) &&
                        m_les.Reference.Length == 0)
                    {
                        // we were given an empty LexExampleSentence, so use this one for our first new Example.
                        newLexExample = m_les;
                    }
                    else
                    {
                        // create a new example sentence.
                        newLexExample =
                            m_cache.ServiceLocator.GetInstance <ILexExampleSentenceFactory>().Create();
                        m_owningSense.ExamplesOS.Insert(insertIndex + cNewExamples, newLexExample);
                        cNewExamples++;
                    }
                    // copy the segment string into the new LexExampleSentence
                    // Enhance: bold the relevant occurrence(s).
                    // LT-11388 Make sure baseline text gets copied into correct ws
                    var baseWs = GetBestVernWsForNewExample(seg);
                    newLexExample.Example.set_String(baseWs, seg.BaselineText);
                    if (seg.FreeTranslation.AvailableWritingSystemIds.Length > 0)
                    {
                        var trans = m_cache.ServiceLocator.GetInstance <ICmTranslationFactory>().Create(newLexExample,
                                                                                                        m_cache.ServiceLocator.GetInstance <ICmPossibilityRepository>().GetObject(
                                                                                                            CmPossibilityTags.kguidTranFreeTranslation));
                        trans.Translation.CopyAlternatives(seg.FreeTranslation);
                    }
                    if (seg.LiteralTranslation.AvailableWritingSystemIds.Length > 0)
                    {
                        var trans = m_cache.ServiceLocator.GetInstance <ICmTranslationFactory>().Create(newLexExample,
                                                                                                        m_cache.ServiceLocator.GetInstance <ICmPossibilityRepository>().GetObject(
                                                                                                            CmPossibilityTags.kguidTranLiteralTranslation));
                        trans.Translation.CopyAlternatives(seg.LiteralTranslation);
                    }
                    // copy the reference.
                    ITsString tssRef = seg.Paragraph.Reference(seg, seg.BeginOffset);
                    // convert the plain reference string into a link.
                    ITsStrBldr tsb = tssRef.GetBldr();
                    FwLinkArgs fwl = new FwLinkArgs("interlinearEdit", seg.Owner.Owner.Guid);
                    // It's not clear how to focus in on something smaller than the text when following
                    // a link.
                    //fwl.PropertyTableEntries.Add(new Property("LinkSegmentGuid", seg.Guid.ToString()));
                    tsb.SetStrPropValue(0, tsb.Length, (int)FwTextPropType.ktptObjData,
                                        (char)FwObjDataTypes.kodtExternalPathName + fwl.ToString());
                    tsb.SetStrPropValue(0, tsb.Length, (int)FwTextPropType.ktptNamedStyle,
                                        "Hyperlink");
                    newLexExample.Reference = tsb.GetString();
                }
            });
        }