SIL.FieldWorks.FdoUi.PhonologicalFeatureEditor.DoIt C# (CSharp) Method

DoIt() public method

Execute the change requested by the current selection in the combo. There are two main cases: 1. The user is removing a feature. 2. The user is using priority union to include the values of a feature structure. The latter has two subcases: a. The user has selected a value for the targeted feature and we have put that value in a FsFeatStruc. b. The user has employed the chooser to build a FsFeatStruc with the value(s) to change. These values may or may not be for the targeted feature. We do nothing to (phoneme) records where the check box is turned off. For phonemes with the check box on, we either 1. remove the specified feature from the phoneme or 2. use priority union to set the value(s) in the FsFeatStruc.
public DoIt ( IEnumerable itemsToChange, SIL.FieldWorks.Common.Controls.ProgressState state ) : void
itemsToChange IEnumerable
state SIL.FieldWorks.Common.Controls.ProgressState
return void
		public void DoIt(IEnumerable<int> itemsToChange, ProgressState state)
		{
			CheckDisposed();

			string labelToShow = SelectedLabel;
			var selectedObject = m_cache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(SelectedHvo);

			int i = 0;
			// Report progress 50 times or every 100 items, whichever is more (but no more than once per item!)
			int interval = Math.Min(100, Math.Max(itemsToChange.Count()/50, 1));
			m_cache.DomainDataByFlid.BeginUndoTask(FdoUiStrings.ksUndoBEPhonemeFeatures, FdoUiStrings.ksRedoBEPhonemeFeatures);
			if (SelectedHvo != 0)
			{
				IFsFeatStruc fsTarget = GetTargetFsFeatStruc();
				foreach (var hvoPhoneme in itemsToChange)
				{
					i++;
					if (i%interval == 0)
					{
						state.PercentDone = i * 100 / itemsToChange.Count() + 20;
						state.Breath();
					}
					var phoneme = m_cache.ServiceLocator.GetInstance<IPhPhonemeRepository>().GetObject(hvoPhoneme);
					if (phoneme.FeaturesOA == null)
						phoneme.FeaturesOA = Cache.ServiceLocator.GetInstance<IFsFeatStrucFactory>().Create();
					if (fsTarget == null && selectedObject is IFsClosedFeature)
					{  // it's the remove option
						var closedValues = from s in phoneme.FeaturesOA.FeatureSpecsOC
										   where s.FeatureRA == selectedObject
										   select s;
						if (closedValues.Any())
							phoneme.FeaturesOA.FeatureSpecsOC.Remove(closedValues.First());
					}
					else
					{
						phoneme.FeaturesOA.PriorityUnion(fsTarget);
					}
				}
			}
			m_cache.DomainDataByFlid.EndUndoTask();
		}