diff --git a/DistFiles/Language Explorer/Configuration/UtilityCatalogInclude.xml b/DistFiles/Language Explorer/Configuration/UtilityCatalogInclude.xml index d741ba7198..d0284c837f 100644 --- a/DistFiles/Language Explorer/Configuration/UtilityCatalogInclude.xml +++ b/DistFiles/Language Explorer/Configuration/UtilityCatalogInclude.xml @@ -3,6 +3,7 @@ + diff --git a/DistFiles/Language Explorer/Configuration/strings-en.xml b/DistFiles/Language Explorer/Configuration/strings-en.xml index 1eb29b3575..15ccd22384 100644 --- a/DistFiles/Language Explorer/Configuration/strings-en.xml +++ b/DistFiles/Language Explorer/Configuration/strings-en.xml @@ -303,6 +303,12 @@ + + + + + + diff --git a/Src/LexText/Interlinear/InterlinMaster.cs b/Src/LexText/Interlinear/InterlinMaster.cs index 5d9a139130..0347f8ac1a 100644 --- a/Src/LexText/Interlinear/InterlinMaster.cs +++ b/Src/LexText/Interlinear/InterlinMaster.cs @@ -883,6 +883,15 @@ protected override void OnValidating(System.ComponentModel.CancelEventArgs e) SaveWorkInProgress(); } + public void OnRefreshInterlin(object argument) + { + // Reset data. + RootStText = null; + m_idcAnalyze.ResetAnalysisCache(); + // Refresh the display. + Clerk.JumpToIndex(Clerk.CurrentIndex); + } + protected override void ShowRecord() { SaveWorkInProgress(); diff --git a/Src/LexText/Morphology/MorphologyEditorDll.csproj b/Src/LexText/Morphology/MorphologyEditorDll.csproj index 381492f4ae..8744e11db1 100644 --- a/Src/LexText/Morphology/MorphologyEditorDll.csproj +++ b/Src/LexText/Morphology/MorphologyEditorDll.csproj @@ -384,6 +384,7 @@ UserControl + Form diff --git a/Src/LexText/Morphology/UserAnalysisRemover.cs b/Src/LexText/Morphology/UserAnalysisRemover.cs new file mode 100644 index 0000000000..4e7990f999 --- /dev/null +++ b/Src/LexText/Morphology/UserAnalysisRemover.cs @@ -0,0 +1,133 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SIL.FieldWorks.Common.FwUtils; +using SIL.FieldWorks.FwCoreDlgs; +using SIL.LCModel.Infrastructure; +using SIL.LCModel; + +namespace SIL.FieldWorks.XWorks.MorphologyEditor +{ + /// + /// This class serves to remove all analyses that are only approved by the user. + /// Analyses that have a parser evaluation (approved or disapproved) remain afterwards. + /// + public class UserAnalysisRemover : IUtility + { + #region Data members + + private UtilityDlg m_dlg; + const string kPath = "/group[@id='Linguistics']/group[@id='Morphology']/group[@id='RemoveUserAnalyses']/"; + + #endregion Data members + + /// + /// Override method to return the Label property. + /// + /// + public override string ToString() + { + return Label; + } + + #region IUtility implementation + + /// + /// Get the main label describing the utility. + /// + public string Label + { + get + { + Debug.Assert(m_dlg != null); + return StringTable.Table.GetStringWithXPath("Label", kPath); + } + } + + /// + /// Set the UtilityDlg. + /// + /// + /// This must be set, before calling any other property or method. + /// + public UtilityDlg Dialog + { + set + { + Debug.Assert(value != null); + Debug.Assert(m_dlg == null); + + m_dlg = value; + } + } + + /// + /// Load 0 or more items in the list box. + /// + public void LoadUtilities() + { + Debug.Assert(m_dlg != null); + m_dlg.Utilities.Items.Add(this); + + } + + /// + /// Notify the utility that has been selected in the dlg. + /// + public void OnSelection() + { + Debug.Assert(m_dlg != null); + m_dlg.WhenDescription = StringTable.Table.GetStringWithXPath("WhenDescription", kPath); + m_dlg.WhatDescription = StringTable.Table.GetStringWithXPath("WhatDescription", kPath); + m_dlg.RedoDescription = StringTable.Table.GetStringWithXPath("RedoDescription", kPath); + } + + /// + /// Have the utility do what it does. + /// + public void Process() + { + Debug.Assert(m_dlg != null); + var cache = m_dlg.PropTable.GetValue("cache"); + IWfiAnalysis[] analyses = cache.ServiceLocator.GetInstance().AllInstances().ToArray(); + if (analyses.Length == 0) + return; + + // Set up progress bar. + m_dlg.ProgressBar.Minimum = 0; + m_dlg.ProgressBar.Maximum = analyses.Length; + m_dlg.ProgressBar.Step = 1; + + NonUndoableUnitOfWorkHelper.Do(cache.ActionHandlerAccessor, () => + { + foreach (IWfiAnalysis analysis in analyses) + { + ICmAgentEvaluation[] humanEvals = analysis.EvaluationsRC.Where(evaluation => evaluation.Human).ToArray(); + foreach (ICmAgentEvaluation humanEval in humanEvals) + analysis.EvaluationsRC.Remove(humanEval); + + IWfiWordform wordform = analysis.Wordform; + if (analysis.EvaluationsRC.Count == 0) + wordform.AnalysesOC.Remove(analysis); + + if (humanEvals.Length > 0) + { + wordform.Checksum = 0; + if (analysis.Cache != null) + analysis.MoveConcAnnotationsToWordform(); + } + + m_dlg.ProgressBar.PerformStep(); + } + }); + + m_dlg.Mediator.SendMessage("RefreshInterlin", null); + + } + + #endregion IUtility implementation + } +}