/// <summary>
		/// when calling the dialog from an "Insert Variant" context this
		/// constructor is used to indicate that m_startingEntry is a componentLexeme
		/// rather than the variant
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="mediator"></param>
		/// <param name="componentLexeme">the entry we wish to find or create a variant for.</param>
		protected void SetDlgInfoForComponentLexeme(FdoCache cache, Mediator mediator, IVariantComponentLexeme componentLexeme)
		{
			m_fBackRefToVariant = true;
			ILexEntry startingEntry = null;
			if (componentLexeme.ClassID == LexEntry.kclsidLexEntry)
			{
				startingEntry = componentLexeme as LexEntry;
			}
			else
			{
				int hvoEntry = cache.GetOwnerOfObjectOfClass(componentLexeme.Hvo, LexEntry.kclsidLexEntry);
				if (hvoEntry != 0)
					startingEntry = LexEntry.CreateFromDBObject(cache, hvoEntry);
			}
			base.SetDlgInfo(cache, mediator, startingEntry);
			// we are looking for an existing variant form
			// so hide the Entry/Sense radio group box.
			grplbl.Visible = false;
			// also hide variant type.
			tcVariantTypes.Visible = false;
			lblVariantType.Visible = false;
			m_fGetVariantEntryTypeFromTreeCombo = false;
			lblCreateEntry.Visible = false;

			// The dialog title and other labels need to reflect "Insert Variant" context.
			m_formLabel.Text = LexTextControls.ks_Variant;
			this.Text = LexTextControls.ksFindVariant;
			btnInsert.Text = LexTextControls.ks_Create;
			// We disable the "Create" button when we don't have text in the Find textbox.
			UpdateButtonCreateNew();
		}
예제 #2
0
        private ILexEntryRef FindMatchingEntryRef(ILexEntry variant, IVariantComponentLexeme componentLexeme, ILexEntryType selectedEntryType)
        {
            ILexEntryRef matchingEntryRef;

            if (variant != null)
            {
                // see if the starting entry has the SelectedID already as a ComponentLexeme
                matchingEntryRef = variant.FindMatchingVariantEntryRef(componentLexeme,
                                                                       selectedEntryType);
            }
            else
            {
                // determine whether the selected entry or sense is already
                // linked to an existing variant with the given lexeme form.
                matchingEntryRef = componentLexeme.FindMatchingVariantEntryBackRef(selectedEntryType, m_tssVariantLexemeForm);
            }
            return(matchingEntryRef);
        }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="mainEntryOrSense"></param>
 /// <param name="mainEntry"></param>
 /// <param name="mainOrFirstSense"></param>
 public static void GetMainEntryAndSenseStack(IVariantComponentLexeme mainEntryOrSense, out ILexEntry mainEntry, out ILexSense mainOrFirstSense)
 {
     if (mainEntryOrSense is ILexEntry)
     {
         mainEntry        = mainEntryOrSense as ILexEntry;
         mainOrFirstSense = mainEntry.SensesOS.Count > 0 ? mainEntry.SensesOS[0] : null;
     }
     else if (mainEntryOrSense is ILexSense)
     {
         mainOrFirstSense = mainEntryOrSense as ILexSense;
         mainEntry        = mainOrFirstSense.Entry;
     }
     else
     {
         mainEntry        = null;
         mainOrFirstSense = null;
     }
 }
예제 #4
0
        protected ILexEntry AddVariantLexeme(List <ICmObject> addList, IVariantComponentLexeme origLe,
                                             string lexForm, IMoMorphType morphTypePoss, string gloss, IPartOfSpeech categoryPoss,
                                             ILexEntryType varType)
        {
            Assert.IsNotNull(varType, "Need a variant entry type!");
            var msa = new SandboxGenericMSA {
                MainPOS = categoryPoss
            };
            var comp = new LexEntryComponents {
                MorphType = morphTypePoss, MSA = msa
            };

            comp.GlossAlternatives.Add(m_tssFact.MakeString(gloss, Cache.DefaultAnalWs));
            comp.LexemeFormAlternatives.Add(m_tssFact.MakeString(lexForm, Cache.DefaultVernWs));
            var entry = m_entryFact.Create(comp);

            entry.MakeVariantOf(origLe, varType);
            addList.Add(entry);
            return(entry);
        }
예제 #5
0
        /// <summary>
        /// 'internal static' so Reversal tests can use it
        /// </summary>
        internal static ILexEntryRef CreateVariantForm(LcmCache cache, IVariantComponentLexeme main, ILexEntry variantForm, string type = TestVariantName)
        {
            var owningList = cache.LangProject.LexDbOA.VariantEntryTypesOA;

            Assert.IsNotNull(owningList, "No VariantEntryTypes property on Lexicon object.");
            var varType = owningList.ReallyReallyAllPossibilities.LastOrDefault(poss => poss.Name.AnalysisDefaultWritingSystem.Text == type) as ILexEntryType;

            if (varType == null && type != null)             // if this type doesn't exist, create it
            {
                varType = cache.ServiceLocator.GetInstance <ILexEntryTypeFactory>().Create();
                owningList.PossibilitiesOS.Add(varType);
                varType.Name.set_String(cache.DefaultAnalWs, type);
            }
            var refOut = variantForm.MakeVariantOf(main, varType);

            // ILexEntry.MakeVariantOf sets a Type even if null is specified. But we want to test typeless variants, so clear them if null is specified.
            if (type == null)
            {
                refOut.VariantEntryTypesRS.Clear();
            }
            return(refOut);
        }
		/// <summary>
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="mediator"></param>
		/// <param name="componentLexeme">the entry we wish to find or create a variant for.</param>
		public void SetDlgInfo(FdoCache cache, Mediator mediator, IVariantComponentLexeme componentLexeme)
		{
			this.SetDlgInfoForComponentLexeme(cache, mediator, componentLexeme);
		}
		/// <summary>
		/// extracts the variant and component from the dialog, depending upon whether we're
		/// called from an "Insert Variant" or "Variant Of..." context.
		/// </summary>
		/// <param name="variant"></param>
		/// <param name="componentLexeme"></param>
		private void GetVariantAndComponentAndSelectedEntryType(out ILexEntry variant, out IVariantComponentLexeme componentLexeme, out ILexEntryType selectedEntryType)
		{
			variant = null;
			componentLexeme = null;
			if (m_fBackRefToVariant)
			{
				// in "Insert Variant" contexts,
				// we're calling the dialog from the component lexeme, so consider SelectedID as the variant.
				componentLexeme = m_startingEntry;
				variant = LexEntry.CreateFromDBObject(m_cache, SelectedID);
			}
			else
			{
				// in "Variant of..." contexts,
				// we're calling the dialog from the variant, so consider SelectedID the componentLexeme.
				variant = m_startingEntry;
				componentLexeme = CmObject.CreateFromDBObject(m_cache, SelectedID) as IVariantComponentLexeme;
			}
			if (m_fGetVariantEntryTypeFromTreeCombo)
				selectedEntryType = LexEntryType.CreateFromDBObject(m_cache, SelectedVariantEntryTypeHvo);
			else
				selectedEntryType = null;
		}
		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;
		}
예제 #9
0
		/// <summary>
		/// Find a LexEntryRef matching the given targetComponent (exlusively), and variantEntryType.
		/// If we can't match on variantEntryType, we'll just return the reference with the matching component.
		/// </summary>
		/// <param name="targetComponent">match on the LexEntryRef that contains this, and only this component.</param>
		/// <param name="variantEntryType"></param>
		/// <returns></returns>
		public ILexEntryRef FindMatchingVariantEntryRef(IVariantComponentLexeme targetComponent, ILexEntryType variantEntryType)
		{
			ILexEntryRef matchingEntryRef = null;
			foreach (ILexEntryRef ler in EntryRefsOS)
			{
				if (ler.RefType == LexEntryRef.krtVariant &&
					ler.ComponentLexemesRS.Count == 1 &&
					ler.ComponentLexemesRS.Contains(targetComponent))
				{
					matchingEntryRef = ler;
					// next see if we can also match against the type, we'll just 'use' that one.
					// otherwise keep going just in case we can find one that does match.
					if (variantEntryType != null && ler.VariantEntryTypesRS.Contains(variantEntryType))
						break;
				}
			}
			return matchingEntryRef;
		}
예제 #10
0
		/// <summary>
		///
		/// </summary>
		/// <param name="mainEntryOrSense"></param>
		/// <param name="variantEntryType"></param>
		/// <param name="targetVariantLexemeForm"></param>
		/// <returns></returns>
		public static ILexEntryRef FindMatchingVariantEntryBackRef(IVariantComponentLexeme mainEntryOrSense,
			ILexEntryType variantEntryType, ITsString targetVariantLexemeForm)
		{
			ILexEntryRef matchingEntryRef = null;
			foreach (int hvoLexEntryRef in mainEntryOrSense.VariantFormEntryBackRefs)
			{
				ILexEntryRef ler = LexEntryRef.CreateFromDBObject((mainEntryOrSense as ICmObject).Cache, hvoLexEntryRef);
				// this only handles matching single component lexemes,
				// so we only try to match those.
				if (ler.ComponentLexemesRS.Count == 1)
				{
					// next see if we can match on the same variant lexeme form
					ILexEntry variantEntry = (ler as CmObject).Owner as ILexEntry;
					if (variantEntry.LexemeFormOA == null || variantEntry.LexemeFormOA.Form == null)
						continue;
					int wsTargetVariant = StringUtils.GetWsAtOffset(targetVariantLexemeForm, 0);
					if (targetVariantLexemeForm.Equals(variantEntry.LexemeFormOA.Form.GetAlternativeTss(wsTargetVariant)))
					{
						// consider this a possible match. we'll use the last such possibility
						// if we can't find a matching variantEntryType (below.)
						matchingEntryRef = ler;
						// next see if we can also match against the type, we'll just 'use' that one.
						// otherwise keep going just in case we can find one that does match.
						if (variantEntryType != null && ler.VariantEntryTypesRS.Contains(variantEntryType))
							break;
					}
					// continue...
				}
			}
			return matchingEntryRef;
		}
예제 #11
0
		/// <summary>
		/// creates a variant entry from this (main) entry using its lexemeForm information,
		/// and links the variant to the given componentLexeme entry via
		/// EntryRefs.ComponentLexemes
		/// </summary>
		/// <param name="variantType">the type of the new variant</param>
		/// <param name="componentLexeme">the entry or sense of which the new variant entry is a variant</param>
		/// <param name="tssVariantLexemeForm">the lexeme form of the new variant</param>
		/// <returns>the new variant entry reference</returns>
		internal ILexEntryRef CreateVariantEntryAndBackRef(IVariantComponentLexeme componentLexeme, ILexEntryType variantType, ITsString tssVariantLexemeForm)
		{
			using (new UndoRedoTaskHelper(Cache, Strings.ksUndoCreateVariantEntry, Strings.ksRedoCreateVariantEntry))
			{
				ILexEntry variantEntry = new LexEntry();
				Cache.LangProject.LexDbOA.EntriesOC.Add(variantEntry);
				if (this.LexemeFormOA is IMoAffixAllomorph)
					variantEntry.LexemeFormOA = new MoAffixAllomorph();
				else
					variantEntry.LexemeFormOA = new MoStemAllomorph();
				if (this.LexemeFormOA != null)
					variantEntry.LexemeFormOA.MorphTypeRAHvo = this.LexemeFormOA.MorphTypeRAHvo;
				if (tssVariantLexemeForm != null)
					variantEntry.LexemeFormOA.FormMinusReservedMarkers = tssVariantLexemeForm;
				(variantEntry as LexEntry).UpdateHomographNumbersAccountingForNewEntry();
				return (variantEntry as LexEntry).MakeVariantOf(componentLexeme, variantType);
			}
		}
예제 #12
0
		/// <summary>
		/// Make this entry a variant of the given componentLexeme (primary entry) with
		/// the given variantType
		/// </summary>
		/// <param name="componentLexeme"></param>
		/// <param name="variantType"></param>
		public ILexEntryRef MakeVariantOf(IVariantComponentLexeme componentLexeme, ILexEntryType variantType)
		{
			ILexEntryRef ler = this.EntryRefsOS.Append(new LexEntryRef());
			ler.RefType = LexEntryRef.krtVariant; // variant by default, but good to be explicit here.
			ler.HideMinorEntry = 0;
			ler.ComponentLexemesRS.Append(componentLexeme);
			if (variantType != null)
				ler.VariantEntryTypesRS.Append(variantType);
			return ler;
		}
예제 #13
0
 /// <summary>
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="mediator"></param>
 /// <param name="componentLexeme">the entry we wish to find or create a variant for.</param>
 public void SetDlgInfo(FdoCache cache, Mediator mediator, IVariantComponentLexeme componentLexeme)
 {
     this.SetDlgInfoForComponentLexeme(cache, mediator, componentLexeme);
 }
예제 #14
0
        /// <summary>
        /// when calling the dialog from an "Insert Variant" context this
        /// constructor is used to indicate that m_startingEntry is a componentLexeme
        /// rather than the variant
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="mediator"></param>
        /// <param name="componentLexeme">the entry we wish to find or create a variant for.</param>
        protected void SetDlgInfoForComponentLexeme(FdoCache cache, Mediator mediator, IVariantComponentLexeme componentLexeme)
        {
            m_fBackRefToVariant = true;
            ILexEntry startingEntry = null;

            if (componentLexeme.ClassID == LexEntry.kclsidLexEntry)
            {
                startingEntry = componentLexeme as LexEntry;
            }
            else
            {
                int hvoEntry = cache.GetOwnerOfObjectOfClass(componentLexeme.Hvo, LexEntry.kclsidLexEntry);
                if (hvoEntry != 0)
                {
                    startingEntry = LexEntry.CreateFromDBObject(cache, hvoEntry);
                }
            }
            base.SetDlgInfo(cache, mediator, startingEntry);
            // we are looking for an existing variant form
            // so hide the Entry/Sense radio group box.
            grplbl.Visible = false;
            // also hide variant type.
            tcVariantTypes.Visible = false;
            lblVariantType.Visible = false;
            m_fGetVariantEntryTypeFromTreeCombo = false;
            lblCreateEntry.Visible = false;

            // The dialog title and other labels need to reflect "Insert Variant" context.
            m_formLabel.Text = LexTextControls.ks_Variant;
            this.Text        = LexTextControls.ksFindVariant;
            btnInsert.Text   = LexTextControls.ks_Create;
            // We disable the "Create" button when we don't have text in the Find textbox.
            UpdateButtonCreateNew();
        }
		/// <summary>
		/// extracts the variant and component from the dialog, depending upon whether we're
		/// called from an "Insert Variant" or "Variant Of..." context.
		/// </summary>
		/// <param name="variant">The variant.</param>
		/// <param name="componentLexeme">The component lexeme.</param>
		/// <param name="selectedEntryType">Type of the selected entry.</param>
		private void GetVariantAndComponentAndSelectedEntryType(out ILexEntry variant, out IVariantComponentLexeme componentLexeme, out ILexEntryType selectedEntryType)
		{
			if (m_fBackRefToVariant)
			{
				// in "Insert Variant" contexts,
				// we're calling the dialog from the component lexeme, so consider SelectedID as the variant.
				componentLexeme = m_startingEntry;
				variant = SelectedObject as ILexEntry;
			}
			else
			{
				// in "Variant of..." contexts,
				// we're calling the dialog from the variant, so consider SelectedID the componentLexeme.
				variant = m_startingEntry;
				componentLexeme = SelectedObject as IVariantComponentLexeme;
			}
			selectedEntryType = m_fGetVariantEntryTypeFromTreeCombo
				? m_cache.ServiceLocator.GetInstance<ILexEntryTypeRepository>().GetObject(SelectedVariantEntryTypeHvo) : null;
		}
예제 #16
0
 /// <summary>
 /// Use reflection to set the guid on a variant form. May not work for all kinds of tests or appropriately be editing the database.
 /// Because changing the Guid causes teardown problem, it must be reset prior to teardown (hence the Disposable <returns/>)
 /// </summary>
 internal static TempGuidOn <ILexEntryRef> CreateVariantForm(LcmCache cache, IVariantComponentLexeme main, ILexEntry variantForm, Guid guid,
                                                             string type = TestVariantName)
 {
     return(new TempGuidOn <ILexEntryRef>(CreateVariantForm(cache, main, variantForm, type), guid));
 }
예제 #17
0
        /// <summary>
        /// when calling the dialog from an "Insert Variant" context this
        /// constructor is used to indicate that m_startingEntry is a componentLexeme
        /// rather than the variant
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="mediator"></param>
        /// <param name="propertyTable"></param>
        /// <param name="componentLexeme">the entry we wish to find or create a variant for.</param>
        protected void SetDlgInfoForComponentLexeme(LcmCache cache, Mediator mediator, XCore.PropertyTable propertyTable, IVariantComponentLexeme componentLexeme)
        {
            m_fBackRefToVariant = true;
            ILexEntry startingEntry;

            if (componentLexeme.ClassID == LexEntryTags.kClassId)
            {
                startingEntry = componentLexeme as ILexEntry;
            }
            else
            {
                startingEntry = componentLexeme.Owner as ILexEntry;
            }
            SetDlgInfo(cache, mediator, propertyTable, startingEntry);
            // we are looking for an existing variant form
            // so hide the Entry/Sense radio group box.
            grplbl.Visible = false;
            // also hide variant type.
            tcVariantTypes.Visible = false;
            lblVariantType.Visible = false;
            m_fGetVariantEntryTypeFromTreeCombo = false;
            lblCreateEntry.Visible = false;

            // The dialog title and other labels need to reflect "Insert Variant" context.
            m_formLabel.Text = LexTextControls.ks_Variant;
            Text             = LexTextControls.ksFindVariant;
            m_btnInsert.Text = LexTextControls.ks_Create;
            // We disable the "Create" button when we don't have text in the Find textbox.
            UpdateButtonCreateNew();
        }
예제 #18
0
 /// <summary>
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="mediator"></param>
 /// <param name="propertyTable"></param>
 /// <param name="componentLexeme">the entry we wish to find or create a variant for.</param>
 public void SetDlgInfo(LcmCache cache, Mediator mediator, XCore.PropertyTable propertyTable, IVariantComponentLexeme componentLexeme)
 {
     SetDlgInfoForComponentLexeme(cache, mediator, propertyTable, componentLexeme);
 }
예제 #19
0
 /// <summary>
 /// extracts the variant and component from the dialog, depending upon whether we're
 /// called from an "Insert Variant" or "Variant Of..." context.
 /// </summary>
 /// <param name="variant">The variant.</param>
 /// <param name="componentLexeme">The component lexeme.</param>
 /// <param name="selectedEntryType">Type of the selected entry.</param>
 private void GetVariantAndComponentAndSelectedEntryType(out ILexEntry variant, out IVariantComponentLexeme componentLexeme, out ILexEntryType selectedEntryType)
 {
     if (m_fBackRefToVariant)
     {
         // in "Insert Variant" contexts,
         // we're calling the dialog from the component lexeme, so consider SelectedID as the variant.
         componentLexeme = m_startingEntry;
         variant         = SelectedObject as ILexEntry;
     }
     else
     {
         // in "Variant of..." contexts,
         // we're calling the dialog from the variant, so consider SelectedID the componentLexeme.
         variant         = m_startingEntry;
         componentLexeme = SelectedObject as IVariantComponentLexeme;
     }
     selectedEntryType = m_fGetVariantEntryTypeFromTreeCombo
                         ? m_cache.ServiceLocator.GetInstance <ILexEntryTypeRepository>().GetObject(SelectedVariantEntryTypeHvo) : null;
 }
예제 #20
0
 /// <summary>
 /// Use reflection to set the guid on a complex form. May not work for all kinds of tests or appropriately be editing the database.
 /// Because changing the Guid causes teardown problem, it must be reset prior to teardown (hence the Disposable <returns/>)
 /// </summary>
 internal static TempGuidOn <ILexEntryRef> CreateComplexForm(LcmCache cache, IVariantComponentLexeme main, ILexEntry complexForm, Guid guid,
                                                             bool subentry)
 {
     return(new TempGuidOn <ILexEntryRef>(CreateComplexForm(cache, main, complexForm, subentry), guid));
 }
예제 #21
0
 /// <summary>
 /// extracts the variant and component from the dialog, depending upon whether we're
 /// called from an "Insert Variant" or "Variant Of..." context.
 /// </summary>
 /// <param name="variant"></param>
 /// <param name="componentLexeme"></param>
 private void GetVariantAndComponentAndSelectedEntryType(out ILexEntry variant, out IVariantComponentLexeme componentLexeme, out ILexEntryType selectedEntryType)
 {
     variant         = null;
     componentLexeme = null;
     if (m_fBackRefToVariant)
     {
         // in "Insert Variant" contexts,
         // we're calling the dialog from the component lexeme, so consider SelectedID as the variant.
         componentLexeme = m_startingEntry;
         variant         = LexEntry.CreateFromDBObject(m_cache, SelectedID);
     }
     else
     {
         // in "Variant of..." contexts,
         // we're calling the dialog from the variant, so consider SelectedID the componentLexeme.
         variant         = m_startingEntry;
         componentLexeme = CmObject.CreateFromDBObject(m_cache, SelectedID) as IVariantComponentLexeme;
     }
     if (m_fGetVariantEntryTypeFromTreeCombo)
     {
         selectedEntryType = LexEntryType.CreateFromDBObject(m_cache, SelectedVariantEntryTypeHvo);
     }
     else
     {
         selectedEntryType = null;
     }
 }