コード例 #1
0
        /// <summary>
        /// The user selected an item; now we actually need a LexEntryRef.
        /// </summary>
        /// <param name="hvoNew"></param>
        private void AddItem(ICmObject newObj)
        {
            CheckDisposed();

            bool   fForVariant = XmlUtils.GetOptionalBooleanAttributeValue(m_configurationNode, "forVariant", false);
            string sUndo, sRedo;

            if (fForVariant)
            {
                sUndo = LexEdStrings.ksUndoVariantOf;
                sRedo = LexEdStrings.ksRedoVariantOf;
            }
            else
            {
                sUndo = LexEdStrings.ksUndoAddComponent;
                sRedo = LexEdStrings.ksRedoAddComponent;
            }
            try
            {
                UndoableUnitOfWorkHelper.Do(sUndo, sRedo, m_obj,
                                            () =>
                {
                    ILexEntry ent = m_obj as ILexEntry;

                    // Adapted from part of DtMenuHandler.AddNewLexEntryRef.
                    ILexEntryRef ler = ent.Services.GetInstance <ILexEntryRefFactory>().Create();
                    ent.EntryRefsOS.Add(ler);
                    if (fForVariant)
                    {
                        // The slice this is part of should only be displayed for lex entries with no VariantEntryRefs.
                        Debug.Assert(ent.VariantEntryRefs.Count() == 0);
                        ler.VariantEntryTypesRS.Add(ent.Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS[0] as ILexEntryType);
                        ler.RefType        = LexEntryRefTags.krtVariant;
                        ler.HideMinorEntry = 0;
                    }
                    else
                    {
                        // The slice this is part of should only be displayed for lex entries with no ComplexEntryRefs.
                        Debug.Assert(ent.ComplexFormEntryRefs.Count() == 0);
                        //ler.ComplexEntryTypesRS.Append(ent.Cache.LangProject.LexDbOA.ComplexEntryTypesOA.PossibilitiesOS[0].Hvo);
                        ler.RefType        = LexEntryRefTags.krtComplexForm;
                        ler.HideMinorEntry = 0;                         // LT-10928
                        // Logic similar to this is in EntrySequenceReferenceLauncher.AddNewObjectsToProperty()
                        // (when LER already exists so slice is not ghost)
                        ler.PrimaryLexemesRS.Add(newObj);
                        // Since it's a new LER, we can't know it to be a derivative, so by default it is visible.
                        // but do NOT do that here, it's now built into the process of adding it to PrimaryLexemes,
                        // and we don't want to do it twice.
                        // ler.ShowComplexFormsInRS.Add(newObj);
                        ent.ChangeRootToStem();
                    }
                    // Must do this AFTER setting the RefType (so dependent virtual properties can be updated properly)
                    ler.ComponentLexemesRS.Add(newObj);
                });
            }
            catch (ArgumentException)
            {
                MessageBoxes.ReportLexEntryCircularReference((ILexEntry)m_obj, newObj, true);
            }
        }
コード例 #2
0
ファイル: GhostLexRefSlice.cs プロジェクト: sillsdev/WorldPad
        /// <summary>
        /// The user selected an item; now we actually need a LexEntryRef.
        /// </summary>
        /// <param name="hvoNew"></param>
        private void AddItem(int hvoNew)
        {
            CheckDisposed();

            bool   fForVariant = XmlUtils.GetOptionalBooleanAttributeValue(m_configurationNode, "forVariant", false);
            string sUndo, sRedo;

            if (fForVariant)
            {
                sUndo = LexEdStrings.ksUndoVariantOf;
                sRedo = LexEdStrings.ksRedoVariantOf;
            }
            else
            {
                sUndo = LexEdStrings.ksUndoAddComponent;
                sRedo = LexEdStrings.ksRedoAddComponent;
            }
            using (new UndoRedoTaskHelper(m_obj.Cache, sUndo, sRedo))
            {
                ILexEntry ent = m_obj as ILexEntry;
                // The slice this is part of should only be displayed for lex entries with no EntryRefs.
                Debug.Assert(ent.EntryRefsOS.Count == 0);

                // Adapted from part of DtMenuHandler.AddNewLexEntryRef.
                ILexEntryRef ler = new LexEntryRef();
                ent.EntryRefsOS.Append(ler);
                if (fForVariant)
                {
                    ler.VariantEntryTypesRS.Append(ent.Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS[0].Hvo);
                    ler.RefType        = LexEntryRef.krtVariant;
                    ler.HideMinorEntry = 0;
                }
                else
                {
                    //ler.ComplexEntryTypesRS.Append(ent.Cache.LangProject.LexDbOA.ComplexEntryTypesOA.PossibilitiesOS[0].Hvo);
                    ler.RefType        = LexEntryRef.krtComplexForm;
                    ler.HideMinorEntry = 1;
                    ler.PrimaryLexemesRS.Append(hvoNew);
                    ent.ChangeRootToStem();
                }
                ler.ComponentLexemesRS.Append(hvoNew);
                // No automatic propchanged for new objects, need to let the view see it.
                // At that point our slice will be disposed, so don't do anything after this.
                ent.Cache.PropChanged(ent.Hvo, (int)LexEntry.LexEntryTags.kflidEntryRefs, 0, 1, 0);
            }
        }
コード例 #3
0
        /// <summary>
        /// The user selected an item; now we actually need a LexEntryRef.
        /// </summary>
        /// <param name="hvoNew"></param>
        private void AddItem(ICmObject newObj)
        {
            CheckDisposed();

            bool   fForVariant = XmlUtils.GetOptionalBooleanAttributeValue(m_configurationNode, "forVariant", false);
            string sUndo, sRedo;

            if (fForVariant)
            {
                sUndo = LexEdStrings.ksUndoVariantOf;
                sRedo = LexEdStrings.ksRedoVariantOf;
            }
            else
            {
                sUndo = LexEdStrings.ksUndoAddComponent;
                sRedo = LexEdStrings.ksRedoAddComponent;
            }
            try
            {
                UndoableUnitOfWorkHelper.Do(sUndo, sRedo, m_obj,
                                            () =>
                {
                    ILexEntry ent = m_obj as ILexEntry;

                    // It IS a ghost slice after all; it shouldn't already have any of whatever we're about to add.
                    Debug.Assert(!(fForVariant ? ent.VariantEntryRefs.Any() : ent.ComplexFormEntryRefs.Any()));
                    if (fForVariant ? ent.VariantEntryRefs.Any() : ent.ComplexFormEntryRefs.Any())
                    {
                        return;
                    }

                    // Adapted from part of DtMenuHandler.AddNewLexEntryRef.
                    ILexEntryRef ler = ent.Services.GetInstance <ILexEntryRefFactory>().Create();
                    ent.EntryRefsOS.Add(ler);
                    if (fForVariant)
                    {
                        const string unspecVariantEntryTypeGuid = "3942addb-99fd-43e9-ab7d-99025ceb0d4e";
                        var type = ent.Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS
                                   .First(lrt => lrt.Guid.ToString() == unspecVariantEntryTypeGuid) as ILexEntryType;
                        ler.VariantEntryTypesRS.Add(type);
                        ler.RefType        = LexEntryRefTags.krtVariant;
                        ler.HideMinorEntry = 0;
                    }
                    else
                    {
                        ler.RefType = LexEntryRefTags.krtComplexForm;
                        const string unspecComplexFormEntryTypeGuid = "fec038ed-6a8c-4fa5-bc96-a4f515a98c50";
                        var type = ent.Cache.LangProject.LexDbOA.ComplexEntryTypesOA.PossibilitiesOS
                                   .First(lrt => lrt.Guid.ToString() == unspecComplexFormEntryTypeGuid) as ILexEntryType;
                        ler.ComplexEntryTypesRS.Add(type);
                        ler.HideMinorEntry = 0;                         // LT-10928
                        // Logic similar to this is in EntrySequenceReferenceLauncher.AddNewObjectsToProperty()
                        // (when LER already exists so slice is not ghost)
                        ler.PrimaryLexemesRS.Add(newObj);
                        // Since it's a new LER, we can't know it to be a derivative, so by default it is visible.
                        // but do NOT do that here, it's now built into the process of adding it to PrimaryLexemes,
                        // and we don't want to do it twice.
                        ent.ChangeRootToStem();
                    }
                    // Must do this AFTER setting the RefType (so dependent virtual properties can be updated properly)
                    ler.ComponentLexemesRS.Add(newObj);
                });
            }
            catch (ArgumentException)
            {
                MessageBoxes.ReportLexEntryCircularReference(m_obj, newObj, true);
            }
        }