/// <summary> /// Add the specified type of freeform annotation to the given segment. /// Undoable by default. /// </summary> /// <param name="hvoSeg"></param> /// <param name="hvoType">freeform annotation type</param> /// <returns></returns> public ICmIndirectAnnotation AddFreeformAnnotation(int hvoSeg, int hvoType) { using (SuppressSubTasks suppressor = new SuppressSubTasks(m_fdoCache, true)) { // convert any preceeding dummy segments, so paragraph parser does not push this to the first dummy sentence. (LT-7318) int hvoPara = m_fdoCache.GetObjProperty(hvoSeg, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginObject); StTxtPara para = StTxtPara.CreateFromDBObject(m_fdoCache, hvoPara) as StTxtPara; para.EnsurePreceedingSegmentsAreReal(hvoSeg); string undoString = ""; string redoString = ""; if (hvoType == ktagSegFF_freeTranslation) { undoString = ITextStrings.ksUndoAddFreeformTranslation; redoString = ITextStrings.ksRedoAddFreeformTranslation; } else if (hvoType == ktagSegFF_literalTranslation) { undoString = ITextStrings.ksUndoAddLiteralTranslation; redoString = ITextStrings.ksRedoAddLiteralTranslation; } else if (hvoType == ktagSegFF_note) { undoString = ITextStrings.ksUndoAddNote; redoString = ITextStrings.ksRedoAddNote; } else { throw new ArgumentException(String.Format("segment freeform type {0} is not yet supported here.", hvoType)); } ICmIndirectAnnotation ann; m_fdoCache.BeginUndoTask(undoString, redoString); { ann = CmIndirectAnnotation.CreateUnownedIndirectAnnotation(m_fdoCache); ann.AppliesToRS.Append(hvoSeg); ann.AnnotationTypeRAHvo = hvoType; // Add it to the cached collection of freeform annotations. This is a bit clumsy because // it isn't a real property so we can't just use the normal methods for modifying a property. // Enhance JohnT: put it with the other ones of the same type. ISilDataAccess sda = m_fdoCache.MainCacheAccessor; IVwCacheDa cda = (IVwCacheDa)sda; int cFreeForm = sda.get_VecSize(hvoSeg, ktagSegFF); int[] freeForms = new int[cFreeForm + 1]; for (int i = 0; i < cFreeForm; i++) { freeForms[i] = sda.get_VecItem(hvoSeg, ktagSegFF, i); } freeForms[cFreeForm] = ann.Hvo; cda.CacheVecProp(hvoSeg, ktagSegFF, freeForms, cFreeForm + 1); sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvoSeg, ktagSegFF, cFreeForm, 1, 0); } m_fdoCache.EndUndoTask(); return(ann); } }