示例#1
0
        /// ------------------------------------------------------------------------------------
        internal static PaComplexFormInfo Create(ILexEntryRef lxEntryRef)
        {
            if (lxEntryRef.RefType != LexEntryRefTags.krtComplexForm)
            {
                return(null);
            }

            var pcfi = new PaComplexFormInfo();

            pcfi.xComplexFormComment = PaMultiString.Create(lxEntryRef.Summary, lxEntryRef.Cache.ServiceLocator);
            pcfi.xComplexFormType    = lxEntryRef.ComplexEntryTypesRS.Select(x => PaCmPossibility.Create(x)).ToList();

            foreach (var component in lxEntryRef.ComponentLexemesRS)
            {
                if (component is ILexEntry)
                {
                    pcfi.xComponents.Add(((ILexEntry)component).HeadWord.Text);
                }
                else if (component is ILexSense)
                {
                    var lxSense = (ILexSense)component;
                    var text    = lxSense.Entry.HeadWord.Text;
                    if (lxSense.Entry.SensesOS.Count > 1)
                    {
                        text += string.Format(" {0}", lxSense.IndexInOwner + 1);
                    }

                    pcfi.xComponents.Add(text);
                }
            }

            return(pcfi);
        }
示例#2
0
        protected override void m_btnInsert_Click(object sender, EventArgs e)
        {
            if (!m_fBackRefToVariant)
            {
                base.m_btnInsert_Click(sender, e);
            }

            // the user wants to try to create a variant with a lexeme form
            // built from the current state of our Find text box and WritingSystem combo.
            ITsString tssNewVariantLexemeForm = CreateVariantTss();

            if (tssNewVariantLexemeForm == null)
            {
                return;
            }

            // we need to create the new LexEntryRef and its variant from the starting entry.
            UndoableUnitOfWorkHelper.Do(LexTextControls.ksUndoCreateVarEntry, LexTextControls.ksRedoCreateVarEntry, m_startingEntry, () =>
            {
                m_variantEntryRefResult = m_startingEntry.CreateVariantEntryAndBackRef(null, tssNewVariantLexemeForm);
            });
            m_fNewlyCreatedVariantEntryRef = true;
            m_selObject     = m_variantEntryRefResult.Owner as ILexEntry;
            m_fNewlyCreated = true;
            DialogResult    = DialogResult.OK;
            Close();
        }
示例#3
0
        /// <summary>
        /// update the OK button and selected entry type according to whether or not SelectedID
        /// is already linked.
        /// </summary>
        protected override void HandleMatchingSelectionChanged()
        {
            base.HandleMatchingSelectionChanged();
            // by default, btnOK should be set to "Add Variant"
            m_btnOK.Text = LexTextControls.ksAddVariant;
            if (SelectedObject != null)
            {
                // detect whether SelectedID already matches an existing EntryRef relationship.
                // If so, we want to "Use" it rather than say "Add" when clicking OK.

                ILexEntry variant;
                IVariantComponentLexeme componentLexeme;
                ILexEntryType           selectedEntryType;
                GetVariantAndComponentAndSelectedEntryType(out variant, out componentLexeme, out selectedEntryType);
                ILexEntryRef matchingEntryRef = FindMatchingEntryRef(variant, componentLexeme, selectedEntryType);
                if (matchingEntryRef != null)
                {
                    // Indicate to the user that the SelectedID matches an existing EntryRef relationship.
                    m_btnOK.Text = m_fBackRefToVariant ? LexTextControls.ks_OK : LexTextControls.ksUseEntry;
                    // if the VariantTypes combo is visible, select the last appended type of the matching relationship.
                    if (tcVariantTypes.Visible && matchingEntryRef.VariantEntryTypesRS.Count > 0)
                    {
                        int hvoLastAppendedType = matchingEntryRef.VariantEntryTypesRS[matchingEntryRef.VariantEntryTypesRS.Count - 1].Hvo;
                        LoadVariantTypesAndSelectTarget(hvoLastAppendedType);
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// The user selected an item; now we actually need a LexEntryRef.
        /// </summary>
        /// <param name="hvoNew"></param>
        private void AddItem(ICmObject newObj)
        {
            CheckDisposed();

            bool   fForVariant = XmlUtils.GetOptionalBooleanAttributeValue(m_configurationNode, "forVariant", false);
            string sUndo, sRedo;

            if (fForVariant)
            {
                sUndo = LexEdStrings.ksUndoVariantOf;
                sRedo = LexEdStrings.ksRedoVariantOf;
            }
            else
            {
                sUndo = LexEdStrings.ksUndoAddComponent;
                sRedo = LexEdStrings.ksRedoAddComponent;
            }
            try
            {
                UndoableUnitOfWorkHelper.Do(sUndo, sRedo, m_obj,
                                            () =>
                {
                    ILexEntry ent = m_obj as ILexEntry;

                    // Adapted from part of DtMenuHandler.AddNewLexEntryRef.
                    ILexEntryRef ler = ent.Services.GetInstance <ILexEntryRefFactory>().Create();
                    ent.EntryRefsOS.Add(ler);
                    if (fForVariant)
                    {
                        // The slice this is part of should only be displayed for lex entries with no VariantEntryRefs.
                        Debug.Assert(ent.VariantEntryRefs.Count() == 0);
                        ler.VariantEntryTypesRS.Add(ent.Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS[0] as ILexEntryType);
                        ler.RefType        = LexEntryRefTags.krtVariant;
                        ler.HideMinorEntry = 0;
                    }
                    else
                    {
                        // The slice this is part of should only be displayed for lex entries with no ComplexEntryRefs.
                        Debug.Assert(ent.ComplexFormEntryRefs.Count() == 0);
                        //ler.ComplexEntryTypesRS.Append(ent.Cache.LangProject.LexDbOA.ComplexEntryTypesOA.PossibilitiesOS[0].Hvo);
                        ler.RefType        = LexEntryRefTags.krtComplexForm;
                        ler.HideMinorEntry = 0;                         // LT-10928
                        // Logic similar to this is in EntrySequenceReferenceLauncher.AddNewObjectsToProperty()
                        // (when LER already exists so slice is not ghost)
                        ler.PrimaryLexemesRS.Add(newObj);
                        // Since it's a new LER, we can't know it to be a derivative, so by default it is visible.
                        // but do NOT do that here, it's now built into the process of adding it to PrimaryLexemes,
                        // and we don't want to do it twice.
                        // ler.ShowComplexFormsInRS.Add(newObj);
                        ent.ChangeRootToStem();
                    }
                    // Must do this AFTER setting the RefType (so dependent virtual properties can be updated properly)
                    ler.ComponentLexemesRS.Add(newObj);
                });
            }
            catch (ArgumentException)
            {
                MessageBoxes.ReportLexEntryCircularReference((ILexEntry)m_obj, newObj, true);
            }
        }
示例#5
0
		/// ------------------------------------------------------------------------------------
		internal static PaComplexFormInfo Create(ILexEntryRef lxEntryRef)
		{
			if (lxEntryRef.RefType != LexEntryRefTags.krtComplexForm)
				return null;

			var pcfi = new PaComplexFormInfo();
			pcfi.xComplexFormComment = PaMultiString.Create(lxEntryRef.Summary, lxEntryRef.Cache.ServiceLocator);
			pcfi.xComplexFormType = lxEntryRef.ComplexEntryTypesRS.Select(x => PaCmPossibility.Create(x)).ToList();

			foreach (var component in lxEntryRef.ComponentLexemesRS)
			{
				if (component is ILexEntry)
					pcfi.xComponents.Add(((ILexEntry)component).HeadWord.Text);
				else if (component is ILexSense)
				{
					var lxSense = (ILexSense)component;
					var text = lxSense.Entry.HeadWord.Text;
					if (lxSense.Entry.SensesOS.Count > 1)
						text += string.Format(" {0}", lxSense.IndexInOwner + 1);

					pcfi.xComponents.Add(text);
				}
			}

			return pcfi;
		}
示例#6
0
        public override void AddItem(ICmObject obj)
        {
            CheckDisposed();

            var          lexemes = new HashSet <ICmObject>();
            ILexEntryRef ler     = m_obj as ILexEntryRef;

            if (m_flid == LexEntryRefTags.kflidComponentLexemes)
            {
                lexemes.UnionWith(ler.ComponentLexemesRS);
            }
            else if (m_flid == LexEntryRefTags.kflidPrimaryLexemes)
            {
                lexemes.UnionWith(ler.PrimaryLexemesRS);
            }
            // don't add a duplicate items.
            if (!lexemes.Contains(obj))
            {
                lexemes.Add(obj);
                try
                {
                    SetItems(lexemes);
                }
                catch (ArgumentException)
                {
                    MessageBoxes.ReportLexEntryCircularReference(m_obj.Owner, obj, true);
                }
            }
        }
        /// <summary>
        /// If a reference is removed from the ComponentLexeme list, it must also be removed
        /// from the PrimaryLexeme list (if it exists there as well).
        /// </summary>
        /// <param name="hvo"></param>
        /// <param name="tag"></param>
        /// <param name="ivMin"></param>
        /// <param name="cvIns"></param>
        /// <param name="cvDel"></param>
        public void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel)
        {
            if (hvo != m_obj.Hvo ||
                m_obj.ClassID != LexEntryRef.kclsidLexEntryRef ||
                tag != (int)LexEntryRef.LexEntryRefTags.kflidComponentLexemes)
            {
                return;
            }
            ILexEntryRef ler = m_obj as ILexEntryRef;
            FdoReferenceSequence <ICmObject> rgobjComponent = ler.ComponentLexemesRS;

            if (cvDel > cvIns)
            {
                int[] rghvoPrimary = ler.PrimaryLexemesRS.HvoArray;
                for (int i = 0; i < rghvoPrimary.Length; ++i)
                {
                    if (!rgobjComponent.Contains(rghvoPrimary[i]))
                    {
                        ler.PrimaryLexemesRS.Remove(rghvoPrimary[i]);
                    }
                }
            }
            else if (cvIns > cvDel && ler.ComponentLexemesRS.Count == 1 && ler.PrimaryLexemesRS.Count == 0)
            {
                ler.PrimaryLexemesRS.Append(ler.ComponentLexemesRS[0]);
            }
        }
示例#8
0
        /// ------------------------------------------------------------------------------------
        internal PaVariant(ILexEntryRef lxEntryRef)
        {
            var lx = lxEntryRef.OwnerOfClass <ILexEntry>();

            xVariantForm = PaMultiString.Create(lx.LexemeFormOA.Form, lxEntryRef.Cache.ServiceLocator);
            xVariantInfo = new PaVariantOfInfo(lxEntryRef);
        }
 public AddComponentChooserCommand(FdoCache cache, bool fCloseBeforeExecuting,
                                   string sLabel, XCore.Mediator mediator, ICmObject obj,
                                   Form form)
     : base(cache, fCloseBeforeExecuting, sLabel, mediator)
 {
     m_ler  = obj as ILexEntryRef;
     m_form = form;
 }
示例#10
0
 public AddPrimaryLexemeChooserCommand(FdoCache cache, bool fCloseBeforeExecuting,
                                       string sLabel, XCore.Mediator mediator, ICmObject lexEntryRef, /* Why ICmObject? */
                                       Form parentWindow)
     : base(cache, fCloseBeforeExecuting, sLabel, mediator)
 {
     m_lexEntryRef  = lexEntryRef as ILexEntryRef;
     m_parentWindow = parentWindow;
 }
示例#11
0
 public AddPrimaryLexemeChooserCommand(LcmCache cache, bool fCloseBeforeExecuting,
                                       string sLabel, Mediator mediator, PropertyTable propertyTable, ICmObject lexEntryRef, /* Why ICmObject? */
                                       Form parentWindow)
     : base(cache, fCloseBeforeExecuting, sLabel, mediator, propertyTable)
 {
     m_lexEntryRef  = lexEntryRef as ILexEntryRef;
     m_parentWindow = parentWindow;
 }
        private ILexEntryRef MakeComplexFormLexEntryRef(ILexEntry ownerEntry)
        {
            ILexEntryRef result = null;

            result = Cache.ServiceLocator.GetInstance <ILexEntryRefFactory>().Create();
            ownerEntry.EntryRefsOS.Add(result);
            result.RefType = LexEntryRefTags.krtComplexForm;
            return(result);
        }
示例#13
0
        private ILexEntryRef MakeLexEntryRef(ILexEntry ownerEntry, int refType)
        {
            ILexEntryRef result = null;

            result = Cache.ServiceLocator.GetInstance <ILexEntryRefFactory>().Create();
            ownerEntry.EntryRefsOS.Add(result);
            result.RefType = refType;
            return(result);
        }
示例#14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="variantRef"></param>
        /// <returns></returns>
        public static ILexSense GetMainOrFirstSenseOfVariant(ILexEntryRef variantRef)
        {
            var mainEntryOrSense = variantRef.ComponentLexemesRS[0] as IVariantComponentLexeme;
            // find first gloss
            ILexEntry mainEntry;
            ILexSense mainOrFirstSense;

            GetMainEntryAndSenseStack(mainEntryOrSense, out mainEntry, out mainOrFirstSense);
            return(mainOrFirstSense);
        }
示例#15
0
 private bool IsPublishableReference(ILexEntryRef entryRef)
 {
     // A reference is not publishable if its owner is excluded
     if (m_excludedItems.Contains(entryRef.Owner.Hvo))
     {
         return(false);
     }
     // A reference is also not publishable if all of its PrimarySensesOrEntries are excluded
     return(entryRef.PrimarySensesOrEntries.Any(senseOrEntry => !m_excludedItems.Contains(senseOrEntry.Item.Hvo)));
 }
示例#16
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (SelectedObject == null)
            {
                return;                 // odd. nothing more to do.
            }
            ILexEntry variant;
            IVariantComponentLexeme componentLexeme;
            ILexEntryType           selectedEntryType;

            GetVariantAndComponentAndSelectedEntryType(out variant, out componentLexeme, out selectedEntryType);

            ILexEntryRef matchingEntryRef = FindMatchingEntryRef(variant, componentLexeme, selectedEntryType);

            try
            {
                UndoableUnitOfWorkHelper.Do(LexTextControls.ksUndoAddVariant, LexTextControls.ksRedoAddVariant,
                                            m_cache.ServiceLocator.GetInstance <IActionHandler>(), () =>
                {
                    if (matchingEntryRef != null)
                    {
                        // we found a matching ComponentLexeme. See if we can find the selected type.
                        // if the selected type does not yet exist, add it.
                        if (selectedEntryType != null &&
                            !matchingEntryRef.VariantEntryTypesRS.Contains(selectedEntryType))
                        {
                            matchingEntryRef.VariantEntryTypesRS.Add(selectedEntryType);
                        }

                        m_variantEntryRefResult        = matchingEntryRef;
                        m_fNewlyCreatedVariantEntryRef = false;
                    }
                    else
                    {
                        // otherwise we need to create a new LexEntryRef.
                        m_fNewlyCreatedVariantEntryRef = true;
                        if (variant != null)
                        {
                            m_variantEntryRefResult = variant.MakeVariantOf(componentLexeme, selectedEntryType);
                        }
                        else
                        {
                            m_variantEntryRefResult = componentLexeme.CreateVariantEntryAndBackRef(selectedEntryType,
                                                                                                   m_tssVariantLexemeForm);
                        }
                    }
                });
            }
            catch (ArgumentException)
            {
                MessageBoxes.ReportLexEntryCircularReference(componentLexeme, variant, false);
            }
        }
        public static void WriteMsaElement(this XmlWriter writer, FdoCache cache, string formID, string msaID, string type, string wordType)
        {
            // Irregulary inflected forms can have a combination MSA hvo: the LexEntry hvo, a period, and an index to the LexEntryRef
            Tuple <int, int> msaTuple = ProcessMsaHvo(msaID);
            ICmObject        obj      = cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(msaTuple.Item1);

            switch (obj.GetType().Name)
            {
            default:
                throw new ApplicationException(String.Format("Invalid MSA type: {0}.", obj.GetType().Name));

            case "MoStemMsa":
                WriteStemMsaXmlElement(writer, (IMoStemMsa)obj, Enumerable.Empty <ILexEntryRef>());
                break;

            case "MoInflAffMsa":
                WriteInflectionClasses(writer, cache, int.Parse(formID, CultureInfo.InvariantCulture));
                WriteInflMsaXmlElement(writer, (IMoInflAffMsa)obj, type);
                break;

            case "MoDerivAffMsa":
                WriteDerivMsaXmlElement(writer, (IMoDerivAffMsa)obj);
                break;

            case "MoUnclassifiedAffixMsa":
                WriteUnclassifedMsaXmlElement(writer, (IMoUnclassifiedAffixMsa)obj);
                break;

            case "LexEntry":
                // is an irregularly inflected form
                // get the MoStemMsa of its variant
                var entry = (ILexEntry)obj;
                if (entry.EntryRefsOS.Count > 0)
                {
                    ILexEntryRef lexEntryRef = entry.EntryRefsOS[msaTuple.Item2];
                    ILexSense    sense       = MorphServices.GetMainOrFirstSenseOfVariant(lexEntryRef);
                    WriteStemMsaXmlElement(writer, (IMoStemMsa)sense.MorphoSyntaxAnalysisRA, entry.VariantEntryRefs);
                }
                break;

            case "LexEntryInflType":
                // This is one of the null allomorphs we create when building the
                // input for the parser in order to still get the Word Grammar to have something in any
                // required slots in affix templates.
                WriteInflMsaForLexEntryInflType(writer, wordType, (ILexEntryInflType)obj);
                break;
            }
        }
        /// <summary>
        /// Remove the given entry (or any sense owned by that entry) from the given LexEntryRef.  If the LexEntryRef no
        /// longer points to anything, remove it from its owner.
        /// </summary>
        private static void RemoveEntryFromLexEntryRef(ILexEntryRef ler, ILexEntry entry, StringBuilder bldrLog)
        {
            // Remove from the Components list as well as the PrimaryLexemes list
            RemoveEntryFromList(ler.PrimaryLexemesRS, entry);
            RemoveEntryFromList(ler.ComponentLexemesRS, entry);
            ILexEntry owner = ler.OwningEntry;

            bldrLog.AppendFormat(Strings.ksRemovingCircularComponentLexeme, entry.HeadWord.Text, owner.HeadWord.Text);
            // If the Components list is now empty, delete the LexEntryRef
            if (ler.ComponentLexemesRS.Count == 0)
            {
                owner.EntryRefsOS.Remove(ler);
                bldrLog.AppendLine();
                bldrLog.AppendFormat(Strings.ksAlsoEmptyComplexFormInfo, owner.HeadWord.Text);
            }
        }
示例#19
0
        private ILexEntryRef FindMatchingEntryRef(ILexEntry variant, IVariantComponentLexeme componentLexeme, ILexEntryType selectedEntryType)
        {
            ILexEntryRef matchingEntryRef = null;

            if (variant != null)
            {
                // see if the starting entry has the SelectedID already as a ComponentLexeme
                matchingEntryRef = (variant as LexEntry).FindMatchingVariantEntryRef(componentLexeme,
                                                                                     selectedEntryType);
            }
            else
            {
                // determine whether the selected entry or sense is already
                // linked to an existing variant with the given lexeme form.
                matchingEntryRef = LexEntry.FindMatchingVariantEntryBackRef(componentLexeme,
                                                                            selectedEntryType, m_tssVariantLexemeForm);
            }
            return(matchingEntryRef);
        }
示例#20
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (SelectedID == 0)
            {
                return;                 // odd. nothing more to do.
            }
            ILexEntry variant;
            IVariantComponentLexeme componentLexeme;
            ILexEntryType           selectedEntryType;

            GetVariantAndComponentAndSelectedEntryType(out variant, out componentLexeme, out selectedEntryType);

            ILexEntryRef matchingEntryRef = FindMatchingEntryRef(variant, componentLexeme, selectedEntryType);

            if (matchingEntryRef != null)
            {
                // we found a matching ComponentLexeme. See if we can find the selected type.
                // if the selected type does not yet exist, add it.
                if (selectedEntryType != null &&
                    !matchingEntryRef.VariantEntryTypesRS.Contains(selectedEntryType))
                {
                    matchingEntryRef.VariantEntryTypesRS.Append(selectedEntryType);
                }

                m_variantEntryRefResult        = matchingEntryRef;
                m_fNewlyCreatedVariantEntryRef = false;
                return;
            }

            // otherwise we need to create a new LexEntryRef.
            m_fNewlyCreatedVariantEntryRef = true;
            if (variant != null)
            {
                m_variantEntryRefResult = variant.MakeVariantOf(componentLexeme, selectedEntryType);
            }
            else
            {
                m_variantEntryRefResult = componentLexeme.CreateVariantEntryAndBackRef(selectedEntryType,
                                                                                       m_tssVariantLexemeForm);
            }
        }
        public override void AddItem(int hvoNew)
        {
            CheckDisposed();

            List <int>   lexemes = new List <int>();
            ILexEntryRef ler     = m_obj as ILexEntryRef;

            if (m_flid == (int)LexEntryRef.LexEntryRefTags.kflidComponentLexemes)
            {
                lexemes.AddRange(ler.ComponentLexemesRS.HvoArray);
            }
            else if (m_flid == (int)LexEntryRef.LexEntryRefTags.kflidPrimaryLexemes)
            {
                lexemes.AddRange(ler.PrimaryLexemesRS.HvoArray);
            }
            // don't add a duplicate items.
            if (!lexemes.Contains(hvoNew))
            {
                lexemes.Add(hvoNew);
                SetItems(lexemes);
            }
        }
 /// <summary>
 /// Check whether this LexEntryRef has a circular reference in its PrimaryLexemesRS collection.
 /// The m_refsProcessed class variable is set as a side-effect of this method, and used by later
 /// processing if the method returns true.  (Using a class variable saves the noise of allocated
 /// a new list thousands of times.)  The m_entriesEncountered class variable is also set as a
 /// side-effect, but is used only by this recursive method to detect a circular reference.
 /// </summary>
 private static bool CheckForCircularRef(ILexEntryRef ler)
 {
     m_entriesEncountered.Add(ler.OwningEntry.Guid);
     m_refsProcessed.Add(ler);
     foreach (var item in ler.PrimaryLexemesRS)
     {
         var entry = item as ILexEntry ?? ((ILexSense)item).Entry;
         if (m_entriesEncountered.Contains(entry.Guid))
         {
             return(true);
         }
         foreach (var leref in entry.ComplexFormEntryRefs)
         {
             if (CheckForCircularRef(leref))
             {
                 return(true);
             }
         }
     }
     m_refsProcessed.RemoveAt(m_refsProcessed.Count - 1);
     m_entriesEncountered.Remove(ler.OwningEntry.Guid);
     return(false);
 }
示例#23
0
        protected override void btnInsert_Click(object sender, EventArgs e)
        {
            if (!m_fBackRefToVariant)
            {
                base.btnInsert_Click(sender, e);
            }

            // the user wants to try to create a variant with a lexeme form
            // built from the current state of our Find text box and WritingSystem combo.
            ITsString tssNewVariantLexemeForm = CreateVariantTss();

            if (tssNewVariantLexemeForm == null)
            {
                return;
            }

            // we need to create the new LexEntryRef and its variant from the starting entry.
            m_variantEntryRefResult        = m_startingEntry.CreateVariantEntryAndBackRef(null, tssNewVariantLexemeForm);
            m_fNewlyCreatedVariantEntryRef = true;
            m_selEntryID    = m_variantEntryRefResult.OwnerHVO;
            m_fNewlyCreated = true;
            DialogResult    = DialogResult.OK;
            Close();
        }
			/// <summary>
			///
			/// </summary>
			/// <param name="mf"></param>
			/// <param name="le">the entry used in the morph bundle (for sense info). typically
			/// this is an owner of hvoMorph, but if not, it most likely has hvoMorph linked as its variant.</param>
			private void BuildMorphItemsFromEntry(IMoForm mf, ILexEntry le, ILexEntryRef ler)
			{
				int hvoLexEntry = 0;
				if (le != null)
					hvoLexEntry = le.Hvo;
				ITsString tssName = null;
				if (le != null)
				{
					tssName = LexEntryVc.GetLexEntryTss(m_caches.MainCache, le.Hvo, m_wsVern, ler);
				}
				else
				{
					// looks like we're not in a good state, so just use the form for the name.
					int wsActual;
					tssName = mf.Form.GetAlternativeOrBestTss(m_wsVern, out wsActual);
				}
				var wsAnalysis = m_caches.MainCache.ServiceLocator.WritingSystemManager.Get(m_caches.MainCache.DefaultAnalWs);

				// Populate morphItems with Sense/Msa level specifics
				if (le != null)
				{
					foreach (ILexSense sense in le.AllSenses)
					{
						var tssSense = sense.Gloss.get_String(wsAnalysis.Handle);
						if (ler != null)
						{
							MorphItem mi;
							var lexEntryInflTypes =
									ler.VariantEntryTypesRS.Where(let => let is ILexEntryInflType).Select(let => let as ILexEntryInflType);
							if (lexEntryInflTypes.Count() > 0)
							{
								foreach (var inflType in lexEntryInflTypes)
								{
									var glossAccessor = (tssSense.Length == 0 ? (IMultiStringAccessor) sense.Definition : sense.Gloss);
									tssSense = MorphServices.MakeGlossOptionWithInflVariantTypes(inflType, glossAccessor, wsAnalysis);
									mi = GetMorphItem(mf, tssName, sense, tssSense, ler, hvoLexEntry, inflType);
									m_morphItems.Add(mi);
								}
							}
							else
							{
								AddMorphItemToList(mf, ler, tssSense, sense, wsAnalysis, tssName, hvoLexEntry);
							}
						}
						else
						{
							AddMorphItemToList(mf, null, tssSense, sense, wsAnalysis, tssName, hvoLexEntry);
						}
					}
				}
				// Make a LexEntry level item
				m_morphItems.Add(new MorphItem(mf.Hvo, ler != null ? hvoLexEntry : 0, tssName));
			}
			private static ILexEntry GetMainEntryOfVariant(ILexEntryRef ler)
			{
				IVariantComponentLexeme component = ler.ComponentLexemesRS[0] as IVariantComponentLexeme;
				ILexEntry mainEntryOfVariant = null;
				if (component.ClassID == LexEntryTags.kClassId)
					mainEntryOfVariant = component as ILexEntry;
				else if (component.ClassID == LexSenseTags.kClassId)
					mainEntryOfVariant = (component as ILexSense).Entry;
				return mainEntryOfVariant;
			}
				/// <summary>
				///
				/// </summary>
				/// <param name="hvoMorph">IMoForm (e.g. wmb.MorphRA)</param>
				/// <param name="hvoMainEntryOfVariant">for variant specs, this is hvoMorph's Entry.VariantEntryRef.ComponentLexeme target, 0 otherwise</param>
				/// <param name="tssName"></param>
				/// <param name="hvoSense">ILexSense (e.g. wmb.SensaRA)</param>
				/// <param name="nameSense"></param>
				/// <param name="hvoMsa">IMoMorphSynAnalysis (e.g. wmb.MsaRA)</param>
				/// <param name="nameMsa"></param>
				public MorphItem(int hvoMorph, int hvoMainEntryOfVariant, ITsString tssName, int hvoSense, string nameSense, int hvoMsa, string nameMsa)
				{
					m_hvoMorph = hvoMorph;
					m_hvoMainEntryOfVariant = hvoMainEntryOfVariant;
					m_name = tssName;
					m_hvoSense = hvoSense;
					m_nameSense = nameSense;
					m_hvoMsa = hvoMsa;
					m_nameMsa = nameMsa;
					m_inflType = null;
					m_entryRef = null;
				}
示例#27
0
		private void WriteLexEntryRef(TextWriter w, ILexEntryRef ler)
		{
			var typeString = "_component-lexeme";
			// special case to export the BaseForm complex form type as expected by WeSay.
			if (ler.ComplexEntryTypesRS.Count == 1 && ler.ComplexEntryTypesRS[0].Name.get_String(m_cache.WritingSystemFactory.GetWsFromStr("en")).Text == "BaseForm")
				typeString = "BaseForm";
			int order = 0;
			foreach (var obj in ler.ComponentLexemesRS)
			{
				w.WriteLine("<relation type=\"" + typeString + "\" ref=\"{0}\" order=\"{1}\">",
					MakeSafeAndNormalizedAttribute(GetProperty(obj, "LIFTid").ToString()), order);
				if (ler.PrimaryLexemesRS.Contains(obj))
					w.WriteLine("<trait name=\"is-primary\" value=\"true\"/>");
				WriteLexEntryRefBasics(w, ler);
				w.WriteLine("</relation>");
				++order;
			}
			if (ler.ComponentLexemesRS.Count == 0)
			{
				w.WriteLine("<relation type=\"_component-lexeme\" ref=\"\">");
				WriteLexEntryRefBasics(w, ler);
				w.WriteLine("</relation>");
			}
		}
示例#28
0
 /// ------------------------------------------------------------------------------------
 internal PaVariantOfInfo(ILexEntryRef lxEntryRef)
 {
     xVariantComment = PaMultiString.Create(lxEntryRef.Summary, lxEntryRef.Cache.ServiceLocator);
     xVariantType    = lxEntryRef.VariantEntryTypesRS.Select(x => PaCmPossibility.Create(x)).ToList();
 }
示例#29
0
		/// <summary>
		/// Determines whether the entry is in a variant relationship with the given sense (or its entry).
		/// </summary>
		/// <param name="senseTargetComponent">the sense of which we are possibly a variant. If we aren't a variant of the sense,
		/// we will try to see if we are a variant of its owner entry</param>
		/// <param name="matchinEntryRef">if we found a match, the first (and only) ComponentLexeme will have matching sense or its owner entry.</param>
		/// <returns></returns>
		public bool IsVariantOfSenseOrOwnerEntry(ILexSense senseTargetComponent, out ILexEntryRef matchinEntryRef)
		{
			matchinEntryRef = null;
			if (senseTargetComponent != null && senseTargetComponent.Hvo != 0 && senseTargetComponent.EntryID != this.Hvo)
			{
				// expect hvoLexEntry to be a variant of the sense or the sense's entry.
				matchinEntryRef = this.FindMatchingVariantEntryRef(senseTargetComponent, null);
				if (matchinEntryRef == null)
				{
					// must be in relationship with the sense's entry, rather than the sense.
					matchinEntryRef = this.FindMatchingVariantEntryRef(senseTargetComponent.Entry, null);
				}
			}
			return matchinEntryRef != null;
		}
示例#30
0
		private void JoinGlossAffixesOfInflVariantTypes(ILexEntryRef entryRef1, int wsPreferred, out ITsIncStrBldr sbPrepend1, out ITsIncStrBldr sbAppend1)
		{
			var glossWs1 = Cache.ServiceLocator.WritingSystemManager.Get(wsPreferred);
			MorphServices.JoinGlossAffixesOfInflVariantTypes(entryRef1.VariantEntryTypesRS, glossWs1,
															 out sbPrepend1, out sbAppend1);
		}
示例#31
0
        /// <summary>
        /// The user has attempted to delete something which the system does not inherently
        /// know how to delete.  If the problem is a "complex range", then try to delete one
        /// object from the vector displayed in the entry sequence.
        /// </summary>
        public override VwDelProbResponse OnProblemDeletion(IVwSelection sel, VwDelProbType dpt)
        {
            if (dpt == VwDelProbType.kdptComplexRange)
            {
                var       helper = SelectionHelper.GetSelectionInfo(sel, this);
                var       clev   = helper.NumberOfLevels;
                var       rginfo = helper.LevelInfo;
                var       info   = rginfo[clev - 1];
                ICmObject cmo;
                if (info.tag == m_rootFlid &&
                    m_cache.ServiceLocator.ObjectRepository.TryGetObject(info.hvo, out cmo))
                {
                    var sda = m_cache.DomainDataByFlid as ISilDataAccessManaged;
                    Debug.Assert(sda != null);
                    var rghvos = sda.VecProp(m_rootObj.Hvo, m_rootFlid);
                    var ihvo   = -1;
                    for (var i = 0; i < rghvos.Length; ++i)
                    {
                        if (rghvos[i] == cmo.Hvo)
                        {
                            ihvo = i;
                            break;
                        }
                    }
                    if (ihvo >= 0)
                    {
                        var startHeight = m_rootb.Height;
                        if (Cache.MetaDataCacheAccessor.get_IsVirtual(m_rootFlid))
                        {
                            var          obj = m_cache.ServiceLocator.GetObject(rghvos[ihvo]);
                            ILexEntryRef ler = null;
                            if (obj is ILexEntry)
                            {
                                var complex = (ILexEntry)obj;
                                // the selected object in the list is a complex entry which has this as one of
                                // its components.  We want to remove this from its components.
                                foreach (var item in complex.EntryRefsOS)
                                {
                                    switch (item.RefType)
                                    {
                                    case LexEntryRefTags.krtComplexForm:
                                    case LexEntryRefTags.krtVariant:
                                        ler = item;
                                        break;

                                    default:
                                        throw new Exception("Unexpected LexEntryRef type in EntrySequenceVectorReferenceView.OnProblemDeletion");
                                    }
                                }
                            }
                            else if (obj is ILexEntryRef)
                            {
                                ler = (ILexEntryRef)obj;
                            }
                            else
                            {
                                return(VwDelProbResponse.kdprAbort);                                // we don't know how to delete it.
                            }
                            var fieldName = m_cache.MetaDataCacheAccessor.GetFieldName(m_rootFlid);
                            if (fieldName == "Subentries")
                            {
                                ler.PrimaryLexemesRS.Remove(m_rootObj);
                            }
                            else if (fieldName == "VisibleComplexFormEntries" || fieldName == "VisibleComplexFormBackRefs")
                            {
                                ler.ShowComplexFormsInRS.Remove(m_rootObj);
                            }
                            else if (fieldName == "VariantFormEntries")
                            {
                                ler.ComponentLexemesRS.Remove(m_rootObj);
                            }
                        }
                        else
                        {
                            sda.Replace(m_rootObj.Hvo, m_rootFlid, ihvo, ihvo + 1, new int[0], 0);
                        }
                        if (m_rootb != null)
                        {
                            CheckViewSizeChanged(startHeight, m_rootb.Height);
                            // Redisplay (?) the vector property.
                            m_rootb.SetRootObject(m_rootObj.Hvo, m_VectorReferenceVc, kfragTargetVector,
                                                  m_rootb.Stylesheet);
                        }
                        return(VwDelProbResponse.kdprDone);
                    }
                }
            }
            return(base.OnProblemDeletion(sel, dpt));
        }
示例#32
0
        /// <summary>
        /// The user selected an item; now we actually need a LexEntryRef.
        /// </summary>
        /// <param name="hvoNew"></param>
        private void AddItem(ICmObject newObj)
        {
            CheckDisposed();

            bool   fForVariant = XmlUtils.GetOptionalBooleanAttributeValue(m_configurationNode, "forVariant", false);
            string sUndo, sRedo;

            if (fForVariant)
            {
                sUndo = LexEdStrings.ksUndoVariantOf;
                sRedo = LexEdStrings.ksRedoVariantOf;
            }
            else
            {
                sUndo = LexEdStrings.ksUndoAddComponent;
                sRedo = LexEdStrings.ksRedoAddComponent;
            }
            try
            {
                UndoableUnitOfWorkHelper.Do(sUndo, sRedo, m_obj,
                                            () =>
                {
                    ILexEntry ent = m_obj as ILexEntry;

                    // It IS a ghost slice after all; it shouldn't already have any of whatever we're about to add.
                    Debug.Assert(!(fForVariant ? ent.VariantEntryRefs.Any() : ent.ComplexFormEntryRefs.Any()));
                    if (fForVariant ? ent.VariantEntryRefs.Any() : ent.ComplexFormEntryRefs.Any())
                    {
                        return;
                    }

                    // Adapted from part of DtMenuHandler.AddNewLexEntryRef.
                    ILexEntryRef ler = ent.Services.GetInstance <ILexEntryRefFactory>().Create();
                    ent.EntryRefsOS.Add(ler);
                    if (fForVariant)
                    {
                        const string unspecVariantEntryTypeGuid = "3942addb-99fd-43e9-ab7d-99025ceb0d4e";
                        var type = ent.Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS
                                   .First(lrt => lrt.Guid.ToString() == unspecVariantEntryTypeGuid) as ILexEntryType;
                        ler.VariantEntryTypesRS.Add(type);
                        ler.RefType        = LexEntryRefTags.krtVariant;
                        ler.HideMinorEntry = 0;
                    }
                    else
                    {
                        ler.RefType = LexEntryRefTags.krtComplexForm;
                        const string unspecComplexFormEntryTypeGuid = "fec038ed-6a8c-4fa5-bc96-a4f515a98c50";
                        var type = ent.Cache.LangProject.LexDbOA.ComplexEntryTypesOA.PossibilitiesOS
                                   .First(lrt => lrt.Guid.ToString() == unspecComplexFormEntryTypeGuid) as ILexEntryType;
                        ler.ComplexEntryTypesRS.Add(type);
                        ler.HideMinorEntry = 0;                         // LT-10928
                        // Logic similar to this is in EntrySequenceReferenceLauncher.AddNewObjectsToProperty()
                        // (when LER already exists so slice is not ghost)
                        ler.PrimaryLexemesRS.Add(newObj);
                        // Since it's a new LER, we can't know it to be a derivative, so by default it is visible.
                        // but do NOT do that here, it's now built into the process of adding it to PrimaryLexemes,
                        // and we don't want to do it twice.
                        ent.ChangeRootToStem();
                    }
                    // Must do this AFTER setting the RefType (so dependent virtual properties can be updated properly)
                    ler.ComponentLexemesRS.Add(newObj);
                });
            }
            catch (ArgumentException)
            {
                MessageBoxes.ReportLexEntryCircularReference(m_obj, newObj, true);
            }
        }
示例#33
0
		/// <summary>
		/// Does this component show this complex form in the dictionary?
		/// The component can be a ILexEntry or a ILexSense.
		/// The reference to the complex form from the component is outted.
		/// </summary>
		/// <param name="component">A component of a complex form, not necessarily cplxForm.</param>
		/// <param name="cplxForm">The complex form in question.</param>
		/// <param name="cfRef">The complex form reference from the component.</param>
		/// <returns>true if cplxForm "contains" component (it has a reference to it).</returns>
		private bool ComponentShowsComplexForm(ICmObject component, ILexEntry cplxForm, out ILexEntryRef cfRef)
		{
			cfRef = (from item in cplxForm.EntryRefsOS where item.RefType == LexEntryRefTags.krtComplexForm select item).FirstOrDefault();
			Debug.Assert(cfRef != null,"A component of a complex form has no reference to its complex form");
			return cfRef.ShowComplexFormsInRS.Contains(component);
		}
示例#34
0
		private void WriteLexEntryRefBasics(TextWriter w, ILexEntryRef ler)
		{
			foreach (var type in ler.ComplexEntryTypesRS)
				WriteTrait(w, "complex-form-type", type.Name, m_wsBestAnalVern);
			foreach (var type in ler.VariantEntryTypesRS)
				WriteTrait(w, "variant-type", type.Name, m_wsBestAnalVern);
			if (ler.ComplexEntryTypesRS.Count == 0 && ler.VariantEntryTypesRS.Count == 0)
			{
				switch (ler.RefType)
				{
					case LexEntryRefTags.krtVariant:
						w.WriteLine("<trait name=\"variant-type\" value=\"\"/>");
						break;
					case LexEntryRefTags.krtComplexForm:
						w.WriteLine("<trait name=\"complex-form-type\" value=\"\"/>");
						break;
				}
			}
			if (ler.HideMinorEntry != 0)
				w.WriteLine("<trait name=\"hide-minor-entry\" value=\"{0}\"/>", ler.HideMinorEntry);
			WriteAllForms(w, "field", "type=\"summary\"", "form", ler.Summary);
		}
			private void AddMorphItemToList(IMoForm mf, ILexEntryRef ler, ITsString tssSense, ILexSense sense,
											IWritingSystem wsAnalysis, ITsString tssName, int hvoLexEntry)
			{
				MorphItem mi;
				if (tssSense.Length == 0)
				{
					// If it doesn't have a gloss (e.g., from Categorised Entry), use the definition.
					tssSense = sense.Definition.get_String(wsAnalysis.Handle);
				}
				mi = GetMorphItem(mf, tssName, sense, tssSense, ler, hvoLexEntry, null);
				m_morphItems.Add(mi);
			}
			private static MorphItem GetMorphItem(IMoForm mf, ITsString tssName, ILexSense sense, ITsString tssSense,
				ILexEntryRef ler, int hvoLexEntry, ILexEntryInflType inflType)
			{
				IMoMorphSynAnalysis msa = null;
				string msaText = null;
				if (sense != null)
				{
					msa = sense.MorphoSyntaxAnalysisRA;
					if (msa != null)
						msaText = msa.InterlinearName;
				}

				var options = new MorphItemOptions
				{
					HvoMoForm = HvoOrZero(mf),
					HvoEntry = ler != null ? hvoLexEntry : 0,
					TssName = tssName,
					HvoSense = HvoOrZero(sense),
					SenseName = tssSense != null ? tssSense.Text : null,
					HvoMsa = HvoOrZero(msa),
					MsaName = msaText,
					InflType = inflType,
					EntryRef = ler,
				};
				return new MorphItem(options);
			}
		private void btnOK_Click(object sender, EventArgs e)
		{
			if (SelectedObject == null)
				return; // odd. nothing more to do.

			ILexEntry variant;
			IVariantComponentLexeme componentLexeme;
			ILexEntryType selectedEntryType;
			GetVariantAndComponentAndSelectedEntryType(out variant, out componentLexeme, out selectedEntryType);

			ILexEntryRef matchingEntryRef = FindMatchingEntryRef(variant, componentLexeme, selectedEntryType);
			try
			{
				UndoableUnitOfWorkHelper.Do(LexTextControls.ksUndoAddVariant, LexTextControls.ksRedoAddVariant,
					m_cache.ServiceLocator.GetInstance<IActionHandler>(), () =>
				{
					if (matchingEntryRef != null)
					{
						// we found a matching ComponentLexeme. See if we can find the selected type.
						// if the selected type does not yet exist, add it.
						if (selectedEntryType != null &&
							!matchingEntryRef.VariantEntryTypesRS.Contains(selectedEntryType))
						{
							matchingEntryRef.VariantEntryTypesRS.Add(selectedEntryType);
						}

						m_variantEntryRefResult = matchingEntryRef;
						m_fNewlyCreatedVariantEntryRef = false;
					}
					else
					{
						// otherwise we need to create a new LexEntryRef.
						m_fNewlyCreatedVariantEntryRef = true;
						if (variant != null)
						{
							m_variantEntryRefResult = variant.MakeVariantOf(componentLexeme, selectedEntryType);
						}
						else
						{
							m_variantEntryRefResult = componentLexeme.CreateVariantEntryAndBackRef(selectedEntryType,
								m_tssVariantLexemeForm);
						}
					}
				});
			}
			catch (ArgumentException)
			{
				MessageBoxes.ReportLexEntryCircularReference((ILexEntry)componentLexeme, variant, false);
			}
		}
示例#38
0
        private static bool TryCreateParseMorph(FdoCache cache, XElement morphElem, out ParseMorph morph)
        {
            XElement formElement = morphElem.Element("MoForm");

            Debug.Assert(formElement != null);
            var formHvo = (string)formElement.Attribute("DbRef");

            XElement msiElement = morphElem.Element("MSI");

            Debug.Assert(msiElement != null);
            var msaHvo = (string)msiElement.Attribute("DbRef");

            // Normally, the hvo for MoForm is a MoForm and the hvo for MSI is an MSA
            // There are four exceptions, though, when an irregularly inflected form is involved:
            // 1. <MoForm DbRef="x"... and x is an hvo for a LexEntryInflType.
            //       This is one of the null allomorphs we create when building the
            //       input for the parser in order to still get the Word Grammar to have something in any
            //       required slots in affix templates.  The parser filer can ignore these.
            // 2. <MSI DbRef="y"... and y is an hvo for a LexEntryInflType.
            //       This is one of the null allomorphs we create when building the
            //       input for the parser in order to still get the Word Grammar to have something in any
            //       required slots in affix templates.  The parser filer can ignore these.
            // 3. <MSI DbRef="y"... and y is an hvo for a LexEntry.
            //       The LexEntry is a variant form for the first set of LexEntryRefs.
            // 4. <MSI DbRef="y"... and y is an hvo for a LexEntry followed by a period and an index digit.
            //       The LexEntry is a variant form and the (non-zero) index indicates
            //       which set of LexEntryRefs it is for.
            ICmObject objForm;

            if (!cache.ServiceLocator.GetInstance <ICmObjectRepository>().TryGetObject(int.Parse(formHvo), out objForm))
            {
                morph = null;
                return(false);
            }
            var form = objForm as IMoForm;

            if (form == null)
            {
                morph = null;
                return(true);
            }

            // Irregulary inflected forms can have a combination MSA hvo: the LexEntry hvo, a period, and an index to the LexEntryRef
            Tuple <int, int> msaTuple = ProcessMsaHvo(msaHvo);
            ICmObject        objMsa;

            if (!cache.ServiceLocator.GetInstance <ICmObjectRepository>().TryGetObject(msaTuple.Item1, out objMsa))
            {
                morph = null;
                return(false);
            }
            var msa = objMsa as IMoMorphSynAnalysis;

            if (msa != null)
            {
                morph = new ParseMorph(form, msa);
                return(true);
            }

            var msaAsLexEntry = objMsa as ILexEntry;

            if (msaAsLexEntry != null)
            {
                // is an irregularly inflected form
                // get the MoStemMsa of its variant
                if (msaAsLexEntry.EntryRefsOS.Count > 0)
                {
                    ILexEntryRef lexEntryRef = msaAsLexEntry.EntryRefsOS[msaTuple.Item2];
                    ILexSense    sense       = MorphServices.GetMainOrFirstSenseOfVariant(lexEntryRef);
                    var          inflType    = lexEntryRef.VariantEntryTypesRS[0] as ILexEntryInflType;
                    morph = new ParseMorph(form, sense.MorphoSyntaxAnalysisRA, inflType);
                    return(true);
                }
            }

            // if it is anything else, we ignore it
            morph = null;
            return(true);
        }
		private void btnOK_Click(object sender, EventArgs e)
		{
			if (SelectedID == 0)
				return; // odd. nothing more to do.

			ILexEntry variant;
			IVariantComponentLexeme componentLexeme;
			ILexEntryType selectedEntryType;
			GetVariantAndComponentAndSelectedEntryType(out variant, out componentLexeme, out selectedEntryType);

			ILexEntryRef matchingEntryRef = FindMatchingEntryRef(variant, componentLexeme, selectedEntryType);
			if (matchingEntryRef != null)
			{
				// we found a matching ComponentLexeme. See if we can find the selected type.
				// if the selected type does not yet exist, add it.
				if (selectedEntryType != null &&
					!matchingEntryRef.VariantEntryTypesRS.Contains(selectedEntryType))
				{
					matchingEntryRef.VariantEntryTypesRS.Append(selectedEntryType);
				}

				m_variantEntryRefResult = matchingEntryRef;
				m_fNewlyCreatedVariantEntryRef = false;
				return;
			}

			// otherwise we need to create a new LexEntryRef.
			m_fNewlyCreatedVariantEntryRef = true;
			if (variant != null)
			{
				m_variantEntryRefResult = variant.MakeVariantOf(componentLexeme, selectedEntryType);
			}
			else
			{
				m_variantEntryRefResult = componentLexeme.CreateVariantEntryAndBackRef(selectedEntryType,
					m_tssVariantLexemeForm);
			}
		}
示例#40
0
		/// ------------------------------------------------------------------------------------
		internal PaVariantOfInfo(ILexEntryRef lxEntryRef)
		{
			xVariantComment = PaMultiString.Create(lxEntryRef.Summary, lxEntryRef.Cache.ServiceLocator);
			xVariantType = lxEntryRef.VariantEntryTypesRS.Select(x => PaCmPossibility.Create(x)).ToList();
		}
		protected override void m_btnInsert_Click(object sender, EventArgs e)
		{
			if (!m_fBackRefToVariant)
				base.m_btnInsert_Click(sender, e);

			// the user wants to try to create a variant with a lexeme form
			// built from the current state of our Find text box and WritingSystem combo.
			ITsString tssNewVariantLexemeForm = CreateVariantTss();
			if (tssNewVariantLexemeForm == null)
				return;

			// we need to create the new LexEntryRef and its variant from the starting entry.
			UndoableUnitOfWorkHelper.Do(LexTextControls.ksUndoCreateVarEntry, LexTextControls.ksRedoCreateVarEntry, m_startingEntry, () =>
			{
				m_variantEntryRefResult = m_startingEntry.CreateVariantEntryAndBackRef(null, tssNewVariantLexemeForm);
			});
			m_fNewlyCreatedVariantEntryRef = true;
			m_selObject = m_variantEntryRefResult.Owner as ILexEntry;
			m_fNewlyCreated = true;
			DialogResult = DialogResult.OK;
			Close();
		}
示例#42
0
        protected override void HandleChooser()
        {
            string displayWs = "analysis vernacular";

#pragma warning disable 219
            string postDialogMessageTrigger = null;
#pragma warning restore 219

            if (m_configurationNode != null)
            {
                XmlNode node = m_configurationNode.SelectSingleNode("deParams");
                if (node != null)
                {
                    displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower();
                    postDialogMessageTrigger = XmlUtils.GetAttributeValue(node, "postChangeMessageTrigger", null);
                }
            }

            var labels = ObjectLabel.CreateObjectLabels(m_cache, m_obj.ReferenceTargetCandidates(m_flid),
                                                        m_displayNameProperty, displayWs);

            using (MorphTypeChooser chooser = GetChooser(labels))
            {
                bool fMadeMorphTypeChange = false;
                var  entry = (ILexEntry)m_obj.Owner;
                chooser.InitializeExtras(m_configurationNode, Mediator);
                chooser.SetObjectAndFlid(m_obj.Hvo, m_flid);
                chooser.SetHelpTopic(Slice.GetChooserHelpTopicID());

                var hvoType      = m_cache.DomainDataByFlid.get_ObjectProp(m_obj.Hvo, m_flid);
                var morphTypeRep = m_cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>();
                var type         = hvoType != 0 ? morphTypeRep.GetObject(hvoType) : null;
                chooser.MakeSelection(type);
                // LT-4433 changed the Alternate Forms to choose between Stem and Affix automatically
                // when inserting.  Thus, we need the check box in that environment as well.
                //if (m_obj.OwningFlid != (int)LexEntry.LexEntryTags.kflidLexemeForm)
                //    chooser.ShowAllTypesCheckBoxVisible = false;
                if (chooser.ShowDialog() == DialogResult.OK)
                {
                    var    selected = (IMoMorphType)chooser.ChosenOne.Object;
                    var    original = Target as IMoMorphType;
                    string sUndo    = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeUndo", m_ksPath);
                    string sRedo    = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeRedo", m_ksPath);

                    bool fRemoveComponents = false;
                    if (selected.Guid == MoMorphTypeTags.kguidMorphRoot ||
                        selected.Guid == MoMorphTypeTags.kguidMorphBoundRoot)
                    {
                        // changing to root...not allowed to have complex forms.
                        foreach (ILexEntryRef ler in entry.EntryRefsOS)
                        {
                            if (ler.RefType == LexEntryRefTags.krtComplexForm)
                            {
                                fRemoveComponents = true;
                                // If there are no components we will delete without asking...but must then check for more
                                // complex forms that DO have components.
                                if (ler.ComponentLexemesRS.Count > 0)
                                {
                                    // TODO-Linux: Help is not implemented in Mono
                                    if (MessageBox.Show(FindForm(), DetailControlsStrings.ksRootNoComponentsMessage,
                                                        DetailControlsStrings.ksRootNoComponentsCaption, MessageBoxButtons.YesNo,
                                                        MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0, m_mediator.HelpTopicProvider.HelpFile,
                                                        HelpNavigator.Topic, "/Using_Tools/Lexicon_tools/Lexicon_Edit/change_the_morph_type.htm") != DialogResult.Yes)
                                    {
                                        return;
                                    }
                                    break;
                                }
                            }
                        }
                    }

                    UndoableUnitOfWorkHelper.Do(sUndo, sRedo, entry, () =>
                    {
                        if (fRemoveComponents)
                        {
                            foreach (var ler in entry.EntryRefsOS.Where(entryRef => entryRef.RefType == LexEntryRefTags.krtComplexForm))
                            {
                                entry.EntryRefsOS.Remove(ler);
                            }
                        }

                        if (IsStemType(original) || m_obj is IMoStemAllomorph)
                        {
                            if (IsStemType(selected))
                            {
                                Target = selected;
                            }
                            else
                            {
                                //have to switch from stem to affix
                                fMadeMorphTypeChange = ChangeStemToAffix(entry, selected);
                            }
                        }
                        else
                        {
                            // original is affix variety
                            if (IsStemType(selected))
                            {
                                //have to switch from affix to stem
                                fMadeMorphTypeChange = ChangeAffixToStem(entry, selected);
                            }
                            else
                            {
                                Target = selected;
                            }
                        }
                        if (selected.Guid == MoMorphTypeTags.kguidMorphPhrase)
                        {
                            ILexEntryRef ler = m_cache.ServiceLocator.GetInstance <ILexEntryRefFactory>().Create();
                            entry.EntryRefsOS.Add(ler);
                            ler.RefType        = LexEntryRefTags.krtComplexForm;
                            ler.HideMinorEntry = 1;
                        }
                    });
                }
            }
        }
        public override void FixtureSetup()
        {
            base.FixtureSetup();
            m_entryFactory       = Cache.ServiceLocator.GetInstance <ILexEntryFactory>();
            m_senseFactory       = Cache.ServiceLocator.GetInstance <ILexSenseFactory>();
            m_exampleFactory     = Cache.ServiceLocator.GetInstance <ILexExampleSentenceFactory>();
            m_lexEntryRefFactory = Cache.ServiceLocator.GetInstance <ILexEntryRefFactory>();
            m_lexRefTypeFactory  = Cache.ServiceLocator.GetInstance <ILexRefTypeFactory>();
            m_lexRefFactory      = Cache.ServiceLocator.GetInstance <ILexReferenceFactory>();
            m_possListFactory    = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>();

            m_flidReferringSenses = Cache.MetaDataCacheAccessor.GetFieldId2(CmSemanticDomainTags.kClassId, "ReferringSenses",
                                                                            false);

            UndoableUnitOfWorkHelper.Do("do", "undo", Cache.ActionHandlerAccessor,
                                        () =>
            {
                m_domainBadWords    = Cache.ServiceLocator.GetInstance <ICmSemanticDomainFactory>().Create();
                m_domainTemperature = Cache.ServiceLocator.GetInstance <ICmSemanticDomainFactory>().Create();
                Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(m_domainBadWords);
                Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(m_domainTemperature);
                m_mainDict = Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS[0];
                m_blank    = MakeEntry("blank", "swear word", true);
                m_blank.SensesOS[0].SemanticDomainsRC.Add(m_domainBadWords);
                m_hot     = MakeEntry("hot", "high temperature", false);
                m_hotTemp = m_hot.SensesOS[0];
                m_hotTemp.SemanticDomainsRC.Add(m_domainTemperature);
                m_trouble = MakeSense(m_hot, "trouble");
                m_trouble.DoNotPublishInRC.Add(m_mainDict);
                m_trouble.PicturesOS.Add(Cache.ServiceLocator.GetInstance <ICmPictureFactory>().Create());
                m_desirable = MakeSense(m_hot, "desirable");
                m_fastCar   = MakeSense(m_desirable, "fast (car)");

                m_badHot  = MakeExample(m_hotTemp, "a hot pile of blank", true);
                m_goodHot = MakeExample(m_hotTemp, "a hot bath", false);

                m_water              = MakeEntry("water", "H2O", false);
                m_waterH2O           = m_water.SensesOS[0];
                m_hotWater           = MakeEntry("hot water", "trouble", false);
                m_hotWaterComponents = MakeEntryRef(m_hotWater, new ICmObject[] { m_trouble, m_waterH2O },
                                                    new[] { m_trouble, m_waterH2O },
                                                    LexEntryRefTags.krtComplexForm);

                m_blank2      = MakeEntry("blank", "vacant", false);
                m_blank3      = MakeEntry("blank", "erase", false);
                m_water2      = MakeEntry("water", "urinate", true);
                m_waterPrefix = MakeEntry("water", "aquatic", false);
                m_waterPrefix.LexemeFormOA.MorphTypeRA = Cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>()
                                                         .GetObject(MoMorphTypeTags.kguidMorphPrefix);

                m_synonym       = MakeRefType("synonym", null, (int)LexRefTypeTags.MappingTypes.kmtSenseCollection);
                m_blip          = MakeEntry("blip", "rude word", true);
                m_bother        = MakeEntry("bother", "I'm annoyed by that", false);
                m_ouch          = MakeEntry("ouch", "that hurt", false);
                m_blipOuch      = MakeSense(m_blip.SensesOS[0], "rude ouch");
                m_blankSynonyms = MakeLexRef(m_synonym, new ICmObject[] { m_blank, m_ouch.SensesOS[0], m_blip.SensesOS[0], m_blipOuch, m_bother });

                m_problem         = MakeEntry("problem", "difficulty", false);
                m_problemSynonyms = MakeLexRef(m_synonym, new ICmObject[] { m_problem, m_trouble });

                m_body       = MakeEntry("body", "body", true);
                m_arm        = MakeEntry("arm", "arm", false);
                m_leg        = MakeEntry("leg", "leg", false);
                m_belly      = MakeEntry("belly", "belly", true);
                m_torso      = MakeEntry("torso", "torso", false);
                m_partWhole  = MakeRefType("partWhole", null, (int)LexRefTypeTags.MappingTypes.kmtEntryTree);
                m_bodyParts  = MakeLexRef(m_partWhole, new ICmObject[] { m_body, m_arm, m_leg.SensesOS[0], m_torso, m_belly });
                m_torsoParts = MakeLexRef(m_partWhole, new ICmObject[] { m_torso, m_arm, m_belly });

                m_hotBlank = MakeEntry("hotBlank", "problem rude word", false);
                MakeEntryRef(m_hotBlank, new ICmObject[] { m_trouble, m_water2 },
                             new ICmObject[] { m_trouble, m_water2 },
                             LexEntryRefTags.krtComplexForm);

                m_blueColor = MakeEntry("blue", "color blue", false);
                m_blueCold  = MakeEntry("blue", "cold", false);
                m_blueMusic = MakeEntry("blue", "jazzy", false);
                m_blueSad   = MakeEntry("blue", "sad", false);

                m_blueMusic.HomographNumber = 2;                               // will duplicate blue cold; pathological, but should not crash.
                m_blueSad.HomographNumber   = 3;                               // will conflict with renumbered blueMusic

                m_bluer             = m_blueColor.SensesOS[0];
                m_sky               = MakeEntry("sky", "interface between atmosphere and space", false, true);                   // true excludes as headword
                m_skyReal           = m_sky.SensesOS[0];
                m_blueSky           = MakeEntry("blue sky", "clear, huge potential", false, false);
                m_blueSkyComponents = MakeEntryRef(m_blueSky, new ICmObject[] { m_blueColor, m_skyReal },
                                                   new[] { m_bluer, m_skyReal },
                                                   LexEntryRefTags.krtComplexForm);

                m_ringBell   = MakeEntry("ring", "bell", false, false);
                m_ringCircle = MakeEntry("ring", "circle", false, true);
                m_ringGold   = MakeEntry("ring", "gold", false, false);

                m_blackVerb  = MakeEntry("black", "darken", false, true);
                m_blackColor = MakeEntry("black", "dark", false, false);

                m_hotArm           = MakeEntry("hotarm", "pitcher", false, false);
                m_hotArmComponents = MakeEntryRef(m_hotArm, new ICmObject[] { m_hot, m_arm },
                                                  new[] { m_hot, m_arm },
                                                  LexEntryRefTags.krtComplexForm);
                m_hotArm.DoNotPublishInRC.Add(m_mainDict);
                m_hotArmComponents.ShowComplexFormsInRS.Add(m_hot);

                m_nolanryan           = MakeEntry("Nolan_Ryan", "pitcher", false, false);
                m_nolanryanComponents = MakeEntryRef(m_nolanryan, new ICmObject[] { m_hot },
                                                     new[] { m_hot },
                                                     LexEntryRefTags.krtVariant);
                m_nolanryanComponents.VariantEntryTypesRS.Add(
                    (ILexEntryType)Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS[0]);
                m_nolanryan.DoNotPublishInRC.Add(m_mainDict);

                m_publisher = new MockPublisher((ISilDataAccessManaged)Cache.DomainDataByFlid, kmainFlid);
                m_publisher.SetOwningPropValue(Cache.LangProject.LexDbOA.Entries.Select(le => le.Hvo).ToArray());
                m_decorator = new DictionaryPublicationDecorator(Cache, m_publisher, ObjectListPublisher.OwningFlid);
            });
        }
		public AddComponentChooserCommand(FdoCache cache, bool fCloseBeforeExecuting,
			string sLabel, XCore.Mediator mediator, ICmObject obj,
			Form form)
			: base(cache, fCloseBeforeExecuting, sLabel, mediator)
		{
			m_ler = obj as ILexEntryRef;
			m_form = form;
		}
        public static void WriteMorphInfoElements(this XmlWriter writer, FdoCache cache, string formID, string msaID, string wordType, string props)
        {
            ICmObject obj  = cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(int.Parse(formID, CultureInfo.InvariantCulture));
            var       form = obj as IMoForm;

            if (form == null)
            {
                // This is one of the null allomorphs we create when building the
                // input for the parser in order to still get the Word Grammar to have something in any
                // required slots in affix templates.
                var lexEntryInflType = obj as ILexEntryInflType;
                if (lexEntryInflType != null)
                {
                    WriteLexEntryInflTypeElement(writer, wordType, lexEntryInflType);
                    return;
                }
            }
            string shortName;
            string alloform;
            string gloss;
            string citationForm;

            if (form != null)
            {
                shortName = form.LongName;
                int iFirstSpace = shortName.IndexOf(" (", StringComparison.Ordinal);
                int iLastSpace  = shortName.LastIndexOf("):", StringComparison.Ordinal) + 2;
                alloform = shortName.Substring(0, iFirstSpace);
                Tuple <int, int> msaTuple = ProcessMsaHvo(msaID);
                ICmObject        msaObj   = cache.ServiceLocator.GetObject(msaTuple.Item1);
                if (msaObj.ClassID == LexEntryTags.kClassId)
                {
                    var entry = msaObj as ILexEntry;
                    Debug.Assert(entry != null);
                    if (entry.EntryRefsOS.Count > 0)
                    {
                        ILexEntryRef   lexEntryRef = entry.EntryRefsOS[msaTuple.Item2];
                        ITsIncStrBldr  sbGlossPrepend;
                        ITsIncStrBldr  sbGlossAppend;
                        ILexSense      sense   = MorphServices.GetMainOrFirstSenseOfVariant(lexEntryRef);
                        IWritingSystem glossWs = cache.ServiceLocator.WritingSystemManager.Get(cache.DefaultAnalWs);
                        MorphServices.JoinGlossAffixesOfInflVariantTypes(lexEntryRef.VariantEntryTypesRS,
                                                                         glossWs, out sbGlossPrepend, out sbGlossAppend);
                        ITsIncStrBldr sbGloss = sbGlossPrepend;
                        sbGloss.Append(sense.Gloss.BestAnalysisAlternative.Text);
                        sbGloss.Append(sbGlossAppend.Text);
                        gloss = sbGloss.Text;
                    }
                    else
                    {
                        gloss = ParserCoreStrings.ksUnknownGloss;
                    }
                }
                else
                {
                    var msa = msaObj as IMoMorphSynAnalysis;
                    gloss = msa != null?msa.GetGlossOfFirstSense() : shortName.Substring(iFirstSpace, iLastSpace - iFirstSpace).Trim();
                }
                citationForm = shortName.Substring(iLastSpace).Trim();
                shortName    = String.Format(ParserCoreStrings.ksX_Y_Z, alloform, gloss, citationForm);
            }
            else
            {
                alloform     = ParserCoreStrings.ksUnknownMorpheme;             // in case the user continues...
                gloss        = ParserCoreStrings.ksUnknownGloss;
                citationForm = ParserCoreStrings.ksUnknownCitationForm;
                shortName    = String.Format(ParserCoreStrings.ksX_Y_Z, alloform, gloss, citationForm);
                throw new ApplicationException(shortName);
            }
            writer.WriteElementString("shortName", shortName);
            writer.WriteElementString("alloform", alloform);
            switch (form.ClassID)
            {
            case MoStemAllomorphTags.kClassId:
                WriteStemNameElement(writer, form, props);
                break;

            case MoAffixAllomorphTags.kClassId:
                WriteAffixAlloFeatsElement(writer, form, props);
                WriteStemNameAffixElement(writer, cache, props);
                break;
            }
            writer.WriteElementString("gloss", gloss);
            writer.WriteElementString("citationForm", citationForm);
        }
		public override void FixtureSetup()
		{
			base.FixtureSetup();
			m_entryFactory = Cache.ServiceLocator.GetInstance<ILexEntryFactory>();
			m_senseFactory = Cache.ServiceLocator.GetInstance<ILexSenseFactory>();
			m_exampleFactory = Cache.ServiceLocator.GetInstance<ILexExampleSentenceFactory>();
			m_lexEntryRefFactory = Cache.ServiceLocator.GetInstance<ILexEntryRefFactory>();
			m_lexRefTypeFactory = Cache.ServiceLocator.GetInstance<ILexRefTypeFactory>();
			m_lexRefFactory = Cache.ServiceLocator.GetInstance<ILexReferenceFactory>();
			m_possListFactory = Cache.ServiceLocator.GetInstance<ICmPossibilityListFactory>();

			m_flidReferringSenses = Cache.MetaDataCacheAccessor.GetFieldId2(CmSemanticDomainTags.kClassId, "ReferringSenses",
				false);

			UndoableUnitOfWorkHelper.Do("do", "undo", Cache.ActionHandlerAccessor,
				() =>
					{
						m_domainBadWords = Cache.ServiceLocator.GetInstance<ICmSemanticDomainFactory>().Create();
						m_domainTemperature = Cache.ServiceLocator.GetInstance<ICmSemanticDomainFactory>().Create();
						Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(m_domainBadWords);
						Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(m_domainTemperature);
						m_mainDict = Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS[0];
						m_blank = MakeEntry("blank", "swear word", true);
						m_blank.SensesOS[0].SemanticDomainsRC.Add(m_domainBadWords);
						m_hot = MakeEntry("hot", "high temperature", false);
						m_hotTemp = m_hot.SensesOS[0];
						m_hotTemp.SemanticDomainsRC.Add(m_domainTemperature);
						m_trouble = MakeSense(m_hot, "trouble");
						m_trouble.DoNotPublishInRC.Add(m_mainDict);
						m_trouble.PicturesOS.Add(Cache.ServiceLocator.GetInstance<ICmPictureFactory>().Create());
						m_desirable = MakeSense(m_hot, "desirable");
						m_fastCar = MakeSense(m_desirable, "fast (car)");

						m_badHot = MakeExample(m_hotTemp, "a hot pile of blank", true);
						m_goodHot = MakeExample(m_hotTemp, "a hot bath", false);

						m_water = MakeEntry("water", "H2O", false);
						m_waterH2O = m_water.SensesOS[0];
						m_hotWater = MakeEntry("hot water", "trouble", false);
						m_hotWaterComponents = MakeEntryRef(m_hotWater, new ICmObject[] { m_trouble, m_waterH2O },
							new[] { m_trouble, m_waterH2O },
							LexEntryRefTags.krtComplexForm);

						m_blank2 = MakeEntry("blank", "vacant", false);
						m_blank3 = MakeEntry("blank", "erase", false);
						m_water2 = MakeEntry("water", "urinate", true);
						m_waterPrefix = MakeEntry("water", "aquatic", false);
						m_waterPrefix.LexemeFormOA.MorphTypeRA = Cache.ServiceLocator.GetInstance<IMoMorphTypeRepository>()
							.GetObject(MoMorphTypeTags.kguidMorphPrefix);

						m_synonym = MakeRefType("synonym", null, (int)LexRefTypeTags.MappingTypes.kmtSenseCollection);
						m_blip = MakeEntry("blip", "rude word", true);
						m_bother = MakeEntry("bother", "I'm annoyed by that", false);
						m_ouch = MakeEntry("ouch", "that hurt", false);
						m_blipOuch = MakeSense(m_blip.SensesOS[0], "rude ouch");
						m_blankSynonyms = MakeLexRef(m_synonym, new ICmObject[] {m_blank, m_ouch.SensesOS[0], m_blip.SensesOS[0], m_blipOuch, m_bother});

						m_problem = MakeEntry("problem", "difficulty", false);
						m_problemSynonyms = MakeLexRef(m_synonym, new ICmObject[] { m_problem, m_trouble });

						m_body = MakeEntry("body", "body", true);
						m_arm = MakeEntry("arm", "arm", false);
						m_leg = MakeEntry("leg", "leg", false);
						m_belly = MakeEntry("belly", "belly", true);
						m_torso = MakeEntry("torso", "torso", false);
						m_partWhole = MakeRefType("partWhole", null, (int)LexRefTypeTags.MappingTypes.kmtEntryTree);
						m_bodyParts = MakeLexRef(m_partWhole, new ICmObject[] {m_body, m_arm, m_leg.SensesOS[0], m_torso, m_belly});
						m_torsoParts = MakeLexRef(m_partWhole, new ICmObject[] {m_torso, m_arm, m_belly});

						m_hotBlank = MakeEntry("hotBlank", "problem rude word", false);
						MakeEntryRef(m_hotBlank, new ICmObject[] { m_trouble, m_water2 },
							new ICmObject[] { m_trouble, m_water2 },
							LexEntryRefTags.krtComplexForm);

						m_blueColor = MakeEntry("blue", "color blue", false);
						m_blueCold = MakeEntry("blue", "cold", false);
						m_blueMusic = MakeEntry("blue", "jazzy", false);
						m_blueSad = MakeEntry("blue", "sad", false);

						m_blueMusic.HomographNumber = 2; // will duplicate blue cold; pathological, but should not crash.
						m_blueSad.HomographNumber = 3; // will conflict with renumbered blueMusic

						m_bluer = m_blueColor.SensesOS[0];
						m_sky = MakeEntry("sky", "interface between atmosphere and space", false, true); // true excludes as headword
						m_skyReal = m_sky.SensesOS[0];
						m_blueSky = MakeEntry("blue sky", "clear, huge potential", false, false);
						m_blueSkyComponents = MakeEntryRef(m_blueSky, new ICmObject[] { m_blueColor, m_skyReal },
							new[] { m_bluer, m_skyReal },
							LexEntryRefTags.krtComplexForm);

						m_ringBell = MakeEntry("ring", "bell", false, false);
						m_ringCircle = MakeEntry("ring", "circle", false, true);
						m_ringGold = MakeEntry("ring", "gold", false, false);

						m_blackVerb = MakeEntry("black", "darken", false, true);
						m_blackColor = MakeEntry("black", "dark", false, false);

						m_hotArm = MakeEntry("hotarm", "pitcher", false, false);
						m_hotArmComponents = MakeEntryRef(m_hotArm, new ICmObject[] { m_hot, m_arm },
												new[] { m_hot, m_arm },
												LexEntryRefTags.krtComplexForm);
						m_hotArm.DoNotPublishInRC.Add(m_mainDict);
						m_hotArmComponents.ShowComplexFormsInRS.Add(m_hot);

						m_nolanryan = MakeEntry("Nolan_Ryan", "pitcher", false, false);
						m_nolanryanComponents = MakeEntryRef(m_nolanryan, new ICmObject[] { m_hot },
												new[] { m_hot },
												LexEntryRefTags.krtVariant);
						m_nolanryanComponents.VariantEntryTypesRS.Add(
							(ILexEntryType)Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS[0]);
						m_nolanryan.DoNotPublishInRC.Add(m_mainDict);

						m_edName = MakeEntry("ed", "someone called ed", false);
						m_edSuffix = MakeEntry("ed", "past", false, false, true);

						m_publisher = new MockPublisher((ISilDataAccessManaged)Cache.DomainDataByFlid, kmainFlid);
						m_publisher.SetOwningPropValue(Cache.LangProject.LexDbOA.Entries.Select(le => le.Hvo).ToArray());
						m_decorator = new DictionaryPublicationDecorator(Cache, m_publisher, ObjectListPublisher.OwningFlid);
					});
		}
示例#47
0
		/// ------------------------------------------------------------------------------------
		internal PaVariant(ILexEntryRef lxEntryRef)
		{
			var lx = lxEntryRef.OwnerOfClass<ILexEntry>();
			xVariantForm = PaMultiString.Create(lx.LexemeFormOA.Form, lxEntryRef.Cache.ServiceLocator);
			xVariantInfo = new PaVariantOfInfo(lxEntryRef);
		}
		protected override void btnInsert_Click(object sender, EventArgs e)
		{
			if (!m_fBackRefToVariant)
				base.btnInsert_Click(sender, e);

			// the user wants to try to create a variant with a lexeme form
			// built from the current state of our Find text box and WritingSystem combo.
			ITsString tssNewVariantLexemeForm = CreateVariantTss();
			if (tssNewVariantLexemeForm == null)
				return;

			// we need to create the new LexEntryRef and its variant from the starting entry.
			m_variantEntryRefResult = m_startingEntry.CreateVariantEntryAndBackRef(null, tssNewVariantLexemeForm);
			m_fNewlyCreatedVariantEntryRef = true;
			m_selEntryID = m_variantEntryRefResult.OwnerHVO;
			m_fNewlyCreated = true;
			DialogResult = DialogResult.OK;
			Close();
		}
		public AddPrimaryLexemeChooserCommand(FdoCache cache, bool fCloseBeforeExecuting,
			string sLabel, XCore.Mediator mediator, ICmObject lexEntryRef, /* Why ICmObject? */
			Form parentWindow)
			: base(cache, fCloseBeforeExecuting, sLabel, mediator)
		{
			m_lexEntryRef = lexEntryRef as ILexEntryRef;
			m_parentWindow = parentWindow;
		}
示例#50
0
		/// <summary>
		///
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="hvoEntryToDisplay"></param>
		/// <param name="wsVern"></param>
		/// <param name="ler"></param>
		/// <returns></returns>
		static public ITsString GetLexEntryTss(FdoCache cache, int hvoEntryToDisplay, int wsVern, ILexEntryRef ler)
		{
			LexEntryVc vcEntry = new LexEntryVc(cache);
			vcEntry.WritingSystemCode = wsVern;
			TsStringCollectorEnv collector = new TsStringCollectorEnv(null, cache.MainCacheAccessor, hvoEntryToDisplay);
			collector.RequestAppendSpaceForFirstWordInNewParagraph = false;
			vcEntry.Display(collector, hvoEntryToDisplay, (int)VcFrags.kfragHeadWord);
			if (ler != null)
				vcEntry.Display(collector, ler.Hvo, LexEntryVc.kfragVariantTypes);
			return collector.Result;
		}
				public MorphItem(MorphItemOptions options)
					: this(options.HvoMoForm, options.HvoEntry, options.TssName, options.HvoSense, options.SenseName, options.HvoMsa, options.MsaName)
				{
					m_inflType = options.InflType;
					m_entryRef = options.EntryRef;
					if (m_entryRef != null)
					{
						var entry = GetMainEntryOfVariant(m_entryRef);
						m_hvoMainEntryOfVariant = entry.Hvo;
					}
				}
示例#52
0
        /// <summary>
        /// Override method to handle launching of a chooser for selecting lexical entries or senses.
        /// </summary>
        protected override void HandleChooser()
        {
            if (m_flid == LexEntryRefTags.kflidComponentLexemes)
            {
                using (LinkEntryOrSenseDlg dlg = new LinkEntryOrSenseDlg())
                {
                    ILexEntry le = null;
                    if (m_obj.ClassID == LexEntryTags.kClassId)
                    {
                        // filter this entry from the list.
                        le = m_obj as ILexEntry;
                    }
                    else
                    {
                        // assume the owner is the entry (e.g. owner of LexEntryRef)
                        le = m_obj.OwnerOfClass <ILexEntry>();
                    }
                    dlg.SetDlgInfo(m_cache, m_mediator, m_propertyTable, le);
                    String str = ShowHelp.RemoveSpaces(this.Slice.Label);
                    dlg.SetHelpTopic("khtpChooseLexicalEntryOrSense-" + str);
                    if (dlg.ShowDialog(FindForm()) == DialogResult.OK)
                    {
                        AddItem(dlg.SelectedObject);
                    }
                }
            }
            else if (m_flid == LexEntryRefTags.kflidPrimaryLexemes)
            {
                string displayWs = "analysis vernacular";
                if (m_configurationNode != null)
                {
                    XmlNode node = m_configurationNode.SelectSingleNode("deParams");
                    if (node != null)
                    {
                        displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower();
                    }
                }
                ILexEntryRef ler = m_obj as ILexEntryRef;
                Debug.Assert(ler != null);
                var labels = ObjectLabel.CreateObjectLabels(m_cache, ler.ComponentLexemesRS.Cast <ICmObject>(),
                                                            m_displayNameProperty, displayWs);
                using (ReallySimpleListChooser chooser = new ReallySimpleListChooser(null,
                                                                                     labels, "PrimaryLexemes", m_cache, ler.PrimaryLexemesRS.Cast <ICmObject>(),
                                                                                     false, m_propertyTable.GetValue <IHelpTopicProvider>("HelpTopicProvider")))
                {
                    chooser.HideDisplayUsageCheckBox();
                    chooser.SetObjectAndFlid(m_obj.Hvo, m_flid);                        // may set TextParamHvo
                    chooser.Text = LexEdStrings.ksChooseWhereToShowSubentry;
                    chooser.SetHelpTopic(Slice.GetChooserHelpTopicID());
                    chooser.InitializeExtras(null, Mediator, m_propertyTable);
                    chooser.AddLink(LexEdStrings.ksAddAComponent, ReallySimpleListChooser.LinkType.kDialogLink,
                                    new AddPrimaryLexemeChooserCommand(m_cache, false, null, m_mediator, m_propertyTable, m_obj, FindForm()));
                    DialogResult res = chooser.ShowDialog();
                    if (DialogResult.Cancel == res)
                    {
                        return;
                    }
                    if (chooser.ChosenObjects != null)
                    {
                        SetItems(chooser.ChosenObjects);
                    }
                }
            }
            else
            {
                string fieldName = m_obj.Cache.MetaDataCacheAccessor.GetFieldName(m_flid);
                Debug.Assert(m_obj is ILexEntry || m_obj is ILexSense);
                switch (fieldName)
                {
                case "ComplexFormEntries":
                    using (var dlg = new EntryGoDlg())
                    {
                        dlg.StartingEntry = m_obj as ILexEntry ?? (m_obj as ILexSense).Entry;
                        dlg.SetDlgInfo(m_cache, null, m_mediator, m_propertyTable);
                        String str = ShowHelp.RemoveSpaces(Slice.Label);
                        dlg.SetHelpTopic("khtpChooseComplexFormEntryOrSense-" + str);
                        dlg.SetOkButtonText(LexEdStrings.ksMakeComponentOf);
                        if (dlg.ShowDialog(FindForm()) == DialogResult.OK)
                        {
                            try
                            {
                                UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoAddComplexForm, LexEdStrings.ksRedoAddComplexForm,
                                                            m_obj.Cache.ActionHandlerAccessor,
                                                            () => ((ILexEntry)dlg.SelectedObject).AddComponent(m_obj));
                            }
                            catch (ArgumentException)
                            {
                                MessageBoxes.ReportLexEntryCircularReference(dlg.SelectedObject, m_obj, false);
                            }
                        }
                    }
                    break;

                case "VisibleComplexFormEntries":                         // obsolete?
                case "Subentries":
                    HandleChooserForBackRefs(fieldName, false);
                    break;

                case "VisibleComplexFormBackRefs":
                    HandleChooserForBackRefs(fieldName, true);
                    break;

                default:
                    Debug.Fail("EntrySequenceReferenceLauncher should only be used for variants, components, or complex forms");
                    break;
                }
            }
        }
示例#53
0
			/// <summary>
			///
			/// </summary>
			/// <param name="hvoMorph"></param>
			/// <param name="le">the entry used in the morph bundle (for sense info). typically
			/// this is an owner of hvoMorph, but if not, it most likely has hvoMorph linked as its variant.</param>
			/// <param name="fMorphIsVariantOfEntry">indicates whether the given morph is a variant of the given entry(le) or
			/// one of its senses</param>
			private void BuildMorphItemsFromEntry(int hvoMorph, ILexEntry le, ILexEntryRef ler)
			{
				IMoForm mf = MoForm.CreateFromDBObject(m_caches.MainCache, hvoMorph);
				int hvoLexEntry = 0;
				if (le != null)
					hvoLexEntry = le.Hvo;
				ITsString tssName = null;
				if (le != null)
				{
					tssName = InterlinDocChild.GetLexEntryTss(m_caches.MainCache, le.Hvo, m_wsVern, ler);
				}
				else
				{
					// looks like we're not in a good state, so just use the form for the name.
					int wsActual;
					tssName = mf.Form.GetAlternativeOrBestTss(m_wsVern, out wsActual);
				}
				string sql2 = string.Format("select SenseId from fnGetSensesInEntry$({0})", hvoLexEntry);
				List<int> hvoSenses = DbOps.ReadIntsFromCommand(m_caches.MainCache,
					sql2, null);
				if (hvoSenses.Count > 0)
				{
					// Populate morphItems with Sense/Msa level specifics
					for (int i = 0; i < hvoSenses.Count; ++i)
					{
						int hvoSense = hvoSenses[i];

						ITsString tssSense =
							m_caches.MainCache.MainCacheAccessor.get_MultiStringAlt(
							(int)hvoSense,
							(int)LexSense.LexSenseTags.kflidGloss,
							m_caches.MainCache.DefaultAnalWs);
						if (tssSense.Length == 0)
						{
							// If it doesn't have a gloss (e.g., from Categorised Entry), use the definition.
							tssSense = m_caches.MainCache.MainCacheAccessor.get_MultiStringAlt(
								(int)hvoSense,
								(int)LexSense.LexSenseTags.kflidDefinition,
								m_caches.MainCache.DefaultAnalWs);
						}

						ILexSense sense = LexSense.CreateFromDBObject(
							m_caches.MainCache, (int)hvoSense);
						IMoMorphSynAnalysis msa = sense.MorphoSyntaxAnalysisRA;
						string msaText = null;
						if (msa != null)
							msaText = msa.InterlinearName;
						MorphItem mi = new MorphItem(hvoMorph, ler != null ? hvoLexEntry : 0, tssName,
							hvoSense, tssSense.Text, sense.MorphoSyntaxAnalysisRAHvo, msaText);
						m_morphItems.Add(mi);
					}
				}
				// Make a LexEntry level item
				m_morphItems.Add(new MorphItem(hvoMorph, ler != null ? hvoLexEntry : 0, tssName));
			}