/// <summary> /// When inserting a LexSense, copy the MSA from the one we are inserting after, or the /// first one. If this is the first one, we may need to create an MSA if the owning entry /// does not have an appropriate one. /// </summary> /// <param name="mediator"></param> /// <param name="classId"></param> /// <param name="hvoOwner"></param> /// <param name="flid"></param> /// <param name="insertionPosition"></param> /// <returns></returns> public new static LexSenseUi CreateNewUiObject(Mediator mediator, int classId, int hvoOwner, int flid, int insertionPosition) { LexSenseUi result = null; var cache = (FdoCache) mediator.PropertyTable.GetValue("cache"); UndoableUnitOfWorkHelper.Do(FdoUiStrings.ksUndoInsertSense, FdoUiStrings.ksRedoInsertSense, cache.ServiceLocator.GetInstance<IActionHandler>(), () => { ICmObject owner; int hvoMsa = 0; int chvo = cache.DomainDataByFlid.get_VecSize(hvoOwner, flid); if (chvo == 0) { // See if we're inserting a subsense. If so copy from parent. owner = cache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(hvoOwner); if (owner is ILexSense) { var ls = owner as ILexSense; hvoMsa = GetSafeHvoMsa(cache, ls); } else if (owner is ILexEntry) { // If we don't get the MSA here, trouble ensues. See LT-5411. hvoMsa = (owner as ILexEntry).FindOrCreateDefaultMsa().Hvo; } } else { int copyFrom = insertionPosition - 1; if (copyFrom < 0) copyFrom = 0; if (copyFrom < chvo) { var ls = cache.ServiceLocator.GetInstance<ILexSenseRepository>().GetObject(cache.DomainDataByFlid.get_VecItem(hvoOwner, flid, copyFrom)); hvoMsa = GetSafeHvoMsa(cache, ls); } } owner = cache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(hvoOwner); var newSense = cache.ServiceLocator.GetInstance<ILexSenseFactory>().Create(); if (owner is ILexSense) { (owner as ILexSense).SensesOS.Insert(insertionPosition, newSense); } else { ((ILexEntry)owner).SensesOS.Insert(insertionPosition, newSense); } if (hvoMsa != 0) newSense.MorphoSyntaxAnalysisRA = cache.ServiceLocator.GetInstance<IMoMorphSynAnalysisRepository>().GetObject(hvoMsa); result = new LexSenseUi(newSense); }); return result; }
private static CmObjectUi MakeUi(FdoCache cache, int hvo, int clsid) { IFwMetaDataCache mdc = cache.DomainDataByFlid.MetaDataCache; // If we've encountered an object with this Clsid before, and this clsid isn't in // the switch below, the dictioanry will give us the appropriate clsid that IS in the // map, so the loop below will have only one iteration. Otherwise, we start the // search with the clsid of the object itself. int realClsid = m_subclasses.ContainsKey(clsid) ? m_subclasses[clsid] : clsid; // Each iteration investigates whether we have a CmObjectUi subclass that // corresponds to realClsid. If not, we move on to the base class of realClsid. // In this way, the CmObjectUi subclass we return is the one designed for the // closest base class of obj that has one. CmObjectUi result = null; while (result == null) { switch (realClsid) { // Todo: lots more useful cases. case WfiAnalysisTags.kClassId: result = new WfiAnalysisUi(); break; case PartOfSpeechTags.kClassId: result = new PartOfSpeechUi(); break; case CmPossibilityTags.kClassId: result = new CmPossibilityUi(); break; case CmObjectTags.kClassId: result = new CmObjectUi(); break; case LexPronunciationTags.kClassId: result = new LexPronunciationUi(); break; case LexSenseTags.kClassId: result = new LexSenseUi(); break; case LexEntryTags.kClassId: result = new LexEntryUi(); break; case MoMorphSynAnalysisTags.kClassId: result = new MoMorphSynAnalysisUi(); break; case MoStemMsaTags.kClassId: result = new MoStemMsaUi(); break; case MoDerivAffMsaTags.kClassId: result = new MoDerivAffMsaUi(); break; case MoInflAffMsaTags.kClassId: result = new MoInflAffMsaUi(); break; case MoAffixAllomorphTags.kClassId: case MoStemAllomorphTags.kClassId: result = new MoFormUi(); break; case ReversalIndexEntryTags.kClassId: result = new ReversalIndexEntryUi(); break; case WfiWordformTags.kClassId: result = new WfiWordformUi(); break; case WfiGlossTags.kClassId: result = new WfiGlossUi(); break; default: realClsid = mdc.GetBaseClsId(realClsid); // This isn't needed because CmObject.kClassId IS 0. // if (realClsid == 0) // { // // Somehow the class doesn't have CmObject in its inheritance path! // Debug.Assert(false); // // this may help make us more robust if this somehow happens. // realClsid = (uint)CmObject.kClassId; // } break; } } if (realClsid != clsid) m_subclasses[clsid] = realClsid; result.m_hvo = hvo; result.m_cache = cache; return result; }
/// <summary> /// When inserting a LexSense, copy the MSA from the one we are inserting after, or the /// first one. If this is the first one, we may need to create an MSA if the owning entry /// does not have an appropriate one. /// </summary> /// <param name="mediator"></param> /// <param name="classId"></param> /// <param name="hvoOwner"></param> /// <param name="flid"></param> /// <param name="insertionPosition"></param> /// <returns></returns> public new static LexSenseUi CreateNewUiObject(Mediator mediator, uint classId, int hvoOwner, int flid, int insertionPosition) { FdoCache cache = (FdoCache)mediator.PropertyTable.GetValue("cache"); cache.BeginUndoTask(FdoUiStrings.ksUndoInsertSense, FdoUiStrings.ksRedoInsertSense); int hvoMsa = 0; int chvo = cache.MainCacheAccessor.get_VecSize(hvoOwner, flid); if (chvo == 0) { // See if we're inserting a subsense. If so copy from parent. ICmObject owner = CmObject.CreateFromDBObject(cache, hvoOwner); if (owner is ILexSense) { hvoMsa = (owner as ILexSense).MorphoSyntaxAnalysisRAHvo; } else if (owner is ILexEntry) { // If we don't get the MSA here, trouble ensues. See LT-5411. hvoMsa = (owner as ILexEntry).FindOrCreateDefaultMsa(); } } else { int copyFrom = insertionPosition - 1; if (copyFrom < 0) copyFrom = 0; if (copyFrom < chvo) { int hvoCopyFrom = cache.MainCacheAccessor.get_VecItem(hvoOwner, flid, copyFrom); hvoMsa = cache.MainCacheAccessor.get_ObjectProp(hvoCopyFrom, (int)LexSense.LexSenseTags.kflidMorphoSyntaxAnalysis); } } int newHvo = cache.CreateObject((int)classId, hvoOwner, flid, insertionPosition); if (hvoMsa != 0) cache.MainCacheAccessor.SetObjProp(newHvo, (int)LexSense.LexSenseTags.kflidMorphoSyntaxAnalysis, hvoMsa); LexSenseUi result = new LexSenseUi(new LexSense(cache, newHvo, false, false)); cache.EndUndoTask(); cache.MainCacheAccessor.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvoOwner, flid, insertionPosition, 1, 0); return result; }