private void OnSelectVariantOf(object sender, EventArgs args)
			{
				try
				{
					using (LinkVariantToEntryOrSense dlg = new LinkVariantToEntryOrSense())
					{
						ILexEntry variantEntry = null;
						// if no previous variant relationship has been defined,
						// then don't try to fill initial information,
						ITsString tssForm;
						ITsString tssFullForm;
						IMoMorphType morphType;
						IMoForm morphReal;
						GetMorphInfo(out tssForm, out tssFullForm, out morphReal, out morphType);
						if (morphReal != null && morphReal.IsValidObject)
						{
							variantEntry = morphReal.Owner as ILexEntry;
							dlg.SetDlgInfo(m_sandbox.Cache, m_sandbox.Mediator, variantEntry);
						}
						else
						{
							// since we didn't start with an entry,
							// set up the dialog using the form of the variant
							dlg.SetDlgInfo(m_sandbox.Cache, m_sandbox.Mediator, tssForm);
						}
						dlg.SetHelpTopic("khtpAddVariantFromInterlinear");
						Form mainWnd = m_sandbox.FindForm();
						// Making the form active fixes problems like LT-2619.
						// I'm (RandyR) not sure what adverse impact might show up by doing this.
						mainWnd.Activate();
						if (dlg.ShowDialog(mainWnd) == DialogResult.OK)
						{
							if (dlg.SelectedObject == null)
								return; // odd. nothing more to do.

							ILexEntryRef variantEntryRef = dlg.VariantEntryRefResult;
							// if we didn't have a starting entry, create one now.
							ILexEntry variantResult = variantEntryRef.Owner as ILexEntry;
							int classOfSelectedId = dlg.SelectedObject.ClassID;
							int hvoVariantType = dlg.SelectedVariantEntryTypeHvo;
							ILexEntryInflType inflType = null;
							m_caches.MainCache.ServiceLocator.GetInstance<ILexEntryInflTypeRepository>().
									TryGetObject(hvoVariantType, out inflType);

							// we need to create a new LexEntryRef.
							ILexEntry morphBundleEntry = dlg.SelectedObject as ILexEntry;
							ILexSense morphBundleSense = dlg.SelectedObject as ILexSense;
							if (morphBundleSense != null)
								morphBundleEntry = morphBundleSense.OwnerOfClass(LexEntryTags.kClassId) as ILexEntry;
							UpdateMorphEntry(variantResult.LexemeFormOA, morphBundleEntry, morphBundleSense, inflType);
						}
					}

				}
				catch (Exception exc)
				{
					MessageBox.Show(exc.Message, ITextStrings.ksCannotAddVariant);
				}
			}
Exemplo n.º 2
0
			private void OnSelectVariantOf(object sender, EventArgs args)
			{
				try
				{
					using (LinkVariantToEntryOrSense dlg = new LinkVariantToEntryOrSense())
					{
						ILexEntry variantEntry = null;
						// if no previous variant relationship has been defined,
						// then don't try to fill initial information,
						ITsString tssForm;
						ITsString tssFullForm;
						int hvoType;
						int hvoMorphReal;
						GetMorphInfo(out tssForm, out tssFullForm, out hvoMorphReal, out hvoType);
						if (m_caches.MainCache.IsValidObject(hvoMorphReal))
						{
							IMoForm mf = MoForm.CreateFromDBObject(m_sandbox.Cache, hvoMorphReal);
							variantEntry = (mf as CmObject).Owner as ILexEntry;
							dlg.SetDlgInfo(m_sandbox.Cache, m_sandbox.Mediator, variantEntry);
						}
						else
						{
							// since we didn't start with an entry,
							// set up the dialog using the form of the variant
							dlg.SetDlgInfo(m_sandbox.Cache, m_sandbox.Mediator, tssForm);
						}
						dlg.SetHelpTopic("khtpAddVariantFromInterlinear");
						Form mainWnd = m_sandbox.FindForm();
						// Making the form active fixes problems like LT-2619.
						// I'm (RandyR) not sure what adverse impact might show up by doing this.
						mainWnd.Activate();
						if (dlg.ShowDialog(mainWnd) == DialogResult.OK)
						{
							if (dlg.SelectedID == 0)
								return; // odd. nothing more to do.

							ILexEntryRef variantEntryRef = dlg.VariantEntryRefResult;
							// if we didn't have a starting entry, create one now.
							ILexEntry variantResult = (variantEntryRef as CmObject).Owner as ILexEntry;
							int classOfSelectedId = m_sandbox.Cache.GetClassOfObject(dlg.SelectedID);
							// we need to create a new LexEntryRef.
							int morphBundleEntryHvo = 0;
							int morphBundleSenseHvo = 0;
							if (classOfSelectedId == LexEntry.kclsidLexEntry)
							{
								morphBundleEntryHvo = dlg.SelectedID;
								morphBundleSenseHvo = 0; // establish default sense.
							}
							else if (classOfSelectedId == LexSense.kclsidLexSense)
							{
								morphBundleSenseHvo = dlg.SelectedID;
								morphBundleEntryHvo = m_sandbox.Cache.GetOwnerOfObjectOfClass(morphBundleSenseHvo, LexEntry.kclsidLexEntry);
							}
							UpdateMorphEntry(variantResult.LexemeFormOAHvo, morphBundleEntryHvo, morphBundleSenseHvo);
						}
					}

				}
				catch (Exception exc)
				{
					MessageBox.Show(exc.Message, ITextStrings.ksCannotAddVariant);
				}
			}