From 34cde00c366c85f665a25eee5a5a872b2809509f Mon Sep 17 00:00:00 2001
From: Jake Oliver <jeoliver97@gmail.com>
Date: Thu, 27 Jun 2024 17:49:05 -0400
Subject: [PATCH] Properly handle hyperlink to another project

---
 Src/xWorks/LinkListener.cs | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/Src/xWorks/LinkListener.cs b/Src/xWorks/LinkListener.cs
index d8dd723e4d..686b7423b7 100644
--- a/Src/xWorks/LinkListener.cs
+++ b/Src/xWorks/LinkListener.cs
@@ -438,13 +438,13 @@ private bool FollowActiveLink(bool suspendLoadingRecord)
 		{
 			try
 			{
+				var cache = m_propertyTable.GetValue<LcmCache>("cache");
 				//Debug.Assert(!(m_lnkActive is FwAppArgs), "Beware: This will not handle link requests for other databases/applications." +
 				//	" To handle other databases or applications, pass the FwAppArgs to the IFieldWorksManager.HandleLinkRequest method.");
 				if (m_lnkActive.ToolName == "default")
 				{
 					// Need some smarts here. The link creator was not sure what tool to use.
 					// The object may also be a child we don't know how to jump to directly.
-					var cache = m_propertyTable.GetValue<LcmCache>("cache");
 					ICmObject target;
 					if (!cache.ServiceLocator.ObjectRepository.TryGetObject(m_lnkActive.TargetGuid, out target))
 						return false; // or message?
@@ -500,6 +500,12 @@ private bool FollowActiveLink(bool suspendLoadingRecord)
 					m_lnkActive = new FwLinkArgs(realTool, realTarget.Guid);
 					// Todo JohnT: need to do something special here if we c
 				}
+				// Return false if the link is to a different database
+				var databases = m_lnkActive.PropertyTableEntries.Where(p => p.name == "database");
+				if (databases.Any() && databases.First().name != cache.LangProject.ShortName)
+				{
+					return false;
+				}
 				// It's important to do this AFTER we set the real tool name if it is "default". Otherwise, the code that
 				// handles the jump never realizes we have reached the desired tool (as indicated by the value of
 				// SuspendLoadingRecordUntilOnJumpToRecord) and we stop recording context history and various similar problems.
@@ -518,10 +524,8 @@ private bool FollowActiveLink(bool suspendLoadingRecord)
 				// or more likely, when the HVO was set to -1.
 				if (m_lnkActive.TargetGuid != Guid.Empty)
 				{
-					LcmCache cache = m_propertyTable.GetValue<LcmCache>("cache");
 					ICmObject obj = cache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(m_lnkActive.TargetGuid);
-					if (obj is IReversalIndexEntry && m_lnkActive.ToolName == "reversalToolEditComplete" ||
-						(m_lnkActive?.PropertyTableEntries.Where(p => p.name.Equals("database")).Any() ?? false))
+					if (obj is IReversalIndexEntry && m_lnkActive.ToolName == "reversalToolEditComplete")
 					{
 						// For the reversal index tool, just getting the tool right isn't enough.  We
 						// also need to be showing the proper index.  (See FWR-1105.)