Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LT-20509: Can't delete words with undefined phonemes #166

Merged
merged 8 commits into from
Oct 8, 2024
16 changes: 16 additions & 0 deletions Src/FdoUi/WfiWordformUi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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<ICmBaseAnnotationRepository>();
IEnumerable<ICmBaseAnnotation> 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;
Expand Down
Loading