public void ReactToChange(string changedMember, object oldValue, EventResponseSave ers, IElement container)
 {
     if (changedMember == "EventName")
     {
         ReactToEventRename(oldValue, ers, container);
     }
 }
        /// <summary>
        /// Gets associated EventSave that comes from BuiltInEvents.csv.  This may be null
        /// if the EventResponseSave is an event responding to a changed variable.
        /// </summary>
        public static EventSave GetEventSave(this EventResponseSave instance)
        {
            EventSave toReturn = null;

            string key = "";

            if (!string.IsNullOrEmpty(instance.SourceObject) && !string.IsNullOrEmpty(instance.SourceObjectEvent))
            {
                key = instance.SourceObjectEvent;

                IElement container = ObjectFinder.Self.GetElementContaining(instance);

                if (container != null)
                {
                    NamedObjectSave nos = container.GetNamedObjectRecursively(instance.SourceObject);
#if GLUE
                    string type;
                    string args;

                    FlatRedBall.Glue.Plugins.PluginManager.GetEventSignatureArgs(nos, instance, out type, out args);
                    if (type != null)
                    {
                        toReturn              = new EventSave();
                        toReturn.Arguments    = args;
                        toReturn.DelegateType = type;
                    }
#endif
                    if (toReturn == null && nos != null && nos.SourceType == SourceType.Entity)
                    {
                        // This may be a tunnel into a tunneled event
                        FlatRedBall.Glue.SaveClasses.IElement element = ObjectFinder.Self.GetIElement(nos.SourceClassType);

                        if (element != null)
                        {
                            foreach (EventResponseSave ers in element.Events)
                            {
                                if (ers.EventName == instance.SourceObjectEvent)
                                {
                                    toReturn = ers.GetEventSave();
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                key = instance.EventName;
            }

            if (toReturn == null && EventManager.AllEvents.ContainsKey(key))
            {
                toReturn = EventManager.AllEvents[key];
            }

            return(toReturn);
        }
 public static IElement GetContainer(this EventResponseSave instance)
 {
     if (ObjectFinder.Self.GlueProject != null)
     {
         return(ObjectFinder.Self.GetElementContaining(instance));
     }
     else
     {
         return(null);
     }
 }
Exemple #4
0
        public static string GetSharedCodeFullFileName(this EventResponseSave instance)
        {
            var container = instance.GetContainer();

            if (container != null)
            {
                return(FileManager.GetDirectory(ProjectManager.GlueProjectFileName) + EventResponseSave.GetEventFileNameForElement(instance.GetContainer()));
            }
            else
            {
                return(null);
            }
        }
Exemple #5
0
        public void Initialize()
        {
            OverallInitializer.Initialize();

            mEntitySave = new EntitySave();
            mEntitySave.ImplementsIWindow = true;
            mEntitySave.Name = "EventTestEntity";
            mEntitySave.ImplementsIWindow = true;
            ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave);

            mScreenSave = new ScreenSave();
            mScreenSave.Name = "EventTestScreen";
            ObjectFinder.Self.GlueProject.Screens.Add(mScreenSave);

            NamedObjectSave nos = new NamedObjectSave();
            nos.SourceType = SourceType.Entity;
            nos.SourceClassType = "EventTestEntity";
            mScreenSave.NamedObjects.Add(nos);


            EventResponseSave ers = new EventResponseSave();
            ers.SourceObject = "EventTestEntity";
            ers.SourceObjectEvent = "Click";
            ers.EventName = "EventTestEntityClick";
            mScreenSave.Events.Add(ers);

            EventResponseSave pushErs = new EventResponseSave();
            pushErs.SourceObject = "EventTestEntity";
            pushErs.SourceObjectEvent = "Push";
            pushErs.EventName = "EventTestEntityPush";
            mScreenSave.Events.Add(pushErs);

            // Create a POList so we can expose its event(s)
            mListNos = new NamedObjectSave();
            mListNos.SourceType = SourceType.FlatRedBallType;
            mListNos.SourceClassType = "PositionedObjectList<T>";
            mListNos.SourceClassGenericType = "Sprite";
            mScreenSave.NamedObjects.Add(mListNos);

            mDerivedEntitySave = new EntitySave();
            mDerivedEntitySave.Name = "EventTestsDerivedEntity";
            mDerivedEntitySave.BaseEntity = mEntitySave.Name;
            ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave);
        }
        private void UpdateIncludedAndExcluded(EventResponseSave instance)
        {
            ////////////////////Early Out/////////////////////////
            if (instance == null)
            {
                return;
            }
            ///////////////////End Early Out///////////////////////
            ResetToDefault();

            ExcludeMember("ToStringDelegate");
            ExcludeMember("Contents");

            AvailableCustomVariables typeConverter = new AvailableCustomVariables(CurrentElement);
            typeConverter.IncludeNone = false;

            typeConverter.InclusionPredicate = DoesCustomVariableCreateEvent;
            IncludeMember(typeof(EventResponseSave).GetProperty("SourceVariable").Name,
                typeof(EventResponseSave), typeConverter);


            if (string.IsNullOrEmpty(instance.SourceVariable))
            {
                ExcludeMember( typeof(EventResponseSave).GetProperty("BeforeOrAfter").Name);
            }



            AvailableNamedObjectsAndFiles availableNamedObjects = new AvailableNamedObjectsAndFiles(
                CurrentElement);
            availableNamedObjects.IncludeReferencedFiles = false;
            IncludeMember(typeof(EventResponseSave).GetProperty("SourceObject").Name,
                typeof(EventResponseSave),
                availableNamedObjects);

            AvailableEvents availableEvents = new AvailableEvents();
            availableEvents.Element = CurrentElement;
            availableEvents.NamedObjectSave = CurrentElement.GetNamedObjectRecursively(instance.SourceObject);
            IncludeMember(typeof(EventResponseSave).GetProperty("SourceObjectEvent").Name,
                typeof(EventResponseSave),
                availableEvents);

        }
Exemple #7
0
        public static string GetEventContents(this EventResponseSave instance)
        {
            IElement element = instance.GetContainer();

            string textToAssign = null;

            if (FacadeContainer.Self.GlueState.CurrentEventResponseSave != null)
            {
                if (!string.IsNullOrEmpty(instance.Contents))
                {
                    textToAssign = instance.Contents;
                }
                else
                {
                    // Is there a non-Generated.Event.cs file?
                    string fileToLookFor = FileManager.RelativeDirectory +
                                           EventResponseSave.GetEventFileNameForElement(element);

                    if (File.Exists(fileToLookFor))
                    {
                        ParsedMethod parsedMethod =
                            instance.GetParsedMethodFromAssociatedFile();

                        if (parsedMethod != null)
                        {
                            textToAssign =
                                parsedMethod.MethodContents;
                        }
                    }
                }
            }
            else
            {
                textToAssign = null;
            }
            return(textToAssign);
        }
        public static string GetEffectiveDelegateType(this EventResponseSave ers, IElement containingElement)
        {
            if (ers.GetIsTunneling())
            {
                IElement          tunneledElement;
                EventResponseSave tunneledTo = ers.GetEventThisTunnelsTo(containingElement, out tunneledElement);

                if (tunneledTo != null)
                {
                    return(tunneledTo.GetEffectiveDelegateType(tunneledElement));
                }
            }

            EventSave eventSave = ers.GetEventSave();

            string delegateType;

            if (eventSave != null && !string.IsNullOrEmpty(eventSave.DelegateType))
            {
                delegateType = eventSave.DelegateType;
            }
            else if (!string.IsNullOrEmpty(ers.DelegateType))
            {
                delegateType = ers.DelegateType;
            }
            else
            {
                delegateType = "EventHandler";
            }

            if (delegateType == "Action")
            {
                delegateType = "System.Action";
            }

            return(delegateType);
        }
        public static EventResponseSave GetEventThisTunnelsTo(this EventResponseSave instance, IElement element, out IElement containingElement)
        {
            if (instance.GetIsTunneling() == false)
            {
                containingElement = null;
                return(null);
            }
            else
            {
                NamedObjectSave nos = element.GetNamedObject(instance.SourceObject);

                if (nos != null && nos.SourceType == SourceType.Entity)
                {
                    containingElement = ObjectFinder.Self.GetIElement(nos.SourceClassType);

                    if (containingElement != null)
                    {
                        return(containingElement.GetEvent(instance.SourceObjectEvent));
                    }
                }
            }
            containingElement = null;
            return(null);
        }
        private void ApplyEventResponseSave(ElementRuntime elementRuntime, EventResponseSave ers)
        {
            IElement element = elementRuntime.AssociatedIElement;
            string projectDirectory = FileManager.GetDirectory(GlueViewState.Self.CurrentGlueProjectFile);
            string[] lines = GetMethodLines(element, ers, projectDirectory);
            string fileName = EventResponseSave.GetSharedCodeFullFileName(element, projectDirectory);

            CodeContext codeContext = new CodeContext(elementRuntime);
            ApplyLinesInternal(lines, 0, lines.Length, element, codeContext, fileName);
        }
        public static ParsedMethod GetParsedMethodFromAssociatedFile(string fullFileName, EventResponseSave instance)
        {


            if (File.Exists(fullFileName))
            {
                ParsedFile file = new ParsedFile(fullFileName, false, false);

                if (file.Namespaces.Count != 0)
                {
                    ParsedNamespace parsedNamespace = file.Namespaces[0];

                    if (parsedNamespace.Classes.Count != 0)
                    {
                        ParsedClass parsedClass = parsedNamespace.Classes[0];

                        return parsedClass.GetMethod("On" + instance.EventName);
                    }
                }
            }

            return null;
        }
        private static void GenerateInitializeForEvent(ICodeBlock codeBlock, IElement element, EventResponseSave ers)
        {
            bool wasEventAdded = false;

            //We always want this to happen, even if it's 
            // emtpy
            //if (!string.IsNullOrEmpty(ers.Contents))
            //{
            NamedObjectSave sourceNos = null;
            bool shouldCloseIfStatementForNos = false;

            if (!string.IsNullOrEmpty(ers.SourceVariable))
            {
                // This is tied to a variable, so the name comes from the variable event rather than the
                // event name itself
                string eventName = ers.BeforeOrAfter.ToString() + ers.SourceVariable + "Set";
                codeBlock.Line("this." + eventName + " += On" + ers.EventName + ";");
                wasEventAdded = true;
            }

            else if (string.IsNullOrEmpty(ers.SourceObject))
            {

                string leftSide = null;
                EventSave eventSave = ers.GetEventSave();
                if (eventSave == null || string.IsNullOrEmpty(eventSave.ExternalEvent))
                {
                    leftSide = "this." + ers.EventName;
                }
                else
                {
                    leftSide = eventSave.ExternalEvent;
                }



                codeBlock.Line(leftSide + " += On" + ers.EventName + ";");
                wasEventAdded = true;
            }
            else if (!string.IsNullOrEmpty(ers.SourceObjectEvent))
            {
                // Only append this if the source NOS is fully-defined.  If not, we don't want to generate compile errors.
                sourceNos = element.GetNamedObject(ers.SourceObject);

                if (sourceNos != null && sourceNos.IsFullyDefined)
                {
                    NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, sourceNos);

                    string leftSide = null;

                    leftSide = ers.SourceObject + "." + ers.SourceObjectEvent;

                    codeBlock.Line(leftSide + " += On" + ers.EventName + ";");
                    wasEventAdded = true;
                    shouldCloseIfStatementForNos = true;
                }
            }

            if (!string.IsNullOrEmpty(ers.SourceObject) && !string.IsNullOrEmpty(ers.SourceObjectEvent) && wasEventAdded)
            {

                codeBlock.Line(ers.SourceObject + "." + ers.SourceObjectEvent + " += On" + ers.EventName + "Tunnel;");
                if (shouldCloseIfStatementForNos)
                {
                    NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, sourceNos);
                }
            }
        }
        public static ParsedMethod GetParsedMethodFromAssociatedFile(this EventResponseSave instance, IElement container, string baseProjectDirectory)
        {
            string fullFileName = EventResponseSave.GetSharedCodeFullFileName(container, baseProjectDirectory);

            return(GetParsedMethodFromAssociatedFile(fullFileName, instance));
        }
 public TreeNode GetTreeNodeFor(EventResponseSave eventResponse)
 {
     foreach (TreeNode treeNode in this.mEventsTreeNode.Nodes)
     {
         if (treeNode.Tag == eventResponse)
         {
             return treeNode;
         }
     }
     return null;
 }
Exemple #15
0
        public void TestRenamingEvents()
        {
            EventResponseSave ers = new EventResponseSave();
            ers.EventName = "Whatever";
            ers.DelegateType = "System.EventHandler";
            mEntitySave.Events.Add(ers);
            string fileName = ers.GetSharedCodeFullFileName();

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            string directory = FileManager.CurrentDirectory + fileName;

            string contents = "int m = 33;";


            string contentsFileName = EventCodeGenerator.InjectTextForEventAndSaveCustomFile(
                mEntitySave, ers, contents);

            string entireFileContents = FileManager.FromFileText(contentsFileName);

            // Make sure that this file contains the contents
            if (!entireFileContents.Contains(contents))
            {
                throw new Exception("The entire files aren't being added to the event");
            }

            // Test renaming now
            string oldName = ers.EventName;

            string newName = "AfterRename";
            ers.EventName = newName;

            // I can't write unit tests for this yet because it requires that
            // all generate code be moved out of BaseElementTreeNode into CodeWriter:
            //EventResponseSavePropertyChangeHandler.Self.ReactToChange("EventName", oldName, ers, mEntitySave);

            //entireFileContents = FileManager.FromFileText(contentsFileName);

        }
        public static void AddEventToElementAndSave(IElement currentElement, EventResponseSave eventResponseSave)
        {
            currentElement.Events.Add(eventResponseSave);

            string fullGeneratedFileName = ProjectManager.ProjectBase.Directory + EventManager.GetGeneratedEventFileNameForElement(currentElement);

            if (!File.Exists(fullGeneratedFileName))
            {
                CodeWriter.AddEventGeneratedCodeFileForElement(currentElement);
            }

            ElementViewWindow.GenerateSelectedElementCode();

            EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes();

            GluxCommands.Self.SaveGlux();

            EditorLogic.CurrentEventResponseSave = eventResponseSave;
        }
 public static bool GetIsTunneling(this EventResponseSave instance)
 {
     return(!string.IsNullOrEmpty(instance.SourceObject) && !string.IsNullOrEmpty(instance.SourceObjectEvent));
 }
 public static string EventResponseSaveToString(this EventResponseSave eventResponseSave)
 {
     return(eventResponseSave.EventName + "(Event Response in " + eventResponseSave.GetContainer() + ")");
 }
        public static string GetArgsForMethod(this EventResponseSave ers, IElement containingElement)
        {
            EventSave eventSave = ers.GetEventSave();


            string args      = null;
            bool   foundArgs = false;

            if (eventSave != null)
            {
                args      = eventSave.Arguments;
                foundArgs = true;
            }
            else if (ers.GetIsTunneling())
            {
                IElement          tunneledContainingElement;
                EventResponseSave tunneled = ers.GetEventThisTunnelsTo(containingElement, out tunneledContainingElement);

                if (tunneled != null)
                {
                    return(tunneled.GetArgsForMethod(tunneledContainingElement));
                }
            }
            else if (!string.IsNullOrEmpty(ers.DelegateType))
            {
                if (ers.DelegateType.StartsWith("System.Action<"))
                {
                    string delegateType = ers.DelegateType;

                    int startOfGeneric  = delegateType.IndexOf("<") + 1;
                    int endofGeneric    = delegateType.LastIndexOf(">");
                    int lengthOfGeneric = endofGeneric - startOfGeneric;

                    string genericType = delegateType.Substring(startOfGeneric, lengthOfGeneric);

                    args      = genericType + " value";
                    foundArgs = true;
                }
                else
                {
                    Type type = TypeManager.GetTypeFromString(ers.DelegateType);

                    if (type != null)
                    {
                        MethodInfo      methodInfo = type.GetMethod("Invoke");
                        ParameterInfo[] parameters = methodInfo.GetParameters();
                        for (int i = 0; i < parameters.Length; i++)
                        {
                            if (i != 0)
                            {
                                args += ", ";
                            }

                            ParameterInfo param = parameters[i];

                            args += param.ParameterType.FullName + " " + param.Name;
                            Console.WriteLine("{0} {1}", param.ParameterType.Name, param.Name);
                        }

                        foundArgs = true;
                    }
                }
            }

            if (!foundArgs)
            {
                args = "object sender, EventArgs e";
            }

            return(args);
        }
 public static bool GetIsNewEvent(this EventResponseSave eventResponseSave)
 {
     return(!eventResponseSave.GetIsExposing() && !eventResponseSave.GetIsTunneling() &&
            !string.IsNullOrEmpty(eventResponseSave.DelegateType));
 }
        public static ParsedMethod GetParsedMethodFromAssociatedFile(string fullFileName, EventResponseSave instance)
        {
            if (File.Exists(fullFileName))
            {
                ParsedFile file = new ParsedFile(fullFileName, false, false);

                if (file.Namespaces.Count != 0)
                {
                    ParsedNamespace parsedNamespace = file.Namespaces[0];

                    if (parsedNamespace.Classes.Count != 0)
                    {
                        ParsedClass parsedClass = parsedNamespace.Classes[0];

                        return(parsedClass.GetMethod("On" + instance.EventName));
                    }
                }
            }

            return(null);
        }
        private string[] GetMethodLines(IElement element, EventResponseSave ers, string projectDirectory)
        {
            string[] toReturn = null;
            lock (mCachedMethodLines)
            {
                if (!mCachedMethodLines.ContainsKey(ers.EventName))
                {
                    ParsedMethod parsedMethod =
                        ers.GetParsedMethodFromAssociatedFile(element, projectDirectory);
                    string[] lines = parsedMethod.MethodContents.Split(separators, StringSplitOptions.RemoveEmptyEntries);

                    mCachedMethodLines.Add(ers.EventName, lines);
                }

                toReturn = mCachedMethodLines[ers.EventName];
            }
            return toReturn;
        }
        private static void HandleAddEventOk(AddEventWindow addEventWindow)
        {
            string resultName = addEventWindow.ResultName;
            IElement currentElement = EditorLogic.CurrentElement;

            #region Show message boxes if there is an error with the variable
            bool isInvalid = IsVariableInvalid(null, resultName, currentElement);

            #endregion

            if (!isInvalid)
            {
                EventResponseSave eventResponseSave = new EventResponseSave();
                eventResponseSave.EventName = resultName;

                eventResponseSave.SourceObject = addEventWindow.TunnelingObject;
                eventResponseSave.SourceObjectEvent = addEventWindow.TunnelingEvent;

                eventResponseSave.SourceVariable = addEventWindow.SourceVariable;
                eventResponseSave.BeforeOrAfter = addEventWindow.BeforeOrAfter;

                eventResponseSave.DelegateType = addEventWindow.ResultDelegateType;

                AddEventToElementAndSave(currentElement, eventResponseSave);
            }
        }
        private static void ReactToEventRename(object oldValue, EventResponseSave ers, IElement container)
        {
            string oldName = oldValue as string;
            string newName = ers.EventName;
            // The code
            // inside this
            // event handler
            // are saved in the
            // Element.Event.cs file
            // so that it can be edited
            // in Visual Studio.  If the
            // EventResponseSave changes then
            // it will use a new method.  We need
            // to take out the old method and move
            // the contents to the new method.

            // We'll "cheat" by setting the name to the old
            // one and getting the contents, then switching it
            // back to the new:
            string fullFileName = ers.GetSharedCodeFullFileName();
            if (!System.IO.File.Exists(fullFileName))
            {
                PluginManager.ReceiveError("Could not find the file " + fullFileName);
            }
            else if (CodeEditorControl.DetermineIfCodeFileIsValid(fullFileName) == false)
            {
                PluginManager.ReceiveError("Invalid code file " + fullFileName);

            }
            else
            {
                ers.EventName = oldName;
                string contents =
                    CodeEditorControl.RemoveWhiteSpaceForCodeWindow(ers.GetEventContents());

                ers.EventName = newName;
                // Now save the contents into the new method:

                if (string.IsNullOrEmpty(contents) || CodeEditorControl.HasMatchingBrackets(contents))
                {
                    EventCodeGenerator.InjectTextForEventAndSaveCustomFile(
                        container, ers, contents);
                    PluginManager.ReceiveOutput("Saved " + ers);
                    GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode();

                    DialogResult result = MessageBox.Show("Would you like to delete the old method On" + oldName + "?", "Delete old function?", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        int startIndex;
                        int endIndex;

                        contents = FileManager.FromFileText(fullFileName);

                        EventCodeGenerator.GetStartAndEndIndexForMethod(contents,
                            "On" + oldName, out startIndex, out endIndex);

                        contents = contents.Remove(startIndex, endIndex - startIndex);

                        FileManager.SaveText(contents, fullFileName);
                    }
                }
                else
                {
                    PluginManager.ReceiveError("Mismatch of } and { in event " + ers);

                }
            }
        }   
Exemple #25
0
        public TreeNode EventResponseTreeNode(EventResponseSave eventResponse)
        {
            TreeNode foundNode = null;

            foreach (ScreenTreeNode treeNode in ElementViewWindow.ScreensTreeNode.Nodes)
            {
                foundNode = treeNode.GetTreeNodeFor(eventResponse);
                if (foundNode != null)
                {
                    return foundNode;
                }
            }

            TreeNodeCollection nodeCollection = ElementViewWindow.EntitiesTreeNode.Nodes;
            foundNode = FindEventResponseSaveInEntities(eventResponse, nodeCollection);

            return foundNode;
        }
Exemple #26
0
        public IElement GetElementContaining(EventResponseSave ers)
        {
            for (int i = 0; i < ObjectFinder.Self.GlueProject.Screens.Count; i++)
            {
                foreach (EventResponseSave possibleErs in ObjectFinder.Self.GlueProject.Screens[i].Events)
                {
                    if (possibleErs == ers)
                    {
                        return ObjectFinder.Self.GlueProject.Screens[i];
                    }
                }
            }
            for (int i = 0; i < ObjectFinder.Self.GlueProject.Entities.Count; i++)
            {
                foreach (EventResponseSave possibleErs in ObjectFinder.Self.GlueProject.Entities[i].Events)
                {
                    if (possibleErs == ers)
                    {
                        return ObjectFinder.Self.GlueProject.Entities[i];
                    }
                }
            }

            return null;

        }
Exemple #27
0
        public static ParsedMethod GetParsedMethodFromAssociatedFile(this EventResponseSave instance)
        {
            string fullFileName = instance.GetSharedCodeFullFileName();

            return(EventResponseSaveExtensionMethods.GetParsedMethodFromAssociatedFile(fullFileName, instance));
        }
        /// <summary>
        /// Injects the insideOfMethod into an event for the argument 
        /// </summary>
        /// <param name="currentElement">The IElement containing the EventResponseSave.</param>
        /// <param name="eventResponseSave">The EventResponseSave which should have its contents set or replaced.</param>
        /// <param name="insideOfMethod">The inside of the methods to assign.</param>
        /// <returns>The full file name which contains the method contents.</returns>
        public static string InjectTextForEventAndSaveCustomFile(IElement currentElement, EventResponseSave eventResponseSave, string insideOfMethod)
        {
            // In case the user passes null we don't want to have null reference exceptions:
            if (insideOfMethod == null)
            {
                insideOfMethod = "";
            }

            ParsedMethod parsedMethod =
                eventResponseSave.GetParsedMethodFromAssociatedFile();


            string fullFileName = eventResponseSave.GetSharedCodeFullFileName();

            bool forceRegenerate = false;

            string fileContents = null;

            if (File.Exists(fullFileName))
            {
                fileContents = FileManager.FromFileText(fullFileName);
                forceRegenerate = fileContents.Contains("public partial class") == false && fileContents.Contains("{") == false;

                if (forceRegenerate)
                {
                    GlueGui.ShowMessageBox("Forcing a regneration of " + fullFileName + " because it appears to be empty.");
                }
            }

            CreateEmptyCodeIfNecessary(currentElement, fullFileName, forceRegenerate);

            fileContents = FileManager.FromFileText(fullFileName);

            int indexToAddAt = 0;

            if (parsedMethod != null)
            {
                int startIndex;
                int endIndex;
                GetStartAndEndIndexForMethod(parsedMethod, fileContents, out startIndex, out endIndex);
                // We want to include the \r\n at the end, so add 2
                endIndex += 2;
                string whatToRemove = fileContents.Substring(startIndex, endIndex - startIndex);

                fileContents = fileContents.Replace(whatToRemove, null);

                indexToAddAt = startIndex;
                // remove the method to re-add it
            }
            else
            {
                indexToAddAt = EventManager.GetLastLocationInClass(fileContents, startOfLine:true);
            }
            ICodeBlock codeBlock = new CodeDocument(2);
            codeBlock.TabCharacter = "    ";

            insideOfMethod = "" + insideOfMethod.Replace("\r\n", "\r\n            ");
            codeBlock = EventCodeGenerator.FillWithCustomEventCode(codeBlock, eventResponseSave, insideOfMethod, currentElement);

            string methodContents = codeBlock.ToString();


            fileContents = fileContents.Insert(indexToAddAt, codeBlock.ToString());

            eventResponseSave.Contents = null;
            try
            {
                FlatRedBall.Glue.IO.FileWatchManager.IgnoreNextChangeOnFile(fullFileName);
                FileManager.SaveText(fileContents, fullFileName);
            }
            catch (Exception e)
            {
                PluginManager.ReceiveError("Could not save file to " + fullFileName);
            }
            return fullFileName;
        }
 public static bool GetIsExposing(this EventResponseSave instance)
 {
     return(instance.GetEventSave() != null && instance.GetEventSave().CreatesEventMember);
 }
 public static bool GetCreatesEvent(this EventResponseSave eventResponseSave)
 {
     return(eventResponseSave.GetEventSave() != null &&
            eventResponseSave.GetEventSave().CreatesEventMember);
 }
        public void SetBackingObjects(IElement element, EventResponseSave eventResponse)
        {
            mElement = element;
            mEventResponse = eventResponse;

            RefreshLists();
        }
        public static ICodeBlock FillWithGeneratedEventCode(ICodeBlock currentBlock, EventResponseSave ers, IElement element)
        {
            EventSave eventSave = ers.GetEventSave();

            string args = ers.GetArgsForMethod(element);

            if (!string.IsNullOrEmpty(ers.SourceObject) && !string.IsNullOrEmpty(ers.SourceObjectEvent))
            {
                currentBlock = currentBlock
                    .Function("void", "On" + ers.EventName + "Tunnel", args);

                string reducedArgs = StripTypesFromArguments(args);

                currentBlock.If("this." + ers.EventName + " != null")
                    .Line(ers.EventName + "(" + reducedArgs + ");")
                    .End();

                currentBlock = currentBlock.End();
            }
            return currentBlock;
        }
Exemple #33
0
        private TreeNode FindEventResponseSaveInEntities(EventResponseSave eventResponse, TreeNodeCollection nodeCollection)
        {
            TreeNode foundNode = null;

            foreach (TreeNode treeNode in nodeCollection)
            {
                if (treeNode is EntityTreeNode)
                {
                    foundNode = ((EntityTreeNode)treeNode).GetTreeNodeFor(eventResponse);
                    if (foundNode != null)
                    {
                        break;
                    }
                }
                else
                {
                    foundNode = FindEventResponseSaveInEntities(eventResponse, treeNode.Nodes);
                    if (foundNode != null)
                    {
                        break;
                    }
                }
            }
            return foundNode;
        }
        public static ICodeBlock FillWithCustomEventCode(ICodeBlock currentBlock, EventResponseSave ers, string contents, IElement element)
        {
            string args = ers.GetArgsForMethod(element);

            // We used to not 
            // generate the empty
            // shell of an event if
            // the contents were empty.
            // However now we want to for
            // two reasons:
            // 1:  A user may want to add an
            // event in Glue, but then mdoify
            // the event in Visual Studio.  The
            // user shouldn't be forced into adding
            // some content in Glue first to wdit the
            // event in Visual Studio.
            // 2:  A designer may decide to remove the 
            // contents of a method.  If this happens then
            // code that the designer doesn't work with shouldn't
            // break (IE, if the code calls the OnXXXX method).
            //if (!string.IsNullOrEmpty(contents))
            {

                // Need to modify the event CSV to include the arguments for this event

                currentBlock = currentBlock
                    .Function("void", "On" + ers.EventName, args);

                currentBlock.TabCharacter = "";

                int tabCount = currentBlock.TabCount;
                currentBlock.TabCount = 0;

                currentBlock
                        .Line(contents);

                currentBlock = currentBlock.End();
            }
            return currentBlock;
        }