diff --git a/FRBDK/Glue/Glue/Elements/ObjectFinder.cs b/FRBDK/Glue/Glue/Elements/ObjectFinder.cs index ad4ddf85d..d23ed8936 100644 --- a/FRBDK/Glue/Glue/Elements/ObjectFinder.cs +++ b/FRBDK/Glue/Glue/Elements/ObjectFinder.cs @@ -12,6 +12,7 @@ using FlatRedBall.Glue.GuiDisplay.Facades; using FlatRedBall.Glue.Plugins.ExportedImplementations; using FlatRedBall.Content.Instructions; +using System.Windows.Navigation; namespace FlatRedBall.Glue.Elements; @@ -998,8 +999,20 @@ public NamedObjectSave GetDefaultListToContain(NamedObjectSave namedObject, Glue } + public List GetPossibleListsToContain(NamedObjectSave namedObject, GlueElement containerElement) + { + var namedObjectSourceClassType = namedObject.SourceClassType; + return GetPossibleListsToContain(namedObjectSourceClassType, containerElement); + } + public NamedObjectSave GetDefaultListToContain(string namedObjectSourceClassType, GlueElement containerElement) { + return GetPossibleListsToContain(namedObjectSourceClassType, containerElement).FirstOrDefault(); + } + + public List GetPossibleListsToContain(string namedObjectSourceClassType, GlueElement containerElement) + { + List possibleContainers = new List(); var isNosShape = namedObjectSourceClassType == "FlatRedBall.Math.Geometry.Circle" || namedObjectSourceClassType == "FlatRedBall.Math.Geometry.AxisAlignedRectangle" || namedObjectSourceClassType == "FlatRedBall.Math.Geometry.Polygon"; @@ -1009,18 +1022,30 @@ public NamedObjectSave GetDefaultListToContain(string namedObjectSourceClassType if (isNosShape) { - return containerElement.NamedObjects.FirstOrDefault(item => item.GetAssetTypeInfo() == AvailableAssetTypes.CommonAtis.ShapeCollection); + possibleContainers.AddRange(containerElement.NamedObjects.Where(item => item.GetAssetTypeInfo() == AvailableAssetTypes.CommonAtis.ShapeCollection)); + } + + if (nosEntity != null) + { + possibleContainers.AddRange(GetPossibleListsToContain(nosEntity, containerElement)); } - else if (nosEntity != null) + else { - return GetDefaultListToContain(nosEntity, containerElement); + possibleContainers.AddRange(containerElement.NamedObjects.Where(item => item.IsList && item.SourceClassGenericType == namedObjectSourceClassType)); } - return null; + return possibleContainers; } public NamedObjectSave GetDefaultListToContain(EntitySave nosEntity, GlueElement containerElement) { + return GetPossibleListsToContain(nosEntity, containerElement).FirstOrDefault(); + } + + public List GetPossibleListsToContain(EntitySave nosEntity, GlueElement containerElement) + { + var toReturn = new List(); + var baseEntityTypes = GetAllBaseElementsRecursively(nosEntity); // Do the top-level NamedObjects instead of AllNamedObjects @@ -1034,12 +1059,12 @@ public NamedObjectSave GetDefaultListToContain(EntitySave nosEntity, GlueElement { if (listEntityType == nosEntity || baseEntityTypes.Contains(listEntityType)) { - return listCandidate; + toReturn.Add(listCandidate); } } } } - return null; + return toReturn; } public NamedObjectSave GetRootDefiningObject(NamedObjectSave derivedNos) diff --git a/FRBDK/Glue/Glue/Managers/CopyPasteManager.cs b/FRBDK/Glue/Glue/Managers/CopyPasteManager.cs index f7d277ca8..a1283a2a1 100644 --- a/FRBDK/Glue/Glue/Managers/CopyPasteManager.cs +++ b/FRBDK/Glue/Glue/Managers/CopyPasteManager.cs @@ -65,7 +65,10 @@ internal async Task HandlePaste() } else if(copiedObjectClone is NamedObjectSave asNos) { - var response = await GlueCommands.Self.GluxCommands.CopyNamedObjectIntoElement(asNos, GlueState.Self.CurrentElement); + var response = await GlueCommands.Self.GluxCommands.CopyNamedObjectIntoElement(asNos, GlueState.Self.CurrentElement, + // pass the current nos so that we can attempt to add it to the current list + // This could be the list itself, or a child of the list - either is fine + GlueState.Self.CurrentNamedObjectSave); if(response.Succeeded == false) { GlueCommands.Self.PrintError(response.Message); diff --git a/FRBDK/Glue/Glue/Plugins/ExportedImplementations/CommandInterfaces/GluxCommands.cs b/FRBDK/Glue/Glue/Plugins/ExportedImplementations/CommandInterfaces/GluxCommands.cs index fc64f9ba8..c0a99f03d 100644 --- a/FRBDK/Glue/Glue/Plugins/ExportedImplementations/CommandInterfaces/GluxCommands.cs +++ b/FRBDK/Glue/Glue/Plugins/ExportedImplementations/CommandInterfaces/GluxCommands.cs @@ -1823,7 +1823,7 @@ await TaskManager.Self.AddAsync(() => var toReturn = new List>(); foreach (var originalNos in nosList) { - var response = await CopyNamedObjectIntoElementInner(originalNos, targetElement, performSaveAndGenerateCode:false, updateUi: false, notifyPlugins: false); + var response = await CopyNamedObjectIntoElementInner(originalNos, targetElement, targetNos:null, performSaveAndGenerateCode:false, updateUi: false, notifyPlugins: false); toReturn.Add(response); } @@ -1893,7 +1893,7 @@ await TaskManager.Self.AddAsync(() => } - public async Task> CopyNamedObjectIntoElementInner(NamedObjectSave originalNos, GlueElement targetElement, NamedObjectSave targetNos = null, bool performSaveAndGenerateCode, bool updateUi, + private async Task> CopyNamedObjectIntoElementInner(NamedObjectSave originalNos, GlueElement targetElement, NamedObjectSave targetNos, bool performSaveAndGenerateCode, bool updateUi, bool notifyPlugins) { bool succeeded = true; @@ -1921,11 +1921,25 @@ await TaskManager.Self.AddAsync(() => - NamedObjectSave listOfThisType = null; - // if the current object is a list, or if the current object is in a list that matches this type, then use that + var possibleLists = ObjectFinder.Self.GetPossibleListsToContain(newNos, targetElement); + NamedObjectSave listOfThisType = null; + if(targetNos != null) + { + // is it a list? + var targetList = targetNos.IsList ? targetNos : + targetElement.NamedObjects.FirstOrDefault(item => item.ContainedObjects?.Contains(targetNos) == true); + + if(targetList != null && possibleLists.Contains(targetList)) + { + listOfThisType = targetList; + } + } - listOfThisType = ObjectFinder.Self.GetDefaultListToContain(newNos, targetElement); + if(listOfThisType == null) + { + listOfThisType = ObjectFinder.Self.GetDefaultListToContain(newNos, targetElement); + } if (listOfThisType != null) {