diff --git a/Src/FdoUi/WfiWordformUi.cs b/Src/FdoUi/WfiWordformUi.cs index eebb682cf8..0ebf95a1da 100644 --- a/Src/FdoUi/WfiWordformUi.cs +++ b/Src/FdoUi/WfiWordformUi.cs @@ -2,10 +2,13 @@ // This software is licensed under the LGPL, version 2.1 or later // (http://www.gnu.org/licenses/lgpl-2.1.html) +using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Windows.Forms; using SIL.LCModel; +using SIL.LCModel.Infrastructure; namespace SIL.FieldWorks.FdoUi { @@ -76,6 +79,19 @@ protected override bool IsAcceptableContextToJump(string toolCurrent, string too public override bool CanDelete(out string cannotDeleteMsg) { + // Delete problem annotations of the word form. + // These aren't used within FieldWorks, and they block deletion. + NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () => + { + ICmBaseAnnotationRepository repository = base.Object.Cache.ServiceLocator.GetInstance(); + IEnumerable problemAnnotations = + from ann in repository.AllInstances() + where ann.BeginObjectRA == base.Object && ann.SourceRA is ICmAgent + select ann; + foreach (ICmBaseAnnotation problem in problemAnnotations) + m_cache.DomainDataByFlid.DeleteObj(problem.Hvo); + }); + if (base.CanDelete(out cannotDeleteMsg)) return true; cannotDeleteMsg = FdoUiStrings.ksCannotDeleteWordform;