/// ------------------------------------------------------------------------------------ /// <summary> /// Deletes the picture specified by the hvo. /// </summary> /// <param name="helper">Selection containing the picture.</param> /// <param name="hvoPic">hvo of picture.</param> /// ------------------------------------------------------------------------------------ protected void DeletePicture(SelectionHelper helper, int hvoPic) { int paraHvo = helper.GetLevelInfoForTag((int)StText.StTextTags.kflidParagraphs).hvo; Debug.Assert(paraHvo != 0); int iBook, iSection; iBook = ((ITeView)Control).LocationTracker.GetBookIndex(helper, SelectionHelper.SelLimitType.Anchor); iSection = ((ITeView)Control).LocationTracker.GetSectionIndexInBook(helper, SelectionHelper.SelLimitType.Anchor); StTxtPara para = new StTxtPara(m_cache, paraHvo); // Find the ORC and delete it from the paragraph ITsString contents = para.Contents.UnderlyingTsString; int startOfRun = 0; for(int i = 0; i < contents.RunCount; i++) { string str = contents.get_Properties(i).GetStrPropValue( (int)FwTextPropType.ktptObjData); if (str != null) { Guid guid = MiscUtils.GetGuidFromObjData(str.Substring(1)); int hvo = m_cache.GetIdFromGuid(guid); if (hvo == hvoPic) { ITsStrBldr bldr = contents.GetBldr(); startOfRun = contents.get_MinOfRun(i); bldr.Replace(startOfRun, contents.get_LimOfRun(i), string.Empty, null); para.Contents.UnderlyingTsString = bldr.GetString(); break; } } } // TODO (TE-4967): do a prop change that actually works. // m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, // para.Hvo, (int)StTxtPara.StTxtParaTags.kflidContents, // startOfRun, 0, 1); if (FwApp.App != null) FwApp.App.RefreshAllViews(m_cache); m_cache.DeleteObject(hvoPic); // TODO (TimS): This code to create a selection in the paragraph the picture was // in probably won't work when deleting a picture in back translation // material (which isn't possible to insert yet). ((ITeView)Control).LocationTracker.SetBookAndSection(helper, SelectionHelper.SelLimitType.Anchor, iBook, iSection); helper.RemoveLevel((int)StTxtPara.StTxtParaTags.kflidContents); if (Callbacks != null && Callbacks.EditedRootBox != null) // may not exist in tests. { try { MakeSimpleTextSelection(helper.LevelInfo, (int)StTxtPara.StTxtParaTags.kflidContents, startOfRun); } catch { // If we couldn't make the selection in the contents, it's probably because // we are in a user prompt, so try that instead. MakeSimpleTextSelection(helper.LevelInfo, (int)SimpleRootSite.kTagUserPrompt, startOfRun); } Callbacks.EditedRootBox.Site.ScrollSelectionIntoView(Callbacks.EditedRootBox.Selection, VwScrollSelOpts.kssoNearTop); } }