static string GetOptionString(RuleInsertType type)
        {
            switch (type)
            {
            case RuleInsertType.MORPHEME_BOUNDARY:
                return(MEStrings.ksRuleMorphBdryOpt);

            case RuleInsertType.NATURAL_CLASS:
                return(MEStrings.ksRuleNCOpt);

            case RuleInsertType.PHONEME:
                return(MEStrings.ksRulePhonemeOpt);

            case RuleInsertType.WORD_BOUNDARY:
                return(MEStrings.ksRuleWordBdryOpt);

            case RuleInsertType.FEATURES:
                return(MEStrings.ksRuleFeaturesOpt);

            case RuleInsertType.VARIABLE:
                return(MEStrings.ksRuleVarOpt);

            case RuleInsertType.INDEX:
                return(MEStrings.ksRuleIndexOpt);

            case RuleInsertType.COLUMN:
                return(MEStrings.ksRuleColOpt);
            }

            return(null);
        }
Ejemplo n.º 2
0
		static string GetOptionString(RuleInsertType type)
		{
			switch (type)
			{
				case RuleInsertType.MORPHEME_BOUNDARY:
					return MEStrings.ksRuleMorphBdryOpt;

				case RuleInsertType.NATURAL_CLASS:
					return MEStrings.ksRuleNCOpt;

				case RuleInsertType.PHONEME:
					return MEStrings.ksRulePhonemeOpt;

				case RuleInsertType.WORD_BOUNDARY:
					return MEStrings.ksRuleWordBdryOpt;

				case RuleInsertType.FEATURES:
					return MEStrings.ksRuleFeaturesOpt;

				case RuleInsertType.VARIABLE:
					return MEStrings.ksRuleVarOpt;

				case RuleInsertType.INDEX:
					return MEStrings.ksRuleIndexOpt;

				case RuleInsertType.COLUMN:
					return MEStrings.ksRuleColOpt;
			}

			return null;
		}
Ejemplo n.º 3
0
        private bool DisplayOption(object option)
        {
            RuleInsertType  type   = ((InsertOption)option).Type;
            SelectionHelper sel    = SelectionHelper.Create(m_view);
            int             cellId = GetCell(sel);

            if (cellId == -1 || cellId == -2)
            {
                return(false);
            }

            switch (cellId)
            {
            case AffixRuleFormulaVc.ktagLeftEmpty:
            case AffixRuleFormulaVc.ktagRightEmpty:
                return(type != RuleInsertType.Index);

            case MoAffixProcessTags.kflidOutput:
                return(type == RuleInsertType.Index || type == RuleInsertType.Phoneme || type == RuleInsertType.MorphemeBoundary);

            default:
                var ctxtOrVar = m_cache.ServiceLocator.GetInstance <IPhContextOrVarRepository>().GetObject(cellId);
                if (ctxtOrVar.ClassID == PhVariableTags.kClassId)
                {
                    return(false);
                }
                return(type != RuleInsertType.Index);
            }
        }
 public RuleInsertEventArgs(RuleInsertType type, object data, string undoMsg, string redoMsg)
 {
     Type    = type;
     Data    = data;
     UndoMsg = undoMsg;
     RedoMsg = redoMsg;
 }
Ejemplo n.º 5
0
		private static string GetOptionString(RuleInsertType type)
		{
			switch (type)
			{
				case RuleInsertType.MorphemeBoundary:
					return MEStrings.ksRuleMorphBdryOpt;

				case RuleInsertType.NaturalClass:
					return MEStrings.ksRuleNCOpt;

				case RuleInsertType.Phoneme:
					return MEStrings.ksRulePhonemeOpt;

				case RuleInsertType.WordBoundary:
					return MEStrings.ksRuleWordBdryOpt;

				case RuleInsertType.Features:
					return MEStrings.ksRuleFeaturesOpt;

				case RuleInsertType.Variable:
					return MEStrings.ksRuleVarOpt;

				case RuleInsertType.Index:
					return MEStrings.ksRuleIndexOpt;

				case RuleInsertType.Column:
					return MEStrings.ksRuleColOpt;
			}

			return null;
		}
        /// <summary>
        /// Adds an insertion option. A predicate can be provided to determine in what contexts
        /// this insertion option can be displayed.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="shouldDisplay">The should display predicate.</param>
        public void AddOption(RuleInsertType type, DisplayOption shouldDisplay)
        {
            CheckDisposed();

            m_options.Add(new InsertOption(type, shouldDisplay, null));
        }
        bool DisplayOption(RuleInsertType type)
        {
            SelectionHelper sel    = SelectionHelper.Create(m_view);
            int             cellId = GetCell(sel);

            if (cellId == -1 || cellId == -2)
            {
                return(false);
            }

            switch (cellId)
            {
            case PhMetathesisRuleTags.kidxLeftSwitch:
                switch (type)
                {
                case RuleInsertType.WORD_BOUNDARY:
                    return(false);

                case RuleInsertType.MORPHEME_BOUNDARY:
                    if (Rule.LeftSwitchIndex == -1 || Rule.MiddleIndex != -1 || sel.IsRange)
                    {
                        return(false);
                    }
                    else
                    {
                        return(GetInsertionIndex(Rule.StrucDescOS.ToArray(), sel) == Rule.LeftSwitchIndex + 1);
                    }

                default:
                    if (Rule.LeftSwitchIndex == -1)
                    {
                        return(true);
                    }
                    else if (sel.IsRange)
                    {
                        var beginObj = GetItem(sel, SelectionHelper.SelLimitType.Top);
                        var endObj   = GetItem(sel, SelectionHelper.SelLimitType.Bottom);

                        IPhSimpleContext lastCtxt = null;
                        if (Rule.MiddleIndex != -1 && Rule.IsMiddleWithLeftSwitch)
                        {
                            lastCtxt = Rule.StrucDescOS[Rule.MiddleLimit - 1];
                        }
                        else
                        {
                            lastCtxt = Rule.StrucDescOS[Rule.LeftSwitchLimit - 1];
                        }

                        return(beginObj == Rule.StrucDescOS[Rule.LeftSwitchIndex] && endObj == lastCtxt);
                    }
                    return(false);
                }

            case PhMetathesisRuleTags.kidxRightSwitch:
                switch (type)
                {
                case RuleInsertType.WORD_BOUNDARY:
                    return(false);

                case RuleInsertType.MORPHEME_BOUNDARY:
                    if (Rule.RightSwitchIndex == -1 || Rule.MiddleIndex != -1 || sel.IsRange)
                    {
                        return(false);
                    }
                    else
                    {
                        return(GetInsertionIndex(Rule.StrucDescOS.ToArray(), sel) == Rule.RightSwitchIndex);
                    }

                default:
                    if (Rule.RightSwitchIndex == -1)
                    {
                        return(true);
                    }
                    else if (sel.IsRange)
                    {
                        var beginObj = GetItem(sel, SelectionHelper.SelLimitType.Top);
                        var endObj   = GetItem(sel, SelectionHelper.SelLimitType.Bottom);

                        IPhSimpleContext firstCtxt = null;
                        if (Rule.MiddleIndex != -1 && !Rule.IsMiddleWithLeftSwitch)
                        {
                            firstCtxt = Rule.StrucDescOS[Rule.MiddleIndex];
                        }
                        else
                        {
                            firstCtxt = Rule.StrucDescOS[Rule.RightSwitchIndex];
                        }

                        return(beginObj == firstCtxt && endObj == Rule.StrucDescOS[Rule.RightSwitchLimit - 1]);
                    }
                    return(false);
                }

            case PhMetathesisRuleTags.kidxLeftEnv:
                IPhSimpleContext[] leftCtxts = Rule.StrucDescOS.ToArray();
                IPhSimpleContext   first     = null;
                if (Rule.StrucDescOS.Count > 0)
                {
                    first = Rule.StrucDescOS[0];
                }

                if (type == RuleInsertType.WORD_BOUNDARY)
                {
                    // only display the word boundary option if we are at the beginning of the left context and
                    // there is no word boundary already inserted
                    if (sel.IsRange)
                    {
                        return(GetIndicesToRemove(leftCtxts, sel)[0] == 0);
                    }
                    else
                    {
                        return(GetInsertionIndex(leftCtxts, sel) == 0 && !IsWordBoundary(first));
                    }
                }
                else
                {
                    // we cannot insert anything to the left of a word boundary in the left context
                    return(sel.IsRange || GetInsertionIndex(leftCtxts, sel) != 0 || !IsWordBoundary(first));
                }

            case PhMetathesisRuleTags.kidxRightEnv:
                IPhSimpleContext[] rightCtxts = Rule.StrucDescOS.ToArray();
                IPhSimpleContext   last       = null;
                if (Rule.StrucDescOS.Count > 0)
                {
                    last = Rule.StrucDescOS[Rule.StrucDescOS.Count - 1];
                }
                if (type == RuleInsertType.WORD_BOUNDARY)
                {
                    // only display the word boundary option if we are at the end of the right context and
                    // there is no word boundary already inserted
                    if (sel.IsRange)
                    {
                        int[] indices = GetIndicesToRemove(rightCtxts, sel);
                        return(indices[indices.Length - 1] == rightCtxts.Length - 1);
                    }
                    else
                    {
                        return(GetInsertionIndex(rightCtxts, sel) == rightCtxts.Length && !IsWordBoundary(last));
                    }
                }
                else
                {
                    // we cannot insert anything to the right of a word boundary in the right context
                    return(sel.IsRange || GetInsertionIndex(rightCtxts, sel) != rightCtxts.Length || !IsWordBoundary(last));
                }
            }

            return(false);
        }
Ejemplo n.º 8
0
		bool DisplayOption(RuleInsertType type)
		{
			SelectionHelper sel = SelectionHelper.Create(m_view);
			int cellId = GetCell(sel);
			if (cellId == -1 || cellId == -2)
				return false;

			switch (cellId)
			{
				case PhMetathesisRule.kidxLeftSwitch:
					switch (type)
					{
						case RuleInsertType.WORD_BOUNDARY:
							return false;

						case RuleInsertType.MORPHEME_BOUNDARY:
							if (Rule.LeftSwitchIndex == -1 || Rule.MiddleIndex != -1 || sel.IsRange)
								return false;
							else
								return GetInsertionIndex(Rule.StrucDescOS.HvoArray, sel) == Rule.LeftSwitchIndex + 1;

						default:
							if (Rule.LeftSwitchIndex == -1)
							{
								return true;
							}
							else if (sel.IsRange)
							{
								int beginHvo = GetItemHvo(sel, SelectionHelper.SelLimitType.Top);
								int endHvo = GetItemHvo(sel, SelectionHelper.SelLimitType.Bottom);

								int lastHvo = 0;
								if (Rule.MiddleIndex != -1 && Rule.IsMiddleWithLeftSwitch)
									lastHvo = Rule.StrucDescOS[Rule.MiddleLimit - 1].Hvo;
								else
									lastHvo = Rule.StrucDescOS[Rule.LeftSwitchLimit - 1].Hvo;

								return beginHvo == Rule.StrucDescOS[Rule.LeftSwitchIndex].Hvo && endHvo == lastHvo;
							}
							return false;
					}

				case PhMetathesisRule.kidxRightSwitch:
					switch (type)
					{
						case RuleInsertType.WORD_BOUNDARY:
							return false;

						case RuleInsertType.MORPHEME_BOUNDARY:
							if (Rule.RightSwitchIndex == -1 || Rule.MiddleIndex != -1 || sel.IsRange)
								return false;
							else
								return GetInsertionIndex(Rule.StrucDescOS.HvoArray, sel) == Rule.RightSwitchIndex;

						default:
							if (Rule.RightSwitchIndex == -1)
							{
								return true;
							}
							else if (sel.IsRange)
							{
								int beginHvo = GetItemHvo(sel, SelectionHelper.SelLimitType.Top);
								int endHvo = GetItemHvo(sel, SelectionHelper.SelLimitType.Bottom);

								int firstHvo = 0;
								if (Rule.MiddleIndex != -1 && !Rule.IsMiddleWithLeftSwitch)
									firstHvo = Rule.StrucDescOS[Rule.MiddleIndex].Hvo;
								else
									firstHvo = Rule.StrucDescOS[Rule.RightSwitchIndex].Hvo;

								return beginHvo == firstHvo && endHvo == Rule.StrucDescOS[Rule.RightSwitchLimit - 1].Hvo;
							}
							return false;
					}

				case PhMetathesisRule.kidxLeftEnv:
					int[] leftHvos = Rule.StrucDescOS.HvoArray;
					IPhSimpleContext first = null;
					if (Rule.StrucDescOS.Count > 0)
						first = Rule.StrucDescOS[0];

					if (type == RuleInsertType.WORD_BOUNDARY)
					{
						// only display the word boundary option if we are at the beginning of the left context and
						// there is no word boundary already inserted
						if (sel.IsRange)
							return GetIndicesToRemove(leftHvos, sel)[0] == 0;
						else
							return GetInsertionIndex(leftHvos, sel) == 0 && !IsWordBoundary(first);
					}
					else
					{
						// we cannot insert anything to the left of a word boundary in the left context
						return sel.IsRange || GetInsertionIndex(leftHvos, sel) != 0 || !IsWordBoundary(first);
					}

				case PhMetathesisRule.kidxRightEnv:
					int[] rightHvos = Rule.StrucDescOS.HvoArray;
					IPhSimpleContext last = null;
					if (Rule.StrucDescOS.Count > 0)
						last = Rule.StrucDescOS[Rule.StrucDescOS.Count - 1];
					if (type == RuleInsertType.WORD_BOUNDARY)
					{
						// only display the word boundary option if we are at the end of the right context and
						// there is no word boundary already inserted
						if (sel.IsRange)
						{
							int[] indices = GetIndicesToRemove(rightHvos, sel);
							return indices[indices.Length - 1] == rightHvos.Length - 1;
						}
						else
						{
							return GetInsertionIndex(rightHvos, sel) == rightHvos.Length && !IsWordBoundary(last);
						}
					}
					else
					{
						// we cannot insert anything to the right of a word boundary in the right context
						return sel.IsRange || GetInsertionIndex(rightHvos, sel) != rightHvos.Length || !IsWordBoundary(last);
					}
			}

			return false;
		}
Ejemplo n.º 9
0
			public InsertOption(RuleInsertType type, DisplayOption shouldDisplay, DisplayIndices displayIndices)
			{
				this.type = type;
				this.shouldDisplay = shouldDisplay;
				this.displayIndices = displayIndices;
			}
Ejemplo n.º 10
0
		public RuleInsertEventArgs(RuleInsertType type, int data)
		{
			m_type = type;
			m_data = data;
		}
Ejemplo n.º 11
0
		bool DisplayColumnOption(RuleInsertType type)
		{
			SelectionHelper sel = SelectionHelper.Create(m_view);
			if (sel.IsRange)
				return false;

			int cellId = GetCell(sel);
			if (cellId == -1 || cellId == -2)
				return false;
			switch (cellId)
			{
				case AffixRuleFormulaVc.ktagLeftEmpty:
				case AffixRuleFormulaVc.ktagRightEmpty:
				case (int)MoAffixProcess.MoAffixProcessTags.kflidOutput:
					return false;

				default:
					return GetColumnInsertIndex(sel) != -1;
			}
		}
Ejemplo n.º 12
0
        bool DisplayOption(RuleInsertType type)
        {
            SelectionHelper sel    = SelectionHelper.Create(m_view);
            int             cellId = GetCell(sel);

            if (cellId < 0)
            {
                return(false);
            }

            switch (cellId)
            {
            case (int)PhSegRuleRHS.PhSegRuleRHSTags.kflidLeftContext:
                if (RHS.LeftContextOAHvo == 0)
                {
                    return(true);
                }

                int[]          leftHvos = null;
                IPhPhonContext first    = null;
                if (RHS.LeftContextOA.ClassID != PhSequenceContext.kclsidPhSequenceContext)
                {
                    leftHvos = new int[] { RHS.LeftContextOAHvo };
                    first    = RHS.LeftContextOA;
                }
                else
                {
                    IPhSequenceContext seqCtxt = RHS.LeftContextOA as IPhSequenceContext;
                    if (seqCtxt.MembersRS.Count > 0)
                    {
                        first = seqCtxt.MembersRS[0];
                    }
                    leftHvos = seqCtxt.MembersRS.HvoArray;
                }

                if (type == RuleInsertType.WORD_BOUNDARY)
                {
                    // only display the word boundary option if we are at the beginning of the left context and
                    // there is no word boundary already inserted
                    if (sel.IsRange)
                    {
                        return(GetIndicesToRemove(leftHvos, sel)[0] == 0);
                    }
                    else
                    {
                        return(GetInsertionIndex(leftHvos, sel) == 0 && !IsWordBoundary(first));
                    }
                }
                else
                {
                    // we cannot insert anything to the left of a word boundary in the left context
                    return(sel.IsRange || GetInsertionIndex(leftHvos, sel) != 0 || !IsWordBoundary(first));
                }

            case (int)PhSegRuleRHS.PhSegRuleRHSTags.kflidRightContext:
                if (RHS.RightContextOAHvo == 0 || sel.IsRange)
                {
                    return(true);
                }

                int[]          rightHvos = null;
                IPhPhonContext last      = null;
                if (RHS.RightContextOA.ClassID != PhSequenceContext.kclsidPhSequenceContext)
                {
                    rightHvos = new int[] { RHS.RightContextOAHvo };
                    last      = RHS.RightContextOA;
                }
                else
                {
                    IPhSequenceContext seqCtxt = RHS.RightContextOA as IPhSequenceContext;
                    if (seqCtxt.MembersRS.Count > 0)
                    {
                        last = seqCtxt.MembersRS[seqCtxt.MembersRS.Count - 1];
                    }
                    rightHvos = seqCtxt.MembersRS.HvoArray;
                }

                if (type == RuleInsertType.WORD_BOUNDARY)
                {
                    // only display the word boundary option if we are at the end of the right context and
                    // there is no word boundary already inserted
                    if (sel.IsRange)
                    {
                        int[] indices = GetIndicesToRemove(rightHvos, sel);
                        return(indices[indices.Length - 1] == rightHvos.Length - 1);
                    }
                    else
                    {
                        return(GetInsertionIndex(rightHvos, sel) == rightHvos.Length && !IsWordBoundary(last));
                    }
                }
                else
                {
                    // we cannot insert anything to the right of a word boundary in the right context
                    return(sel.IsRange || GetInsertionIndex(rightHvos, sel) != rightHvos.Length || !IsWordBoundary(last));
                }

            default:
                return(type != RuleInsertType.WORD_BOUNDARY);
            }
        }
Ejemplo n.º 13
0
 public RuleInsertEventArgs(RuleInsertType type, int data)
 {
     m_type = type;
     m_data = data;
 }
Ejemplo n.º 14
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));
            }
        }
Ejemplo n.º 15
0
			public InsertOption(RuleInsertType type)
			{
				m_type = type;
			}
        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));
        }
Ejemplo n.º 17
0
		bool DisplayOption(RuleInsertType type)
		{
			SelectionHelper sel = SelectionHelper.Create(m_view);
			int cellId = GetCell(sel);
			if (cellId == -1 || cellId == -2)
				return false;

			switch (cellId)
			{
				case AffixRuleFormulaVc.ktagLeftEmpty:
				case AffixRuleFormulaVc.ktagRightEmpty:
					return type != RuleInsertType.INDEX;

				case (int)MoAffixProcess.MoAffixProcessTags.kflidOutput:
					return type == RuleInsertType.INDEX || type == RuleInsertType.PHONEME || type == RuleInsertType.MORPHEME_BOUNDARY;

				default:
					if (m_cache.GetClassOfObject(cellId) == PhVariable.kclsidPhVariable)
						return false;
					return type != RuleInsertType.INDEX;
			}
		}
Ejemplo n.º 18
0
		/// <summary>
		/// Adds an insertion option. A predicate can be provided to determine in what contexts
		/// this insertion option can be displayed.
		/// </summary>
		/// <param name="type">The type.</param>
		/// <param name="shouldDisplay">The should display predicate.</param>
		public void AddOption(RuleInsertType type, DisplayOption shouldDisplay)
		{
			CheckDisposed();

			m_options.Add(new InsertOption(type, shouldDisplay, null));
		}
Ejemplo n.º 19
0
		bool DisplayVariableOption(RuleInsertType type)
		{
			SelectionHelper sel = SelectionHelper.Create(m_view);
			int cellId = GetCell(sel);
			if (cellId == -1 || cellId == -2)
				return false;

			switch (cellId)
			{
				case AffixRuleFormulaVc.ktagLeftEmpty:
				case AffixRuleFormulaVc.ktagRightEmpty:
					return true;

				case (int)MoAffixProcess.MoAffixProcessTags.kflidOutput:
					return false;

				default:
					if (m_cache.GetClassOfObject(cellId) == PhSequenceContext.kclsidPhSequenceContext)
					{
						int size = m_cache.GetVectorSize(cellId, (int)PhSequenceContext.PhSequenceContextTags.kflidMembers);
						if (size == 0)
							return true;
					}
					return false;
			}
		}
 public InsertOption(RuleInsertType type, DisplayOption shouldDisplay, DisplayIndices displayIndices)
 {
     this.type           = type;
     this.shouldDisplay  = shouldDisplay;
     this.displayIndices = displayIndices;
 }
Ejemplo n.º 21
0
		bool DisplayOption(RuleInsertType type)
		{
			SelectionHelper sel = SelectionHelper.Create(m_view);
			int cellId = GetCell(sel);
			if (cellId < 0)
				return false;

			switch (cellId)
			{
				case (int)PhSegRuleRHS.PhSegRuleRHSTags.kflidLeftContext:
					if (RHS.LeftContextOAHvo == 0)
						return true;

					int[] leftHvos = null;
					IPhPhonContext first = null;
					if (RHS.LeftContextOA.ClassID != PhSequenceContext.kclsidPhSequenceContext)
					{
						leftHvos = new int[] { RHS.LeftContextOAHvo };
						first = RHS.LeftContextOA;
					}
					else
					{
						IPhSequenceContext seqCtxt = RHS.LeftContextOA as IPhSequenceContext;
						if (seqCtxt.MembersRS.Count > 0)
							first = seqCtxt.MembersRS[0];
						leftHvos = seqCtxt.MembersRS.HvoArray;
					}

					if (type == RuleInsertType.WORD_BOUNDARY)
					{
						// only display the word boundary option if we are at the beginning of the left context and
						// there is no word boundary already inserted
						if (sel.IsRange)
							return GetIndicesToRemove(leftHvos, sel)[0] == 0;
						else
							return GetInsertionIndex(leftHvos, sel) == 0 && !IsWordBoundary(first);
					}
					else
					{
						// we cannot insert anything to the left of a word boundary in the left context
						return sel.IsRange || GetInsertionIndex(leftHvos, sel) != 0 || !IsWordBoundary(first);
					}

				case (int)PhSegRuleRHS.PhSegRuleRHSTags.kflidRightContext:
					if (RHS.RightContextOAHvo == 0 || sel.IsRange)
						return true;

					int[] rightHvos = null;
					IPhPhonContext last = null;
					if (RHS.RightContextOA.ClassID != PhSequenceContext.kclsidPhSequenceContext)
					{
						rightHvos = new int[] { RHS.RightContextOAHvo };
						last = RHS.RightContextOA;
					}
					else
					{
						IPhSequenceContext seqCtxt = RHS.RightContextOA as IPhSequenceContext;
						if (seqCtxt.MembersRS.Count > 0)
							last = seqCtxt.MembersRS[seqCtxt.MembersRS.Count - 1];
						rightHvos = seqCtxt.MembersRS.HvoArray;
					}

					if (type == RuleInsertType.WORD_BOUNDARY)
					{
						// only display the word boundary option if we are at the end of the right context and
						// there is no word boundary already inserted
						if (sel.IsRange)
						{
							int[] indices = GetIndicesToRemove(rightHvos, sel);
							return indices[indices.Length - 1] == rightHvos.Length - 1;
						}
						else
						{
							return GetInsertionIndex(rightHvos, sel) == rightHvos.Length && !IsWordBoundary(last);
						}
					}
					else
					{
						// we cannot insert anything to the right of a word boundary in the right context
						return sel.IsRange || GetInsertionIndex(rightHvos, sel) != rightHvos.Length || !IsWordBoundary(last);
					}

				default:
					return type != RuleInsertType.WORD_BOUNDARY;
			}
		}