public void SetMappingFeatures()
        {
            SelectionHelper.Create(m_view);
            bool reconstruct = false;
            int  index       = -1;

            UndoableUnitOfWorkHelper.Do(MEStrings.ksAffixRuleUndoSetMappingFeatures,
                                        MEStrings.ksAffixRuleRedoSetMappingFeatures, m_cache.ActionHandlerAccessor, () =>
            {
                using (var featChooser = new LexText.Controls.PhonologicalFeatureChooserDlg())
                {
                    var obj = CurrentObject;
                    switch (obj.ClassID)
                    {
                    case MoCopyFromInputTags.kClassId:
                        featChooser.SetDlgInfo(m_cache, m_mediator);
                        if (featChooser.ShowDialog() == DialogResult.OK)
                        {
                            // create a new natural class behind the scenes
                            var featNC = m_cache.ServiceLocator.GetInstance <IPhNCFeaturesFactory>().Create();
                            m_cache.LangProject.PhonologicalDataOA.NaturalClassesOS.Add(featNC);
                            featNC.Name.SetUserWritingSystem(string.Format(MEStrings.ksRuleNCFeatsName,
                                                                           Rule.Form.BestVernacularAnalysisAlternative.Text));
                            featNC.FeaturesOA = m_cache.ServiceLocator.GetInstance <IFsFeatStrucFactory>().Create();
                            featChooser.FS    = featNC.FeaturesOA;
                            featChooser.UpdateFeatureStructure();

                            var copy      = (IMoCopyFromInput)obj;
                            var newModify = m_cache.ServiceLocator.GetInstance <IMoModifyFromInputFactory>().Create();
                            Rule.OutputOS.Insert(copy.IndexInOwner, newModify);
                            newModify.ModificationRA = featNC;
                            newModify.ContentRA      = copy.ContentRA;
                            index = newModify.IndexInOwner;

                            Rule.OutputOS.Remove(copy);
                            reconstruct = true;
                        }
                        break;

                    case MoModifyFromInputTags.kClassId:
                        var modify = (IMoModifyFromInput)obj;
                        featChooser.SetDlgInfo(m_cache, m_mediator, modify.ModificationRA.FeaturesOA);
                        if (featChooser.ShowDialog() == DialogResult.OK)
                        {
                            if (modify.ModificationRA.FeaturesOA.FeatureSpecsOC.Count == 0)
                            {
                                var newCopy = m_cache.ServiceLocator.GetInstance <IMoCopyFromInputFactory>().Create();
                                Rule.OutputOS.Insert(modify.IndexInOwner, newCopy);
                                newCopy.ContentRA = modify.ContentRA;
                                index             = newCopy.IndexInOwner;

                                Rule.OutputOS.Remove(modify);
                            }
                            else
                            {
                                index = modify.IndexInOwner;
                            }
                            reconstruct = true;
                        }
                        break;
                    }
                }
            });

            m_view.Select();
            if (reconstruct)
            {
                ReconstructView(MoAffixProcessTags.kflidOutput, index, true);
            }
        }
		public void SetMappingFeatures()
		{
			SelectionHelper.Create(m_view);
			bool reconstruct = false;
			int index = -1;
			UndoableUnitOfWorkHelper.Do(MEStrings.ksAffixRuleUndoSetMappingFeatures,
				MEStrings.ksAffixRuleRedoSetMappingFeatures, m_cache.ActionHandlerAccessor, () =>
			{
				using (var featChooser = new LexText.Controls.PhonologicalFeatureChooserDlg())
				{
					var obj = CurrentObject;
					switch (obj.ClassID)
					{
						case MoCopyFromInputTags.kClassId:
							featChooser.SetDlgInfo(m_cache, m_mediator);
							if (featChooser.ShowDialog() == DialogResult.OK)
							{
								// create a new natural class behind the scenes
								var featNC = m_cache.ServiceLocator.GetInstance<IPhNCFeaturesFactory>().Create();
								m_cache.LangProject.PhonologicalDataOA.NaturalClassesOS.Add(featNC);
								featNC.Name.SetUserWritingSystem(string.Format(MEStrings.ksRuleNCFeatsName,
									Rule.Form.BestVernacularAnalysisAlternative.Text));
								featNC.FeaturesOA = m_cache.ServiceLocator.GetInstance<IFsFeatStrucFactory>().Create();
								featChooser.FS = featNC.FeaturesOA;
								featChooser.UpdateFeatureStructure();

								var copy = (IMoCopyFromInput) obj;
								var newModify = m_cache.ServiceLocator.GetInstance<IMoModifyFromInputFactory>().Create();
								Rule.OutputOS.Insert(copy.IndexInOwner, newModify);
								newModify.ModificationRA = featNC;
								newModify.ContentRA = copy.ContentRA;
								index = newModify.IndexInOwner;

								Rule.OutputOS.Remove(copy);
								reconstruct = true;
							}
							break;

						case MoModifyFromInputTags.kClassId:
							var modify = (IMoModifyFromInput) obj;
							featChooser.SetDlgInfo(m_cache, m_mediator, modify.ModificationRA.FeaturesOA);
							if (featChooser.ShowDialog() == DialogResult.OK)
							{
								if (modify.ModificationRA.FeaturesOA.FeatureSpecsOC.Count == 0)
								{
									var newCopy = m_cache.ServiceLocator.GetInstance<IMoCopyFromInputFactory>().Create();
									Rule.OutputOS.Insert(modify.IndexInOwner, newCopy);
									newCopy.ContentRA = modify.ContentRA;
									index = newCopy.IndexInOwner;

									Rule.OutputOS.Remove(modify);
								}
								else
								{
									index = modify.IndexInOwner;
								}
								reconstruct = true;
							}
							break;
					}
				}
			});

			m_view.Select();
			if (reconstruct)
				ReconstructView(MoAffixProcessTags.kflidOutput, index, true);
		}
示例#3
0
		/// <summary>
		/// Sets the phonological features for the currently selected natural class simple context with
		/// a feature-based natural class.
		/// </summary>
		public void SetContextFeatures()
		{
			SelectionHelper sel = SelectionHelper.Create(m_view);
			bool reconstruct = false;

			using (var featChooser = new LexText.Controls.PhonologicalFeatureChooserDlg())
			{
				var ctxt = (IPhSimpleContextNC) CurrentContext;
				var natClass = (IPhNCFeatures) ctxt.FeatureStructureRA;
				featChooser.Title = MEStrings.ksRuleFeatsChooserTitle;
				if (m_obj is IPhSegRuleRHS)
				{
					featChooser.ShowFeatureConstraintValues = true;
					if (natClass.FeaturesOA != null)
					{
						var rule = m_obj as IPhSegRuleRHS;
						featChooser.SetDlgInfo(m_cache, Mediator, rule.OwningRule, ctxt);
					}
					else
						featChooser.SetDlgInfo(m_cache, Mediator, natClass, PhNCFeaturesTags.kflidFeatures);
				}
				else
				{
					if (natClass.FeaturesOA != null)
						featChooser.SetDlgInfo(m_cache, Mediator, natClass.FeaturesOA);
					else
						featChooser.SetDlgInfo(m_cache, Mediator);
				}
				// FWR-2405: Setting the Help topic requires that the Mediator be already set!
				featChooser.SetHelpTopic("khtpChoose-Grammar-PhonRules-SetPhonologicalFeatures");
				DialogResult res = featChooser.ShowDialog();
				if (res != DialogResult.Cancel)
					featChooser.HandleJump();
				reconstruct = res == DialogResult.OK;
			}

			m_view.Select();
			if (reconstruct)
			{
				m_view.RootBox.Reconstruct();
				sel.RestoreSelectionAndScrollPos();
			}
		}