/// <returns> /// 'true' means we found a suitable place to insert an object, /// not that it was actually inserted. It may, or may not, have been inserted in this case. /// 'false' means no suitable place was found, so the calling code can try other locations. /// </returns> private bool InsertObjectIfPossible(int newObjectClassId, int ownerClassId, string fieldName, Slice slice, string recomputeVirtual) { if ((ownerClassId > 0 && IsOrInheritsFrom((slice.Object.ClassID), ownerClassId)) // For adding senses using the simple edit mode, no matter where the cursor is. || slice.Object == Object //|| slice.Object == ContainingDataTree.Root) || slice.Object.Equals(ContainingDataTree.Root)) // Other cases. { // The slice's object has an acceptable type provided it implements the required field. // See if the current slice's object has the field named. int flid = slice.GetFlid(fieldName); var mdc = Cache.MetaDataCacheAccessor as IFwMetaDataCacheManaged; int flidT = ContainingDataTree.GetFlidIfPossible(ownerClassId, fieldName, mdc); if (flidT != 0 && flid != flidT) flid = flidT; if (flid == 0) return false; // Found a suitable slice. Do the insertion. int insertionPosition; // causes return false if not changed. if (m_cache.IsReferenceProperty(flid)) { insertionPosition = InsertObjectIntoVirtualBackref(Cache, m_mediator, slice.Object.Hvo, newObjectClassId, flid); } else { insertionPosition = slice.InsertObject(flid, newObjectClassId); } if (insertionPosition < 0) return insertionPosition == -2; // -2 keeps dlg for adding subPOSes from firing for each slice when cancelled. if (String.IsNullOrEmpty(recomputeVirtual)) return true; // Figure the things to recompute. string[] parts = recomputeVirtual.Split('.'); if (parts.Length != 2) { Debug.Assert(parts.Length == 2); return true; // but fairly harmless to ignore } return true; } return false; }
/// <summary> /// /// </summary> /// <param name="newObjectClassId"></param> /// <param name="ownerClassId"></param> /// <param name="fieldName"></param> /// <param name="slice"></param> /// <param name="recomputeVirtual"></param> /// <returns></returns> /// <remarks> /// 'true' means we found a suitable place to insert an object, /// not that it was actually inserted. It may, or may not, have been inserted in this case. /// 'false' means no suitable place was found, so the calling code can try other locations. /// </remarks> private bool InsertObjectIfPossible(uint newObjectClassId, uint ownerClassId, string fieldName, Slice slice, string recomputeVirtual) { if ((ownerClassId > 0 && IsOrInheritsFrom((uint)(slice.Object.ClassID), ownerClassId)) // For adding senses using the simple edit mode, no matter where the cursor is. || slice.Object == Object //|| slice.Object == ContainingDataTree.Root) || slice.Object.Equals(ContainingDataTree.Root)) // Other cases. { // The slice's object has an acceptable type provided it implements the required field. // See if the current slice's object has the field named. uint flid = slice.GetFlid(fieldName); uint flidT = m_cache.MetaDataCacheAccessor.GetFieldId2((uint)ownerClassId, fieldName, true); if (flidT != 0 && flid != flidT) flid = flidT; if (flid == 0) return false; // Found a suitable slice. Do the insertion. IFwMetaDataCache mdc = Cache.MetaDataCacheAccessor; int insertionPosition = -1; // causes return false if not changed. if (m_cache.IsReferenceProperty((int)flid)) { insertionPosition = Slice.InsertObjectIntoVirtualBackref(Cache, m_mediator, Cache.VwCacheDaAccessor.GetVirtualHandlerId((int)flid), slice.Object.Hvo, newObjectClassId, ownerClassId, flid); } else { insertionPosition = slice.InsertObject(flid, newObjectClassId); } if (insertionPosition < 0) return insertionPosition == -2; // -2 keeps dlg for adding subPOSes from firing for each slice when cancelled. if (String.IsNullOrEmpty(recomputeVirtual)) return true; // Figure the things to recompute. int hvoOwner = slice.Object.Hvo; string[] parts = recomputeVirtual.Split('.'); if (parts.Length != 2) { Debug.Assert(parts.Length == 2); return true; // but fairly harmless to ignore } uint clidVirtual = mdc.GetClassId(parts[0]); int flidVirtual = (int)mdc.GetFieldId2(clidVirtual, parts[1], true); ISilDataAccess sda = Cache.MainCacheAccessor; int chvo = sda.get_VecSize(hvoOwner, (int)flid); IVwVirtualHandler vh = Cache.VwCacheDaAccessor.GetVirtualHandlerId(flidVirtual); int typeVirtual = mdc.GetFieldType((uint)flidVirtual); if (vh == null) return true; // not a virtual property. for (int i = insertionPosition + 1; i < chvo; i++) { RecomputeVirtuals(sda.get_VecItem(hvoOwner, (int)flid, i), clidVirtual, flidVirtual, typeVirtual, mdc, sda, vh); } return true; } return false; }