<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using FlatRedBall.IO;

using FlatRedBall.Glue.Elements;
using FlatRedBall.Glue.Controls;


namespace FlatRedBall.Glue.SaveClasses
{


    public static class NamedObjectContainerHelper
    {

        public static bool DoesMemberNeedToBeSetByContainer(this IElement namedObjectContainer, string memberName)
        {
            foreach (NamedObjectSave namedObject in namedObjectContainer.NamedObjects)
            {
                if (namedObject.InstanceName == memberName && namedObject.SetByContainer)
                {
                    return namedObject.SetByContainer;
                }
            }

            if ( namedObjectContainer.InheritsFromElement())
            {
                EntitySave baseEntity = ObjectFinder.Self.GetEntitySave(namedObjectContainer.BaseObject);

                return baseEntity.DoesMemberNeedToBeSetByContainer(memberName);
            }


            return false;
        }

        public static bool ReactToRenamedReferencedFile(this INamedObjectContainer namedObjectContainer, string oldName, string newName)
        {
            bool toReturn = false;

            for (int i = 0; i < namedObjectContainer.NamedObjects.Count; i++)
            {
                NamedObjectSave namedObject = namedObjectContainer.NamedObjects[i];

                if (namedObject.SourceFile == oldName)
                {
                    toReturn = true;
                    namedObject.SourceFile = newName;
                }
            }
            
            return toReturn;
        }

        public static List<NamedObjectSave> GetNamedObjectsToBeExposedInDerived(this INamedObjectContainer namedObjectContainer)
        {
            List<NamedObjectSave> namedObjectsToBeExposedInDerived = new List<NamedObjectSave>();

            if (!string.IsNullOrEmpty(namedObjectContainer.BaseObject) && namedObjectContainer.BaseObject != "<NONE>")
            {
                //If this is a Screen
                if ((namedObjectContainer as EntitySave) == null)
                {
                    namedObjectsToBeExposedInDerived.AddRange(
                        ObjectFinder.Self.GetScreenSave(namedObjectContainer.BaseObject).GetNamedObjectsToBeExposedInDerived());
                }
                //Otherwise it's an Entity
                else
                {
                    EntitySave baseEntitySave = ObjectFinder.Self.GetEntitySave(namedObjectContainer.BaseObject);

                    if (baseEntitySave == null)
                    {
                        bool inheritsFromFrbType = 
                            namedObjectContainer is EntitySave && (namedObjectContainer as EntitySave).InheritsFromFrbType();

                        if (!inheritsFromFrbType)
                        {
                            System.Windows.Forms.MessageBox.Show("The Element\n\n" + namedObjectContainer.ToString() + "\n\nhas a base type\n\n" + namedObjectContainer.BaseObject +
                                "\n\nbut this base type can't be found.  " +
                                "It was probably removed from the project.  You will need to set the base object to NONE.");
                        }
                    }
                    else
                    {
                        namedObjectsToBeExposedInDerived.AddRange(
                            baseEntitySave.GetNamedObjectsToBeExposedInDerived());
                    }
                }
            }

            foreach (NamedObjectSave nos in namedObjectContainer.NamedObjects)
            {
                if (nos.ExposedInDerived)
                {
                    bool isAlreadyThere = false;

                    for (int i = namedObjectsToBeExposedInDerived.Count - 1; i > -1; i--)
                    {
                        if (namedObjectsToBeExposedInDerived[i].InstanceName == nos.InstanceName)
                        {<commit_msg>Fixed bug where ExposedInDerived objects in lists would be asked to be removed when changing other ExposedInDerived objects in the base screen.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using FlatRedBall.IO;

using FlatRedBall.Glue.Elements;
using FlatRedBall.Glue.Controls;


namespace FlatRedBall.Glue.SaveClasses
{


    public static class NamedObjectContainerHelper
    {

        public static bool DoesMemberNeedToBeSetByContainer(this IElement namedObjectContainer, string memberName)
        {
            foreach (NamedObjectSave namedObject in namedObjectContainer.NamedObjects)
            {
                if (namedObject.InstanceName == memberName && namedObject.SetByContainer)
                {
                    return namedObject.SetByContainer;
                }
            }

            if ( namedObjectContainer.InheritsFromElement())
            {
                EntitySave baseEntity = ObjectFinder.Self.GetEntitySave(namedObjectContainer.BaseObject);

                return baseEntity.DoesMemberNeedToBeSetByContainer(memberName);
            }


            return false;
        }

        public static bool ReactToRenamedReferencedFile(this INamedObjectContainer namedObjectContainer, string oldName, string newName)
        {
            bool toReturn = false;

            for (int i = 0; i < namedObjectContainer.NamedObjects.Count; i++)
            {
                NamedObjectSave namedObject = namedObjectContainer.NamedObjects[i];

                if (namedObject.SourceFile == oldName)
                {
                    toReturn = true;
                    namedObject.SourceFile = newName;
                }
            }
            
            return toReturn;
        }

        public static List<NamedObjectSave> GetNamedObjectsToBeExposedInDerived(this INamedObjectContainer namedObjectContainer)
        {
            List<NamedObjectSave> namedObjectsToBeExposedInDerived = new List<NamedObjectSave>();

            if (!string.IsNullOrEmpty(namedObjectContainer.BaseObject) && namedObjectContainer.BaseObject != "<NONE>")
            {
                //If this is a Screen
                if ((namedObjectContainer as EntitySave) == null)
                {
                    namedObjectsToBeExposedInDerived.AddRange(
                        ObjectFinder.Self.GetScreenSave(namedObjectContainer.BaseObject).GetNamedObjectsToBeExposedInDerived());
                }
                //Otherwise it's an Entity
                else
                {
                    EntitySave baseEntitySave = ObjectFinder.Self.GetEntitySave(namedObjectContainer.BaseObject);

                    if (baseEntitySave == null)
                    {
                        bool inheritsFromFrbType = 
                            namedObjectContainer is EntitySave && (namedObjectContainer as EntitySave).InheritsFromFrbType();

                        if (!inheritsFromFrbType)
                        {
                            System.Windows.Forms.MessageBox.Show("The Element\n\n" + namedObjectContainer.ToString() + "\n\nhas a base type\n\n" + namedObjectContainer.BaseObject +
                                "\n\nbut this base type can't be found.  " +
                                "It was probably removed from the project.  You will need to set the base object to NONE.");
                        }
                    }
                    else
                    {
                        namedObjectsToBeExposedInDerived.AddRange(
                            baseEntitySave.GetNamedObjectsToBeExposedInDerived());
                    }
                }
            }

            foreach (NamedObjectSave nos in namedObjectContainer.AllNamedObjects)
            {
                if (nos.ExposedInDerived)
                {
                    bool isAlreadyThere = false;

                    for (int i = namedObjectsToBeExposedInDerived.Count - 1; i > -1; i--)
                    {
                        if (namedObjectsToBeExposedInDerived[i].InstanceName == nos.InstanceName)
                        {
{'fraction_non_alphanumeric': 0.06534750213753511, 'fraction_numerical': 0.0007328691828508611, 'mean_word_length': 1.5952456418383518, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5995348', 'n_tokens_mistral': 1987, 'n_tokens_neox': 1824, 'n_words': 391}