/// <summary>
		/// Override method to handle launching of a chooser for selecting lexical entries.
		/// </summary>
		protected override void HandleChooser()
		{
			ILexRefType lrt = (ILexRefType)m_obj.Owner;
			LexRefTypeTags.MappingTypes type = (LexRefTypeTags.MappingTypes)lrt.MappingType;
			BaseGoDlg dlg = null;
			try
			{
				switch (type)
				{
					case LexRefTypeTags.MappingTypes.kmtSensePair:
					case LexRefTypeTags.MappingTypes.kmtSenseAsymmetricPair: // Sense pair with different Forward/Reverse names
						dlg = new LinkEntryOrSenseDlg();
						(dlg as LinkEntryOrSenseDlg).SelectSensesOnly = true;
						break;
					case LexRefTypeTags.MappingTypes.kmtEntryPair:
					case LexRefTypeTags.MappingTypes.kmtEntryAsymmetricPair: // Entry pair with different Forward/Reverse names
						dlg = new EntryGoDlg();
						break;
					case LexRefTypeTags.MappingTypes.kmtEntryOrSensePair:
					case LexRefTypeTags.MappingTypes.kmtEntryOrSenseAsymmetricPair: // Entry or sense pair with different Forward/Reverse
						dlg = new LinkEntryOrSenseDlg();
						(dlg as LinkEntryOrSenseDlg).SelectSensesOnly = false;
						break;
				}
				Debug.Assert(dlg != null);
				var wp = new WindowParams();
				//on creating Pair Lexical Relation have an Add button and Add in the title bar
				if (Target == null)
				{
					wp.m_title = String.Format(LexEdStrings.ksIdentifyXEntry, lrt.Name.BestAnalysisAlternative.Text);
					wp.m_btnText = LexEdStrings.ks_Add;
				}
				else //Otherwise we are Replacing the item
				{
					wp.m_title = String.Format(LexEdStrings.ksReplaceXEntry);
					wp.m_btnText = LexEdStrings.ks_Replace;
				}

				dlg.SetDlgInfo(m_cache, wp, m_mediator);
				dlg.SetHelpTopic("khtpChooseLexicalRelationAdd");
				if (dlg.ShowDialog(FindForm()) == DialogResult.OK)
				{
					if (dlg.SelectedObject != null)
					{
						AddItem(dlg.SelectedObject);
						// it is possible that the previous update has caused the data tree to refresh
						if (!IsDisposed)
							m_atomicRefView.RootBox.Reconstruct(); // view is somehow too complex for auto-update.
					}
				}
			}
			finally
			{
				if (dlg != null)
					dlg.Dispose();
			}
		}
        /// <summary>
        /// Handles the xCore message to go to or link to a lexical entry.
        /// </summary>
        /// <param name="argument">The xCore Command object.</param>
        /// <returns>true</returns>
        public bool OnGotoLexEntry(object argument)
        {
            CheckDisposed();

            using (var dlg = new EntryGoDlg())
            {
                var cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache");
                Debug.Assert(cache != null);
                dlg.SetDlgInfo(cache, null, m_mediator);
                dlg.SetHelpTopic("khtpFindLexicalEntry");
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    m_mediator.BroadcastMessageUntilHandled("JumpToRecord", dlg.SelectedObject.Hvo);
                }
            }
            return(true);
        }
		/// <summary>
		/// Override method to handle launching of a chooser for selecting lexical entries.
		/// </summary>
		protected override void HandleChooser()
		{
			var lrt = (ILexRefType)m_obj.Owner;
			var type = (LexRefTypeTags.MappingTypes)lrt.MappingType;
			BaseGoDlg dlg = null;
			string sTitle = string.Empty;
			try
			{
				switch (type)
				{
					case LexRefTypeTags.MappingTypes.kmtSenseCollection:
						dlg = new LinkEntryOrSenseDlg();
						(dlg as LinkEntryOrSenseDlg).SelectSensesOnly = true;
						sTitle = String.Format(LexEdStrings.ksIdentifyXSense,
							lrt.Name.BestAnalysisAlternative.Text);
						break;
					case LexRefTypeTags.MappingTypes.kmtEntryCollection:
						dlg = new EntryGoDlg();
						sTitle = String.Format(LexEdStrings.ksIdentifyXLexEntry,
							lrt.Name.BestAnalysisAlternative.Text);
						break;
					case LexRefTypeTags.MappingTypes.kmtEntryOrSenseCollection:
						dlg = new LinkEntryOrSenseDlg();
						sTitle = String.Format(LexEdStrings.ksIdentifyXLexEntryOrSense,
							lrt.Name.BestAnalysisAlternative.Text);
						break;
				}
				Debug.Assert(dlg != null);
				var wp = new WindowParams { m_title = sTitle, m_btnText = LexEdStrings.ks_Add };
				dlg.SetDlgInfo(m_cache, wp, m_mediator);
				dlg.SetHelpTopic("khtpChooseLexicalRelationAdd");
				if (dlg.ShowDialog(FindForm()) == DialogResult.OK && dlg.SelectedObject != null)
				{
					if (!((ILexReference)m_obj).TargetsRS.Contains(dlg.SelectedObject))
						AddItem(dlg.SelectedObject);
				}
			}
			finally
			{
				if (dlg != null)
					dlg.Dispose();
			}
		}
		/// <summary>
		/// Handles the xCore message to go to or link to a lexical entry.
		/// </summary>
		/// <param name="argument">The xCore Command object.</param>
		/// <returns>true</returns>
		public bool OnGotoLexEntry(object argument)
		{
			CheckDisposed();

			using (var dlg = new EntryGoDlg())
			{
				var cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache");
				Debug.Assert(cache != null);
				dlg.SetDlgInfo(cache, null, m_mediator);
				dlg.SetHelpTopic("khtpFindLexicalEntry");
				if (dlg.ShowDialog() == DialogResult.OK)
					m_mediator.BroadcastMessageUntilHandled("JumpToRecord", dlg.SelectedObject.Hvo);
			}
			return true;
		}
Exemple #5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Launch the Find Entry dialog, and if one is created or selected return it.
		/// </summary>
		/// <param name="cache">The cache.</param>
		/// <param name="mediator">The mediator.</param>
		/// <param name="tssForm">The TSS form.</param>
		/// <param name="owner">The owner.</param>
		/// <returns>The HVO of the selected or created entry</returns>
		/// ------------------------------------------------------------------------------------
		internal static ILexEntry ShowFindEntryDialog(FdoCache cache, Mediator mediator,
			ITsString tssForm, IWin32Window owner)
		{
			// Ensure that we have a valid mediator with the proper string table.
			bool fRestore = false;
			StringTable stOrig = null;
			mediator = EnsureValidMediator(mediator, out fRestore, out stOrig);
			try
			{
				using (EntryGoDlg entryGoDlg = new EntryGoDlg())
				{
					// Temporarily set TopMost to true so it will launch above any calling app (e.g. Paratext)
					// but reset after activated.
					SetCurrentModalForm(entryGoDlg);
					var wp = new WindowParams
								 {
									 m_btnText = FdoUiStrings.ksShow,
									 m_title = FdoUiStrings.ksFindInDictionary,
									 m_label = FdoUiStrings.ksFind_
								 };
					if (owner == null)
						entryGoDlg.StartPosition = FormStartPosition.CenterScreen;
					entryGoDlg.Owner = owner as Form;
					entryGoDlg.SetDlgInfo(cache, wp, mediator, tssForm);
					entryGoDlg.SetHelpTopic("khtpFindInDictionary");
					if (entryGoDlg.ShowDialog() == DialogResult.OK)
					{
						var entry = entryGoDlg.SelectedObject as ILexEntry;
						Debug.Assert(entry != null);
						return entry;
					}
				}
			}
			finally
			{
				// Restore the original string table in the mediator if needed.
				if (fRestore)
					mediator.StringTbl = stOrig;
			}
			return null;
		}
		/// <summary>
		/// Override method to handle launching of a chooser for selecting lexical entries.
		/// </summary>
		protected override void HandleChooser()
		{
			ILexRefType lrt = (ILexRefType)m_obj.Owner;
			int type = lrt.MappingType;
			BaseGoDlg dlg = null;
			try
			{
				switch ((LexRefTypeTags.MappingTypes)type)
				{
					case LexRefTypeTags.MappingTypes.kmtSenseTree:
						dlg = new LinkEntryOrSenseDlg();
						(dlg as LinkEntryOrSenseDlg).SelectSensesOnly = true;
						break;
					case LexRefTypeTags.MappingTypes.kmtEntryTree:
						dlg = new EntryGoDlg();
						break;
					case LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree:
						dlg = new LinkEntryOrSenseDlg();
						break;
				}
				Debug.Assert(dlg != null);
				var wp = new WindowParams { m_title = String.Format(LexEdStrings.ksReplaceXEntry), m_btnText = LexEdStrings.ks_Replace };
				//This method is only called when we are Replacing the
				//tree root of a Whole/Part lexical relation
				dlg.SetDlgInfo(m_cache, wp, m_mediator);
				dlg.SetHelpTopic("khtpChooseLexicalRelationAdd");
				if (dlg.ShowDialog(FindForm()) == DialogResult.OK)
				{
					if (dlg.SelectedObject != null)
						AddItem(dlg.SelectedObject);
				}
			}
			finally
			{
				if (dlg != null)
					dlg.Dispose();
			}
		}
		/// <summary>
		/// This method is called when we are creating a new lexical relation slice.
		/// If the user selects an item it's hvo is returned.
		/// Otherwise 0 is returned and the lexical relation should not be created.
		/// </summary>
		/// <param name="lrt"></param>
		/// <returns></returns>
		private ICmObject GetChildObject(ILexRefType lrt)
		{
			ICmObject first = null;
			EntryGoDlg dlg = null;
			string sTitle = string.Empty;
			try
			{
				switch ((LexRefTypeTags.MappingTypes)lrt.MappingType)
				{
					case LexRefTypeTags.MappingTypes.kmtEntryOrSensePair:
					case LexRefTypeTags.MappingTypes.kmtEntryOrSenseAsymmetricPair:
						// Entry or sense pair with different Forward/Reverse
						dlg = new LinkEntryOrSenseDlg();
						(dlg as LinkEntryOrSenseDlg).SelectSensesOnly = false;
						sTitle = String.Format(LexEdStrings.ksIdentifyXLexEntryOrSense, lrt.Name.BestAnalysisAlternative.Text);
						break;

					case LexRefTypeTags.MappingTypes.kmtSenseCollection:
					case LexRefTypeTags.MappingTypes.kmtSensePair:
					case LexRefTypeTags.MappingTypes.kmtSenseAsymmetricPair:
					// Sense pair with different Forward/Reverse names
					case LexRefTypeTags.MappingTypes.kmtSenseSequence:
					case LexRefTypeTags.MappingTypes.kmtSenseTree:
						dlg = new LinkEntryOrSenseDlg();
						(dlg as LinkEntryOrSenseDlg).SelectSensesOnly = true;
						sTitle = String.Format(LexEdStrings.ksIdentifyXSense, lrt.Name.BestAnalysisAlternative.Text);
						break;

					case LexRefTypeTags.MappingTypes.kmtEntryCollection:
					case LexRefTypeTags.MappingTypes.kmtEntryPair:
					case LexRefTypeTags.MappingTypes.kmtEntryAsymmetricPair:
					// Entry pair with different Forward/Reverse names
					case LexRefTypeTags.MappingTypes.kmtEntrySequence:
					case LexRefTypeTags.MappingTypes.kmtEntryTree:
						dlg = new EntryGoDlg();
						sTitle = String.Format(LexEdStrings.ksIdentifyXLexEntry, lrt.Name.BestAnalysisAlternative.Text);
						break;

					case LexRefTypeTags.MappingTypes.kmtEntryOrSenseCollection:
					case LexRefTypeTags.MappingTypes.kmtEntryOrSenseSequence:
					case LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree:
						dlg = new LinkEntryOrSenseDlg();
						sTitle = String.Format(LexEdStrings.ksIdentifyXLexEntryOrSense, lrt.Name.BestAnalysisAlternative.Text);
						break;
					default:
						Debug.Assert(lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtSenseAsymmetricPair || lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtSenseTree);
						return null;
				}
				Debug.Assert(dlg != null);
				var wp = new WindowParams { m_title = sTitle, m_btnText = LexEdStrings.ks_Add };

				// Don't display the current entry in the list of matching entries.  See LT-2611.
				ICmObject objEntry = this.Object;
				while (objEntry.ClassID == LexSenseTags.kClassId)
					objEntry = objEntry.Owner;
				Debug.Assert(objEntry.ClassID == LexEntryTags.kClassId);
				dlg.StartingEntry = objEntry as ILexEntry;

				dlg.SetDlgInfo(m_cache, wp, Mediator);
				dlg.SetHelpTopic("khtpChooseLexicalRelationAdd");
				if (dlg.ShowDialog(FindForm()) == DialogResult.OK)
					first = dlg.SelectedObject;
				return first;
			}
			finally
			{
				if (dlg != null)
					dlg.Dispose();
			}
		}
		/// <summary>
		/// This method is called when we are creating a new lexical relation slice.
		/// If the user selects an item it's hvo is returned.
		/// Otherwise 0 is returned and the lexical relation should not be created.
		/// </summary>
		/// <param name="lrt"></param>
		/// <returns></returns>
		private ICmObject GetRootObject(ILexRefType lrt)
		{
			ICmObject first = null;
			EntryGoDlg dlg = null;
			try
			{
				switch ((LexRefTypeTags.MappingTypes)lrt.MappingType)
				{
					case LexRefTypeTags.MappingTypes.kmtSenseAsymmetricPair:
					case LexRefTypeTags.MappingTypes.kmtSenseTree:
						dlg = new LinkEntryOrSenseDlg();
						(dlg as LinkEntryOrSenseDlg).SelectSensesOnly = true;
						break;
					case LexRefTypeTags.MappingTypes.kmtEntryAsymmetricPair:
					case LexRefTypeTags.MappingTypes.kmtEntryTree:
						dlg = new EntryGoDlg();
						break;
					case LexRefTypeTags.MappingTypes.kmtEntryOrSenseAsymmetricPair:
					case LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree:
						dlg = new LinkEntryOrSenseDlg();
						break;
					default:
						Debug.Assert(lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtSenseAsymmetricPair || lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtSenseTree);
						return null;
				}
				Debug.Assert(dlg != null);
				var wp = new WindowParams { m_title = String.Format(LexEdStrings.ksIdentifyXEntry, lrt.ReverseName.BestAnalysisAlternative.Text), m_btnText = LexEdStrings.ks_Add };
				dlg.SetDlgInfo(m_cache, wp, Mediator);
				dlg.SetHelpTopic("khtpChooseLexicalRelationAdd");
				if (dlg.ShowDialog(FindForm()) == DialogResult.OK)
					first = dlg.SelectedObject;
				return first;
			}
			finally
			{
				if (dlg != null)
					dlg.Dispose();
			}
		}
		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, 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_mediator.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);
					chooser.AddLink(LexEdStrings.ksAddAComponent, ReallySimpleListChooser.LinkType.kDialogLink,
						new AddPrimaryLexemeChooserCommand(m_cache, false, null, m_mediator, 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);
							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((ILexEntry) 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;
				}
			}
		}
		public override ObjectLabel Execute()
		{
			ObjectLabel result = null;
			if (m_lexEntry != null)
			{
				using (var dlg = new EntryGoDlg())
				{
					dlg.SetDlgInfo(m_cache, null, m_mediator);
					dlg.SetHelpTopic("khtpChooseLexicalEntryOrSense"); // TODO: When LT-11318 is fixed, use its help topic ID.
					dlg.SetOkButtonText(LexEdStrings.ksMakeComponentOf);
					if (dlg.ShowDialog(m_parentWindow) == DialogResult.OK)
					{
						try
						{
							if (m_lexSense != null)
							{
								UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoAddComplexForm, LexEdStrings.ksRedoAddComplexForm,
								m_lexEntry.Cache.ActionHandlerAccessor,
								() => ((ILexEntry)dlg.SelectedObject).AddComponent((ICmObject)m_lexSense ?? m_lexEntry));
							}
							else
							{
								UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoAddComplexForm, LexEdStrings.ksRedoAddComplexForm,
								m_lexEntry.Cache.ActionHandlerAccessor,
								() => ((ILexEntry)dlg.SelectedObject).AddComponent(m_lexEntry));
							}
						}
						catch (ArgumentException)
						{
							MessageBoxes.ReportLexEntryCircularReference((ILexEntry)dlg.SelectedObject, m_lexEntry, false);
						}
					}
				}
			}
			return result;
		}