Esempio n. 1
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;

            using (var featChooser = new 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, m_propertyTable, rule.OwningRule, ctxt);
                    }
                    else
                    {
                        featChooser.SetDlgInfo(m_cache, Mediator, m_propertyTable, natClass, PhNCFeaturesTags.kflidFeatures);
                    }
                }
                else
                {
                    if (natClass.FeaturesOA != null)
                    {
                        featChooser.SetDlgInfo(m_cache, Mediator, m_propertyTable, natClass.FeaturesOA);
                    }
                    else
                    {
                        featChooser.SetDlgInfo(m_cache, Mediator, m_propertyTable);
                    }
                }
                // 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();
            }
        }
        void link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            RuleInsertType type = (RuleInsertType)e.Link.LinkData;

            string optStr = GetOptionString(type);
            var    undo   = string.Format(MEStrings.ksRuleUndoInsert, optStr);
            var    redo   = string.Format(MEStrings.ksRuleRedoInsert, optStr);

            object data = null;

            switch (type)
            {
            case RuleInsertType.PHONEME:
                var phonemes = m_cache.LangProject.PhonologicalDataOA.PhonemeSetsOS[0].PhonemesOC.Cast <ICmObject>();
                data = DisplayChooser(MEStrings.ksRulePhonemeOpt, MEStrings.ksRulePhonemeChooserLink,
                                      "phonemeEdit", "RulePhonemeFlatList", phonemes);
                break;

            case RuleInsertType.NATURAL_CLASS:
                var natClasses = m_cache.LangProject.PhonologicalDataOA.NaturalClassesOS.Cast <ICmObject>();
                data = DisplayChooser(MEStrings.ksRuleNCOpt, MEStrings.ksRuleNCChooserLink,
                                      "naturalClassedit", "RuleNaturalClassFlatList", natClasses);
                break;

            case RuleInsertType.FEATURES:
                using (var featChooser = new PhonologicalFeatureChooserDlg())
                {
                    featChooser.SetDlgInfo(m_cache, m_mediator);
                    if (this.Parent is SIL.FieldWorks.XWorks.MorphologyEditor.RegRuleFormulaControl)
                    {
                        featChooser.SetHelpTopic("khtpChoose-Grammar-PhonFeats-RegRuleFormulaControl");
                    }
                    else if (this.Parent is SIL.FieldWorks.XWorks.MorphologyEditor.MetaRuleFormulaControl)
                    {
                        featChooser.SetHelpTopic("khtpChoose-Grammar-PhonFeats-MetaRuleFormulaControl");
                    }
                    else if (this.Parent is SIL.FieldWorks.XWorks.MorphologyEditor.AffixRuleFormulaControl)
                    {
                        featChooser.SetHelpTopic("khtpChoose-LexiconEdit-PhonFeats-AffixRuleFormulaControl");
                    }
                    DialogResult res = featChooser.ShowDialog();
                    if (res == DialogResult.OK)
                    {
                        UndoableUnitOfWorkHelper.Do(undo, redo, m_cache.ActionHandlerAccessor, () =>
                        {
                            var featNC = m_cache.ServiceLocator.GetInstance <IPhNCFeaturesFactory>().Create();
                            m_cache.LangProject.PhonologicalDataOA.NaturalClassesOS.Add(featNC);
                            featNC.Name.SetUserWritingSystem(string.Format(MEStrings.ksRuleNCFeatsName, m_ruleName));
                            featNC.FeaturesOA = m_cache.ServiceLocator.GetInstance <IFsFeatStrucFactory>().Create();
                            featChooser.FS    = featNC.FeaturesOA;
                            featChooser.UpdateFeatureStructure();
                            data = featNC;
                        });
                    }
                    else if (res != DialogResult.Cancel)
                    {
                        featChooser.HandleJump();
                    }
                }
                break;

            case RuleInsertType.WORD_BOUNDARY:
                data = m_cache.ServiceLocator.GetInstance <IPhBdryMarkerRepository>().GetObject(LangProjectTags.kguidPhRuleWordBdry);
                break;

            case RuleInsertType.MORPHEME_BOUNDARY:
                data = m_cache.ServiceLocator.GetInstance <IPhBdryMarkerRepository>().GetObject(LangProjectTags.kguidPhRuleMorphBdry);
                break;

            case RuleInsertType.INDEX:
                // put the clicked index in the data field
                data = (int)e.Link.Tag;
                break;
            }

            // Some cases will do nothing (and so make an empty UOW) if data is empty. However, other cases
            // (such as inserting X Variable, LT-11136) need the event even if data is empty, and the empty UOW
            // is discarded harmlessly.
            Insert(this, new RuleInsertEventArgs(type, data, undo, redo));
        }
 protected override void SetupPhonologicalFeatureChoooserDlg(PhonologicalFeatureChooserDlg featChooser)
 {
     featChooser.ShowFeatureConstraintValues = true;
     featChooser.SetDlgInfo(m_cache, m_mediator, Rhs.OwningRule);
 }
Esempio n. 4
0
        void link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            RuleInsertType type = (RuleInsertType)e.Link.LinkData;

            string optStr = GetOptionString(type);

            using (new UndoRedoTaskHelper(m_cache, string.Format(MEStrings.ksRuleUndoInsert, optStr),
                                          string.Format(MEStrings.ksRuleRedoInsert, optStr)))
            {
                int data = -1;
                switch (type)
                {
                case RuleInsertType.PHONEME:
                    Set <int> phonemes   = new Set <int>(m_cache.LangProject.PhonologicalDataOA.PhonemeSetsOS[0].PhonemesOC.HvoArray);
                    int       phonemeHvo = DisplayChooser(MEStrings.ksRulePhonemeOpt, MEStrings.ksRulePhonemeChooserLink,
                                                          "phonemeEdit", "RulePhonemeFlatList", phonemes);
                    if (phonemeHvo != 0)
                    {
                        data = phonemeHvo;
                    }
                    break;

                case RuleInsertType.NATURAL_CLASS:
                    Set <int> natClasses = new Set <int>(m_cache.LangProject.PhonologicalDataOA.NaturalClassesOS.HvoArray);
                    int       ncHvo      = DisplayChooser(MEStrings.ksRuleNCOpt, MEStrings.ksRuleNCChooserLink,
                                                          "naturalClassedit", "RuleNaturalClassFlatList", natClasses);
                    if (ncHvo != 0)
                    {
                        data = ncHvo;
                    }
                    break;

                case RuleInsertType.FEATURES:
                    using (PhonologicalFeatureChooserDlg featChooser = new PhonologicalFeatureChooserDlg())
                    {
                        featChooser.SetDlgInfo(m_cache, m_mediator);
                        if (this.Parent is SIL.FieldWorks.XWorks.MorphologyEditor.RegRuleFormulaControl)
                        {
                            featChooser.SetHelpTopic("khtpChoose-Grammar-PhonFeats-RegRuleFormulaControl");
                        }
                        else if (this.Parent is SIL.FieldWorks.XWorks.MorphologyEditor.MetaRuleFormulaControl)
                        {
                            featChooser.SetHelpTopic("khtpChoose-Grammar-PhonFeats-MetaRuleFormulaControl");
                        }
                        else if (this.Parent is SIL.FieldWorks.XWorks.MorphologyEditor.AffixRuleFormulaControl)
                        {
                            featChooser.SetHelpTopic("khtpChoose-LexiconEdit-PhonFeats-AffixRuleFormulaControl");
                        }
                        DialogResult res = featChooser.ShowDialog();
                        if (res == DialogResult.OK)
                        {
                            PhNCFeatures featNC = new PhNCFeatures();
                            m_cache.LangProject.PhonologicalDataOA.NaturalClassesOS.Append(featNC);
                            featNC.Name.UserDefaultWritingSystem = string.Format(MEStrings.ksRuleNCFeatsName, m_ruleName);
                            featNC.FeaturesOA = new FsFeatStruc();
                            featChooser.FS    = featNC.FeaturesOA;
                            featChooser.UpdateFeatureStructure();
                            featNC.FeaturesOA.NotifyNew();
                            featNC.NotifyNew();
                            data = featNC.Hvo;
                        }
                        else if (res != DialogResult.Cancel)
                        {
                            featChooser.HandleJump();
                        }
                    }
                    break;

                case RuleInsertType.WORD_BOUNDARY:
                    data = m_cache.GetIdFromGuid(LangProject.kguidPhRuleWordBdry);
                    break;

                case RuleInsertType.MORPHEME_BOUNDARY:
                    data = m_cache.GetIdFromGuid(LangProject.kguidPhRuleMorphBdry);
                    break;

                case RuleInsertType.INDEX:
                    // put the clicked index in the data field
                    data = (int)e.Link.Tag;
                    break;

                default:
                    data = 0;
                    break;
                }

                Insert(this, new RuleInsertEventArgs(type, data));
            }
        }
Esempio n. 5
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 (new UndoRedoTaskHelper(m_cache, MEStrings.ksRuleUndoSetFeatures, MEStrings.ksRuleRedoSetFeatures))
			{
				using (PhonologicalFeatureChooserDlg featChooser = new PhonologicalFeatureChooserDlg())
				{
					IPhSimpleContextNC ctxt = new PhSimpleContextNC(m_cache, CurrentContextHvo);
					IPhNCFeatures natClass = ctxt.FeatureStructureRA as IPhNCFeatures;
					featChooser.Title = MEStrings.ksRuleFeatsChooserTitle;
					featChooser.SetHelpTopic("khtpChoose-Grammar-PhonRules-SetPhonologicalFeatures");

					if (natClass.FeaturesOAHvo != 0)
						featChooser.SetDlgInfo(m_cache, Mediator, natClass.FeaturesOA);
					else
						featChooser.SetDlgInfo(m_cache, Mediator, natClass, (int)PhNCFeatures.PhNCFeaturesTags.kflidFeatures);

					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();
			}
		}
Esempio n. 6
0
		protected virtual void SetupPhonologicalFeatureChoooserDlg(PhonologicalFeatureChooserDlg featChooser)
		{
			featChooser.SetDlgInfo(m_cache, m_mediator);
		}
Esempio n. 7
0
        protected override void m_treeCombo_AfterSelect(object sender, TreeViewEventArgs e)
        {
            HvoTreeNode selectedNode = e.Node as HvoTreeNode;
            PopupTree   pt           = GetPopupTree();

            switch (selectedNode.Hvo)
            {
            case kChoosePhonologicaFeatures:
                // Only launch the dialog by a mouse click (or simulated mouse click).
                if (e.Action != TreeViewAction.ByMouse)
                {
                    break;
                }
                // Force the PopupTree to Hide() to trigger popupTree_PopupTreeClosed().
                // This will effectively revert the list selection to a previous confirmed state.
                // Whatever happens below, we don't want to actually leave the "Choose phonological features" node selected!
                // This is at least required if the user selects "Cancel" from the dialog below.
                // N.B. the above does not seem to be true; therefore we check for cancel and an empty result
                // and force the combo text to be what it should be.
                pt.Hide();
                using (PhonologicalFeatureChooserDlg dlg = new PhonologicalFeatureChooserDlg())
                {
                    Cache.DomainDataByFlid.BeginUndoTask(LexTextControls.ksUndoInsertPhonologicalFeature, LexTextControls.ksRedoInsertPhonologicalFeature);
                    var fs = CreateEmptyFeatureStructureInAnnotation(null);
                    dlg.SetDlgInfo(Cache, m_mediator, m_propertyTable, fs);
                    dlg.ShowIgnoreInsteadOfDontCare = true;
                    dlg.SetHelpTopic("khtptoolBulkEditPhonemesChooserDlg");

                    DialogResult result = dlg.ShowDialog(ParentForm);
                    if (result == DialogResult.OK)
                    {
                        if (dlg.FS != null)
                        {
                            var sFeatures = dlg.FS.LongName;
                            if (string.IsNullOrEmpty(sFeatures))
                            {
                                // user did not select anything in chooser; we want to show the last known node
                                // in the dropdown, not "choose phonological feature".
                                SetComboTextToLastConfirmedSelection();
                            }
                            else if (!pt.Nodes.ContainsKey(sFeatures))
                            {
                                var newSelectedNode = new HvoTreeNode(fs.LongNameTSS, fs.Hvo);
                                pt.Nodes.Add(newSelectedNode);
                                LoadPopupTree(fs.Hvo);
                                selectedNode = newSelectedNode;
                            }
                        }
                    }
                    else if (result != DialogResult.Cancel)
                    {
                        dlg.HandleJump();
                    }
                    else if (result == DialogResult.Cancel)
                    {
                        // The user canceled out of the chooser; we want to show the last known node
                        // in the dropdown, not "choose phonological feature".
                        SetComboTextToLastConfirmedSelection();
                    }
                    Cache.DomainDataByFlid.EndUndoTask();
                }
                break;
            }
            // FWR-3432 - If we get here and we still haven't got a valid Hvo, don't continue
            // on to the base method. It'll crash.
            if (selectedNode.Hvo == kChoosePhonologicaFeatures)
            {
                return;
            }
            base.m_treeCombo_AfterSelect(sender, e);
        }
		public void SetMappingFeatures()
		{
			SelectionHelper sel = SelectionHelper.Create(m_view);
			bool reconstruct = false;
			int index = -1;
			using (new UndoRedoTaskHelper(m_cache, MEStrings.ksAffixRuleUndoSetMappingFeatures, MEStrings.ksAffixRuleRedoSetMappingFeatures))
			{
				using (PhonologicalFeatureChooserDlg featChooser = new PhonologicalFeatureChooserDlg())
				{
					int hvo = CurrentHvo;
					switch (m_cache.GetClassOfObject(hvo))
					{
						case MoCopyFromInput.kclsidMoCopyFromInput:
							featChooser.SetDlgInfo(m_cache, m_mediator);
							if (featChooser.ShowDialog() == DialogResult.OK)
							{
								// create a new natural class behind the scenes
								PhNCFeatures featNC = new PhNCFeatures();
								m_cache.LangProject.PhonologicalDataOA.NaturalClassesOS.Append(featNC);
								featNC.Name.UserDefaultWritingSystem = string.Format(MEStrings.ksRuleNCFeatsName,
									Rule.Form.BestVernacularAnalysisAlternative.Text);
								featNC.FeaturesOA = new FsFeatStruc();
								featChooser.FS = featNC.FeaturesOA;
								featChooser.UpdateFeatureStructure();
								featNC.FeaturesOA.NotifyNew();
								featNC.NotifyNew();

								IMoCopyFromInput copy = new MoCopyFromInput(m_cache, hvo);
								IMoModifyFromInput newModify = new MoModifyFromInput();
								Rule.OutputOS.InsertAt(newModify, copy.IndexInOwner);
								newModify.ModificationRAHvo = featNC.Hvo;
								newModify.ContentRAHvo = copy.ContentRAHvo;
								index = newModify.IndexInOwner;
								newModify.NotifyNew();

								copy.DeleteUnderlyingObject();

								reconstruct = true;
							}
							break;

						case MoModifyFromInput.kclsidMoModifyFromInput:
							IMoModifyFromInput modify = new MoModifyFromInput(m_cache, hvo);
							featChooser.SetDlgInfo(m_cache, m_mediator, modify.ModificationRA.FeaturesOA);
							if (featChooser.ShowDialog() == DialogResult.OK)
							{
								if (modify.ModificationRA.FeaturesOA.FeatureSpecsOC.Count == 0)
								{
									IMoCopyFromInput newCopy = new MoCopyFromInput();
									Rule.OutputOS.InsertAt(newCopy, modify.IndexInOwner);
									newCopy.ContentRAHvo = modify.ContentRAHvo;
									index = newCopy.IndexInOwner;
									newCopy.NotifyNew();

									modify.DeleteUnderlyingObject();
								}
								else
								{
									index = modify.IndexInOwner;
								}
								reconstruct = true;
							}
							break;
					}
				}
			}

			m_view.Select();
			if (reconstruct)
				ReconstructView((int)MoAffixProcess.MoAffixProcessTags.kflidOutput, index, true);
		}