示例#1
0
        public override ObjectLabel Execute()
        {
            ObjectLabel result = null;

            if (m_lexEntryRef != null)
            {
                using (LinkEntryOrSenseDlg dlg = new LinkEntryOrSenseDlg())
                {
                    ILexEntry le = null;
                    // assume the owner is the entry (e.g. owner of LexEntryRef)
                    le = m_lexEntryRef.OwnerOfClass <ILexEntry>();
                    dlg.SetDlgInfo(m_cache, m_mediator, le);
                    dlg.SetHelpTopic("khtpChooseLexicalEntryOrSense");
                    if (dlg.ShowDialog(m_parentWindow) == DialogResult.OK)
                    {
                        ICmObject obj = dlg.SelectedObject;
                        if (obj != null)
                        {
                            if (!m_lexEntryRef.PrimaryLexemesRS.Contains(obj))
                            {
                                try
                                {
                                    UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(
                                        LexEdStrings.ksUndoCreatingEntry,
                                        LexEdStrings.ksRedoCreatingEntry,
                                        Cache.ActionHandlerAccessor,
                                        () =>
                                    {
                                        if (!m_lexEntryRef.ComponentLexemesRS.Contains(obj))
                                        {
                                            m_lexEntryRef.ComponentLexemesRS.Add(obj);
                                        }
                                        m_lexEntryRef.PrimaryLexemesRS.Add(obj);
                                    });
                                }
                                catch (ArgumentException)
                                {
                                    EntrySequenceReferenceLauncher.ReportComponentFailure((ILexEntry)m_lexEntryRef.Owner, obj, true);
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
示例#2
0
        public override ObjectLabel Execute()
        {
            ObjectLabel result = null;

            if (m_lexEntry != null)
            {
                using (var dlg = new EntryGoDlg())
                {
                    dlg.SetDlgInfo(m_cache, null, m_mediator);
                    dlg.SetHelpTopic("khtpChooseLexicalEntryOrSense");                     // TODO: When LT-11318 is fixed, use its help topic ID.
                    dlg.SetOkButtonText(LexEdStrings.ksMakeComponentOf);
                    if (dlg.ShowDialog(m_parentWindow) == DialogResult.OK)
                    {
                        try
                        {
                            if (m_lexSense != null)
                            {
                                UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoAddComplexForm, LexEdStrings.ksRedoAddComplexForm,
                                                            m_lexEntry.Cache.ActionHandlerAccessor,
                                                            () => ((ILexEntry)dlg.SelectedObject).AddComponent((ICmObject)m_lexSense ?? m_lexEntry));
                            }
                            else
                            {
                                UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoAddComplexForm, LexEdStrings.ksRedoAddComplexForm,
                                                            m_lexEntry.Cache.ActionHandlerAccessor,
                                                            () => ((ILexEntry)dlg.SelectedObject).AddComponent(m_lexEntry));
                            }
                        }
                        catch (ArgumentException)
                        {
                            EntrySequenceReferenceLauncher.ReportComponentFailure((ILexEntry)dlg.SelectedObject, m_lexEntry, false);
                        }
                    }
                }
            }
            return(result);
        }
示例#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;

                    // 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)
            {
                EntrySequenceReferenceLauncher.ReportComponentFailure((ILexEntry)m_obj, newObj, true);
                return;
            }
        }